From d1e44df1fa5fefd8a083f6c1e909bbcdc97c6438 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 17 Apr 2015 09:02:19 -0700 Subject: Add arm-nacl port. --- ChangeLog | 7 + abi-tags | 2 + sysdeps/arm/nacl/Implies | 2 + sysdeps/arm/nacl/Makefile | 33 ++++ sysdeps/arm/nacl/____longjmp_chk.S | 47 ++++++ sysdeps/arm/nacl/aeabi_read_tp.S | 44 ++++++ sysdeps/arm/nacl/arm-features.h | 43 +++++ sysdeps/arm/nacl/dl-machine.h | 53 +++++++ sysdeps/arm/nacl/dl-trampoline.S | 278 ++++++++++++++++++++++++++++++++ sysdeps/arm/nacl/include/bits/setjmp.h | 38 +++++ sysdeps/arm/nacl/shlib-versions | 4 + sysdeps/arm/nacl/start.c | 1 + sysdeps/arm/nacl/sysdep.h | 69 ++++++++ sysdeps/arm/nacl/tls.h | 2 + sysdeps/nacl/Implies | 3 + sysdeps/nacl/Makefile | 135 ++++++++++++++++ sysdeps/nacl/Subdirs | 3 + sysdeps/nacl/Versions | 21 +++ sysdeps/nacl/_exit.c | 34 ++++ sysdeps/nacl/access.c | 28 ++++ sysdeps/nacl/backtrace.c | 1 + sysdeps/nacl/bits/dirent.h | 52 ++++++ sysdeps/nacl/bits/fcntl.h | 149 ++++++++++++++++++ sysdeps/nacl/bits/local_lim.h | 64 ++++++++ sysdeps/nacl/bits/mman.h | 24 +++ sysdeps/nacl/bits/param.h | 23 +++ sysdeps/nacl/bits/posix_opt.h | 210 +++++++++++++++++++++++++ sysdeps/nacl/bits/stat.h | 147 +++++++++++++++++ sysdeps/nacl/bits/typesizes.h | 71 +++++++++ sysdeps/nacl/brk.c | 93 +++++++++++ sysdeps/nacl/chdir.c | 28 ++++ sysdeps/nacl/check_fds.c | 23 +++ sysdeps/nacl/chmod.c | 28 ++++ sysdeps/nacl/clock.c | 29 ++++ sysdeps/nacl/clock_getres.c | 28 ++++ sysdeps/nacl/clock_gettime.c | 29 ++++ sysdeps/nacl/close.c | 31 ++++ sysdeps/nacl/configure | 18 +++ sysdeps/nacl/configure.ac | 18 +++ sysdeps/nacl/createthread.c | 46 ++++++ sysdeps/nacl/dl-map-segments.h | 238 ++++++++++++++++++++++++++++ sysdeps/nacl/dl-osinfo.h | 34 ++++ sysdeps/nacl/dl-sysdep.c | 89 +++++++++++ sysdeps/nacl/dl-sysdep.h | 30 ++++ sysdeps/nacl/dl-unmap-segments.h | 65 ++++++++ sysdeps/nacl/dl-writev.h | 45 ++++++ sysdeps/nacl/dup.c | 30 ++++ sysdeps/nacl/dup2.c | 31 ++++ sysdeps/nacl/entry.h | 6 + sysdeps/nacl/errnos.awk | 87 ++++++++++ sysdeps/nacl/euidaccess.c | 27 ++++ sysdeps/nacl/exit-thread.h | 35 +++++ sysdeps/nacl/fchdir.c | 28 ++++ sysdeps/nacl/fchmod.c | 28 ++++ sysdeps/nacl/fdatasync.c | 28 ++++ sysdeps/nacl/fork.c | 3 + sysdeps/nacl/fsync.c | 27 ++++ sysdeps/nacl/ftruncate.c | 32 ++++ sysdeps/nacl/ftruncate64.c | 1 + sysdeps/nacl/fxstat.c | 45 ++++++ sysdeps/nacl/fxstat64.c | 1 + sysdeps/nacl/getcwd.c | 56 +++++++ sysdeps/nacl/getdents.c | 29 ++++ sysdeps/nacl/getdents64.c | 1 + sysdeps/nacl/getdtsz.c | 28 ++++ sysdeps/nacl/getpagesize.c | 1 + sysdeps/nacl/getpid.c | 32 ++++ sysdeps/nacl/getsysstats.c | 65 ++++++++ sysdeps/nacl/gettimeofday.c | 40 +++++ sysdeps/nacl/glob.c | 26 +++ sysdeps/nacl/glob64.c | 1 + sysdeps/nacl/ifaddrs.c | 2 + sysdeps/nacl/init-first.c | 27 ++++ sysdeps/nacl/iofdopen.c | 26 +++ sysdeps/nacl/irt.sed | 12 ++ sysdeps/nacl/isatty.c | 38 +++++ sysdeps/nacl/kernel-features.h | 28 ++++ sysdeps/nacl/ldsodefs.h | 35 +++++ sysdeps/nacl/libc-start.c | 4 + sysdeps/nacl/link.c | 28 ++++ sysdeps/nacl/lowlevellock-futex.h | 87 ++++++++++ sysdeps/nacl/lseek.c | 43 +++++ sysdeps/nacl/lseek64.c | 1 + sysdeps/nacl/lxstat.c | 46 ++++++ sysdeps/nacl/lxstat64.c | 1 + sysdeps/nacl/mkdir.c | 28 ++++ sysdeps/nacl/mmap.c | 49 ++++++ sysdeps/nacl/mmap64.c | 1 + sysdeps/nacl/mprotect.c | 33 ++++ sysdeps/nacl/munmap.c | 32 ++++ sysdeps/nacl/nacl-after-link.sh | 69 ++++++++ sysdeps/nacl/nacl-interface-list.h | 47 ++++++ sysdeps/nacl/nacl-interface-table.c | 43 +++++ sysdeps/nacl/nacl-interfaces.c | 123 +++++++++++++++ sysdeps/nacl/nacl-interfaces.h | 108 +++++++++++++ sysdeps/nacl/nacl-interfaces.mk.in | 25 +++ sysdeps/nacl/nacl-test-wrapper.sh | 280 +++++++++++++++++++++++++++++++++ sysdeps/nacl/nacl_interface_query.c | 49 ++++++ sysdeps/nacl/nanosleep.c | 33 ++++ sysdeps/nacl/open.c | 52 ++++++ sysdeps/nacl/open64.c | 1 + sysdeps/nacl/preconfigure | 7 + sysdeps/nacl/profil.c | 2 + sysdeps/nacl/read.c | 32 ++++ sysdeps/nacl/readdir.c | 11 ++ sysdeps/nacl/readdir64.c | 1 + sysdeps/nacl/readdir64_r.c | 1 + sysdeps/nacl/readdir_r.c | 8 + sysdeps/nacl/readlink.c | 32 ++++ sysdeps/nacl/rename.c | 27 ++++ sysdeps/nacl/rmdir.c | 28 ++++ sysdeps/nacl/sched_yield.c | 31 ++++ sysdeps/nacl/shlib-versions | 9 ++ sysdeps/nacl/sigaction.c | 11 ++ sysdeps/nacl/sprofil.c | 2 + sysdeps/nacl/start.c | 73 +++++++++ sysdeps/nacl/symlink.c | 28 ++++ sysdeps/nacl/tls.h | 41 +++++ sysdeps/nacl/truncate.c | 32 ++++ sysdeps/nacl/truncate64.c | 1 + sysdeps/nacl/unlink.c | 28 ++++ sysdeps/nacl/utimes.c | 29 ++++ sysdeps/nacl/write.c | 33 ++++ sysdeps/nacl/xstat.c | 45 ++++++ sysdeps/nacl/xstat64.c | 1 + sysdeps/nacl/xstatconv.c | 76 +++++++++ sysdeps/nacl/xstatconv.h | 32 ++++ 127 files changed, 5120 insertions(+) create mode 100644 sysdeps/arm/nacl/Implies create mode 100644 sysdeps/arm/nacl/Makefile create mode 100644 sysdeps/arm/nacl/____longjmp_chk.S create mode 100644 sysdeps/arm/nacl/aeabi_read_tp.S create mode 100644 sysdeps/arm/nacl/arm-features.h create mode 100644 sysdeps/arm/nacl/dl-machine.h create mode 100644 sysdeps/arm/nacl/dl-trampoline.S create mode 100644 sysdeps/arm/nacl/include/bits/setjmp.h create mode 100644 sysdeps/arm/nacl/shlib-versions create mode 100644 sysdeps/arm/nacl/start.c create mode 100644 sysdeps/arm/nacl/sysdep.h create mode 100644 sysdeps/arm/nacl/tls.h create mode 100644 sysdeps/nacl/Implies create mode 100644 sysdeps/nacl/Makefile create mode 100644 sysdeps/nacl/Subdirs create mode 100644 sysdeps/nacl/Versions create mode 100644 sysdeps/nacl/_exit.c create mode 100644 sysdeps/nacl/access.c create mode 100644 sysdeps/nacl/backtrace.c create mode 100644 sysdeps/nacl/bits/dirent.h create mode 100644 sysdeps/nacl/bits/fcntl.h create mode 100644 sysdeps/nacl/bits/local_lim.h create mode 100644 sysdeps/nacl/bits/mman.h create mode 100644 sysdeps/nacl/bits/param.h create mode 100644 sysdeps/nacl/bits/posix_opt.h create mode 100644 sysdeps/nacl/bits/stat.h create mode 100644 sysdeps/nacl/bits/typesizes.h create mode 100644 sysdeps/nacl/brk.c create mode 100644 sysdeps/nacl/chdir.c create mode 100644 sysdeps/nacl/check_fds.c create mode 100644 sysdeps/nacl/chmod.c create mode 100644 sysdeps/nacl/clock.c create mode 100644 sysdeps/nacl/clock_getres.c create mode 100644 sysdeps/nacl/clock_gettime.c create mode 100644 sysdeps/nacl/close.c create mode 100644 sysdeps/nacl/configure create mode 100644 sysdeps/nacl/configure.ac create mode 100644 sysdeps/nacl/createthread.c create mode 100644 sysdeps/nacl/dl-map-segments.h create mode 100644 sysdeps/nacl/dl-osinfo.h create mode 100644 sysdeps/nacl/dl-sysdep.c create mode 100644 sysdeps/nacl/dl-sysdep.h create mode 100644 sysdeps/nacl/dl-unmap-segments.h create mode 100644 sysdeps/nacl/dl-writev.h create mode 100644 sysdeps/nacl/dup.c create mode 100644 sysdeps/nacl/dup2.c create mode 100644 sysdeps/nacl/entry.h create mode 100644 sysdeps/nacl/errnos.awk create mode 100644 sysdeps/nacl/euidaccess.c create mode 100644 sysdeps/nacl/exit-thread.h create mode 100644 sysdeps/nacl/fchdir.c create mode 100644 sysdeps/nacl/fchmod.c create mode 100644 sysdeps/nacl/fdatasync.c create mode 100644 sysdeps/nacl/fork.c create mode 100644 sysdeps/nacl/fsync.c create mode 100644 sysdeps/nacl/ftruncate.c create mode 100644 sysdeps/nacl/ftruncate64.c create mode 100644 sysdeps/nacl/fxstat.c create mode 100644 sysdeps/nacl/fxstat64.c create mode 100644 sysdeps/nacl/getcwd.c create mode 100644 sysdeps/nacl/getdents.c create mode 100644 sysdeps/nacl/getdents64.c create mode 100644 sysdeps/nacl/getdtsz.c create mode 100644 sysdeps/nacl/getpagesize.c create mode 100644 sysdeps/nacl/getpid.c create mode 100644 sysdeps/nacl/getsysstats.c create mode 100644 sysdeps/nacl/gettimeofday.c create mode 100644 sysdeps/nacl/glob.c create mode 100644 sysdeps/nacl/glob64.c create mode 100644 sysdeps/nacl/ifaddrs.c create mode 100644 sysdeps/nacl/init-first.c create mode 100644 sysdeps/nacl/iofdopen.c create mode 100644 sysdeps/nacl/irt.sed create mode 100644 sysdeps/nacl/isatty.c create mode 100644 sysdeps/nacl/kernel-features.h create mode 100644 sysdeps/nacl/ldsodefs.h create mode 100644 sysdeps/nacl/libc-start.c create mode 100644 sysdeps/nacl/link.c create mode 100644 sysdeps/nacl/lowlevellock-futex.h create mode 100644 sysdeps/nacl/lseek.c create mode 100644 sysdeps/nacl/lseek64.c create mode 100644 sysdeps/nacl/lxstat.c create mode 100644 sysdeps/nacl/lxstat64.c create mode 100644 sysdeps/nacl/mkdir.c create mode 100644 sysdeps/nacl/mmap.c create mode 100644 sysdeps/nacl/mmap64.c create mode 100644 sysdeps/nacl/mprotect.c create mode 100644 sysdeps/nacl/munmap.c create mode 100755 sysdeps/nacl/nacl-after-link.sh create mode 100644 sysdeps/nacl/nacl-interface-list.h create mode 100644 sysdeps/nacl/nacl-interface-table.c create mode 100644 sysdeps/nacl/nacl-interfaces.c create mode 100644 sysdeps/nacl/nacl-interfaces.h create mode 100644 sysdeps/nacl/nacl-interfaces.mk.in create mode 100755 sysdeps/nacl/nacl-test-wrapper.sh create mode 100644 sysdeps/nacl/nacl_interface_query.c create mode 100644 sysdeps/nacl/nanosleep.c create mode 100644 sysdeps/nacl/open.c create mode 100644 sysdeps/nacl/open64.c create mode 100644 sysdeps/nacl/preconfigure create mode 100644 sysdeps/nacl/profil.c create mode 100644 sysdeps/nacl/read.c create mode 100644 sysdeps/nacl/readdir.c create mode 100644 sysdeps/nacl/readdir64.c create mode 100644 sysdeps/nacl/readdir64_r.c create mode 100644 sysdeps/nacl/readdir_r.c create mode 100644 sysdeps/nacl/readlink.c create mode 100644 sysdeps/nacl/rename.c create mode 100644 sysdeps/nacl/rmdir.c create mode 100644 sysdeps/nacl/sched_yield.c create mode 100644 sysdeps/nacl/shlib-versions create mode 100644 sysdeps/nacl/sigaction.c create mode 100644 sysdeps/nacl/sprofil.c create mode 100644 sysdeps/nacl/start.c create mode 100644 sysdeps/nacl/symlink.c create mode 100644 sysdeps/nacl/tls.h create mode 100644 sysdeps/nacl/truncate.c create mode 100644 sysdeps/nacl/truncate64.c create mode 100644 sysdeps/nacl/unlink.c create mode 100644 sysdeps/nacl/utimes.c create mode 100644 sysdeps/nacl/write.c create mode 100644 sysdeps/nacl/xstat.c create mode 100644 sysdeps/nacl/xstat64.c create mode 100644 sysdeps/nacl/xstatconv.c create mode 100644 sysdeps/nacl/xstatconv.h diff --git a/ChangeLog b/ChangeLog index 215fd119a2..44dc704b55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-04-17 Roland McGrath + + Add preliminary port to Google Native Client on ARM. + * abi-tags (.*-.*-nacl.*): New entry. + * sysdeps/arm/nacl: New directory. + * sysdeps/nacl: New directory. + 2015-04-16 David S. Miller * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Make use of diff --git a/abi-tags b/abi-tags index 87cd6816a9..150d29b991 100644 --- a/abi-tags +++ b/abi-tags @@ -28,5 +28,7 @@ .*-.*-syllable.* 5 2.0.0 # just an arbitrary value +.*-.*-nacl.* 6 42.0.0 # earliest compatible Chromium version + # There is no catch-all default here because every supported OS that uses # ELF must have its own unique ABI tag. diff --git a/sysdeps/arm/nacl/Implies b/sysdeps/arm/nacl/Implies new file mode 100644 index 0000000000..2294208dba --- /dev/null +++ b/sysdeps/arm/nacl/Implies @@ -0,0 +1,2 @@ +arm/nptl +init_array diff --git a/sysdeps/arm/nacl/Makefile b/sysdeps/arm/nacl/Makefile new file mode 100644 index 0000000000..c9226595e6 --- /dev/null +++ b/sysdeps/arm/nacl/Makefile @@ -0,0 +1,33 @@ +# Makefile fragment for ARM/NaCl configurations. + +# 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 +# . + +# sysdeps/nacl/Makefile needs this set to the architecture suffix used in +# the NaCl SDK. +nacl-sdk-arch = arm + +# We don't really support TLSDESC, even though the compiler thinks it does. +have-arm-tls-desc = no + +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..f950f17d7b --- /dev/null +++ b/sysdeps/arm/nacl/____longjmp_chk.S @@ -0,0 +1,47 @@ +/* longjmp that validates stack addresses. ARM/NaCl version. + 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 + . */ + +#include + + .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..153e6dbdcb --- /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) 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. + + 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 + . */ + +#include + +/* 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..b00cfdbfa5 --- /dev/null +++ b/sysdeps/arm/nacl/arm-features.h @@ -0,0 +1,43 @@ +/* Macros to test for CPU features on ARM. NaCl version. + 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 + . */ + +#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 + +/* Only ARM mode code is allowed, never Thumb mode. */ +#define NO_THUMB + +#include_next + +#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..81f3755b3b --- /dev/null +++ b/sysdeps/arm/nacl/dl-machine.h @@ -0,0 +1,53 @@ +/* Machine-dependent ELF dynamic relocation inline functions. ARM/NaCl version. + 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 + . */ + +#ifndef dl_machine_h + +/* This is only needed for handling TEXTRELs and NaCl will never + support TEXTRELs at all. */ +#define CLEAR_CACHE(start, end) __builtin_trap () + +#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 + +#ifdef dl_machine_h + +/* Initial entry point code for the dynamic linker. + The C function `_dl_start' is the real entry point; + its return value is the user program's entry point. */ +#undef RTLD_START +#define RTLD_START asm ("\ +.text\n\ +.globl _start\n\ +.type _start, %function\n\ +.p2align 4\n\ +_start:\n\ + @ r0 has the pointer to the info block (see nacl_startup.h)\n\ + mov r1, sp @ Save stack base for __libc_stack_end.\n\ + push {r0-r3} @ Push those, maintaining alignment to 16.\n\ + mov r0, sp @ Pointer to {info, sp} is argument.\n\ + sfi_bl _dl_start\n\ + pop {r1-r4} @ Restore stack, getting info block into r1.\n\ + mov lr, #0 @ Return address for noreturn call.\n\ + b _dl_start_user"); + +#endif diff --git a/sysdeps/arm/nacl/dl-trampoline.S b/sysdeps/arm/nacl/dl-trampoline.S new file mode 100644 index 0000000000..47bc0cac79 --- /dev/null +++ b/sysdeps/arm/nacl/dl-trampoline.S @@ -0,0 +1,278 @@ +/* PLT trampolines. ARM/NaCl version. + 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 + . */ + +#include + + .syntax unified + .text + +@ Change &GOT[n+3] into 8*n. Note relocs are 8 bytes each. +.macro compute_reloc_arg pltgot, got2 + sub r1, \pltgot, \got2 @ r1 = &GOT[n+3] - &GOT[2] = 4*(n-1) + sub r1, r1, #4 @ r1 = 4*n + add r1, r1, r1 @ r1 *= 2 = 8*n +.endm + + CFI_SECTIONS + .globl _dl_runtime_resolve + .type _dl_runtime_resolve, %function + .p2align 4 +_dl_runtime_resolve: + cfi_startproc + cfi_adjust_cfa_offset (8) + + @ We get called with: + @ lr contains the return address from this call + @ stack[1] contains &GOT[n+3] (pointer to function) + @ stack[0] points to &GOT[2] + + ldr ip, [sp] @ ip gets &GOT[2] + + @ Save the argument registers and the return address. + @ r4 doesn't need to be saved, but it makes the total + @ adjustment to sp (including the two words pushed by + @ the PLT code) an even eight words, so sp stays aligned. + push {r0-r4, lr} + cfi_adjust_cfa_offset (24) + cfi_rel_offset (r0, 0) + cfi_rel_offset (r1, 4) + cfi_rel_offset (r2, 8) + cfi_rel_offset (r3, 12) + cfi_rel_offset (r4, 16) + cfi_rel_offset (lr, 20) + + ldr r1, [sp, #28] @ r1 gets &GOT[n+3] + + @ Get the 'struct link_map *' for the first argument to _dl_fixup. + sfi_breg ip, ldr r0, [\B, #-4] + + @ Get the reloc offset for the second argument to _dl_fixup. + compute_reloc_arg r1, ip + + @ This does the real work, and returns the real call target. + sfi_bl _dl_fixup + mov ip, r0 + + @ Restore the saved registers. + pop {r0-r4, lr} + cfi_adjust_cfa_offset (-24) + cfi_restore (r0) + cfi_restore (r1) + cfi_restore (r2) + cfi_restore (r3) + cfi_restore (r4) + cfi_restore (lr) + + @ Now compensate for the two words pushed by the PLT code. + sfi_sp add sp, #8 + cfi_adjust_cfa_offset (-8) + + @ Finally, jump to the newfound call target. + sfi_bx ip + + cfi_endproc + .size _dl_runtime_resolve, .-_dl_runtime_resolve + +#ifndef PROF + .globl _dl_runtime_profile + .type _dl_runtime_profile, #function + .p2align 4 +_dl_runtime_profile: + cfi_startproc + cfi_adjust_cfa_offset (8) + + @ We get called with: + @ lr contains the return address from this call + @ stack[1] contains &GOT[n+3] (pointer to function) + @ stack[0] points to &GOT[2] + + @ Stack layout: + @ sp + 204 framesize returned from pltenter + @ sp + 12 La_arm_regs + @ sp + 4 Saved two arguments to _dl_profile_fixup + @ sp + 0 outgoing argument to _dl_profile_fixup + @ For now, we only save the general purpose registers. +# define PLTEXIT_ARGS 4 +# define LA_ARM_REGS (PLTEXIT_ARGS + 8) +# define LA_ARM_REGS_SIZE (4 * (4 + 1 + 1 + 42)) +# define PLTENTER_FRAMESIZE (LA_ARM_REGS + LA_ARM_REGS_SIZE) +# define FRAMESIZE (((PLTENTER_FRAMESIZE + 4) + 15) & -16) + + @ The NaCl ABI requires that sp be aligned to 16 bytes at call + @ sites. Assuming that was met on entry to the PLT, sp is + @ now exactly 8 bytes misaligned. + sfi_sp sub sp, #(FRAMESIZE - 8) + cfi_def_cfa_offset (FRAMESIZE) + + @ Store the argument registers in La_arm_regs. + strd r0, r1, [sp, #LA_ARM_REGS] + cfi_offset (r0, LA_ARM_REGS + 0) + cfi_offset (r1, LA_ARM_REGS + 4) + strd r2, r3, [sp, #(LA_ARM_REGS + 8)] + cfi_offset (r2, LA_ARM_REGS + 8) + cfi_offset (r3, LA_ARM_REGS + 12) + + ldr ip, [sp, #(FRAMESIZE - 8)] @ ip gets &GOT[2] + ldr r3, [sp, #(FRAMESIZE - 4)] @ r3 gets &GOT[n+3] + + @ Recover the incoming sp and lr and save those in La_arm_regs. + add r0, sp, #FRAMESIZE + mov r1, lr + strd r0, r1, [sp, #(LA_ARM_REGS + 16)] + cfi_offset (sp, LA_ARM_REGS + 16) + cfi_offset (lr, LA_ARM_REGS + 20) + + @ Get the 'struct link_map *' for the first arg to _dl_profile_fixup. + sfi_breg ip, ldr r0, [\B, #-4] + + @ Get the reloc offset for the second argument to _dl_profile_fixup. + compute_reloc_arg r3, ip + + @ The third argument is the original return address, still in lr. + mov r2, lr + + @ Compute the fourth argument, the La_arm_regs pointer. + add r3, sp, #PLTEXIT_ARGS + + @ Compute the fifth argument, the address of the 'framesize' + @ out parameter, and store it at the top of the stack. + add ip, sp, #PLTENTER_FRAMESIZE + str ip, [sp] + + @ Save away the first two arguments, which we will need + @ again for _dl_call_pltexit, below. + strd r0, r1, [sp, #PLTEXIT_ARGS] + + @ This does the real work, and returns the real call target. + sfi_bl _dl_profile_fixup + + @ The address to call is now in r0. + + @ Check whether we're wrapping this function, + @ i.e. if the framesize out parameter is >= 0. + ldr ip, [sp, #PLTENTER_FRAMESIZE] + cmp ip, #0 + bge 1f + cfi_remember_state + + @ Save _dl_profile_fixup's return value: the real call target. + mov ip, r0 + + @ Restore the registers from the La_arm_regs (perhaps as modified + @ by audit modules' pltenter functions). + add r1, sp, #LA_ARM_REGS + sfi_sp sfi_breg r1, ldmia \B, {r0-r3, sp, lr} + cfi_def_cfa_offset (0) + cfi_restore (r0) + cfi_restore (r1) + cfi_restore (r2) + cfi_restore (r3) + cfi_restore (sp) + cfi_restore (lr) + + @ Finally, jump to the newfound call target. + sfi_bx ip + +1: cfi_restore_state + @ The new frame size is in ip. + + @ Save the fp in the stack slot previously used for the fifth + @ argument to _dl_profile_fixup. + str fp, [sp] + cfi_offset (fp, 0) + + @ Save the result of _dl_profile_fixup, the real call target. + @ We'll reuse the stack slot just used for the 'framesize' + @ out parameter to _dl_profile_fixup. + str r0, [sp, #PLTENTER_FRAMESIZE] + + @ Stack layout: + @ fp + 264 call target + @ fp + 72 La_arm_regs + @ fp + 68 Saved two arguments to _dl_profile_fixup + @ fp + 64 saved fp + @ fp + 0 La_arm_retval + @ sp..fp copied incoming stack space (plus alignment) + @ For now, we only save the general purpose registers. +# define FP_LA_ARM_RETVAL 0 +# define LA_ARM_RETVAL_SIZE (4 * (4 + 12)) +# define FP_SAVED_FP LA_ARM_RETVAL_SIZE +# define FP_PLTEXIT_ARGS (FP_SAVED_FP + 4) +# define FP_LA_ARM_REGS (FP_PLTEXIT_ARGS + 8) +# define FP_CALL_TARGET (FP_LA_ARM_REGS + LA_ARM_REGS_SIZE) +# define FP_FRAMESIZE (FP_CALL_TARGET + 4) + + sub fp, sp, #(FP_FRAMESIZE - FRAMESIZE) + cfi_def_cfa (fp, FP_FRAMESIZE) + + sub r1, fp, ip + @ This doesn't need sfi_sp because we just include the + @ sandboxing mask along with the alignment mask. + bic sp, r1, #0xc000000f + + @ Copy the stack arguments. The audit modules' pltenter + @ function(s) decided how much needs to be copied. + @ Load the sp as modified by pltenter functions, rather + @ than what we think the incoming sp was (fp + FP_FRAMESIZE). + sfi_breg fp, ldr r1, [\B, #(FP_LA_ARM_REGS + 16)] + mov r0, sp + mov r2, ip + sfi_bl memcpy + + @ Load up the arguments from La_arm_regs and call the user's function. + sfi_breg fp, ldr ip, [\B, #FP_CALL_TARGET] + sfi_breg fp, ldrd r0, r1, [\B, #FP_LA_ARM_REGS] + sfi_breg fp, ldrd r2, r3, [\B, #(FP_LA_ARM_REGS + 8)] + sfi_blx ip + + @ Stash the return value registers in La_arm_retval. + sfi_breg fp, strd r0, r1, [\B, #FP_LA_ARM_RETVAL] + sfi_breg fp, strd r2, r3, [\B, #(FP_LA_ARM_RETVAL + 8)] + + @ Call pltexit. We saved the first two arguments earlier--they + @ are the same ones passed to _dl_profile_fixup. The latter two + @ arguments are La_arm_regs and La_arm_retval blocks, respectively. + sfi_breg fp, ldrd r0, r1, [\B, #FP_PLTEXIT_ARGS] + add r2, fp, #FP_LA_ARM_REGS + add r3, fp, #FP_LA_ARM_RETVAL + sfi_bl _dl_call_pltexit + + @ Reload the saved return value registers for the caller. + sfi_breg fp, ldrd r0, r1, [\B, #FP_LA_ARM_RETVAL] + sfi_breg fp, ldrd r2, r3, [\B, #(FP_LA_ARM_RETVAL + 8)] + + @ Unwind the frame. + sfi_sp mov sp, fp + cfi_def_cfa_register (sp) + ldr fp, [sp, #FP_SAVED_FP] + cfi_restore (fp) + @ Reload the lr and sp values from La_arm_regs, where they + @ might have been modified by pltenter functions, rather than + @ computing what we think the incoming value was. + ldr lr, [sp, #(FP_LA_ARM_REGS + 20)] + cfi_restore (lr) + sfi_sp ldr sp, [sp, #(FP_LA_ARM_REGS + 16)] + cfi_def_cfa_offset (0) + + @ Finally, return to the caller. + sfi_bx lr + + cfi_endproc + .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..41830e5c79 --- /dev/null +++ b/sysdeps/arm/nacl/include/bits/setjmp.h @@ -0,0 +1,38 @@ +/* Private jmp_buf-related definitions. NaCl/ARM version. + 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 + . */ + +#ifndef _INCLUDE_BITS_SETJMP_H +#define _INCLUDE_BITS_SETJMP_H 1 + +#ifndef __ASSEMBLER__ +/* Get the public declarations. */ +# include +#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} + +/* Index of __jmp_buf where the sp register resides. */ +#define __JMP_BUF_SP 0 + +#endif /* include/bits/setjmp.h */ diff --git a/sysdeps/arm/nacl/shlib-versions b/sysdeps/arm/nacl/shlib-versions new file mode 100644 index 0000000000..9d94784282 --- /dev/null +++ b/sysdeps/arm/nacl/shlib-versions @@ -0,0 +1,4 @@ +# Library=version Earliest symbol set (optional) +# --------------- ------------------------------ + +ld=ld-nacl-arm.so.1 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 diff --git a/sysdeps/arm/nacl/sysdep.h b/sysdeps/arm/nacl/sysdep.h new file mode 100644 index 0000000000..951df3215d --- /dev/null +++ b/sysdeps/arm/nacl/sysdep.h @@ -0,0 +1,69 @@ +/* Assembler macros for ARM/NaCl. + 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 + . */ + +#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 + +#ifdef __ASSEMBLER__ + +# 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..646e7a9d06 --- /dev/null +++ b/sysdeps/arm/nacl/tls.h @@ -0,0 +1,2 @@ +#include +#include diff --git a/sysdeps/nacl/Implies b/sysdeps/nacl/Implies new file mode 100644 index 0000000000..0448f3f018 --- /dev/null +++ b/sysdeps/nacl/Implies @@ -0,0 +1,3 @@ +nptl +posix +gnu diff --git a/sysdeps/nacl/Makefile b/sysdeps/nacl/Makefile new file mode 100644 index 0000000000..b51156b5ad --- /dev/null +++ b/sysdeps/nacl/Makefile @@ -0,0 +1,135 @@ +# Makefile fragment for NaCl configurations. + +# 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 +# . + +# The libthread_db code does not compile for NaCl because there is no +# sys/procfs.h supplying the register layout types. But since libthread_db +# will probably never be useful for NaCl, just elide the directory rather +# than implementing stuff to make it compile (and never get used). +subdirs := $(filter-out nptl_db,$(subdirs)) +sorted-subdirs := $(filter-out nptl_db,$(sorted-subdirs)) + +# 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 = $(..)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) + +# Massage NaCl's irt.h (and irt_dev.h) into something we can use. +# See irt.sed for details. +nacl-irt.h = $(common-objpfx)nacl-irt.h +$(nacl-irt.h): $(nacl)/irt.sed \ + $(naclsrc)/untrusted/irt/irt.h \ + $(naclsrc)/untrusted/irt/irt_dev.h + sed -f $^ > $@.new + mv -f $@.new $@ +common-generated += nacl-irt.h +before-compile += $(nacl-irt.h) + +$(common-objpfx)nacl-interfaces.v.i: $(nacl)/nacl-interfaces.mk.in \ + $(nacl)/nacl-interface-list.h +-include $(common-objpfx)nacl-interfaces.v +common-generated += nacl-interfaces.v +before-compile += $(common-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_MODULE $(firstword $(subst -, ,$*))'; \ + echo '#define INTERFACE_TYPE $(word 2,$(subst -, ,$*))'; \ + 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 $(common-objpfx)nacl-interfaces.v + $(make-target-directory) + $(call nacl-interface-table-command,mandatory) +$(nacl-optional-interfaces:%=$(nacl-interface-pattern)): \ + $(nacl-interface-pattern): $(nacl)/Makefile $(common-objpfx)nacl-interfaces.v + $(make-target-directory) + $(call nacl-interface-table-command,optional) + +nacl-routines-of = $(filter nacl-interface-$1-%,$(nacl-interface-routines)) + + +# Run the NaCl code validator on binaries after we link them, so the +# build does not succeed with any binary that won't pass validation. +# Moving the file around makes sure that we don't leave a target +# appearing complete after it fails validation. +define after-link +mv -f $1 $1.prevalidation +$(nacl)/nacl-after-link.sh '${READELF}' $1.prevalidation +mv -f $1.prevalidation $1 +endef + +# The test wrapper script takes care of running things under NaCl's sel_ldr. +test-wrapper-env-only = $(nacl)/nacl-test-wrapper.sh --arch=$(nacl-sdk-arch) +test-wrapper-env = $(test-wrapper-env-only) +test-wrapper = $(test-wrapper-env) -- + +ifeq ($(subdir),csu) +sysdep_routines += nacl_interface_query \ + nacl-interfaces $(call nacl-routines-of,libc) +endif + +ifeq ($(subdir),elf) +sysdep-dl-routines += $(call nacl-routines-of,rtld) +sysdep-rtld-routines += nacl-interfaces $(call nacl-routines-of,rtld) +endif + +ifeq ($(subdir),io) +sysdep_routines += xstatconv +endif + +ifeq ($(subdir),nptl) +# We do not need any wrappers in libpthread. +libpthread-routines := $(filter-out ptw-%,$(libpthread-routines)) +endif + +ifeq ($(subdir),misc) +# We reuse the Linux file since the bits match. The file lives in the +# top-level source tree so we can use it without reference to any +# sysdeps/.../linux/ directories, but it's still a sysdeps decision to +# install it. +sysdep_headers += bits/mman-linux.h +endif diff --git a/sysdeps/nacl/Subdirs b/sysdeps/nacl/Subdirs new file mode 100644 index 0000000000..5d570b9969 --- /dev/null +++ b/sysdeps/nacl/Subdirs @@ -0,0 +1,3 @@ +inet +resolv +nss diff --git a/sysdeps/nacl/Versions b/sysdeps/nacl/Versions new file mode 100644 index 0000000000..4ac56c2a28 --- /dev/null +++ b/sysdeps/nacl/Versions @@ -0,0 +1,21 @@ +ld { + GLIBC_PRIVATE { + __nacl_irt_*; + } +} + +libc { + GLIBC_2.22 { + nacl_interface_query; + } + + GLIBC_PRIVATE { + # These are used by libpthread. + __libc_write; + __libc_open; + __libc_close; + __libc_fork; + + __nacl_irt_*; + } +} diff --git a/sysdeps/nacl/_exit.c b/sysdeps/nacl/_exit.c new file mode 100644 index 0000000000..6006e26e55 --- /dev/null +++ b/sysdeps/nacl/_exit.c @@ -0,0 +1,34 @@ +/* _exit -- low-level program termination. NaCl version. + 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 + . */ + +#include +#include +#include + +void +_exit (int status) +{ + __nacl_irt_basic.exit (status); + + /* That never returns unless something is severely and unrecoverably wrong. + If it ever does, try to make sure we crash. */ + while (1) + __builtin_trap (); +} +libc_hidden_def (_exit) +weak_alias (_exit, _Exit) diff --git a/sysdeps/nacl/access.c b/sysdeps/nacl/access.c new file mode 100644 index 0000000000..531a999c01 --- /dev/null +++ b/sysdeps/nacl/access.c @@ -0,0 +1,28 @@ +/* Check file access permission. NaCl version. + 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 + . */ + +#include +#include + +/* Test for access to FILE. */ +int +__access (const char *file, int type) +{ + return NACL_CALL (__nacl_irt_dev_filename.access (file, type), 0); +} +weak_alias (__access, access) diff --git a/sysdeps/nacl/backtrace.c b/sysdeps/nacl/backtrace.c new file mode 100644 index 0000000000..27ce597b39 --- /dev/null +++ b/sysdeps/nacl/backtrace.c @@ -0,0 +1 @@ +#include diff --git a/sysdeps/nacl/bits/dirent.h b/sysdeps/nacl/bits/dirent.h new file mode 100644 index 0000000000..571ac0c67b --- /dev/null +++ b/sysdeps/nacl/bits/dirent.h @@ -0,0 +1,52 @@ +/* Directory entry structure `struct dirent'. NaCl version. + 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 + . */ + +#ifndef _DIRENT_H +# error "Never use directly; include 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/fcntl.h b/sysdeps/nacl/bits/fcntl.h new file mode 100644 index 0000000000..ceef8dfeab --- /dev/null +++ b/sysdeps/nacl/bits/fcntl.h @@ -0,0 +1,149 @@ +/* O_*, F_*, FD_* bit values. NaCl version. + 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 + . */ + +#ifndef _FCNTL_H +#error "Never use directly; include instead." +#endif + + +/* File access modes for `open' and `fcntl'. */ +#define O_RDONLY 0 /* Open read-only. */ +#define O_WRONLY 1 /* Open write-only. */ +#define O_RDWR 2 /* Open read/write. */ + + +/* Bits OR'd into the second argument to open. */ +#define O_CREAT 00100 /* Create file if it doesn't exist. */ +#define O_EXCL 00200 /* Fail if file already exists. */ +#define O_TRUNC 01000 /* Truncate file to zero length. */ +#define O_NOCTTY 0 /* Don't assign a controlling terminal. */ +#define O_ASYNC 020000 /* Send SIGIO to owner when data is ready. */ +#define O_FSYNC 010000 /* Synchronous writes. */ +#define O_SYNC O_FSYNC +#ifdef __USE_MISC +# define O_SHLOCK XXX /* Open with shared file lock. */ +# define O_EXLOCK XXX /* Open with shared exclusive lock. */ +#endif +#ifdef __USE_XOPEN2K8 +# define O_DIRECTORY 00200000 /* Must be a directory. */ +# define O_NOFOLLOW 00400000 /* Do not follow links. */ +# define O_CLOEXEC 02000000 /* Set close_on_exec. */ +#endif +#if defined __USE_POSIX199309 || defined __USE_UNIX98 +# define O_DSYNC O_SYNC /* Synchronize data. */ +# define O_RSYNC O_SYNC /* Synchronize read operations. */ +#endif + +/* All opens support large file sizes, so there is no flag bit for this. */ +#ifdef __USE_LARGEFILE64 +# define O_LARGEFILE 0 +#endif + +/* File status flags for `open' and `fcntl'. */ +#define O_APPEND 02000 /* Writes append to the file. */ +#define O_NONBLOCK 04000 /* Non-blocking I/O. */ + +#ifdef __USE_MISC +# define O_NDELAY O_NONBLOCK +#endif + +#ifdef __USE_MISC +/* Bits in the file status flags returned by F_GETFL. + These are all the O_* flags, plus FREAD and FWRITE, which are + independent bits set by which of O_RDONLY, O_WRONLY, and O_RDWR, was + given to `open'. */ +# define FREAD 1 +# define FWRITE 2 + +/* Traditional BSD names the O_* bits. */ +# define FASYNC O_ASYNC +# define FFSYNC O_FSYNC +# define FSYNC O_SYNC +# define FAPPEND O_APPEND +# define FNDELAY O_NDELAY +#endif + +/* Mask for file access modes. This is system-dependent in case + some system ever wants to define some other flavor of access. */ +#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) + +/* Values for the second argument to `fcntl'. */ +#define F_DUPFD 0 /* Duplicate file descriptor. */ +#define F_GETFD 1 /* Get file descriptor flags. */ +#define F_SETFD 2 /* Set file descriptor flags. */ +#define F_GETFL 3 /* Get file status flags. */ +#define F_SETFL 4 /* Set file status flags. */ +#if defined __USE_UNIX98 || defined __USE_XOPEN2K8 +#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ +#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ +#endif +#define F_GETLK 7 /* Get record locking info. */ +#define F_SETLK 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW 9 /* Set record locking info (blocking). */ +/* Not necessary, we always have 64-bit offsets. */ +#define F_GETLK64 F_GETLK /* Get record locking info. */ +#define F_SETLK64 F_SETLK /* Set record locking info (non-blocking). */ +#define F_SETLKW64 F_SETLKW/* Set record locking info (blocking). */ +#ifdef __USE_XOPEN2K8 +# define F_DUPFD_CLOEXEC 12 /* Duplicate file descriptor with + close-on-exec set. */ +#endif + +/* File descriptor flags used with F_GETFD and F_SETFD. */ +#define FD_CLOEXEC 1 /* Close on exec. */ + + +#include + +/* The structure describing an advisory lock. This is the type of the third + argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */ +struct flock + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ + __off_t l_start; /* Offset where the lock begins. */ + __off_t l_len; /* Size of the locked area; zero means until EOF. */ + __pid_t l_pid; /* Process holding the lock. */ + }; + +#ifdef __USE_LARGEFILE64 +/* Note this matches struct flock exactly. */ +struct flock64 + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ + __off_t l_start; /* Offset where the lock begins. */ + __off_t l_len; /* Size of the locked area; zero means until EOF. */ + __pid_t l_pid; /* Process holding the lock. */ + }; +#endif + +/* Values for the `l_type' field of a `struct flock'. */ +#define F_RDLCK 1 /* Read lock. */ +#define F_WRLCK 2 /* Write lock. */ +#define F_UNLCK 3 /* Remove lock. */ + +/* Advice to `posix_fadvise'. */ +#ifdef __USE_XOPEN2K +# define POSIX_FADV_NORMAL 0 /* No further special treatment. */ +# define POSIX_FADV_RANDOM 1 /* Expect random page references. */ +# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */ +# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */ +# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */ +# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */ +#endif diff --git a/sysdeps/nacl/bits/local_lim.h b/sysdeps/nacl/bits/local_lim.h new file mode 100644 index 0000000000..950a2371e0 --- /dev/null +++ b/sysdeps/nacl/bits/local_lim.h @@ -0,0 +1,64 @@ +/* Minimum guaranteed maximum values for system limits. NaCl version. + 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 + . */ + +#define NAME_MAX 255 + +#define PATH_MAX 4096 + +#define NGROUPS_MAX 65536 + +/* The number of data keys per process. */ +#define _POSIX_THREAD_KEYS_MAX 128 +/* This is the value this implementation supports. */ +#define PTHREAD_KEYS_MAX 1024 + +/* Controlling the iterations of destructors for thread-specific data. */ +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +/* Number of iterations this implementation does. */ +#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS + +/* The number of threads per process. */ +#define _POSIX_THREAD_THREADS_MAX 64 +/* We have no predefined limit on the number of threads. */ +#undef PTHREAD_THREADS_MAX + +/* Maximum amount by which a process can descrease its asynchronous I/O + priority level. */ +#define AIO_PRIO_DELTA_MAX 20 + +/* Minimum size for a thread. We are free to choose a reasonable value. */ +#define PTHREAD_STACK_MIN 131072 + +/* Maximum number of timer expiration overruns. */ +#define DELAYTIMER_MAX 2147483647 + +/* Maximum tty name length. */ +#define TTY_NAME_MAX 32 + +/* Maximum login name length. This is arbitrary. */ +#define LOGIN_NAME_MAX 256 + +/* Maximum host name length. */ +#define HOST_NAME_MAX 64 + +/* Maximum message queue priority level. */ +#define MQ_PRIO_MAX 32768 + +/* Maximum value the semaphore can have. */ +#define SEM_VALUE_MAX (2147483647) diff --git a/sysdeps/nacl/bits/mman.h b/sysdeps/nacl/bits/mman.h new file mode 100644 index 0000000000..2d5fdfc17b --- /dev/null +++ b/sysdeps/nacl/bits/mman.h @@ -0,0 +1,24 @@ +/* Definitions for POSIX memory map interface. NaCl version. + 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 + . */ + +#ifndef _SYS_MMAN_H +# error "Never use directly; include instead." +#endif + +/* NaCl uses the Linux bits for this. */ +#include 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 + . */ + +#ifndef _SYS_PARAM_H +# error "Never use directly; include instead." +#endif + +#define EXEC_PAGESIZE 0x10000 diff --git a/sysdeps/nacl/bits/posix_opt.h b/sysdeps/nacl/bits/posix_opt.h new file mode 100644 index 0000000000..2a5d6fd70a --- /dev/null +++ b/sysdeps/nacl/bits/posix_opt.h @@ -0,0 +1,210 @@ +/* Define POSIX options for NaCl. + 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; see the file COPYING.LIB. If + not, see . */ + +#ifndef _BITS_POSIX_OPT_H +#define _BITS_POSIX_OPT_H 1 + +/* Job control is supported. (Not really, but the APIs exist.) */ +#define _POSIX_JOB_CONTROL 1 + +/* Processes have a saved set-user-ID and a saved set-group-ID. */ +#define _POSIX_SAVED_IDS 1 + +/* Priority scheduling is supported. ??? */ +#define _POSIX_PRIORITY_SCHEDULING 200809L + +/* Synchronizing file data is supported. ??? */ +#define _POSIX_SYNCHRONIZED_IO 200809L + +/* The fsync function is present. */ +#define _POSIX_FSYNC 200809L + +/* Mapping of files to memory is supported. */ +#define _POSIX_MAPPED_FILES 200809L + +/* Locking of all memory is not supported. */ +#define _POSIX_MEMLOCK -1 + +/* Locking of ranges of memory is not supported. */ +#define _POSIX_MEMLOCK_RANGE -1 + +/* Setting of memory protections is supported. */ +#define _POSIX_MEMORY_PROTECTION 200809L + +/* Some filesystems allow all users to change file ownership. */ +#define _POSIX_CHOWN_RESTRICTED 0 + +/* `c_cc' member of 'struct termios' structure can be disabled by + using the value _POSIX_VDISABLE. ??? */ +#define _POSIX_VDISABLE '\0' + +/* Filenames are not silently truncated. */ +#define _POSIX_NO_TRUNC 1 + +/* X/Open realtime support is not fully available. This requires the + following set of POSIX.1 features, not all of which NaCl supports: + _POSIX_FSYNC + _POSIX_MEMLOCK + _POSIX_MEMLOCK_RANGE + _POSIX_MESSAGE_PASSING + _POSIX_PRIORITIZED_IO + _POSIX_PRIORITY_SCHEDULING + _POSIX_SHARED_MEMORY_OBJECTS + _POSIX_SYNCHRONIZED_IO + */ +#define _XOPEN_REALTIME -1 + +/* X/Open thread realtime support is not available. This requires the + following set of POSIX.1 features, none of which NaCl supports: + _POSIX_THREAD_PRIO_INHERIT + _POSIX_THREAD_PRIO_PROTECT + _POSIX_THREAD_PRIORITY_SCHEDULING + _POSIX_THREAD_ROBUST_PRIO_INHERIT + _POSIX_THREAD_ROBUST_PRIO_PROTECT + */ +#define _XOPEN_REALTIME_THREADS -1 + +/* XPG4.2 shared memory is not supported. + ??? What is this? shm* interfaces? +*/ +#define _XOPEN_SHM -1 + +/* POSIX threads are supported. */ +#define _POSIX_THREADS 200809L + +/* We have the reentrant functions described in POSIX. */ +#define _POSIX_REENTRANT_FUNCTIONS 1 +#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L + +/* We do not provide priority scheduling for threads. */ +#define _POSIX_THREAD_PRIORITY_SCHEDULING -1 + +/* We support user-defined stack sizes. */ +#define _POSIX_THREAD_ATTR_STACKSIZE 200809L + +/* We support user-defined stacks. */ +#define _POSIX_THREAD_ATTR_STACKADDR 200809L + +/* We do not support priority inheritence. */ +#define _POSIX_THREAD_PRIO_INHERIT -1 + +/* We do not support priority protection. */ +#define _POSIX_THREAD_PRIO_PROTECT -1 + +#ifdef __USE_XOPEN2K8 +/* We do not support priority inheritence for robust mutexes. */ +# define _POSIX_THREAD_ROBUST_PRIO_INHERIT -1 + +/* We do not support priority protection for robust mutexes. */ +# define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1 +#endif + +/* We support POSIX.1b semaphores. */ +#define _POSIX_SEMAPHORES 200809L + +/* Real-time signals are supported. ??? */ +#define _POSIX_REALTIME_SIGNALS 200809L + +/* We support asynchronous I/O. */ +#define _POSIX_ASYNCHRONOUS_IO 200809L +#define _POSIX_ASYNC_IO 1 +/* Alternative name for Unix98. */ +#define _LFS_ASYNCHRONOUS_IO 1 +/* Support for prioritization is not available. */ +#define _POSIX_PRIORITIZED_IO -1 + +/* The LFS support in asynchronous I/O is also available. */ +#define _LFS64_ASYNCHRONOUS_IO 1 + +/* The rest of the LFS is also available. */ +#define _LFS_LARGEFILE 1 +#define _LFS64_LARGEFILE 1 +#define _LFS64_STDIO 1 + +/* POSIX shared memory objects are implemented. */ +#define _POSIX_SHARED_MEMORY_OBJECTS 200809L + +/* Process CPU-time clocks are not supported. */ +#define _POSIX_CPUTIME -1 + +/* Thread CPU-time locks are supported. */ +#define _POSIX_THREAD_CPUTIME 200809L + +/* GNU libc provides regular expression handling. */ +#define _POSIX_REGEXP 1 + +/* Reader/Writer locks are available. */ +#define _POSIX_READER_WRITER_LOCKS 200809L + +/* We have a POSIX shell. */ +#define _POSIX_SHELL 1 + +/* We support the Timeouts option. */ +#define _POSIX_TIMEOUTS 200809L + +/* We support spinlocks. */ +#define _POSIX_SPIN_LOCKS 200809L + +/* The `spawn' function family is supported. */ +#define _POSIX_SPAWN 200809L + +/* We have POSIX timers. */ +#define _POSIX_TIMERS 200809L + +/* The barrier functions are available. */ +#define _POSIX_BARRIERS 200809L + +/* POSIX message queues are n