Better error when calling an undefined alien function on x86-64.
[sbcl.git] / src / compiler / generic / parms.lisp
1 ;;;; This file contains some parameterizations of various VM
2 ;;;; attributes common to all architectures.
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!VM")
14
15 (def!macro !configure-dynamic-space-end (&optional default)
16   (with-open-file (f "output/dynamic-space-size.txt")
17     (let ((line (read-line f)))
18       (multiple-value-bind (number end)
19           (parse-integer line :junk-allowed t)
20         (if number
21             (let* ((ext (subseq line end))
22                    (mult (cond ((or (zerop (length ext))
23                                     (member ext '("MB MIB") :test #'equalp))
24                                 (expt 2 20))
25                                ((member ext '("GB" "GIB") :test #'equalp)
26                                 (expt 2 30))
27                                (t
28                                 (error "Invalid --dynamic-space-size=~A" line)))))
29               `(+ dynamic-space-start ,(* number mult)))
30             (or default
31                 `(+ dynamic-space-start
32                     (ecase n-word-bits
33                       (32 (expt 2 29))
34                       (64 (expt 2 30))))))))))
35
36 #!+gencgc
37 ;; Define START/END constants for GENCGC spaces.
38 ;; Assumptions:
39 ;;     We only need very small read-only and static spaces, because
40 ;;     gencgc does not purify any more.  We can count on being able to
41 ;;     allocate them with roughly the same size, and next to each other.
42 ;;
43 ;;     There is one page of unmapped buffer between them for good measure.
44 ;;
45 ;;     The linkage table (if enabled) can be treated the same way.
46 ;;
47 ;;     Dynamic space traditionally sits elsewhere, so has its own
48 ;;     parameter.  But if not specified, it is allocated right after
49 ;;     the other spaces (used on Windows/x86).
50 ;;
51 ;;     The safepoint page (if enabled) is to be allocated immediately
52 ;;     prior to static page.  For x86(-64) this would not matter, because
53 ;;     they can only reference it using an absolute fixup anyway, but
54 ;;     for RISC platforms we can (and must) do better.
55 ;;
56 ;;     The safepoint page needs to be small enough that the offset from
57 ;;     static space is immediate, e.g. >= -2^12 for SPARC.  #x1000 works
58 ;;     for almost all platforms, but is too small to make VirtualProtect
59 ;;     happy -- hence the need for an extra `alignment' configuration
60 ;;     option below, which parms.lisp can set to #x10000 on Windows.
61 ;;
62 ;; Cosmetic problem:
63 ;;
64 ;;     In the interest of readability, &KEY would be much nicer than
65 ;;     &OPTIONAL.  But is it possible to use keyword arguments to
66 ;;     DEF!MACRO?
67 ;;
68 (def!macro !gencgc-space-setup
69     (small-spaces-start
70      &optional dynamic-space-start*
71                default-dynamic-space-size
72                ;; Smallest os_validate()able alignment; used as safepoint
73                ;; page size.  Default suitable for POSIX platforms.
74                (alignment            #x1000)
75                ;; traditional distance between spaces -- including the margin:
76                (small-space-spread #x100000)
77                ;; traditional margin between spaces
78                (margin-size          #x1000))
79   (let* ((spaces '(read-only static #!+linkage-table linkage-table))
80          (ptr small-spaces-start)
81          safepoint-address
82          (small-space-forms
83           (loop for (space next-space) on spaces appending
84                 (let* ((next-start (+ ptr small-space-spread))
85                        (end next-start))
86                   (when (eq next-space 'static)
87                     ;; margin becomes safepoint page; substract margin again.
88                     (decf end alignment)
89                     (setf safepoint-address end))
90                   (prog1
91                       `((def!constant ,(symbolicate space "-SPACE-START")
92                             ,ptr)
93                         (def!constant ,(symbolicate space "-SPACE-END")
94                             ,(- end margin-size)))
95                     (setf ptr next-start)))))
96          (safepoint-page-forms
97           (list #!+sb-safepoint
98                 `(def!constant gc-safepoint-page-addr ,safepoint-address)))
99          (dynamic-space-start* (or dynamic-space-start* ptr))
100          (optional-dynamic-space-end
101           (when default-dynamic-space-size
102             (list (+ dynamic-space-start* default-dynamic-space-size)))))
103     `(progn
104        ,@safepoint-page-forms
105        ,@small-space-forms
106        (def!constant dynamic-space-start ,dynamic-space-start*)
107        (def!constant dynamic-space-end (!configure-dynamic-space-end
108                                         ,@optional-dynamic-space-end)))))
109
110 (defparameter *c-callable-static-symbols*
111   '(sub-gc
112     sb!kernel::post-gc
113     sb!kernel::internal-error
114     sb!kernel::control-stack-exhausted-error
115     sb!kernel::binding-stack-exhausted-error
116     sb!kernel::alien-stack-exhausted-error
117     sb!kernel::heap-exhausted-error
118     sb!kernel::undefined-alien-variable-error
119     sb!kernel::memory-fault-error
120     sb!kernel::unhandled-trap-error
121     ;; On x86-64 it's called through the internal errors mechanism
122     #!-x86-64 undefined-alien-fun-error
123     sb!di::handle-breakpoint
124     sb!di::handle-single-step-trap
125     fdefinition-object
126     #!+win32 sb!kernel::handle-win32-exception
127     #!+sb-thruption sb!thread::run-interruption
128     #!+sb-safepoint sb!thread::enter-foreign-callback
129     #!+(and sb-safepoint-strictly (not win32))
130     sb!unix::signal-handler-callback))
131
132 (defparameter *common-static-symbols*
133   '(t
134
135     ;; filled in by the C code to propagate to Lisp
136     *posix-argv* *core-string*
137
138     ;; free pointers.  Note that these are FIXNUM word counts, not (as
139     ;; one might expect) byte counts or SAPs. The reason seems to be
140     ;; that by representing them this way, we can avoid consing
141     ;; bignums.  -- WHN 2000-10-02
142     *read-only-space-free-pointer*
143     *static-space-free-pointer*
144
145     ;; things needed for non-local-exit
146     *current-catch-block*
147     *current-unwind-protect-block*
148
149     #!+hpux *c-lra*
150
151     ;; stack pointers
152     *binding-stack-start*
153     *control-stack-start*
154     *control-stack-end*
155
156     ;; interrupt handling
157     *alloc-signal*
158     *free-interrupt-context-index*
159     sb!unix::*allow-with-interrupts*
160     sb!unix::*interrupts-enabled*
161     sb!unix::*interrupt-pending*
162     #!+sb-thruption sb!unix::*thruption-pending*
163     #!+sb-thruption sb!impl::*restart-clusters*
164     sb!vm::*in-without-gcing*
165     *gc-inhibit*
166     *gc-pending*
167     #!-sb-thread
168     *stepping*
169     #!+sb-safepoint sb!impl::*gc-safe*
170     #!+sb-safepoint sb!impl::*in-safepoint*
171
172     ;; threading support
173     #!+sb-thread *stop-for-gc-pending*
174     #!+sb-thread *free-tls-index*
175     #!+sb-thread *tls-index-lock*
176
177     ;; dynamic runtime linking support
178     #!+sb-dynamic-core *required-runtime-c-symbols*
179     sb!kernel::*gc-epoch*
180
181     ;; Dispatch tables for generic array access
182     sb!impl::%%data-vector-reffers%%
183     sb!impl::%%data-vector-reffers/check-bounds%%
184     sb!impl::%%data-vector-setters%%
185     sb!impl::%%data-vector-setters/check-bounds%%
186
187     ;; non-x86oid gencgc object pinning
188     #!+(and gencgc (not (or x86 x86-64)))
189     *pinned-objects*
190
191     ;; hash table weaknesses
192     :key
193     :value
194     :key-and-value
195     :key-or-value))
196
197 ;;; Number of entries in the thread local storage. Limits the number
198 ;;; of symbols with thread local bindings.
199 (def!constant tls-size 4096)
200
201 #!+gencgc
202 (progn
203   (def!constant +highest-normal-generation+ 5)
204   (def!constant +pseudo-static-generation+ 6))
205
206 (defenum ()
207   trace-table-normal
208   trace-table-call-site
209   trace-table-fun-prologue
210   trace-table-fun-epilogue)