> Why would you build SBCL to only do single threaded applications?
Because multithreading is not easy in SBCL. Currently, I have no idea how
to implement it. For all other platforms -lpthread is used only for
multithreaded SBCL (see sbcl-source/src/runtime/Config.x86-64-freebsd for
example).
It is strange to supply -lpthread to single threaded app just to avoid some
bugs, is it not? But I've already done it as a temporal (I hope!) solution.
> or did I misunderstand and the executable built by the SBCL compiler has
to be linked with pthread and not the compiler itself?
No. pthread is being loaded indirectly via rtld when user (programmer)
wants to load any library depending on it. In case of IOLib, SBCL
loads(with dlopen) libfixposix which is linked against pthread.
Just to clear the situation: no, I do not want to save the linker from
loading pthreads, and, yes, it would be nice to prevent libthread_xu from
allocating the stack guard page for main thread twice.
> please provide all the patches you are using (including this -pthread
addition when you figure it out)
Sure. Build it with "sh make.sh --xc-host=clisp". Do not forget to run all
tests: "cd tests && sh run-tests.sh". They must pass, but it will be better
to doublecheck. I attach the patch as a single file, will that do?
2014-04-16 17:37 GMT+04:00 John Marino <[email protected]>:
> On 4/16/2014 15:17, Vasily Postnicov wrote:
>
> > I don't know. Anyway, why user should care? Imagine that I'm trying to
> > unload not pthread itself (which, of course, I must not do), but a
> > random library foo.so, which depends on pthreads indirectly. So why it
> > must break otherwise working application? Especially if it is not
> > multithreaded?
>
> I don't get why this matters. Your problem has been solved. Build the
> executable with -pthread and the issue goes away. Why would you build
> SBCL to only do single threaded applications? That doesn't make sense
> to me. You build it with -pthread, then it can do both single and
> multithread. Are you trying to save the dynamic linker from loading
> pthread library?
>
> or did I misunderstand and the executable built by the SBCL compiler has
> to be linked with pthread and not the compiler itself?
>
>
> > And adding -lpthread to SBCL is not necessary if it is not
> > multithreaded. It's just a hack which prevents unloading of libthread_xu
> > by keeping its reference counter above zero.
> >
> > So I am not telling that I found a bug, I am just asking is this
> > behaviour OK? I think it is not.
>
> yes, why not?
> It's the first time any kind of issue has come it, and it's probably
> related to how SBCL was designed, so it seems pretty application
> specific, not a general problem. At least to me, given only what I've
> skimmed on this list.
>
> If you want SBCL on DragonFly, please provide all the patches you are
> using (including this -pthread addition when you figure it out) or
> submit them to upstream and we'll eventually get them from ports.
>
> Thanks,
> John
>
diff --git a/TODO b/TODO
index 6c8d83b..e93e629 100644
--- a/TODO
+++ b/TODO
@@ -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.
diff --git a/base-target-features.lisp-expr b/base-target-features.lisp-expr
index e469fda..e972470 100644
--- a/base-target-features.lisp-expr
+++ b/base-target-features.lisp-expr
@@ -442,23 +442,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.)
diff --git a/contrib/asdf/asdf.lisp b/contrib/asdf/asdf.lisp
index e90fae7..49e1d5b 100644
--- a/contrib/asdf/asdf.lisp
+++ b/contrib/asdf/asdf.lisp
@@ -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 ()
diff --git a/contrib/sb-bsd-sockets/constants.lisp b/contrib/sb-bsd-sockets/constants.lisp
index de0e2e8..ba3c221 100644
--- a/contrib/sb-bsd-sockets/constants.lisp
+++ b/contrib/sb-bsd-sockets/constants.lisp
@@ -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")
diff --git a/contrib/sb-bsd-sockets/tests.lisp b/contrib/sb-bsd-sockets/tests.lisp
index d10a31b..89839d5 100644
--- a/contrib/sb-bsd-sockets/tests.lisp
+++ b/contrib/sb-bsd-sockets/tests.lisp
@@ -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 ()
diff --git a/contrib/sb-sprof/test.lisp b/contrib/sb-sprof/test.lisp
index ed49cf7..baaa6d5 100644
--- a/contrib/sb-sprof/test.lisp
+++ b/contrib/sb-sprof/test.lisp
@@ -38,7 +38,7 @@
#-(or win32 darwin) ;not yet
(test)
-#-(or win32 darwin) ;not yet
+#-(or win32 darwin freebsd) ;not yet
(consing-test)
;; For debugging purposes, print output for visual inspection to see if
diff --git a/make-config.sh b/make-config.sh
index fe67983..24e623d 100755
--- a/make-config.sh
+++ b/make-config.sh
@@ -277,6 +277,9 @@ case `uname` in
;;
esac
;;
+ DragonFly)
+ sbcl_os="dragonfly"
+ ;;
Darwin)
sbcl_os="darwin"
;;
@@ -385,7 +388,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
@@ -499,6 +503,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
@@ -584,7 +601,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
diff --git a/src/code/run-program.lisp b/src/code/run-program.lisp
index a194917..13c82c5 100644
--- a/src/code/run-program.lisp
+++ b/src/code/run-program.lisp
@@ -405,7 +405,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))
@@ -457,7 +457,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)))
diff --git a/src/code/unix.lisp b/src/code/unix.lisp
index 81d7f99..d6056ca 100644
--- a/src/code/unix.lisp
+++ b/src/code/unix.lisp
@@ -385,15 +385,15 @@ 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 linux openbsd freebsd netbsd sunos osf1 darwin hpux win32)
+ #!-(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly)
#.(error "POSIX-GETCWD is not implemented.")
- #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32)
+ #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly)
(or (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))
(simple-perror "getcwd")))
diff --git a/src/cold/shared.lisp b/src/cold/shared.lisp
index 479b426..203795e 100644
--- a/src/cold/shared.lisp
+++ b/src/cold/shared.lisp
@@ -173,7 +173,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*))
diff --git a/src/compiler/x86/parms.lisp b/src/compiler/x86/parms.lisp
index 75d2345..15a37ba 100644
--- a/src/compiler/x86/parms.lisp
+++ b/src/compiler/x86/parms.lisp
@@ -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)
diff --git a/src/runtime/Config.x86-64-dragonfly b/src/runtime/Config.x86-64-dragonfly
new file mode 100644
index 0000000..c8cf688
--- /dev/null
+++ b/src/runtime/Config.x86-64-dragonfly
@@ -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
diff --git a/src/runtime/Config.x86-dragonfly b/src/runtime/Config.x86-dragonfly
new file mode 100644
index 0000000..03b3598
--- /dev/null
+++ b/src/runtime/Config.x86-dragonfly
@@ -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
diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c
index 4c08b97..d308d9b 100644
--- a/src/runtime/bsd-os.c
+++ b/src/runtime/bsd-os.c
@@ -72,6 +72,12 @@ static void netbsd_init();
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>
@@ -98,6 +104,8 @@ os_init(char *argv[], char *envp[])
openbsd_init();
#elif defined(LISP_FEATURE_DARWIN)
darwin_init();
+#elif defined(__DragonFly__)
+ dragonfly_init();
#endif
}
@@ -107,7 +115,7 @@ 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(__FreeBSD__) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__)
return &context->uc_sigmask;
#elif defined (__OpenBSD__)
return &context->sc_mask;
@@ -444,6 +452,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)
@@ -478,6 +538,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)
@@ -487,7 +561,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)
{
diff --git a/src/runtime/bsd-os.h b/src/runtime/bsd-os.h
index 880c5f7..61aaf0e 100644
--- a/src/runtime/bsd-os.h
+++ b/src/runtime/bsd-os.h
@@ -9,7 +9,7 @@
* files for more information.
*/
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <osreldate.h>
#endif
@@ -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;
diff --git a/src/runtime/monitor.c b/src/runtime/monitor.c
index 75c4119..e5ed098 100644
--- a/src/runtime/monitor.c
+++ b/src/runtime/monitor.c
@@ -138,7 +138,7 @@ dump_cmd(char **ptr)
while (count-- > 0) {
#ifndef LISP_FEATURE_ALPHA
- printf("0x%p: ", (os_vm_address_t) addr);
+ printf("%p: ", (os_vm_address_t) addr);
#else
printf("0x%08X: ", (u32) addr);
#endif
@@ -199,13 +199,13 @@ regs_cmd(char **ptr)
{
struct thread *thread=arch_os_get_current_thread();
- printf("CSP\t=\t0x%p ", access_control_stack_pointer(thread));
+ printf("CSP\t=\t0x%08lx ", (unsigned long)access_control_stack_pointer(thread));
#if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
- printf("CFP\t=\t0x%p ", access_control_frame_pointer(thread));
+ printf("CFP\t=\t0x%08lx ", (unsigned long)access_control_frame_pointer(thread));
#endif
#ifdef reg_BSP
- printf("BSP\t=\t0x%p\n", get_binding_stack_pointer(thread));
+ printf("BSP\t=\t0x%08lx\n", (unsigned long)get_binding_stack_pointer(thread));
#else
/* printf("BSP\t=\t0x%08lx\n",
(unsigned long)SymbolValue(BINDING_STACK_POINTER)); */
@@ -215,8 +215,8 @@ regs_cmd(char **ptr)
#ifdef LISP_FEATURE_GENCGC
/* printf("DYNAMIC\t=\t0x%08lx\n", DYNAMIC_SPACE_START); */
#else
- printf("STATIC\t=\t0x%p ",
- SymbolValue(STATIC_SPACE_FREE_POINTER, thread));
+ printf("STATIC\t=\t0x%08lx ",
+ (unsigned long)SymbolValue(STATIC_SPACE_FREE_POINTER, thread));
printf("RDONLY\t=\t0x%08lx ",
(unsigned long)SymbolValue(READ_ONLY_SPACE_FREE_POINTER, thread));
printf("DYNAMIC\t=\t0x%08lx\n", (unsigned long)current_dynamic_space);
@@ -275,10 +275,10 @@ search_cmd(char **ptr)
start = end = addr;
lastcount = count;
- printf("searching for 0x%x at 0x%p\n", val, (void*)(uword_t)end);
+ printf("searching for 0x%x at 0x%08lx\n", val, (uword_t)end);
while (search_for_type(val, &end, &count)) {
- printf("found 0x%x at 0x%p:\n", val, (void*)(uword_t)end);
+ printf("found 0x%x at 0x%08lx:\n", val, (uword_t)end);
obj = *end;
addr = end;
end += 2;
diff --git a/src/runtime/pthread-futex.c b/src/runtime/pthread-futex.c
index cddcda9..209480c 100644
--- a/src/runtime/pthread-futex.c
+++ b/src/runtime/pthread-futex.c
@@ -279,7 +279,7 @@ again:
* emulate this behaviour. */
sigpending(&pendset);
for (i = 1; i < NSIG; i++) {
- if (sigismember(&pendset, i) && sigismember(&newset, i)) {
+ if (sigismember(&pendset, i) && sigismember(&oldset, i)) {
result = EINTR;
goto done;
}
diff --git a/src/runtime/thread.c b/src/runtime/thread.c
index 34f1d62..e1d5b23 100644
--- a/src/runtime/thread.c
+++ b/src/runtime/thread.c
@@ -58,8 +58,8 @@
#define LOCK_CREATE_THREAD
#endif
-#ifdef LISP_FEATURE_FREEBSD
-#define CREATE_CLEANUP_THREAD
+#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
+#define CREATE_POST_MORTEM_THREAD
#define LOCK_CREATE_THREAD
#endif
@@ -337,6 +337,7 @@ schedule_thread_post_mortem(struct thread *corpse)
/* Finally run, the cleanup, if any. */
perform_thread_post_mortem(post_mortem);
#elif defined(CREATE_POST_MORTEM_THREAD)
+ pthread_t thread;
gc_assert(!pthread_create(&thread, NULL, perform_thread_post_mortem, post_mortem));
#else
post_mortem = (struct thread_post_mortem *)
diff --git a/src/runtime/undefineds.h b/src/runtime/undefineds.h
index b1cb325..024b565 100644
--- a/src/runtime/undefineds.h
+++ b/src/runtime/undefineds.h
@@ -39,7 +39,8 @@ F(brk)
|| defined(SVR4) \
|| defined(__FreeBSD__) \
|| defined(__OpenBSD__) \
- || defined(__NetBSD__)
+ || defined(__NetBSD__) \
+ || defined(__DragonFly__)
F(cfgetospeed)
F(cfsetospeed)
F(cfgetispeed)
@@ -154,7 +155,7 @@ F(sigreturn)
#if !defined(SVR4)
F(sigsetmask)
#endif
-#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
F(sigstack)
F(sigvec)
#endif
@@ -180,6 +181,7 @@ F(readdir)
|| defined(__FreeBSD__) \
|| defined(__OpenBSD__) \
|| defined(__NetBSD__) \
+ || defined(__DragonFly__) \
|| defined(__linux__)
F(tcgetattr)
F(tcsetattr)
@@ -198,6 +200,7 @@ F(umask)
&& !defined(SOLARIS) \
&& !defined(__OpenBSD__) \
&& !defined(__FreeBSD__) \
+ && !defined(__DragonFly__) \
&& !defined(__NetBSD__)
F(umount)
#endif
@@ -208,7 +211,7 @@ F(utimes)
#ifndef irix
F(vfork)
#endif
-#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
F(vhangup)
#endif
F(wait)
diff --git a/src/runtime/x86-64-arch.c b/src/runtime/x86-64-arch.c
index 573dc7e..ade1367 100644
--- a/src/runtime/x86-64-arch.c
+++ b/src/runtime/x86-64-arch.c
@@ -68,7 +68,7 @@ context_eflags_addr(os_context_t *context)
* we need to do this nasty absolute index magic number thing
* instead. */
return &context->uc_mcontext.gregs[17];
-#elif defined __FreeBSD__
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
return &context->uc_mcontext.mc_rflags;
#elif defined LISP_FEATURE_DARWIN
return CONTEXT_ADDR_FROM_STEM(rflags);
diff --git a/src/runtime/x86-64-assem.S b/src/runtime/x86-64-assem.S
index d19855c..22c3124 100644
--- a/src/runtime/x86-64-assem.S
+++ b/src/runtime/x86-64-assem.S
@@ -25,7 +25,7 @@
#include "genesis/thread.h"
/* Minimize conditionalization for different OS naming schemes. */
-#if defined __linux__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64
+#if defined __linux__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64 || defined __DragonFly__
#define GNAME(var) var
#else
#define GNAME(var) _##var
@@ -33,7 +33,7 @@
/* Get the right type of alignment. Linux, FreeBSD and OpenBSD
* want alignment in bytes. */
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64 || defined(__DragonFly__)
#define align_4byte 4
#define align_8byte 8
#define align_16byte 16
diff --git a/src/runtime/x86-64-bsd-os.c b/src/runtime/x86-64-bsd-os.c
index 3d9a9c7..b394118 100644
--- a/src/runtime/x86-64-bsd-os.c
+++ b/src/runtime/x86-64-bsd-os.c
@@ -12,6 +12,10 @@
#include <machine/fpu.h>
#endif
+#if defined(LISP_FEATURE_DRAGONFLY)
+#include <machine/npx.h>
+#endif
+
/* KLUDGE: There is strong family resemblance in the signal context
* stuff in FreeBSD and OpenBSD, but in detail they're different in
* almost every line of code. It would be nice to find some way to
@@ -23,7 +27,7 @@
* entails; unfortunately, currently the situation is worse, not
* better, than in the above paragraph. */
-#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD)
+#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY)
os_context_register_t *
os_context_register_addr(os_context_t *context, int offset)
{
@@ -168,6 +172,19 @@ int arch_os_thread_cleanup(struct thread *thread) {
return 1; /* success */
}
+#if defined(LISP_FEATURE_DRAGONFLY)
+void
+os_restore_fp_control(os_context_t *context)
+{
+ struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpregs);
+ /* reset exception flags and restore control flags on SSE2 FPU */
+ unsigned int temp = (ex->en_mxcsr) & ~0x3F;
+ asm ("ldmxcsr %0" : : "m" (temp));
+ /* same for x87 FPU. */
+ asm ("fldcw %0" : : "m" (ex->en_cw));
+}
+#endif
+
#if defined(LISP_FEATURE_FREEBSD)
void
os_restore_fp_control(os_context_t *context)
diff --git a/src/runtime/x86-64-bsd-os.h b/src/runtime/x86-64-bsd-os.h
index 9db3ae7..2c960c9 100644
--- a/src/runtime/x86-64-bsd-os.h
+++ b/src/runtime/x86-64-bsd-os.h
@@ -5,6 +5,10 @@
#include <machine/fpu.h>
#endif
+#ifdef LISP_FEATURE_DRAGONFLY
+#include <machine/npx.h>
+#endif
+
typedef register_t os_context_register_t;
static inline os_context_t *arch_os_get_context(void **void_context)
@@ -16,7 +20,7 @@ static inline os_context_t *arch_os_get_context(void **void_context)
* store signal context information, but at least they tend to use the
* same stems to name the structure fields, so by using this macro we
* can share a fair amount of code between different variants. */
-#if defined __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
#define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem
#elif defined(__OpenBSD__)
#define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem
@@ -26,6 +30,24 @@ static inline os_context_t *arch_os_get_context(void **void_context)
#error unsupported BSD variant
#endif
+#if defined LISP_FEATURE_DRAGONFLY
+/* I am not sure if following definition is needed after this:
+ http://gitweb.dragonflybsd.org/dragonfly.git/commit/e6e019a801e99ba7888ed009c5c3b3c7b047af1e
+
+ But It will not harm if I leave it here. */
+#define RESTORE_FP_CONTROL_FROM_CONTEXT
+void os_restore_fp_control(os_context_t *context);
+
+#define X86_64_SIGFPE_FIXUP
+
+static inline unsigned int *
+arch_os_context_mxcsr_addr(os_context_t *context)
+{
+ struct envxmm *ex = (struct envxmm *)(&context->uc_mcontext.mc_fpregs);
+ return &ex->en_mxcsr;
+}
+#endif
+
#if defined LISP_FEATURE_FREEBSD
#define RESTORE_FP_CONTROL_FROM_CONTEXT
void os_restore_fp_control(os_context_t *context);
diff --git a/src/runtime/x86-arch.c b/src/runtime/x86-arch.c
index d00f26b..3692625 100644
--- a/src/runtime/x86-arch.c
+++ b/src/runtime/x86-arch.c
@@ -66,7 +66,7 @@ context_eflags_addr(os_context_t *context)
* we need to do this nasty absolute index magic number thing
* instead. */
return &context->uc_mcontext.gregs[16];
-#elif defined __FreeBSD__
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
return &context->uc_mcontext.mc_eflags;
#elif defined __OpenBSD__
return &context->sc_eflags;
diff --git a/src/runtime/x86-assem.S b/src/runtime/x86-assem.S
index 1cfa64b..0d90d60 100644
--- a/src/runtime/x86-assem.S
+++ b/src/runtime/x86-assem.S
@@ -32,7 +32,7 @@
*
* (Except Win32, which is unlikely ever to be ELF, sorry. -- AB 2005-12-08)
*/
-#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun
+#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun || defined __DragonFly__
#define GNAME(var) var
#else
#define GNAME(var) _##var
@@ -47,7 +47,7 @@
* matter any more, perhaps it's just clutter we could get
* rid of? -- WHN 2004-04-18)
*/
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32) || defined(__Dragonfly__)
#define align_4byte 4
#define align_8byte 8
#define align_16byte 16
@@ -131,7 +131,7 @@
# define LoadCurrentThreadSlot(offset,reg); \
movl SBCL_THREAD_BASE_EA, reg ; \
movl offset(reg), reg ;
-#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD)
+#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
/* see comment in arch_os_thread_init */
# define SBCL_THREAD_BASE_EA %fs:THREAD_SELFPTR_OFFSET
# define MAYBE_FS(addr) addr
diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c
index fe75566..4f985fe 100644
--- a/src/runtime/x86-bsd-os.c
+++ b/src/runtime/x86-bsd-os.c
@@ -16,7 +16,7 @@
#endif /* LISP_FEATURE_DARWIN */
#endif
-#if defined(LISP_FEATURE_FREEBSD)
+#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
#include "machine/npx.h"
#endif
@@ -40,7 +40,7 @@
* entails; unfortunately, currently the situation is worse, not
* better, than in the above paragraph. */
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__)
int *
os_context_register_addr(os_context_t *context, int offset)
{
@@ -72,7 +72,7 @@ os_context_sp_addr(os_context_t *context)
return (int *)CONTEXT_ADDR_FROM_STEM(esp);
}
-#endif /* __FreeBSD__ || __OpenBSD__ */
+#endif /* __FreeBSD__ || __OpenBSD__ || __DragonFly__ */
#ifdef __NetBSD__
int *
@@ -112,7 +112,7 @@ os_context_sp_addr(os_context_t *context)
int *os_context_pc_addr(os_context_t *context)
{
-#if defined __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
return CONTEXT_ADDR_FROM_STEM(eip);
#elif defined __OpenBSD__
return CONTEXT_ADDR_FROM_STEM(pc);
@@ -264,6 +264,14 @@ os_restore_fp_control(os_context_t *context)
}
#endif
+#if defined(LISP_FEATURE_DRAGONFLY)
+void os_restore_fp_control (os_context_t *context)
+{
+ struct envxmm *ex = (struct envxmm *)(context->uc_mcontext.mc_fpregs);
+ __asm__ __volatile__ ("fldcw %0" : : "m" (ex->en_cw));
+}
+#endif /* LISP_FEATURE_DRAGONFLY */
+
#if defined(LISP_FEATURE_OPENBSD)
void
os_restore_fp_control(os_context_t *context)
diff --git a/src/runtime/x86-bsd-os.h b/src/runtime/x86-bsd-os.h
index dc9d9f7..5b90b39 100644
--- a/src/runtime/x86-bsd-os.h
+++ b/src/runtime/x86-bsd-os.h
@@ -1,7 +1,7 @@
#ifndef _X86_BSD_OS_H
#define _X86_BSD_OS_H
-#ifdef LISP_FEATURE_FREEBSD
+#if defined(LISP_FEATURE_FREEBSD)
#include <machine/segments.h>
#include <machine/cpufunc.h>
#endif
@@ -17,7 +17,7 @@ static inline os_context_t *arch_os_get_context(void **void_context)
* store signal context information, but at least they tend to use the
* same stems to name the structure fields, so by using this macro we
* can share a fair amount of code between different variants. */
-#if defined __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
#define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem
#elif defined(__OpenBSD__)
#define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem
@@ -35,7 +35,7 @@ void os_restore_tls_segment_register(os_context_t *context);
void os_restore_fp_control(os_context_t *context);
#endif
-#if defined LISP_FEATURE_OPENBSD
+#if defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY)
#define RESTORE_FP_CONTROL_FROM_CONTEXT
void os_restore_fp_control(os_context_t *context);
#endif
diff --git a/tests/run-compiler.sh b/tests/run-compiler.sh
index fbe1930..a281d19 100755
--- a/tests/run-compiler.sh
+++ b/tests/run-compiler.sh
@@ -37,6 +37,8 @@ while [ $# -gt 0 ]; do
SunOS-SPARC) new=-fPIC ;;
SunOS-X86) new=-fPIC ;;
SunOS-X86-64) new=-fPIC ;;
+ DragonFly-X86-64)new=-fPIC ;;
+ DragonFly-X84) new=-fPIC ;;
esac
;;
diff --git a/tools-for-build/ldso-stubs.lisp b/tools-for-build/ldso-stubs.lisp
index 8cdfc6a..24dd15f 100644
--- a/tools-for-build/ldso-stubs.lisp
+++ b/tools-for-build/ldso-stubs.lisp
@@ -325,7 +325,7 @@ ldso_stub__ ## fct: ; \\
'("ptsname"
"grantpt"
"unlockpt")
- #!+(or openbsd freebsd)
+ #!+(or openbsd freebsd dragonfly)
'("openpty")
'("dlclose"
"dlerror"