3 |
|
* |
4 |
|
* Copyright (c) 2003 Michael Z. Sliczniak |
5 |
|
* |
6 |
< |
* Basilisk II (C) 1997-2003 Christian Bauer |
6 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
7 |
|
* |
8 |
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
* it under the terms of the GNU General Public License as published by |
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 |
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); |
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); |
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 |