|
30 | 30 |
|
31 | 31 | const char * runtime_bundle_path(void); |
32 | 32 |
|
| 33 | +static char *bundle_path; |
| 34 | +static char *doc_path; |
| 35 | + |
| 36 | +const char * |
| 37 | +get_bundle_path (void) |
| 38 | +{ |
| 39 | + if (bundle_path) |
| 40 | + return bundle_path; |
| 41 | + |
| 42 | + #if RUNTIME_IOS |
| 43 | + NSBundle *main_bundle = [NSBundle mainBundle]; |
| 44 | + NSString *path; |
| 45 | + |
| 46 | + path = [main_bundle bundlePath]; |
| 47 | + bundle_path = strdup ([path UTF8String]); |
| 48 | +#else |
| 49 | + if ((bundle_path = _getcwd(NULL, 0)) == NULL) |
| 50 | + { |
| 51 | + perror("getcwd error"); |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + printf("doc_path=%s\n", doc_path); |
| 56 | + } |
| 57 | +#endif |
| 58 | + return bundle_path; |
| 59 | +} |
| 60 | + |
| 61 | +const char * |
| 62 | +get_documents_path(void) |
| 63 | +{ |
| 64 | + if (doc_path) |
| 65 | + return doc_path; |
| 66 | + |
| 67 | +#if RUNTIME_IOS |
| 68 | + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
| 69 | + NSString *path = [paths objectAtIndex : 0]; |
| 70 | + doc_path = strdup([path UTF8String]); |
| 71 | +#else |
| 72 | + if ((doc_path = _getcwd(NULL, 0)) == NULL) |
| 73 | + { |
| 74 | + perror("getcwd error"); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + printf("doc_path=%s\n", doc_path); |
| 79 | + } |
| 80 | +#endif |
| 81 | + return doc_path; |
| 82 | +} |
| 83 | + |
| 84 | + |
33 | 85 | void mono_ios_setup_execution_mode (void) |
34 | 86 | { |
35 | 87 | mono_icall_table_init (); |
@@ -58,7 +110,7 @@ void set_log_callback(print_log callback) |
58 | 110 | const char *bundle = runtime_bundle_path (); |
59 | 111 |
|
60 | 112 | // LOG (PRODUCT ": Looking for aot data for assembly '%s'.", name); |
61 | | - res = snprintf (path, sizeof (path) - 1, "%s/%s.aotdata", bundle, aname); |
| 113 | + res = snprintf (path, sizeof (path) - 1, "%s/%s.dll.aotdata", bundle, aname); |
62 | 114 | assert (res > 0); |
63 | 115 |
|
64 | 116 | int fd = open (path, O_RDONLY); |
@@ -129,28 +181,96 @@ void set_log_callback(print_log callback) |
129 | 181 | //mono_jit_init_version ("Mono.ios", "mobile"); |
130 | 182 | } |
131 | 183 |
|
132 | | -char* doc_path = NULL; |
| 184 | + |
| 185 | + |
| 186 | +// |
| 187 | +// ICALLS used by the mobile profile of mscorlib |
| 188 | +// |
| 189 | +// NOTE: The timezone functions are duplicated in XI, so if you're going to modify here, you have to |
| 190 | +// modify there. |
| 191 | +// |
| 192 | +// See in XI runtime/xamarin-support.m |
| 193 | + |
| 194 | +void* |
| 195 | +xamarin_timezone_get_data (const char *name, uint32_t *size) |
| 196 | +{ |
| 197 | + NSTimeZone *tz = nil; |
| 198 | + if (name) { |
| 199 | + NSString *n = [[NSString alloc] initWithUTF8String: name]; |
| 200 | + tz = [[NSTimeZone alloc] initWithName:n]; |
| 201 | + } else { |
| 202 | + tz = [NSTimeZone localTimeZone]; |
| 203 | + } |
| 204 | + NSData *data = [tz data]; |
| 205 | + *size = [data length]; |
| 206 | + void* result = malloc (*size); |
| 207 | + memcpy (result, data.bytes, *size); |
| 208 | + return result; |
| 209 | +} |
| 210 | + |
| 211 | +// |
| 212 | +// Returns the geopolitical region ID of the local timezone. |
| 213 | + |
133 | 214 | const char * |
134 | | -get_documents_path(void) |
| 215 | +xamarin_timezone_get_local_name () |
135 | 216 | { |
136 | | - if (doc_path) |
137 | | - return doc_path; |
| 217 | + NSTimeZone *tz = nil; |
| 218 | + tz = [NSTimeZone localTimeZone]; |
| 219 | + NSString *name = [tz name]; |
| 220 | + return (name != nil) ? strdup ([name UTF8String]) : strdup ("Local"); |
| 221 | +} |
138 | 222 |
|
139 | | -#if RUNTIME_IOS |
140 | | - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
141 | | - NSString *path = [paths objectAtIndex : 0]; |
142 | | - doc_path = strdup([path UTF8String]); |
| 223 | +char** |
| 224 | +xamarin_timezone_get_names (uint32_t *count) |
| 225 | +{ |
| 226 | + // COOP: no managed memory access: any mode. |
| 227 | + NSArray *array = [NSTimeZone knownTimeZoneNames]; |
| 228 | + *count = array.count; |
| 229 | + char** result = (char**) malloc (sizeof (char*) * (*count)); |
| 230 | + for (uint32_t i = 0; i < *count; i++) { |
| 231 | + NSString *s = [array objectAtIndex: i]; |
| 232 | + result [i] = strdup (s.UTF8String); |
| 233 | + } |
| 234 | + return result; |
| 235 | +} |
| 236 | + |
| 237 | +// called from mono-extensions/mcs/class/corlib/System/Environment.iOS.cs |
| 238 | +const char * |
| 239 | +xamarin_GetFolderPath (int folder) |
| 240 | +{ |
| 241 | + // COOP: no managed memory access: any mode. |
| 242 | + // NSUInteger-based enum (and we do not want corlib exposed to 32/64 bits differences) |
| 243 | + NSSearchPathDirectory dd = (NSSearchPathDirectory) folder; |
| 244 | + NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:dd inDomains:NSUserDomainMask] lastObject]; |
| 245 | + NSString *path = [url path]; |
| 246 | + return strdup ([path UTF8String]); |
| 247 | +} |
| 248 | + |
| 249 | + |
| 250 | +// mcs/class/corlib/System/Console.iOS.cs |
| 251 | +void |
| 252 | +xamarin_log (const unsigned short *unicodeMessage) |
| 253 | +{ |
| 254 | + // COOP: no managed memory access: any mode. |
| 255 | + int length = 0; |
| 256 | + const unsigned short *ptr = unicodeMessage; |
| 257 | + while (*ptr++) |
| 258 | + length += sizeof (unsigned short); |
| 259 | + NSString *msg = [[NSString alloc] initWithBytes: unicodeMessage length: length encoding: NSUTF16LittleEndianStringEncoding]; |
| 260 | + |
| 261 | + // if(print_log_callback != NULL) |
| 262 | + // print_log_callback(msg); |
| 263 | +#if TARGET_OS_WATCH && defined (__arm__) // maybe make this configurable somehow? |
| 264 | + const char *utf8 = [msg UTF8String]; |
| 265 | + int len = strlen (utf8); |
| 266 | + fwrite (utf8, 1, len, stdout); |
| 267 | + if (len == 0 || utf8 [len - 1] != '\n') |
| 268 | + fwrite ("\n", 1, 1, stdout); |
| 269 | + fflush (stdout); |
143 | 270 | #else |
144 | | - if ((doc_path = _getcwd(NULL, 0)) == NULL) |
145 | | - { |
146 | | - perror("getcwd error"); |
147 | | - } |
148 | | - else |
149 | | - { |
150 | | - printf("doc_path=%s\n", doc_path); |
151 | | - } |
| 271 | + // os_log (stdout_log, "%{public}@", msg); |
| 272 | + NSLog (@"%@", msg); |
152 | 273 | #endif |
153 | | - return doc_path; |
154 | 274 | } |
155 | 275 |
|
156 | 276 | #endif |
0 commit comments