/[cmucl]/src/lisp/darwin-lispadjuster.c
ViewVC logotype

Contents of /src/lisp/darwin-lispadjuster.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Mon Sep 5 06:09:13 2005 UTC (8 years, 7 months ago) by cshapiro
Branch: MAIN
Changes since 1.1: +1 -1 lines
File MIME type: text/plain
Replace all uses of the old b{copy,zero} byte string functions with
the equivalent standard C mem{cpy,move,set} functions.
1 pmai 1.1 /* Modify the final lisp binary to enlarge the generated CMUCLRO segment */
2     #include <stdlib.h>
3     #include <string.h>
4     #include <mach-o/loader.h>
5     #include <sys/types.h>
6     #include <sys/uio.h>
7     #include <unistd.h>
8     #include <fcntl.h>
9     #include <stdio.h>
10     #include "validate.h"
11    
12     #ifdef DEBUG
13     #define dprintf printf
14     #else
15     #define dprintf(...)
16     #endif
17    
18     int main(int argc, char** argv)
19     {
20     char* filename;
21     int fd;
22     int i,result;
23     off_t curpos;
24     struct mach_header theheader;
25     struct segment_command thesegment;
26     char segname[17];
27    
28     if (argc != 2)
29     return 1;
30     filename = argv[1];
31    
32     fd = open(filename, O_RDWR, 0755);
33     read(fd,&theheader,sizeof(theheader));
34    
35     if ((theheader.magic != MH_MAGIC) || (theheader.filetype != MH_EXECUTE))
36     return 2;
37    
38     dprintf("Reading %d commands:\n",theheader.ncmds);
39    
40     for (i=0;i<theheader.ncmds;i++) {
41     curpos = lseek(fd,0,SEEK_CUR);
42     dprintf("Reading command %d (%d bytes):\n",i,sizeof(struct load_command));
43     read(fd,&thesegment,sizeof(struct load_command));
44     dprintf("Command is %d, length %d\n",thesegment.cmd,thesegment.cmdsize);
45     if (thesegment.cmd != LC_SEGMENT) {
46     dprintf("Skipping remainder of command...\n");
47     lseek(fd,thesegment.cmdsize - sizeof(struct load_command),SEEK_CUR);
48     continue;
49     }
50    
51     dprintf("Reading remainder of Segment command (%d bytes)", sizeof(thesegment)-sizeof(struct load_command));
52     read(fd,&thesegment.segname,sizeof(thesegment)-sizeof(struct load_command));
53 cshapiro 1.2 memset(segname,0,17);
54 pmai 1.1 memcpy(segname,thesegment.segname,16);
55     dprintf("Segname: %s\n",segname);
56     if (0==strncmp(thesegment.segname,"CMUCLRO",7)) {
57     dprintf("Frobbing the segment, setting vmsize from %8X to %8X\n",thesegment.vmsize,READ_ONLY_SPACE_SIZE);
58     thesegment.vmsize = READ_ONLY_SPACE_SIZE;
59     dprintf("Skipping back to %lld.\n",curpos);
60     lseek(fd,curpos,SEEK_SET);
61     dprintf("Writing %d bytes.\n",sizeof(thesegment));
62     result=write(fd,&thesegment,sizeof(thesegment));
63     if (result==-1)
64     perror("Error:");
65     close(fd);
66     return 0;
67     } else {
68     dprintf("Cmdsize = %d, Already read = %d, Now seeking %d\n",thesegment.cmdsize, sizeof(thesegment), thesegment.cmdsize - sizeof(thesegment));
69     lseek(fd,thesegment.cmdsize - sizeof(thesegment),SEEK_CUR);
70     }
71     }
72     close(fd);
73     return 3;
74     }

  ViewVC Help
Powered by ViewVC 1.1.5