int main (int argc, char* argv[]) { char **newargs; int i, k = 0; newargs = (char **) malloc (sizeof (char *) * (argc + 2 + count_mono_options_args ())); newargs [k++] = argv [0]; if (mono_options != NULL) { i = 0; while (mono_options[i] != NULL) newargs[k++] = mono_options[i++]; } newargs [k++] = image_name; for (i = 1; i < argc; i++) { newargs [k++] = argv [i]; } newargs [k] = NULL; if (config_dir != NULL && getenv ("MONO_CFG_DIR") == NULL) mono_set_dirs (getenv ("MONO_PATH"), config_dir); mono_mkbundle_init(); return mono_main (k, newargs); }
// // Execute a managed assembly with given arguments // // Parameters: // hostHandle - Handle of the host // domainId - Id of the domain // argc - Number of arguments passed to the executed assembly // argv - Array of arguments passed to the executed assembly // managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint). // exitCode - Exit code returned by the executed assembly // // Returns: // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed // int STDAPICALLTYPE coreclr_execute_assembly (void* hostHandle, unsigned int domainId, int argc, const char** argv, const char* managedAssemblyPath, unsigned int* exitCode) { if (exitCode == NULL) { return -1; } // // Make room for program name and executable assembly // int mono_argc = argc + 2; char **mono_argv = (char **) malloc (sizeof (char *) * (mono_argc + 1 /* null terminated */)); const char **ptr = (const char **) mono_argv; *ptr++ = NULL; // executable assembly *ptr++ = (char*) managedAssemblyPath; // the rest for (int i = 0; i < argc; ++i) *ptr++ = argv [i]; *ptr = NULL; mono_parse_env_options (&mono_argc, &mono_argv); *exitCode = mono_main (mono_argc, mono_argv); return 0; }
int main (int argc, char* argv[]) { // work around Android's linker which does not support LD_LIBRARY_PATH... setenv("MONO_PATH", "/data/data/com.koushikdutta.mono/", 0); setenv("HOME", "/data/local", 0); void* libmono = dlopen ("/data/data/com.koushikdutta.mono/libmono.so", RTLD_NOW); void* mono_main_ptr = dlsym (libmono, "mono_main"); mono_main_type mono_main = (mono_main_type)mono_main_ptr; return mono_main (argc, argv); }
int main (int argc, char* argv[]) { char **newargs; int i, k = 0; #ifdef _WIN32 /* CommandLineToArgvW() might return a different argc than the * one passed to main(), so let it overwrite that, as we won't * use argv[] on Windows anyway. */ wchar_t **wargv = CommandLineToArgvW (GetCommandLineW (), &argc); #endif newargs = (char **) malloc (sizeof (char *) * (argc + 2) + count_mono_options_args ()); #ifdef _WIN32 newargs [k++] = g_utf16_to_utf8 (wargv [0], -1, NULL, NULL, NULL); #else newargs [k++] = argv [0]; #endif if (mono_options != NULL) { i = 0; while (mono_options[i] != NULL) newargs[k++] = mono_options[i++]; } newargs [k++] = image_name; for (i = 1; i < argc; i++) { #ifdef _WIN32 newargs [k++] = g_utf16_to_utf8 (wargv [i], -1, NULL, NULL, NULL); #else newargs [k++] = argv [i]; #endif } #ifdef _WIN32 LocalFree (wargv); #endif newargs [k] = NULL; if (config_dir != NULL && getenv ("MONO_CFG_DIR") == NULL) mono_set_dirs (getenv ("MONO_PATH"), config_dir); mono_mkbundle_init(); return mono_main (k, newargs); }
int main (int argc, char* argv[]) { char **newargs; int i, k = 0; #ifdef _WIN32 /* CommandLineToArgvW() might return a different argc than the * one passed to main(), so let it overwrite that, as we won't * use argv[] on Windows anyway. */ wchar_t **wargv = CommandLineToArgvW (GetCommandLineW (), &argc); #endif newargs = (char **) malloc (sizeof (char *) * (argc + 2) + count_mono_options_args ()); #ifdef _WIN32 newargs [k++] = g_utf16_to_utf8 (wargv [0], -1, NULL, NULL, NULL); #else newargs [k++] = argv [0]; #endif if (mono_options != NULL) { i = 0; while (mono_options[i] != NULL) newargs[k++] = mono_options[i++]; } BrInitError err = 0; if (br_init(&err) == 1) { char *exedir = br_find_exe_dir(NULL); if (exedir) { setenv("MONO_PATH",exedir,1); mono_set_dirs(exedir, exedir); chdir(exedir); free(exedir); } } else { switch (err) { case BR_INIT_ERROR_NOMEM: printf("Could not allocate enough memory\n"); break; case BR_INIT_ERROR_OPEN_MAPS: case BR_INIT_ERROR_READ_MAPS: case BR_INIT_ERROR_INVALID_MAPS: printf("Couldn't access /proc/self/maps!\n"); break; case BR_INIT_ERROR_DISABLED: printf("BinReloc disabled!!\n"); break; } return 1; } // Calculate image_name char *image_name; char *exe = br_find_exe(NULL); char *pos = strrchr(exe, '/'); if (pos != NULL) { image_name = strdup(pos+1); pos = strstr(image_name,".bin."); if (pos != NULL) { strcpy(pos, ".exe"); } } free(exe); newargs [k++] = image_name; for (i = 1; i < argc; i++) { #ifdef _WIN32 newargs [k++] = g_utf16_to_utf8 (wargv [i], -1, NULL, NULL, NULL); #else newargs [k++] = argv [i]; #endif } #ifdef _WIN32 LocalFree (wargv); #endif newargs [k] = NULL; return mono_main (k, newargs); }