1 /* 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 #ifndef NATIVE_CLIENT_SRC_PUBLIC_IRT_CORE_H_ 8 #define NATIVE_CLIENT_SRC_PUBLIC_IRT_CORE_H_ 1 9 10 #include "native_client/src/include/nacl_base.h" 11 12 EXTERN_C_BEGIN 13 14 /* 15 * This header file declares functions that may be used by an embedder 16 * of NaCl (such as Chromium) to implement a NaCl IRT. 17 */ 18 19 #include <stddef.h> 20 #include <stdint.h> 21 22 /* Type of the IRT query function provided by the IRT to user code. */ 23 typedef size_t (*nacl_irt_query_func_t)(const char *interface_ident, 24 void *table, size_t tablesize); 25 26 /* 27 * nacl_irt_start() is the entry point that the embedder should 28 * define. This is similar to _start(), except that _start() is 29 * defined by the standard libraries (specifically, by libnacl) and an 30 * IRT cannot reliably override _start() by defining it in a ".a" 31 * library. nacl_irt_start() may, however, be defined by a ".a" 32 * library. 33 * 34 * See nacl_startup.h for the layout of the |info| pointer. 35 */ 36 void nacl_irt_start(uint32_t *info); 37 38 /* 39 * nacl_irt_init() initializes libc and Thread Local Storage (TLS 40 * variables) inside the IRT. Calling nacl_irt_init() will typically 41 * be the first thing that nacl_irt_start() does. 42 * 43 * This is provided as a separate function just in case there is any 44 * initialization the IRT needs to do before nacl_irt_init(), or for 45 * very minimal IRTs that do not need to initialize libc. 46 */ 47 void nacl_irt_init(uint32_t *info); 48 49 /* 50 * nacl_irt_enter_user_code() jumps to the entry point of the user 51 * nexe, passing |query_func| to it via an AT_SYSINFO entry in the 52 * auxiliary vector. This function does not return. 53 */ 54 void nacl_irt_enter_user_code(uint32_t *info, nacl_irt_query_func_t query_func); 55 56 /* Function type for user code's initial entry point. */ 57 typedef void (*nacl_entry_func_t)(uint32_t *args); 58 59 /* 60 * nacl_irt_nonsfi_entry() acts like nacl_irt_enter_user_code, 61 * but allows passing in additional arguments. 62 */ 63 int nacl_irt_nonsfi_entry(int argc, char **argv, char **environ, 64 nacl_entry_func_t entry_func, 65 nacl_irt_query_func_t query_func); 66 67 /* For nonsfi_loader. */ 68 void nacl_irt_nonsfi_allow_dev_interfaces(void); 69 70 /* Function for querying for NaCl's core IRT interfaces. */ 71 size_t nacl_irt_query_core(const char *interface_ident, 72 void *table, size_t tablesize); 73 74 /* Definition of an IRT interface, for use with nacl_irt_query_list(). */ 75 struct nacl_irt_interface { 76 const char *name; 77 const void *table; 78 size_t size; 79 /* 80 * filter() returns whether the interface should be enabled. 81 * |filter| may be NULL, in which case the interface is always 82 * enabled. 83 */ 84 int (*filter)(void); 85 }; 86 87 /* 88 * nacl_irt_query_list() is a helper function for defining an IRT 89 * query function given an array of nacl_irt_interface structs (as 90 * specified by |available| and |available_size|, which is the size of 91 * the array in bytes rather than the number of entries). 92 */ 93 size_t nacl_irt_query_list(const char *interface_ident, 94 void *table, size_t tablesize, 95 const struct nacl_irt_interface *available, 96 size_t available_size); 97 98 EXTERN_C_END 99 100 #endif 101