blob: b7b45bbf38937f27475fcdcd73eff597b342b675 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001/* Using NaCl interface tables.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _NACL_INTERFACES_H
20#define _NACL_INTERFACES_H 1
21
22#include <errno.h>
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26#include <sys/types.h>
27
28/* <nacl-irt.h> is massaged from native_client/src/untrusted/irt/irt.h so
29 that it uses nacl_abi_*_t type names. We must define those types first. */
30
31/* These are the same in the IRT ABI as in the libc ABI. */
32typedef blksize_t nacl_abi_blksize_t;
33typedef dev_t nacl_abi_dev_t;
34typedef gid_t nacl_abi_gid_t;
35typedef ino_t nacl_abi_ino_t;
36typedef mode_t nacl_abi_mode_t;
37typedef nlink_t nacl_abi_nlink_t;
38typedef size_t nacl_abi_size_t;
39typedef time_t nacl_abi_time_t;
40typedef uid_t nacl_abi_uid_t;
41typedef struct dirent nacl_abi_dirent_t;
42typedef struct timeval nacl_abi_timeval_t;
43typedef struct timespec nacl_abi_timespec_t;
44
45/* This is unsigned in the IRT ABI, but it's traditionally 'long int',
46 so we stick with that. */
47typedef clock_t nacl_abi_clock_t;
48
49typedef int32_t nacl_abi_blkcnt_t;
50
51/* This is different by design. */
52typedef struct nacl_abi_stat nacl_abi_stat_t;
53
54#include <nacl-irt.h>
55
56/* This is how we access the IRT interface-query function.
57 This formulation makes it usable as if it were a function name. */
58#define __nacl_irt_query (*(TYPE_nacl_irt_query) GLRO(dl_sysinfo))
59
60
61/* This describes one IRT (or IRT-like) interface that libc uses.
62 This structure contains no pointers, so it can go into rodata
63 without relocs. Instead, the actual tables we use for these
64 interfaces live in a parallel section in writable data. */
65struct nacl_interface {
66 size_t table_size;
67 size_t namelen;
68 char name[];
69};
70
71/* Increment for 'const struct nacl_interface *' pointers. */
72static inline const struct nacl_interface *
73next_nacl_interface (const struct nacl_interface *i)
74{
75 uintptr_t align = __alignof (*i);
76 return (const void *) (((uintptr_t) &i->name[i->namelen] + align - 1)
77 & -align);
78}
79
80#if IS_IN (libpthread)
81# define libpthread_hidden_proto(name) hidden_proto (name)
82#else
83# define libpthread_hidden_proto(name)
84#endif
85
86#define DECLARE_INTERFACE(module, type) \
87 extern struct type __##type; module##_hidden_proto (__##type);
88
89#define NACL_MANDATORY_INTERFACE(module, id, type) \
90 DECLARE_INTERFACE (module, type)
91#define NACL_OPTIONAL_INTERFACE(module, id, type) \
92 DECLARE_INTERFACE (module, type)
93#include "nacl-interface-list.h"
94#undef NACL_MANDATORY_INTERFACE
95#undef NACL_OPTIONAL_INTERFACE
96
97extern void __nacl_initialize_interfaces (void) attribute_hidden;
98extern bool __nacl_supply_interface_libc (const char *ident, size_t ident_len,
99 const void *table, size_t tablesize)
100 internal_function attribute_hidden;
101extern bool __nacl_supply_interface_rtld (const char *ident, size_t ident_len,
102 const void *table, size_t tablesize);
103 internal_function;
104
105/* Convenience function for handling IRT call return values. */
106static inline int
107__nacl_fail (int err)
108{
109 errno = err;
110 return -1;
111}
112
113#define NACL_CALL(err, val) \
114 ({ int _err = (err); _err ? __nacl_fail (_err) : (val); })
115
116#endif /* nacl-interfaces.h */