annotate src/unexnext.c @ 72158:89c27eb47328

(gdb-info-breakpoints-custom): Use different faces for enable character.
author Nick Roberts <nickrob@snap.net.nz>
date Fri, 28 Jul 2006 12:11:09 +0000
parents 3bd95f4f2941
children e90d04cd455a c5406394f567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Dump Emacs in macho format.
64770
a0d1312ede66 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
2 Copyright (C) 1990, 1993, 2002, 2003, 2004,
68651
3bd95f4f2941 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64770
diff changeset
3 2005, 2006 Free Software Foundation, Inc.
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 Written by Bradley Taylor (btaylor@next.com).
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 This file is part of GNU Emacs.
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 GNU Emacs is free software; you can redistribute it and/or modify
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
2660
b70f4760d769 Changes for Emacs 19 from Thorsten Ohl <ohl@chico.harvard.edu>:
Jim Blandy <jimb@redhat.com>
parents: 1349
diff changeset
10 the Free Software Foundation; either version 2, or (at your option)
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 any later version.
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 GNU Emacs is distributed in the hope that it will be useful,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 GNU General Public License for more details.
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 along with GNU Emacs; see the file COPYING. If not, write to
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
21 Boston, MA 02110-1301, USA. */
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 #undef __STRICT_BSD__
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 #include <stdio.h>
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 #include <stdlib.h>
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 #include <stdarg.h>
2660
b70f4760d769 Changes for Emacs 19 from Thorsten Ohl <ohl@chico.harvard.edu>:
Jim Blandy <jimb@redhat.com>
parents: 1349
diff changeset
29 #include <mach/mach.h>
b70f4760d769 Changes for Emacs 19 from Thorsten Ohl <ohl@chico.harvard.edu>:
Jim Blandy <jimb@redhat.com>
parents: 1349
diff changeset
30 #include <mach-o/loader.h>
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
31 #include <mach-o/reloc.h>
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 #include <sys/file.h>
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 #include <sys/stat.h>
19669
e8e724dad99a Include unistd.h instead of libc.h.
Richard M. Stallman <rms@gnu.org>
parents: 16853
diff changeset
34 #include <unistd.h>
19670
4383d4a532de Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 19669
diff changeset
35 /* Instead of unistd.h, this used to include libc.h.
4383d4a532de Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 19669
diff changeset
36 "Nelson H. F. Beebe" <beebe@math.utah.edu> says that doesn't work
4383d4a532de Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 19669
diff changeset
37 in system version 3.3. */
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
2660
b70f4760d769 Changes for Emacs 19 from Thorsten Ohl <ohl@chico.harvard.edu>:
Jim Blandy <jimb@redhat.com>
parents: 1349
diff changeset
40 int malloc_cookie;
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 * Kludge: we don't expect any program data beyond VM_HIGHDATA
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 * What is really needed is a way to find out from malloc() which
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 * pages it vm_allocated and write only those out into the data segment.
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 *
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 * This kludge may break when we stop using fixed virtual address
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
48 * shared libraries. Actually, emacs will probably continue working, but be
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 * much larger on disk than it needs to be (because non-malloced data will
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 * be in the file).
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 static const unsigned VM_HIGHDATA = 0x2000000;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 typedef struct region_t {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 vm_address_t address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 vm_size_t size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 vm_prot_t protection;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 vm_prot_t max_protection;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 vm_inherit_t inheritance;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 boolean_t shared;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 port_t object_name;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 vm_offset_t offset;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 } region_t;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 static void
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 grow(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 struct load_command ***the_commands,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 unsigned *the_commands_len
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 if (*the_commands == NULL) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 *the_commands_len = 1;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 *the_commands = malloc(sizeof(*the_commands));
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 } else {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (*the_commands_len)++;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
77 *the_commands = realloc(*the_commands,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (*the_commands_len *
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 sizeof(**the_commands)));
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 static void
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 save_command(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 struct load_command *command,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 struct load_command ***the_commands,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 unsigned *the_commands_len
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 struct load_command **tmp;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 grow(the_commands, the_commands_len);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 tmp = &(*the_commands)[*the_commands_len - 1];
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 *tmp = malloc(command->cmdsize);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 bcopy(command, *tmp, command->cmdsize);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 static void
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 fatal_unexec(char *format, ...)
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 va_list ap;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 va_start(ap, format);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 fprintf(stderr, "unexec: ");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 vfprintf(stderr, format, ap);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 fprintf(stderr, "\n");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 va_end(ap);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 static int
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 read_macho(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 int fd,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 struct mach_header *the_header,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 struct load_command ***the_commands,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 unsigned *the_commands_len
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 struct load_command command;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 struct load_command *buf;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 int i;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 int size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 if (read(fd, the_header, sizeof(*the_header)) != sizeof(*the_header)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 fatal_unexec("cannot read macho header");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 for (i = 0; i < the_header->ncmds; i++) {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
129 if (read(fd, &command, sizeof(struct load_command)) !=
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 sizeof(struct load_command)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 fatal_unexec("cannot read macho load command header");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 size = command.cmdsize - sizeof(struct load_command);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 if (size < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 fatal_unexec("bogus load command size");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 buf = malloc(command.cmdsize);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 buf->cmd = command.cmd;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 buf->cmdsize = command.cmdsize;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
142 if (read(fd, ((char *)buf +
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
143 sizeof(struct load_command)),
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 size) != size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 fatal_unexec("cannot read load command data");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 save_command(buf, the_commands, the_commands_len);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 return (1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 static int
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 filldatagap(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 vm_address_t start_address,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 vm_size_t *size,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 vm_address_t end_address
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 vm_address_t address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 vm_size_t gapsize;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 address = (start_address + *size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 gapsize = end_address - address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 *size += gapsize;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 if (vm_allocate(task_self(), &address, gapsize,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 FALSE) != KERN_SUCCESS) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 fatal_unexec("cannot vm_allocate");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 return (1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 static int
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 get_data_region(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 vm_address_t *address,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 vm_size_t *size
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 region_t region;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 kern_return_t ret;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 struct section *sect;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
4598
cec168152d88 (get_data_region): Add cast to avoid warning.
Richard M. Stallman <rms@gnu.org>
parents: 2660
diff changeset
184 sect = (struct section *) getsectbyname(SEG_DATA, SECT_DATA);
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 region.address = 0;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 *address = 0;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 for (;;) {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
188 ret = vm_region(task_self(),
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
189 &region.address,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
190 &region.size,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
191 &region.protection,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
192 &region.max_protection,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 &region.inheritance,
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
194 &region.shared,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
195 &region.object_name,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 &region.offset);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 if (ret != KERN_SUCCESS || region.address >= VM_HIGHDATA) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 break;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 if (*address != 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 if (region.address > *address + *size) {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
202 if (!filldatagap(*address, size,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 region.address)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
206 }
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 *size += region.size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 } else {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 if (region.address == sect->addr) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 *address = region.address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 *size = region.size;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
212 }
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 region.address += region.size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 return (1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 static char *
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 my_malloc(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 vm_size_t size
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 vm_address_t address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 if (vm_allocate(task_self(), &address, size, TRUE) != KERN_SUCCESS) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 return (NULL);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 return ((char *)address);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 static void
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 my_free(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 char *buf,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 vm_size_t size
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 vm_deallocate(task_self(), (vm_address_t)buf, size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 static int
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 unexec_doit(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 int infd,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 int outfd
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 int i;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 struct load_command **the_commands = NULL;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 unsigned the_commands_len;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 struct mach_header the_header;
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
251 int fgrowth = 0;
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 int fdatastart;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 int fdatasize;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 int size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 struct stat st;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 char *buf;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 vm_address_t data_address;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 vm_size_t data_size;
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
259 vm_size_t vmaddr_growth = 0;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
260 vm_size_t dataseg_vmaddr, dataseg_vmend;
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 struct segment_command *segment;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
264 #ifdef NS_TARGET
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
265 unsigned long extreloff = 0;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
266 unsigned long nextrel = 0;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
267 struct dysymtab_command *dysymtab;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
268 struct relocation_info reloc_info;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
269 #endif
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
270
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 if (!read_macho(infd, &the_header, &the_commands, &the_commands_len)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
2660
b70f4760d769 Changes for Emacs 19 from Thorsten Ohl <ohl@chico.harvard.edu>:
Jim Blandy <jimb@redhat.com>
parents: 1349
diff changeset
276 malloc_cookie = malloc_freezedry ();
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 if (!get_data_region(&data_address, &data_size)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 * DO NOT USE MALLOC IN THIS SECTION
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 * Fix offsets
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 for (i = 0; i < the_commands_len; i++) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 switch (the_commands[i]->cmd) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 case LC_SEGMENT:
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 segment = ((struct segment_command *)
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 the_commands[i]);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 if (strcmp(segment->segname, SEG_DATA) == 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 fdatastart = segment->fileoff;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 fdatasize = segment->filesize;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
297 fgrowth = (data_size -
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 segment->filesize);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 segment->vmsize = data_size;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 segment->filesize = data_size;
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
301 dataseg_vmaddr = segment->vmaddr;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
302 dataseg_vmend = segment->vmaddr + segment->vmsize;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
303 vmaddr_growth = segment->vmaddr + segment->vmsize;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
304 } else {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
305 ((struct segment_command *)the_commands[i])->fileoff += fgrowth;
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 }
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
307
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
308 if( strcmp( segment->segname, SEG_LINKEDIT ) == 0 ) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
309 segment->vmaddr = vmaddr_growth;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
310 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
311
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 break;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 case LC_SYMTAB:
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ((struct symtab_command *)
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 the_commands[i])->symoff += fgrowth;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ((struct symtab_command *)
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 the_commands[i])->stroff += fgrowth;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 break;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 case LC_SYMSEG:
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ((struct symseg_command *)
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 the_commands[i])->offset += fgrowth;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 break;
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
323 #ifdef NS_TARGET
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
324 case LC_DYSYMTAB:
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
325 dysymtab = ((struct dysymtab_command *)the_commands[i]);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
326 extreloff = dysymtab->extreloff;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
327 nextrel = dysymtab->nextrel;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
328 dysymtab->indirectsymoff += fgrowth;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
329 dysymtab->extreloff += fgrowth;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
330 break;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
331 #endif
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 default:
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 break;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
336
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 * Write header
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
340 if (write(outfd, &the_header,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 sizeof(the_header)) != sizeof(the_header)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 fatal_unexec("cannot write output file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
345
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 * Write commands
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 for (i = 0; i < the_commands_len; i++) {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
350 if (write(outfd, the_commands[i],
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
351 the_commands[i]->cmdsize) !=
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 the_commands[i]->cmdsize) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 fatal_unexec("cannot write output file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
357
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 * Write original text
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
361 if (lseek(infd, the_header.sizeofcmds + sizeof(the_header),
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 L_SET) < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 fatal_unexec("cannot seek input file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
366 size = fdatastart - (sizeof(the_header) +
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 the_header.sizeofcmds);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 buf = my_malloc(size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 if (read(infd, buf, size) != size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 my_free(buf, size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 fatal_unexec("cannot read input file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 if (write(outfd, buf, size) != size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 my_free(buf, size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 fatal_unexec("cannot write output file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 my_free(buf, size);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
379
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
380
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 * Write new data
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
384 if (write(outfd, (char *)data_address,
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 data_size) != data_size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 fatal_unexec("cannot write output file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
389
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 * OKAY TO USE MALLOC NOW
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 /*
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 * Write rest of file
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 */
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 fstat(infd, &st);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 if (lseek(infd, fdatasize, L_INCR) < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 fatal_unexec("cannot seek input file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 size = st.st_size - lseek(infd, 0, L_INCR);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 buf = malloc(size);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 if (read(infd, buf, size) != size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 free(buf);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 fatal_unexec("cannot read input file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 if (write(outfd, buf, size) != size) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 free(buf);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 fatal_unexec("cannot write output file");
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 return (0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 free(buf);
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
418
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
419 #ifdef NS_TARGET
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
420 /*
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
421 * Fix up relocation entries in the data segment.
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
422 */
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
423
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
424 if (lseek(infd, extreloff, L_SET) < 0) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
425 fatal_unexec("cannot seek input file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
426 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
427 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
428
16853
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
429 for (i = 0; i < nextrel; i++)
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
430 {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
431 long zeroval = 0;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
432
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
433 if (read(infd, &reloc_info, sizeof (reloc_info)) != sizeof (reloc_info)) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
434 fatal_unexec("cannot read input file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
435 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
436 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
437 if (reloc_info.r_address >= dataseg_vmaddr && reloc_info.r_address < dataseg_vmend)
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
438 {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
439 if (lseek (outfd, fdatastart + reloc_info.r_address - dataseg_vmaddr, L_SET) < 0 ) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
440 fatal_unexec("cannot seek input file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
441 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
442 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
443 switch (reloc_info.r_length) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
444 case 0:
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
445 if (write(outfd, &zeroval, 1) != 1) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
446 fatal_unexec("cannot write output file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
447 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
448 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
449 break;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
450 case 1:
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
451 if (write(outfd, &zeroval, 2) != 2) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
452 fatal_unexec("cannot write output file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
453 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
454 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
455 break;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
456 case 2:
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
457 if (write(outfd, &zeroval, 4) != 4) {
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
458 fatal_unexec("cannot write output file");
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
459 return (0);
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
460 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
461 break;
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
462 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
463 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
464 }
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
465 #endif
63f2ad395c81 Include <mach-o/reloc.h>.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
466
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 return (1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 void
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 unexec(
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 char *outfile,
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 char *infile
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 )
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 int infd;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 int outfd;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 char tmpbuf[L_tmpnam];
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 char *tmpfile;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 infd = open(infile, O_RDONLY, 0);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 if (infd < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 fatal_unexec("cannot open input file `%s'", infile);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 exit(1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 19670
diff changeset
486
1349
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 tmpnam(tmpbuf);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 tmpfile = rindex(tmpbuf, '/');
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 if (tmpfile == NULL) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 tmpfile = tmpbuf;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 } else {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 tmpfile++;
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 outfd = open(tmpfile, O_WRONLY|O_TRUNC|O_CREAT, 0755);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 if (outfd < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 close(infd);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 fatal_unexec("cannot open tmp file `%s'", tmpfile);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 exit(1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 if (!unexec_doit(infd, outfd)) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 close(infd);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 close(outfd);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 unlink(tmpfile);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 exit(1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 close(infd);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 close(outfd);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 if (rename(tmpfile, outfile) < 0) {
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 unlink(tmpfile);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 fatal_unexec("cannot rename `%s' to `%s'", tmpfile, outfile);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 exit(1);
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 }
5f7b21303f10 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
514
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
515 /* arch-tag: 9796bdc3-c050-417a-b2f5-4cfd31032634
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
516 (do not change this comment) */