summaryrefslogtreecommitdiff
path: root/libexec/ld.so
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2014-07-05 17:06:19 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2014-07-05 17:06:19 +0000
commite4d35aae0ad3ac50a5832a7462831f9eeffba0e7 (patch)
treefa3f9aeb6851b2d0d9f1ed593fd6baed94c2f93d /libexec/ld.so
parentf7ecdeb981cc74e94de01d855496f4a17241fd29 (diff)
Add more sugar to build syscall stubs, and turn them from inlines to real
entry points; also, make sure syscall failures return -errno rather than -1.
Diffstat (limited to 'libexec/ld.so')
-rw-r--r--libexec/ld.so/powerpc/ldasm.S62
-rw-r--r--libexec/ld.so/powerpc/rtld_machine.c14
-rw-r--r--libexec/ld.so/powerpc/syscall.h407
3 files changed, 85 insertions, 398 deletions
diff --git a/libexec/ld.so/powerpc/ldasm.S b/libexec/ld.so/powerpc/ldasm.S
index 9940b66a08b..991000bb7c5 100644
--- a/libexec/ld.so/powerpc/ldasm.S
+++ b/libexec/ld.so/powerpc/ldasm.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldasm.S,v 1.16 2013/12/23 22:03:52 kettenis Exp $ */
+/* $OpenBSD: ldasm.S,v 1.17 2014/07/05 17:06:18 miod Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -161,3 +161,63 @@ ENTRY(_dl_bind_start)
addi 1,1,64
bctr
+
+#define DL_SYSCALL(n) DL_SYSCALL2(n,n)
+#define DL_SYSCALL_NOERR(n) DL_SYSCALL2_NOERR(n,n)
+#define DL_SYSCALL2(n,c) \
+ENTRY(_dl_##n) \
+ li 0, SYS_##c; \
+ sc; \
+ cmpwi 0, 0; \
+ beqlr+; \
+ b _dl_cerror
+#define DL_SYSCALL2_NOERR(n,c) \
+ENTRY(_dl_##n) \
+ li 0, SYS_##c; \
+ sc; \
+ blr
+
+_dl_cerror:
+ neg 3, 3
+ blr
+
+ENTRY(_dl_sigprocmask)
+ /* _dl_sigprocmask does not support NULL as the new mask */
+#if 0
+ cmpwi 4, 0
+ bne+ 1f
+ li 3, 1 /* SIG_BLOCK */
+ b 2f
+1:
+#endif
+ lwz 4, 0(4)
+2:
+ li 0, SYS_sigprocmask
+ sc
+ cmpwi 0, 0
+ bne- _dl_cerror
+ cmpwi 5, 0
+ beq- 1f
+ stw 3, 0(5)
+1:
+ li 3, 0
+ blr
+
+DL_SYSCALL(close)
+DL_SYSCALL_NOERR(exit)
+DL_SYSCALL(fcntl)
+DL_SYSCALL(fstat)
+DL_SYSCALL2(getcwd,__getcwd)
+DL_SYSCALL(getdents)
+DL_SYSCALL(gettimeofday)
+DL_SYSCALL_NOERR(issetugid)
+DL_SYSCALL(lstat)
+DL_SYSCALL(mprotect)
+DL_SYSCALL(munmap)
+DL_SYSCALL(open)
+DL_SYSCALL(read)
+DL_SYSCALL(readlink)
+DL_SYSCALL2(_syscall,__syscall)
+DL_SYSCALL2(sysctl,__sysctl)
+DL_SYSCALL(utrace)
+DL_SYSCALL(write)
diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c
index 0551a4c54dc..7562305d9e9 100644
--- a/libexec/ld.so/powerpc/rtld_machine.c
+++ b/libexec/ld.so/powerpc/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.51 2013/06/13 04:13:47 brad Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.52 2014/07/05 17:06:18 miod Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -687,15 +687,3 @@ _dl_syncicache(char *from, size_t len)
off += CACHELINESIZE;
}
}
-__asm__(".section\t\".text\"\n\t"
- ".align 2\n\t"
- ".globl _dl__syscall\n\t"
- ".type _dl__syscall,@function\n"
- "_dl__syscall:\n\t"
- "li 0, " XSTRINGIFY(SYS___syscall) "\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3, -1\n\t"
- "1:\n\t"
- "blr");
diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h
index d154465a59b..38bd7e1ce67 100644
--- a/libexec/ld.so/powerpc/syscall.h
+++ b/libexec/ld.so/powerpc/syscall.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.h,v 1.29 2013/08/13 22:33:04 miod Exp $ */
+/* $OpenBSD: syscall.h,v 1.30 2014/07/05 17:06:18 miod Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -34,7 +34,6 @@
#include <sys/signal.h>
#include <sys/time.h>
-
static off_t _dl_lseek(int, off_t, int);
#ifndef _dl_MAX_ERRNO
@@ -43,111 +42,32 @@ static off_t _dl_lseek(int, off_t, int);
#define _dl_mmap_error(__res) \
((long)__res < 0 && (long)__res >= -_dl_MAX_ERRNO)
-/*
- * Inlined system call functions that can be used before
- * any dynamic address resolving has been done.
- */
-
-static inline void
-_dl_exit(int status)
-{
- register int __status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "sc"
- : "=r" (__status)
- : "I" (SYS_exit), "r" (status) : "0", "3");
-
- while (1)
- ;
-}
-
-static inline int
-_dl_open(const char* addr, int flags)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_open), "r" (addr), "r" (flags)
- : "memory", "0", "3", "4" );
- return status;
-}
-
-static inline int
-_dl_close(int fd)
-{
- register int status;
+int _dl_close(int);
+void _dl_exit(int);
+int _dl_fcntl(int, int, int);
+int _dl_fstat(int, struct stat *);
+int _dl_getcwd(char *, size_t);
+ssize_t _dl_getdents(int, char *, size_t);
+int _dl_gettimeofday(struct timeval *, struct timezone *);
+int _dl_issetugid(void);
+int _dl_lstat(const char *, struct stat *);
+int _dl_mprotect(const void *, size_t, int);
+int _dl_munmap(const void *, size_t);
+int _dl_open(const char *, int);
+ssize_t _dl_read(int, const char *, size_t);
+int _dl_readlink(const char *, char *, size_t);
+int _dl_sigprocmask(int, const sigset_t *, sigset_t *);
+long _dl__syscall(quad_t, ...);
+int _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t);
+int _dl_utrace(const char *, const void *, size_t);
+ssize_t _dl_write(int, const char *, size_t);
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_close), "r" (fd)
- : "0", "3");
- return status;
-}
-
-static inline ssize_t
-_dl_write(int fd, const char* buf, size_t len)
-{
- register ssize_t status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_write), "r" (fd), "r" (buf), "r" (len)
- : "memory", "0", "3", "4", "5" );
- return status;
-}
-
-static inline ssize_t
-_dl_read(int fd, const char* buf, size_t len)
+static inline off_t
+_dl_lseek(int fildes, off_t offset, int whence)
{
- register ssize_t status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_read), "r" (fd), "r" (buf), "r" (len)
- : "memory", "0", "3", "4", "5");
- return status;
+ return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence);
}
-#define STRINGIFY(x) #x
-#define XSTRINGIFY(x) STRINGIFY(x)
-long _dl__syscall(quad_t val, ...);
-
static inline void *
_dl_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
{
@@ -155,285 +75,4 @@ _dl_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
flags, fd, 0, offset));
}
-static inline int
-_dl_munmap(const void* addr, size_t len)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_munmap), "r" (addr), "r" (len)
- : "memory", "0", "3", "4");
- return status;
-}
-
-static inline int
-_dl_mprotect(const void *addr, size_t size, int prot)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_mprotect), "r" (addr), "r" (size), "r" (prot)
- : "memory", "0", "3", "4", "5");
- return status;
-}
-
-static inline int
-_dl_fstat(int fd, struct stat *sb)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_fstat), "r" (fd), "r" (sb)
- : "memory", "0", "3", "4");
- return status;
-}
-
-static inline int
-_dl_fcntl(int fd, int cmd, int flag)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- : "=r" (status)
- : "I" (SYS_fcntl), "r" (fd), "r" (cmd), "r"(flag)
- : "memory", "0", "3", "4", "5");
- return status;
-}
-
-static inline ssize_t
-_dl_getdents(int fd, char *buf, size_t nbytes)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_getdents), "r" (fd), "r" (buf), "r" (nbytes)
- : "memory", "0", "3", "4", "5", "6");
- return status;
-}
-
-static inline int
-_dl_issetugid(void)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_issetugid)
- : "0", "3");
- return status;
-}
-
-static inline off_t
-_dl_lseek(int fildes, off_t offset, int whence)
-{
- return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence);
-}
-
-static inline int
-_dl_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
-{
- sigset_t sig_store;
- sigset_t sig_store1;
-
- if (set != NULL) {
- sig_store1 = *set;
- } else {
- sig_store1 = 0;
- }
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "mr %0, 3"
- : "=r" (sig_store)
- : "I" (SYS_sigprocmask), "r" (how), "r" (sig_store1)
- : "memory", "0", "3", "4");
- if (oset != NULL)
- *oset = sig_store;
-
- return 0;
-}
-
-static inline int
-_dl_sysctl(const int *name, u_int namelen, void *oldp, size_t *oldplen,
- void *newp, size_t newlen)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "mr 6,%5\n\t"
- "mr 7,%6\n\t"
- "mr 8,%7\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS___sysctl), "r" (name), "r" (namelen), "r" (oldp),
- "r" (oldplen), "r" (newp), "r" (newlen)
- : "memory", "0", "3", "4", "5", "6", "7", "8");
- return status;
-}
-
-static inline int
-_dl_gettimeofday(struct timeval *tp, struct timezone *tzp)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_gettimeofday), "r" (tp), "r" (tzp)
- : "memory", "0", "3", "4" );
- return status;
-}
-
-static inline int
-_dl_readlink(const char *path, char *buf, size_t bufsiz)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_readlink), "r" (path), "r" (buf), "r" (bufsiz)
- : "memory", "0", "3", "4", "5");
- return status;
-}
-
-static inline int
-_dl_lstat(const char *path, struct stat *sb)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_lstat), "r" (path), "r" (sb)
- : "memory", "0", "3", "4" );
- return status;
-}
-
-static inline int
-_dl_getcwd(char *buf, size_t size)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS___getcwd), "r" (buf), "r" (size)
- : "0", "3", "4");
- return status;
-}
-
-static inline int
-_dl_utrace(const char *label, const void *addr, size_t len)
-{
- register int status;
-
- __asm__ volatile ("li 0,%1\n\t"
- "mr 3,%2\n\t"
- "mr 4,%3\n\t"
- "mr 5,%4\n\t"
- "sc\n\t"
- "cmpwi 0, 0\n\t"
- "beq 1f\n\t"
- "li 3,-1\n\t"
- "1:"
- "mr %0,3\n\t"
- : "=r" (status)
- : "I" (SYS_utrace), "r" (label), "r" (addr), "r" (len)
- : "memory", "0", "3", "4", "5");
- return status;
-}
-
#endif /*__DL_SYSCALL_H__*/
-