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 static int32_t number_of_workers = 0; |
| 3442 if (0 == number_of_workers) { |
| 3443 SYSTEM_INFO si; |
| 3444 GetSystemInfo(&si); |
| 3445 number_of_workers = (int32_t) si.dwNumberOfProcessors; |
| 3446 } |
| 3447 result_value = number_of_workers; |
| 3448 #elif NACL_LINUX || NACL_OSX |
| 3449 if (-1 == nap->sc_nprocessors_onln) { |
| 3450 /* Unable to get the number of processors at startup. */ |
| 3451 goto cleanup; |
| 3452 } |
| 3453 result_value = nap->sc_nprocessors_onln; |
| 3454 #else |
| 3455 #error Unsupported platform |
| 3456 #endif |
| 3457 break; |
| 3458 } |
| 3459 case NACL_ABI__SC_SENDMSG_MAX_SIZE: { |
| 3460 /* TODO(sehr,bsy): this value needs to be determined at run time. */ |
| 3461 const int32_t kImcSendMsgMaxSize = 1 << 16; |
| 3462 result_value = kImcSendMsgMaxSize; |
| 3463 break; |
| 3464 } |
| 3465 case NACL_ABI__SC_PAGESIZE: { |
| 3466 result_value = 1 << 16; /* always 64k pages */ |
| 3467 break; |
| 3468 } |
| 3469 default: { |
| 3470 retval = -NACL_ABI_EINVAL; |
| 3471 goto cleanup; |
| 3472 } |
| 3473 } |
| 3474 if (!NaClCopyOutToUser(nap, (uintptr_t) result, &result_value, |
| 3475 sizeof result_value)) { |
| 3476 retval = -NACL_ABI_EFAULT; |
| 3477 goto cleanup; |
| 3478 } |
| 3479 retval = 0; |
| 3480 cleanup: |
| 3481 return retval; |
| 3482 } |
| 3483 |
3422 int32_t NaClSysExceptionHandler(struct NaClAppThread *natp, | 3484 int32_t NaClSysExceptionHandler(struct NaClAppThread *natp, |
3423 uint32_t handler_addr, | 3485 uint32_t handler_addr, |
3424 uint32_t old_handler) { | 3486 uint32_t old_handler) { |
3425 struct NaClApp *nap = natp->nap; | 3487 struct NaClApp *nap = natp->nap; |
3426 int32_t rv = -NACL_ABI_EINVAL; | 3488 int32_t rv = -NACL_ABI_EINVAL; |
3427 | 3489 |
3428 if (!nap->enable_exception_handling) { | 3490 if (!nap->enable_exception_handling) { |
3429 rv = -NACL_ABI_ENOSYS; | 3491 rv = -NACL_ABI_ENOSYS; |
3430 goto no_lock_exit; | 3492 goto no_lock_exit; |
3431 } | 3493 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3712 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, | 3774 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, |
3713 NaClClockGetRes); | 3775 NaClClockGetRes); |
3714 } | 3776 } |
3715 | 3777 |
3716 int32_t NaClSysClockGetTime(struct NaClAppThread *natp, | 3778 int32_t NaClSysClockGetTime(struct NaClAppThread *natp, |
3717 int clk_id, | 3779 int clk_id, |
3718 uint32_t tsp) { | 3780 uint32_t tsp) { |
3719 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, | 3781 return NaClSysClockGetCommon(natp, clk_id, (uintptr_t) tsp, |
3720 NaClClockGetTime); | 3782 NaClClockGetTime); |
3721 } | 3783 } |
OLD | NEW |