X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fio-layer%2Fprocesses.c;h=df8d7143d57ffa72c6cc47e4f5fd300cb08cb7cb;hb=ced936f46b70e059b00f98ae25e5819c6ce9b3ea;hp=df101ae76a42d42424b56a21f47a2c1f2fb93566;hpb=2901e91c9d60c0556f993a474b0d582dc53a84f2;p=mono.git diff --git a/mono/io-layer/processes.c b/mono/io-layer/processes.c index df101ae76a4..df8d7143d57 100644 --- a/mono/io-layer/processes.c +++ b/mono/io-layer/processes.c @@ -83,7 +83,6 @@ #include #include #include -#include #include #include #include @@ -91,19 +90,25 @@ #include #include #include -#include +#include #include #include +#include /* The process' environment strings */ -#if defined(__APPLE__) && !defined (__arm__) && !defined (__aarch64__) +#if defined(__APPLE__) +#if defined (TARGET_OSX) /* Apple defines this in crt_externs.h but doesn't provide that header for * arm-apple-darwin9. We'll manually define the symbol on Apple as it does * in fact exist on all implementations (so far) */ -char ***_NSGetEnviron(void); +gchar ***_NSGetEnviron(void); #define environ (*_NSGetEnviron()) #else +static char *mono_environ[1] = { NULL }; +#define environ mono_environ +#endif /* defined (TARGET_OSX) */ +#else extern char **environ; #endif @@ -1032,7 +1037,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline, mono_process = (struct MonoProcess *) g_malloc0 (sizeof (struct MonoProcess)); mono_process->pid = pid; mono_process->handle_count = 1; - if (MONO_SEM_INIT (&mono_process->exit_sem, 0) != 0) { + if (mono_os_sem_init (&mono_process->exit_sem, 0) != 0) { /* If we can't create the exit semaphore, we just don't add anything * to our list of mono processes. Waiting on the process will return * immediately. */ @@ -1046,10 +1051,10 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline, process_handle_data->mono_process = mono_process; - mono_mutex_lock (&mono_processes_mutex); + mono_os_mutex_lock (&mono_processes_mutex); mono_process->next = mono_processes; mono_processes = mono_process; - mono_mutex_unlock (&mono_processes_mutex); + mono_os_mutex_unlock (&mono_processes_mutex); } if (process_info != NULL) { @@ -1143,6 +1148,8 @@ wapi_processes_init (void) current_process = _wapi_handle_new (WAPI_HANDLE_PROCESS, &process_handle); g_assert (current_process); + + mono_os_mutex_init (&mono_processes_mutex); } gpointer @@ -1775,7 +1782,7 @@ gboolean EnumProcessModules (gpointer process, gpointer *modules, return FALSE; } pid = process_handle->id; - proc_name = process_handle->proc_name; + proc_name = g_strdup (process_handle->proc_name); } #if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__HAIKU__) @@ -1793,6 +1800,7 @@ gboolean EnumProcessModules (gpointer process, gpointer *modules, */ modules[0] = NULL; *needed = sizeof(gpointer); + g_free (proc_name); return TRUE; } mods = load_modules (fp); @@ -1826,7 +1834,8 @@ gboolean EnumProcessModules (gpointer process, gpointer *modules, free_procmodule (g_slist_nth_data (mods, i)); } g_slist_free (mods); - + g_free (proc_name); + return TRUE; } @@ -2578,10 +2587,10 @@ mono_processes_cleanup (void) if (mp->pid == 0 && mp->handle) { /* This process has exited and we need to remove the artifical ref * on the handle */ - mono_mutex_lock (&mono_processes_mutex); + mono_os_mutex_lock (&mono_processes_mutex); unref_handle = mp->handle; mp->handle = NULL; - mono_mutex_unlock (&mono_processes_mutex); + mono_os_mutex_unlock (&mono_processes_mutex); if (unref_handle) _wapi_handle_unref (unref_handle); } @@ -2593,7 +2602,7 @@ mono_processes_cleanup (void) * asynchronously. The handler requires that the mono_processes list * remain valid. */ - mono_mutex_lock (&mono_processes_mutex); + mono_os_mutex_lock (&mono_processes_mutex); mp = mono_processes; while (mp) { @@ -2625,12 +2634,12 @@ mono_processes_cleanup (void) * accessing them. */ mp = l->data; - MONO_SEM_DESTROY (&mp->exit_sem); + mono_os_sem_destroy (&mp->exit_sem); g_free (mp); } g_slist_free (finished); - mono_mutex_unlock (&mono_processes_mutex); + mono_os_mutex_unlock (&mono_processes_mutex); DEBUG ("%s done", __func__); @@ -2682,7 +2691,7 @@ MONO_SIGNAL_HANDLER_FUNC (static, mono_sigchld_signal_handler, (int _dummy, sigi if (p) { p->pid = 0; /* this pid doesn't exist anymore, clear it */ p->status = status; - MONO_SEM_POST (&p->exit_sem); + mono_os_sem_post (&p->exit_sem); mono_memory_barrier (); /* Mark this as freeable, the pointer becomes invalid afterwards */ p->freeable = TRUE; @@ -2752,12 +2761,11 @@ process_wait (gpointer handle, guint32 timeout, gboolean alertable) if (timeout != INFINITE) { DEBUG ("%s (%p, %u): waiting on semaphore for %li ms...", __func__, handle, timeout, (timeout - (now - start))); - - ret = MONO_SEM_TIMEDWAIT_ALERTABLE (&mp->exit_sem, (timeout - (now - start)), alertable); + ret = mono_os_sem_timedwait (&mp->exit_sem, (timeout - (now - start)), alertable ? MONO_SEM_FLAGS_ALERTABLE : MONO_SEM_FLAGS_NONE); } else { DEBUG ("%s (%p, %u): waiting on semaphore forever...", __func__, handle, timeout); - ret = MONO_SEM_WAIT_ALERTABLE (&mp->exit_sem, alertable); + ret = mono_os_sem_wait (&mp->exit_sem, alertable ? MONO_SEM_FLAGS_ALERTABLE : MONO_SEM_FLAGS_NONE); } if (ret == -1 && errno != EINTR && errno != ETIMEDOUT) { @@ -2768,7 +2776,7 @@ process_wait (gpointer handle, guint32 timeout, gboolean alertable) if (ret == 0) { /* Success, process has exited */ - MONO_SEM_POST (&mp->exit_sem); + mono_os_sem_post (&mp->exit_sem); break; }