/* * returns: -1 on error: * timeout on timeout * index into _signals array of signal that was generated on success */ int Mono_Unix_UnixSignal_WaitAny (void** _signals, int count, int timeout /* milliseconds */, Mono_Posix_RuntimeIsShuttingDown shutting_down) { int r; int currfd = 0; struct pollfd fd_structs[NUM_SIGNALS]; signal_info** signals = (signal_info**) _signals; if (count > NUM_SIGNALS) return -1; if (acquire_mutex (&signals_mutex) == -1) return -1; r = setup_pipes (signals, count, &fd_structs[0], &currfd); release_mutex (&signals_mutex); if (r == 0) { r = wait_for_any (signals, count, &currfd, &fd_structs[0], timeout, shutting_down); } if (acquire_mutex (&signals_mutex) == -1) return -1; teardown_pipes (signals, count); release_mutex (&signals_mutex); return r; }
int Mono_Unix_UnixSignal_uninstall (void* info) { signal_info* h; int r = -1; if (acquire_mutex (&signals_mutex) == -1) return -1; h = info; if (h == NULL || h < signals || h > &signals [NUM_SIGNALS]) errno = EINVAL; else { /* last UnixSignal -- we can unregister */ if (h->have_handler && count_handlers (h->signum) == 1) { mph_sighandler_t p = signal (h->signum, h->handler); if (p != SIG_ERR) r = 0; h->handler = NULL; h->have_handler = 0; } h->signum = 0; } release_mutex (&signals_mutex); return r; }
// A UnixSignal object is being Disposed int Mono_Unix_UnixSignal_uninstall (void* info) { #if defined(HAVE_SIGNAL) signal_info* h; int r = -1; if (acquire_mutex (&signals_mutex) == -1) return -1; h = info; if (h == NULL || h < signals || h > &signals [NUM_SIGNALS]) errno = EINVAL; else { /* last UnixSignal -- we can unregister */ int signum = mph_int_get (&h->signum); if (h->have_handler && count_handlers (signum) == 1) { mph_sighandler_t p = signal (signum, h->handler); if (p != SIG_ERR) r = 0; h->handler = NULL; h->have_handler = 0; } mph_int_set (&h->signum, 0); } release_mutex (&signals_mutex); return r; #else g_error ("signal() is not supported by this platform"); return 0; #endif }
static gboolean publish_session_bus (const char *address) { HANDLE init_mutex; init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX); published_daemon_mutex = CreateMutexA (NULL, FALSE, DBUS_DAEMON_MUTEX); if (WaitForSingleObject (published_daemon_mutex, 10 ) != WAIT_OBJECT_0) { release_mutex (init_mutex); CloseHandle (published_daemon_mutex); published_daemon_mutex = NULL; return FALSE; } published_shared_mem = set_shm (DBUS_DAEMON_ADDRESS_INFO, address); if (!published_shared_mem) { release_mutex (init_mutex); CloseHandle (published_daemon_mutex); published_daemon_mutex = NULL; return FALSE; } release_mutex (init_mutex); return TRUE; }
disp_path_handle dpmgr_create_path(DDP_SCENARIO_ENUM scenario, cmdqRecHandle cmdq_handle) { int i =0; int module_name ; ddp_path_handle path_handle = NULL; int * modules = ddp_get_scenario_list(scenario); int module_num = ddp_get_module_num(scenario); DDP_MANAGER_CONTEXT * content = _get_context(); path_handle = kzalloc(sizeof(uint8_t*) * sizeof(ddp_path_handle_t), GFP_KERNEL); if (NULL != path_handle) { path_handle->cmdqhandle = cmdq_handle; path_handle->scenario = scenario; path_handle->hwmutexid = acquire_mutex(scenario); assign_default_irqs_table(scenario,path_handle->irq_event_map); DISP_LOG_I("create handle 0x%x on scenario %s\n",path_handle,ddp_get_scenario_name(scenario)); for( i=0; i< module_num;i++) { module_name = modules[i]; DISP_LOG_I(" scenario %s include module %s\n",ddp_get_scenario_name(scenario),ddp_get_module_name(module_name)); content->module_usage_table[module_name]++; content->module_path_table[module_name] = path_handle; } content->handle_cnt ++; content->handle_pool[path_handle->hwmutexid] = path_handle; } else { DISP_LOG_E("Fail to create handle on scenario %s\n",ddp_get_scenario_name(scenario)); } return path_handle; }
static void unpublish_session_bus (void) { HANDLE init_mutex; init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX); CloseHandle (published_shared_mem); published_shared_mem = NULL; release_mutex (published_daemon_mutex); published_daemon_mutex = NULL; release_mutex (init_mutex); }
void* Mono_Unix_UnixSignal_install (int sig) { int i; signal_info* h = NULL; int have_handler = 0; void* handler = NULL; if (acquire_mutex (&signals_mutex) == -1) return NULL; #if defined (SIGRTMIN) && defined (SIGRTMAX) /*The runtime uses some rt signals for itself so it's important to not override them.*/ if (sig >= SIGRTMIN && sig <= SIGRTMAX && count_handlers (sig) == 0) { struct sigaction sinfo; sigaction (sig, NULL, &sinfo); if (sinfo.sa_handler != SIG_DFL || (void*)sinfo.sa_sigaction != (void*)SIG_DFL) { pthread_mutex_unlock (&signals_mutex); errno = EADDRINUSE; return NULL; } } #endif /*defined (SIGRTMIN) && defined (SIGRTMAX)*/ for (i = 0; i < NUM_SIGNALS; ++i) { if (h == NULL && signals [i].signum == 0) { h = &signals [i]; h->handler = signal (sig, default_handler); if (h->handler == SIG_ERR) { h->handler = NULL; h = NULL; break; } else { h->have_handler = 1; } } if (!have_handler && signals [i].signum == sig && signals [i].handler != default_handler) { have_handler = 1; handler = signals [i].handler; } if (h && have_handler) break; } if (h && have_handler) { h->have_handler = 1; h->handler = handler; } if (h) { mph_int_set (&h->count, h->count, 0); mph_int_set (&h->signum, h->signum, sig); mph_int_set (&h->pipecnt, h->pipecnt, 0); } release_mutex (&signals_mutex); return h; }
// A UnixSignal object is being constructed void* Mono_Unix_UnixSignal_install (int sig) { #if defined(HAVE_SIGNAL) int i; signal_info* h = NULL; // signals[] slot to install to int have_handler = 0; // Candidates for signal_info handler fields void* handler = NULL; if (acquire_mutex (&signals_mutex) == -1) return NULL; #if defined (SIGRTMIN) && defined (SIGRTMAX) /*The runtime uses some rt signals for itself so it's important to not override them.*/ if (sig >= SIGRTMIN && sig <= SIGRTMAX && count_handlers (sig) == 0) { struct sigaction sinfo; sigaction (sig, NULL, &sinfo); if (sinfo.sa_handler != SIG_DFL || (void*)sinfo.sa_sigaction != (void*)SIG_DFL) { pthread_mutex_unlock (&signals_mutex); errno = EADDRINUSE; return NULL; // This is an rt signal with an existing handler. Bail out. } } #endif /*defined (SIGRTMIN) && defined (SIGRTMAX)*/ // Scan through signals list looking for (1) an unused spot (2) a usable value for handler for (i = 0; i < NUM_SIGNALS; ++i) { int just_installed = 0; // We're still looking for a signal_info spot, and this one is available: if (h == NULL && mph_int_get (&signals [i].signum) == 0) { h = &signals [i]; h->handler = signal (sig, default_handler); if (h->handler == SIG_ERR) { h->handler = NULL; h = NULL; break; } else { just_installed = 1; } } // Check if this slot has a "usable" (not installed by this file) handler-to-restore-later: // (On the first signal to be installed, signals [i] will be == h when this happens.) if (!have_handler && (just_installed || mph_int_get (&signals [i].signum) == sig) && signals [i].handler != default_handler) { have_handler = 1; handler = signals [i].handler; } if (h && have_handler) // We have everything we need break; } if (h) { // If we reached here without have_handler, this means that default_handler // was set as the signal handler before the first UnixSignal object was installed. g_assert (have_handler); // Overwrite the tenative handler we set a moment ago with a known-usable one h->handler = handler; h->have_handler = 1; mph_int_set (&h->count, 0); mph_int_set (&h->pipecnt, 0); mph_int_set (&h->signum, sig); } release_mutex (&signals_mutex); return h; #else g_error ("signal() is not supported by this platform"); return 0; #endif }
static gchar * get_session_address_dbus_launch (GError **error) { HANDLE autolaunch_mutex, init_mutex; char *address = NULL; wchar_t gio_path[MAX_PATH+1+200]; autolaunch_mutex = acquire_mutex (DBUS_AUTOLAUNCH_MUTEX); init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX); if (is_mutex_owned (DBUS_DAEMON_MUTEX)) address = read_shm (DBUS_DAEMON_ADDRESS_INFO); release_mutex (init_mutex); if (address == NULL) { gio_path[MAX_PATH] = 0; if (GetModuleFileNameW (_g_io_win32_get_module (), gio_path, MAX_PATH)) { PROCESS_INFORMATION pi = { 0 }; STARTUPINFOW si = { 0 }; BOOL res; wchar_t gio_path_short[MAX_PATH]; wchar_t rundll_path[MAX_PATH*2]; wchar_t args[MAX_PATH*4]; GetShortPathNameW (gio_path, gio_path_short, MAX_PATH); GetWindowsDirectoryW (rundll_path, MAX_PATH); wcscat (rundll_path, L"\\rundll32.exe"); if (GetFileAttributesW (rundll_path) == INVALID_FILE_ATTRIBUTES) { GetSystemDirectoryW (rundll_path, MAX_PATH); wcscat (rundll_path, L"\\rundll32.exe"); } wcscpy (args, L"\""); wcscat (args, rundll_path); wcscat (args, L"\" "); wcscat (args, gio_path_short); #if defined(_WIN64) || defined(_M_X64) || defined(_M_AMD64) wcscat (args, L",g_win32_run_session_bus"); #elif defined (_MSC_VER) wcscat (args, L",_g_win32_run_session_bus@16"); #else wcscat (args, L",g_win32_run_session_bus@16"); #endif res = CreateProcessW (rundll_path, args, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW | DETACHED_PROCESS, 0, NULL /* TODO: Should be root */, &si, &pi); if (res) address = read_shm (DBUS_DAEMON_ADDRESS_INFO); } } release_mutex (autolaunch_mutex); if (address == NULL) g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Session dbus not running, and autolaunch failed")); return address; }