From fb77cb0f007d25ab8a99b64eb77a2c87f0f2716b Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 6 Jul 2003 20:04:01 +0000 Subject: various proto, ansi, and knf repair. tested on all architectures that use it. (build may require make cleandir because of .depend balony) --- libexec/ld.so/Makefile | 10 +-- libexec/ld.so/alpha/rtld_machine.c | 25 +++---- libexec/ld.so/alpha/syscall.h | 3 +- libexec/ld.so/dir.c | 3 +- libexec/ld.so/dl_printf.c | 3 +- libexec/ld.so/i386/syscall.h | 9 +-- libexec/ld.so/ldconfig/etc.c | 3 +- libexec/ld.so/ldconfig/ldconfig.c | 36 ++++----- libexec/ld.so/ldconfig/shlib.c | 6 +- libexec/ld.so/library.c | 6 +- libexec/ld.so/library_mquery.c | 4 +- libexec/ld.so/loader.c | 21 +++--- libexec/ld.so/mips/syscall.h | 30 ++++---- libexec/ld.so/powerpc/rtld_machine.c | 10 +-- libexec/ld.so/powerpc/syscall.h | 30 ++++---- libexec/ld.so/resolve.h | 10 ++- libexec/ld.so/sod.c | 7 +- libexec/ld.so/sparc/rtld_machine.c | 8 +- libexec/ld.so/sparc/syscall.h | 3 +- libexec/ld.so/sparc64/rtld_machine.c | 7 +- libexec/ld.so/sparc64/syscall.h | 3 +- libexec/ld.so/strtol.c | 138 +++++++++++++++++++++++++++++++++++ libexec/ld.so/util.c | 6 +- libexec/ld.so/util.h | 11 ++- 24 files changed, 273 insertions(+), 119 deletions(-) create mode 100644 libexec/ld.so/strtol.c (limited to 'libexec/ld.so') diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile index eb9e4fe185d..4b9c2247ab1 100644 --- a/libexec/ld.so/Makefile +++ b/libexec/ld.so/Makefile @@ -1,14 +1,14 @@ -# $OpenBSD: Makefile,v 1.21 2003/06/27 01:13:00 deraadt Exp $ +# $OpenBSD: Makefile,v 1.22 2003/07/06 20:03:57 deraadt Exp $ SUBDIR=ldconfig ldd -VPATH=${.CURDIR}/../../lib/libc/string:${.CURDIR}/../../sys/lib/libsa +VPATH=${.CURDIR}/../../lib/libc/string SRCS= ldasm.S loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c SRCS+= util.c sod.c strsep.c strtol.c dir.c .if (${MACHINE_ARCH} == "i386") -SRCS+= library_mquery.c +SRCS+= library_mquery.c .else -SRCS+= library.c +SRCS+= library.c .endif PROG= ld.so @@ -19,7 +19,7 @@ MAN= ld.so.1 CFLAGS += -Werror -Wall CFLAGS += -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH} \ - -Dstrsep=_dl_strsep -Dstrtol=_dl_strtol + -Dstrsep=_dl_strsep INSTALL_STRIP= ELF_LDFLAGS+=--shared -Bsymbolic diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c index 6212e84af19..ea16b9123ef 100644 --- a/libexec/ld.so/alpha/rtld_machine.c +++ b/libexec/ld.so/alpha/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.23 2003/06/03 16:20:40 art Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.24 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -45,12 +46,12 @@ #include "resolve.h" void -_dl_bcopy(void *src, void *dest, int size) +_dl_bcopy(const void *src, void *dest, int size) { - unsigned char *psrc, *pdest; + unsigned const char *psrc = src; + unsigned char *pdest = dest; int i; - psrc = src; - pdest = dest; + for (i = 0; i < size; i++) { pdest[i] = psrc[i]; } @@ -177,8 +178,8 @@ resolve_failed: /* * Resolve a symbol at run-time. */ -void * -_dl_bind(elf_object_t *object, Elf_Word reloff) +Elf_Addr +_dl_bind(elf_object_t *object, int reloff) { Elf_RelA *rela; Elf_Addr *addr, ooff; @@ -218,7 +219,7 @@ _dl_bind(elf_object_t *object, Elf_Word reloff) _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } - return (void *)*addr; + return *addr; } /* @@ -282,8 +283,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) object->plt_size += plt_addr - object->plt_start; object->plt_size = ELF_ROUND(object->plt_size, _dl_pagesz); } - - if (object->obj_type == OBJTYPE_LDR || !lazy || pltgot == NULL) { _dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ); @@ -316,10 +315,10 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) /* relocate the GOT early */ +void _reloc_alpha_got(Elf_Dyn *dynp, Elf_Addr relocbase); + void -_reloc_alpha_got(dynp, relocbase) - Elf_Dyn *dynp; - Elf_Addr relocbase; +_reloc_alpha_got(Elf_Dyn *dynp, Elf_Addr relocbase) { const Elf_RelA *rela = 0, *relalim; Elf_Addr relasz = 0; diff --git a/libexec/ld.so/alpha/syscall.h b/libexec/ld.so/alpha/syscall.h index b4c63f06379..405344ab451 100644 --- a/libexec/ld.so/alpha/syscall.h +++ b/libexec/ld.so/alpha/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.12 2003/06/09 16:10:03 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.13 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -47,7 +47,6 @@ int _dl_munmap(const void*, size_t); int _dl_open(const char*, int); ssize_t _dl_read(int, const char*, size_t); int _dl_stat(const char *, struct stat *); -ssize_t _dl_write(int, const char*, size_t); int _dl_fstat(int, struct stat *); int _dl_fcntl(int, int, ...); int _dl_getdirentries(int, char*, int, long *); diff --git a/libexec/ld.so/dir.c b/libexec/ld.so/dir.c index 921d174567f..a9d12329be3 100644 --- a/libexec/ld.so/dir.c +++ b/libexec/ld.so/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.7 2003/06/02 19:38:24 millert Exp $ */ +/* $OpenBSD: dir.c,v 1.8 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -44,6 +44,7 @@ static char rcsid[] = ": opendir.c,v 1.6 1998/08/15 08:10:14 deraadt Exp $"; #include #include "util.h" #include "archdep.h" +#include "dir.h" long _dl_telldir(const DIR *dirp); void _dl_seekdir(DIR *dirp, long loc); diff --git a/libexec/ld.so/dl_printf.c b/libexec/ld.so/dl_printf.c index 8d3a80f1980..a7f84f02da3 100644 --- a/libexec/ld.so/dl_printf.c +++ b/libexec/ld.so/dl_printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_printf.c,v 1.12 2003/06/02 19:38:24 millert Exp $ */ +/* $OpenBSD: dl_printf.c,v 1.13 2003/07/06 20:03:57 deraadt Exp $ */ /*- * Copyright (c) 1993 @@ -58,6 +58,7 @@ #include #include #include "syscall.h" +#include "util.h" static void kprintn(void (*)(int,int), int, u_long, int); static void kdoprnt(void (*)(int,int), int, const char *, va_list); diff --git a/libexec/ld.so/i386/syscall.h b/libexec/ld.so/i386/syscall.h index e6077a430dd..09e2f1f5839 100644 --- a/libexec/ld.so/i386/syscall.h +++ b/libexec/ld.so/i386/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.4 2003/06/09 16:10:03 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.5 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -44,11 +44,10 @@ int _dl_exit(int); int _dl_issetugid(void); long _dl__syscall(quad_t, ...); int _dl_mprotect(const void *, int, int); -int _dl_munmap(const void*, unsigned int); -int _dl_open(const char*, unsigned int); -int _dl_read(int, const char*, int); +int _dl_munmap(const void *, unsigned int); +int _dl_open(const char *, unsigned int); +int _dl_read(int, const char *, int); int _dl_stat(const char *, struct stat *); -int _dl_write(int, const char*, int); int _dl_fstat(int, struct stat *); int _dl_fcntl(int, int, ...); int _dl_getdirentries(int, char*, int, long *); diff --git a/libexec/ld.so/ldconfig/etc.c b/libexec/ld.so/ldconfig/etc.c index caa0710d5e1..a1783c4ebf1 100644 --- a/libexec/ld.so/ldconfig/etc.c +++ b/libexec/ld.so/ldconfig/etc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: etc.c,v 1.4 2002/05/24 00:25:42 ericj Exp $ */ +/* $OpenBSD: etc.c,v 1.5 2003/07/06 20:04:00 deraadt Exp $ */ /* Public Domain */ @@ -7,6 +7,7 @@ #include #include #include +#include "ld.h" #define OOM_MSG "Out of memory" diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c index 0197c4ccacc..505cac37afe 100644 --- a/libexec/ld.so/ldconfig/ldconfig.c +++ b/libexec/ld.so/ldconfig/ldconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldconfig.c,v 1.12 2002/07/30 22:25:27 deraadt Exp $ */ +/* $OpenBSD: ldconfig.c,v 1.13 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1993,1995 Paul Kranenburg @@ -275,7 +275,7 @@ enter(char *dir, char *file, char *name, int dewey[], int ndewey) #define _PATH_LD_HINTS "./ld.so.hints" #endif -int +static int hinthash(char *cp, int vmajor, int vminor) { int k = 0; @@ -294,15 +294,11 @@ hinthash(char *cp, int vmajor, int vminor) int buildhints(void) { - struct hints_header hdr; - struct hints_bucket *blist; - struct shlib_list *shp; - char *strtab; - int i, n, str_index = 0; - int strtab_sz = 0; /* Total length of strings */ - int nhints = 0; /* Total number of hints */ - int fd; - char *tmpfile; + int strtab_sz = 0, nhints = 0, fd, i, n, str_index = 0; + struct hints_bucket *blist; + struct hints_header hdr; + struct shlib_list *shp; + char *strtab, *tmpfile; for (shp = shlib_head; shp; shp = shp->next) { strtab_sz += 1 + strlen(shp->name); @@ -425,13 +421,13 @@ buildhints(void) static int readhints(void) { - int fd, i; - caddr_t addr; - long msize; - struct hints_header *hdr; - struct hints_bucket *blist; - char *strtab; - struct shlib_list *shp; + struct hints_bucket *blist; + struct hints_header *hdr; + struct shlib_list *shp; + caddr_t addr; + char *strtab; + long msize; + int fd, i; if ((fd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1) { warn("%s", _PATH_LD_HINTS); @@ -507,8 +503,8 @@ readhints(void) static void listhints(void) { - struct shlib_list *shp; - int i; + struct shlib_list *shp; + int i; printf("%s:\n", _PATH_LD_HINTS); printf("\tsearch directories: %s\n", dir_list); diff --git a/libexec/ld.so/ldconfig/shlib.c b/libexec/ld.so/ldconfig/shlib.c index 20526743a0c..4d765f51d71 100644 --- a/libexec/ld.so/ldconfig/shlib.c +++ b/libexec/ld.so/ldconfig/shlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: shlib.c,v 1.7 2002/07/30 22:25:27 deraadt Exp $ */ +/* $OpenBSD: shlib.c,v 1.8 2003/07/06 20:04:00 deraadt Exp $ */ /* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */ /* @@ -128,7 +128,7 @@ add_search_path(char *path) free(dup); } -void +static void remove_search_path(char *path) { char *cp, *dup; @@ -223,7 +223,7 @@ cmpndewey(int d1[], int n1, int d2[], int n2) #undef major #undef minor -char * +static char * findshlib(char *name, int *majorp, int *minorp, int do_dot_a) { int major = *majorp, minor = *minorp, ndewey, i, len; diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c index 9d515878393..f0f11b29089 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.30 2003/07/02 08:18:03 niklas Exp $ */ +/* $OpenBSD: library.c,v 1.31 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -188,7 +188,7 @@ nohints: match = 1; len = _dl_strlcpy( _dl_hint_store, lp, - MAXPATHLEN); + MAXPATHLEN); if (lp[len-1] != '/') { _dl_hint_store[len] = '/'; @@ -335,8 +335,6 @@ _dl_load_list_free(struct load_list *load_list) } } -void _dl_run_dtors(elf_object_t *object); - void _dl_unload_shlib(elf_object_t *object) { diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 6224e5a5417..c3007fc822a 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.10 2003/07/02 08:18:03 niklas Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.11 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -188,7 +188,7 @@ nohints: match = 1; len = _dl_strlcpy( _dl_hint_store, lp, - MAXPATHLEN); + MAXPATHLEN); if (lp[len-1] != '/') { _dl_hint_store[len] = '/'; diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index e78020d8144..1fdc48cb4e0 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.64 2003/06/22 21:39:01 drahn Exp $ */ +/* $OpenBSD: loader.c,v 1.65 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -45,8 +45,13 @@ /* * Local decls. */ -static char *_dl_getenv(const char *var, char **env); -static void _dl_unsetenv(const char *var, char **env); +static char *_dl_getenv(const char *, char **); +static void _dl_unsetenv(const char *, char **); +unsigned long _dl_boot(const char **, char **, const long, long *); +void _dl_debug_state(void); +void _dl_setup_env(char **); +void _dl_dtors(void); +void _dl_boot_bind(const long, long *); const char *_dl_progname; int _dl_pagesz; @@ -121,7 +126,6 @@ _dl_dopreload(char *paths) * grab interesting environment variables, zap bad env vars if * issetugid */ - void _dl_setup_env(char **envp) { @@ -192,8 +196,8 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data) _dl_pagesz = 4096; /* - * now that GOT and PLT has been relocated, and we know page size - * protect it from modification + * now that GOT and PLT has been relocated, and we know + * page size, protect it from modification */ { extern char *__got_start; @@ -205,18 +209,17 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data) _dl_mprotect((void *)ELF_TRUNC((long)&__got_start, _dl_pagesz), ELF_ROUND((long)&__got_end,_dl_pagesz) - - ELF_TRUNC((long)&__got_start, _dl_pagesz), + ELF_TRUNC((long)&__got_start, _dl_pagesz), GOT_PERMS); #ifndef __i386__ /* only for DATA_PLT or BSS_PLT */ _dl_mprotect((void *)ELF_TRUNC((long)&__plt_start, _dl_pagesz), ELF_ROUND((long)&__plt_end,_dl_pagesz) - - ELF_TRUNC((long)&__plt_start, _dl_pagesz), + ELF_TRUNC((long)&__plt_start, _dl_pagesz), PROT_READ|PROT_EXEC); #endif } - DL_DEB(("rtld loading: '%s'\n", _dl_progname)); diff --git a/libexec/ld.so/mips/syscall.h b/libexec/ld.so/mips/syscall.h index 241c9d3ebe6..7f1f6f6dfef 100644 --- a/libexec/ld.so/mips/syscall.h +++ b/libexec/ld.so/mips/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.11 2003/06/09 16:10:04 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.12 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -46,7 +46,7 @@ extern long _dl__syscall(quad_t val, ...); */ extern inline int -_dl_exit (int status) +_dl_exit(int status) { register int __status __asm__ ("$2"); @@ -63,7 +63,7 @@ _dl_exit (int status) } extern inline int -_dl_open (const char* addr, int flags) +_dl_open(const char* addr, int flags) { register int status __asm__ ("$2"); @@ -83,7 +83,7 @@ _dl_open (const char* addr, int flags) } extern inline int -_dl_close (int fd) +_dl_close(int fd) { register int status __asm__ ("$2"); @@ -102,7 +102,7 @@ _dl_close (int fd) } extern inline ssize_t -_dl_write (int fd, const char* buf, size_t len) +_dl_write(int fd, const char* buf, size_t len) { register ssize_t status __asm__ ("$2"); @@ -123,7 +123,7 @@ _dl_write (int fd, const char* buf, size_t len) } extern inline ssize_t -_dl_read (int fd, const char* buf, size_t len) +_dl_read(int fd, const char* buf, size_t len) { register ssize_t status __asm__ ("$2"); @@ -144,7 +144,7 @@ _dl_read (int fd, const char* buf, size_t len) } extern inline void * -_dl_mmap (void *addr, size_t size, int prot, int flags, int fd, off_t f_offset) +_dl_mmap(void *addr, size_t size, int prot, int flags, int fd, off_t f_offset) { register void * malloc_buffer __asm__ ("$2"); @@ -182,7 +182,7 @@ _dl_mmap (void *addr, size_t size, int prot, int flags, int fd, off_t f_offset) } extern inline int -_dl_munmap (const void* addr, size_t len) +_dl_munmap(const void* addr, size_t len) { register int status __asm__ ("$2"); @@ -202,7 +202,7 @@ _dl_munmap (const void* addr, size_t len) } extern inline int -_dl_mprotect (const void *addr, size_t size, int prot) +_dl_mprotect(const void *addr, size_t size, int prot) { register int status __asm__ ("$2"); @@ -220,7 +220,7 @@ _dl_mprotect (const void *addr, size_t size, int prot) } extern inline int -_dl_stat (const char *addr, struct stat *sb) +_dl_stat(const char *addr, struct stat *sb) { register int status __asm__ ("$2"); @@ -237,7 +237,7 @@ _dl_stat (const char *addr, struct stat *sb) } extern inline int -_dl_fstat (const int fd, struct stat *sb) +_dl_fstat(const int fd, struct stat *sb) { register int status __asm__ ("$2"); @@ -254,7 +254,7 @@ _dl_fstat (const int fd, struct stat *sb) } extern inline ssize_t -_dl_fcntl (int fd, int cmd, int flag) +_dl_fcntl(int fd, int cmd, int flag) { register int status __asm__ ("$2"); @@ -275,7 +275,7 @@ _dl_fcntl (int fd, int cmd, int flag) } extern inline ssize_t -_dl_getdirentries (int fd, char *buf, int nbytes, long *basep) +_dl_getdirentries(int fd, char *buf, int nbytes, long *basep) { register int status __asm__ ("$2"); @@ -296,7 +296,7 @@ _dl_getdirentries (int fd, char *buf, int nbytes, long *basep) } extern inline int -_dl_issetugid (void) +_dl_issetugid(void) { register int status __asm__ ("$2"); @@ -311,7 +311,7 @@ _dl_issetugid (void) } extern inline off_t -_dl_lseek (int fd, off_t offset, int whence) +_dl_lseek(int fd, off_t offset, int whence) { return _dl__syscall((quad_t)SYS_lseek, fd, 0, offset, whence); } diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index 11fc9730a35..e8129f58b11 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.26 2003/06/09 16:10:04 deraadt Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.27 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -72,9 +72,10 @@ void _dl_syncicache(char *from, size_t len); void _dl_bind_start(void); /* XXX */ void -_dl_bcopy(void *src, void *dest, int size) +_dl_bcopy(const void *src, void *dest, int size) { - unsigned char *psrc = src, *pdest = dest; + unsigned const char *psrc = src; + unsigned char *pdest = dest; int i; for (i = 0; i < size; i++) @@ -502,8 +503,7 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) object->plt_size += plt_addr - object->plt_start; object->plt_size = ELF_ROUND(object->plt_size, _dl_pagesz); } - - + if (!lazy) { _dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ); return; diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h index e6104be9cf4..654b5be4da4 100644 --- a/libexec/ld.so/powerpc/syscall.h +++ b/libexec/ld.so/powerpc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.16 2003/06/09 16:10:04 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.17 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -48,7 +48,7 @@ static off_t _dl_lseek(int, off_t, int); */ static inline int -_dl_exit (int status) +_dl_exit(int status) { register int __status __asm__ ("3"); @@ -63,7 +63,7 @@ _dl_exit (int status) } static inline int -_dl_open (const char* addr, int flags) +_dl_open(const char* addr, int flags) { register int status __asm__ ("3"); @@ -82,7 +82,7 @@ _dl_open (const char* addr, int flags) } static inline int -_dl_close (int fd) +_dl_close(int fd) { register int status __asm__ ("3"); @@ -100,7 +100,7 @@ _dl_close (int fd) } static inline ssize_t -_dl_write (int fd, const char* buf, size_t len) +_dl_write(int fd, const char* buf, size_t len) { register ssize_t status __asm__ ("3"); @@ -120,7 +120,7 @@ _dl_write (int fd, const char* buf, size_t len) } static inline ssize_t -_dl_read (int fd, const char* buf, size_t len) +_dl_read(int fd, const char* buf, size_t len) { register ssize_t status __asm__ ("3"); @@ -154,14 +154,14 @@ __asm__(".align 2\n\t" "blr"); static inline void * -_dl_mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) +_dl_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { return((void *)_dl__syscall((quad_t)SYS_mmap, addr, len, prot, flags, fd, 0, offset)); } static inline int -_dl_munmap (const void* addr, size_t len) +_dl_munmap(const void* addr, size_t len) { register int status __asm__ ("3"); @@ -180,7 +180,7 @@ _dl_munmap (const void* addr, size_t len) } static inline int -_dl_mprotect (const void *addr, size_t size, int prot) +_dl_mprotect(const void *addr, size_t size, int prot) { register int status __asm__ ("3"); @@ -200,7 +200,7 @@ _dl_mprotect (const void *addr, size_t size, int prot) } static inline int -_dl_stat (const char *addr, struct stat *sb) +_dl_stat(const char *addr, struct stat *sb) { register int status __asm__ ("3"); @@ -219,7 +219,7 @@ _dl_stat (const char *addr, struct stat *sb) } static inline int -_dl_fstat (int fd, struct stat *sb) +_dl_fstat(int fd, struct stat *sb) { register int status __asm__ ("3"); @@ -238,7 +238,7 @@ _dl_fstat (int fd, struct stat *sb) } static inline int -_dl_fcntl (int fd, int cmd, int flag) +_dl_fcntl(int fd, int cmd, int flag) { register int status __asm__ ("3"); @@ -280,7 +280,7 @@ _dl_getdirentries(int fd, char *buf, int nbytes, long *basep) } static inline int -_dl_issetugid() +_dl_issetugid(void) { register int status __asm__ ("3"); @@ -303,10 +303,11 @@ _dl_lseek(int fildes, off_t offset, int whence) } static inline int -_dl_sigprocmask (int how, const sigset_t *set, sigset_t *oset) +_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 { @@ -349,7 +350,6 @@ _dl_sysctl(int *name, u_int namelen, void *oldp, size_t *oldplen, void *newp, "r" (oldplen), "r" (newp), "r" (newlen) : "0", "3", "4", "5", "6", "7", "8"); return status; - } #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 00c6166146c..b2ce3c5e556 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.26 2003/06/22 21:39:01 drahn Exp $ */ +/* $OpenBSD: resolve.h,v 1.27 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -170,6 +170,14 @@ void _dl_rtld(elf_object_t *object); void _dl_call_init(elf_object_t *object); void _dl_link_sub(elf_object_t *dep, elf_object_t *p); +void _dl_run_dtors(elf_object_t *object); + +Elf_Addr _dl_bind(elf_object_t *object, int index); + +int _dl_match_file(struct sod *sodp, char *name, int namelen); +char *_dl_find_shlib(struct sod *sodp, const char *searchpath, int nohints); +void _dl_load_list_free(struct load_list *load_list); + extern elf_object_t *_dl_objects; extern elf_object_t *_dl_last_object; diff --git a/libexec/ld.so/sod.c b/libexec/ld.so/sod.c index eb42997162b..9e8e3db24f5 100644 --- a/libexec/ld.so/sod.c +++ b/libexec/ld.so/sod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sod.c,v 1.17 2003/05/08 16:30:52 millert Exp $ */ +/* $OpenBSD: sod.c,v 1.18 2003/07/06 20:03:57 deraadt Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg @@ -50,6 +50,7 @@ #include "sod.h" int _dl_hinthash(char *cp, int vmajor, int vminor); +void _dl_maphints(void); /* * Populate sod struct for dlopen's call to map_object @@ -99,13 +100,13 @@ _dl_build_sod(const char *name, struct sod *sodp) break; case 2: /* major version extension */ - major = strtol(tok, &etok, 10); + major = _dl_strtol(tok, &etok, 10); if (*tok == '\0' || *etok != '\0') goto backout; break; case 3: /* minor version extension */ - minor = strtol(tok, &etok, 10); + minor = _dl_strtol(tok, &etok, 10); if (*tok == '\0' || *etok != '\0') goto backout; break; diff --git a/libexec/ld.so/sparc/rtld_machine.c b/libexec/ld.so/sparc/rtld_machine.c index 82e4a124537..b9f6820c24a 100644 --- a/libexec/ld.so/sparc/rtld_machine.c +++ b/libexec/ld.so/sparc/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.15 2003/06/03 16:20:41 art Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.16 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -323,7 +323,7 @@ resolve_failed: * Resolve a symbol at run-time. */ Elf_Addr -_dl_bind(elf_object_t *object, Elf_Word reloff) +_dl_bind(elf_object_t *object, int reloff) { const Elf_Sym *sym, *this; Elf_Addr *addr, ooff; @@ -354,7 +354,7 @@ _dl_bind(elf_object_t *object, Elf_Word reloff) sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); /* mprotect the actual modified region, not the whole plt */ - _dl_mprotect((void*)addr,sizeof (Elf_Addr) * 3, + _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 3, PROT_READ|PROT_WRITE|PROT_EXEC); } @@ -363,7 +363,7 @@ _dl_bind(elf_object_t *object, Elf_Word reloff) /* if PLT is (to be protected, change back to RO/X */ if (object->plt_size != 0) { /* mprotect the actual modified region, not the whole plt */ - _dl_mprotect((void*)addr,sizeof (Elf_Addr) * 3, + _dl_mprotect((void*)addr, sizeof (Elf_Addr) * 3, PROT_READ|PROT_EXEC); _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } diff --git a/libexec/ld.so/sparc/syscall.h b/libexec/ld.so/sparc/syscall.h index cc6556e9f75..520203bc847 100644 --- a/libexec/ld.so/sparc/syscall.h +++ b/libexec/ld.so/sparc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.5 2003/06/09 16:10:04 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.6 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -48,7 +48,6 @@ int _dl_munmap(const void*, unsigned int); int _dl_open(const char*, unsigned int); int _dl_read(int, const char*, int); int _dl_stat(const char *, struct stat *); -int _dl_write(int, const char*, int); int _dl_fstat(int, struct stat *); int _dl_fcntl(int, int, ...); int _dl_getdirentries(int, char*, int, long *); diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index 4e2b0a52d4d..93a28a9dd0c 100644 --- a/libexec/ld.so/sparc64/rtld_machine.c +++ b/libexec/ld.so/sparc64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.26 2003/06/03 16:20:41 art Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.27 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -209,6 +209,7 @@ static long reloc_target_bitmask[] = { #define RELOC_VALUE_BITMASK(t) (reloc_target_bitmask[t]) void _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela); +void _dl_install_plt(Elf_Word *pltgot, Elf_Addr proc); int _dl_md_reloc(elf_object_t *object, int rel, int relasz) @@ -589,7 +590,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela) /* * Resolve a symbol at run-time. */ -void * +Elf_Addr _dl_bind(elf_object_t *object, int index) { Elf_RelA *rela; @@ -654,7 +655,7 @@ _dl_bind(elf_object_t *object, int index) _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } - return (void *)ooff + this->st_value; + return ooff + this->st_value; } /* diff --git a/libexec/ld.so/sparc64/syscall.h b/libexec/ld.so/sparc64/syscall.h index e7eae1fb51f..f6b0638ff04 100644 --- a/libexec/ld.so/sparc64/syscall.h +++ b/libexec/ld.so/sparc64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.13 2003/06/09 16:10:04 deraadt Exp $ */ +/* $OpenBSD: syscall.h,v 1.14 2003/07/06 20:04:00 deraadt Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -48,7 +48,6 @@ int _dl_munmap(const void*, size_t); int _dl_open(const char*, int); ssize_t _dl_read(int, const char*, size_t); int _dl_stat(const char *, struct stat *); -ssize_t _dl_write(int, const char*, size_t); int _dl_fstat(int, struct stat *); int _dl_fcntl(int, int, ...); int _dl_getdirentries(int, char*, int, long *); diff --git a/libexec/ld.so/strtol.c b/libexec/ld.so/strtol.c new file mode 100644 index 00000000000..fbaf805b516 --- /dev/null +++ b/libexec/ld.so/strtol.c @@ -0,0 +1,138 @@ +/* $OpenBSD: strtol.c,v 1.1 2003/07/06 20:03:58 deraadt Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include "util.h" + +/* + * Convert a string to a long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long +_dl_strtol(const char *nptr, char **endptr, int base) +{ + const char *s; + long acc, cutoff; + int c; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = (unsigned char) *s++; + } while (c <= ' ' || c >= 0x7f); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? LONG_MIN : LONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + if (neg) { + if (cutlim > 0) { + cutlim -= base; + cutoff += 1; + } + cutlim = -cutlim; + } + for (acc = 0, any = 0;; c = (unsigned char) *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0) + continue; + if (neg) { + if (acc < cutoff || (acc == cutoff && c > cutlim)) { + any = -1; + acc = LONG_MIN; + } else { + any = 1; + acc *= base; + acc -= c; + } + } else { + if (acc > cutoff || (acc == cutoff && c > cutlim)) { + any = -1; + acc = LONG_MAX; + } else { + any = 1; + acc *= base; + acc += c; + } + } + } + if (endptr != 0) + *endptr = (char *) (any ? s - 1 : nptr); + return (acc); +} diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c index 797d0aef434..5ceaaf5f435 100644 --- a/libexec/ld.so/util.c +++ b/libexec/ld.so/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.15 2003/06/09 16:10:03 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.16 2003/07/06 20:03:58 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -40,6 +40,8 @@ */ long __guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; +void __stack_smash_handler(char [], int); + void __stack_smash_handler(char func[], int damaged) { @@ -120,7 +122,7 @@ _dl_free(void *p) unsigned int -_dl_random(void) +_dl_random(void) { int mib[2]; unsigned int rnd; diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index 65fa4177afc..6a027480919 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.15 2003/06/11 17:47:57 deraadt Exp $ */ +/* $OpenBSD: util.h,v 1.16 2003/07/06 20:03:58 deraadt Exp $ */ /* * Copyright (c) 1998 Todd C. Miller @@ -30,13 +30,22 @@ #ifndef __DL_UTIL_H__ #define __DL_UTIL_H__ + +#include + void *_dl_malloc(const size_t size); void _dl_free(void *); char *_dl_strdup(const char *); void _dl_printf(const char *fmt, ...); +void _dl_vprintf(const char *fmt, va_list ap); void _dl_fdprintf(int, const char *fmt, ...); void _dl_show_objects(void); unsigned int _dl_random(void); +ssize_t _dl_write(int fd, const char* buf, size_t len); + +void _dl_bcopy(const void *src, void *dest, int size); + +long _dl_strtol(const char *nptr, char **endptr, int base); /* * The following functions are declared inline so they can -- cgit v1.2.3