Skip to content

Commit

Permalink
support for DragonFly BSD
Browse files Browse the repository at this point in the history
x86(-64) only for now, and threads are currently non-functional.
Closes lp#1292845, thanks to Vasily Postnicov.
  • Loading branch information
csrhodes committed Jun 20, 2014
1 parent 233cf1b commit c06b8c1
Show file tree
Hide file tree
Showing 27 changed files with 273 additions and 57 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ changes relative to sbcl-1.2.0:
to Christoph Egger)
* enhancement: experimental support for threads on NetBSD/x86-64. (thanks
to Robert Swindells)
* enhancement: support for DragonFly BSD. (lp#1292845, thanks to Vasily
Postnicov)
* bug fix: TYPE-OF must not return AND/OR/NOT expressions.
(lp#1317308)
* bug fix: accessing NIL arrays stopped producing errors. (lp#1311421)
Expand Down
5 changes: 5 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ DARWIN
Needs love, particularly threads and exceptions/signals. slam.sh is
also broken there.

DRAGONFLY
Multithreading does not work. Possibly because of bug in mmap/munmap.
Hint: Comment out call to os_invalidate in perform_thread_post_mortem
and threads will work, but space will not be freed, of course.

FUNCTION NAMES

We'd like to be able to (SETF %FUNCTION-NAME) on a closure.
Expand Down
35 changes: 18 additions & 17 deletions base-target-features.lisp-expr
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,24 @@
;; implemented for this platform.
;;
;; operating system features:
;; :unix = We're intended to run under some Unix-like OS. (This is not
;; exclusive with the features which indicate which particular
;; Unix-like OS we're intended to run under.)
;; :linux = We're intended to run under some version of Linux.
;; :bsd = We're intended to run under some version of BSD Unix. (This
;; is not exclusive with the features which indicate which
;; particular version of BSD we're intended to run under.)
;; :freebsd = We're intended to run under FreeBSD.
;; :openbsd = We're intended to run under OpenBSD.
;; :netbsd = We're intended to run under NetBSD.
;; :darwin = We're intended to run under Darwin (including MacOS X).
;; :sunos = We're intended to run under Solaris user environment
;; with the SunOS kernel.
;; :hpux = We're intended to run under HP-UX 11.11 or later
;; :osf1 = We're intended to run under Tru64 (aka Digital Unix
;; aka OSF/1).
;; :win32 = We're intended to under some version of Microsoft Windows.
;; :unix = We're intended to run under some Unix-like OS. (This is not
;; exclusive with the features which indicate which particular
;; Unix-like OS we're intended to run under.)
;; :linux = We're intended to run under some version of Linux.
;; :bsd = We're intended to run under some version of BSD Unix. (This
;; is not exclusive with the features which indicate which
;; particular version of BSD we're intended to run under.)
;; :freebsd = We're intended to run under FreeBSD.
;; :openbsd = We're intended to run under OpenBSD.
;; :netbsd = We're intended to run under NetBSD.
;; :dragonfly = We're intended to run under DragonFly BSD.
;; :darwin = We're intended to run under Darwin (including MacOS X).
;; :sunos = We're intended to run under Solaris user environment
;; with the SunOS kernel.
;; :hpux = We're intended to run under HP-UX 11.11 or later
;; :osf1 = We're intended to run under Tru64 (aka Digital Unix
;; aka OSF/1).
;; :win32 = We're intended to under some version of Microsoft Windows.
;; (No others are supported by SBCL as of 1.0.8, but :hpux or :irix
;; support could be ported from CMU CL if anyone is sufficiently
;; motivated to do so.)
Expand Down
2 changes: 1 addition & 1 deletion contrib/asdf/asdf.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ then returning the non-empty string value of the variable"
'(:cygwin (:win :windows :mswindows :win32 :mingw32) ;; try cygwin first!
(:linux :linux :linux-target) ;; for GCL at least, must appear before :bsd
(:macosx :macosx :darwin :darwin-target :apple) ; also before :bsd
(:solaris :solaris :sunos) (:bsd :bsd :freebsd :netbsd :openbsd) :unix
(:solaris :solaris :sunos) (:bsd :bsd :freebsd :netbsd :openbsd :dragonfly) :unix
:genera)))

