diff options
Diffstat (limited to 'libc/sysdeps/linux/x86_64')
54 files changed, 1312 insertions, 735 deletions
diff --git a/libc/sysdeps/linux/x86_64/Makefile.arch b/libc/sysdeps/linux/x86_64/Makefile.arch index b6ad71cbd..2bc838f0e 100644 --- a/libc/sysdeps/linux/x86_64/Makefile.arch +++ b/libc/sysdeps/linux/x86_64/Makefile.arch @@ -5,9 +5,15 @@ # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. # -CSRC := brk.c sigaction.c __syscall_error.c mmap.c +CSRC-y := brk.c __syscall_error.c sigaction.c -SSRC := \ - __longjmp.S vfork.S setjmp.S syscall.S bsd-setjmp.S bsd-_setjmp.S clone.S +SSRC-y := \ + __longjmp.S setjmp.S syscall.S bsd-setjmp.S bsd-_setjmp.S -include $(top_srcdir)libc/sysdeps/linux/Makefile.commonarch +SSRC-$(if $(UCLIBC_HAS_THREADS_NATIVE),,y) += vfork.S clone.S +ARCH_OBJ_FILTEROUT-$(UCLIBC_LINUX_SPECIFIC) := sched_getcpu.c +ifeq ($(UCLIBC_LINUX_SPECIFIC),y) +SSRC-$(UCLIBC_HAS_TLS) += sched_getcpu.S +endif +CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c +SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += setcontext.S getcontext.S swapcontext.S __start_context.S diff --git a/libc/sysdeps/linux/x86_64/__longjmp.S b/libc/sysdeps/linux/x86_64/__longjmp.S index db2928bf0..907b64c9d 100644 --- a/libc/sysdeps/linux/x86_64/__longjmp.S +++ b/libc/sysdeps/linux/x86_64/__longjmp.S @@ -12,14 +12,10 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ -#include <features.h> -#define _ASM -#define _SETJMP_H -#include <bits/setjmp.h> +#include <jmpbuf-offsets.h> /* Jump to the position specified by ENV, causing the setjmp call there to return VAL, or 1 if VAL is 0. diff --git a/libc/sysdeps/linux/x86_64/__start_context.S b/libc/sysdeps/linux/x86_64/__start_context.S new file mode 100644 index 000000000..9f2ee2373 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/__start_context.S @@ -0,0 +1,49 @@ +/* Copyright (C) 2002-2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2002. + + 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> + +/* This is the helper code which gets called if a function which is + registered with 'makecontext' returns. In this case we have to + install the context listed in the uc_link element of the context + 'makecontext' manipulated at the time of the 'makecontext' call. + If the pointer is NULL the process must terminate. */ + + +ENTRY(__start_context) + /* This removes the parameters passed to the function given to + 'makecontext' from the stack. RBX contains the address + on the stack pointer for the next context. */ + movq %rbx, %rsp + + popq %rdi /* This is the next context. */ + cfi_adjust_cfa_offset(-8) + testq %rdi, %rdi + je 2f /* If it is zero exit. */ + + call JUMPTARGET(__setcontext) + /* If this returns (which can happen if the syscall fails) we'll + exit the program with the return error value (-1). */ + movq %rax,%rdi + +2: + call HIDDEN_JUMPTARGET(exit) + /* The 'exit' call should never return. In case it does cause + the process to terminate. */ + hlt +END(__start_context) diff --git a/libc/sysdeps/linux/x86_64/bits/atomic.h b/libc/sysdeps/linux/x86_64/bits/atomic.h index 04870cbf5..1887f79fa 100644 --- a/libc/sysdeps/linux/x86_64/bits/atomic.h +++ b/libc/sysdeps/linux/x86_64/bits/atomic.h @@ -13,9 +13,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #include <stdint.h> @@ -57,28 +56,28 @@ typedef uintmax_t uatomic_max_t; #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \ ({ __typeof (*mem) ret; \ - __asm__ __volatile__ (LOCK_PREFIX "cmpxchgb %b2, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "cmpxchgb %b2, %1" \ : "=a" (ret), "=m" (*mem) \ : "q" (newval), "m" (*mem), "0" (oldval)); \ ret; }) #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \ ({ __typeof (*mem) ret; \ - __asm__ __volatile__ (LOCK_PREFIX "cmpxchgw %w2, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "cmpxchgw %w2, %1" \ : "=a" (ret), "=m" (*mem) \ : "r" (newval), "m" (*mem), "0" (oldval)); \ ret; }) #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \ ({ __typeof (*mem) ret; \ - __asm__ __volatile__ (LOCK_PREFIX "cmpxchgl %2, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "cmpxchgl %2, %1" \ : "=a" (ret), "=m" (*mem) \ : "r" (newval), "m" (*mem), "0" (oldval)); \ ret; }) #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \ ({ __typeof (*mem) ret; \ - __asm__ __volatile__ (LOCK_PREFIX "cmpxchgq %q2, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "cmpxchgq %q2, %1" \ : "=a" (ret), "=m" (*mem) \ : "r" ((long) (newval)), "m" (*mem), \ "0" ((long) (oldval))); \ @@ -97,7 +96,7 @@ typedef uintmax_t uatomic_max_t; : "=r" (result), "=m" (*mem) \ : "0" (newvalue), "m" (*mem)); \ else if (sizeof (*mem) == 4) \ - __asm__ __volatile__ ("xchgl %0, %1" \ + __asm__ __volatile__ ("xchgl %0, %1" \ : "=r" (result), "=m" (*mem) \ : "0" (newvalue), "m" (*mem)); \ else \ @@ -110,11 +109,11 @@ typedef uintmax_t uatomic_max_t; #define atomic_exchange_and_add(mem, value) \ ({ __typeof (*mem) result; \ if (sizeof (*mem) == 1) \ - __asm__ __volatile__ (LOCK_PREFIX "xaddb %b0, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "xaddb %b0, %1" \ : "=r" (result), "=m" (*mem) \ : "0" (value), "m" (*mem)); \ else if (sizeof (*mem) == 2) \ - __asm__ __volatile__ (LOCK_PREFIX "xaddw %w0, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "xaddw %w0, %1" \ : "=r" (result), "=m" (*mem) \ : "0" (value), "m" (*mem)); \ else if (sizeof (*mem) == 4) \ @@ -122,7 +121,7 @@ typedef uintmax_t uatomic_max_t; : "=r" (result), "=m" (*mem) \ : "0" (value), "m" (*mem)); \ else \ - __asm__ __volatile__ (LOCK_PREFIX "xaddq %q0, %1" \ + __asm__ __volatile__ (LOCK_PREFIX "xaddq %q0, %1" \ : "=r" (result), "=m" (*mem) \ : "0" ((long) (value)), "m" (*mem)); \ result; }) @@ -155,11 +154,11 @@ typedef uintmax_t uatomic_max_t; #define atomic_add_negative(mem, value) \ ({ unsigned char __result; \ if (sizeof (*mem) == 1) \ - __asm__ __volatile__ (LOCK_PREFIX "addb %b2, %0; sets %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addb %b2, %0; sets %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else if (sizeof (*mem) == 2) \ - __asm__ __volatile__ (LOCK_PREFIX "addw %w2, %0; sets %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addw %w2, %0; sets %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else if (sizeof (*mem) == 4) \ @@ -167,7 +166,7 @@ typedef uintmax_t uatomic_max_t; : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else \ - __asm__ __volatile__ (LOCK_PREFIX "addq %q2, %0; sets %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addq %q2, %0; sets %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" ((long) (value)), "m" (*mem)); \ __result; }) @@ -176,11 +175,11 @@ typedef uintmax_t uatomic_max_t; #define atomic_add_zero(mem, value) \ ({ unsigned char __result; \ if (sizeof (*mem) == 1) \ - __asm__ __volatile__ (LOCK_PREFIX "addb %b2, %0; setz %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addb %b2, %0; setz %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else if (sizeof (*mem) == 2) \ - __asm__ __volatile__ (LOCK_PREFIX "addw %w2, %0; setz %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addw %w2, %0; setz %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else if (sizeof (*mem) == 4) \ @@ -188,7 +187,7 @@ typedef uintmax_t uatomic_max_t; : "=m" (*mem), "=qm" (__result) \ : "ir" (value), "m" (*mem)); \ else \ - __asm__ __volatile__ (LOCK_PREFIX "addq %q2, %0; setz %1" \ + __asm__ __volatile__ (LOCK_PREFIX "addq %q2, %0; setz %1" \ : "=m" (*mem), "=qm" (__result) \ : "ir" ((long) (value)), "m" (*mem)); \ __result; }) @@ -196,19 +195,19 @@ typedef uintmax_t uatomic_max_t; #define atomic_increment(mem) \ (void) ({ if (sizeof (*mem) == 1) \ - __asm__ __volatile__ (LOCK_PREFIX "incb %b0" \ + __asm__ __volatile__ (LOCK_PREFIX "incb %b0" \ : "=m" (*mem) \ : "m" (*mem)); \ else if (sizeof (*mem) == 2) \ - __asm__ __volatile__ (LOCK_PREFIX "incw %w0" \ + __asm__ __volatile__ (LOCK_PREFIX "incw %w0" \ : "=m" (*mem) \ : "m" (*mem)); \ else if (sizeof (*mem) == 4) \ - __asm__ __volatile__ (LOCK_PREFIX "incl %0" \ + __asm__ __volatile__ (LOCK_PREFIX "incl %0" \ : "=m" (*mem) \ : "m" (*mem)); \ else \ - __asm__ __volatile__ (LOCK_PREFIX "incq %q0" \ + __asm__ __volatile__ (LOCK_PREFIX "incq %q0" \ : "=m" (*mem) \ : "m" (*mem)); \ }) @@ -225,7 +224,7 @@ typedef uintmax_t uatomic_max_t; : "=m" (*mem), "=qm" (__result) \ : "m" (*mem)); \ else if (sizeof (*mem) == 4) \ - __asm__ __volatile__ (LOCK_PREFIX "incl %0; sete %1" \ + __asm__ __volatile__ (LOCK_PREFIX "incl %0; sete %1" \ : "=m" (*mem), "=qm" (__result) \ : "m" (*mem)); \ else \ @@ -237,19 +236,19 @@ typedef uintmax_t uatomic_max_t; #define atomic_decrement(mem) \ (void) ({ if (sizeof (*mem) == 1) \ - __asm__ __volatile__ (LOCK_PREFIX "decb %b0" \ + __asm__ __volatile__ (LOCK_PREFIX "decb %b0" \ : "=m" (*mem) \ : "m" (*mem)); \ else if (sizeof (*mem) == 2) \ - __asm__ __volatile__ (LOCK_PREFIX "decw %w0" \ + __asm__ __volatile__ (LOCK_PREFIX "decw %w0" \ : "=m" (*mem) \ : "m" (*mem)); \ else if (sizeof (*mem) == 4) \ - __asm__ __volatile__ (LOCK_PREFIX "decl %0" \ + __asm__ __volatile__ (LOCK_PREFIX "decl %0" \ : "=m" (*mem) \ : "m" (*mem)); \ else \ - __asm__ __volatile__ (LOCK_PREFIX "decq %q0" \ + __asm__ __volatile__ (LOCK_PREFIX "decq %q0" \ : "=m" (*mem) \ : "m" (*mem)); \ }) @@ -266,7 +265,7 @@ typedef uintmax_t uatomic_max_t; : "=m" (*mem), "=qm" (__result) \ : "m" (*mem)); \ else if (sizeof (*mem) == 4) \ - __asm__ __volatile__ (LOCK_PREFIX "decl %0; sete %1" \ + __asm__ __volatile__ (LOCK_PREFIX "decl %0; sete %1" \ : "=m" (*mem), "=qm" (__result) \ : "m" (*mem)); \ else \ @@ -314,7 +313,7 @@ typedef uintmax_t uatomic_max_t; __asm__ __volatile__ (LOCK_PREFIX "btsl %3, %1; setc %0" \ : "=q" (__result), "=m" (*mem) \ : "m" (*mem), "ir" (bit)); \ - else \ + else \ __asm__ __volatile__ (LOCK_PREFIX "btsq %3, %1; setc %0" \ : "=q" (__result), "=m" (*mem) \ : "m" (*mem), "ir" (bit)); \ diff --git a/libc/sysdeps/linux/x86_64/bits/byteswap.h b/libc/sysdeps/linux/x86_64/bits/byteswap.h index e1c861c75..2a759bed4 100644 --- a/libc/sysdeps/linux/x86_64/bits/byteswap.h +++ b/libc/sysdeps/linux/x86_64/bits/byteswap.h @@ -13,121 +13,55 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ -#if !defined _BYTESWAP_H && !defined _NETINET_IN_H -# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead." -#endif - -#ifndef _BITS_BYTESWAP_H -#define _BITS_BYTESWAP_H 1 +#ifndef _ASM_BITS_BYTESWAP_H +#define _ASM_BITS_BYTESWAP_H 1 #include <bits/wordsize.h> -/* Swap bytes in 16 bit value. */ -#define __bswap_constant_16(x) \ - ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) - -#if defined __GNUC__ && __GNUC__ >= 2 -# define __bswap_16(x) \ +#define __bswap_non_constant_16(x) \ (__extension__ \ - ({ register unsigned short int __v, __x = (x); \ - if (__builtin_constant_p (__x)) \ - __v = __bswap_constant_16 (__x); \ - else \ - __asm__ ("rorw $8, %w0" \ - : "=r" (__v) \ - : "0" (__x) \ - : "cc"); \ + ({ register unsigned short int __v; \ + __asm__ ("rorw $8, %w0" \ + : "=r" (__v) \ + : "0" (x) \ + : "cc"); \ __v; })) -#else -/* This is better than nothing. */ -# define __bswap_16(x) \ - (__extension__ \ - ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); })) -#endif - - -/* Swap bytes in 32 bit value. */ -#define __bswap_constant_32(x) \ - ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) -#if defined __GNUC__ && __GNUC__ >= 2 -# if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__ \ - || defined __pentiumpro__ || defined __pentium4__ \ - || defined __k8__ || defined __athlon__ \ - || defined __k6__) +#if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__ \ + || defined __pentiumpro__ || defined __pentium4__ \ + || defined __k8__ || defined __athlon__ \ + || defined __k6__) /* To swap the bytes in a word the i486 processors and up provide the `bswap' opcode. On i386 we have to use three instructions. */ -# define __bswap_32(x) \ +# define __bswap_non_constant_32(x) \ (__extension__ \ - ({ register unsigned int __v, __x = (x); \ - if (__builtin_constant_p (__x)) \ - __v = __bswap_constant_32 (__x); \ - else \ - __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \ + ({ register unsigned int __v; \ + __asm__ ("bswap %0" : "=r" (__v) : "0" (x)); \ __v; })) -# else -# define __bswap_32(x) \ - (__extension__ \ - ({ register unsigned int __v, __x = (x); \ - if (__builtin_constant_p (__x)) \ - __v = __bswap_constant_32 (__x); \ - else \ - __asm__ ("rorw $8, %w0;" \ - "rorl $16, %0;" \ - "rorw $8, %w0" \ - : "=r" (__v) \ - : "0" (__x) \ - : "cc"); \ - __v; })) -# endif #else -# define __bswap_32(x) \ +# define __bswap_non_constant_32(x) \ (__extension__ \ - ({ register unsigned int __x = (x); __bswap_constant_32 (__x); })) + ({ register unsigned int __v; \ + __asm__ ("rorw $8, %w0;" \ + "rorl $16, %0;" \ + "rorw $8, %w0" \ + : "=r" (__v) \ + : "0" (x) \ + : "cc"); \ + __v; })) #endif - -#if defined __GNUC__ && __GNUC__ >= 2 -/* Swap bytes in 64 bit value. */ -# define __bswap_constant_64(x) \ - ((((x) & 0xff00000000000000ull) >> 56) \ - | (((x) & 0x00ff000000000000ull) >> 40) \ - | (((x) & 0x0000ff0000000000ull) >> 24) \ - | (((x) & 0x000000ff00000000ull) >> 8) \ - | (((x) & 0x00000000ff000000ull) << 8) \ - | (((x) & 0x0000000000ff0000ull) << 24) \ - | (((x) & 0x000000000000ff00ull) << 40) \ - | (((x) & 0x00000000000000ffull) << 56)) - -# if __WORDSIZE == 64 -# define __bswap_64(x) \ +#if __WORDSIZE == 64 +# define __bswap_non_constant_64(x) \ (__extension__ \ - ({ register unsigned long __v, __x = (x); \ - if (__builtin_constant_p (__x)) \ - __v = __bswap_constant_64 (__x); \ - else \ - __asm__ ("bswap %q0" : "=r" (__v) : "0" (__x)); \ + ({ register unsigned long __v; \ + __asm__ ("bswap %q0" : "=r" (__v) : "0" (x)); \ __v; })) -# else -# define __bswap_64(x) \ - (__extension__ \ - ({ union { __extension__ unsigned long long int __ll; \ - unsigned int __l[2]; } __w, __r; \ - if (__builtin_constant_p (x)) \ - __r.__ll = __bswap_constant_64 (x); \ - else \ - { \ - __w.__ll = (x); \ - __r.__l[0] = __bswap_32 (__w.__l[1]); \ - __r.__l[1] = __bswap_32 (__w.__l[0]); \ - } \ - __r.__ll; })) -# endif #endif -#endif /* _BITS_BYTESWAP_H */ +#endif + +#include <bits/byteswap-common.h> diff --git a/libc/sysdeps/linux/x86_64/bits/environments.h b/libc/sysdeps/linux/x86_64/bits/environments.h index a51a564cb..007f4fcce 100644 --- a/libc/sysdeps/linux/x86_64/bits/environments.h +++ b/libc/sysdeps/linux/x86_64/bits/environments.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _UNISTD_H # error "Never include this file directly. Use <unistd.h> instead" diff --git a/libc/sysdeps/linux/x86_64/bits/epoll.h b/libc/sysdeps/linux/x86_64/bits/epoll.h new file mode 100644 index 000000000..be1f5a636 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/bits/epoll.h @@ -0,0 +1,31 @@ +/* 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 _SYS_EPOLL_H +# error "Never use <bits/epoll.h> directly; include <sys/epoll.h> instead." +#endif + +/* Flags to be passed to epoll_create1. */ +enum + { + EPOLL_CLOEXEC = 02000000, +#define EPOLL_CLOEXEC EPOLL_CLOEXEC + EPOLL_NONBLOCK = 00004000 +#define EPOLL_NONBLOCK EPOLL_NONBLOCK + }; + +#define __EPOLL_PACKED __attribute__ ((__packed__)) diff --git a/libc/sysdeps/linux/x86_64/bits/fcntl.h b/libc/sysdeps/linux/x86_64/bits/fcntl.h index 42c790a51..757d6be22 100644 --- a/libc/sysdeps/linux/x86_64/bits/fcntl.h +++ b/libc/sysdeps/linux/x86_64/bits/fcntl.h @@ -13,9 +13,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _FCNTL_H # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead." @@ -50,9 +49,8 @@ # define O_DIRECTORY 0200000 /* Must be a directory. */ # define O_NOFOLLOW 0400000 /* Do not follow links. */ # define O_NOATIME 01000000 /* Do not set atime. */ -# if 0 # define O_CLOEXEC 02000000 /* Set close_on_exec. */ -# endif +# define O_PATH 010000000 /* Resolve pathname but do not open file. */ #endif /* For now Linux has synchronisity options for data and read operations. @@ -116,6 +114,8 @@ # define F_NOTIFY 1026 /* Request notfications on a directory. */ # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with close-on-exit set on new fd. */ +# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */ +# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */ #endif /* For F_[GET|SET]FD. */ @@ -203,7 +203,7 @@ struct flock64 #endif -#ifdef __USE_GNU +#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__ /* Flags for SYNC_FILE_RANGE. */ # define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages in the range before performing the @@ -226,7 +226,7 @@ struct flock64 __BEGIN_DECLS -#ifdef __USE_GNU +#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__ /* Provide kernel hint to read ahead. */ extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count) diff --git a/libc/sysdeps/linux/x86_64/bits/fenv.h b/libc/sysdeps/linux/x86_64/bits/fenv.h index 11859f00c..8c720e675 100644 --- a/libc/sysdeps/linux/x86_64/bits/fenv.h +++ b/libc/sysdeps/linux/x86_64/bits/fenv.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _FENV_H # error "Never use <bits/fenv.h> directly; include <fenv.h> instead." @@ -89,9 +88,9 @@ typedef struct fenv_t; /* If the default argument is used we use this value. */ -#define FE_DFL_ENV ((__const fenv_t *) -1) +#define FE_DFL_ENV ((const fenv_t *) -1) #ifdef __USE_GNU /* Floating-point environment where none of the exception is masked. */ -# define FE_NOMASK_ENV ((__const fenv_t *) -2) +# define FE_NOMASK_ENV ((const fenv_t *) -2) #endif diff --git a/libc/sysdeps/linux/x86_64/bits/kernel_stat.h b/libc/sysdeps/linux/x86_64/bits/kernel_stat.h index 7dca5ffbb..e194a7f76 100644 --- a/libc/sysdeps/linux/x86_64/bits/kernel_stat.h +++ b/libc/sysdeps/linux/x86_64/bits/kernel_stat.h @@ -1,14 +1,8 @@ /* Ripped from linux/include/asm-x86_64/stat.h * and renamed 'struct stat' to 'struct kernel_stat' */ -#ifndef _ASM_X86_64_STAT_H -#define _ASM_X86_64_STAT_H - -#ifndef _LIBC -#error bits/kernel_stat.h is for internal uClibc use only! -#endif - -#define STAT_HAVE_NSEC 1 +#ifndef _BITS_STAT_STRUCT_H +#define _BITS_STAT_STRUCT_H struct kernel_stat { unsigned long st_dev; @@ -24,30 +18,12 @@ struct kernel_stat { long st_blksize; long st_blocks; /* Number 512-byte blocks allocated. */ - unsigned long st_atime; - unsigned long st_atime_nsec; - unsigned long st_mtime; - unsigned long st_mtime_nsec; - unsigned long st_ctime; - unsigned long st_ctime_nsec; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; long __unused[3]; }; -/* For 32bit emulation */ -struct __old_kernel_stat { - unsigned short st_dev; - unsigned short st_ino; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - unsigned short st_rdev; - unsigned int st_size; - unsigned int st_atime; - unsigned int st_mtime; - unsigned int st_ctime; -}; - /* x86-64 stat64 is same as stat */ #define kernel_stat64 kernel_stat diff --git a/libc/sysdeps/linux/x86_64/bits/kernel_types.h b/libc/sysdeps/linux/x86_64/bits/kernel_types.h index 73f6ffb54..0cae08c60 100644 --- a/libc/sysdeps/linux/x86_64/bits/kernel_types.h +++ b/libc/sysdeps/linux/x86_64/bits/kernel_types.h @@ -4,8 +4,17 @@ * our private content, and not the kernel header, will win. * -Erik */ -#ifndef _ASM_X86_64_POSIX_TYPES_H + +/* a hack for compiling a 32 bit user space with 64 bit + * kernel on x86_64 */ +#if !defined(__ARCH_I386_POSIX_TYPES_H) && \ + !defined(_ASM_X86_64_POSIX_TYPES_H) && \ + !defined(_ASM_X86_POSIX_TYPES_32_H) && \ + !defined(_ASM_X86_POSIX_TYPES_64_H) #define _ASM_X86_64_POSIX_TYPES_H +#define __ARCH_I386_POSIX_TYPES_H +#define _ASM_X86_POSIX_TYPES_32_H +#define _ASM_X86_POSIX_TYPES_64_H typedef unsigned long __kernel_dev_t; typedef unsigned long __kernel_ino_t; @@ -31,6 +40,8 @@ typedef unsigned int __kernel_gid32_t; typedef unsigned short __kernel_old_uid_t; typedef unsigned short __kernel_old_gid_t; typedef __kernel_dev_t __kernel_old_dev_t; +typedef long __kernel_long_t; +typedef unsigned long __kernel_ulong_t; typedef long long __kernel_loff_t; typedef struct { @@ -41,4 +52,4 @@ typedef struct { #endif } __kernel_fsid_t; -#endif /* _ASM_X86_64_POSIX_TYPES_H */ +#endif diff --git a/libc/sysdeps/linux/x86_64/bits/mathdef.h b/libc/sysdeps/linux/x86_64/bits/mathdef.h index b0567e4d4..fc6524898 100644 --- a/libc/sysdeps/linux/x86_64/bits/mathdef.h +++ b/libc/sysdeps/linux/x86_64/bits/mathdef.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #if !defined _MATH_H && !defined _COMPLEX_H # error "Never use <bits/mathdef.h> directly; include <math.h> instead" diff --git a/libc/sysdeps/linux/x86_64/bits/mathinline.h b/libc/sysdeps/linux/x86_64/bits/mathinline.h index 39d11b678..d706ae4d0 100644 --- a/libc/sysdeps/linux/x86_64/bits/mathinline.h +++ b/libc/sysdeps/linux/x86_64/bits/mathinline.h @@ -14,9 +14,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _MATH_H # error "Never use <bits/mathinline.h> directly; include <math.h> instead." @@ -25,7 +24,7 @@ #ifdef __cplusplus # define __MATH_INLINE __inline #else -# define __MATH_INLINE extern __inline +# define __MATH_INLINE __extern_inline #endif diff --git a/libc/sysdeps/linux/x86_64/bits/mman.h b/libc/sysdeps/linux/x86_64/bits/mman.h index 535c9edcf..a0b7a0e97 100644 --- a/libc/sysdeps/linux/x86_64/bits/mman.h +++ b/libc/sysdeps/linux/x86_64/bits/mman.h @@ -1,104 +1,4 @@ -/* Definitions for POSIX memory map interface. Linux/x86_64 version. - Copyright (C) 2001, 2003, 2005, 2006 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _SYS_MMAN_H -# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead." -#endif - -/* The following definitions basically come from the kernel headers. - But the kernel header is not namespace clean. */ - - -/* Protections are chosen from these bits, OR'd together. The - implementation does not necessarily support PROT_EXEC or PROT_WRITE - without PROT_READ. The only guarantees are that no writing will be - allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */ - -#define PROT_READ 0x1 /* Page can be read. */ -#define PROT_WRITE 0x2 /* Page can be written. */ -#define PROT_EXEC 0x4 /* Page can be executed. */ -#define PROT_NONE 0x0 /* Page can not be accessed. */ -#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of - growsdown vma (mprotect only). */ -#define PROT_GROWSUP 0x02000000 /* Extend change to start of - growsup vma (mprotect only). */ - -/* Sharing types (must choose one and only one of these). */ -#define MAP_SHARED 0x01 /* Share changes. */ -#define MAP_PRIVATE 0x02 /* Changes are private. */ -#ifdef __USE_MISC -# define MAP_TYPE 0x0f /* Mask for type of mapping. */ -#endif - -/* Other flags. */ -#define MAP_FIXED 0x10 /* Interpret addr exactly. */ #ifdef __USE_MISC -# define MAP_FILE 0 -# define MAP_ANONYMOUS 0x20 /* Don't use a file. */ -# define MAP_ANON MAP_ANONYMOUS # define MAP_32BIT 0x40 /* Only give out 32-bit addresses. */ #endif - -/* These are Linux-specific. */ -#ifdef __USE_MISC -# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */ -# define MAP_DENYWRITE 0x00800 /* ETXTBSY */ -# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */ -# define MAP_LOCKED 0x02000 /* Lock the mapping. */ -# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */ -# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */ -# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */ -#endif - -/* Flags to `msync'. */ -#define MS_ASYNC 1 /* Sync memory asynchronously. */ -#define MS_SYNC 4 /* Synchronous memory sync. */ -#define MS_INVALIDATE 2 /* Invalidate the caches. */ - -/* Flags for `mlockall'. */ -#define MCL_CURRENT 1 /* Lock all currently mapped pages. */ -#define MCL_FUTURE 2 /* Lock all additions to address - space. */ - -/* Flags for `mremap'. */ -#ifdef __USE_GNU -# define MREMAP_MAYMOVE 1 -# define MREMAP_FIXED 2 -#endif - -/* Advice to `madvise'. */ -#ifdef __USE_BSD -# define MADV_NORMAL 0 /* No further special treatment. */ -# define MADV_RANDOM 1 /* Expect random page references. */ -# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */ -# define MADV_WILLNEED 3 /* Will need these pages. */ -# define MADV_DONTNEED 4 /* Don't need these pages. */ -# define MADV_REMOVE 9 /* Remove these pages and resources. */ -# define MADV_DONTFORK 10 /* Do not inherit across fork. */ -# define MADV_DOFORK 11 /* Do inherit across fork. */ -#endif - -/* The POSIX people had to invent similar names for the same things. */ -#ifdef __USE_XOPEN2K -# define POSIX_MADV_NORMAL 0 /* No further special treatment. */ -# define POSIX_MADV_RANDOM 1 /* Expect random page references. */ -# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */ -# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */ -# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */ -#endif +#include <bits/mman-common.h> diff --git a/libc/sysdeps/linux/x86_64/bits/msq.h b/libc/sysdeps/linux/x86_64/bits/msq.h index 422218a5f..838910713 100644 --- a/libc/sysdeps/linux/x86_64/bits/msq.h +++ b/libc/sysdeps/linux/x86_64/bits/msq.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_MSG_H # error "Never use <bits/msq.h> directly; include <sys/msg.h> instead." diff --git a/libc/sysdeps/linux/x86_64/bits/sem.h b/libc/sysdeps/linux/x86_64/bits/sem.h index 9b1d993ee..8c09031c7 100644 --- a/libc/sysdeps/linux/x86_64/bits/sem.h +++ b/libc/sysdeps/linux/x86_64/bits/sem.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_SEM_H # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead." diff --git a/libc/sysdeps/linux/x86_64/bits/setjmp.h b/libc/sysdeps/linux/x86_64/bits/setjmp.h index 515d769be..9a2c12863 100644 --- a/libc/sysdeps/linux/x86_64/bits/setjmp.h +++ b/libc/sysdeps/linux/x86_64/bits/setjmp.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +/* Copyright (C) 2001,2002,2003,2005,2006 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 @@ -12,13 +12,12 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* Define the machine-dependent type `jmp_buf'. x86-64 version. */ #ifndef _BITS_SETJMP_H -#define _BITS_SETJMP_H 1 +#define _BITS_SETJMP_H 1 #if !defined _SETJMP_H && !defined _PTHREAD_H # error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead." @@ -27,52 +26,9 @@ #include <bits/wordsize.h> #if __WORDSIZE == 64 - -/* We only need to save callee-saved registers plus stackpointer and - program counter. */ -# if defined __USE_MISC || defined _ASM -# define JB_RBX 0 -# define JB_RBP 1 -# define JB_R12 2 -# define JB_R13 3 -# define JB_R14 4 -# define JB_R15 5 -# define JB_RSP 6 -# define JB_PC 7 -# define JB_SIZE (8*8) -# endif - -#else - -# if defined __USE_MISC || defined _ASM -# define JB_BX 0 -# define JB_SI 1 -# define JB_DI 2 -# define JB_BP 3 -# define JB_SP 4 -# define JB_PC 5 -# define JB_SIZE 24 -# endif - -#endif - -#ifndef _ASM - -# if __WORDSIZE == 64 typedef long int __jmp_buf[8]; -# else +#else typedef int __jmp_buf[6]; -# endif - -/* Test if longjmp to JMPBUF would unwind the frame - containing a local variable at ADDRESS. */ -# if __WORDSIZE == 64 -# define _JMPBUF_UNWINDS(jmpbuf, address) \ - ((void *) (address) < (void *) (jmpbuf)[JB_RSP]) -# else -# define _JMPBUF_UNWINDS(jmpbuf, address) \ - ((void *) (address) < (void *) (jmpbuf)[JB_SP]) -# endif #endif -#endif /* bits/setjmp.h */ +#endif /* bits/setjmp.h */ diff --git a/libc/sysdeps/linux/x86_64/bits/shm.h b/libc/sysdeps/linux/x86_64/bits/shm.h index 3d8c05d21..3a25de562 100644 --- a/libc/sysdeps/linux/x86_64/bits/shm.h +++ b/libc/sysdeps/linux/x86_64/bits/shm.h @@ -13,9 +13,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_SHM_H # error "Never include <bits/shm.h> directly; use <sys/shm.h> instead." diff --git a/libc/sysdeps/linux/x86_64/bits/sigcontext.h b/libc/sysdeps/linux/x86_64/bits/sigcontext.h index c0d5fe72d..197c14883 100644 --- a/libc/sysdeps/linux/x86_64/bits/sigcontext.h +++ b/libc/sysdeps/linux/x86_64/bits/sigcontext.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _BITS_SIGCONTEXT_H #define _BITS_SIGCONTEXT_H 1 diff --git a/libc/sysdeps/linux/x86_64/bits/sigcontextinfo.h b/libc/sysdeps/linux/x86_64/bits/sigcontextinfo.h index 11493c580..1c4b89240 100644 --- a/libc/sysdeps/linux/x86_64/bits/sigcontextinfo.h +++ b/libc/sysdeps/linux/x86_64/bits/sigcontextinfo.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #define SIGCONTEXT siginfo_t *_si, struct ucontext * #define SIGCONTEXT_EXTRA_ARGS _si, diff --git a/libc/sysdeps/linux/x86_64/bits/stackinfo.h b/libc/sysdeps/linux/x86_64/bits/stackinfo.h index 60668d10b..2d50e7575 100644 --- a/libc/sysdeps/linux/x86_64/bits/stackinfo.h +++ b/libc/sysdeps/linux/x86_64/bits/stackinfo.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* This file contains a bit of information about the stack allocation of the processor. */ diff --git a/libc/sysdeps/linux/x86_64/bits/stat.h b/libc/sysdeps/linux/x86_64/bits/stat.h index 3a9c7740a..e25f01521 100644 --- a/libc/sysdeps/linux/x86_64/bits/stat.h +++ b/libc/sysdeps/linux/x86_64/bits/stat.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc. +/* Copyright (C) 1999,2000,2001,2002,2003,2009 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 @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_STAT_H # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead." @@ -61,7 +60,7 @@ struct stat __uid_t st_uid; /* User ID of the file's owner. */ __gid_t st_gid; /* Group ID of the file's group.*/ #if __WORDSIZE == 64 - int pad0; + int __pad0; #endif __dev_t st_rdev; /* Device number, if device. */ #if __WORDSIZE == 32 @@ -78,7 +77,7 @@ struct stat #else __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */ #endif -#if 0 /*def __USE_MISC*/ +#ifdef __USE_MISC /* Nanosecond resolution timestamps are stored in a format equivalent to 'struct timespec'. This is the type used whenever possible but the Unix namespace rules do not allow the @@ -129,7 +128,7 @@ struct stat64 __uid_t st_uid; /* User ID of the file's owner. */ __gid_t st_gid; /* Group ID of the file's group.*/ #if __WORDSIZE == 64 - int pad0; + int __pad0; __dev_t st_rdev; /* Device number, if device. */ __off_t st_size; /* Size of file, in bytes. */ #else @@ -139,7 +138,7 @@ struct stat64 #endif __blksize_t st_blksize; /* Optimal block size for I/O. */ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */ -#if 0 /*def __USE_MISC*/ +#ifdef __USE_MISC /* Nanosecond resolution timestamps are stored in a format equivalent to 'struct timespec'. This is the type used whenever possible but the Unix namespace rules do not allow the @@ -201,3 +200,8 @@ struct stat64 #define __S_IREAD 0400 /* Read by owner. */ #define __S_IWRITE 0200 /* Write by owner. */ #define __S_IEXEC 0100 /* Execute by owner. */ + +#ifdef __USE_ATFILE +# define UTIME_NOW ((1l << 30) - 1l) +# define UTIME_OMIT ((1l << 30) - 2l) +#endif diff --git a/libc/sysdeps/linux/x86_64/bits/syscalls.h b/libc/sysdeps/linux/x86_64/bits/syscalls.h index 80f42596a..e4ea4d833 100644 --- a/libc/sysdeps/linux/x86_64/bits/syscalls.h +++ b/libc/sysdeps/linux/x86_64/bits/syscalls.h @@ -13,59 +13,6 @@ #include <errno.h> -#define SYS_ify(syscall_name) (__NR_##syscall_name) - -#undef _syscall0 -#define _syscall0(type,name) \ -type name(void) \ -{ \ -return (type) (INLINE_SYSCALL(name, 0)); \ -} - -#undef _syscall1 -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ -return (type) (INLINE_SYSCALL(name, 1, arg1)); \ -} - -#undef _syscall2 -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ -{ \ -return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \ -} - -#undef _syscall3 -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \ -} - -#undef _syscall4 -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \ -} - -#undef _syscall5 -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \ -} - -#undef _syscall6 -#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5,type6,arg6) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ -{ \ -return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ -} - /* The Linux/x86-64 kernel expects the system call parameters in registers according to the following table: @@ -103,9 +50,6 @@ return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ Syscalls of more than 6 arguments are not supported. */ -#undef SYS_ify -#define SYS_ify(syscall_name) __NR_##syscall_name - #undef DO_CALL #define DO_CALL(syscall_name, args) \ DOARGS_##args \ @@ -122,41 +66,19 @@ return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ /* Define a macro which expands inline into the wrapper code for a system call. */ -#undef INLINE_SYSCALL -#define INLINE_SYSCALL(name, nr, args...) \ - ({ \ - unsigned long _resultvar = INTERNAL_SYSCALL (name, , nr, args); \ - if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_resultvar, ), 0)) \ - { \ - __set_errno (INTERNAL_SYSCALL_ERRNO (_resultvar, )); \ - _resultvar = (unsigned long) -1; \ - } \ - (long) _resultvar; }) - -#undef INTERNAL_SYSCALL_DECL -#define INTERNAL_SYSCALL_DECL(err) do { } while (0) - #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ +(__extension__ \ ({ \ unsigned long resultvar; \ LOAD_ARGS_##nr (args) \ LOAD_REGS_##nr \ - __asm__ __volatile__ ( \ + __asm__ __volatile__ ( \ "syscall\n\t" \ : "=a" (resultvar) \ : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \ - (long) resultvar; }) -#undef INTERNAL_SYSCALL -#define INTERNAL_SYSCALL(name, err, nr, args...) \ - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args) - -#undef INTERNAL_SYSCALL_ERROR_P -#define INTERNAL_SYSCALL_ERROR_P(val, err) \ - ((unsigned long) (val) >= -4095L) - -#undef INTERNAL_SYSCALL_ERRNO -#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) - + (long) resultvar; \ + }) \ +) #define LOAD_ARGS_0() #define LOAD_REGS_0 #define ASM_ARGS_0 @@ -165,49 +87,49 @@ return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \ long int __arg1 = (long) (a1); \ LOAD_ARGS_0 () #define LOAD_REGS_1 \ - register long int _a1 __asm__ ("rdi") = __arg1; \ + register long int __a1 __asm__ ("rdi") = __arg1; \ LOAD_REGS_0 -#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1) +#define ASM_ARGS_1 ASM_ARGS_0, "r" (__a1) #define LOAD_ARGS_2(a1, a2) \ long int __arg2 = (long) (a2); \ LOAD_ARGS_1 (a1) #define LOAD_REGS_2 \ - register long int _a2 __asm__ ("rsi") = __arg2; \ + register long int __a2 __asm__ ("rsi") = __arg2; \ LOAD_REGS_1 -#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2) +#define ASM_ARGS_2 ASM_ARGS_1, "r" (__a2) #define LOAD_ARGS_3(a1, a2, a3) \ long int __arg3 = (long) (a3); \ LOAD_ARGS_2 (a1, a2) #define LOAD_REGS_3 \ - register long int _a3 __asm__ ("rdx") = __arg3; \ + register long int __a3 __asm__ ("rdx") = __arg3; \ LOAD_REGS_2 -#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3) +#define ASM_ARGS_3 ASM_ARGS_2, "r" (__a3) #define LOAD_ARGS_4(a1, a2, a3, a4) \ long int __arg4 = (long) (a4); \ LOAD_ARGS_3 (a1, a2, a3) #define LOAD_REGS_4 \ - register long int _a4 __asm__ ("r10") = __arg4; \ + register long int __a4 __asm__ ("r10") = __arg4; \ LOAD_REGS_3 -#define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4) +#define ASM_ARGS_4 ASM_ARGS_3, "r" (__a4) #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ long int __arg5 = (long) (a5); \ LOAD_ARGS_4 (a1, a2, a3, a4) #define LOAD_REGS_5 \ - register long int _a5 __asm__ ("r8") = __arg5; \ + register long int __a5 __asm__ ("r8") = __arg5; \ LOAD_REGS_4 -#define ASM_ARGS_5 ASM_ARGS_4, "r" (_a5) +#define ASM_ARGS_5 ASM_ARGS_4, "r" (__a5) #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ long int __arg6 = (long) (a6); \ LOAD_ARGS_5 (a1, a2, a3, a4, a5) #define LOAD_REGS_6 \ - register long int _a6 __asm__ ("r9") = __arg6; \ + register long int __a6 __asm__ ("r9") = __arg6; \ LOAD_REGS_5 -#define ASM_ARGS_6 ASM_ARGS_5, "r" (_a6) +#define ASM_ARGS_6 ASM_ARGS_5, "r" (__a6) #endif /* __ASSEMBLER__ */ #endif /* _BITS_SYSCALLS_H */ diff --git a/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h index e3e2c8332..43801699e 100644 --- a/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h +++ b/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h @@ -11,28 +11,31 @@ /* can your target use syscall6() for mmap ? */ #define __UCLIBC_MMAP_HAS_6_ARGS__ -/* does your target use syscall4() for truncate64 ? (32bit arches only) */ -#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__ +/* does your target align 64bit values in register pairs ? (32bit arches only) */ +#undef __UCLIBC_SYSCALL_ALIGN_64BIT__ /* does your target have a broken create_module() ? */ #undef __UCLIBC_BROKEN_CREATE_MODULE__ +/* does your target have to worry about older [gs]etrlimit() ? */ +#undef __UCLIBC_HANDLE_OLDER_RLIMIT__ + /* does your target have an asm .set ? */ #define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__ -/* define if target doesn't like .global */ -#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__ - /* define if target supports .weak */ #define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__ /* define if target supports .weakext */ #undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__ -/* needed probably only for ppc64 */ -#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__ +/* define if target supports CFI pseudo ops */ +#define __UCLIBC_HAVE_ASM_CFI_DIRECTIVES__ /* define if target supports IEEE signed zero floats */ #define __UCLIBC_HAVE_SIGNED_ZERO__ +/* only weird assemblers generally need this */ +#undef __UCLIBC_ASM_LINE_SEP__ + #endif /* _BITS_UCLIBC_ARCH_FEATURES_H */ diff --git a/libc/sysdeps/linux/x86_64/bits/wordsize.h b/libc/sysdeps/linux/x86_64/bits/wordsize.h index 0cce4ead9..9db982c90 100644 --- a/libc/sysdeps/linux/x86_64/bits/wordsize.h +++ b/libc/sysdeps/linux/x86_64/bits/wordsize.h @@ -1,8 +1,12 @@ /* Determine the wordsize from the preprocessor defines. */ -#if defined __x86_64__ +#if defined __x86_64__ && !defined __ILP32__ # define __WORDSIZE 64 -/*# define __WORDSIZE_COMPAT32 1*/ #else # define __WORDSIZE 32 #endif + +#ifdef __x86_64__ +/* This makes /var/run/utmp compatible with 32-bit environment: */ +# define __WORDSIZE_TIME64_COMPAT32 1 +#endif diff --git a/libc/sysdeps/linux/x86_64/brk.c b/libc/sysdeps/linux/x86_64/brk.c index eddfd9830..66b34b527 100644 --- a/libc/sysdeps/linux/x86_64/brk.c +++ b/libc/sysdeps/linux/x86_64/brk.c @@ -13,9 +13,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <unistd.h> @@ -24,20 +23,20 @@ /* This must be initialized data because commons can't have aliases. */ void *__curbrk attribute_hidden = 0; -libc_hidden_proto(brk) -int brk (void *addr) +int brk(void *addr) { - void *__unbounded newbrk; + void *newbrk; __asm__ ("syscall\n" - : "=a" (newbrk) - : "0" (__NR_brk), "D" (__ptrvalue (addr)) - : "r11","rcx","memory"); + : "=a" (newbrk) + : "0" (__NR_brk), "D" (addr) + : "r11", "rcx" + ); __curbrk = newbrk; if (newbrk < addr) { - __set_errno (ENOMEM); + __set_errno(ENOMEM); return -1; } diff --git a/libc/sysdeps/linux/x86_64/bsd-_setjmp.S b/libc/sysdeps/linux/x86_64/bsd-_setjmp.S index 81a4352f3..7fd985958 100644 --- a/libc/sysdeps/linux/x86_64/bsd-_setjmp.S +++ b/libc/sysdeps/linux/x86_64/bsd-_setjmp.S @@ -13,17 +13,18 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* This just does a tail-call to `__sigsetjmp (ARG, 0)'. We cannot do it in C because it must be a tail-call, so frame-unwinding in setjmp doesn't clobber the state restored by longjmp. */ +#include <sysdep.h> + .global _setjmp .type _setjmp,%function _setjmp: xorq %rsi, %rsi - jmp __sigsetjmp@PLT + jmp HIDDEN_JUMPTARGET(__sigsetjmp) .size _setjmp,.-_setjmp diff --git a/libc/sysdeps/linux/x86_64/bsd-setjmp.S b/libc/sysdeps/linux/x86_64/bsd-setjmp.S index a906a6132..1d3b8ee1f 100644 --- a/libc/sysdeps/linux/x86_64/bsd-setjmp.S +++ b/libc/sysdeps/linux/x86_64/bsd-setjmp.S @@ -13,17 +13,12 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define _ASM -#define _SETJMP_H -#include <bits/setjmp.h> + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ .global setjmp .type setjmp,%function setjmp: movq $1, %rsi - jmp __sigsetjmp@PLT + jmp HIDDEN_JUMPTARGET(__sigsetjmp) .size setjmp,.-setjmp diff --git a/libc/sysdeps/linux/x86_64/clone.S b/libc/sysdeps/linux/x86_64/clone.S index dc5eeb0a0..374504140 100644 --- a/libc/sysdeps/linux/x86_64/clone.S +++ b/libc/sysdeps/linux/x86_64/clone.S @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* clone() is even more special than fork() as it mucks with stacks and invokes a function in the right context after its all over. */ @@ -109,6 +108,8 @@ clone: call *%rax /* Call exit with return value from function call. */ movq %rax, %rdi - call HIDDEN_JUMPTARGET(_exit) + movl $__NR_exit, %eax + syscall .size clone,.-clone +weak_alias(clone, __clone) diff --git a/libc/sysdeps/linux/x86_64/crt1.S b/libc/sysdeps/linux/x86_64/crt1.S index f6c1eb1e7..87777dd5d 100644 --- a/libc/sysdeps/linux/x86_64/crt1.S +++ b/libc/sysdeps/linux/x86_64/crt1.S @@ -31,9 +31,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* Originally based on glibc's sysdeps/x86_64/elf/start.S */ @@ -55,7 +54,9 @@ ... NULL */ - +#if defined NOT_IN_libc +# error error in build framework +#endif #include <features.h> .text diff --git a/libc/sysdeps/linux/x86_64/crtn.S b/libc/sysdeps/linux/x86_64/crtn.S index 5b110d967..9804e0f76 100644 --- a/libc/sysdeps/linux/x86_64/crtn.S +++ b/libc/sysdeps/linux/x86_64/crtn.S @@ -7,7 +7,6 @@ .type _init, %function addq $8, %rsp ret -.size _init,.-_init .section .fini @@ -15,4 +14,3 @@ .type _fini, %function addq $8, %rsp ret -.size _fini, .-_fini diff --git a/libc/sysdeps/linux/x86_64/fpu_control.h b/libc/sysdeps/linux/x86_64/fpu_control.h index 6e9b3b362..2ff4edb53 100644 --- a/libc/sysdeps/linux/x86_64/fpu_control.h +++ b/libc/sysdeps/linux/x86_64/fpu_control.h @@ -14,9 +14,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _FPU_CONTROL_H #define _FPU_CONTROL_H 1 diff --git a/libc/sysdeps/linux/x86_64/getcontext.S b/libc/sysdeps/linux/x86_64/getcontext.S new file mode 100644 index 000000000..dcebc4f29 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/getcontext.S @@ -0,0 +1,88 @@ +/* Save current context. + Copyright (C) 2002-2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2002. + + 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> + +#include "ucontext_i.h" + +/* int __getcontext (ucontext_t *ucp) + + Saves the machine context in UCP such that when it is activated, + it appears as if __getcontext() returned again. + + This implementation is intended to be used for *synchronous* context + switches only. Therefore, it does not have to save anything + other than the PRESERVED state. */ + + +ENTRY(__getcontext) + /* Save the preserved registers, the registers used for passing + args, and the return address. */ + movq %rbx, oRBX(%rdi) + movq %rbp, oRBP(%rdi) + movq %r12, oR12(%rdi) + movq %r13, oR13(%rdi) + movq %r14, oR14(%rdi) + movq %r15, oR15(%rdi) + + movq %rdi, oRDI(%rdi) + movq %rsi, oRSI(%rdi) + movq %rdx, oRDX(%rdi) + movq %rcx, oRCX(%rdi) + movq %r8, oR8(%rdi) + movq %r9, oR9(%rdi) + + movq (%rsp), %rcx + movq %rcx, oRIP(%rdi) + leaq 8(%rsp), %rcx /* Exclude the return address. */ + movq %rcx, oRSP(%rdi) + + /* We have separate floating-point register content memory on the + stack. We use the __fpregs_mem block in the context. Set the + links up correctly. */ + + leaq oFPREGSMEM(%rdi), %rcx + movq %rcx, oFPREGS(%rdi) + /* Save the floating-point environment. */ + fnstenv (%rcx) + fldenv (%rcx) + stmxcsr oMXCSR(%rdi) + + /* Save the current signal mask with + rt_sigprocmask (SIG_BLOCK, NULL, set,_NSIG/8). */ + leaq oSIGMASK(%rdi), %rdx + xorl %esi,%esi +#if SIG_BLOCK == 0 + xorl %edi, %edi +#else + movl $SIG_BLOCK, %edi +#endif + movl $_NSIG8,%r10d + movl $__NR_rt_sigprocmask, %eax + syscall + cmpq $-4095, %rax /* Check %rax for error. */ + jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */ + + /* All done, return 0 for success. */ + xorl %eax, %eax +L(pseudo_end): + ret +PSEUDO_END(__getcontext) + +weak_alias (__getcontext, getcontext) diff --git a/libc/sysdeps/linux/x86_64/jmpbuf-offsets.h b/libc/sysdeps/linux/x86_64/jmpbuf-offsets.h new file mode 100644 index 000000000..55f7c9719 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/jmpbuf-offsets.h @@ -0,0 +1,45 @@ +/* Private macros for accessing __jmp_buf contents. x86-64 version. + Copyright (C) 2006 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 <bits/wordsize.h> + +#if __WORDSIZE == 64 + +/* We only need to save callee-saved registers plus stackpointer and + program counter. */ +# define JB_RBX 0 +# define JB_RBP 1 +# define JB_R12 2 +# define JB_R13 3 +# define JB_R14 4 +# define JB_R15 5 +# define JB_RSP 6 +# define JB_PC 7 +# define JB_SIZE (8*8) + +#else + +# define JB_BX 0 +# define JB_SI 1 +# define JB_DI 2 +# define JB_BP 3 +# define JB_SP 4 +# define JB_PC 5 +# define JB_SIZE 24 + +#endif diff --git a/libc/sysdeps/linux/x86_64/jmpbuf-unwind.h b/libc/sysdeps/linux/x86_64/jmpbuf-unwind.h new file mode 100644 index 000000000..152587222 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/jmpbuf-unwind.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ +#include <setjmp.h> +#include <jmpbuf-offsets.h> + +/* Test if longjmp to JMPBUF would unwind the frame + containing a local variable at ADDRESS. */ +#if __WORDSIZE == 64 +# define _JMPBUF_UNWINDS(jmpbuf, address) \ + ((void *) (address) < (void *) (jmpbuf)[JB_RSP]) +#else +# define _JMPBUF_UNWINDS(jmpbuf, address) \ + ((void *) (address) < (void *) (jmpbuf)[JB_SP]) +#endif + +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +#include <stdint.h> +#include <unwind.h> + +#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \ + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj) + +#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \ + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[JB_RSP] - (_adj)) +#endif diff --git a/libc/sysdeps/linux/x86_64/makecontext.c b/libc/sysdeps/linux/x86_64/makecontext.c new file mode 100644 index 000000000..54730312a --- /dev/null +++ b/libc/sysdeps/linux/x86_64/makecontext.c @@ -0,0 +1,121 @@ +/* Create new context. + Copyright (C) 2002, 2004, 2005, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2002. + + 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> +#include <stdarg.h> +#include <stdint.h> +#include <ucontext.h> + +#include "ucontext_i.h" + +/* This implementation can handle any ARGC value but only + normal integer parameters. + makecontext sets up a stack and the registers for the + user context. The stack looks like this: + +-----------------------+ + | next context | + +-----------------------+ + | parameter 7-n | + +-----------------------+ + | trampoline address | + %rsp -> +-----------------------+ + + The registers are set up like this: + %rdi,%rsi,%rdx,%rcx,%r8,%r9: parameter 1 to 6 + %rbx : address of next context + %rsp : stack pointer. +*/ + +/* XXX: This implementation currently only handles integer arguments. + To handle long int and pointer arguments the va_arg arguments needs + to be changed to long and also the stdlib/tst-setcontext.c file needs + to be changed to pass long arguments to makecontext. */ + + +void +__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) +{ + extern void __start_context (void); + greg_t *sp; + unsigned int idx_uc_link; + va_list ap; + int i; + + /* Generate room on stack for parameter if needed and uc_link. */ + sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + + ucp->uc_stack.ss_size); + sp -= (argc > 6 ? argc - 6 : 0) + 1; + /* Align stack and make space for trampoline address. */ + sp = (greg_t *) ((((uintptr_t) sp) & -16L) - 8); + + idx_uc_link = (argc > 6 ? argc - 6 : 0) + 1; + + /* Setup context ucp. */ + /* Address to jump to. */ + ucp->uc_mcontext.gregs[REG_RIP] = (uintptr_t) func; + /* Setup rbx.*/ + ucp->uc_mcontext.gregs[REG_RBX] = (uintptr_t) &sp[idx_uc_link]; + ucp->uc_mcontext.gregs[REG_RSP] = (uintptr_t) sp; + + /* Setup stack. */ + sp[0] = (uintptr_t) &__start_context; + sp[idx_uc_link] = (uintptr_t) ucp->uc_link; + + va_start (ap, argc); + /* Handle arguments. + + The standard says the parameters must all be int values. This is + an historic accident and would be done differently today. For + x86-64 all integer values are passed as 64-bit values and + therefore extending the API to copy 64-bit values instead of + 32-bit ints makes sense. It does not break existing + functionality and it does not violate the standard which says + that passing non-int values means undefined behavior. */ + for (i = 0; i < argc; ++i) + switch (i) + { + case 0: + ucp->uc_mcontext.gregs[REG_RDI] = va_arg (ap, greg_t); + break; + case 1: + ucp->uc_mcontext.gregs[REG_RSI] = va_arg (ap, greg_t); + break; + case 2: + ucp->uc_mcontext.gregs[REG_RDX] = va_arg (ap, greg_t); + break; + case 3: + ucp->uc_mcontext.gregs[REG_RCX] = va_arg (ap, greg_t); + break; + case 4: + ucp->uc_mcontext.gregs[REG_R8] = va_arg (ap, greg_t); + break; + case 5: + ucp->uc_mcontext.gregs[REG_R9] = va_arg (ap, greg_t); + break; + default: + /* Put value on stack. */ + sp[i - 5] = va_arg (ap, greg_t); + break; + } + va_end (ap); + +} + + +weak_alias (__makecontext, makecontext) diff --git a/libc/sysdeps/linux/x86_64/mmap.c b/libc/sysdeps/linux/x86_64/mmap.c deleted file mode 100644 index baaee6847..000000000 --- a/libc/sysdeps/linux/x86_64/mmap.c +++ /dev/null @@ -1,20 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * mmap() for uClibc/x86_64 - * - * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> - * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org> - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -#include <errno.h> -#include <unistd.h> -#include <sys/mman.h> -#include <sys/syscall.h> - -libc_hidden_proto(mmap) - -_syscall6(void *, mmap, void *, start, size_t, length, int, prot, - int, flags, int, fd, off_t, offset); -libc_hidden_def(mmap) diff --git a/libc/sysdeps/linux/x86_64/sched_getcpu.S b/libc/sysdeps/linux/x86_64/sched_getcpu.S new file mode 100644 index 000000000..f8c09c0f2 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/sched_getcpu.S @@ -0,0 +1,71 @@ +/* Copyright (C) 2007, 2011 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> +#include <tls.h> +#define _ERRNO_H 1 +#include <bits/errno.h> +#include <bits/kernel-features.h> + +/* For the calculation see asm/vsyscall.h. */ +#define VSYSCALL_ADDR_vgetcpu 0xffffffffff600800 + + +ENTRY (sched_getcpu) + /* Align stack and create local variable for result. */ + sub $0x8, %rsp + cfi_adjust_cfa_offset(8) + + movq %rsp, %rdi + xorl %esi, %esi + movl $VGETCPU_CACHE_OFFSET, %edx + addq %fs:0, %rdx + +#ifdef SHARED + movq __vdso_getcpu(%rip), %rax + PTR_DEMANGLE (%rax) + callq *%rax +#else +# ifdef __NR_getcpu + movl $__NR_getcpu, %eax + syscall +# ifndef __ASSUME_GETCPU_SYSCALL + cmpq $-ENOSYS, %rax + jne 1f +# endif +# endif +# ifndef __ASSUME_GETCPU_SYSCALL + movq $VSYSCALL_ADDR_vgetcpu, %rax + callq *%rax +1: +# else +# ifndef __NR_getcpu +# error "cannot happen" +# endif +# endif +#endif + + cmpq $-4095, %rax + jae SYSCALL_ERROR_LABEL + + movl (%rsp), %eax + +L(pseudo_end): + add $0x8, %rsp + cfi_adjust_cfa_offset(-8) + ret +PSEUDO_END(sched_getcpu) diff --git a/libc/sysdeps/linux/x86_64/setcontext.S b/libc/sysdeps/linux/x86_64/setcontext.S new file mode 100644 index 000000000..561ab9f75 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/setcontext.S @@ -0,0 +1,103 @@ +/* Install given context. + Copyright (C) 2002-2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2002. + + 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> + +#include "ucontext_i.h" + + +/* int __setcontext (const ucontext_t *ucp) + + Restores the machine context in UCP and thereby resumes execution + in that context. + + This implementation is intended to be used for *synchronous* context + switches only. Therefore, it does not have to restore anything + other than the PRESERVED state. */ + +ENTRY(__setcontext) + /* Save argument since syscall will destroy it. */ + pushq %rdi + cfi_adjust_cfa_offset(8) + + /* Set the signal mask with + rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8). */ + leaq oSIGMASK(%rdi), %rsi + xorl %edx, %edx + movl $SIG_SETMASK, %edi + movl $_NSIG8,%r10d + movl $__NR_rt_sigprocmask, %eax + syscall + popq %rdi /* Reload %rdi, adjust stack. */ + cfi_adjust_cfa_offset(-8) + cmpq $-4095, %rax /* Check %rax for error. */ + jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */ + + /* Restore the floating-point context. Not the registers, only the + rest. */ + movq oFPREGS(%rdi), %rcx + fldenv (%rcx) + ldmxcsr oMXCSR(%rdi) + + + /* Load the new stack pointer, the preserved registers and + registers used for passing args. */ + cfi_def_cfa(%rdi, 0) + cfi_offset(%rbx,oRBX) + cfi_offset(%rbp,oRBP) + cfi_offset(%r12,oR12) + cfi_offset(%r13,oR13) + cfi_offset(%r14,oR14) + cfi_offset(%r15,oR15) + cfi_offset(%rsp,oRSP) + cfi_offset(%rip,oRIP) + + movq oRSP(%rdi), %rsp + movq oRBX(%rdi), %rbx + movq oRBP(%rdi), %rbp + movq oR12(%rdi), %r12 + movq oR13(%rdi), %r13 + movq oR14(%rdi), %r14 + movq oR15(%rdi), %r15 + + /* The following ret should return to the address set with + getcontext. Therefore push the address on the stack. */ + movq oRIP(%rdi), %rcx + pushq %rcx + + movq oRSI(%rdi), %rsi + movq oRDX(%rdi), %rdx + movq oRCX(%rdi), %rcx + movq oR8(%rdi), %r8 + movq oR9(%rdi), %r9 + + /* Setup finally %rdi. */ + movq oRDI(%rdi), %rdi + + /* End FDE here, we fall into another context. */ + cfi_endproc + cfi_startproc + + /* Clear rax to indicate success. */ + xorl %eax, %eax +L(pseudo_end): + ret +PSEUDO_END(__setcontext) + +weak_alias (__setcontext, setcontext) diff --git a/libc/sysdeps/linux/x86_64/setjmp.S b/libc/sysdeps/linux/x86_64/setjmp.S index eb4b97363..648946f54 100644 --- a/libc/sysdeps/linux/x86_64/setjmp.S +++ b/libc/sysdeps/linux/x86_64/setjmp.S @@ -13,13 +13,10 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ -#define _ASM -#define _SETJMP_H -#include <bits/setjmp.h> +#include <jmpbuf-offsets.h> .global __sigsetjmp .type __sigsetjmp,%function @@ -43,3 +40,4 @@ __sigsetjmp: jmp __sigjmp_save #endif .size __sigsetjmp,.-__sigsetjmp +libc_hidden_def(__sigsetjmp) diff --git a/libc/sysdeps/linux/x86_64/sigaction.c b/libc/sysdeps/linux/x86_64/sigaction.c index aa5c0d472..a4042a9c8 100644 --- a/libc/sysdeps/linux/x86_64/sigaction.c +++ b/libc/sysdeps/linux/x86_64/sigaction.c @@ -13,9 +13,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -25,90 +24,64 @@ #include <sys/syscall.h> -/* The difference here is that the sigaction structure used in the - kernel is not the same as we use in the libc. Therefore we must - translate it here. */ #include <bits/kernel_sigaction.h> /* We do not globally define the SA_RESTORER flag so do it here. */ #define SA_RESTORER 0x04000000 -extern __typeof(sigaction) __libc_sigaction; - #ifdef __NR_rt_sigaction + /* Using the hidden attribute here does not change the code but it helps to avoid warnings. */ -extern void restore_rt (void) __asm__ ("__restore_rt") attribute_hidden; -extern void restore (void) __asm__ ("__restore") attribute_hidden; - -/* Experimentally off - libc_hidden_proto(memcpy) */ +extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden; +extern void restore(void) __asm__ ("__restore") attribute_hidden; /* If ACT is not NULL, change the action for SIG to *ACT. If OACT is not NULL, put the old action for SIG in *OACT. */ int -__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) +__libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact) { - int result; - struct kernel_sigaction kact, koact; + struct sigaction kact; if (act) { - kact.k_sa_handler = act->sa_handler; - memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t)); - kact.sa_flags = act->sa_flags | SA_RESTORER; - + memcpy(&kact, act, sizeof(kact)); + kact.sa_flags |= SA_RESTORER; kact.sa_restorer = &restore_rt; + act = &kact; } - - /* XXX The size argument hopefully will have to be changed to the - real size of the user-level sigset_t. */ - result = INLINE_SYSCALL (rt_sigaction, 4, - sig, act ? __ptrvalue (&kact) : NULL, - oact ? __ptrvalue (&koact) : NULL, _NSIG / 8); - if (oact && result >= 0) { - oact->sa_handler = koact.k_sa_handler; - memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t)); - oact->sa_flags = koact.sa_flags; - oact->sa_restorer = koact.sa_restorer; - } - return result; + /* NB: kernel (as of 2.6.25) will return EINVAL + * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */ + return INLINE_SYSCALL(rt_sigaction, 4, sig, act, oact, sizeof(act->sa_mask)); } + #else -extern void restore (void) __asm__ ("__restore") attribute_hidden; +extern void restore(void) __asm__ ("__restore") attribute_hidden; /* If ACT is not NULL, change the action for SIG to *ACT. If OACT is not NULL, put the old action for SIG in *OACT. */ int -__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) +__libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact) { int result; struct old_kernel_sigaction kact, koact; -#ifdef SIGCANCEL - if (sig == SIGCANCEL) { - __set_errno (EINVAL); - return -1; - } -#endif - if (act) { kact.k_sa_handler = act->sa_handler; kact.sa_mask = act->sa_mask.__val[0]; kact.sa_flags = act->sa_flags | SA_RESTORER; kact.sa_restorer = &restore; } - - __asm__ __volatile__ ("syscall\n" - : "=a" (result) - : "0" (__NR_sigaction), "mr" (sig), - "c" (act ? __ptrvalue (&kact) : 0), - "d" (oact ? __ptrvalue (&koact) : 0)); - + __asm__ __volatile__ ( + "syscall\n" + : "=a" (result) + : "0" (__NR_sigaction), "mr" (sig), + "c" (act ? &kact : NULL), + "d" (oact ? &koact : NULL)); if (result < 0) { __set_errno(-result); return -1; } - if (oact) { oact->sa_handler = koact.k_sa_handler; oact->sa_mask.__val[0] = koact.sa_mask; @@ -117,34 +90,50 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) } return result; } + #endif + #ifndef LIBC_SIGACTION -libc_hidden_proto(sigaction) +# ifndef __UCLIBC_HAS_THREADS__ +strong_alias(__libc_sigaction,sigaction) +libc_hidden_def(sigaction) +# else weak_alias(__libc_sigaction,sigaction) libc_hidden_weak(sigaction) +# endif #endif + /* NOTE: Please think twice before making any changes to the bits of code below. GDB needs some intimate knowledge about it to recognize them as signal trampolines, and make backtraces through signal handlers work right. Important are both the names (__restore_rt) and the exact instruction sequence. If you ever feel the need to make any changes, please notify the - appropriate GDB maintainer. */ - -#define RESTORE(name, syscall) RESTORE2 (name, syscall) -# define RESTORE2(name, syscall) \ -__asm__ ( \ - ".text\n" \ - "__" #name ":\n" \ - " movq $" #syscall ", %rax\n" \ - " syscall\n" \ - ); + appropriate GDB maintainer. + + The unwind information starts a byte before __restore_rt, so that + it is found when unwinding, to get an address the unwinder assumes + will be in the middle of a call instruction. See the Linux kernel + (the i386 vsyscall, in particular) for an explanation of the complex + unwind information used here in order to get the traditional CFA. + */ + +#define RESTORE(name, syscall) RESTORE2(name, syscall) +#define RESTORE2(name, syscall) \ +__asm__ ( \ + "nop\n" \ + ".text\n" \ + "__" #name ":\n" \ + " movq $" #syscall ", %rax\n" \ + " syscall\n" \ +); + #ifdef __NR_rt_sigaction /* The return code for realtime-signals. */ -RESTORE (restore_rt, __NR_rt_sigreturn) +RESTORE(restore_rt, __NR_rt_sigreturn) #endif #ifdef __NR_sigreturn -RESTORE (restore, __NR_sigreturn) +RESTORE(restore, __NR_sigreturn) #endif diff --git a/libc/sysdeps/linux/x86_64/swapcontext.S b/libc/sysdeps/linux/x86_64/swapcontext.S new file mode 100644 index 000000000..6d2ebb823 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/swapcontext.S @@ -0,0 +1,121 @@ +/* Save current context and install the given one. + Copyright (C) 2002-2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2002. + + 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> + +#include "ucontext_i.h" + + +/* int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp); + + Saves the machine context in oucp such that when it is activated, + it appears as if __swapcontextt() returned again, restores the + machine context in ucp and thereby resumes execution in that + context. + + This implementation is intended to be used for *synchronous* context + switches only. Therefore, it does not have to save anything + other than the PRESERVED state. */ + +ENTRY(__swapcontext) + /* Save the preserved registers, the registers used for passing args, + and the return address. */ + movq %rbx, oRBX(%rdi) + movq %rbp, oRBP(%rdi) + movq %r12, oR12(%rdi) + movq %r13, oR13(%rdi) + movq %r14, oR14(%rdi) + movq %r15, oR15(%rdi) + + movq %rdi, oRDI(%rdi) + movq %rsi, oRSI(%rdi) + movq %rdx, oRDX(%rdi) + movq %rcx, oRCX(%rdi) + movq %r8, oR8(%rdi) + movq %r9, oR9(%rdi) + + movq (%rsp), %rcx + movq %rcx, oRIP(%rdi) + leaq 8(%rsp), %rcx /* Exclude the return address. */ + movq %rcx, oRSP(%rdi) + + /* We have separate floating-point register content memory on the + stack. We use the __fpregs_mem block in the context. Set the + links up correctly. */ + leaq oFPREGSMEM(%rdi), %rcx + movq %rcx, oFPREGS(%rdi) + /* Save the floating-point environment. */ + fnstenv (%rcx) + stmxcsr oMXCSR(%rdi) + + + /* The syscall destroys some registers, save them. */ + movq %rsi, %r12 + + /* Save the current signal mask and install the new one with + rt_sigprocmask (SIG_BLOCK, newset, oldset,_NSIG/8). */ + leaq oSIGMASK(%rdi), %rdx + leaq oSIGMASK(%rsi), %rsi + movl $SIG_SETMASK, %edi + movl $_NSIG8,%r10d + movl $__NR_rt_sigprocmask, %eax + syscall + cmpq $-4095, %rax /* Check %rax for error. */ + jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */ + + /* Restore destroyed registers. */ + movq %r12, %rsi + + /* Restore the floating-point context. Not the registers, only the + rest. */ + movq oFPREGS(%rsi), %rcx + fldenv (%rcx) + ldmxcsr oMXCSR(%rsi) + + /* Load the new stack pointer and the preserved registers. */ + movq oRSP(%rsi), %rsp + movq oRBX(%rsi), %rbx + movq oRBP(%rsi), %rbp + movq oR12(%rsi), %r12 + movq oR13(%rsi), %r13 + movq oR14(%rsi), %r14 + movq oR15(%rsi), %r15 + + /* The following ret should return to the address set with + getcontext. Therefore push the address on the stack. */ + movq oRIP(%rsi), %rcx + pushq %rcx + + /* Setup registers used for passing args. */ + movq oRDI(%rsi), %rdi + movq oRDX(%rsi), %rdx + movq oRCX(%rsi), %rcx + movq oR8(%rsi), %r8 + movq oR9(%rsi), %r9 + + /* Setup finally %rsi. */ + movq oRSI(%rsi), %rsi + + /* Clear rax to indicate success. */ + xorl %eax, %eax +L(pseudo_end): + ret +PSEUDO_END(__swapcontext) + +weak_alias (__swapcontext, swapcontext) diff --git a/libc/sysdeps/linux/x86_64/sys/debugreg.h b/libc/sysdeps/linux/x86_64/sys/debugreg.h index 8abbf7546..170431ed0 100644 --- a/libc/sysdeps/linux/x86_64/sys/debugreg.h +++ b/libc/sysdeps/linux/x86_64/sys/debugreg.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_DEBUGREG_H #define _SYS_DEBUGREG_H 1 diff --git a/libc/sysdeps/linux/x86_64/sys/epoll.h b/libc/sysdeps/linux/x86_64/sys/epoll.h deleted file mode 100644 index 02672d3c7..000000000 --- a/libc/sysdeps/linux/x86_64/sys/epoll.h +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (C) 2002,2003,2004,2005,2006 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _SYS_EPOLL_H -#define _SYS_EPOLL_H 1 - -#include <stdint.h> -#include <sys/types.h> - - -enum EPOLL_EVENTS - { - EPOLLIN = 0x001, -#define EPOLLIN EPOLLIN - EPOLLPRI = 0x002, -#define EPOLLPRI EPOLLPRI - EPOLLOUT = 0x004, -#define EPOLLOUT EPOLLOUT - EPOLLRDNORM = 0x040, -#define EPOLLRDNORM EPOLLRDNORM - EPOLLRDBAND = 0x080, -#define EPOLLRDBAND EPOLLRDBAND - EPOLLWRNORM = 0x100, -#define EPOLLWRNORM EPOLLWRNORM - EPOLLWRBAND = 0x200, -#define EPOLLWRBAND EPOLLWRBAND - EPOLLMSG = 0x400, -#define EPOLLMSG EPOLLMSG - EPOLLERR = 0x008, -#define EPOLLERR EPOLLERR - EPOLLHUP = 0x010, -#define EPOLLHUP EPOLLHUP - EPOLLONESHOT = (1 << 30), -#define EPOLLONESHOT EPOLLONESHOT - EPOLLET = (1 << 31) -#define EPOLLET EPOLLET - }; - - -/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */ -#define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface. */ -#define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface. */ -#define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure. */ - - -typedef union epoll_data -{ - void *ptr; - int fd; - uint32_t u32; - uint64_t u64; -} epoll_data_t; - -struct epoll_event -{ - uint32_t events; /* Epoll events */ - epoll_data_t data; /* User data variable */ -} __attribute__ ((__packed__)); - - -__BEGIN_DECLS - -/* Creates an epoll instance. Returns an fd for the new instance. - The "size" parameter is a hint specifying the number of file - descriptors to be associated with the new instance. The fd - returned by epoll_create() should be closed with close(). */ -extern int epoll_create (int __size) __THROW; - - -/* Manipulate an epoll instance "epfd". Returns 0 in case of success, - -1 in case of error ( the "errno" variable will contain the - specific error code ) The "op" parameter is one of the EPOLL_CTL_* - constants defined above. The "fd" parameter is the target of the - operation. The "event" parameter describes which events the caller - is interested in and any associated user data. */ -extern int epoll_ctl (int __epfd, int __op, int __fd, - struct epoll_event *__event) __THROW; - - -/* Wait for events on an epoll instance "epfd". Returns the number of - triggered events returned in "events" buffer. Or -1 in case of - error with the "errno" variable set to the specific error code. The - "events" parameter is a buffer that will contain triggered - events. The "maxevents" is the maximum number of events to be - returned ( usually size of "events" ). The "timeout" parameter - specifies the maximum wait time in milliseconds (-1 == infinite). - - This function is a cancellation point and therefore not marked with - __THROW. */ -extern int epoll_wait (int __epfd, struct epoll_event *__events, - int __maxevents, int __timeout); - -__END_DECLS - -#endif /* sys/epoll.h */ diff --git a/libc/sysdeps/linux/x86_64/sys/io.h b/libc/sysdeps/linux/x86_64/sys/io.h index 802a0dfb4..7a65a16a8 100644 --- a/libc/sysdeps/linux/x86_64/sys/io.h +++ b/libc/sysdeps/linux/x86_64/sys/io.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_IO_H #define _SYS_IO_H 1 @@ -23,6 +22,7 @@ __BEGIN_DECLS +#if defined __UCLIBC_LINUX_SPECIFIC__ /* If TURN_ON is TRUE, request for permission to do direct i/o on the port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O permission off for that range. This call requires root privileges. @@ -37,6 +37,7 @@ extern int ioperm (unsigned long int __from, unsigned long int __num, access any I/O port is granted. This call requires root privileges. */ extern int iopl (int __level) __THROW; +#endif /* __UCLIBC_LINUX_SPECIFIC__ */ #if defined __GNUC__ && __GNUC__ >= 2 diff --git a/libc/sysdeps/linux/x86_64/sys/perm.h b/libc/sysdeps/linux/x86_64/sys/perm.h index 382fa92ee..cbfeaf825 100644 --- a/libc/sysdeps/linux/x86_64/sys/perm.h +++ b/libc/sysdeps/linux/x86_64/sys/perm.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_PERM_H diff --git a/libc/sysdeps/linux/x86_64/sys/procfs.h b/libc/sysdeps/linux/x86_64/sys/procfs.h index 5995b7115..fd2960169 100644 --- a/libc/sysdeps/linux/x86_64/sys/procfs.h +++ b/libc/sysdeps/linux/x86_64/sys/procfs.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_PROCFS_H #define _SYS_PROCFS_H 1 diff --git a/libc/sysdeps/linux/x86_64/sys/reg.h b/libc/sysdeps/linux/x86_64/sys/reg.h index 865e34559..0718e1fca 100644 --- a/libc/sysdeps/linux/x86_64/sys/reg.h +++ b/libc/sysdeps/linux/x86_64/sys/reg.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_REG_H #define _SYS_REG_H 1 diff --git a/libc/sysdeps/linux/x86_64/sys/ucontext.h b/libc/sysdeps/linux/x86_64/sys/ucontext.h index b59cd292f..a39762058 100644 --- a/libc/sysdeps/linux/x86_64/sys/ucontext.h +++ b/libc/sysdeps/linux/x86_64/sys/ucontext.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_UCONTEXT_H #define _SYS_UCONTEXT_H 1 diff --git a/libc/sysdeps/linux/x86_64/sys/user.h b/libc/sysdeps/linux/x86_64/sys/user.h index 5ff68e575..9d0bd8d96 100644 --- a/libc/sysdeps/linux/x86_64/sys/user.h +++ b/libc/sysdeps/linux/x86_64/sys/user.h @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #ifndef _SYS_USER_H #define _SYS_USER_H 1 diff --git a/libc/sysdeps/linux/x86_64/syscall.S b/libc/sysdeps/linux/x86_64/syscall.S index ee223e3e6..5c92dc34f 100644 --- a/libc/sysdeps/linux/x86_64/syscall.S +++ b/libc/sysdeps/linux/x86_64/syscall.S @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ /* Please consult the file sysdeps/unix/sysv/linux/x86-64/sysdep.h for more information about the value -4095 used below. */ diff --git a/libc/sysdeps/linux/x86_64/sysdep.h b/libc/sysdeps/linux/x86_64/sysdep.h new file mode 100644 index 000000000..3bfeaca50 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/sysdep.h @@ -0,0 +1,330 @@ +/* Copyright (C) 2001-2005, 2007 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 _LINUX_X86_64_SYSDEP_H +#define _LINUX_X86_64_SYSDEP_H 1 + +/* There is some commonality. */ +#include <sys/syscall.h> +#include <common/sysdep.h> + +#ifdef __ASSEMBLER__ + +/* Syntactic details of assembler. */ + +/* ELF uses byte-counts for .align, most others use log2 of count of bytes. */ +#define ALIGNARG(log2) 1<<log2 +/* For ELF we need the `.type' directive to make shared libs work right. */ +#define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg; +#define ASM_SIZE_DIRECTIVE(name) .size name,.-name; + +/* In ELF C symbols are asm symbols. */ +#undef NO_UNDERSCORES +#define NO_UNDERSCORES + +/* Define an entry point visible from C. */ +#define ENTRY(name) \ + .globl C_SYMBOL_NAME(name); \ + ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \ + .align ALIGNARG(4); \ + C_LABEL(name) \ + cfi_startproc; \ + CALL_MCOUNT + +#undef END +#define END(name) \ + cfi_endproc; \ + ASM_SIZE_DIRECTIVE(name) + +/* If compiled for profiling, call `mcount' at the start of each function. */ +#ifdef PROF +/* The mcount code relies on a normal frame pointer being on the stack + to locate our caller, so push one just for its benefit. */ +#define CALL_MCOUNT \ + pushq %rbp; \ + cfi_adjust_cfa_offset(8); \ + movq %rsp, %rbp; \ + cfi_def_cfa_register(%rbp); \ + call JUMPTARGET(mcount); \ + popq %rbp; \ + cfi_def_cfa(rsp,8); +#else +#define CALL_MCOUNT /* Do nothing. */ +#endif + +#ifdef NO_UNDERSCORES +/* Since C identifiers are not normally prefixed with an underscore + on this system, the asm identifier `syscall_error' intrudes on the + C name space. Make sure we use an innocuous name. */ +#define syscall_error __syscall_error +#define mcount _mcount +#endif + +#define PSEUDO(name, syscall_name, args) \ +lose: \ + jmp JUMPTARGET(syscall_error) \ + .globl syscall_error; \ + ENTRY (name) \ + DO_CALL (syscall_name, args); \ + jb lose + +#undef PSEUDO_END +#define PSEUDO_END(name) \ + END (name) + +#undef JUMPTARGET +#ifdef __PIC__ +#define JUMPTARGET(name) name##@PLT +#else +#define JUMPTARGET(name) name +#endif + +/* Local label name for asm code. */ +#ifndef L +#define L(name) .L##name +#endif + +#endif /* __ASSEMBLER__ */ + +/* For Linux we can use the system call table in the header file + /usr/include/asm/unistd.h + of the kernel. But these symbols do not follow the SYS_* syntax + so we have to redefine the `SYS_ify' macro here. */ +#undef SYS_ify +#define SYS_ify(syscall_name) __NR_##syscall_name + +/* This is a kludge to make syscalls.list find these under the names + pread and pwrite, since some kernel headers define those names + and some define the *64 names for the same system calls. */ +#if !defined __NR_pread && defined __NR_pread64 +# define __NR_pread __NR_pread64 +#endif +#if !defined __NR_pwrite && defined __NR_pwrite64 +# define __NR_pwrite __NR_pwrite64 +#endif + +/* This is to help the old kernel headers where __NR_semtimedop is not + available. */ +#ifndef __NR_semtimedop +# define __NR_semtimedop 220 +#endif + + +#ifdef __ASSEMBLER__ + +/* Linux uses a negative return value to indicate syscall errors, + unlike most Unices, which use the condition codes' carry flag. + + Since version 2.1 the return value of a system call might be + negative even if the call succeeded. E.g., the `lseek' system call + might return a large offset. Therefore we must not anymore test + for < 0, but test for a real error by making sure the value in %eax + is a real error number. Linus said he will make sure the no syscall + returns a value in -1 .. -4095 as a valid result so we can savely + test with -4095. */ + +/* We don't want the label for the error handle to be global when we define + it here. */ +# ifdef __PIC__ +# define SYSCALL_ERROR_LABEL 0f +# else +# define SYSCALL_ERROR_LABEL syscall_error +# endif + +# undef PSEUDO +# define PSEUDO(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args); \ + cmpq $-4095, %rax; \ + jae SYSCALL_ERROR_LABEL; \ + L(pseudo_end): + +# undef PSEUDO_END +# define PSEUDO_END(name) \ + SYSCALL_ERROR_HANDLER \ + END (name) + +# undef PSEUDO_NOERRNO +# define PSEUDO_NOERRNO(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args) + +# undef PSEUDO_END_NOERRNO +# define PSEUDO_END_NOERRNO(name) \ + END (name) + +# define ret_NOERRNO ret + +# undef PSEUDO_ERRVAL +# define PSEUDO_ERRVAL(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + DO_CALL (syscall_name, args); \ + negq %rax + +# undef PSEUDO_END_ERRVAL +# define PSEUDO_END_ERRVAL(name) \ + END (name) + +# ifndef __PIC__ +# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */ +# elif defined(RTLD_PRIVATE_ERRNO) +# define SYSCALL_ERROR_HANDLER \ +0: \ + leaq rtld_errno(%rip), %rcx; \ + xorl %edx, %edx; \ + subq %rax, %rdx; \ + movl %edx, (%rcx); \ + orq $-1, %rax; \ + jmp L(pseudo_end); +# elif USE___THREAD +# ifndef NOT_IN_libc +# define SYSCALL_ERROR_ERRNO __libc_errno +# else +# define SYSCALL_ERROR_ERRNO errno +# endif +# define SYSCALL_ERROR_HANDLER \ +0: \ + movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\ + xorl %edx, %edx; \ + subq %rax, %rdx; \ + movl %edx, %fs:(%rcx); \ + orq $-1, %rax; \ + jmp L(pseudo_end); +# elif defined _LIBC_REENTRANT +/* Store (- %rax) into errno through the GOT. + Note that errno occupies only 4 bytes. */ +# define SYSCALL_ERROR_HANDLER \ +0: \ + xorl %edx, %edx; \ + subq %rax, %rdx; \ + pushq %rdx; \ + cfi_adjust_cfa_offset(8); \ + call __errno_location@PLT; \ + popq %rdx; \ + cfi_adjust_cfa_offset(-8); \ + movl %edx, (%rax); \ + orq $-1, %rax; \ + jmp L(pseudo_end); + +/* A quick note: it is assumed that the call to `__errno_location' does + not modify the stack! */ +# else /* Not _LIBC_REENTRANT. */ +# define SYSCALL_ERROR_HANDLER \ +0:movq errno@GOTPCREL(%RIP), %rcx; \ + xorl %edx, %edx; \ + subq %rax, %rdx; \ + movl %edx, (%rcx); \ + orq $-1, %rax; \ + jmp L(pseudo_end); +# endif /* __PIC__ */ + +/* The Linux/x86-64 kernel expects the system call parameters in + registers according to the following table: + + syscall number rax + arg 1 rdi + arg 2 rsi + arg 3 rdx + arg 4 r10 + arg 5 r8 + arg 6 r9 + + The Linux kernel uses and destroys internally these registers: + return address from + syscall rcx + eflags from syscall r11 + + Normal function call, including calls to the system call stub + functions in the libc, get the first six parameters passed in + registers and the seventh parameter and later on the stack. The + register use is as follows: + + system call number in the DO_CALL macro + arg 1 rdi + arg 2 rsi + arg 3 rdx + arg 4 rcx + arg 5 r8 + arg 6 r9 + + We have to take care that the stack is aligned to 16 bytes. When + called the stack is not aligned since the return address has just + been pushed. + + + Syscalls of more than 6 arguments are not supported. */ + +# undef DO_CALL +# define DO_CALL(syscall_name, args) \ + DOARGS_##args \ + movl $SYS_ify (syscall_name), %eax; \ + syscall; + +# define DOARGS_0 /* nothing */ +# define DOARGS_1 /* nothing */ +# define DOARGS_2 /* nothing */ +# define DOARGS_3 /* nothing */ +# define DOARGS_4 movq %rcx, %r10; +# define DOARGS_5 DOARGS_4 +# define DOARGS_6 DOARGS_5 + +#endif /* __ASSEMBLER__ */ + + +/* Pointer mangling support. */ +#if defined NOT_IN_libc && defined IS_IN_rtld +/* We cannot use the thread descriptor because in ld.so we use setjmp + earlier than the descriptor is initialized. */ +# ifdef __ASSEMBLER__ +# define PTR_MANGLE(reg) xorq __pointer_chk_guard_local(%rip), reg; \ + rolq $17, reg +# define PTR_DEMANGLE(reg) rorq $17, reg; \ + xorq __pointer_chk_guard_local(%rip), reg +# else +# define PTR_MANGLE(reg) __asm__ ("xorq __pointer_chk_guard_local(%%rip), %0\n" \ + "rolq $17, %0" \ + : "=r" (reg) : "0" (reg)) +# define PTR_DEMANGLE(reg) __asm__ ("rorq $17, %0\n" \ + "xorq __pointer_chk_guard_local(%%rip), %0" \ + : "=r" (reg) : "0" (reg)) +# endif +#else +# ifdef __ASSEMBLER__ +# define PTR_MANGLE(reg) xorq %fs:POINTER_GUARD, reg; \ + rolq $17, reg +# define PTR_DEMANGLE(reg) rorq $17, reg; \ + xorq %fs:POINTER_GUARD, reg +# else +# define PTR_MANGLE(var) __asm__ ("xorq %%fs:%c2, %0\n" \ + "rolq $17, %0" \ + : "=r" (var) \ + : "0" (var), \ + "i" (offsetof (tcbhead_t, \ + pointer_guard))) +# define PTR_DEMANGLE(var) __asm__ ("rorq $17, %0\n" \ + "xorq %%fs:%c2, %0" \ + : "=r" (var) \ + : "0" (var), \ + "i" (offsetof (tcbhead_t, \ + pointer_guard))) +# endif +#endif + +#endif /* linux/x86_64/sysdep.h */ diff --git a/libc/sysdeps/linux/x86_64/ucontext_i.sym b/libc/sysdeps/linux/x86_64/ucontext_i.sym new file mode 100644 index 000000000..af3e0e544 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/ucontext_i.sym @@ -0,0 +1,37 @@ +#include <stddef.h> +#include <signal.h> +#include <sys/ucontext.h> + +-- + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +#define ucontext(member) offsetof (ucontext_t, member) +#define mcontext(member) ucontext (uc_mcontext.member) +#define mreg(reg) mcontext (gregs[REG_##reg]) + +oRBP mreg (RBP) +oRSP mreg (RSP) +oRBX mreg (RBX) +oR8 mreg (R8) +oR9 mreg (R9) +oR10 mreg (R10) +oR11 mreg (R11) +oR12 mreg (R12) +oR13 mreg (R13) +oR14 mreg (R14) +oR15 mreg (R15) +oRDI mreg (RDI) +oRSI mreg (RSI) +oRDX mreg (RDX) +oRAX mreg (RAX) +oRCX mreg (RCX) +oRIP mreg (RIP) +oEFL mreg (EFL) +oFPREGS mcontext (fpregs) +oSIGMASK ucontext (uc_sigmask) +oFPREGSMEM ucontext (__fpregs_mem) +oMXCSR ucontext (__fpregs_mem.mxcsr) diff --git a/libc/sysdeps/linux/x86_64/vfork.S b/libc/sysdeps/linux/x86_64/vfork.S index 2dadbbfe0..a8a2f6e4b 100644 --- a/libc/sysdeps/linux/x86_64/vfork.S +++ b/libc/sysdeps/linux/x86_64/vfork.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2002, 2004, 2008 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 @@ -12,9 +12,8 @@ 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, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ #include <sys/syscall.h> @@ -31,7 +30,7 @@ .text .global __vfork .hidden __vfork -.type __vfork,%function +.type __vfork,%function __vfork: @@ -39,6 +38,10 @@ __vfork: is preserved by the syscall and that we're allowed to destroy. */ popq %rdi +#ifdef SAVE_PID + SAVE_PID +#endif + /* Stuff the syscall number in RAX and enter into the kernel. */ movl $__NR_vfork, %eax syscall @@ -46,6 +49,10 @@ __vfork: /* Push back the return PC. */ pushq %rdi +#ifdef RESTORE_PID + RESTORE_PID +#endif + cmpl $-4095, %eax jae __syscall_error /* Branch forward if it failed. */ @@ -55,4 +62,4 @@ __vfork: .size __vfork,.-__vfork weak_alias(__vfork,vfork) -libc_hidden_weak(vfork) +libc_hidden_def(vfork) |
