| 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 dirent; | 16 struct dirent; |
| 17 | 17 |
| 18 struct NaClExceptionContext; | 18 struct NaClExceptionContext; |
| 19 struct NaClMemMappingInfo; | 19 struct NaClMemMappingInfo; |
| 20 | 20 |
| 21 typedef int64_t nacl_irt_off_t; | 21 typedef int64_t nacl_irt_off_t; |
| 22 typedef uint32_t nacl_irt_clockid_t; | 22 typedef uint32_t nacl_irt_clockid_t; |
| 23 typedef uintptr_t nacl_irt_tid_t; | |
| 24 #define NACL_IRT_MAIN_THREAD_TID 0 | |
| 25 | 23 |
| 26 /* | 24 /* |
| 27 * Under newlib, the 'struct stat' defined in <sys/stat.h> matches the | 25 * Under newlib, the 'struct stat' defined in <sys/stat.h> matches the |
| 28 * layout of 'struct nacl_abi_stat', so the standard type 'struct stat' | 26 * layout of 'struct nacl_abi_stat', so the standard type 'struct stat' |
| 29 * is used in IRT function signatures. Under glibc, the 'struct stat' | 27 * is used in IRT function signatures. Under glibc, the 'struct stat' |
| 30 * defined by the C library differs and translation between the C | 28 * defined by the C library differs and translation between the C |
| 31 * library format and the IRT format is required. | 29 * library format and the IRT format is required. |
| 32 */ | 30 */ |
| 33 #if defined(__native_client__) && defined(__GLIBC__) | 31 #if defined(__native_client__) && defined(__GLIBC__) |
| 34 typedef struct nacl_abi_stat nacl_irt_stat_t; | 32 typedef struct nacl_abi_stat nacl_irt_stat_t; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 * |*stack_flag|. This is intended to be used by a threading | 246 * |*stack_flag|. This is intended to be used by a threading |
| 249 * library to determine when the thread's stack can be deallocated | 247 * library to determine when the thread's stack can be deallocated |
| 250 * or reused. The system will not read or write the thread's stack | 248 * or reused. The system will not read or write the thread's stack |
| 251 * after writing 0 to |*stack_flag|. | 249 * after writing 0 to |*stack_flag|. |
| 252 */ | 250 */ |
| 253 void (*thread_exit)(int32_t *stack_flag); | 251 void (*thread_exit)(int32_t *stack_flag); |
| 254 int (*thread_nice)(const int nice); | 252 int (*thread_nice)(const int nice); |
| 255 }; | 253 }; |
| 256 | 254 |
| 257 /* | 255 /* |
| 258 * This interface is only available on Non-SFI Mode. | |
| 259 */ | |
| 260 #define NACL_IRT_THREAD_v0_2 "nacl-irt-thread-0.2" | |
| 261 struct nacl_irt_thread_v0_2 { | |
| 262 /* | |
| 263 * This interface is the same as nacl_irt_thread_v0_1, with the additional | |
| 264 * feature that it assigns the thread ID of the child thread into | |
| 265 * |child_tid| before the child thread starts and before execution control | |
| 266 * returns to the parent. | |
| 267 */ | |
| 268 int (*thread_create)(void (*start_func)(void), void *stack, void *thread_ptr, | |
| 269 nacl_irt_tid_t *child_tid); | |
| 270 void (*thread_exit)(int32_t *stack_flag); | |
| 271 int (*thread_nice)(const int nice); | |
| 272 }; | |
| 273 | |
| 274 /* | |
| 275 * The irt_futex interface is based on Linux's futex() system call. | 256 * The irt_futex interface is based on Linux's futex() system call. |
| 276 * | 257 * |
| 277 * irt_futex provides process-private futexes, so futex wait queues are | 258 * irt_futex provides process-private futexes, so futex wait queues are |
| 278 * associated with numeric virtual addresses only. This is equivalent to | 259 * associated with numeric virtual addresses only. This is equivalent to |
| 279 * Linux's FUTEX_PRIVATE_FLAG. If a page is mmap()'d twice, futex_wake() | 260 * Linux's FUTEX_PRIVATE_FLAG. If a page is mmap()'d twice, futex_wake() |
| 280 * on one mapping will *not* wake a thread that is waiting on the other | 261 * on one mapping will *not* wake a thread that is waiting on the other |
| 281 * mapping with futex_wait_abs() -- futex wait queues are not associated | 262 * mapping with futex_wait_abs() -- futex wait queues are not associated |
| 282 * with pages' identities. | 263 * with pages' identities. |
| 283 */ | 264 */ |
| 284 #define NACL_IRT_FUTEX_v0_1 "nacl-irt-futex-0.1" | 265 #define NACL_IRT_FUTEX_v0_1 "nacl-irt-futex-0.1" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 */ | 441 */ |
| 461 #define NACL_IRT_ICACHE_v0_1 "nacl-irt-icache-0.1" | 442 #define NACL_IRT_ICACHE_v0_1 "nacl-irt-icache-0.1" |
| 462 struct nacl_irt_icache { | 443 struct nacl_irt_icache { |
| 463 /* | 444 /* |
| 464 * clear_cache() makes instruction cache and data cache for the address | 445 * clear_cache() makes instruction cache and data cache for the address |
| 465 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. | 446 * range from |addr| to |(intptr_t)addr + size| (exclusive) coherent. |
| 466 */ | 447 */ |
| 467 int (*clear_cache)(void *addr, size_t size); | 448 int (*clear_cache)(void *addr, size_t size); |
| 468 }; | 449 }; |
| 469 | 450 |
| 470 /* | |
| 471 * This interface is only available on Non-SFI Mode. | |
| 472 * | |
| 473 * For more information, consult documentation/nonsfi_mode_async_signals.txt. | |
| 474 */ | |
| 475 | |
| 476 typedef void (*NaClIrtAsyncSignalHandler)( | |
| 477 struct NaClExceptionContext *context); | |
| 478 | |
| 479 #define NACL_IRT_ASYNC_SIGNAL_HANDLING_v0_1 "nacl-irt-async-signal-handling-0.1" | |
| 480 struct nacl_irt_async_signal_handling { | |
| 481 /* | |
| 482 * NaCl applications can register a single, global async signal handler that | |
| 483 * will be invoked on the thread that receives the signal. When | |
| 484 * send_async_signal is called, |handler| is invoked on the thread specified | |
| 485 * by |tid| on the thread's stack and without modifying the underlying signal | |
| 486 * mask (as opposed to the POSIX behavior), so it is possible for |handler| to | |
| 487 * be invoked recursively (if a signal is sent from |handler|) and | |
| 488 * concurrently (if two threads send signals at the same time). | |
| 489 * | |
| 490 * If the thread was executing an IRT function, the suspended thread will | |
| 491 * continue it after |handler| finishes. In other words, no IRT function will | |
| 492 * be aborted. | |
| 493 * | |
| 494 * You can safely use only async-signal-safe operations in |handler|. The | |
| 495 * following NaCl IRT functions are async-signal-safe: | |
| 496 * | |
| 497 * - tls_get | |
| 498 * - futex_wait_abs | |
| 499 * - futex_wake | |
| 500 * - send_async_signal | |
| 501 * | |
| 502 * This function in particular is not async-signal-safe and must not be called | |
| 503 * from signal handlers. | |
| 504 */ | |
| 505 int (*set_async_signal_handler)(NaClIrtAsyncSignalHandler handler); | |
| 506 /* | |
| 507 * Asynchronously delivers a signal to the thread identified by |tid| within | |
| 508 * the same process as the caller. |tid| should be a valid thread identifier | |
| 509 * obtained when creating a thread (through the |child_tid| parameter to | |
| 510 * create_thread()) and the thread must still be alive. The constant | |
| 511 * NACL_IRT_MAIN_THREAD_TID can be used to refer to the main thread. | |
| 512 * | |
| 513 * As opposed to POSIX, NaCl only provides a way to send a single signal. | |
| 514 * Delivery of different kinds of signals to be POSIX-compliant can be | |
| 515 * implemented in userspace. | |
| 516 * | |
| 517 * When |tid| is invalid, the result is unspecified. This IRT function | |
| 518 * returns 0 on success or may return ESRCH or EINVAL on failure. | |
| 519 */ | |
| 520 int (*send_async_signal)(nacl_irt_tid_t tid); | |
| 521 }; | |
| 522 | |
| 523 #if defined(__cplusplus) | 451 #if defined(__cplusplus) |
| 524 } | 452 } |
| 525 #endif | 453 #endif |
| 526 | 454 |
| 527 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ | 455 #endif /* NATIVE_CLIENT_SRC_UNTRUSTED_IRT_IRT_H */ |
| OLD | NEW |