diff options
author | Roland McGrath <roland@hack.frob.com> | 2015-04-17 09:02:19 -0700 |
---|---|---|
committer | Roland McGrath <roland@hack.frob.com> | 2015-04-17 09:02:19 -0700 |
commit | d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438 (patch) | |
tree | a76176eca62c0907dd7f135979312c8e55ad06a5 /sysdeps/nacl/nacl-interfaces.c | |
parent | f70925993ada98039250d46c62fb89c168b8f9d6 (diff) | |
download | glibc-d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438.tar glibc-d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438.tar.gz glibc-d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438.tar.bz2 glibc-d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438.zip |
Add arm-nacl port.
Diffstat (limited to 'sysdeps/nacl/nacl-interfaces.c')
-rw-r--r-- | sysdeps/nacl/nacl-interfaces.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/sysdeps/nacl/nacl-interfaces.c b/sysdeps/nacl/nacl-interfaces.c new file mode 100644 index 0000000000..cb0dcd0bc8 --- /dev/null +++ b/sysdeps/nacl/nacl-interfaces.c @@ -0,0 +1,123 @@ +/* Using NaCl interface tables. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <nacl-interfaces.h> +#include <ldsodefs.h> + + +/* These magic symbols are provided implicitly by the linker to + give us the bounds of the specially-named sections. */ + +extern const struct nacl_interface __start_nacl_mandatory_interface_names[] + attribute_hidden; +extern const struct nacl_interface __stop_nacl_mandatory_interface_names[] + attribute_hidden; + +extern uintptr_t __start_nacl_mandatory_interface_tables[] + attribute_hidden; +extern uintptr_t __stop_nacl_mandatory_interface_tables[] + attribute_hidden; + +/* We use weak references for the optional ones, since they + might not be included at all in any given statically-linked program. */ + +extern const struct nacl_interface __start_nacl_optional_interface_names[] + attribute_hidden __attribute__ ((weak)); +extern const struct nacl_interface __stop_nacl_optional_interface_names[] + attribute_hidden __attribute__ ((weak)); + +extern uintptr_t __start_nacl_optional_interface_tables[] + attribute_hidden __attribute__ ((weak)); +extern uintptr_t __stop_nacl_optional_interface_tables[] + attribute_hidden __attribute__ ((weak)); + +static uintptr_t * +next_nacl_table (uintptr_t *t, const struct nacl_interface *i) +{ + return (void *) t + i->table_size; +} + +static void __attribute__ ((noreturn)) +missing_mandatory_interface (const struct nacl_interface *i) +{ + static const char before[] = + "FATAL: NaCl IRT interface query failed for essential interface \""; + static const char after[] = + "\"\n"; + + if (__nacl_irt_fdio.write != NULL) + { + size_t wrote; + (*__nacl_irt_fdio.write) (2, before, sizeof before - 1, &wrote); + (*__nacl_irt_fdio.write) (2, i->name, i->namelen - 1, &wrote); + (*__nacl_irt_fdio.write) (2, after, sizeof after - 1, &wrote); + } + + if (__nacl_irt_basic.exit != NULL) + (*__nacl_irt_basic.exit) (-1); + + __builtin_trap (); +} + +static void +initialize_mandatory_interfaces (void) +{ + const struct nacl_interface *i = __start_nacl_mandatory_interface_names; + uintptr_t *t = __start_nacl_mandatory_interface_tables; + while (i < __stop_nacl_mandatory_interface_names) + { + if (__nacl_irt_query (i->name, t, i->table_size) != i->table_size) + missing_mandatory_interface (i); + + t = next_nacl_table (t, i); + i = next_nacl_interface (i); + } +} + + +static int +nacl_missing_optional_interface (void) +{ + return ENOSYS; +} + +static void +initialize_optional_interfaces (void) +{ + const struct nacl_interface *i = __start_nacl_optional_interface_names; + uintptr_t *t = __start_nacl_optional_interface_tables; + while (i < __stop_nacl_optional_interface_names) + { + size_t filled = __nacl_irt_query (i->name, t, i->table_size); + if (filled != i->table_size) + for (size_t slot = 0; slot < i->table_size / sizeof *t; ++slot) + t[slot] = (uintptr_t) &nacl_missing_optional_interface; + + t = next_nacl_table (t, i); + i = next_nacl_interface (i); + } +} + + +void attribute_hidden +__nacl_initialize_interfaces (void) +{ + initialize_mandatory_interfaces (); + initialize_optional_interfaces (); +} |