ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/Darwin/lowmem.c
(Generate patch)

Comparing BasiliskII/src/Unix/Darwin/lowmem.c (file contents):
Revision 1.3 by gbeauche, 2005-01-30T21:42:14Z vs.
Revision 1.5 by gbeauche, 2007-06-15T22:54:24Z

# Line 25 | Line 25
25   #include <fcntl.h>
26   #include <errno.h>
27   #include <stdio.h>
28 + #include <stdlib.h>
29   #include <string.h>
30   #include <mach/vm_prot.h>
31   #include <mach-o/loader.h>
32  
33   static const char progname[] = "lowmem";
34  
35 + static int do_swap = 0;
36 +
37 + static uint32_t target_uint32(uint32_t value)
38 + {
39 +        if (do_swap)
40 +                value = NXSwapInt(value);
41 +        return value;
42 + }
43 +
44   /*
45   * Under Mach there is very little assumed about the memory map of object
46   * files. It is the job of the loader to create the initial memory map of an
# Line 88 | Line 98 | main(int argc, const char *argv[])
98           * we do not care about that.
99           */
100          machhead = (void *)addr;
101 <        if (machhead->magic != MH_MAGIC) {
101 >        if (machhead->magic == MH_CIGAM)
102 >                do_swap = 1;
103 >        if (target_uint32(machhead->magic) != MH_MAGIC) {
104                  (void)fprintf(stderr, "%s: %s does not appear to be a Mach-O object file\n",
105                                  progname, argv[1]);
106                  exit(1);
107          }
108  
109 <        if (machhead->filetype != MH_EXECUTE) {
109 >        if (target_uint32(machhead->filetype) != MH_EXECUTE) {
110                  (void)fprintf(stderr, "%s: %s does not appear to be an executable file\n",
111                                  progname, argv[1]);
112                  exit(1);
# Line 107 | Line 119 | main(int argc, const char *argv[])
119          }
120  
121          sc_cmd = (void *)&machhead[1];
122 <        if (sc_cmd->cmd != LC_SEGMENT){
122 >        if (target_uint32(sc_cmd->cmd) != LC_SEGMENT){
123                  (void)fprintf(stderr, "%s: load segment not first command in %s\n",
124                                  progname, argv[1]);
125                  exit(1);
# Line 121 | Line 133 | main(int argc, const char *argv[])
133          }
134  
135          /* change the permissions */
136 <        sc_cmd->maxprot = VM_PROT_ALL;
137 <        sc_cmd->initprot = VM_PROT_ALL;
136 >        sc_cmd->maxprot = target_uint32(VM_PROT_ALL);
137 >        sc_cmd->initprot = target_uint32(VM_PROT_ALL);
138  
139          /*
140           * We do not make __PAGEZERO 8K in this program because then

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines