summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-02-15 01:33:05 +0000
committerMike Frysinger <vapier@gentoo.org>2005-02-15 01:33:05 +0000
commitfc59b6ec5140386c0072cae932d2812015016a5b (patch)
tree5d131ce249cfc8d2058e033b5feea39b64e7b7cb /libc/sysdeps/linux
parent1fef64b22811709b2e640d341237bce1c8081203 (diff)
some source files for x86_64
Diffstat (limited to 'libc/sysdeps/linux')
-rw-r--r--libc/sysdeps/linux/x86_64/__longjmp.S45
-rw-r--r--libc/sysdeps/linux/x86_64/brk.c44
-rw-r--r--libc/sysdeps/linux/x86_64/bsd-_setjmp.S34
-rw-r--r--libc/sysdeps/linux/x86_64/bsd-setjmp.S30
-rw-r--r--libc/sysdeps/linux/x86_64/crtn.S19
-rw-r--r--libc/sysdeps/linux/x86_64/setjmp.S46
-rw-r--r--libc/sysdeps/linux/x86_64/sigaction.c135
7 files changed, 353 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/x86_64/__longjmp.S b/libc/sysdeps/linux/x86_64/__longjmp.S
new file mode 100644
index 000000000..40e459e27
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/__longjmp.S
@@ -0,0 +1,45 @@
+/* Copyright (C) 2001, 2004 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. */
+
+#define _ASM
+#define _SETJMP_H
+#include <bits/setjmp.h>
+
+/* Jump to the position specified by ENV, causing the
+ setjmp call there to return VAL, or 1 if VAL is 0.
+ void __longjmp (__jmp_buf env, int val). */
+.globl __longjmp;
+.type __longjmp,@function;
+.align 16;
+__longjmp:
+ /* Restore registers. */
+ movq (JB_RBX*8)(%rdi),%rbx
+ movq (JB_RBP*8)(%rdi),%rbp
+ movq (JB_R12*8)(%rdi),%r12
+ movq (JB_R13*8)(%rdi),%r13
+ movq (JB_R14*8)(%rdi),%r14
+ movq (JB_R15*8)(%rdi),%r15
+ /* Set return value for setjmp. */
+ test %esi,%esi
+ mov $01,%eax
+ cmove %eax,%esi
+ mov %esi, %eax
+ movq (JB_PC*8)(%rdi),%rdx
+ movq (JB_RSP*8)(%rdi),%rsp
+ jmpq *%rdx
+.size __longjmp,.-__longjmp;
diff --git a/libc/sysdeps/linux/x86_64/brk.c b/libc/sysdeps/linux/x86_64/brk.c
new file mode 100644
index 000000000..303b5c0de
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/brk.c
@@ -0,0 +1,44 @@
+/* brk system call for Linux/x86_64.
+ Copyright (C) 1995, 1996, 2000 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. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+/* This must be initialized data because commons can't have aliases. */
+void *__curbrk = 0;
+
+int brk (void *addr)
+{
+ void *__unbounded newbrk;
+
+ asm ("syscall\n"
+ : "=a" (newbrk)
+ : "0" (__NR_brk), "D" (__ptrvalue (addr))
+ : "r11","rcx","memory");
+
+ __curbrk = newbrk;
+
+ if (newbrk < addr) {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/libc/sysdeps/linux/x86_64/bsd-_setjmp.S b/libc/sysdeps/linux/x86_64/bsd-_setjmp.S
new file mode 100644
index 000000000..89676bf5f
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/bsd-_setjmp.S
@@ -0,0 +1,34 @@
+/* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'. i386 version.
+ Copyright (C) 1994,1995,1996,1997,2000,2001 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. */
+
+/* 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. */
+
+#define _ASM
+#define _SETJMP_H
+#include <bits/setjmp.h>
+
+.globl _setjmp;
+.type _setjmp,@function
+.align 16;
+_setjmp:
+ xorq %rsi, %rsi
+ jmp __sigsetjmp
+.size _setjmp,.-_setjmp;
diff --git a/libc/sysdeps/linux/x86_64/bsd-setjmp.S b/libc/sysdeps/linux/x86_64/bsd-setjmp.S
new file mode 100644
index 000000000..340d59642
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/bsd-setjmp.S
@@ -0,0 +1,30 @@
+/* BSD `setjmp' entry point to `sigsetjmp (..., 1)'. i386 version.
+ Copyright (C) 1995, 1996, 1997, 2000, 2001 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. */
+
+#define _ASM
+#define _SETJMP_H
+#include <bits/setjmp.h>
+
+.globl setjmp;
+.type setjmp,@function
+.align 16;
+setjmp:
+ movq $1, %rsi
+ jmp __sigsetjmp
+.size setjmp,.-setjmp;
diff --git a/libc/sysdeps/linux/x86_64/crtn.S b/libc/sysdeps/linux/x86_64/crtn.S
new file mode 100644
index 000000000..292e499a7
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/crtn.S
@@ -0,0 +1,19 @@
+/* glibc's sysdeps/x86_64/elf/initfini.c used for reference [EPILOG] */
+
+.file "initfini.c"
+
+
+.section .init
+.globl _init
+.type _init, @function
+ addq $8, %rsp
+ ret
+.size _init, .-_init
+
+
+.section .fini
+.globl _fini
+.type _fini, @function
+ addq $8, %rsp
+ ret
+.size _fini, .-_fini
diff --git a/libc/sysdeps/linux/x86_64/setjmp.S b/libc/sysdeps/linux/x86_64/setjmp.S
new file mode 100644
index 000000000..cb560248b
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/setjmp.S
@@ -0,0 +1,46 @@
+/* setjmp for x86-64.
+ Copyright (C) 2001, 2003 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. */
+
+#define _ASM
+#define _SETJMP_H
+#include <bits/setjmp.h>
+
+.globl __sigsetjmp;
+.type __sigsetjmp,@function
+.align 4;
+__sigsetjmp:
+ /* Save registers. */
+ movq %rbx, (JB_RBX*8)(%rdi)
+ movq %rbp, (JB_RBP*8)(%rdi)
+ movq %r12, (JB_R12*8)(%rdi)
+ movq %r13, (JB_R13*8)(%rdi)
+ movq %r14, (JB_R14*8)(%rdi)
+ movq %r15, (JB_R15*8)(%rdi)
+ leaq 8(%rsp), %rdx /* Save SP as it will be after we return. */
+ movq %rdx, (JB_RSP*8)(%rdi)
+ movq (%rsp), %rax /* Save PC we are returning to now. */
+ movq %rax, (JB_PC*8)(%rdi)
+
+ /* Make a tail call to __sigjmp_save; it takes the same args. */
+#ifdef __PIC__
+ jmp __sigjmp_save@PLT
+#else
+ jmp __sigjmp_save
+#endif
+.size __sigsetjmp,.-__sigsetjmp;
diff --git a/libc/sysdeps/linux/x86_64/sigaction.c b/libc/sysdeps/linux/x86_64/sigaction.c
new file mode 100644
index 000000000..217fd2ae1
--- /dev/null
+++ b/libc/sysdeps/linux/x86_64/sigaction.c
@@ -0,0 +1,135 @@
+/* POSIX.1 `sigaction' call for Linux/x86-64.
+ Copyright (C) 2001, 2002, 2003 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. */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <bits/kernel_sigaction.h>
+
+#define SA_RESTORER 0x04000000
+
+
+#if defined __NR_rt_sigaction
+#warning "Yes there are two warnings here. Don't worry about it."
+static void restore_rt (void) asm ("__restore_rt");
+static void restore (void) asm ("__restore");
+
+/* 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)
+{
+ int result;
+ struct kernel_sigaction kact, koact;
+
+ 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;
+
+ kact.sa_restorer = &restore_rt;
+ }
+
+ /* 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;
+}
+#else
+
+#warning "Yes there is a warning here. Don't worry about it."
+static void restore (void) asm ("__restore");
+
+/* 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)
+{
+ 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));
+
+ 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;
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+ return result;
+}
+#endif
+
+weak_alias (__libc_sigaction, sigaction)
+
+/* 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" \
+ ".align 16\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)
+#endif
+#ifdef __NR_sigreturn
+RESTORE (restore, __NR_sigreturn)
+#endif