f1669d6ccaed9b0bb5146eeb785bcc0c437c8196
[sbcl.git] / src / runtime / bsd-os.h
1 /*
2  * This software is part of the SBCL system. See the README file for
3  * more information.
4  *
5  * This software is derived from the CMU CL system, which was
6  * written at Carnegie Mellon University and released into the
7  * public domain. The software is in the public domain and is
8  * provided with absolutely no warranty. See the COPYING and CREDITS
9  * files for more information.
10  */
11
12 #ifdef __FreeBSD__
13 #include <osreldate.h>
14 #endif
15
16 #include <sys/types.h>
17 #include <sys/mman.h>
18 #include <sys/signal.h>
19
20 #ifdef LISP_FEATURE_DARWIN
21 #include <mach/mach_types.h>
22 #endif
23
24 typedef caddr_t os_vm_address_t;
25 #if defined __NetBSD__
26 typedef vsize_t os_vm_size_t;
27 #elif defined __OpenBSD__
28 typedef size_t os_vm_size_t;
29 #else
30 typedef vm_size_t os_vm_size_t;
31 #endif
32 typedef off_t os_vm_offset_t;
33 typedef int os_vm_prot_t;
34
35 #if defined __OpenBSD__
36 /* name defined for compatibility between OpenBSD 3.1 sigaltstack(2) and
37  * Linux sigaltstack(2) */
38 typedef struct sigaltstack stack_t;
39 #elif defined __FreeBSD__
40 /* FreeBSD 4.6 and NetBSD 1.6 already have stack_t defined. */
41 #endif
42
43 #if defined __FreeBSD__
44 /* Note: The man page for sigaction(2) in FreeBSD 4.0 says that this
45  * is an mcontext_t, but according to comments by Raymond Wiker in the
46  * original FreeBSD port of SBCL, that's wrong, it's actually a
47  * ucontext_t. */
48
49 #include <sys/ucontext.h>
50 typedef ucontext_t os_context_t;
51 /* As the sbcl-devel message from Raymond Wiker 2000-12-01, FreeBSD
52  * (unlike Linux and OpenBSD) doesn't let us tweak the CPU's single
53  * step flag bit by messing with the flags stored in a signal context,
54  * so we need to implement single stepping in a more roundabout way. */
55 #define CANNOT_GET_TO_SINGLE_STEP_FLAG
56 /* Sometime in late 2005 FreeBSD was changed to signal SIGSEGV instead
57  * of SIGBUS for memory faults, as required by POSIX. In order to
58  * support both new and old FreeBSD at the same time, both signals are
59  * hooked to the GC write barrier machinery. If you're reading this
60  * message in the far future where FreeBSD 6 and earlier are just
61  * quaint memories, feel free to delete this hack (and any code that's
62  * #ifdef SIG_MEMORY_FAULT2'ed). -- JES, 2005-12-30
63  */
64 /* Hooking both SIGBUS and SIGSEGV causes troubles on some situation,
65  * so use a variable.
66  */
67 extern int sig_memory_fault;
68 #define SIG_MEMORY_FAULT (sig_memory_fault)
69
70 #define SIG_INTERRUPT_THREAD (SIGINFO)
71 #define SIG_STOP_FOR_GC (SIGUSR1)
72 #define SIG_RESUME_FROM_GC (SIGUSR2)
73
74 #elif defined __OpenBSD__
75
76 typedef struct sigcontext os_context_t;
77 #define SIG_MEMORY_FAULT SIGSEGV
78
79 #elif defined __NetBSD__
80
81 #include <ucontext.h>
82 typedef ucontext_t os_context_t;
83 #define SIG_MEMORY_FAULT SIGSEGV
84
85 #elif defined LISP_FEATURE_DARWIN
86 #include "darwin-os.h"
87 #else
88 #error unsupported BSD variant
89 #endif
90
91 #include "target-arch-os.h"
92 #include "target-arch.h"
93
94 #define OS_VM_PROT_READ PROT_READ
95 #define OS_VM_PROT_WRITE PROT_WRITE
96 #define OS_VM_PROT_EXECUTE PROT_EXEC