diff options
author | Roland McGrath <roland@hack.frob.com> | 2013-04-12 14:53:58 -0700 |
---|---|---|
committer | Roland McGrath <roland@hack.frob.com> | 2013-04-12 14:53:58 -0700 |
commit | fd486ec7cc4527327c0410dc34b730435634796e (patch) | |
tree | e0357197fa846c18c24b4b38bd60d0c234a3d2b6 | |
download | glibc-fd486ec7cc4527327c0410dc34b730435634796e.tar.gz glibc-fd486ec7cc4527327c0410dc34b730435634796e.tar.xz glibc-fd486ec7cc4527327c0410dc34b730435634796e.zip |
Initial commit of hacky state
67 files changed, 2004 insertions, 0 deletions
diff --git a/abi-tags b/abi-tags new file mode 100644 index 0000000000..9eaf23e083 --- /dev/null +++ b/abi-tags @@ -0,0 +1,4 @@ +# Configuration ABI OS ABI version +# ------------- ------ ----------- + +.*-.*-nacl.* 6 22.0.0 diff --git a/configure b/configure new file mode 100644 index 0000000000..dc81f05d0f --- /dev/null +++ b/configure @@ -0,0 +1,8 @@ +libc_add_on_canonical=nacl-port + +case "$config_machine-$config_os" in +arm*-nacl* | i?86-nacl*) + libc_commonpagesize=0x10000 + libc_config_ok=yes + ;; +esac diff --git a/sysdeps/arm/armv7/nacl/Implies b/sysdeps/arm/armv7/nacl/Implies new file mode 100644 index 0000000000..d696921929 --- /dev/null +++ b/sysdeps/arm/armv7/nacl/Implies @@ -0,0 +1,2 @@ +# We can do everything that 6T2 can +arm/armv6t2/nacl diff --git a/sysdeps/arm/nacl/Implies b/sysdeps/arm/nacl/Implies new file mode 100644 index 0000000000..9ab295139c --- /dev/null +++ b/sysdeps/arm/nacl/Implies @@ -0,0 +1 @@ +init_array diff --git a/sysdeps/arm/nacl/Makefile b/sysdeps/arm/nacl/Makefile new file mode 100644 index 0000000000..3fa689fa57 --- /dev/null +++ b/sysdeps/arm/nacl/Makefile @@ -0,0 +1,7 @@ +ifeq ($(subdir),csu) +sysdep_routines += aeabi_read_tp +endif + +ifeq ($(subdir),elf) +sysdep-rtld-routines += aeabi_read_tp +endif diff --git a/sysdeps/arm/nacl/____longjmp_chk.S b/sysdeps/arm/nacl/____longjmp_chk.S new file mode 100644 index 0000000000..22c812ce2f --- /dev/null +++ b/sysdeps/arm/nacl/____longjmp_chk.S @@ -0,0 +1,47 @@ +/* longjmp that validates stack addresses. ARM/NaCl version. + Copyright (C) 2013 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 <sysdep.h> + + .section .rodata.str1.1,"aMS",%progbits,1 + .type longjmp_msg,%object +longjmp_msg: + .string "longjmp causes uninitialized stack frame" + .size longjmp_msg, .-longjmp_msg + + .text + +/* We don't have sigaltstack and so any longjmp must be to an outer frame. */ +.macro check_sp reg + cmp sp, \reg + bls .Lok +#ifdef PIC + movw r0, #:lower16:longjmp_msg-(.LPIC0+8) + movt r0, #:upper16:longjmp_msg-(.LPIC0+8) +.LPIC0: add r0, r0, pc +#else + movw r0, #:lower16:longjmp_msg + movt r0, #:upper16:longjmp_msg +#endif + b HIDDEN_JUMPTARGET(__fortify_fail) +.Lok: +.endm + +#define CHECK_SP(reg) check_sp reg +#define __longjmp ____longjmp_chk +#include <__longjmp.S> diff --git a/sysdeps/arm/nacl/aeabi_read_tp.S b/sysdeps/arm/nacl/aeabi_read_tp.S new file mode 100644 index 0000000000..3655d3e60b --- /dev/null +++ b/sysdeps/arm/nacl/aeabi_read_tp.S @@ -0,0 +1,44 @@ +/* ARM EABI helper function for reading the thread pointer. NaCl version. + Copyright (C) 2013 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. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + 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 <sysdep.h> + +/* GCC will emit calls to this routine under -mtp=soft. */ + + .hidden __aeabi_read_tp +ENTRY (__aeabi_read_tp) + ldr r0, [r9] + sfi_bx lr +END (__aeabi_read_tp) diff --git a/sysdeps/arm/nacl/arm-features.h b/sysdeps/arm/nacl/arm-features.h new file mode 100644 index 0000000000..f5a9d3e7e7 --- /dev/null +++ b/sysdeps/arm/nacl/arm-features.h @@ -0,0 +1,40 @@ +/* Macros to test for CPU features on ARM. NaCl version. + Copyright (C) 2013 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/>. */ + +#ifndef _NACL_ARM_FEATURES_H +#define _NACL_ARM_FEATURES_H 1 + +#ifdef __SOFTFP__ +# error NaCl should always have VFP enabled +#endif + +/* NaCl does not support iWMMXt at all. */ +#define ARM_ASSUME_NO_IWMMXT 1 + +/* NaCl does not allow instructions to target the pc register. */ +#define ARM_ALWAYS_BX 1 + +/* Computed branch targets must be bundle-aligned, which is to 16 bytes. */ +#define ARM_BX_ALIGN_LOG2 4 + +/* Two-register addressing modes are never allowed. */ +#define ARM_NO_INDEX_REGISTER 1 + +#include_next <arm-features.h> + +#endif /* arm-features.h */ diff --git a/sysdeps/arm/nacl/dl-machine.h b/sysdeps/arm/nacl/dl-machine.h new file mode 100644 index 0000000000..aa9202f80d --- /dev/null +++ b/sysdeps/arm/nacl/dl-machine.h @@ -0,0 +1,30 @@ +/* Machine-dependent ELF dynamic relocation inline functions. ARM/NaCl version. + Copyright (C) 2013 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/>. */ + +#ifndef dl_machine_h + +/* This is only needed for handling TEXTRELs and NaCl will never + support TEXTRELs at all. */ +#define CLEAR_CACHE(start, end) abort () + +#endif + +/* The rest is just machine-specific. + This #include is outside the #ifndef because the parts of + dl-machine.h used only by dynamic-link.h are outside the guard. */ +#include <sysdeps/arm/dl-machine.h> diff --git a/sysdeps/arm/nacl/dl-trampoline.S b/sysdeps/arm/nacl/dl-trampoline.S new file mode 100644 index 0000000000..052b61ab1f --- /dev/null +++ b/sysdeps/arm/nacl/dl-trampoline.S @@ -0,0 +1,19 @@ +/* XXX temporary stubs */ + + .text + .globl _dl_runtime_resolve + .type _dl_runtime_resolve, #function + .p2align 4 +_dl_runtime_resolve: + sfi_trap + .size _dl_runtime_resolve, .-_dl_runtime_resolve + +#ifndef PROF + .globl _dl_runtime_profile + .type _dl_runtime_profile, #function + .p2align 4 +_dl_runtime_profile: + sfi_trap + .size _dl_runtime_profile, .-_dl_runtime_profile +#endif + .previous diff --git a/sysdeps/arm/nacl/include/bits/setjmp.h b/sysdeps/arm/nacl/include/bits/setjmp.h new file mode 100644 index 0000000000..59c83cddcb --- /dev/null +++ b/sysdeps/arm/nacl/include/bits/setjmp.h @@ -0,0 +1,38 @@ +/* Private jmp_buf-related definitions. NaCl/ARM version. + Copyright (C) 2013 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/>. */ + +#ifndef _INCLUDE_BITS_SETJMP_H +#define _INCLUDE_BITS_SETJMP_H 1 + +#ifndef __ASSEMBLER__ +/* Get the public declarations. */ +# include <sysdeps/arm/bits/setjmp.h> +#endif + +/* Register list for a ldm/stm instruction to load/store + the general registers from a __jmp_buf. + + The generic ARM definition includes r9 (v6), which is not + permitted under NaCl. We add r3 even though it's call-clobbered, + just to keep the size the same as the generic version. */ +#define JMP_BUF_REGLIST {r3, v1-v5, sl, fp, sp, lr} + +/* Index of __jmp_buf where the sp register resides. */ +#define __JMP_BUF_SP 8 + +#endif /* include/bits/setjmp.h */ diff --git a/sysdeps/arm/nacl/start.c b/sysdeps/arm/nacl/start.c new file mode 100644 index 0000000000..25f6fd774a --- /dev/null +++ b/sysdeps/arm/nacl/start.c @@ -0,0 +1 @@ +#include <sysdeps/nacl/start.c> diff --git a/sysdeps/arm/nacl/sysdep.h b/sysdeps/arm/nacl/sysdep.h new file mode 100644 index 0000000000..71c3e13348 --- /dev/null +++ b/sysdeps/arm/nacl/sysdep.h @@ -0,0 +1,73 @@ +/* Assembler macros for ARM/NaCl. + Copyright (C) 2013 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/>. */ + +#ifndef _ARM_NACL_SYSDEP_H +#define _ARM_NACL_SYSDEP_H 1 + +#ifdef __ASSEMBLER__ + +# ifndef NO_THUMB +# define NO_THUMB +# endif +# define ARM_SFI_MACROS 1 + +/* The compiler driver primes the assembler with a standard set of + macros that includes sfi_breg and sfi_sp. The sfi_pld macro is + redundant with sfi_breg, but libc code uses it so as not to run + afoul of the assembler's parsing bug in versions prior to 2.23.2. + NaCl never uses an assembler that has this bug. */ + +.macro sfi_pld basereg, offset=#0 + sfi_breg \basereg, pld [\basereg, \offset] +.endm + +#endif + +#include <sysdeps/arm/sysdep.h> + +#ifdef __ASSEMBLER__ + +/* We use DWARF2 CFI, not EABI unwind info. */ +# undef CFI_SECTIONS +# define CFI_SECTIONS .cfi_sections .eh_frame, .debug_frame + +# undef eabi_fnstart +# define eabi_fnstart +# undef eabi_fnend +# define eabi_fnend +# undef eabi_save +# define eabi_save(...) +# undef eabi_cantunwind +# define eabi_cantunwind +# undef eabi_pad +# define eabi_pad(n) + +/* NaCl has its own special way of getting the thread pointer. */ +# undef GET_TLS +# define GET_TLS(tmp) ldr r0, [r9] + +/* Rather than macroizing the code any more, we can just define a few + mnemonics as macros here. */ +# define bl sfi_bl +# define bx sfi_bx +# define blx sfi_blx +# define bxeq sfi_bxeq /* Only condition now in use. */ + +#endif /* __ASSEMBLER__ */ + +#endif /* sysdep.h */ diff --git a/sysdeps/arm/nacl/tls.h b/sysdeps/arm/nacl/tls.h new file mode 100644 index 0000000000..a9d0240cf4 --- /dev/null +++ b/sysdeps/arm/nacl/tls.h @@ -0,0 +1,92 @@ +/* XXX */ + +#ifndef _TLS_H +#define _TLS_H 1 + +#ifndef __ASSEMBLER__ +# include <stdbool.h> +# include <stddef.h> +# include <stdint.h> +# include <nacl-interfaces.h> + +/* Type for the dtv. */ +typedef union dtv +{ + size_t counter; + struct + { + void *val; + bool is_static; + } pointer; +} dtv_t; + +/* The TP points to the start of the thread blocks. */ +# define TLS_DTV_AT_TP 1 + +typedef struct +{ + dtv_t *dtv; + void *private; +} tcbhead_t; + +/* This is the size of the initial TCB. */ +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) + +/* Alignment requirements for the initial TCB. */ +# define TLS_INIT_TCB_ALIGN 16 + +/* This is the size of the TCB. */ +# define TLS_TCB_SIZE sizeof (tcbhead_t) + +/* This is the size we need before TCB. */ +# define TLS_PRE_TCB_SIZE 0 /* XXX */ + +/* Return the thread descriptor for the current thread. */ +# define THREAD_SELF __builtin_thread_pointer () + +/* Alignment requirements for the TCB. */ +# define TLS_TCB_ALIGN 16 + +/* Install the dtv pointer. The pointer passed is to the element with + index -1 which contain the length. */ +# define INSTALL_DTV(tcbp, dtvp) \ + (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1) + +/* Install new dtv for current thread. */ +# define INSTALL_NEW_DTV(dtv) \ + (THREAD_DTV() = (dtv)) + +/* Return dtv of given thread descriptor. */ +# define GET_DTV(tcbp) \ + (((tcbhead_t *) (tcbp))->dtv) + +/* Return the address of the dtv for the current thread. */ +# define THREAD_DTV() \ + (((tcbhead_t *) __builtin_thread_pointer ())->dtv) + +#define TLS_INIT_TP_EXPENSIVE 1 + +/* Code to initially initialize the thread pointer. This might need + special attention since 'errno' is not yet available and if the + operation can cause a failure 'errno' must not be touched. */ +# define TLS_INIT_TP(tcbp, secondcall) \ + ((*__nacl_irt_tls.tls_init) (tcbp) == 0 ? NULL : "tls_init call failed") + +/* Get and set the global scope generation counter in struct pthread. */ +#define THREAD_GSCOPE_FLAG_UNUSED 0 +#define THREAD_GSCOPE_FLAG_USED 1 +#define THREAD_GSCOPE_FLAG_WAIT 2 +#define THREAD_GSCOPE_RESET_FLAG() \ + do \ + {} \ + while (0) +#define THREAD_GSCOPE_SET_FLAG() \ + do \ + {} \ + while (0) +#define THREAD_GSCOPE_WAIT() ((void) 0) + + +#endif /* __ASSEMBLER__ */ + +#endif /* tls.h */ diff --git a/sysdeps/nacl/Implies b/sysdeps/nacl/Implies new file mode 100644 index 0000000000..f380b879a9 --- /dev/null +++ b/sysdeps/nacl/Implies @@ -0,0 +1,2 @@ +posix +gnu diff --git a/sysdeps/nacl/Makefile b/sysdeps/nacl/Makefile new file mode 100644 index 0000000000..43419821d0 --- /dev/null +++ b/sysdeps/nacl/Makefile @@ -0,0 +1,60 @@ +# The (required) --with-headers option to configure sets sysheaders to the +# location of the native_client/.. source directory. We'll get necessary +# headers directly from there. +naclsrc = $(sysheaders)/native_client/src + +# How to find the directory containing this Makefile. +nacl = $(..)nacl-port/sysdeps/nacl + +# Generate our bits/errno.h with the numbers from NaCl's sys/errno.h file. +nacl-errno = $(naclsrc)/trusted/service_runtime/include/sys/errno.h + +bits-errno = $(common-objpfx)bits/errno.h +$(bits-errno): $(common-objpfx)stamp-errnos ; +$(common-objpfx)stamp-errnos: $(nacl)/errnos.awk $(..)manual/errno.texi \ + $(nacl-errno) + $(make-target-directory) + $(AWK) -f $^ > $(bits-errno)-tmp +# Make it unwritable so noone will edit it by mistake. + -chmod a-w $(bits-errno)-tmp + $(move-if-change) $(bits-errno)-tmp $(bits-errno) + touch $@ +common-generated += stamp-errnos bits/errno.h +before-compile += $(bits-errno) + +ifeq ($(subdir),misc) + +$(objpfx)nacl-interfaces.v.i: $(nacl)/nacl-interfaces.mk.in \ + $(nacl)/nacl-interface-list.h +-include $(objpfx)nacl-interfaces.v + +nacl-all-interfaces = $(nacl-mandatory-interfaces) $(nacl-optional-interfaces) +nacl-interface-routines = $(nacl-all-interfaces:%=nacl-interface-%) + +define nacl-interface-table-command +(echo '#define INTERFACE_CATEGORY $1'; \ + echo '#define INTERFACE_TYPE $*'; \ + echo '#define INTERFACE_STRING $(nacl-$*-string)'; \ + echo '#include "nacl-interface-table.c"' \ +) > $@T +mv -f $@T $@ +endef + +nacl-interface-pattern = $(objpfx)nacl-interface-%.c + +$(nacl-mandatory-interfaces:%=$(nacl-interface-pattern)): \ + $(nacl-interface-pattern): $(nacl)/Makefile + $(make-target-directory) + $(call nacl-interface-table-command,mandatory) +$(nacl-optional-interfaces:%=$(nacl-interface-pattern)): \ + $(nacl-interface-pattern): $(nacl)/Makefile + $(make-target-directory) + $(call nacl-interface-table-command,optional) + +sysdep_routines += nacl_interface_query \ + nacl-interfaces $(nacl-interface-routines) + +# XXX temp test +others += hello + +endif diff --git a/sysdeps/nacl/Versions b/sysdeps/nacl/Versions new file mode 100644 index 0000000000..49e98561dc --- /dev/null +++ b/sysdeps/nacl/Versions @@ -0,0 +1,5 @@ +libc { + GLIBC_2.17 { + nacl_interface_query; + } +} diff --git a/sysdeps/nacl/____longjmp_chk.c b/sysdeps/nacl/____longjmp_chk.c new file mode 100644 index 0000000000..657dd9655a --- /dev/null +++ b/sysdeps/nacl/____longjmp_chk.c @@ -0,0 +1,28 @@ +/* Fortified longjmp. Stub version. + Copyright (C) 2013 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 <setjmp.h> + +/* We don't have any way to validate the stack pointer. + So we just do a vanilla longjmp. */ +void +__attribute__ ((__noreturn__)) +____longjmp_chk (__jmp_buf env, int val) +{ + __longjmp (env, val); +} diff --git a/sysdeps/nacl/_exit.c b/sysdeps/nacl/_exit.c new file mode 100644 index 0000000000..56f58a2340 --- /dev/null +++ b/sysdeps/nacl/_exit.c @@ -0,0 +1,31 @@ +/* _exit -- low-level program termination. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <stdlib.h> +#include <nacl-interfaces.h> + +void +_exit (int status) +{ + __nacl_irt_basic.exit (status); + while (1) + __builtin_trap (); +} +libc_hidden_def (_exit) +weak_alias (_exit, _Exit) diff --git a/sysdeps/nacl/bits/dirent.h b/sysdeps/nacl/bits/dirent.h new file mode 100644 index 0000000000..3fb19c3eab --- /dev/null +++ b/sysdeps/nacl/bits/dirent.h @@ -0,0 +1,52 @@ +/* Directory entry structure `struct dirent'. NaCl version. + Copyright (C) 2012 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/>. */ + +#ifndef _DIRENT_H +# error "Never use <bits/dirent.h> directly; include <dirent.h> instead." +#endif + +/* Note that __ino_t and __ino64_t are the same type. + Likewise __off_t and __off64_t are the same type. */ + +struct dirent + { + __ino_t d_ino; /* File serial number. */ + __off_t d_off; /* File position of this entry. */ + unsigned short int d_reclen; /* Length of the whole `struct dirent'. */ + + /* Only this member is in the POSIX standard. */ + char d_name[256]; /* We must not include limits.h! */ + }; + +#ifdef __USE_LARGEFILE64 +/* This is completely identical to `struct dirent'. */ +struct dirent64 + { + __ino_t d_ino; /* File serial number. */ + __off_t d_off; /* File position of this entry. */ + unsigned short int d_reclen; /* Length of the whole `struct dirent'. */ + + /* Only this member is in the POSIX standard. */ + char d_name[256]; /* We must not include limits.h! */ + }; +#endif + +#define d_fileno d_ino /* Backwards compatibility. */ + +#define _DIRENT_HAVE_D_RECLEN 1 +#define _DIRENT_MATCHES_DIRENT64 1 diff --git a/sysdeps/nacl/bits/param.h b/sysdeps/nacl/bits/param.h new file mode 100644 index 0000000000..17eb1ee43f --- /dev/null +++ b/sysdeps/nacl/bits/param.h @@ -0,0 +1,23 @@ +/* Old-style Unix parameters and limits. NaCl version. + Copyright (C) 2012 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/>. */ + +#ifndef _SYS_PARAM_H +# error "Never use <bits/param.h> directly; include <sys/param.h> instead." +#endif + +#define EXEC_PAGESIZE 0x10000 diff --git a/sysdeps/nacl/bits/typesizes.h b/sysdeps/nacl/bits/typesizes.h new file mode 100644 index 0000000000..c1934b8d4c --- /dev/null +++ b/sysdeps/nacl/bits/typesizes.h @@ -0,0 +1,71 @@ +/* bits/typesizes.h -- underlying types for *_t. NaCl version. + Copyright (C) 2002-2012 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/>. */ + +#ifndef _BITS_TYPES_H +# error "Never include <bits/typesizes.h> directly; use <sys/types.h> instead." +#endif + +#ifndef _BITS_TYPESIZES_H +#define _BITS_TYPESIZES_H 1 + +/* See <bits/types.h> for the meaning of these macros. This file exists so + that <bits/types.h> need not vary across different GNU platforms. */ + +#define __DEV_T_TYPE __UQUAD_TYPE +#define __UID_T_TYPE __U32_TYPE +#define __GID_T_TYPE __U32_TYPE +#define __INO_T_TYPE __UQUAD_TYPE +#define __INO64_T_TYPE __INO_T_TYPE +#define __MODE_T_TYPE __U32_TYPE +#define __NLINK_T_TYPE __UWORD_TYPE +#define __OFF_T_TYPE __SQUAD_TYPE +#define __OFF64_T_TYPE __OFF_T_TYPE +#define __PID_T_TYPE __S32_TYPE +#define __RLIM_T_TYPE __UQUAD_TYPE +#define __RLIM64_T_TYPE __RLIM_T_TYPE +#define __BLKCNT_T_TYPE __SQUAD_TYPE +#define __BLKCNT64_T_TYPE __BLKCNT_T_TYPE +#define __FSBLKCNT_T_TYPE __UQUAD_TYPE +#define __FSBLKCNT64_T_TYPE __FSBLKCNT_T_TYPE +#define __FSFILCNT_T_TYPE __UQUAD_TYPE +#define __FSFILCNT64_T_TYPE __FSFILCNT_T_TYPE +#define __FSWORD_T_TYPE __SWORD_TYPE +#define __ID_T_TYPE __U32_TYPE +#define __CLOCK_T_TYPE __SQUAD_TYPE +#define __TIME_T_TYPE __SQUAD_TYPE +#define __USECONDS_T_TYPE __U32_TYPE +#define __SUSECONDS_T_TYPE __S32_TYPE +#define __DADDR_T_TYPE __S32_TYPE +#define __KEY_T_TYPE __S32_TYPE +#define __CLOCKID_T_TYPE __S32_TYPE +#define __TIMER_T_TYPE void * +#define __BLKSIZE_T_TYPE __SLONGWORD_TYPE +#define __FSID_T_TYPE struct { int __val[2]; } +#define __SSIZE_T_TYPE __SWORD_TYPE +#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE +#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE + +/* All our foo64_t types match their foo_t counterparts. */ +#define __OFF_T_MATCHES_OFF64_T 1 +#define __INO_T_MATCHES_INO64_T 1 + +/* Number of descriptors that can fit in an `fd_set'. */ +#define __FD_SETSIZE 1024 + + +#endif /* bits/typesizes.h */ diff --git a/sysdeps/nacl/brk.c b/sysdeps/nacl/brk.c new file mode 100644 index 0000000000..8bb716d430 --- /dev/null +++ b/sysdeps/nacl/brk.c @@ -0,0 +1,41 @@ +/* brk -- Adjust the "break" at the end of initial data. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include "nacl-interfaces.h" + +/* sbrk.c expects this. */ +void *__curbrk; + +/* Set the end of the process's data space to ADDR. + Return 0 if successful, -1 if not. */ +int +__brk (void *addr) +{ + int error = __nacl_irt_memory_v0_2.sysbrk (&addr); + if (__glibc_unlikely (error)) + { + __set_errno (error); + return -1; + } + + __curbrk = addr; + return 0; +} +weak_alias (__brk, brk) diff --git a/sysdeps/nacl/check_fds.c b/sysdeps/nacl/check_fds.c new file mode 100644 index 0000000000..2a86771f8b --- /dev/null +++ b/sysdeps/nacl/check_fds.c @@ -0,0 +1,23 @@ +/* Check inherited file descriptors for sanity at startup. NaCl version. + Copyright (C) 2013 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/>. */ + +/* Nothing to do here. */ +void +__libc_check_standard_fds (void) +{ +} diff --git a/sysdeps/nacl/clock.c b/sysdeps/nacl/clock.c new file mode 100644 index 0000000000..196608f28a --- /dev/null +++ b/sysdeps/nacl/clock.c @@ -0,0 +1,29 @@ +/* Return the time used by the program so far. NaCl version. + Copyright (C) 2013 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 <time.h> +#include <nacl-interfaces.h> + + +/* Return the time used by the program so far (user time + system time). */ +clock_t +clock (void) +{ + clock_t result; + return NACL_CALL (__nacl_irt_basic.clock (&result), result); +} diff --git a/sysdeps/nacl/clock_getres.c b/sysdeps/nacl/clock_getres.c new file mode 100644 index 0000000000..a67e425f9d --- /dev/null +++ b/sysdeps/nacl/clock_getres.c @@ -0,0 +1,28 @@ +/* Get the resolution of a clock. NaCl version. + Copyright (C) 2013 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 <time.h> +#include <nacl-interfaces.h> + +/* Get resolution of clock. */ +int +__clock_getres (clockid_t clock_id, struct timespec *res) +{ + return NACL_CALL (__nacl_irt_clock.clock_getres (clock_id, res), 0); +} +weak_alias (__clock_getres, clock_getres) diff --git a/sysdeps/nacl/clock_gettime.c b/sysdeps/nacl/clock_gettime.c new file mode 100644 index 0000000000..8235de25fa --- /dev/null +++ b/sysdeps/nacl/clock_gettime.c @@ -0,0 +1,28 @@ +/* Get the current value of a clock. NaCl version. + Copyright (C) 2013 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 <time.h> +#include <nacl-interfaces.h> + +/* Get current value of CLOCK and store it in TP. */ +int +__clock_gettime (clockid_t clock_id, struct timespec *tp) +{ + return NACL_CALL (__nacl_irt_clock.clock_getres (clock_id, tp), 0); +} +weak_alias (__clock_gettime, clock_gettime) diff --git a/sysdeps/nacl/close.c b/sysdeps/nacl/close.c new file mode 100644 index 0000000000..8412092184 --- /dev/null +++ b/sysdeps/nacl/close.c @@ -0,0 +1,30 @@ +/* Close a file descriptor. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + + +/* Close the file descriptor FD. */ +int +__close (int fd) +{ + return NACL_CALL (__nacl_irt_fdio.close (fd), 0); +} +libc_hidden_def (__close) +weak_alias (__close, close) diff --git a/sysdeps/nacl/configure b/sysdeps/nacl/configure new file mode 100644 index 0000000000..6e9060a9ec --- /dev/null +++ b/sysdeps/nacl/configure @@ -0,0 +1,18 @@ +# This file is generated from configure.in by Autoconf. DO NOT EDIT! + # Local configure fragment for sysdeps/nacl. + +nacl_probe_file=native_client/src/trusted/service_runtime/include/sys/errno.h + +# sysheaders is set by the --with-headers=... option to configure. +# For NaCl, we require that the option be given and point to the +# native_client/.. source tree directory. +test -n "$sysheaders" || { + as_fn_error $? "must supply --with-headers=DIR with native_client source tree" "$LINENO" 5 +} +test -r "$sysheaders/$nacl_probe_file" || { + as_fn_error $? "$sysheaders does not appear to be a native_client source tree" "$LINENO" 5 +} + +# nscd is extremely useless in the NaCl context. +build_nscd=no +use_nscd=no diff --git a/sysdeps/nacl/configure.in b/sysdeps/nacl/configure.in new file mode 100644 index 0000000000..2c6f29fe1b --- /dev/null +++ b/sysdeps/nacl/configure.in @@ -0,0 +1,18 @@ +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. +# Local configure fragment for sysdeps/nacl. + +nacl_probe_file=native_client/src/trusted/service_runtime/include/sys/errno.h + +# sysheaders is set by the --with-headers=... option to configure. +# For NaCl, we require that the option be given and point to the +# native_client/.. source tree directory. +test -n "$sysheaders" || { + AC_MSG_ERROR([must supply --with-headers=DIR with native_client source tree]) +} +test -r "$sysheaders/$nacl_probe_file" || { + AC_MSG_ERROR([$sysheaders does not appear to be a native_client source tree]) +} + +# nscd is extremely useless in the NaCl context. +build_nscd=no +use_nscd=no diff --git a/sysdeps/nacl/dl-osinfo.h b/sysdeps/nacl/dl-osinfo.h new file mode 100644 index 0000000000..505eb4ba86 --- /dev/null +++ b/sysdeps/nacl/dl-osinfo.h @@ -0,0 +1,33 @@ +/* DL_SYSDEP_OSCHECK macro for NaCl. + Copyright (C) 2013 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/>. */ + +#ifndef _DL_OSINFO_H +#define _DL_OSINFO_H 1 + +#include <sysdeps/generic/dl-osinfo.h> + +#include "nacl-interfaces.h" + +/* This doesn't really have anything to do with the purpose for + which this macro is used in Linux configurations. But it is + called at the right place in __libc_start_main. */ + +#define DL_SYSDEP_OSCHECK(fatal) __nacl_initialize_interfaces () + + +#endif /* dl-osinfo.h */ diff --git a/sysdeps/nacl/dl-sysdep.h b/sysdeps/nacl/dl-sysdep.h new file mode 100644 index 0000000000..19c23cb0ac --- /dev/null +++ b/sysdeps/nacl/dl-sysdep.h @@ -0,0 +1,27 @@ +/* System-specific settings for dynamic linker code. NaCl version. + Copyright (C) 2013 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/>. */ + +/* No multiple inclusion protection needed here because it's just macros. + We don't want to use _DL_SYSDEP_H in case we are #include_next'd. */ + +#include_next <dl-sysdep.h> + +/* We use AT_SYSINFO for a different purpose than Linux does, + but we too want to store its value. */ +#define NEED_DL_SYSINFO 1 +#define DL_SYSINFO_DEFAULT 0 diff --git a/sysdeps/nacl/dup.c b/sysdeps/nacl/dup.c new file mode 100644 index 0000000000..7318da8389 --- /dev/null +++ b/sysdeps/nacl/dup.c @@ -0,0 +1,30 @@ +/* Duplicate a file descriptor. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + + +/* Duplicate FD, returning a new file descriptor open on the same file. */ +int +__dup (int fd) +{ + int result; + return NACL_CALL (__nacl_irt_fdio.dup (fd, &result), result); +} +weak_alias (__dup, dup) diff --git a/sysdeps/nacl/dup2.c b/sysdeps/nacl/dup2.c new file mode 100644 index 0000000000..bad77ee540 --- /dev/null +++ b/sysdeps/nacl/dup2.c @@ -0,0 +1,31 @@ +/* Duplicate a file descriptor to a chosen number. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + + +/* Duplicate FD to FD2, closing the old FD2 and making FD2 be + open the same file as FD is. Return FD2 or -1. */ +int +__dup2 (int fd, int fd2) +{ + return NACL_CALL (__nacl_irt_fdio.dup2 (fd, fd2), fd2); +} +libc_hidden_def (__dup2) +weak_alias (__dup2, dup2) diff --git a/sysdeps/nacl/errnos.awk b/sysdeps/nacl/errnos.awk new file mode 100644 index 0000000000..35f29719ea --- /dev/null +++ b/sysdeps/nacl/errnos.awk @@ -0,0 +1,68 @@ +BEGIN { maxerrno = 0 } + +$1 == "#define" && $2 ~ /NACL_ABI_E[A-Z0-9_]+/ && $3 ~ /[0-9]+/ { + ename = $2; + sub(/NACL_ABI_/, "", ename); + errno = $3 + 0; + if (errno > maxerrno) maxerrno = errno; + errnos[errno] = ename; + errnos_by_name[ename] = errno; + if ($4 == "/*" && !(ename in errno_text)) { + etext = $5; + for (i = 6; i <= NF && $i != "*/"; ++i) + etext = etext " " $i; + errno_text[ename] = etext; + } + next; +} + +$1 == "@comment" && $2 == "errno.h" { errnoh=1; next } +errnoh == 1 && $1 == "@comment" { + ++errnoh; + etext = $3; + for (i = 4; i <= NF; ++i) + etext = etext " " $i; + next; +} +errnoh == 2 && $1 == "@deftypevr" && $2 == "Macro" && $3 == "int" { + ename = $4; + errno_text[ename] = etext; + next; +} + +function define_errno(errno, ename) { + etext = errno_text[ename]; + if (length(ename) < 8) ename = ename "\t"; + printf "#define\t%s\t%d\t/* %s */\n", ename, errno, etext; +} + +END { + print "\ +/* This file generated by errnos.awk. */\n\ +\n\ +#if !defined __Emath_defined && (defined _ERRNO_H || defined __need_Emath)\n\ +#undef __need_Emath\n\ +#define __Emath_defined 1"; + emath["EDOM"] = emath["EILSEQ"] = emath["ERANGE"] = 1; + for (ename in emath) { + errno = errnos_by_name[ename]; + define_errno(errno, ename); + delete errnos[errno]; + } + print "\ +#endif\n\ +\n\ +#ifdef _ERRNO_H\n"; + + for (i = 1; i <= maxerrno; ++i) + if (i in errnos) define_errno(i, errnos[i]); + + print "\n\ +#define EWOULDBLOCK EAGAIN\n\ +#define ENOTSUP EOPNOTSUPP\n\ +\n\ +extern __thread int errno;\n\ +#define errno errno\n\ +\n\ +#endif"; +} diff --git a/sysdeps/nacl/getdents.c b/sysdeps/nacl/getdents.c new file mode 100644 index 0000000000..dd7a7c57c0 --- /dev/null +++ b/sysdeps/nacl/getdents.c @@ -0,0 +1,29 @@ +/* Read directory entries from a file descriptor. NaCl version. + Copyright (C) 2013 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 <dirent.h> +#include <nacl-interfaces.h> + +ssize_t +internal_function +__getdents (int fd, char *buf, size_t nbytes) +{ + size_t nread; + return NACL_CALL (__nacl_irt_fdio.getdents (fd, (void *) buf, nbytes, &nread), + nread); +} diff --git a/sysdeps/nacl/getdents64.c b/sysdeps/nacl/getdents64.c new file mode 100644 index 0000000000..730861899c --- /dev/null +++ b/sysdeps/nacl/getdents64.c @@ -0,0 +1 @@ +/* We do not define a getdirentries or getdirentries64 entry point at all. */ diff --git a/sysdeps/nacl/getdtsz.c b/sysdeps/nacl/getdtsz.c new file mode 100644 index 0000000000..dda3c2d3e0 --- /dev/null +++ b/sysdeps/nacl/getdtsz.c @@ -0,0 +1,28 @@ +/* getdtablesize -- Return the limit on file descriptor values. NaCl version. + Copyright (C) 2013 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 <unistd.h> + +/* Return the maximum number of file descriptors + the current process could possibly have. */ +int +__getdtablesize (void) +{ + /* There is no actual limit in NaCl, just memory. */ + return -1; +} diff --git a/sysdeps/nacl/gettimeofday.c b/sysdeps/nacl/gettimeofday.c new file mode 100644 index 0000000000..f15590c856 --- /dev/null +++ b/sysdeps/nacl/gettimeofday.c @@ -0,0 +1,40 @@ +/* Get the current wall clock time. NaCl version. + Copyright (C) 2013 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 <sys/time.h> +#include <nacl-interfaces.h> + + +/* Get the current time of day and timezone information, + putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. + Returns 0 on success, -1 on errors. */ +int +__gettimeofday (struct timeval *tv, struct timezone *tz) +{ + if (__glibc_unlikely (tz != NULL)) + { + errno = ENOTSUP; /* XXX ? */ + return -1; + } + + return NACL_CALL (__nacl_irt_basic.gettod (tv), 0); +} +libc_hidden_def (__gettimeofday) +weak_alias (__gettimeofday, gettimeofday) +libc_hidden_weak (gettimeofday) diff --git a/sysdeps/nacl/kernel-features.h b/sysdeps/nacl/kernel-features.h new file mode 100644 index 0000000000..21df0198e0 --- /dev/null +++ b/sysdeps/nacl/kernel-features.h @@ -0,0 +1,28 @@ +/* Set flags signalling availability of certain operating system features. + Copyright (C) 2013 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/>. */ + +/* This file can define __ASSUME_* macros checked by certain source files. + Almost none of these are used outside of sysdeps/unix/sysv/linux code. + But those referring to POSIX-level features like O_* flags can be. */ + +#define __ASSUME_O_CLOEXEC 1 + +/* +#define __ASSUME_DUP3 1 +#define __ASSUME_ACCEPT4 1 +*/ diff --git a/sysdeps/nacl/ldsodefs.h b/sysdeps/nacl/ldsodefs.h new file mode 100644 index 0000000000..785eee29e8 --- /dev/null +++ b/sysdeps/nacl/ldsodefs.h @@ -0,0 +1,35 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. NaCl. + Copyright (C) 2013 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/>. */ + +#ifndef _LDSODEFS_H + +/* Get the real definitions. */ +#include_next <ldsodefs.h> + +/* Now define our stuff. */ + +/* We have the auxiliary vector. */ +#define HAVE_AUX_VECTOR + +/* Used by static binaries to check the auxiliary vector. */ +extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function; + +/* Initialization which is normally done by the dynamic linker. */ +extern void _dl_non_dynamic_init (void) internal_function; + +#endif /* ldsodefs.h */ diff --git a/sysdeps/nacl/libc-start.c b/sysdeps/nacl/libc-start.c new file mode 100644 index 0000000000..dadd18037a --- /dev/null +++ b/sysdeps/nacl/libc-start.c @@ -0,0 +1,4 @@ +/* We can compute the location of auxv without a loop, so we might as well + pass it in. */ +#define LIBC_START_MAIN_AUXVEC_ARG +#include <csu/libc-start.c> diff --git a/sysdeps/nacl/lseek.c b/sysdeps/nacl/lseek.c new file mode 100644 index 0000000000..bebd523dc5 --- /dev/null +++ b/sysdeps/nacl/lseek.c @@ -0,0 +1,43 @@ +/* lseek -- Move the file position of a file descriptor. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + + +/* Seek to OFFSET on FD, starting from WHENCE. */ +off_t +__libc_lseek (int fd, off_t offset, int whence) +{ + off_t result; + int error = __nacl_irt_fdio.seek (fd, offset, whence, &result); + if (error) + { + __set_errno (error); + return -1; + } + return result; +} +libc_hidden_def (__lseek) +weak_alias (__libc_lseek, __lseek) +weak_alias (__libc_lseek, lseek) + +/* Since off64_t is the same as off_t, lseek64 is just an alias. */ +weak_alias (__libc_lseek, __libc_lseek64) +weak_alias (__libc_lseek, __lseek64) +weak_alias (__libc_lseek, lseek64) diff --git a/sysdeps/nacl/lseek64.c b/sysdeps/nacl/lseek64.c new file mode 100644 index 0000000000..6f42ee6584 --- /dev/null +++ b/sysdeps/nacl/lseek64.c @@ -0,0 +1 @@ +/* lseek.c defines lseek64 as an alias. */ diff --git a/sysdeps/nacl/mmap.c b/sysdeps/nacl/mmap.c new file mode 100644 index 0000000000..270cdfb4a8 --- /dev/null +++ b/sysdeps/nacl/mmap.c @@ -0,0 +1,49 @@ +/* Map addresses from a file or anonymous memory. NaCl version. + Copyright (C) 2013 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 <sys/mman.h> +#include <nacl-interfaces.h> + + +/* Map addresses starting near ADDR and extending for LEN bytes. From + OFFSET into the file FD describes according to PROT and FLAGS. If ADDR + is nonzero, it is the desired mapping address. If the MAP_FIXED bit is + set in FLAGS, the mapping will be at ADDR exactly (which must be + page-aligned); otherwise the system chooses a convenient nearby address. + The return value is the actual mapping address chosen or MAP_FAILED + for errors (in which case `errno' is set). A successful `mmap' call + deallocates any previous mapping for the affected region. */ + +__ptr_t +__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + int error = __nacl_irt_memory_v0_2.mmap (&addr, len, prot, flags, fd, offset); + if (error) + { + errno = error; + return MAP_FAILED; + } + return addr; +} +weak_alias (__mmap, mmap) + + +/* Since off64_t is the same as off_t, mmap64 is just an alias. */ +strong_alias (__mmap, __mmap64) +weak_alias (__mmap, mmap64) diff --git a/sysdeps/nacl/mmap64.c b/sysdeps/nacl/mmap64.c new file mode 100644 index 0000000000..e8775a6931 --- /dev/null +++ b/sysdeps/nacl/mmap64.c @@ -0,0 +1 @@ +/* mmap.c defines mmap64 as an alias. */ diff --git a/sysdeps/nacl/mprotect.c b/sysdeps/nacl/mprotect.c new file mode 100644 index 0000000000..648c102017 --- /dev/null +++ b/sysdeps/nacl/mprotect.c @@ -0,0 +1,33 @@ +/* Change memory protections on pages. NaCl version. + Copyright (C) 2013 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 <sys/types.h> +#include <sys/mman.h> +#include <nacl-interfaces.h> + + +/* Change the memory protection of the region starting at ADDR and + extending LEN bytes to PROT. Returns 0 if successful, -1 for errors + (and sets errno). */ + +int +__mprotect (__ptr_t addr, size_t len, int prot) +{ + return NACL_CALL (__nacl_irt_memory_v0_2.mprotect (addr, len, prot), 0); +} +weak_alias (__mprotect, mprotect) diff --git a/sysdeps/nacl/munmap.c b/sysdeps/nacl/munmap.c new file mode 100644 index 0000000000..d079ad33b1 --- /dev/null +++ b/sysdeps/nacl/munmap.c @@ -0,0 +1,32 @@ +/* Deallocate a region of pages. NaCl version. + Copyright (C) 2013 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 <sys/mman.h> +#include <nacl-interfaces.h> + + +/* Deallocate any mapping for the region starting at ADDR and extending LEN + bytes. Returns 0 if successful, -1 for errors (and sets errno). */ + +int +__munmap (__ptr_t addr, size_t len) +{ + return NACL_CALL (__nacl_irt_memory_v0_2.munmap (addr, len), 0); +} + +weak_alias (__munmap, munmap) diff --git a/sysdeps/nacl/nacl-interface-list.h b/sysdeps/nacl/nacl-interface-list.h new file mode 100644 index 0000000000..2f46b73bc6 --- /dev/null +++ b/sysdeps/nacl/nacl-interface-list.h @@ -0,0 +1,12 @@ +NACL_MANDATORY_INTERFACE (NACL_IRT_BASIC_v0_1, nacl_irt_basic) +NACL_MANDATORY_INTERFACE (NACL_IRT_FDIO_v0_1, nacl_irt_fdio) +NACL_MANDATORY_INTERFACE (NACL_IRT_FILENAME_v0_1, nacl_irt_filename) +NACL_MANDATORY_INTERFACE (NACL_IRT_MEMORY_v0_2, nacl_irt_memory_v0_2) +NACL_MANDATORY_INTERFACE (NACL_IRT_DYNCODE_v0_1, nacl_irt_dyncode) +NACL_MANDATORY_INTERFACE (NACL_IRT_THREAD_v0_1, nacl_irt_thread) +NACL_MANDATORY_INTERFACE (NACL_IRT_MUTEX_v0_1, nacl_irt_mutex) +NACL_MANDATORY_INTERFACE (NACL_IRT_COND_v0_1, nacl_irt_cond) +NACL_MANDATORY_INTERFACE (NACL_IRT_SEM_v0_1, nacl_irt_sem) +NACL_MANDATORY_INTERFACE (NACL_IRT_TLS_v0_1, nacl_irt_tls) +NACL_MANDATORY_INTERFACE (NACL_IRT_RESOURCE_OPEN_v0_1, nacl_irt_resource_open) +NACL_OPTIONAL_INTERFACE (NACL_IRT_CLOCK_v0_1, nacl_irt_clock) diff --git a/sysdeps/nacl/nacl-interface-table.c b/sysdeps/nacl/nacl-interface-table.c new file mode 100644 index 0000000000..a7e78b61eb --- /dev/null +++ b/sysdeps/nacl/nacl-interface-table.c @@ -0,0 +1,38 @@ +/* Define one NaCl interface table. + Copyright (C) 2013 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 "nacl-interfaces.h" + +#define PASTE(a, b) PASTE_1 (a, b) +#define PASTE_1(a, b) a##b +#define STRINGIFY(x) STRINGIFY_1 (x) +#define STRINGIFY_1(x) #x + +#define SECTION(which) \ + section ("nacl_" STRINGIFY (INTERFACE_CATEGORY) "_interface_" #which) + +static const struct nacl_interface PASTE (desc_, INTERFACE_TYPE) + __attribute__ ((used, SECTION (names))) = +{ + .table_size = sizeof (struct INTERFACE_TYPE), + .namelen = sizeof INTERFACE_STRING, + .name = INTERFACE_STRING +}; + +struct INTERFACE_TYPE PASTE (__, INTERFACE_TYPE) + __attribute__ ((SECTION (tables))); diff --git a/sysdeps/nacl/nacl-interfaces.c b/sysdeps/nacl/nacl-interfaces.c new file mode 100644 index 0000000000..95b722e080 --- /dev/null +++ b/sysdeps/nacl/nacl-interfaces.c @@ -0,0 +1,125 @@ +/* Using NaCl interface tables. + Copyright (C) 2013 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 <native_client/src/untrusted/irt/irt.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 == 0) + 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 (); +} diff --git a/sysdeps/nacl/nacl-interfaces.h b/sysdeps/nacl/nacl-interfaces.h new file mode 100644 index 0000000000..c4461f8e7d --- /dev/null +++ b/sysdeps/nacl/nacl-interfaces.h @@ -0,0 +1,72 @@ +/* Using NaCl interface tables. + Copyright (C) 2013 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/>. */ + +#ifndef _NACL_INTERFACES_H +#define _NACL_INTERFACES_H 1 + +#include <errno.h> +#include <stddef.h> +#include <stdint.h> +#include <ldsodefs.h> + +#include <native_client/src/untrusted/irt/irt.h> + +/* This is how we access the IRT interface-query function. + This formulation makes it usable as if it were a function name. */ +#define __nacl_irt_query (*(TYPE_nacl_irt_query) GLRO(dl_sysinfo)) + + +/* This describes one IRT (or IRT-like) interface that libc uses. + This structure contains no pointers, so it can go into rodata + without relocs. Instead, the actual tables we use for these + interfaces live in a parallel section in writable data. */ +struct nacl_interface { + size_t table_size; + size_t namelen; + char name[]; +}; + +/* Increment for 'const struct nacl_interface *' pointers. */ +static inline const struct nacl_interface * +next_nacl_interface (const struct nacl_interface *i) +{ + uintptr_t align = __alignof (*i); + return (const void *) (((uintptr_t) &i->name[i->namelen] + align - 1) + & -align); +} + +#define NACL_MANDATORY_INTERFACE(id, type) extern struct type __##type; +#define NACL_OPTIONAL_INTERFACE(id, type) extern struct type __##type; +#include "nacl-interface-list.h" +#undef NACL_MANDATORY_INTERFACE +#undef NACL_OPTIONAL_INTERFACE + +extern void __nacl_initialize_interfaces (void) attribute_hidden; + +/* Convenience function for handling IRT call return values. */ +static inline int +__nacl_fail (int err) +{ + errno = err; + return -1; +} + +#define NACL_CALL(err, val) \ + ({ int _err = (err); _err ? __nacl_fail (_err) : (val); }) + +#endif /* nacl-interfaces.h */ diff --git a/sysdeps/nacl/nacl-interfaces.mk.in b/sysdeps/nacl/nacl-interfaces.mk.in new file mode 100644 index 0000000000..5d8c36e99f --- /dev/null +++ b/sysdeps/nacl/nacl-interfaces.mk.in @@ -0,0 +1,22 @@ +/* Might as well be -*- C -*-. + This generates a makefile that sets the two variables + nacl-mandatory-interfaces and nacl-optional-interfaces + based on the nacl-interface-list.h list. */ + +%define NACL_MANDATORY_INTERFACE(id, type) \ + nacl-mandatory-interfaces += type +%define NACL_OPTIONAL_INTERFACE(id, type) \ + nacl-optional-interfaces += type + +%include "nacl-interface-list.h" + +%undef NACL_MANDATORY_INTERFACE +%undef NACL_OPTIONAL_INTERFACE + +%define NACL_MANDATORY_INTERFACE(id, type) nacl-type-string := id +%define NACL_OPTIONAL_INTERFACE(id, type) nacl-type-string := id + +%include "nacl-interface-list.h" + +%undef NACL_MANDATORY_INTERFACE +%undef NACL_OPTIONAL_INTERFACE diff --git a/sysdeps/nacl/nacl_interface_query.c b/sysdeps/nacl/nacl_interface_query.c new file mode 100644 index 0000000000..1bbe724637 --- /dev/null +++ b/sysdeps/nacl/nacl_interface_query.c @@ -0,0 +1,33 @@ +/* NaCl function exposing IRT interface query. + Copyright (C) 2013 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 <nacl-interfaces.h> + +/* We can define this trivially using IFUNC rather than a wrapper + because we absolutely require that we get the IRT interface query + function pointer via AT_SYSINFO. */ + +extern TYPE_nacl_irt_query nacl_interface_query_ifunc (void) + asm ("nacl_interface_query"); + +TYPE_nacl_irt_query +nacl_interface_query_ifunc (void) +{ + return &__nacl_irt_query; +} +asm (".type nacl_interface_query, %gnu_indirect_function"); diff --git a/sysdeps/nacl/nanosleep.c b/sysdeps/nacl/nanosleep.c new file mode 100644 index 0000000000..0758e48f8d --- /dev/null +++ b/sysdeps/nacl/nanosleep.c @@ -0,0 +1,33 @@ +/* nanosleep -- Sleep for a duration given in nanoseconds. NaCl version. + Copyright (C) 2013 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 <time.h> +#include <nacl-interfaces.h> + + +/* Pause execution for a number of nanoseconds. */ +int +__libc_nanosleep (const struct timespec *requested_time, + struct timespec *remaining) +{ + return NACL_CALL (__nacl_irt_basic.nanosleep (requested_time, remaining), 0); +} + +weak_alias (__libc_nanosleep, __nanosleep) +libc_hidden_def (__nanosleep) +weak_alias (__libc_nanosleep, nanosleep) diff --git a/sysdeps/nacl/open.c b/sysdeps/nacl/open.c new file mode 100644 index 0000000000..9ef5fe0d7e --- /dev/null +++ b/sysdeps/nacl/open.c @@ -0,0 +1,63 @@ +/* Open a file by name. NaCl version. + Copyright (C) 2013 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 <fcntl.h> +#include <stdarg.h> +#include <stdio.h> +#include <nacl-interfaces.h> + + +/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, + a third argument is the file protection. */ +int +__libc_open (const char *file, int oflag, ...) +{ + mode_t mode = 0; + + if (oflag & O_CREAT) + { + va_list arg; + va_start (arg, oflag); + mode = va_arg (arg, mode_t); + va_end (arg); + } + + int fd; + return NACL_CALL (__nacl_irt_filename.open (file, oflag, mode, &fd), fd); +} +libc_hidden_def (__libc_open) +weak_alias (__libc_open, __open) +libc_hidden_weak (__open) +weak_alias (__libc_open, open) + +/* open64 is just an alias. */ +strong_alias (__libc_open, __libc_open64) +strong_alias (__libc_open64, __open64) +libc_hidden_def (__open64) +weak_alias (__libc_open64, open64) + + +int +__open_2 (const char *file, int oflag) +{ + if (oflag & O_CREAT) + __fortify_fail ("invalid open call: O_CREAT without mode"); + + return __open (file, oflag); +} +strong_alias (__open_2, __open64_2) diff --git a/sysdeps/nacl/open64.c b/sysdeps/nacl/open64.c new file mode 100644 index 0000000000..b3e5563cd6 --- /dev/null +++ b/sysdeps/nacl/open64.c @@ -0,0 +1 @@ +/* open.c defines open64 as an alias. */ diff --git a/sysdeps/nacl/profil-counter.h b/sysdeps/nacl/profil-counter.h new file mode 100644 index 0000000000..b1d3bb6662 --- /dev/null +++ b/sysdeps/nacl/profil-counter.h @@ -0,0 +1,9 @@ +/* XXX */ + +#include <stdlib.h> + +static void +profil_counter (int signr, int code, struct sigcontext *scp) +{ + abort (); +} diff --git a/sysdeps/nacl/read.c b/sysdeps/nacl/read.c new file mode 100644 index 0000000000..4b32e04c48 --- /dev/null +++ b/sysdeps/nacl/read.c @@ -0,0 +1,32 @@ +/* read -- Read data from a file descriptor. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + +/* Read NBYTES into BUF from FD. Return the number read or -1. */ +ssize_t +__libc_read (int fd, void *buf, size_t nbytes) +{ + size_t nread; + return NACL_CALL (__nacl_irt_fdio.read (fd, buf, nbytes, &nread), nread); +} +libc_hidden_def (__libc_read) +weak_alias (__libc_read, __read) +libc_hidden_weak (__read) +weak_alias (__libc_read, read) diff --git a/sysdeps/nacl/readdir.c b/sysdeps/nacl/readdir.c new file mode 100644 index 0000000000..a73bfe42a5 --- /dev/null +++ b/sysdeps/nacl/readdir.c @@ -0,0 +1,11 @@ +/* The compiler complains about aliases with nonmatching type signatures. + The types 'struct dirent' and 'struct dirent64' are actually identical + even though the compiler doesn't consider them to be. So we hide the + declaration from the compiler. */ +#define __readdir64 __avoid___readdir64_declaration +#define readdir64 __avoid_readdir64_declaration +#include <sysdeps/posix/readdir.c> +#undef __readdir64 +#undef readdir64 +strong_alias (__readdir, __readdir64) +weak_alias (__readdir64, readdir64) diff --git a/sysdeps/nacl/readdir64.c b/sysdeps/nacl/readdir64.c new file mode 100644 index 0000000000..f4806bf269 --- /dev/null +++ b/sysdeps/nacl/readdir64.c @@ -0,0 +1 @@ +/* readdir.c defines readdir64 as an alias. */ diff --git a/sysdeps/nacl/readdir64_r.c b/sysdeps/nacl/readdir64_r.c new file mode 100644 index 0000000000..c7830de559 --- /dev/null +++ b/sysdeps/nacl/readdir64_r.c @@ -0,0 +1 @@ +/* readdir_r.c defines readdir64_r as an alias. */ diff --git a/sysdeps/nacl/readdir_r.c b/sysdeps/nacl/readdir_r.c new file mode 100644 index 0000000000..3a9a71703e --- /dev/null +++ b/sysdeps/nacl/readdir_r.c @@ -0,0 +1,8 @@ +/* The compiler complains about aliases with nonmatching type signatures. + The types 'struct dirent' and 'struct dirent64' are actually identical + even though the compiler doesn't consider them to be. So we hide the + declaration from the compiler. */ +#define readdir64_r __avoid_readdir64_r_declaration +#include <sysdeps/posix/readdir_r.c> +#undef readdir64_r +weak_alias (__readdir_r, readdir64_r) diff --git a/sysdeps/nacl/sched_yield.c b/sysdeps/nacl/sched_yield.c new file mode 100644 index 0000000000..4c6bfe258c --- /dev/null +++ b/sysdeps/nacl/sched_yield.c @@ -0,0 +1,31 @@ +/* sched_yield -- Yield the processor. NaCl version. + Copyright (C) 2013 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 <sched.h> +#include <nacl-interfaces.h> + + +/* Yield the processor. */ +int +__sched_yield (void) +{ + return NACL_CALL (__nacl_irt_basic.sched_yield (), 0); +} +libc_hidden_def (__sched_yield) +weak_alias (__sched_yield, sched_yield) diff --git a/sysdeps/nacl/shlib-versions b/sysdeps/nacl/shlib-versions new file mode 100644 index 0000000000..92b4234df7 --- /dev/null +++ b/sysdeps/nacl/shlib-versions @@ -0,0 +1,17 @@ +# Configuration DEFAULT Earliest symbol set +# ------------- --------------- ------------------------------ +.*-.*-nacl.* DEFAULT GLIBC_2.17 + +# Configuration ABI Identifier for ABI data files +# ------------- ---------- ----------------------------- +.*-.*-nacl.* ABI nacl + +# Configuration Library=version Earliest symbol set (optional) +# ------------- --------------- ------------------------------ + +.*-.*-nacl.* libc=1 +.*-.*-nacl.* libm=1 + +arm.*-.*-nacl.* ld=ld-nacl-arm.so.1 +i.86-.*-nacl.* ld=ld-nacl-x86-32.so.1 +x86_64-.*-nacl.* ld=ld-nacl-x86-64.so.1 diff --git a/sysdeps/nacl/start.c b/sysdeps/nacl/start.c new file mode 100644 index 0000000000..cd1e652a87 --- /dev/null +++ b/sysdeps/nacl/start.c @@ -0,0 +1,56 @@ +/* Entry-point for programs. NaCl version. + Copyright (C) 2013 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 <stdint.h> +#include <link.h> + +/* NaCl's elf32.h is incompatible with the real <elf.h>. */ +#define NATIVE_CLIENT_SRC_INCLUDE_ELF32_H_ +#include <native_client/src/untrusted/nacl/nacl_startup.h> + + +/* The application defines this, of course. */ +extern int main (int argc, char **argv, char **envp); + +/* These are defined in libc. */ +extern int __libc_csu_init (int argc, char **argv, char **envp); +extern void __libc_csu_fini (void); +extern void __libc_start_main (int (*main) (int, char **, char **), + int argc, char **argv, ElfW(auxv_t) *auxv, + int (*init) (int, char **, char **), + void (*fini) (void), + void (*rtld_fini) (void), + void *stack_end); + +void +_start (uint32_t info[]) +{ + /* The generic code actually assumes that envp follows argv. */ + + __libc_start_main (&main, + nacl_startup_argc (info), + nacl_startup_argv (info), + nacl_startup_auxv (info), + &__libc_csu_init, &__libc_csu_fini, + nacl_startup_fini (info), + __builtin_frame_address (0)); + + /* That should not return. Make sure we crash if it did. */ + while (1) + *(volatile int *) 0; +} diff --git a/sysdeps/nacl/write.c b/sysdeps/nacl/write.c new file mode 100644 index 0000000000..98602cfef3 --- /dev/null +++ b/sysdeps/nacl/write.c @@ -0,0 +1,33 @@ +/* write -- Write data to a file descriptor. NaCl version. + Copyright (C) 2013 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 <unistd.h> +#include <nacl-interfaces.h> + +/* Write NBYTES of BUF to FD. Return the number written, or -1. */ +ssize_t +__libc_write (int fd, const void *buf, size_t nbytes) +{ + size_t wrote; + return NACL_CALL (__nacl_irt_fdio.write (fd, buf, nbytes, &wrote), wrote); +} +libc_hidden_def (__libc_write) + +weak_alias (__libc_write, __write) +libc_hidden_weak (__write) +weak_alias (__libc_write, write) |