Mark :two-threads-running-gc as broken on sb-safepoint.
[sbcl.git] / tools-for-build / grovel-headers.c
blob65ff433748f5db7ca641b23276368b051cda5194
1 /*
2 * Rummage through the system header files using the C compiler itself
3 * as a parser, extracting stuff like preprocessor constants and the
4 * sizes and signedness of basic system types, and write it out as
5 * Lisp code.
6 */
8 /*
9 * This software is part of the SBCL system. See the README file for
10 * more information.
12 * While most of SBCL is derived from the CMU CL system, many
13 * utilities for the build process (like this one) were written from
14 * scratch after the fork from CMU CL.
16 * This software is in the public domain and is provided with
17 * absolutely no warranty. See the COPYING and CREDITS files for
18 * more information.
21 #include "genesis/config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #ifdef _WIN32
27 /* KLUDGE: From src/runtime/runtime.h, avoid double definition of
28 boolean. We really should clean up our act on this one. */
29 #define boolean rpcndr_boolean
30 #define WIN32_LEAN_AND_MEAN
31 #include <windows.h>
32 #include <shlobj.h>
33 #include <wincrypt.h>
34 #include <winsock2.h>
35 #undef boolean
36 #else
37 #include <poll.h>
38 #include <sys/select.h>
39 #include <sys/times.h>
40 #include <sys/wait.h>
41 #include <sys/ioctl.h>
42 #ifdef LISP_FEATURE_ANDROID
43 #include <termios.h>
44 #else
45 #include <sys/termios.h>
46 #include <langinfo.h>
47 #endif
48 #include <sys/time.h>
49 #include <dlfcn.h>
50 #endif
52 #include <sys/stat.h>
53 #include <fcntl.h>
54 #include <unistd.h>
55 #include <signal.h>
56 #include <errno.h>
57 #include <time.h>
59 #ifdef LISP_FEATURE_HPUX
60 #include <sys/bsdtty.h> /* for TIOCGPGRP */
61 #endif
63 #ifdef LISP_FEATURE_BSD
64 #include <sys/param.h>
65 #include <sys/sysctl.h>
66 #endif
68 #if defined(LISP_FEATURE_WIN32) && defined(LISP_FEATURE_SB_THREAD)
69 #include "pthreads_win32.h"
70 #endif
72 #include "wrap.h"
73 #include "gc.h"
75 #define DEFTYPE(lispname,cname) { cname foo; \
76 printf("(define-alien-type " lispname " (%s %lu))\n", \
77 (((foo=-1)<0) ? "signed" : "unsigned"), (8LU * (sizeof foo))); }
79 #define DEFSTRUCT(lispname,cname,body) { cname bar; \
80 printf("(define-alien-type nil\n (struct %s", #lispname); \
81 body; \
82 printf("))\n"); }
83 #define DEFSLOT(lispname,cname) \
84 printf("\n (%s (%s %lu))", \
85 #lispname, \
86 (((bar.cname=-1)<0) ? "signed" : "unsigned"), \
87 (8LU * (sizeof bar.cname)))
89 void
90 defconstant(char* lisp_name, unsigned long unix_number)
92 printf("(defconstant %s %lu) ; #x%lx\n",
93 lisp_name, unix_number, unix_number);
96 void deferrno(char* lisp_name, unsigned long unix_number)
98 defconstant(lisp_name, unix_number);
101 void defsignal(char* lisp_name, unsigned long unix_number)
103 defconstant(lisp_name, unix_number);
107 main(int argc, char *argv[])
109 /* don't need no steenking command line arguments */
110 if (1 != argc) {
111 fprintf(stderr, "argh! command line argument(s)\n");
112 exit(1);
115 /* don't need no steenking hand-editing */
116 printf(
117 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
118 ;;;; See the program \"grovel-headers.c\".\n\
121 #ifdef _WIN32
122 #include "grovel-headers-win32.h"
123 #else
124 printf("(in-package \"SB!ALIEN\")\n\n");
126 printf (";;;flags for dlopen()\n");
128 defconstant ("rtld-lazy", RTLD_LAZY);
129 defconstant ("rtld-now", RTLD_NOW);
130 defconstant ("rtld-global", RTLD_GLOBAL);
132 printf("(in-package \"SB!UNIX\")\n\n");
134 printf(";;; select()\n");
135 defconstant("fd-setsize", FD_SETSIZE);
137 printf(";;; poll()\n");
138 defconstant("pollin", POLLIN);
139 defconstant("pollout", POLLOUT);
140 defconstant("pollpri", POLLPRI);
141 defconstant("pollhup", POLLHUP);
142 defconstant("pollnval", POLLNVAL);
143 defconstant("pollerr", POLLERR);
144 DEFTYPE("nfds-t", nfds_t);
145 #ifndef LISP_FEATURE_ANDROID
146 printf(";;; langinfo\n");
147 defconstant("codeset", CODESET);
148 #endif
149 printf(";;; types, types, types\n");
150 DEFTYPE("clock-t", clock_t);
151 DEFTYPE("dev-t", dev_t);
152 DEFTYPE("gid-t", gid_t);
153 DEFTYPE("ino-t", ino_t);
154 DEFTYPE("mode-t", mode_t);
155 DEFTYPE("nlink-t", nlink_t);
156 DEFTYPE("off-t", off_t);
157 DEFTYPE("size-t", size_t);
158 DEFTYPE("ssize-t", ssize_t);
159 DEFTYPE("time-t", time_t);
160 #if !defined(LISP_FEATURE_OS_PROVIDES_SUSECONDS_T)
161 /* Similar kludge in sb-posix. */
162 DEFTYPE("suseconds-t", long);
163 #else
164 DEFTYPE("suseconds-t", suseconds_t);
165 #endif
166 DEFTYPE("uid-t", uid_t);
167 printf(";; Types in src/runtime/wrap.h. See that file for explantion.\n");
168 printf(";; Don't use these types for anything other than the stat wrapper.\n");
169 DEFTYPE("wst-ino-t", wst_ino_t);
170 DEFTYPE("wst-dev-t", wst_dev_t);
171 DEFTYPE("wst-off-t", wst_off_t);
172 DEFTYPE("wst-blksize-t", wst_blksize_t);
173 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
174 DEFTYPE("wst-nlink-t", wst_nlink_t);
175 DEFTYPE("wst-uid-t", wst_uid_t);
176 DEFTYPE("wst-gid-t", wst_gid_t);
177 printf("\n");
179 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
180 defconstant("r_ok", R_OK);
181 defconstant("w_ok", W_OK);
182 defconstant("x_ok", X_OK);
183 defconstant("f_ok", F_OK);
184 printf("\n");
186 printf(";;; fcntlbits.h\n");
187 defconstant("o_rdonly", O_RDONLY);
188 defconstant("o_wronly", O_WRONLY);
189 defconstant("o_rdwr", O_RDWR);
190 defconstant("o_accmode", O_ACCMODE);
191 defconstant("o_creat", O_CREAT);
192 defconstant("o_excl", O_EXCL);
193 defconstant("o_noctty", O_NOCTTY);
194 defconstant("o_trunc", O_TRUNC);
195 defconstant("o_append", O_APPEND);
196 #ifdef LISP_FEATURE_LARGEFILE
197 defconstant("o_largefile", O_LARGEFILE);
198 #endif
200 printf(";;;\n");
201 defconstant("s-ifmt", S_IFMT);
202 defconstant("s-ififo", S_IFIFO);
203 defconstant("s-ifchr", S_IFCHR);
204 defconstant("s-ifdir", S_IFDIR);
205 defconstant("s-ifblk", S_IFBLK);
206 defconstant("s-ifreg", S_IFREG);
207 printf("\n");
209 defconstant("s-iflnk", S_IFLNK);
210 defconstant("s-ifsock", S_IFSOCK);
211 printf("\n");
213 printf(";;; error numbers\n");
214 deferrno("ebadf", EBADF);
215 deferrno("enoent", ENOENT);
216 deferrno("eintr", EINTR);
217 deferrno("eagain", EAGAIN);
218 deferrno("eio", EIO);
219 deferrno("eexist", EEXIST);
220 deferrno("eloop", ELOOP);
221 deferrno("espipe", ESPIPE);
222 deferrno("ewouldblock", EWOULDBLOCK);
223 printf("\n");
225 deferrno("sc-nprocessors-onln", _SC_NPROCESSORS_ONLN);
227 printf(";;; for wait3(2) in run-program.lisp\n");
228 #ifdef WCONTINUED
229 defconstant("wcontinued", WCONTINUED);
230 #else
231 defconstant("wcontinued", 0);
232 #endif
234 defconstant("wnohang", WNOHANG);
235 defconstant("wuntraced", WUNTRACED);
236 printf("\n");
238 printf(";;; various ioctl(2) flags\n");
239 defconstant("tiocgpgrp", TIOCGPGRP);
240 defconstant("tiocspgrp", TIOCSPGRP);
241 defconstant("tiocgwinsz", TIOCGWINSZ);
242 defconstant("tiocswinsz", TIOCSWINSZ);
243 /* KLUDGE: These are referenced by old CMUCL-derived code, but
244 * Linux doesn't define them.
246 * I think these are the BSD names, but I don't know what the
247 * corresponding SysV/Linux names are. As a point of reference,
248 * CMUCL doesn't have these defined either (although the defining
249 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
250 * so bad about not hunting them down. Insight into renamed
251 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
253 * I note that the first one I grepped for, TIOCSIGSEND, is
254 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
255 * Oxbridge know more about things like that? And even if they
256 * don't, one benefit of the Rhodes crusade to heal the worthy
257 * ports should be that afterwards, if we grep for something like
258 * this in CVS and it's not there, we can lightheartedly nuke it.
259 * -- WHN 2002-08-30 */
261 defconstant("tiocsigsend", TIOCSIGSEND);
262 defconstant("tiocflush", TIOCFLUSH);
263 defconstant("tiocgetp", TIOCGETP);
264 defconstant("tiocsetp", TIOCSETP);
265 defconstant("tiocgetc", TIOCGETC);
266 defconstant("tiocsetc", TIOCSETC);
267 defconstant("tiocgltc", TIOCGLTC);
268 defconstant("tiocsltc", TIOCSLTC);
270 printf("\n");
272 printf(";;; signals\n");
273 defconstant("sig-dfl", (unsigned long)SIG_DFL);
274 defconstant("sig-ign", (unsigned long)SIG_IGN);
276 defsignal("sigalrm", SIGALRM);
277 defsignal("sigbus", SIGBUS);
278 defsignal("sigchld", SIGCHLD);
279 defsignal("sigcont", SIGCONT);
280 #ifdef SIGEMT
281 defsignal("sigemt", SIGEMT);
282 #endif
283 defsignal("sigfpe", SIGFPE);
284 defsignal("sighup", SIGHUP);
285 defsignal("sigill", SIGILL);
286 defsignal("sigint", SIGINT);
287 defsignal("sigio", SIGIO);
288 defsignal("sigiot", SIGIOT);
289 defsignal("sigkill", SIGKILL);
290 defsignal("sigpipe", SIGPIPE);
291 defsignal("sigprof", SIGPROF);
292 defsignal("sigquit", SIGQUIT);
293 defsignal("sigsegv", SIGSEGV);
294 #ifdef SIGSTKFLT
295 defsignal("sigstkflt", SIGSTKFLT);
296 #endif
297 defsignal("sigstop", SIGSTOP);
298 #ifdef SIGSYS
299 defsignal("sigsys", SIGSYS);
300 #endif
301 defsignal("sigterm", SIGTERM);
302 defsignal("sigtrap", SIGTRAP);
303 defsignal("sigtstp", SIGTSTP);
304 defsignal("sigttin", SIGTTIN);
305 defsignal("sigttou", SIGTTOU);
306 defsignal("sigurg", SIGURG);
307 defsignal("sigusr1", SIGUSR1);
308 defsignal("sigusr2", SIGUSR2);
309 defsignal("sigvtalrm", SIGVTALRM);
310 #ifdef SIGWAITING
311 defsignal("sigwaiting", SIGWAITING);
312 #endif
313 defsignal("sigwinch", SIGWINCH);
314 #ifdef SIGXCPU
315 defsignal("sigxcpu", SIGXCPU);
316 #endif
317 #ifdef SIGXFSZ
318 defsignal("sigxfsz", SIGXFSZ);
319 #endif
321 /* Floating point exception codes. Some of these
322 * are missing on Darwin. */
323 #ifdef FPE_INTOVF
324 defconstant("fpe-intovf", FPE_INTOVF);
325 #else
326 defconstant("fpe-intovf", -1);
327 #endif
328 #ifdef FPE_INTDIV
329 defconstant("fpe-intdiv", FPE_INTDIV);
330 #else
331 defconstant("fpe-intdiv", -1);
332 #endif
333 defconstant("fpe-fltdiv", FPE_FLTDIV);
334 defconstant("fpe-fltovf", FPE_FLTOVF);
335 defconstant("fpe-fltund", FPE_FLTUND);
336 defconstant("fpe-fltres", FPE_FLTRES);
337 defconstant("fpe-fltinv", FPE_FLTINV);
338 #ifdef FPE_FLTSUB
339 defconstant("fpe-fltsub", FPE_FLTSUB);
340 #else
341 defconstant("fpe-fltsub", -1);
342 #endif
343 #endif // !WIN32
344 printf("\n");
346 printf(";;; structures\n");
347 DEFSTRUCT(timeval, struct timeval,
348 DEFSLOT(tv-sec, tv_sec);
349 DEFSLOT(tv-usec, tv_usec));
350 DEFSTRUCT(timespec, struct timespec,
351 DEFSLOT(tv-sec, tv_sec);
352 DEFSLOT(tv-nsec, tv_nsec));
353 printf("\n");
355 #ifdef LISP_FEATURE_ANDROID
356 defconstant("path-max", PATH_MAX);
357 printf("\n");
358 #endif
360 #ifdef LISP_FEATURE_BSD
361 printf(";;; sysctl(3) names\n");
362 printf("(in-package \"SB!IMPL\")\n");
363 defconstant("ctl-kern", CTL_KERN);
364 defconstant("ctl-hw", CTL_HW);
365 defconstant("ctl-maxname", CTL_MAXNAME);
366 defconstant("kern-ostype", KERN_OSTYPE);
367 defconstant("kern-osrelease", KERN_OSRELEASE);
368 defconstant("hw-model", HW_MODEL);
369 defconstant("hw-pagesize", HW_PAGESIZE);
371 defconstant("path-max", PATH_MAX);
372 printf("\n");
373 #endif
375 printf("(in-package \"SB!KERNEL\")\n\n");
376 #ifdef LISP_FEATURE_GENCGC
377 printf(";;; GENCGC related\n");
378 DEFTYPE("page-index-t", page_index_t);
379 DEFTYPE("generation-index-t", generation_index_t);
380 printf("\n");
381 #endif
383 printf(";;; Our runtime types\n");
384 DEFTYPE("os-vm-size-t", os_vm_size_t);
386 return 0;