Chromium Code Reviews| 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 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H_ | 6 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H_ |
| 7 #define NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H_ | 7 #define NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H_ |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #include <time.h> | 12 #include <time.h> |
| 13 | 13 |
| 14 struct timeval; | 14 struct timeval; |
| 15 struct timespec; | 15 struct timespec; |
| 16 struct stat; | 16 struct stat; |
| 17 struct dirent; | 17 struct dirent; |
| 18 | 18 |
| 19 struct NaClExceptionContext; | 19 struct NaClExceptionContext; |
| 20 struct NaClMemMappingInfo; | 20 struct NaClMemMappingInfo; |
| 21 | 21 |
| 22 typedef int64_t nacl_irt_off_t; | 22 typedef int64_t nacl_irt_off_t; |
| 23 typedef uint32_t nacl_irt_clockid_t; | 23 typedef uint32_t nacl_irt_clockid_t; |
| 24 typedef uintptr_t nacl_irt_tid_t; | |
| 24 | 25 |
| 25 #if defined(__cplusplus) | 26 #if defined(__cplusplus) |
| 26 extern "C" { | 27 extern "C" { |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 /* | 30 /* |
| 30 * The only interface exposed directly to user code is a single function | 31 * The only interface exposed directly to user code is a single function |
| 31 * of this type. It is passed via the AT_SYSINFO field of the ELF | 32 * of this type. It is passed via the AT_SYSINFO field of the ELF |
| 32 * auxiliary vector on the stack at program startup. The interfaces | 33 * auxiliary vector on the stack at program startup. The interfaces |
| 33 * below are accessed by calling this function with the appropriate | 34 * below are accessed by calling this function with the appropriate |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 * If |stack_flag| is non-NULL, thread_exit() will write 0 to | 234 * If |stack_flag| is non-NULL, thread_exit() will write 0 to |
| 234 * |*stack_flag|. This is intended to be used by a threading | 235 * |*stack_flag|. This is intended to be used by a threading |
| 235 * library to determine when the thread's stack can be deallocated | 236 * library to determine when the thread's stack can be deallocated |
| 236 * or reused. The system will not read or write the thread's stack | 237 * or reused. The system will not read or write the thread's stack |
| 237 * after writing 0 to |*stack_flag|. | 238 * after writing 0 to |*stack_flag|. |
| 238 */ | 239 */ |
| 239 void (*thread_exit)(int32_t *stack_flag); | 240 void (*thread_exit)(int32_t *stack_flag); |
| 240 int (*thread_nice)(const int nice); | 241 int (*thread_nice)(const int nice); |
| 241 }; | 242 }; |
| 242 | 243 |
| 244 #define NACL_IRT_THREAD_v0_2 "nacl-irt-thread-0.2" | |
|
Mark Seaborn
2015/06/26 18:32:00
Please comment that this is implemented for Non-SF
Luis Héctor Chávez
2015/07/06 23:45:00
Done.
| |
| 245 struct nacl_irt_thread_v0_2 { | |
| 246 /* | |
| 247 * Now this interface returns the thread ID of the child thread as | |
|
Mark Seaborn
2015/06/26 18:31:59
Nit: It assigns it to *child_tid rather than retur
Luis Héctor Chávez
2015/07/06 23:45:00
Done.
| |
| 248 * |tid|. |tid| is valid until thread_exit is called. | |
| 249 */ | |
| 250 int (*thread_create)(void (*start_func)(void), void *stack, void *thread_ptr, | |
| 251 nacl_irt_tid_t *child_tid); | |
| 252 void (*thread_exit)(int32_t *stack_flag); | |
| 253 int (*thread_nice)(const int nice); | |
| 254 }; | |
| 255 | |
| 243 /* | 256 /* |
| 244 * The irt_futex interface is based on Linux's futex() system call. | 257 * The irt_futex interface is based on Linux's futex() system call. |
| 245 * | 258 * |
| 246 * irt_futex provides process-private futexes, so futex wait queues are | 259 * irt_futex provides process-private futexes, so futex wait queues are |
| 247 * associated with numeric virtual addresses only. This is equivalent to | 260 * associated with numeric virtual addresses only. This is equivalent to |
| 248 * Linux's FUTEX_PRIVATE_FLAG. If a page is mmap()'d twice, futex_wake() | 261 * Linux's FUTEX_PRIVATE_FLAG. If a page is mmap()'d twice, futex_wake() |
| 249 * on one mapping will *not* wake a thread that is waiting on the other | 262 * on one mapping will *not* wake a thread that is waiting on the other |
| 250 * mapping with futex_wait_abs() -- futex wait queues are not associated | 263 * mapping with futex_wait_abs() -- futex wait queues are not associated |
| 251 * with pages' identities. | 264 * with pages' identities. |
| 252 */ | 265 */ |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 #define NACL_IRT_EXCEPTION_HANDLING_v0_1 \ | 396 #define NACL_IRT_EXCEPTION_HANDLING_v0_1 \ |
| 384 "nacl-irt-exception-handling-0.1" | 397 "nacl-irt-exception-handling-0.1" |
| 385 typedef void (*NaClExceptionHandler)(struct NaClExceptionContext *context); | 398 typedef void (*NaClExceptionHandler)(struct NaClExceptionContext *context); |
| 386 struct nacl_irt_exception_handling { | 399 struct nacl_irt_exception_handling { |
| 387 int (*exception_handler)(NaClExceptionHandler handler, | 400 int (*exception_handler)(NaClExceptionHandler handler, |
| 388 NaClExceptionHandler *old_handler); | 401 NaClExceptionHandler *old_handler); |
| 389 int (*exception_stack)(void *stack, size_t size); | 402 int (*exception_stack)(void *stack, size_t size); |
| 390 int (*exception_clear_flag)(void); | 403 int (*exception_clear_flag)(void); |
| 391 }; | 404 }; |
| 392 | 405 |
| 406 #define NACL_IRT_SIGNAL_HANDLING_v0_1 "nacl-irt-signal-handling-0.1" | |
|
Mark Seaborn
2015/06/26 18:31:59
Please comment that this is implemented for Non-SF
Luis Héctor Chávez
2015/07/06 23:45:00
Done.
| |
| 407 typedef void (*NaClIrtSignalHandler)(struct NaClExceptionContext *context); | |
| 408 struct nacl_irt_signal_handling { | |
|
Mark Seaborn
2015/06/26 18:31:59
Let's add "async" into the name to make it clear t
Luis Héctor Chávez
2015/07/06 23:45:00
Done.
| |
| 409 /* | |
| 410 * When send_async_signal is called, |handler| is invoked on the thread | |
| 411 * specified by |tid| on the thread's stack and without modifying the | |
| 412 * underlying signal mask, so |handler| must be reentrant. | |
| 413 * | |
| 414 * You can safely use only async-signal-safe operations in |handler|. The | |
| 415 * following NaCl IRT functions are async-signal-safe: | |
| 416 * | |
| 417 * - tls_get | |
| 418 * - futex_wait_abs | |
| 419 * - futex_wake | |
| 420 * - send_async_signal | |
| 421 * | |
| 422 * If the thread was executing an IRT function, the suspended thread will | |
| 423 * continue it after |handler| finishes. In other words, no IRT function will | |
| 424 * be aborted. | |
| 425 */ | |
| 426 int (*set_async_signal_handler)(NaClIrtSignalHandler handler); | |
| 427 /* | |
| 428 * |tid| should be zero or a value returned by thread_create. If |tid| is | |
| 429 * zero, the signal will be sent to the main thread. | |
| 430 * | |
| 431 * When |tid| is invalid, the result is unspecified. This IRT function | |
| 432 * returns 0 on success or may return ESRCH or EINVAL. | |
| 433 */ | |
| 434 int (*send_async_signal)(nacl_irt_tid_t tid); | |
| 435 }; | |
| 436 | |
| 393 #define NACL_IRT_CODE_DATA_ALLOC_v0_1 "nacl-irt-code-data-alloc-0.1" | 437 #define NACL_IRT_CODE_DATA_ALLOC_v0_1 "nacl-irt-code-data-alloc-0.1" |
| 394 struct nacl_irt_code_data_alloc { | 438 struct nacl_irt_code_data_alloc { |
| 395 /* | 439 /* |
| 396 * Atomically allocate a code segment along with an associated data | 440 * Atomically allocate a code segment along with an associated data |
| 397 * segment with a specified offset. The caller can then call mmap or | 441 * segment with a specified offset. The caller can then call mmap or |
| 398 * dyncode_create for each of the segments starting with the value returned | 442 * dyncode_create for each of the segments starting with the value returned |
| 399 * by |*begin|. | 443 * by |*begin|. |
| 400 * | 444 * |
| 401 * |hint| is a desired address where the code should begin. If |hint| is 0 | 445 * |hint| is a desired address where the code should begin. If |hint| is 0 |
| 402 * this value is ignored and the next available combination of code and data | 446 * this value is ignored and the next available combination of code and data |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. | 478 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. |
| 435 */ | 479 */ |
| 436 int (*clear_cache)(void *addr, size_t size); | 480 int (*clear_cache)(void *addr, size_t size); |
| 437 }; | 481 }; |
| 438 | 482 |
| 439 #if defined(__cplusplus) | 483 #if defined(__cplusplus) |
| 440 } | 484 } |
| 441 #endif | 485 #endif |
| 442 | 486 |
| 443 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ | 487 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ |
| OLD | NEW |