comparison src/unexsunos4.c @ 10406:e656e5fe190d

(unexec): Cast value of sbrk. (run_time_remap): Cast arg to brk. (brk_value): Renamed from Brk. (is_it): Cast 1st arg of mmap.
author Richard M. Stallman <rms@gnu.org>
date Thu, 12 Jan 1995 21:02:30 +0000
parents 2b4365800d04
children 8c38245f7be4
comparison
equal deleted inserted replaced
10405:609f34c0c7bc 10406:e656e5fe190d
90 extern unsigned data_start; 90 extern unsigned data_start;
91 extern int pureptr; 91 extern int pureptr;
92 #endif 92 #endif
93 93
94 extern char *getenv (); 94 extern char *getenv ();
95 static unsigned Brk; 95 static unsigned brk_value;
96 static struct exec nhdr; 96 static struct exec nhdr;
97 static int rd_only_len; 97 static int rd_only_len;
98 static long cookie; 98 static long cookie;
99 99
100 100
143 * Remember a magic cookie so we know we've got the right binary 143 * Remember a magic cookie so we know we've got the right binary
144 * when remapping. 144 * when remapping.
145 */ 145 */
146 cookie = time (0); 146 cookie = time (0);
147 147
148 Brk = sbrk (0); /* Save the break, it is reset to &_end (by ld.so?) */ 148 /* Save the break, it is reset to &_end (by ld.so?). */
149 brk_value = (unsigned) sbrk (0);
149 150
150 /* 151 /*
151 * Round up data start to a page boundary (Lose if not a 2 power!) 152 * Round up data start to a page boundary (Lose if not a 2 power!)
152 */ 153 */
153 data_start = ((((int)&data_start) - 1) & ~(N_PAGSIZ (nhdr) - 1)) + N_PAGSIZ (nhdr); 154 data_start = ((((int)&data_start) - 1) & ~(N_PAGSIZ (nhdr) - 1)) + N_PAGSIZ (nhdr);
161 #ifndef emacs 162 #ifndef emacs
162 /* Have to do this some time before dumping the data */ 163 /* Have to do this some time before dumping the data */
163 initialized = 1; 164 initialized = 1;
164 #endif 165 #endif
165 166
166 /* 167 /* Handle new data and bss sizes and optional new entry point.
167 * Handle new data and bss sizes and optional new entry point. 168 No one actually uses bss_start and entry, but tradition compels
168 * No one actually uses bss_start and entry, but tradition compels 169 one to support them.
169 * one to support them. 170 Could complain if bss_start > brk_value,
170 * Could complain if bss_start > Brk, but the caller is *supposed* to know 171 but the caller is *supposed* to know what she is doing. */
171 * what she is doing. 172 nhdr.a_data = (bss_start ? bss_start : brk_value) - N_DATADDR (nhdr);
172 */ 173 nhdr.a_bss = bss_start ? brk_value - bss_start : 0;
173 nhdr.a_data = (bss_start ? bss_start : Brk) - N_DATADDR (nhdr);
174 nhdr.a_bss = bss_start ? Brk - bss_start : 0;
175 if (entry) 174 if (entry)
176 nhdr.a_entry = entry; 175 nhdr.a_entry = entry;
177 176
178 /* 177 /*
179 * Write out the text segment with new header 178 * Write out the text segment with new header
277 /* Just in case */ 276 /* Just in case */
278 if (!initialized) 277 if (!initialized)
279 return; 278 return;
280 279
281 /* Restore the break */ 280 /* Restore the break */
282 brk (Brk); 281 brk ((char *) brk_value);
283 282
284 /* If nothing to remap: we are done! */ 283 /* If nothing to remap: we are done! */
285 if (rd_only_len == 0) 284 if (rd_only_len == 0)
286 return; 285 return;
287 286
356 * Do the mapping 355 * Do the mapping
357 * The PROT_EXEC may not be needed, but it is safer this way. 356 * The PROT_EXEC may not be needed, but it is safer this way.
358 * should the shared library decide to indirect through 357 * should the shared library decide to indirect through
359 * addresses in the data segment not part of __DYNAMIC 358 * addresses in the data segment not part of __DYNAMIC
360 */ 359 */
361 mmap (data_start, rd_only_len, PROT_READ | PROT_EXEC, 360 mmap ((char *) data_start, rd_only_len, PROT_READ | PROT_EXEC,
362 MAP_FILE | MAP_SHARED | MAP_FIXED, fd, 361 MAP_FILE | MAP_SHARED | MAP_FIXED, fd,
363 N_DATOFF (hdr) + data_start - N_DATADDR (hdr)); 362 N_DATOFF (hdr) + data_start - N_DATADDR (hdr));
364 close (fd); 363 close (fd);
365 return 1; 364 return 1;
366 } 365 }