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; | |
| 25 #define NACL_IRT_MAIN_THREAD_TID 0 | |
| 24 | 26 |
| 25 #if defined(__cplusplus) | 27 #if defined(__cplusplus) |
| 26 extern "C" { | 28 extern "C" { |
| 27 #endif | 29 #endif |
| 28 | 30 |
| 29 /* | 31 /* |
| 30 * The only interface exposed directly to user code is a single function | 32 * 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 | 33 * 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 | 34 * auxiliary vector on the stack at program startup. The interfaces |
| 33 * below are accessed by calling this function with the appropriate | 35 * below are accessed by calling this function with the appropriate |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 * |*stack_flag|. This is intended to be used by a threading | 236 * |*stack_flag|. This is intended to be used by a threading |
| 235 * library to determine when the thread's stack can be deallocated | 237 * 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 | 238 * or reused. The system will not read or write the thread's stack |
| 237 * after writing 0 to |*stack_flag|. | 239 * after writing 0 to |*stack_flag|. |
| 238 */ | 240 */ |
| 239 void (*thread_exit)(int32_t *stack_flag); | 241 void (*thread_exit)(int32_t *stack_flag); |
| 240 int (*thread_nice)(const int nice); | 242 int (*thread_nice)(const int nice); |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 /* | 245 /* |
| 246 * This interface is only available on Non-SFI Mode. | |
| 247 */ | |
| 248 #define NACL_IRT_THREAD_v0_2 "nacl-irt-thread-0.2" | |
| 249 struct nacl_irt_thread_v0_2 { | |
| 250 /* | |
| 251 * Now this interface assigns the thread ID of the child thread into | |
|
Mark Seaborn
2015/08/12 01:43:07
Remove "Now". Can you start by saying "This inter
Luis Héctor Chávez
2015/08/12 22:14:27
Done.
| |
| 252 * |child_tid| atomically when the thread is created. It will be the | |
|
Mark Seaborn
2015/08/12 01:43:07
Nit: the assignment is not atomic. It just happen
Luis Héctor Chávez
2015/08/12 22:14:27
Done.
| |
| 253 * |parent_tid| argument to the clone() system call. |child_tid| can be | |
|
Junichi Uekawa
2015/07/21 23:36:03
This comment is strange.
clone looks something li
Luis Héctor Chávez
2015/07/21 23:42:11
IIUC when calling the clone syscall with the CLONE
Mark Seaborn
2015/08/12 01:43:07
Nit: don't mention clone() here. That's an implem
| |
| 254 * NULL. | |
| 255 */ | |
| 256 int (*thread_create)(void (*start_func)(void), void *stack, void *thread_ptr, | |
| 257 nacl_irt_tid_t *child_tid); | |
| 258 void (*thread_exit)(int32_t *stack_flag); | |
| 259 int (*thread_nice)(const int nice); | |
| 260 }; | |
| 261 | |
| 262 /* | |
| 244 * The irt_futex interface is based on Linux's futex() system call. | 263 * The irt_futex interface is based on Linux's futex() system call. |
| 245 * | 264 * |
| 246 * irt_futex provides process-private futexes, so futex wait queues are | 265 * irt_futex provides process-private futexes, so futex wait queues are |
| 247 * associated with numeric virtual addresses only. This is equivalent to | 266 * 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() | 267 * 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 | 268 * 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 | 269 * mapping with futex_wait_abs() -- futex wait queues are not associated |
| 251 * with pages' identities. | 270 * with pages' identities. |
| 252 */ | 271 */ |
| 253 #define NACL_IRT_FUTEX_v0_1 "nacl-irt-futex-0.1" | 272 #define NACL_IRT_FUTEX_v0_1 "nacl-irt-futex-0.1" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 */ | 448 */ |
| 430 #define NACL_IRT_ICACHE_v0_1 "nacl-irt-icache-0.1" | 449 #define NACL_IRT_ICACHE_v0_1 "nacl-irt-icache-0.1" |
| 431 struct nacl_irt_icache { | 450 struct nacl_irt_icache { |
| 432 /* | 451 /* |
| 433 * clear_cache() makes instruction cache and data cache for the address | 452 * clear_cache() makes instruction cache and data cache for the address |
| 434 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. | 453 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. |
| 435 */ | 454 */ |
| 436 int (*clear_cache)(void *addr, size_t size); | 455 int (*clear_cache)(void *addr, size_t size); |
| 437 }; | 456 }; |
| 438 | 457 |
| 458 /* | |
| 459 * This interface is only available on Non-SFI Mode. | |
|
Mark Seaborn
2015/08/12 01:43:07
Can you refer back to nonsfi_mode_async_signals.tx
Luis Héctor Chávez
2015/08/12 22:14:27
Done.
| |
| 460 */ | |
| 461 #define NACL_IRT_ASYNC_SIGNAL_HANDLING_v0_1 "nacl-irt-async-signal-handling-0.1" | |
| 462 typedef void (*NaClIrtSignalHandler)(struct NaClExceptionContext *context); | |
|
Mark Seaborn
2015/08/12 01:43:07
Nit: don't put this between the #define and the st
Luis Héctor Chávez
2015/08/12 22:14:27
Done.
| |
| 463 struct nacl_irt_async_signal_handling { | |
| 464 /* | |
| 465 * NaCl applications can register a single, global async signal handler that | |
| 466 * will be invoked on the thread that receives the signal. When | |
| 467 * send_async_signal is called, |handler| is invoked on the thread specified | |
| 468 * by |tid| on the thread's stack and without modifying the underlying signal | |
| 469 * mask (as opposed to the POSIX behavior), so |handler| must be reentrant. | |
|
Mark Seaborn
2015/08/12 01:43:07
See my comment in nonsfi_mode_async_signals.txt ab
Luis Héctor Chávez
2015/08/12 22:14:27
Reworded it a bit.
| |
| 470 * | |
| 471 * If the thread was executing an IRT function, the suspended thread will | |
| 472 * continue it after |handler| finishes. In other words, no IRT function will | |
| 473 * be aborted. | |
| 474 * | |
| 475 * You can safely use only async-signal-safe operations in |handler|. The | |
| 476 * following NaCl IRT functions are async-signal-safe: | |
| 477 * | |
| 478 * - tls_get | |
| 479 * - futex_wait_abs | |
| 480 * - futex_wake | |
| 481 * - send_async_signal | |
| 482 * | |
| 483 * This function in particular is not async-signal-safe and must not be called | |
| 484 * from signal handlers. | |
| 485 */ | |
| 486 int (*set_async_signal_handler)(NaClIrtSignalHandler handler); | |
| 487 /* | |
| 488 * Asynchronously delivers a signal to the thread identified by |tid| within | |
| 489 * the same thread group as the caller. This function requires | |
|
Mark Seaborn
2015/08/12 01:43:07
"Thread group" is a Linux concept that shouldn't b
Luis Héctor Chávez
2015/08/12 22:14:27
Changed to "process" to clarify that this can't be
| |
| 490 * nacl_signal_set_handler to be called first, otherwise it will fail with | |
|
Mark Seaborn
2015/08/12 01:43:07
"otherwise it will fail with ESRCH" -- presumably
Luis Héctor Chávez
2015/08/12 22:14:27
Removed.
| |
| 491 * ESRCH. |tid| should be a valid thread identifier obtained when creating a | |
| 492 * thread (through the |parent_tid| parameter) and the thread must still be | |
|
Mark Seaborn
2015/08/12 01:43:07
You mean child_tid.
Luis Héctor Chávez
2015/08/12 22:14:27
Done.
| |
| 493 * alive. The constant NACL_IRT_MAIN_THREAD_TID can be used to refer to the | |
| 494 * main thread. | |
| 495 * | |
| 496 * As opposed to POSIX, NaCl only provides a way to send a single signal. | |
| 497 * Delivery of different kinds of signals to be POSIX-compliant can be | |
| 498 * implemented in userspace. | |
| 499 * | |
| 500 * When |tid| is invalid, the result is unspecified. This IRT function | |
| 501 * returns 0 on success or may return ESRCH or EINVAL on failure. | |
| 502 */ | |
| 503 int (*send_async_signal)(nacl_irt_tid_t tid); | |
| 504 }; | |
| 505 | |
| 439 #if defined(__cplusplus) | 506 #if defined(__cplusplus) |
| 440 } | 507 } |
| 441 #endif | 508 #endif |
| 442 | 509 |
| 443 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ | 510 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ |
| OLD | NEW |