Index: src/trusted/service_runtime/nacl_syscall_common.c |
diff --git a/src/trusted/service_runtime/nacl_syscall_common.c b/src/trusted/service_runtime/nacl_syscall_common.c |
index ec0998041640179738151bd15c12dde85dc6a7bd..2e1acf6f84e435421378b9fd4089f034406be041 100644 |
--- a/src/trusted/service_runtime/nacl_syscall_common.c |
+++ b/src/trusted/service_runtime/nacl_syscall_common.c |
@@ -11,6 +11,9 @@ |
#include <sys/stat.h> |
#include <stdio.h> |
+#if NACL_WINDOWS |
+#include <windows.h> |
+#endif |
#include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
@@ -47,6 +50,7 @@ |
#include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
#include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
#include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
+#include "native_client/src/trusted/service_runtime/include/sys/unistd.h" |
#include "native_client/src/trusted/service_runtime/include/sys/nacl_test_crash.h" |
#include "native_client/src/trusted/service_runtime/internal_errno.h" |
@@ -3419,6 +3423,66 @@ int32_t NaClSysSchedYield(struct NaClAppThread *natp) { |
return 0; |
} |
+int32_t NaClSysSysconf(struct NaClAppThread *natp, |
+ int32_t name, |
+ int32_t *result) { |
+ struct NaClApp *nap = natp->nap; |
+ int32_t retval = -NACL_ABI_EINVAL; |
+ int32_t result_value; |
+ |
+ NaClLog(3, |
+ ("Entered NaClSysSysconf(%08"NACL_PRIxPTR |
+ "x, %d, 0x%08"NACL_PRIxPTR")\n"), |
+ (uintptr_t) natp, name, (uintptr_t) result); |
+ |
+ switch (name) { |
+ case NACL_ABI__SC_NPROCESSORS_ONLN: { |
+#if NACL_WINDOWS |
+ if (0 == nap->sc_nprocessors_onln) { |
Mark Seaborn
2013/09/09 21:39:38
Double-checking a field like this will still be re
Petr Hosek
2013/09/09 21:46:54
Because the original implementation does the some,
|
+ NaClXMutexLock(&nap->mu); |
+ if (0 == nap->sc_nprocessors_onln) { |
+ SYSTEM_INFO si; |
+ GetSystemInfo(&si); |
+ nap->sc_nprocessors_onln = (int32_t) si.dwNumberOfProcessors; |
+ } |
+ NaClXMutexUnlock(&nap->mu); |
+ } |
+#elif NACL_LINUX || NACL_OSX |
+ if (-1 == nap->sc_nprocessors_onln) { |
+ /* Unable to get the number of processors at startup. */ |
+ goto cleanup; |
+ } |
+#else |
+#error Unsupported platform |
+#endif |
+ result_value = nap->sc_nprocessors_onln; |
+ break; |
+ } |
+ case NACL_ABI__SC_SENDMSG_MAX_SIZE: { |
+ /* TODO(sehr,bsy): this value needs to be determined at run time. */ |
+ const int32_t kImcSendMsgMaxSize = 1 << 16; |
+ result_value = kImcSendMsgMaxSize; |
+ break; |
+ } |
+ case NACL_ABI__SC_PAGESIZE: { |
+ result_value = 1 << 16; /* always 64k pages */ |
+ break; |
+ } |
+ default: { |
+ retval = -NACL_ABI_EINVAL; |
+ goto cleanup; |
+ } |
+ } |
+ if (!NaClCopyOutToUser(nap, (uintptr_t) result, &result_value, |
+ sizeof result_value)) { |
+ retval = -NACL_ABI_EFAULT; |
+ goto cleanup; |
+ } |
+ retval = 0; |
+cleanup: |
+ return retval; |
+} |
+ |
int32_t NaClSysExceptionHandler(struct NaClAppThread *natp, |
uint32_t handler_addr, |
uint32_t old_handler) { |