Index: src/trusted/service_runtime/osx/mach_thread_map.c |
=================================================================== |
--- src/trusted/service_runtime/osx/mach_thread_map.c (revision 0) |
+++ src/trusted/service_runtime/osx/mach_thread_map.c (revision 0) |
@@ -0,0 +1,58 @@ |
+/* |
+ * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h" |
+ |
+#include <pthread.h> |
+ |
+#include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" |
+#include "native_client/src/trusted/service_runtime/nacl_globals.h" |
+ |
+#if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 32 |
Mark Seaborn
2013/02/14 23:55:02
Again, probably better to say:
#if NACL_ARCH(NACL_
|
+ |
+static mach_port_t mach_threads[NACL_THREAD_MAX]; |
+ |
+size_t NaClGetThreadIndexForMachThread(mach_port_t mach_thread) { |
+ size_t nacl_thread_index; |
+ |
+ DCHECK(mach_thread != MACH_PORT_NULL); |
+ |
+ CHECK(NACL_TLS_INDEX_INVALID < NACL_THREAD_MAX); /* Skip the invalid slot. */ |
+ for (nacl_thread_index = NACL_TLS_INDEX_INVALID + 1; |
+ nacl_thread_index < NACL_THREAD_MAX; |
+ ++nacl_thread_index) { |
+ if (mach_threads[nacl_thread_index] == mach_thread) { |
+ break; |
+ } |
+ } |
+ |
+ return nacl_thread_index == NACL_THREAD_MAX ? NACL_TLS_INDEX_INVALID : |
+ nacl_thread_index; |
+} |
+ |
+void NaClSetCurrentMachThreadForThreadIndex(size_t nacl_thread_index) { |
+ mach_port_t mach_thread = pthread_mach_thread_np(pthread_self()); |
Mark Seaborn
2013/02/14 23:55:02
It might be worth commenting that:
We assume that
Mark Mentovai
2013/02/15 17:36:42
Mark Seaborn wrote:
Mark Seaborn
2013/02/15 22:48:08
What's this interface called?
Whether it's worth
|
+ CHECK(mach_thread != MACH_PORT_NULL); |
+ |
+ DCHECK(nacl_thread_index > NACL_TLS_INDEX_INVALID && |
+ nacl_thread_index < NACL_THREAD_MAX); |
+ DCHECK(mach_threads[nacl_thread_index] == MACH_PORT_NULL); |
+ DCHECK(NaClGetThreadIndexForMachThread(mach_thread) == |
+ NACL_TLS_INDEX_INVALID); |
+ |
+ mach_threads[nacl_thread_index] = mach_thread; |
+} |
+ |
+void NaClClearMachThreadForThreadIndex(size_t nacl_thread_index) { |
+ DCHECK(nacl_thread_index > NACL_TLS_INDEX_INVALID && |
+ nacl_thread_index < NACL_THREAD_MAX); |
+ DCHECK(mach_threads[nacl_thread_index] == |
+ pthread_mach_thread_np(pthread_self())); |
+ |
+ mach_threads[nacl_thread_index] = MACH_PORT_NULL; |
+} |
+ |
+#endif |
Property changes on: src/trusted/service_runtime/osx/mach_thread_map.c |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |