OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * NaCl service run-time, non-platform specific system call helper routines. | 8 * NaCl service run-time, non-platform specific system call helper routines. |
9 */ | 9 */ |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #if NACL_WINDOWS | |
15 #include <windows.h> | |
16 #endif | |
14 | 17 |
15 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 18 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
16 | 19 |
17 #include "native_client/src/include/nacl_assert.h" | 20 #include "native_client/src/include/nacl_assert.h" |
18 #include "native_client/src/include/nacl_macros.h" | 21 #include "native_client/src/include/nacl_macros.h" |
19 #include "native_client/src/include/nacl_platform.h" | 22 #include "native_client/src/include/nacl_platform.h" |
20 #include "native_client/src/include/portability_process.h" | 23 #include "native_client/src/include/portability_process.h" |
21 #include "native_client/src/include/portability_string.h" | 24 #include "native_client/src/include/portability_string.h" |
22 | 25 |
23 #include "native_client/src/shared/platform/nacl_check.h" | 26 #include "native_client/src/shared/platform/nacl_check.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
40 #include "native_client/src/trusted/desc/nacl_desc_semaphore.h" | 43 #include "native_client/src/trusted/desc/nacl_desc_semaphore.h" |
41 #include "native_client/src/trusted/desc/nrd_xfer.h" | 44 #include "native_client/src/trusted/desc/nrd_xfer.h" |
42 | 45 |
43 #include "native_client/src/trusted/fault_injection/fault_injection.h" | 46 #include "native_client/src/trusted/fault_injection/fault_injection.h" |
44 | 47 |
45 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" | 48 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" |
46 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h " | 49 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h " |
47 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 50 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
48 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 51 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
49 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | 52 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
53 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" | |
50 | 54 |
51 #include "native_client/src/trusted/service_runtime/include/sys/nacl_test_crash. h" | 55 #include "native_client/src/trusted/service_runtime/include/sys/nacl_test_crash. h" |
52 #include "native_client/src/trusted/service_runtime/internal_errno.h" | 56 #include "native_client/src/trusted/service_runtime/internal_errno.h" |
53 | 57 |
54 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 58 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
55 #include "native_client/src/trusted/service_runtime/nacl_copy.h" | 59 #include "native_client/src/trusted/service_runtime/nacl_copy.h" |
56 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 60 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
57 #include "native_client/src/trusted/service_runtime/nacl_signal.h" | 61 #include "native_client/src/trusted/service_runtime/nacl_signal.h" |
58 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h" | 62 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h" |
59 #include "native_client/src/trusted/service_runtime/nacl_text.h" | 63 #include "native_client/src/trusted/service_runtime/nacl_text.h" |
(...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3412 return retval; | 3416 return retval; |
3413 } | 3417 } |
3414 | 3418 |
3415 int32_t NaClSysSchedYield(struct NaClAppThread *natp) { | 3419 int32_t NaClSysSchedYield(struct NaClAppThread *natp) { |
3416 UNREFERENCED_PARAMETER(natp); | 3420 UNREFERENCED_PARAMETER(natp); |
3417 | 3421 |
3418 NaClThreadYield(); | 3422 NaClThreadYield(); |
3419 return 0; | 3423 return 0; |
3420 } | 3424 } |
3421 | 3425 |
3426 int32_t NaClSysSysconf(struct NaClAppThread *natp, | |
3427 int32_t name, | |
3428 int32_t *result) { | |
3429 struct NaClApp *nap = natp->nap; | |
3430 int32_t retval = -NACL_ABI_EINVAL; | |
3431 int32_t result_value; | |
3432 | |
3433 NaClLog(3, | |
3434 ("Entered NaClSysSysconf(%08"NACL_PRIxPTR | |
3435 "x, %d, 0x%08"NACL_PRIxPTR")\n"), | |
3436 (uintptr_t) natp, name, (uintptr_t) result); | |
3437 | |
3438 switch (name) { | |
3439 case NACL_ABI__SC_NPROCESSORS_ONLN: { | |
3440 #if NACL_WINDOWS | |
3441 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,
| |
3442 NaClXMutexLock(&nap->mu); | |
3443 if (0 == nap->sc_nprocessors_onln) { | |
3444 SYSTEM_INFO si; | |
3445 GetSystemInfo(&si); | |
3446 nap->sc_nprocessors_onln = (int32_t) si.dwNumberOfProcessors; | |
3447 } | |
3448 NaClXMutexUnlock(&nap->mu); | |
3449 } | |
3450 #elif NACL_LINUX || NACL_OSX | |
3451 if (-1 == nap->sc_nprocessors_onln) { | |
3452 /* Unable to get the number of processors at startup. */ | |
3453 goto cleanup; | |
3454 } | |
3455 #else | |
3456 #error Unsupported platform | |
3457 #endif | |
3458 result_value = nap->sc_nprocessors_onln; | |
3459 break; | |
3460 } | |
3461 case NACL_ABI__SC_SENDMSG_MAX_SIZE: { | |
3462 /* TODO(sehr,bsy): this value needs to be determined at run time. */ | |
3463 const int32_t kImcSendMsgMaxSize = 1 << 16; | |
3464 result_value = kImcSendMsgMaxSize; | |
3465 break; | |
3466 } | |
3467 case NACL_ABI__SC_PAGESIZE: { | |
3468 result_value = 1 << 16; /* always 64k pages */ | |
3469 break; | |
3470 } | |
3471 default: { | |
3472 retval = -NACL_ABI_EINVAL; | |
3473 goto cleanup; | |
3474 } | |
3475 } | |
3476 if (!NaClCopyOutToUser(nap, (uintptr_t) result, &result_value, | |
3477 sizeof result_value)) { | |
3478 retval = -NACL_ABI_EFAULT; | |
3479 goto cleanup; | |
3480 } | |
3481 retval = 0; | |
3482 cleanup: | |
3483 return retval; | |
3484 } | |
3485 | |
3422 int32_t NaClSysExceptionHandler(struct NaClAppThread *natp, | 3486 int32_t NaClSysExceptionHandler(struct NaClAppThread *natp, |
3423 uint32_t handler_addr, | 3487 uint32_t handler_addr, |
3424 uint32_t old_handler) { | 3488 uint32_t old_handler) { |
3425 struct NaClApp *nap = natp->nap; | 3489 struct NaClApp *nap = natp->nap; |
3426 int32_t rv = -NACL_ABI_EINVAL; | 3490 int32_t rv = -NACL_ABI_EINVAL; |
3427 | 3491 |
3428 if (!nap->enable_exception_handling) { | 3492 if (!nap->enable_exception_handling) { |
3429 rv = -NACL_ABI_ENOSYS; | 3493 rv = -NACL_ABI_ENOSYS; |
3430 goto no_lock_exit; | 3494 goto no_lock_exit; |
3431 } | 3495 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3712 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, | 3776 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, |
3713 NaClClockGetRes); | 3777 NaClClockGetRes); |
3714 } | 3778 } |
3715 | 3779 |
3716 int32_t NaClSysClockGetTime(struct NaClAppThread *natp, | 3780 int32_t NaClSysClockGetTime(struct NaClAppThread *natp, |
3717 int clk_id, | 3781 int clk_id, |
3718 uint32_t tsp) { | 3782 uint32_t tsp) { |
3719 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, | 3783 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, |
3720 NaClClockGetTime); | 3784 NaClClockGetTime); |
3721 } | 3785 } |
OLD | NEW |