1 /* ppc-darwin-fix-rospace.c - fix the segment and section output by ppc-darwin-mkrospace.c to have the correct size */
6 #include <mach-o/loader.h>
17 #include "ppc-darwin-spacelist.h"
19 int main(int argc, char** argv)
24 struct mach_header *header;
27 size_t old_commands_size;
31 /* Open the SBCL binary */
32 fd = open("sbcl", O_RDWR, 0); /* wr unx prgrmmrs, we cn't spll */
37 if (fstat(fd, &filestat) == -1) {
42 filesize = filestat.st_size;
43 if ((int) (file_pointer = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0)) == -1) {
51 header = (struct mach_header*) file_pointer;
52 window = (char*) (header + 1);
53 for (i = 0; i < header->ncmds; i++) {
54 struct load_command* current_segment;
55 current_segment = (struct load_command*) window;
56 segments_size += current_segment->cmdsize;
57 window += current_segment->cmdsize;
58 if (current_segment->cmd == LC_SEGMENT) {
60 struct segment_command* seg = (struct segment_command*) current_segment;
61 struct section* sectptr;
64 if (strncmp("SBCL", seg->segname, 4) == 0) {
66 seg->vmsize = space_sizes[spacei];
71 sectptr = (struct section*) seg;
72 for (j = 0; j < max; j++) {
74 sectptr->size = space_sizes[spacei];
82 munmap(file_pointer, filesize);