(defun architecture ()
Expand Down
2 changes: 1 addition & 1 deletion contrib/sb-bsd-sockets/constants.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
(:integer EAI-BADFLAGS "EAI_BADFLAGS")
(:integer EAI-NONAME "EAI_NONAME")
(:integer EAI-SERVICE "EAI_SERVICE")
#-freebsd
#-(or freebsd dragonfly)
(:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
(:integer EAI-MEMORY "EAI_MEMORY")
(:integer EAI-FAIL "EAI_FAIL")
Expand Down
1 change: 1 addition & 0 deletions contrib/sb-bsd-sockets/tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
;;; Apparently getprotobyname_r on FreeBSD says -1 and EINTR
;;; for unknown protocols...
#-(and freebsd sb-thread)
#-(and dragonfly sb-thread)
(deftest get-protocol-by-name/error
(handler-case (get-protocol-by-name "nonexistent-protocol")
(unknown-protocol ()
Expand Down
21 changes: 19 additions & 2 deletions make-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ case `uname` in
;;
esac
;;
DragonFly)
sbcl_os="dragonfly"
;;
Darwin)
sbcl_os="darwin"
;;
Expand Down Expand Up @@ -399,7 +402,8 @@ then
# If --fancy, enable threads on platforms where they can be built.
case $sbcl_arch in
x86|x86-64|ppc)
if [ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]
if ([ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]) || \
[ "$sbcl_os" = "dragonfly" ]
then
echo "No threads on this platform."
else
Expand Down Expand Up @@ -513,6 +517,19 @@ case "$sbcl_os" in
;;
esac
;;
dragonfly)
printf ' :unix' >> $ltf
printf ' :bsd' >> $ltf
printf ' :elf' >> $ltf
printf ' :dragonfly' >> $ltf
printf ' :sb-qshow' >> $ltf
if [ $sbcl_arch = "x86" ]; then
printf ' :restore-fs-segment-register-from-tls' >> $ltf
fi
link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
link_or_copy bsd-os.h target-os.h
link_or_copy Config.$sbcl_arch-dragonfly Config
;;
darwin)
printf ' :unix' >> $ltf
printf ' :mach-o' >> $ltf
Expand Down Expand Up @@ -598,7 +615,7 @@ if [ "$sbcl_arch" = "x86" ]; then
printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
printf ' :memory-barrier-vops :multiply-high-vops :ash-right-vops :symbol-info-vops' >> $ltf
case "$sbcl_os" in
linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
linux | freebsd | netbsd | openbsd | sunos | darwin | win32 | dragonfly)
printf ' :linkage-table' >> $ltf
esac
if [ "$sbcl_os" = "win32" ]; then
Expand Down
4 changes: 2 additions & 2 deletions src/code/run-program.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,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.
#-(or win32 openbsd freebsd)
#-(or win32 openbsd freebsd dragonfly)
(progn
(define-alien-routine ptsname c-string (fd int))
(define-alien-routine grantpt boolean (fd int))
Expand Down Expand Up @@ -458,7 +458,7 @@ status slot."
(sb-unix:unix-close master-fd))))))
(error "could not find a pty")))

