From c2ac5ba3964165ee2d21ccd4c6bf8bdc48e1a165 Mon Sep 17 00:00:00 2001 From: Richard M Kreuter Date: Wed, 9 Jan 2008 19:12:23 +0000 Subject: [PATCH] 1.0.13.18: Revived OpenBSD support, contributed by Josh Elsasser --- make-config.sh | 5 +-- src/code/foreign-load.lisp | 5 ++- src/code/run-program.lisp | 17 +++++++++- src/compiler/x86/parms.lisp | 22 ++++++++----- src/runtime/Config.x86-openbsd | 23 ++++++++------ src/runtime/bsd-os.c | 69 +++++++++++++++++++++++++++++++++++++++-- src/runtime/bsd-os.h | 8 ----- tests/float.pure.lisp | 4 +-- tools-for-build/ldso-stubs.lisp | 4 ++- version.lisp-expr | 2 +- 10 files changed, 124 insertions(+), 35 deletions(-) diff --git a/make-config.sh b/make-config.sh index 9e60a6f2c..23f8dcc8b 100644 --- a/make-config.sh +++ b/make-config.sh @@ -284,9 +284,10 @@ if [ "$sbcl_arch" = "x86" ]; then printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop' >> $ltf printf ' :stack-allocatable-closures :alien-callbacks' >> $ltf - if [ "$sbcl_os" = "linux" ] || [ "$sbcl_os" = "freebsd" ] || [ "$sbcl_os" = "netbsd" ] || [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "darwin" ] || [ "$sbcl_os" = "win32" ]; then + case "$sbcl_os" in + linux | freebsd | netbsd | openbsd | sunos | darwin | win32) printf ' :linkage-table' >> $ltf - fi + esac if [ "$sbcl_os" = "win32" ]; then # of course it doesn't provide dlopen, but there is # roughly-equivalent magic nevertheless. diff --git a/src/code/foreign-load.lisp b/src/code/foreign-load.lisp index 2e619efc7..7aece9f54 100644 --- a/src/code/foreign-load.lisp +++ b/src/code/foreign-load.lisp @@ -33,7 +33,10 @@ (define-alien-routine dlerror c-string) -(define-alien-routine dlsym system-area-pointer +(define-alien-routine + #!-openbsd dlsym + #!+openbsd ("os_dlsym" dlsym) + system-area-pointer (handle system-area-pointer) (symbol c-string)) diff --git a/src/code/run-program.lisp b/src/code/run-program.lisp index 5339eb1a7..1a928fd29 100644 --- a/src/code/run-program.lisp +++ b/src/code/run-program.lisp @@ -390,7 +390,7 @@ status slot." ;;; Find an unused pty. Return three values: the file descriptor for ;;; the master side of the pty, the file descriptor for the slave side ;;; of the pty, and the name of the tty device for the slave side. -#-win32 +#-(or win32 openbsd) (progn (define-alien-routine ptsname c-string (fd int)) (define-alien-routine grantpt boolean (fd int)) @@ -437,6 +437,21 @@ status slot." slave-name))) (sb-unix:unix-close master-fd)))))) (error "could not find a pty"))) +#+openbsd +(progn + (define-alien-routine openpty int (amaster int :out) (aslave int :out) + (name (* char)) (termp (* t)) (winp (* t))) + (defun find-a-pty () + (with-alien ((name-buf (array char 16))) + (multiple-value-bind (return-val master-fd slave-fd) + (openpty (cast name-buf (* char)) nil nil) + (if (zerop return-val) + (values master-fd + slave-fd + (sb-alien::c-string-to-string (alien-sap name-buf) + (sb-impl::default-external-format) + 'character)) + (error "could not find a pty")))))) #-win32 (defun open-pty (pty cookie) diff --git a/src/compiler/x86/parms.lisp b/src/compiler/x86/parms.lisp index 6a19fc04e..67655cd8a 100644 --- a/src/compiler/x86/parms.lisp +++ b/src/compiler/x86/parms.lisp @@ -159,6 +159,12 @@ ;;; And if KVA_PAGES is extended from 1GB to 1.5GB, we can't use ;;; down to around 0xA0000000. ;;; So we use 0x58000000--0x98000000 for dynamic space. +;;; * OpenBSD address space changes for W^X as well as malloc +;;; randomization made the old addresses unsafe. The only range +;;; that is really safe is between the end of the text segment (it +;;; starts at #x3C000000) and #x7C000000. However if the -Z linker +;;; option is used then the safe range is (probably) #x00001000 to +;;; #x48048000, with the text and data segments at #x08048000. #!+win32 (progn @@ -219,18 +225,18 @@ #!+openbsd (progn - (def!constant read-only-space-start #x10000000) - (def!constant read-only-space-end #x100ff000) + (def!constant read-only-space-start #x7b000000) + (def!constant read-only-space-end #x7b0ff000) - (def!constant static-space-start #x10100000) - (def!constant static-space-end #x101ff000) + (def!constant static-space-start #x7b100000) + (def!constant static-space-end #x7b1ff000) - (def!constant dynamic-space-start #x80000000) - (def!constant dynamic-space-end #xA0000000) + (def!constant dynamic-space-start #x4c000000) + (def!constant dynamic-space-end #x7b0ff000) ;; In CMUCL: 0xB0000000->0xB1000000 - (def!constant linkage-table-space-start #x10200000) - (def!constant linkage-table-space-end #x102ff000)) + (def!constant linkage-table-space-start #x7b200000) + (def!constant linkage-table-space-end #x7b2ff000)) #!+netbsd (progn diff --git a/src/runtime/Config.x86-openbsd b/src/runtime/Config.x86-openbsd index 82943f06f..b55c79436 100644 --- a/src/runtime/Config.x86-openbsd +++ b/src/runtime/Config.x86-openbsd @@ -11,13 +11,18 @@ include Config.x86-bsd -OS_SRC += undefineds.c +ASSEM_SRC += ldso-stubs.S +OS_LIBS += -lutil -# KLUDGE: It might seem as though dynamic libraries should work the -# same way on both systems, but in fact gcc supports the "-export-dynamic" -# option on FreeBSD but not on OpenBSD. The documentation I've been -# able to find doesn't seem to begin to explain what's going on (e.g. I -# have never found documentation for the "-export-dynamic" option), -# so I've just punted and left link flags for OpenBSD in their -# pre-dynamic-library-support state. -- WHN 2000-10-02 -LINKFLAGS += -static +# The -Z linker flag conflicts with the default address space +# locations used. If you wish to link the runtime using -Z option then +# please see the comments in src/compiler/x86/parms.lisp + +# XXX why do all the other Configs set LINKFLAGS instead of LDFLAGS? +# LINKFLAGS is only used in src/runtime/GNUmakefile, this causes the +# dladdr test in tools-for-build/ to fail. + +LINKFLAGS += -export-dynamic +LDFLAGS += -export-dynamic + +CFLAGS = -g -Wall -O2 diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c index f1697200f..a364d5a0b 100644 --- a/src/runtime/bsd-os.c +++ b/src/runtime/bsd-os.c @@ -66,6 +66,15 @@ static void netbsd_init(); static void freebsd_init(); #endif /* __FreeBSD__ */ +#ifdef __OpenBSD__ +#include +#include +#include +#include + +static void openbsd_init(); +#endif + void os_init(char *argv[], char *envp[]) { @@ -75,6 +84,8 @@ os_init(char *argv[], char *envp[]) netbsd_init(); #elif defined(__FreeBSD__) freebsd_init(); +#elif defined(__OpenBSD__) + openbsd_init(); #endif } @@ -464,7 +475,7 @@ os_get_runtime_executable_path() return NULL; return copied_string(path); } -#elif defined(LISP_FEATURE_NETBSD) +#elif defined(LISP_FEATURE_NETBSD) || defined(LISP_FEATURE_OPENBSD) char * os_get_runtime_executable_path() { @@ -477,10 +488,64 @@ os_get_runtime_executable_path() return NULL; } } -#else /* Not DARWIN or FREEBSD or NETBSD */ +#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD */ char * os_get_runtime_executable_path() { return NULL; } #endif + +#ifdef __OpenBSD__ +void +openbsd_init() +{ + struct rlimit rl; + + /* OpenBSD, like NetBSD, counts mmap()ed space against the + * process's data size limit. If the soft limit is lower than the + * hard limit then try to yank it up, this lets users in the + * "staff" login class run sbcl with a default /etc/login.conf + */ + getrlimit (RLIMIT_DATA, &rl); + if (rl.rlim_cur < rl.rlim_max) { + rl.rlim_cur = rl.rlim_max; + if (setrlimit (RLIMIT_DATA, &rl) < 0) { + fprintf (stderr, + "RUNTIME WARNING: unable to raise process data size limit:\n\ + %s.\n\ +The system may fail to start.\n", + strerror(errno)); + } + } + + /* Display a (hopefully) helpful warning if it looks like we won't + * be able to allocate enough memory. In testing I found that on + * my system at least, a minimum of 25M on top of the three space + * sizes was needed to start SBCL. Show a warning below 32M so as + * to leave a little breathing room. + */ + getrlimit (RLIMIT_DATA, &rl); + if (dynamic_space_size + READ_ONLY_SPACE_SIZE + STATIC_SPACE_SIZE + + LINKAGE_TABLE_SPACE_SIZE + (32*1024*1024) > rl.rlim_cur) + fprintf (stderr, + "RUNTIME WARNING: data size resource limit may be too low,\n" + " try decreasing the dynamic space size with --dynamic-space-size\n"); +} + +/* OpenBSD's dlsym() relies on the gcc bulitin + * __builtin_return_address(0) returning an address in the + * executable's text segment, but when called from lisp it will return + * an address in the dynamic space. Work around this by calling this + * wrapper function instead. Note that tail-call optimization will + * defeat this, disable it by saving the dlsym() return value in a + * volatile variable. +*/ +void * +os_dlsym(void *handle, const char *symbol) +{ + void * volatile ret = dlsym(handle, symbol); + return ret; +} + +#endif diff --git a/src/runtime/bsd-os.h b/src/runtime/bsd-os.h index f1669d6cc..23ab40f89 100644 --- a/src/runtime/bsd-os.h +++ b/src/runtime/bsd-os.h @@ -32,14 +32,6 @@ typedef vm_size_t os_vm_size_t; typedef off_t os_vm_offset_t; typedef int os_vm_prot_t; -#if defined __OpenBSD__ -/* name defined for compatibility between OpenBSD 3.1 sigaltstack(2) and - * Linux sigaltstack(2) */ -typedef struct sigaltstack stack_t; -#elif defined __FreeBSD__ -/* FreeBSD 4.6 and NetBSD 1.6 already have stack_t defined. */ -#endif - #if defined __FreeBSD__ /* Note: The man page for sigaction(2) in FreeBSD 4.0 says that this * is an mcontext_t, but according to comments by Raymond Wiker in the diff --git a/tests/float.pure.lisp b/tests/float.pure.lisp index 724d2088b..7acc04889 100644 --- a/tests/float.pure.lisp +++ b/tests/float.pure.lisp @@ -93,7 +93,7 @@ (assert (= 0.0d0 (scale-float 1.0d0 (1- most-negative-fixnum)))) (with-test (:name (:scale-float-overflow :bug-372) - :fails-on '(or :ppc :darwin)) ;; bug 372 + :fails-on '(or :ppc :darwin (and :x86 :openbsd))) ;; bug 372 (progn (assert (raises-error? (scale-float 1.0 most-positive-fixnum) floating-point-overflow)) @@ -125,7 +125,7 @@ (funcall (compile nil '(lambda () (tan (tan (round 0)))))) (with-test (:name (:addition-overflow :bug-372) - :fails-on '(or :ppc :darwin (and :x86 :netbsd))) + :fails-on '(or :ppc :darwin (and :x86 (or :netbsd :openbsd)))) (assert (typep (nth-value 1 (ignore-errors diff --git a/tools-for-build/ldso-stubs.lisp b/tools-for-build/ldso-stubs.lisp index 5df857a06..45d242560 100644 --- a/tools-for-build/ldso-stubs.lisp +++ b/tools-for-build/ldso-stubs.lisp @@ -299,10 +299,12 @@ ldso_stub__ ## fct: ; \\ ;; #!-linkage-table, as we only need these stubs if ;; we don't have linkage-table. Done this way now to ;; cut down on the number of ports affected. - #!-(or win32 darwin freebsd netbsd) + #!-(or win32 darwin freebsd netbsd openbsd) '("ptsname" "grantpt" "unlockpt") + #!+openbsd + '("openpty") #!-darwin '("dlclose" "dlerror" diff --git a/version.lisp-expr b/version.lisp-expr index 023458dbb..29c6535d6 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.13.17" +"1.0.13.18" -- 2.11.4.GIT