Skip to content

Commit 1216016

Browse files
committed
Remove all the WINDOWS, APPLE, desktop and !NET code
A long overdue cleanup
1 parent 66f3db0 commit 1216016

37 files changed

+295
-2082
lines changed

src/monodroid/jni/android-system.cc

Lines changed: 32 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
#include <cstring>
2-
#include <cstdlib>
31
#include <cerrno>
4-
#include <ctype.h>
2+
#include <cstdlib>
3+
#include <cstring>
54
#include <fcntl.h>
65

7-
#if defined (WINDOWS)
8-
#include <windef.h>
9-
#include <winbase.h>
10-
#include <shlobj.h>
11-
#include <objbase.h>
12-
#include <knownfolders.h>
13-
#include <shlwapi.h>
14-
#endif
15-
166
#include "globals.hh"
177
#include "android-system.hh"
18-
#include "monodroid.h"
19-
#include "monodroid-glue-internal.hh"
208
#include "jni-wrappers.hh"
219
#include "xamarin-app.hh"
2210
#include "cpp-util.hh"
2311
#include "java-interop-dlfcn.h"
2412
#include "java-interop.h"
2513

26-
#if defined (DEBUG) || !defined (ANDROID)
14+
#if defined (DEBUG)
2715
namespace xamarin::android::internal {
2816
struct BundledProperty {
2917
char *name;
@@ -32,22 +20,15 @@ namespace xamarin::android::internal {
3220
struct BundledProperty *next;
3321
};
3422
}
35-
#endif // DEBUG || !ANDROID
23+
#endif // DEBUG
3624

3725
using namespace microsoft::java_interop;
3826
using namespace xamarin::android;
3927
using namespace xamarin::android::internal;
4028

41-
#if defined (DEBUG) || !defined (ANDROID)
29+
#if defined (DEBUG)
4230
BundledProperty *AndroidSystem::bundled_properties = nullptr;
43-
#endif // DEBUG || !ANDROID
4431

45-
#if defined (WINDOWS)
46-
std::mutex AndroidSystem::readdir_mutex;
47-
char *AndroidSystem::libmonoandroid_directory_path = nullptr;
48-
#endif
49-
50-
#if defined (DEBUG) || !defined (ANDROID)
5132
BundledProperty*
5233
AndroidSystem::lookup_system_property (const char *name)
5334
{
@@ -58,13 +39,13 @@ AndroidSystem::lookup_system_property (const char *name)
5839
}
5940
return nullptr;
6041
}
61-
#endif // DEBUG || !ANDROID
42+
#endif // DEBUG
6243

