Port to x86-64 versions of Windows
[sbcl.git] / src / runtime / funcall.c
1 /* funcall0 -- funcall3: we can get by with just two sets of these:
2  * for platforms where the control stack is the C-stack, and all others.
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15
16 #include <stdio.h>
17
18 #include "sbcl.h"
19 #include "runtime.h"
20 #include "globals.h"
21 #include "os.h"
22 #include "interrupt.h"
23
24 /* This is implemented in assembly language and called from C: */
25 extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs)
26 #ifdef LISP_FEATURE_X86_64
27     __attribute__((sysv_abi))
28 #endif
29     ;
30
31 static inline lispobj
32 safe_call_into_lisp(lispobj fun, lispobj *args, int nargs)
33 {
34 #ifndef LISP_FEATURE_SB_SAFEPOINT
35     /* SIG_STOP_FOR_GC needs to be enabled before we can call lisp:
36      * otherwise two threads racing here may deadlock: the other will
37      * wait on the GC lock, and the other cannot stop the first
38      * one... */
39     check_gc_signals_unblocked_or_lose(0);
40 #endif
41     return call_into_lisp(fun, args, nargs);
42 }
43
44 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
45 /* These functions are an interface to the Lisp call-in facility.
46  * Since this is C we can know nothing about the calling environment.
47  * The control stack might be the C stack if called from the monitor
48  * or the Lisp stack if called as a result of an interrupt or maybe
49  * even a separate stack. The args are most likely on that stack but
50  * could be in registers depending on what the compiler likes. So we
51  * copy the args into a portable vector and let the assembly language
52  * call-in function figure it out. */
53
54 lispobj
55 funcall0(lispobj function)
56 {
57     lispobj *args = NULL;
58
59     FSHOW((stderr, "/entering funcall0(0x%lx)\n", (long)function));
60     return safe_call_into_lisp(function, args, 0);
61 }
62 lispobj
63 funcall1(lispobj function, lispobj arg0)
64 {
65     lispobj args[1];
66     args[0] = arg0;
67     return safe_call_into_lisp(function, args, 1);
68 }
69
70 lispobj
71 funcall2(lispobj function, lispobj arg0, lispobj arg1)
72 {
73     lispobj args[2];
74     args[0] = arg0;
75     args[1] = arg1;
76     return safe_call_into_lisp(function, args, 2);
77 }
78
79 lispobj
80 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
81 {
82     lispobj args[3];
83     args[0] = arg0;
84     args[1] = arg1;
85     args[2] = arg2;
86     return safe_call_into_lisp(function, args, 3);
87 }
88
89 #else
90
91 lispobj
92 funcall0(lispobj function)
93 {
94     lispobj **stack_pointer
95         = &access_control_stack_pointer(arch_os_get_current_thread());
96     lispobj *args = *stack_pointer;
97
98     return safe_call_into_lisp(function, args, 0);
99 }
100
101 lispobj
102 funcall1(lispobj function, lispobj arg0)
103 {
104     lispobj **stack_pointer
105         = &access_control_stack_pointer(arch_os_get_current_thread());
106     lispobj *args = *stack_pointer;
107
108     *stack_pointer += 1;
109     args[0] = arg0;
110
111     return safe_call_into_lisp(function, args, 1);
112 }
113
114 lispobj
115 funcall2(lispobj function, lispobj arg0, lispobj arg1)
116 {
117     lispobj **stack_pointer
118         = &access_control_stack_pointer(arch_os_get_current_thread());
119     lispobj *args = *stack_pointer;
120
121     *stack_pointer += 2;
122     args[0] = arg0;
123     args[1] = arg1;
124
125     return safe_call_into_lisp(function, args, 2);
126 }
127
128 lispobj
129 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
130 {
131     lispobj **stack_pointer
132         = &access_control_stack_pointer(arch_os_get_current_thread());
133     lispobj *args = *stack_pointer;
134
135     *stack_pointer += 3;
136     args[0] = arg0;
137     args[1] = arg1;
138     args[2] = arg2;
139
140     return safe_call_into_lisp(function, args, 3);
141 }
142 #endif