Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1662)

Unified Diff: src/trusted/service_runtime/arch/mips/nacl_tls.c

Issue 10919162: [MIPS] Implementation of sel_ldr for MIPS architecture. (Closed) Base URL: http://src.chromium.org/native_client/trunk/src/native_client/
Patch Set: Rebase (Saturday morning). Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/trusted/service_runtime/arch/mips/nacl_tls.c
diff --git a/src/trusted/service_runtime/arch/arm/nacl_tls.c b/src/trusted/service_runtime/arch/mips/nacl_tls.c
similarity index 80%
copy from src/trusted/service_runtime/arch/arm/nacl_tls.c
copy to src/trusted/service_runtime/arch/mips/nacl_tls.c
index 0475806eb2a312f5f37ef7b643e3f90ef7c7a3a1..f10206ce37f4928f35d835dd8c642b3246722337 100644
--- a/src/trusted/service_runtime/arch/arm/nacl_tls.c
+++ b/src/trusted/service_runtime/arch/mips/nacl_tls.c
@@ -9,7 +9,7 @@
#include "native_client/src/include/portability.h"
#include "native_client/src/shared/platform/nacl_check.h"
#include "native_client/src/shared/platform/nacl_sync_checked.h"
-#include "native_client/src/trusted/service_runtime/arch/arm/sel_ldr_arm.h"
+#include "native_client/src/trusted/service_runtime/arch/mips/sel_ldr_mips.h"
#include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
#include "native_client/src/trusted/service_runtime/nacl_globals.h"
#include "native_client/src/trusted/service_runtime/nacl_tls.h"
@@ -18,7 +18,6 @@
static struct NaClMutex gNaClTlsMu;
static int gNaClThreadIdxInUse[NACL_THREAD_MAX]; /* bool */
-static size_t const kNumThreads = NACL_ARRAY_SIZE_UNSAFE(gNaClThreadIdxInUse);
/*
* This holds the index of the current thread.
@@ -44,7 +43,7 @@ int NaClTlsInit() {
NaClLog(2, "NaClTlsInit\n");
- for (i = 0; i < kNumThreads; i++) {
+ for (i = 0; i < NACL_ARRAY_SIZE(gNaClThreadIdxInUse); i++) {
gNaClThreadIdxInUse[i] = 0;
}
if (!NaClMutexCtor(&gNaClTlsMu)) {
@@ -62,11 +61,12 @@ void NaClTlsFini() {
NaClMutexDtor(&gNaClTlsMu);
}
+
static int NaClThreadIdxAllocate() {
- size_t i;
+ int i;
NaClXMutexLock(&gNaClTlsMu);
- for (i = 1; i < kNumThreads; i++) {
+ for (i = 0; i < NACL_THREAD_MAX; i++) {
if (!gNaClThreadIdxInUse[i]) {
gNaClThreadIdxInUse[i] = 1;
break;
@@ -74,12 +74,12 @@ static int NaClThreadIdxAllocate() {
}
NaClXMutexUnlock(&gNaClTlsMu);
- if (kNumThreads != i) {
+ if (NACL_THREAD_MAX != i) {
return i;
}
NaClLog(LOG_ERROR, "NaClThreadIdxAllocate: no more slots for a thread\n");
- return NACL_TLS_INDEX_INVALID;
+ return -1;
}
@@ -91,11 +91,18 @@ uint32_t NaClTlsAllocate(struct NaClAppThread *natp) {
int idx = NaClThreadIdxAllocate();
NaClLog(2, "NaClTlsAllocate: $tp %x idx %d\n", natp->tls_values.tls1, idx);
- if (NACL_TLS_INDEX_INVALID != idx) {
- natp->user.r9 = natp->tls_values.tls1;
+ if (-1 == idx) {
+ NaClLog(LOG_FATAL,
+ "NaClTlsAllocate: thread limit reached\n");
+ return NACL_TLS_INDEX_INVALID;
}
- return idx;
+ natp->user.t8 = natp->tls_values.tls1;
+
+ /*
+ * Bias by 1: successful return value is never 0.
+ */
+ return idx + 1;
}
@@ -103,18 +110,18 @@ void NaClTlsFree(struct NaClAppThread *natp) {
uint32_t idx = NaClGetThreadIdx(natp);
NaClLog(2,
"NaClTlsFree: old idx %d $tp %x\n",
- idx, natp->user.r9);
+ idx, natp->user.t8);
NaClXMutexLock(&gNaClTlsMu);
- gNaClThreadIdxInUse[idx] = 0;
+ gNaClThreadIdxInUse[idx - 1] = 0;
NaClXMutexUnlock(&gNaClTlsMu);
- natp->user.r9 = 0;
+ natp->user.t8 = 0;
}
void NaClTlsChange(struct NaClAppThread *natp) {
NaClLog(2, "NaClTlsChange: $tp %x\n", natp->tls_values.tls1);
- natp->user.r9 = natp->tls_values.tls1;
+ natp->user.t8 = natp->tls_values.tls1;
}
« no previous file with comments | « src/trusted/service_runtime/arch/mips/nacl_text_pad_test.S ('k') | src/trusted/service_runtime/arch/mips/sel_addrspace_mips.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698