Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 57372 invoked from network); 16 Sep 2009 18:49:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Sep 2009 18:49:27 -0000 Received: (qmail 55665 invoked by uid 500); 16 Sep 2009 18:49:26 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 55570 invoked by uid 500); 16 Sep 2009 18:49:26 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 55561 invoked by uid 99); 16 Sep 2009 18:49:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Sep 2009 18:49:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Sep 2009 18:49:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 47BA623888D6; Wed, 16 Sep 2009 18:49:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r815925 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_signals.h include/arch/unix/acr_arch.h include/arch/windows/acr_arch_private.h os/win32/main.c os/win32/signals.c os/win32/wusec.c Date: Wed, 16 Sep 2009 18:49:04 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090916184904.47BA623888D6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed Sep 16 18:49:03 2009 New Revision: 815925 URL: http://svn.apache.org/viewvc?rev=815925&view=rev Log: Clear as much as possible on exit Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h Wed Sep 16 18:49:03 2009 @@ -32,12 +32,6 @@ */ /** - * ACR-private function for initializing the signal package - * @internal - */ -int acr_SignalsInit(void); - -/** * Get the description for a specific signal number * @param signum The signal number * @return The description of the signal Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Wed Sep 16 18:49:03 2009 @@ -203,6 +203,11 @@ return p; } +/* Initialize signal handling subsytem. + * ACR private used during init stage + */ +int acr_SignalsInit(void); + /** * Read the content of a txt file, up to the ACR_MAX_FREAD_LEN * and remove all trailing space and control characters. Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Wed Sep 16 18:49:03 2009 @@ -130,6 +130,7 @@ DWORD ACR_EnablePrivilege(LPCWSTR szPrivilege); PSID ACR_DuplicateSid(JNIEnv *_E, PSID sSID); int ACR_InitSecurityDescriptorTable(JNIEnv *); +int ACR_DestroySecurityDescriptorTable(void); LPVOID ACR_GetSecurityDescriptor(JNIEnv *, DWORD, DWORD, DWORD); LPVOID ACR_StdSecurityDescriptor(JNIEnv *, int, int); DWORD ACR_SetSecurityInfo(HANDLE, int, PSID, PSID, int); @@ -158,6 +159,8 @@ */ } acr_sig_msg_t; +int acr_SignalsInit(void); +int acr_SignalsCleanup(void); DWORD ACR_DeliverSignals(void); extern volatile LONG current_signal_listeners; #define ACR_SIG_WAITER_INIT() InterlockedIncrement(¤t_signal_listeners) @@ -216,7 +219,7 @@ size_t iov_len; /* Number of bytes */ }; - + #if defined(ACR_ENABLE_TEST) ACR_DECLARE(pid_t) getppid(void); #else Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Wed Sep 16 18:49:03 2009 @@ -76,6 +76,16 @@ ACR_HeapFree(t);; } +static void acr_dll_exit() +{ + /* Cleanup persistent memory + */ + acr_SignalsCleanup(); + ACR_DestroySecurityDescriptorTable(); + HeapDestroy(dll_heap_handle); + +} + BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) { ULONG heap_value = 2; /* This enables low fragmentation heap */ @@ -137,7 +147,7 @@ } TlsFree(dll_tls_index); } - HeapDestroy(dll_heap_handle); + acr_dll_exit(); dll_instance = NULL; break; default: Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c Wed Sep 16 18:49:03 2009 @@ -59,10 +59,11 @@ static SIG_PF signal_handlers[ACR_NUMSIG]; static volatile int running; -HANDLE sig_raised_event = NULL; -static HANDLE sig_handle_event = NULL; +HANDLE sig_raised_event = NULL; +static HANDLE sig_handle_event = NULL; +static HANDLE sig_handle_thread = NULL; -static HANDLE sig_pipe_handle = INVALID_HANDLE_VALUE; +static HANDLE sig_pipe_handle = INVALID_HANDLE_VALUE; static wchar_t sig_pipe_name[64]; static BYTE sig_pipe_salt[ACR_SHA1_DIGEST_LENGTH]; static DWORD proc_priority_class = NORMAL_PRIORITY_CLASS; @@ -73,6 +74,15 @@ HANDLE pipe; } sig_pipe_data_t; +static void pre_exit_cleanup() +{ + if (IS_VALID_HANDLE(sig_pipe_handle)) { + CloseHandle(sig_pipe_handle); + sig_pipe_handle = INVALID_HANDLE_VALUE; + } + sig_handle_thread = NULL; +} + static void make_security_cookie(acr_sig_msg_t *msg, const wchar_t *key, DWORD sn, DWORD to) { @@ -166,6 +176,7 @@ proc_priority_class = dw; break; case SIGABRT: + pre_exit_cleanup(); #if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Visual C++ 2005 and later */ @@ -175,6 +186,7 @@ break; case SIGTERM: case SIGKILL: + pre_exit_cleanup(); /* Call the System.exit() */ if (ACR_SystemExit(NULL, sig)) { @@ -194,6 +206,7 @@ fprintf(stderr, "[native] Fatal - %s\n", strsignal(sig)); fprintf(stderr, "[native] Terminating ...\n"); fflush(stderr); + pre_exit_cleanup(); ExitProcess(sig); } break; @@ -206,6 +219,7 @@ fprintf(stderr, "[native] Missing JNIEnv - %s\n", strsignal(sig)); fprintf(stderr, "[native] Terminating ...\n"); fflush(stderr); + pre_exit_cleanup(); ExitProcess(sig); } break; @@ -311,9 +325,9 @@ /* On Vista+ we can check the client side process id * and be sure it matches id that was send as part of the * message. - */ + */ if (ACR_HAVE_LATE_DLL_FUNC(GetNamedPipeClientProcessId)) { - ULONG cpid = 0; + ULONG cpid = 0; if (GetNamedPipeClientProcessId(pd->pipe, &cpid)) { if (cpid != pd->msg.sender) { /* Client pretends to be someone else @@ -443,6 +457,10 @@ while (running) { rc = WaitForMultipleObjectsEx(nw, wh, FALSE, INFINITE, TRUE); + if (!running) { + SetEvent(sig_raised_event); + break; + } switch (rc) { case WAIT_OBJECT_0 + 0: /* Dispatch the event to object waiters @@ -512,7 +530,6 @@ break; } } - return 0; } @@ -559,7 +576,7 @@ */ sig_handle_event = CreateEvent(NULL, FALSE, FALSE, NULL); if (IS_INVALID_HANDLE(sig_handle_event)) - return ACR_GET_OS_ERROR(); + goto cleanup; /* * Create a simple unnamed signaling event. @@ -572,7 +589,7 @@ */ sig_raised_event = CreateEvent(NULL, TRUE, FALSE, NULL); if (IS_INVALID_HANDLE(sig_raised_event)) - return ACR_GET_OS_ERROR(); + goto cleanup; for (i = 0; i < ACR_NUMSIG; i++) @@ -607,9 +624,15 @@ * unstable and will probably crash * in the near future. Anyhow, return the error. */ - return ACR_GET_OS_ERROR(); + goto cleanup; } + sig_handle_thread = h; return 0; + +cleanup: + running = 0; + return ACR_GET_OS_ERROR(); + } /* @@ -627,6 +650,9 @@ /* We are invoked from one of the waiters. * */ + + if (!running) + return ACR_INCOMPLETE; EnterCriticalSection(&signal_lock); if (ACR_SIGNAL_NWAITERS() == 0) { /* Main signal dispatching. @@ -756,3 +782,19 @@ return 0; } + +int acr_SignalsCleanup(void) +{ + if (!running) + return ACR_SUCCESS; + + running = 0; + SetEvent(sig_raised_event); + if (sig_handle_thread) { + SetEvent(sig_handle_event); + if (WaitForSingleObject(sig_handle_thread, 1000)) + return ACR_INCOMPLETE; + } + return ACR_SUCCESS; +} + Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c?rev=815925&r1=815924&r2=815925&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Wed Sep 16 18:49:03 2009 @@ -315,6 +315,28 @@ return ACR_SUCCESS; } +static int security_table_free_callback(int mode, void *opaque, + char *key, void *data, + acr_size_t dlen) +{ + if (mode && data) + LocalFree((HLOCAL)data); + return 0; + +} + +int ACR_DestroySecurityDescriptorTable() +{ + + if (!security_table) + return ACR_SUCCESS; + ACR_TableForEach(security_table, 1, NULL, security_table_free_callback); + ACR_TableFree(INVALID_MEMORY_VALUE, THROW_NMARK, security_table); + security_table = NULL; + + return ACR_SUCCESS; +} + static struct { int type; SE_OBJECT_TYPE krnl; @@ -584,7 +606,7 @@ _null_sa->nLength = sizeof(SECURITY_ATTRIBUTES); _null_sa->lpSecurityDescriptor = NULL; _null_sa->bInheritHandle = FALSE; - - SetLastError(rc); + + SetLastError(rc); return _null_sa; }