#+(or openbsd freebsd)
#+(or openbsd freebsd dragonfly)
(progn
(define-alien-routine openpty int (amaster int :out) (aslave int :out)
(name (* char)) (termp (* t)) (winp (* t)))
Expand Down
6 changes: 3 additions & 3 deletions src/code/unix.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,16 @@ corresponds to NAME, or NIL if there is none."
;;
;; Signal an error at compile-time, since it's needed for the
;; runtime to start up
#!-(or android linux openbsd freebsd netbsd sunos osf1 darwin hpux win32)
#!-(or android linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly)
#.(error "POSIX-GETCWD is not implemented.")
(or
#!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32)
#!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly)
(newcharstar-string (alien-funcall (extern-alien "getcwd"
(function (* char)
(* char)
size-t))
nil
#!+(or linux openbsd freebsd netbsd darwin win32) 0
#!+(or linux openbsd freebsd netbsd darwin win32 dragonfly) 0
#!+(or sunos osf1 hpux) 1025))
#!+android
(with-alien ((ptr (array char #.path-max)))
Expand Down
5 changes: 4 additions & 1 deletion src/cold/shared.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@
(and ppc (or sparc x86 x86-64))
(and sparc (or x86 x86-64))
(and x86 x86-64))"
"More than one architecture selected")))
"More than one architecture selected")
;; There is still hope to make multithreading on DragonFly x86-64
("(and sb-thread x86 dragonfly)"
":SB-THREAD not supported on selected architecture")))
(failed-test-descriptions nil))
(dolist (test feature-compatability-tests)
(let ((*features* *shebang-features*))
Expand Down
15 changes: 8 additions & 7 deletions src/compiler/x86/parms.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,14 @@
;;; NetBSD configuration used to have this comment regarding the linkage
;;; table: "In CMUCL: 0xB0000000->0xB1000000"

#!+win32 (!gencgc-space-setup #x22000000 nil nil #x10000)
#!+linux (!gencgc-space-setup #x01000000 #x09000000)
#!+sunos (!gencgc-space-setup #x20000000 #x48000000)
#!+freebsd (!gencgc-space-setup #x01000000 #x58000000)
#!+openbsd (!gencgc-space-setup #x1b000000 #x40000000)
#!+netbsd (!gencgc-space-setup #x20000000 #x60000000)
#!+darwin (!gencgc-space-setup #x04000000 #x10000000)
#!+win32 (!gencgc-space-setup #x22000000 nil nil #x10000)
#!+linux (!gencgc-space-setup #x01000000 #x09000000)
#!+sunos (!gencgc-space-setup #x20000000 #x48000000)
#!+freebsd (!gencgc-space-setup #x01000000 #x58000000)
#!+dragonfly (!gencgc-space-setup #x01000000 #x58000000)
#!+openbsd (!gencgc-space-setup #x1b000000 #x40000000)
#!+netbsd (!gencgc-space-setup #x20000000 #x60000000)
#!+darwin (!gencgc-space-setup #x04000000 #x10000000)

;;; Size of one linkage-table entry in bytes.
(def!constant linkage-table-entry-size 8)
Expand Down
24 changes: 24 additions & 0 deletions src/runtime/Config.x86-64-dragonfly
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- makefile -*- for the C-level run-time support for SBCL

# This software is part of the SBCL system. See the README file for
# more information.
#
# This software is derived from the CMU CL system, which was
# written at Carnegie Mellon University and released into the
# public domain. The software is in the public domain and is
# provided with absolutely no warranty. See the COPYING and CREDITS
# files for more information.

# DragonFly BSD config is a modification of one for FreeBSD

include Config.x86-64-bsd

ASSEM_SRC += ldso-stubs.S
LINKFLAGS += -dynamic -export-dynamic

# Link against pthread even if we do not want threaded SBCL
# This is because of bug in DragonFly RTLD which sometimes
# (in very rare situations) makes loading threaded libraries
# impossible without it.
# See: https://bugs.dragonflybsd.org/issues/2663
OS_LIBS += -lutil -lpthread
25 changes: 25 additions & 0 deletions src/runtime/Config.x86-dragonfly
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- makefile -*- for the C-level run-time support for SBCL

# This software is part of the SBCL system. See the README file for
# more information.
#
# This software is derived from the CMU CL system, which was
# written at Carnegie Mellon University and released into the
# public domain. The software is in the public domain and is
# provided with absolutely no warranty. See the COPYING and CREDITS
# files for more information.

# DragonFly BSD config is a modification of one for FreeBSD

include Config.x86-bsd

ASSEM_SRC += ldso-stubs.S
LINKFLAGS += -dynamic -export-dynamic
# Link against pthread even if we do not want threaded SBCL
# This is because of bug in DragonFly RTLD which sometimes
# (in very rare situations) makes loading threaded libraries
# impossible without it.
# See: https://bugs.dragonflybsd.org/issues/2663
OS_LIBS += -lutil -lpthread

CFLAGS += -fno-omit-frame-pointer
79 changes: 77 additions & 2 deletions src/runtime/bsd-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ static os_vm_size_t max_allocation_size;
static void freebsd_init();
#endif /* __FreeBSD__ */

#ifdef __DragonFly__
#include <sys/sysctl.h>

static void dragonfly_init();
#endif /* __DragonFly__ */

#ifdef __OpenBSD__
#include <sys/types.h>
#include <sys/resource.h>
Expand All @@ -99,6 +105,8 @@ os_init(char *argv[], char *envp[])
openbsd_init();
#elif defined(LISP_FEATURE_DARWIN)
darwin_init();
#elif defined(__DragonFly__)
dragonfly_init();
#endif
}

Expand All @@ -108,7 +116,8 @@ os_context_sigmask_addr(os_context_t *context)
/* (Unlike most of the other context fields that we access, the
* signal mask field is a field of the basic, outermost context
* struct itself both in FreeBSD 4.0 and in OpenBSD 2.6.) */
#if defined(LISP_FEATURE_FREEBSD) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN)
#if defined(LISP_FEATURE_FREEBSD) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) \
|| defined(__DragonFly__)
return &context->uc_sigmask;
#elif defined (__OpenBSD__)
return &context->sc_mask;
Expand Down Expand Up @@ -494,6 +503,58 @@ futex_wake(int *lock_word, int n)
#endif
#endif /* __FreeBSD__ */

#ifdef __DragonFly__
static void dragonfly_init()
{
#ifdef LISP_FEATURE_X86
size_t len;
int instruction_sse;

len = sizeof(instruction_sse);
if (sysctlbyname("hw.instruction_sse", &instruction_sse, &len,
NULL, 0) == 0 && instruction_sse != 0) {
/* Use the SSE detector */
fast_bzero_pointer = fast_bzero_detect;
}
#endif /* LISP_FEATURE_X86 */
}


#if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_SB_FUTEX) \
&& !defined(LISP_FEATURE_SB_PTHREAD_FUTEX)
int
futex_wait(int *lock_word, long oldval, long sec, unsigned long usec)
{
int ret;

if (sec < 0)
ret = umtx_sleep(lock_word, oldval, 0);
else {
int count = usec + 1000000 * sec;
ret = umtx_sleep(lock_word, oldval, count);
}

if (ret == 0) return 0;
else {
switch (errno) {
case EWOULDBLOCK: // Operation timed out
return 1;
case EINTR:
return 2;
default: // Such as EINVAL or EBUSY
return -1;
}
}
}

int
futex_wake(int *lock_word, int n)
{
return umtx_wakeup(lock_word, n);
}
#endif
#endif /* __DragonFly__ */

#ifdef LISP_FEATURE_DARWIN
/* defined in ppc-darwin-os.c instead */
#elif defined(LISP_FEATURE_FREEBSD)
Expand Down Expand Up @@ -532,6 +593,20 @@ os_get_runtime_executable_path(int external)
return NULL;
return copied_string(path);
}
#elif defined(LISP_FEATURE_DRAGONFLY)
char *
os_get_runtime_executable_path(int external)
{
char path[PATH_MAX + 1];
int size = readlink("/proc/curproc/file", path, sizeof(path) - 1);
if (size < 0)
return NULL;
path[size] = '\0';

if (strcmp(path, "unknown") == 0)
return NULL;
return copied_string(path);
}
#elif defined(LISP_FEATURE_NETBSD) || defined(LISP_FEATURE_OPENBSD)
char *
os_get_runtime_executable_path(int external)
Expand All @@ -541,7 +616,7 @@ os_get_runtime_executable_path(int external)
return copied_string("/proc/curproc/file");
return NULL;
}
#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD */
#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD or DragonFly */
char *
os_get_runtime_executable_path(int external)
{
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/bsd-os.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ extern int sig_memory_fault;

#define SIG_STOP_FOR_GC (SIGUSR2)

#elif defined __DragonFly__

#include <sys/ucontext.h>
typedef ucontext_t os_context_t;

#define SIG_MEMORY_FAULT (SIGSEGV)
#define SIG_STOP_FOR_GC (SIGUSR2)

#elif defined __OpenBSD__

typedef struct sigcontext os_context_t;
Expand Down
Loading

0 comments on commit c06b8c1

Please sign in to comment.