Skip to content

Commit

Permalink
Avoid exposing variable in DLL interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Thursfield committed Jul 6, 2011
1 parent 0ef96c0 commit 169b5b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/msrpc-mingw.c
Expand Up @@ -138,13 +138,13 @@ void rpc_log_error_with_status (DWORD status,

static LONG WINAPI exception_handler (LPEXCEPTION_POINTERS exception_pointers);

DWORD __rpc_exception_handler_tls_index;
static DWORD exception_handler_tls_index;
static int exception_handler_enable_global;

static LPTOP_LEVEL_EXCEPTION_FILTER super_exception_handler;

static void exception_handler_init () {
__rpc_exception_handler_tls_index = TlsAlloc ();
exception_handler_tls_index = TlsAlloc ();
exception_handler_enable_global = TRUE;
super_exception_handler = SetUnhandledExceptionFilter (exception_handler);
}
Expand All @@ -154,15 +154,19 @@ void rpc_set_global_exception_handler_enable (int enable) {
exception_handler_enable_global = enable;
}

void _rpc_set_thread_exception_closure (struct _RpcExceptionClosure *closure) {
TlsSetValue (exception_handler_tls_index, closure);
}

static LONG WINAPI exception_handler (LPEXCEPTION_POINTERS exception_pointers) {
struct RpcExceptionClosure *closure;
struct _RpcExceptionClosure *closure;
LPEXCEPTION_RECORD exception;
DWORD status;

exception = exception_pointers->ExceptionRecord;
status = exception->ExceptionCode;

closure = TlsGetValue (__rpc_exception_handler_tls_index);
closure = TlsGetValue (exception_handler_tls_index);

if (closure != NULL) {
/* Local exception handler - jump back into the action */
Expand Down
12 changes: 6 additions & 6 deletions src/msrpc-mingw.h
Expand Up @@ -100,23 +100,23 @@ void rpc_set_global_exception_handler_enable (int enable);
* http://www.opensource.apple.com/source/tcl/tcl-87/tk/tk/win/tkWin32Dll.c
*/

struct RpcExceptionClosure {
struct _RpcExceptionClosure {
jmp_buf return_location;
DWORD status;
};

extern DWORD __rpc_exception_handler_tls_index;
void _rpc_set_thread_exception_closure (struct _RpcExceptionClosure *closure);

#define RPC_TRY_EXCEPT { \
struct RpcExceptionClosure *__rpc_exception_closure; \
__rpc_exception_closure = malloc (sizeof (struct RpcExceptionClosure)); \
struct _RpcExceptionClosure *__rpc_exception_closure; \
__rpc_exception_closure = malloc (sizeof (struct _RpcExceptionClosure)); \
if (setjmp (__rpc_exception_closure->return_location) == 0) { \
TlsSetValue (__rpc_exception_handler_tls_index, __rpc_exception_closure);
_rpc_set_thread_exception_closure (__rpc_exception_closure);

#define RPC_EXCEPT } else

#define RPC_END_EXCEPT \
TlsSetValue (__rpc_exception_handler_tls_index, NULL); \
_rpc_set_thread_exception_closure (NULL); \
free (__rpc_exception_closure); \
}

Expand Down

0 comments on commit 169b5b6

Please sign in to comment.