6344
const char*
6445
AndroidSystem::lookup_system_property (const char *name, size_t &value_len)
6546
{
6647
value_len = 0;
67-
#if defined (DEBUG) || !defined (ANDROID)
48+
#if defined (DEBUG)
6849
BundledProperty *p = lookup_system_property (name);
6950
if (p != nullptr) {
7051
value_len = p->value_len;
@@ -102,7 +83,7 @@ AndroidSystem::lookup_system_property (const char *name, size_t &value_len)
10283
return nullptr;
10384
}
10485

105-
#if defined (DEBUG) || !defined (ANDROID)
86+
#if defined (DEBUG)
10687
void
10788
AndroidSystem::add_system_property (const char *name, const char *value)
10889
{
@@ -138,57 +119,8 @@ AndroidSystem::add_system_property (const char *name, const char *value)
138119
p->next = bundled_properties;
139120
bundled_properties = p;
140121
}
141-
#endif // DEBUG || !ANDROID
142-
143-
#ifndef ANDROID
144-
void
145-
AndroidSystem::monodroid_strreplace (char *buffer, char old_char, char new_char)
146-
{
147-
if (buffer == nullptr)
148-
return;
149-
while (*buffer != '\0') {
150-
if (*buffer == old_char)
151-
*buffer = new_char;
152-
buffer++;
153-
}
154-
}
155-
156-
int
157-
AndroidSystem::_monodroid__system_property_get (const char *name, char *sp_value, size_t sp_value_len)
158-
{
159-
if (!name || !sp_value)
160-
return -1;
161-
162-
char *env_name = utils.monodroid_strdup_printf ("__XA_%s", name);
163-
monodroid_strreplace (env_name, '.', '_');
164-
char *env_value = getenv (env_name);
165-
free (env_name);
166-
167-
size_t env_value_len = env_value ? strlen (env_value) : 0;
168-
if (env_value_len == 0) {
169-
sp_value[0] = '\0';
170-
return 0;
171-
}
172-
173-
if (env_value_len >= sp_value_len)
174-
log_warn (LOG_DEFAULT, "System property buffer size too small by %u bytes", env_value_len == sp_value_len ? 1 : env_value_len - sp_value_len);
175-
176-
//
177-
// sp_value_len includes the terminating nul, avoid a mingw g++ warning about string truncation
178-
// by making the amount of data copied one less than the indicated length. The warning reported
179-
// is:
180-
//
181-
// In function ‘int xamarin::android::internal::AndroidSystem::_monodroid__system_property_get(const char*, char*, size_t)’,
182-
// inlined from ‘int xamarin::android::internal::AndroidSystem::monodroid_get_system_property(const char*, char**)’ at ../../../jni/android-system.cc:243:44:
183-
// ../../../jni/android-system.cc(206,10): warning G20816D19: ‘char* strncpy(char*, const char*, size_t)’ specified bound 93 equals destination size [-Wstringop-truncation] [/home/grendel/vc/xamarin/xamarin-android-worktrees/code-quality-improvements/src/monodroid/monodroid.csproj]
184-
// strncpy (sp_value, env_value, sp_value_len);
185-
//
186-
strncpy (sp_value, env_value, sp_value_len - 2);
187-
sp_value[sp_value_len - 1] = '\0';
122+
#endif // DEBUG
188123

189-
return static_cast<int>(strlen (sp_value));
190-
}
191-
#else
192124
int
193125
AndroidSystem::_monodroid__system_property_get (const char *name, char *sp_value, size_t sp_value_len)
194126
{
@@ -211,7 +143,6 @@ AndroidSystem::_monodroid__system_property_get (const char *name, char *sp_value
211143

212144
return len;
213145
}
214-
#endif
215146

216147
int
217148
AndroidSystem::monodroid_get_system_property (const char *name, dynamic_local_string<PROPERTY_VALUE_BUFFER_LEN>& value)
@@ -263,7 +194,7 @@ AndroidSystem::monodroid_get_system_property (const char *name, char **value)
263194
return len;
264195
}
265196

266-
#if defined (DEBUG) || !defined (ANDROID)
197+
#if defined (DEBUG)
267198
size_t
268199
AndroidSystem::_monodroid_get_system_property_from_file (const char *path, char **value)
269200
{
@@ -299,12 +230,12 @@ AndroidSystem::_monodroid_get_system_property_from_file (const char *path, char
299230
}
300231
return len;
301232
}
302-
#endif
233+
#endif // def DEBUG
303234

304235
size_t
305236
AndroidSystem::monodroid_get_system_property_from_overrides ([[maybe_unused]] const char *name, [[maybe_unused]] char ** value)
306237
{
307-
#if defined (DEBUG) || !defined (ANDROID)
238+
#if defined (DEBUG)
308239
for (const char *od : override_dirs) {
309240
if (od == nullptr) {
310241
continue;
@@ -319,14 +250,14 @@ AndroidSystem::monodroid_get_system_property_from_overrides ([[maybe_unused]] co
319250
log_info (LOG_DEFAULT, "Property '%s' from %s has value '%s'.", name, od, *value);
320251
return result;
321252
}
322-
#endif
253+
#endif // def DEBUG
323254
return 0;
324255
}
325256

326257
void
327258
AndroidSystem::create_update_dir (char *override_dir)
328259
{
329-
#if defined(RELEASE)
260+
#if defined (RELEASE)
330261
/*
331262
* Don't create .__override__ on Release builds, because Google requires
332263
* that pre-loaded apps not create world-writable directories.
@@ -337,7 +268,7 @@ AndroidSystem::create_update_dir (char *override_dir)
337268
if (log_categories == 0 && monodroid_get_system_property (Debug::DEBUG_MONO_PROFILE_PROPERTY, nullptr) == 0) {
338269
return;
339270
}
340-
#endif
271+
#endif // def RELEASE
341272

342273
override_dirs [0] = override_dir;
343274
utils.create_public_directory (override_dir);
@@ -354,7 +285,7 @@ AndroidSystem::get_full_dso_path (const char *base_dir, const char *dso_path, dy
354285
return const_cast<char*>(dso_path); // Absolute path or no base path, can't do much with it
355286

356287
path.assign_c (base_dir)
357-
.append (MONODROID_PATH_SEPARATOR)
288+
.append ("/")
358289
.append_c (dso_path);
359290

360291
return true;
@@ -411,9 +342,9 @@ AndroidSystem::load_dso_from_override_dirs ([[maybe_unused]] const char *name, [
411342
{
412343
#ifdef RELEASE
413344
return nullptr;
414-
#else
345+
#else // def RELEASE
415346
return load_dso_from_specified_dirs (const_cast<const char**> (AndroidSystem::override_dirs.data ()), AndroidSystem::override_dirs.size (), name, dl_flags);
416-
#endif
347+
#endif // ndef RELEASE
417348
}
418349

419350
void*
@@ -447,7 +378,7 @@ AndroidSystem::get_full_dso_path_on_disk (const char *dso_name, dynamic_local_st
447378
if (get_existing_dso_path_on_disk (od, dso_name, path))
448379
return true;
449380
}
450-
#endif
381+
#endif // ndef RELEASE
451382
for (const char *app_lib_dir : app_lib_directories) {
452383
if (get_existing_dso_path_on_disk (app_lib_dir, dso_name, path)) {
453384
return true;
@@ -463,20 +394,20 @@ AndroidSystem::count_override_assemblies (void)
463394
int c = 0;
464395

465396
for (const char *dir_path : override_dirs) {
466-
monodroid_dir_t *dir;
467-
monodroid_dirent_t *e;
397+
DIR *dir;
398+
dirent *e;
468399

469400
if (dir_path == nullptr || !utils.directory_exists (dir_path))
470401
continue;
471402

472-
if ((dir = utils.monodroid_opendir (dir_path)) == nullptr)
403+
if ((dir = ::opendir (dir_path)) == nullptr)
473404
continue;
474405

475-
while ((e = readdir (dir)) != nullptr && e) {
406+
while ((e = ::readdir (dir)) != nullptr && e) {
476407
if (utils.monodroid_dirent_hasextension (e, ".dll"))
477408
++c;
478409
}
479-
utils.monodroid_closedir (dir);
410+
::closedir (dir);
480411
}
481412

482413
return c;
@@ -525,7 +456,7 @@ AndroidSystem::get_gref_gc_threshold ()
525456
return static_cast<int> ((max_gref_count * 90LL) / 100LL);
526457
}
527458

528-
#if defined (DEBUG) || !defined (ANDROID)
459+
#if defined (DEBUG)
529460
void
530461
AndroidSystem::setup_environment (const char *name, const char *value)
531462
{
@@ -548,13 +479,10 @@ AndroidSystem::setup_environment (const char *name, const char *value)
548479
void
549480
AndroidSystem::setup_environment_from_override_file (const char *path)
550481
{
551-
#if WINDOWS
552-
using read_count_type = unsigned int;
553-
#else
554482
using read_count_type = size_t;
555-
#endif
556-
monodroid_stat_t sbuf;
557-
if (utils.monodroid_stat (path, &sbuf) < 0) {
483+
484+
struct stat sbuf;
485+
if (::stat (path, &sbuf) < 0) {
558486
log_warn (LOG_DEFAULT, "Failed to stat the environment override file %s: %s", path, strerror (errno));
559487
return;
560488
}
@@ -636,7 +564,7 @@ AndroidSystem::setup_environment_from_override_file (const char *path)
636564
data_size -= data_width;
637565
}
638566
}
639-
#endif // DEBUG || !ANDROID
567+
#endif // def DEBUG
640568

641569
void
642570
AndroidSystem::setup_environment ()
@@ -656,12 +584,7 @@ AndroidSystem::setup_environment ()
656584
break;
657585

658586
case 'i':
659-
#if !defined (NET)
660-
aotMode = MonoAotMode::MONO_AOT_MODE_LAST;
661-
aot_mode_last_is_interpreter = true;
662-
#else // defined (NET)
663587
aotMode = MonoAotMode::MONO_AOT_MODE_INTERP_ONLY;
664-
#endif // !defined (NET)
665588
break;
666589

667590
default:
@@ -701,19 +624,19 @@ AndroidSystem::setup_environment ()
701624

702625
#if defined (DEBUG)
703626
log_info (LOG_DEFAULT, "Setting environment variable '%s' to '%s'", var_name, var_value);
704-
#endif
627+
#endif // def DEBUG
705628
if (setenv (var_name, var_value, 1) < 0)
706629
log_warn (LOG_DEFAULT, "Failed to set environment variable: %s", strerror (errno));
707630
}
708-
#if defined (DEBUG) || !defined (ANDROID)
631+
#if defined (DEBUG)
709632
// TODO: for debug read from file in the override directory named `environment`
710633
for (const char *od : override_dirs) {
711634
std::unique_ptr<char[]> env_override_file {utils.path_combine (od, OVERRIDE_ENVIRONMENT_FILE_NAME.data ())};
712635
if (utils.file_exists (env_override_file.get ())) {
713636
setup_environment_from_override_file (env_override_file.get ());
714637
}
715638
}
716-
#endif
639+
#endif // def DEBUG
717640
}
718641

719642
void
@@ -731,70 +654,3 @@ AndroidSystem::setup_process_args (jstring_array_wrapper &runtimeApks)
731654
{
732655
for_each_apk (runtimeApks, static_cast<BasicAndroidSystem::ForEachApkHandler> (&AndroidSystem::setup_process_args_apk), nullptr);
733656
}
734-
735-
monodroid_dirent_t*
736-
AndroidSystem::readdir (monodroid_dir_t *dir)
737-
{
738-
#if defined (WINDOWS)
739-
return readdir_windows (dir);
740-
#else
741-
return ::readdir (dir);
742-
#endif
743-
}
744-
745-
#if defined (WINDOWS)
746-
struct _wdirent*
747-
AndroidSystem::readdir_windows (_WDIR *dirp)
748-
{
749-
std::lock_guard<std::mutex> lock (readdir_mutex);
750-
errno = 0;
751-
struct _wdirent *entry = _wreaddir (dirp);
752-
753-
if (entry == nullptr && errno != 0)
754-
return nullptr;
755-
756-
return entry;
757-
}
758-
759-
// Returns the directory in which this library was loaded from
760-
char*
761-
AndroidSystem::get_libmonoandroid_directory_path ()
762-
{
763-
wchar_t module_path[MAX_PATH];
764-
HMODULE module = nullptr;
765-
766-
if (libmonoandroid_directory_path != nullptr)
767-
return libmonoandroid_directory_path;
768-
769-
DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
770-
const wchar_t *dir_path = reinterpret_cast<wchar_t*>(&libmonoandroid_directory_path);
771-
BOOL retval = GetModuleHandleExW (flags, dir_path, &module);
772-
if (!retval)
773-
return nullptr;
774-
775-
GetModuleFileNameW (module, module_path, sizeof (module_path) / sizeof (module_path[0]));
776-
PathRemoveFileSpecW (module_path);
777-
libmonoandroid_directory_path = utils.utf16_to_utf8 (module_path);
778-
return libmonoandroid_directory_path;
779-
}
780-
781-
int
782-
AndroidSystem::setenv (const char *name, const char *value, [[maybe_unused]] int overwrite)
783-
{
784-
wchar_t *wname = utils.utf8_to_utf16 (name);
785-
wchar_t *wvalue = utils.utf8_to_utf16 (value);
786-
787-
BOOL result = SetEnvironmentVariableW (wname, wvalue);
788-
free (wname);
789-
free (wvalue);
790-
791-
return result ? 0 : -1;
792-
}
793-
794-
int
795-
AndroidSystem::symlink (const char *target, const char *linkpath)
796-
{
797-
return utils.file_copy (target, linkpath);
798-
}
799-
#else
800-
#endif

0 commit comments

Comments
 (0)