Preliminary work towards threads on win32
[sbcl.git] / src / runtime / trymap.c
blobf55f167b938eb4c7fcdc30b3ec1ba95928f96018
1 /*
2 * a utility for experimenting with mmap()-at-absolute-address-ranges
3 * as a crude way of checking whether it's reasonable for SBCL to
4 * reserve those address ranges for itself
5 */
7 /*
8 * This software is part of the SBCL system. See the README file for
9 * more information.
11 * This software is derived from the CMU CL system, which was
12 * written at Carnegie Mellon University and released into the
13 * public domain. The software is in the public domain and is
14 * provided with absolutely no warranty. See the COPYING and CREDITS
15 * files for more information.
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include <sys/mman.h>
22 long
23 hexparse(char *s)
25 long result;
26 if (1 != sscanf(s, "%lx", &result)) {
27 fprintf(stderr, "can't parse \"%s\" as hexadecimal integer\n", s);
28 exit(1);
30 return result;
33 int
34 main(int argc, char *argv[])
36 char *addr;
37 char *requested_addr;
39 /* FIXME: It would be nice to make the no-command-line-arguments
40 * case of this program automatically check all the spaces that
41 * SBCL likes to map. Then we could execute this program as a
42 * sanity check in make-target-2.sh before we try to execute sbcl
43 * itself. */
44 if (argc != 3) {
45 fprintf(stderr, "usage: %s $addr $size\n", argv[0]);
46 exit(1);
49 requested_addr = (char*)hexparse(argv[1]);
50 addr = mmap(requested_addr,
51 hexparse(argv[2]),
52 0x7,
53 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
54 -1,
55 0);
57 /* FIXME: It would be nice to make this a stronger test. E.g.
58 * besides just trying to mmap() the area, we could check that the
59 * area is not already mapped (perhaps by checking that attempts
60 * to reference the to-be-mapped area cause SIGSEGV or SIGBUS).
61 * (At least on OpenBSD, "A successful mmap deletes any previous
62 * mapping in the allocated address range.") */
63 if (addr != requested_addr) {
64 perror("mmap");
67 exit(0);