summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-03-20 02:32:41 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-03-20 02:32:41 +0000
commit3924b0c2475a56d000c0c5cae2ca1660a97b489b (patch)
treed5f23aa4e0c292f35123ecaf9761158d7c5d71e6 /lib/libc
parent4621abcf30c5f4ecef9340db8259e51bfabf6529 (diff)
Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a Make crt0 always invoke a new func _csu_finish() in libc to process the auxv and to either register the ld.so cleanup function (in dynamic links) or initialize environ and __progname and do MC_DISABLE_KBIND (in static links). In libc, get pagesize from auxv; cache that between getpagesize() and sysconf(_SC_PAGESIZE) ok mpi@ "good time" deraadt@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/Symbols.list3
-rw-r--r--lib/libc/arch/alpha/gdtoa/kbind.h28
-rw-r--r--lib/libc/arch/amd64/gdtoa/kbind.h26
-rw-r--r--lib/libc/arch/arm/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/hppa/gdtoa/kbind.h30
-rw-r--r--lib/libc/arch/hppa64/gdtoa/kbind.h4
-rw-r--r--lib/libc/arch/i386/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/m88k/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/mips64/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/powerpc/gdtoa/kbind.h23
-rw-r--r--lib/libc/arch/sh/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/sparc/gdtoa/kbind.h27
-rw-r--r--lib/libc/arch/sparc64/gdtoa/kbind.h27
-rw-r--r--lib/libc/dlfcn/Makefile.inc4
-rw-r--r--lib/libc/dlfcn/init.c107
-rw-r--r--lib/libc/gen/getpagesize.c12
-rw-r--r--lib/libc/gen/sysconf.c4
-rw-r--r--lib/libc/hidden/unistd.h7
-rw-r--r--lib/libc/shlib_version2
19 files changed, 427 insertions, 12 deletions
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list
index 54f19a9dbef..f954403d882 100644
--- a/lib/libc/Symbols.list
+++ b/lib/libc/Symbols.list
@@ -467,6 +467,8 @@ nextkey
store
/* dlfcn */
+__progname
+_csu_finish
dl_iterate_phdr
dladdr
dlclose
@@ -474,6 +476,7 @@ dlctl
dlerror
dlopen
dlsym
+environ
/* compat-43 */
creat
diff --git a/lib/libc/arch/alpha/gdtoa/kbind.h b/lib/libc/arch/alpha/gdtoa/kbind.h
new file mode 100644
index 00000000000..a0b474b72e1
--- /dev/null
+++ b/lib/libc/arch/alpha/gdtoa/kbind.h
@@ -0,0 +1,28 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+#include <machine/pal.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("$0") /* v0 */ = SYS_kbind;\
+ register void *arg1 __asm("$16") /* a0 */ = NULL; \
+ __asm volatile("call_pal %1" : "+r" (syscall_num) \
+ : "i" (PAL_OSF1_callsys), "r" (arg1) : "$19", "$20");\
+ } while (0)
diff --git a/lib/libc/arch/amd64/gdtoa/kbind.h b/lib/libc/arch/amd64/gdtoa/kbind.h
new file mode 100644
index 00000000000..7fa6b1df640
--- /dev/null
+++ b/lib/libc/arch/amd64/gdtoa/kbind.h
@@ -0,0 +1,26 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("rax") = SYS_kbind; \
+ __asm volatile("syscall" : "+r" (syscall_num) : \
+ "D" (0) : "cc", "rdx", "rcx", "r11", "memory"); \
+ } while (0)
diff --git a/lib/libc/arch/arm/gdtoa/kbind.h b/lib/libc/arch/arm/gdtoa/kbind.h
new file mode 100644
index 00000000000..bfa8c493a16
--- /dev/null
+++ b/lib/libc/arch/arm/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("r12") = SYS_kbind; \
+ register void *arg1 __asm("r0") = NULL; \
+ __asm volatile("swi 0" : "+r" (arg1) \
+ : "r" (syscall_num) : "r1", "cc"); \
+ } while (0)
diff --git a/lib/libc/arch/hppa/gdtoa/kbind.h b/lib/libc/arch/hppa/gdtoa/kbind.h
new file mode 100644
index 00000000000..26a5099296b
--- /dev/null
+++ b/lib/libc/arch/hppa/gdtoa/kbind.h
@@ -0,0 +1,30 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+#include <machine/vmparam.h> /* SYSCALLGATE */
+
+#define MD_DISABLE_KBIND \
+do { \
+ register long r1 __asm__("r1") = SYSCALLGATE; \
+ register void *arg0 __asm__("r26") = NULL; \
+ __asm__ __volatile__ ("ble 4(%%sr7, %%r1) ! ldi %0, %%r22" \
+ : \
+ : "i" (SYS_kbind), "r" (r1), "r"(arg0) \
+ : "r22", "r28", "r29", "cc", "memory"); \
+} while (0)
diff --git a/lib/libc/arch/hppa64/gdtoa/kbind.h b/lib/libc/arch/hppa64/gdtoa/kbind.h
new file mode 100644
index 00000000000..5ad40bb38eb
--- /dev/null
+++ b/lib/libc/arch/hppa64/gdtoa/kbind.h
@@ -0,0 +1,4 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/* kbind disabled in the kernel for hppa64 until we do dynamic linking */
+#define MD_DISABLE_KBIND do { } while (0)
diff --git a/lib/libc/arch/i386/gdtoa/kbind.h b/lib/libc/arch/i386/gdtoa/kbind.h
new file mode 100644
index 00000000000..ddba710c51d
--- /dev/null
+++ b/lib/libc/arch/i386/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("eax") = SYS_kbind; \
+ __asm volatile("pushl $0; push %%eax; int $0x80;" \
+ " addl $8, %%esp" : "+a" (syscall_num) : \
+ : "edx", "cc"); \
+ } while (0)
diff --git a/lib/libc/arch/m88k/gdtoa/kbind.h b/lib/libc/arch/m88k/gdtoa/kbind.h
new file mode 100644
index 00000000000..329e2060236
--- /dev/null
+++ b/lib/libc/arch/m88k/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("r13") = SYS_kbind; \
+ register void *arg1 __asm("r2") = NULL; \
+ __asm volatile("tb0 0, %%r0, 450; or %%r0, %%r0, %%r0" \
+ : "+r" (arg1) : "r" (syscall_num) : "r3", "cc"); \
+ } while (0)
diff --git a/lib/libc/arch/mips64/gdtoa/kbind.h b/lib/libc/arch/mips64/gdtoa/kbind.h
new file mode 100644
index 00000000000..06ecc4f0758
--- /dev/null
+++ b/lib/libc/arch/mips64/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("v0") = SYS_kbind; \
+ register void *arg1 __asm("a0") = NULL; \
+ __asm volatile("syscall" : "+r" (syscall_num) \
+ : "r" (arg1) : "v1", "a3"); \
+ } while (0)
diff --git a/lib/libc/arch/powerpc/gdtoa/kbind.h b/lib/libc/arch/powerpc/gdtoa/kbind.h
new file mode 100644
index 00000000000..3e324d59636
--- /dev/null
+++ b/lib/libc/arch/powerpc/gdtoa/kbind.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ __asm volatile("li %%r3, 0; li %%r0, %0; sc" : \
+ : "i" (SYS_kbind) : "r0", "r3", "r4", "cc")
diff --git a/lib/libc/arch/sh/gdtoa/kbind.h b/lib/libc/arch/sh/gdtoa/kbind.h
new file mode 100644
index 00000000000..597556f8a33
--- /dev/null
+++ b/lib/libc/arch/sh/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("r0") = SYS_kbind; \
+ register void *arg1 __asm("r4") = NULL; \
+ __asm volatile("trapa #0x80" : "+r" (syscall_num) \
+ : "r" (arg1) : "r1", "cc"); \
+ } while (0)
diff --git a/lib/libc/arch/sparc/gdtoa/kbind.h b/lib/libc/arch/sparc/gdtoa/kbind.h
new file mode 100644
index 00000000000..62db01ad881
--- /dev/null
+++ b/lib/libc/arch/sparc/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("g1") = SYS_kbind; \
+ register void *arg1 __asm("o0") = NULL; \
+ __asm volatile("t 0" : "+r" (arg1) : "r" (syscall_num) \
+ : "o1", "cc"); \
+ } while (0)
diff --git a/lib/libc/arch/sparc64/gdtoa/kbind.h b/lib/libc/arch/sparc64/gdtoa/kbind.h
new file mode 100644
index 00000000000..62db01ad881
--- /dev/null
+++ b/lib/libc/arch/sparc64/gdtoa/kbind.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: kbind.h,v 1.1 2016/03/20 02:32:39 guenther Exp $ */
+
+/*
+ * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+
+#define MD_DISABLE_KBIND \
+ do { \
+ register long syscall_num __asm("g1") = SYS_kbind; \
+ register void *arg1 __asm("o0") = NULL; \
+ __asm volatile("t 0" : "+r" (arg1) : "r" (syscall_num) \
+ : "o1", "cc"); \
+ } while (0)
diff --git a/lib/libc/dlfcn/Makefile.inc b/lib/libc/dlfcn/Makefile.inc
index bdc09511fa8..f88b0f3fc0b 100644
--- a/lib/libc/dlfcn/Makefile.inc
+++ b/lib/libc/dlfcn/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.3 2013/07/05 21:29:51 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.4 2016/03/20 02:32:39 guenther Exp $
.PATH: ${LIBCSRCDIR}/dlfcn
.include <bsd.own.mk>
-SRCS+= dlfcn_stubs.c
+SRCS+= dlfcn_stubs.c init.c
diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c
new file mode 100644
index 00000000000..b12b7104fe9
--- /dev/null
+++ b/lib/libc/dlfcn/init.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#define _DYN_LOADER
+
+#include <sys/types.h>
+#include <sys/exec_elf.h>
+
+#include <limits.h> /* NAME_MAX */
+#include <stdlib.h> /* atexit */
+#include <string.h>
+#include <unistd.h> /* _pagesize */
+#include "kbind.h"
+
+/* XXX should be in an include file shared with csu */
+char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void));
+
+/* provide definition for this */
+int _pagesize = 0;
+
+/*
+ * In dynamicly linked binaries environ and __progname are overriden by
+ * the definitions in ld.so.
+ */
+char **environ __attribute__((weak)) = NULL;
+char *__progname __attribute__((weak)) = NULL;
+
+
+#ifndef PIC
+static inline void early_static_init(char **_argv, char **_envp);
+#endif /* PIC */
+
+
+/*
+ * extract useful bits from the auxiliary vector and either
+ * a) register ld.so's cleanup in dynamic links, or
+ * b) init __progname, environ, and the TIB in static links.
+ */
+char ***
+_csu_finish(char **argv, char **envp, void (*cleanup)(void))
+{
+ AuxInfo *aux;
+
+#ifndef PIC
+ /* static libc in a static link? */
+ if (cleanup == NULL)
+ early_static_init(argv, envp);
+#endif /* !PIC */
+
+ /* Extract useful bits from the auxiliary vector */
+ while (*envp++ != NULL)
+ ;
+ for (aux = (void *)envp; aux->au_id != AUX_null; aux++) {
+ switch (aux->au_id) {
+ case AUX_pagesz:
+ _pagesize = aux->au_v;
+ break;
+ }
+ }
+
+ if (cleanup != NULL)
+ atexit(cleanup);
+
+ return &environ;
+}
+
+#ifndef PIC
+/*
+ * static libc in a static link? Then disable kbind and set up
+ * __progname and environ
+ */
+static inline void
+early_static_init(char **argv, char **envp)
+{
+ static char progname_storage[NAME_MAX+1] = "";
+
+ MD_DISABLE_KBIND;
+
+ environ = envp;
+
+ /* set up __progname */
+ if (*argv != NULL) { /* NULL ptr if argc = 0 */
+ const char *p = strrchr(*argv, '/');
+
+ if (p == NULL)
+ p = *argv;
+ else
+ p++;
+ strlcpy(progname_storage, p, sizeof(progname_storage));
+ }
+ __progname = progname_storage;
+}
+#endif /* !PIC */
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c
index 3c81d64209e..aa2919032fa 100644
--- a/lib/libc/gen/getpagesize.c
+++ b/lib/libc/gen/getpagesize.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getpagesize.c,v 1.8 2015/09/12 14:56:50 guenther Exp $ */
+/* $OpenBSD: getpagesize.c,v 1.9 2016/03/20 02:32:40 guenther Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,18 +35,16 @@
int
getpagesize(void)
{
- static int pagsz;
-
- if (pagsz == 0) {
+ if (_pagesize == 0) {
int mib[2];
size_t size;
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
- size = sizeof pagsz;
- if (sysctl(mib, 2, &pagsz, &size, NULL, 0) == -1)
+ size = sizeof _pagesize;
+ if (sysctl(mib, 2, &_pagesize, &size, NULL, 0) == -1)
return (-1);
}
- return (pagsz);
+ return (_pagesize);
}
DEF_WEAK(getpagesize);
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 3f39418f026..03becb59eec 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysconf.c,v 1.23 2015/09/12 14:56:50 guenther Exp $ */
+/* $OpenBSD: sysconf.c,v 1.24 2016/03/20 02:32:40 guenther Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@@ -131,6 +131,8 @@ sysconf(int name)
/* 1003.1b */
case _SC_PAGESIZE:
+ if (_pagesize != 0)
+ return (_pagesize);
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
break;
diff --git a/lib/libc/hidden/unistd.h b/lib/libc/hidden/unistd.h
index beef03906c7..835dc295b8c 100644
--- a/lib/libc/hidden/unistd.h
+++ b/lib/libc/hidden/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.5 2015/10/17 20:22:08 deraadt Exp $ */
+/* $OpenBSD: unistd.h,v 1.6 2016/03/20 02:32:40 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -20,6 +20,11 @@
#include_next <unistd.h>
+__BEGIN_HIDDEN_DECLS
+/* shared between getpagesize(), sysconf(), and _csu_finish() */
+extern int _pagesize;
+__END_HIDDEN_DECLS
+
PROTO_NORMAL(__tfork_thread);
PROTO_NORMAL(_exit);
PROTO_NORMAL(access);
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 203c482b214..19127031a94 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
major=84
-minor=2
+minor=3
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then librthread/shlib_version also be updated.