From e8c80f67856e7fd94f64574d10b5637fef5af1f6 Mon Sep 17 00:00:00 2001 From: Cyrus Harmon Date: Mon, 7 Mar 2011 23:41:24 +0000 Subject: [PATCH] 1.0.46.26: mach-exception-handler improvement: current_mach_task * define current_mach_task variable, squirrel away the value of mach_task_self there and use that instead of calling mach_task_self so that we don't leak send rights all over the place --- src/runtime/darwin-os.c | 11 +++++++---- src/runtime/darwin-os.h | 4 ++++ src/runtime/thread.c | 6 +++--- version.lisp-expr | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/runtime/darwin-os.c b/src/runtime/darwin-os.c index 63fc6e6..f15e11b 100644 --- a/src/runtime/darwin-os.c +++ b/src/runtime/darwin-os.c @@ -67,6 +67,7 @@ mach_exception_handler(void *port) signal handlers run in the relevant thread directly. */ mach_port_t mach_exception_handler_port_set = MACH_PORT_NULL; +mach_port_t current_mach_task = MACH_PORT_NULL; pthread_t setup_mach_exception_handling_thread() @@ -75,8 +76,10 @@ setup_mach_exception_handling_thread() pthread_t mach_exception_handling_thread = NULL; pthread_attr_t attr; + current_mach_task = mach_task_self(); + /* allocate a mach_port for this process */ - ret = mach_port_allocate(mach_task_self(), + ret = mach_port_allocate(current_mach_task, MACH_PORT_RIGHT_PORT_SET, &mach_exception_handler_port_set); @@ -105,7 +108,7 @@ mach_thread_init(mach_port_t thread_exception_port) FSHOW((stderr, "Allocating mach port %x\n", thread_exception_port)); - ret = mach_port_allocate_name(mach_task_self(), + ret = mach_port_allocate_name(current_mach_task, MACH_PORT_RIGHT_RECEIVE, thread_exception_port); if (ret) { @@ -113,7 +116,7 @@ mach_thread_init(mach_port_t thread_exception_port) } /* establish the right for the thread_exception_port to send messages */ - ret = mach_port_insert_right(mach_task_self(), + ret = mach_port_insert_right(current_mach_task, thread_exception_port, thread_exception_port, MACH_MSG_TYPE_MAKE_SEND); @@ -130,7 +133,7 @@ mach_thread_init(mach_port_t thread_exception_port) lose("thread_set_exception_port failed with return_code %d\n", ret); } - ret = mach_port_move_member(mach_task_self(), + ret = mach_port_move_member(current_mach_task, thread_exception_port, mach_exception_handler_port_set); if (ret) { diff --git a/src/runtime/darwin-os.h b/src/runtime/darwin-os.h index 9228d1b..be8640d 100644 --- a/src/runtime/darwin-os.h +++ b/src/runtime/darwin-os.h @@ -34,4 +34,8 @@ typedef ucontext_t os_context_t; #define SIG_STOP_FOR_GC (SIGUSR2) +#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER +extern mach_port_t current_mach_task; +#endif + #endif /* _DARWIN_OS_H */ diff --git a/src/runtime/thread.c b/src/runtime/thread.c index 535263a..ee11e0f 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -318,12 +318,12 @@ new_thread_trampoline(struct thread *th) #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER FSHOW((stderr, "Deallocating mach port %x\n", THREAD_STRUCT_TO_EXCEPTION_PORT(th))); - mach_port_move_member(mach_task_self(), + mach_port_move_member(current_mach_task, THREAD_STRUCT_TO_EXCEPTION_PORT(th), MACH_PORT_NULL); - mach_port_deallocate(mach_task_self(), + mach_port_deallocate(current_mach_task, THREAD_STRUCT_TO_EXCEPTION_PORT(th)); - mach_port_destroy(mach_task_self(), + mach_port_destroy(current_mach_task, THREAD_STRUCT_TO_EXCEPTION_PORT(th)); #endif diff --git a/version.lisp-expr b/version.lisp-expr index ab530cc..2126bc0 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -20,4 +20,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.46.25" +"1.0.46.26" -- 1.7.10.4