1 /* x86-darwin-mkrospace.c - write a .o which makes sure we get our desired address range */
5 #include <mach-o/loader.h>
15 #include "x86-darwin-spacelist.h"
17 struct simple_object_file
19 struct segment_command thesegment;
20 struct section thesection;
23 int main(int argc, char** argv)
25 struct mach_header *theheader;
26 struct simple_object_file *theobj;
29 /* Produce the mach header */
30 theheader = (struct mach_header*) malloc(sizeof(struct mach_header));
31 theheader->magic = MH_MAGIC;
32 theheader->cputype = CPU_TYPE_X86;
33 theheader->cpusubtype = CPU_SUBTYPE_I386_ALL;
34 theheader->filetype = MH_OBJECT;
35 theheader->ncmds = N_SEGMENTS_TO_PRODUCE;
36 theheader->sizeofcmds = N_SEGMENTS_TO_PRODUCE * (sizeof(struct segment_command) + sizeof(struct section));
37 theheader->flags = MH_NOUNDEFS;
39 fd = open("x86-darwin-rospace.o", O_WRONLY | O_CREAT, 0644);
40 write(fd, theheader, sizeof(struct mach_header));
42 for (i = 0; i < N_SEGMENTS_TO_PRODUCE; i++) {
43 theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file));
44 theobj->thesegment.cmd = LC_SEGMENT;
45 theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section);
46 snprintf(theobj->thesegment.segname, 7, "SBCL%d", i);
47 theobj->thesegment.fileoff = sizeof(struct mach_header) + i * (sizeof(struct segment_command) + sizeof(struct section));
48 theobj->thesegment.vmaddr = space_start_locations[i];
49 theobj->thesegment.vmsize = 0;
50 theobj->thesegment.maxprot = VM_PROT_ALL;
51 theobj->thesegment.initprot = VM_PROT_ALL;
52 theobj->thesegment.nsects = 1;
53 theobj->thesegment.flags = 0;
54 snprintf(theobj->thesection.sectname, 7, "sect%d", i);
55 snprintf(theobj->thesection.segname, 7, "SBCL%d", i);
56 theobj->thesection.addr = space_start_locations[i];
57 theobj->thesection.size = 0;
58 theobj->thesection.offset = 0;
59 theobj->thesection.align = 0;
60 theobj->thesection.reloff = 0;
61 theobj->thesection.nreloc = 0;
62 theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS;
63 theobj->thesection.reserved1 = 0;
64 theobj->thesection.reserved2 = 0;
65 write(fd, theobj, sizeof(struct simple_object_file));
66 printf(",-segaddr,SBCL%d,0x%x", i, space_start_locations[i]);