/[emacs]/emacs/src/unexnext.c
ViewVC logotype

Diff of /emacs/src/unexnext.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by rms, Tue Sep 2 05:05:37 1997 UTC revision 1.7.20.1 by miles, Fri Apr 4 06:21:03 2003 UTC
# Line 44  int malloc_cookie; Line 44  int malloc_cookie;
44   * pages it vm_allocated and write only those out into the data segment.   * pages it vm_allocated and write only those out into the data segment.
45   *   *
46   * This kludge may break when we stop using fixed virtual address   * This kludge may break when we stop using fixed virtual address
47   * shared libraries. Actually, emacs will probably continue working, but be   * shared libraries. Actually, emacs will probably continue working, but be
48   * much larger on disk than it needs to be (because non-malloced data will   * much larger on disk than it needs to be (because non-malloced data will
49   * be in the file).   * be in the file).
50   */   */
# Line 73  grow( Line 73  grow(
73                  *the_commands = malloc(sizeof(*the_commands));                  *the_commands = malloc(sizeof(*the_commands));
74          } else {          } else {
75                  (*the_commands_len)++;                  (*the_commands_len)++;
76                  *the_commands = realloc(*the_commands,                  *the_commands = realloc(*the_commands,
77                                          (*the_commands_len *                                          (*the_commands_len *
78                                           sizeof(**the_commands)));                                           sizeof(**the_commands)));
79          }          }
# Line 125  read_macho( Line 125  read_macho(
125                  return (0);                  return (0);
126          }          }
127          for (i = 0; i < the_header->ncmds; i++) {          for (i = 0; i < the_header->ncmds; i++) {
128                  if (read(fd, &command, sizeof(struct load_command)) !=                  if (read(fd, &command, sizeof(struct load_command)) !=
129                      sizeof(struct load_command)) {                      sizeof(struct load_command)) {
130                          fatal_unexec("cannot read macho load command header");                          fatal_unexec("cannot read macho load command header");
131                          return (0);                          return (0);
# Line 138  read_macho( Line 138  read_macho(
138                  buf = malloc(command.cmdsize);                  buf = malloc(command.cmdsize);
139                  buf->cmd = command.cmd;                  buf->cmd = command.cmd;
140                  buf->cmdsize = command.cmdsize;                  buf->cmdsize = command.cmdsize;
141                  if (read(fd, ((char *)buf +                  if (read(fd, ((char *)buf +
142                                sizeof(struct load_command)),                                sizeof(struct load_command)),
143                           size) != size) {                           size) != size) {
144                          fatal_unexec("cannot read load command data");                          fatal_unexec("cannot read load command data");
145                          return (0);                          return (0);
# Line 184  get_data_region( Line 184  get_data_region(
184          region.address = 0;          region.address = 0;
185          *address = 0;          *address = 0;
186          for (;;) {          for (;;) {
187                  ret = vm_region(task_self(),                  ret = vm_region(task_self(),
188                                  &region.address,                                  &region.address,
189                                  &region.size,                                  &region.size,
190                                  &region.protection,                                  &region.protection,
191                                  &region.max_protection,                                  &region.max_protection,
192                                  &region.inheritance,                                  &region.inheritance,
193                                  &region.shared,                                  &region.shared,
194                                  &region.object_name,                                  &region.object_name,
195                                  &region.offset);                                  &region.offset);
196                  if (ret != KERN_SUCCESS || region.address >= VM_HIGHDATA) {                  if (ret != KERN_SUCCESS || region.address >= VM_HIGHDATA) {
197                          break;                          break;
198                  }                  }
199                  if (*address != 0) {                  if (*address != 0) {
200                          if (region.address > *address + *size) {                          if (region.address > *address + *size) {
201                                  if (!filldatagap(*address, size,                                  if (!filldatagap(*address, size,
202                                                   region.address)) {                                                   region.address)) {
203                                          return (0);                                          return (0);
204                                  }                                  }
205                          }                          }
206                          *size += region.size;                          *size += region.size;
207                  } else {                  } else {
208                          if (region.address == sect->addr) {                          if (region.address == sect->addr) {
209                                  *address = region.address;                                  *address = region.address;
210                                  *size = region.size;                                  *size = region.size;
211                          }                          }
212                  }                  }
213                  region.address += region.size;                  region.address += region.size;
214          }          }
# Line 293  unexec_doit( Line 293  unexec_doit(
293                                  if (strcmp(segment->segname, SEG_DATA) == 0) {                                  if (strcmp(segment->segname, SEG_DATA) == 0) {
294                                          fdatastart = segment->fileoff;                                          fdatastart = segment->fileoff;
295                                          fdatasize = segment->filesize;                                          fdatasize = segment->filesize;
296                                          fgrowth = (data_size -                                          fgrowth = (data_size -
297                                                     segment->filesize);                                                     segment->filesize);
298                                          segment->vmsize = data_size;                                          segment->vmsize = data_size;
299                                          segment->filesize = data_size;                                          segment->filesize = data_size;
# Line 332  unexec_doit( Line 332  unexec_doit(
332                                  break;                                  break;
333                          }                          }
334                  }                  }
335                    
336                  /*                  /*
337                   * Write header                   * Write header
338                   */                   */
339                  if (write(outfd, &the_header,                  if (write(outfd, &the_header,
340                            sizeof(the_header)) != sizeof(the_header)) {                            sizeof(the_header)) != sizeof(the_header)) {
341                          fatal_unexec("cannot write output file");                          fatal_unexec("cannot write output file");
342                          return (0);                          return (0);
343                  }                  }
344                    
345                  /*                  /*
346                   * Write commands                   * Write commands
347                   */                   */
348                  for (i = 0; i < the_commands_len; i++) {                  for (i = 0; i < the_commands_len; i++) {
349                          if (write(outfd, the_commands[i],                          if (write(outfd, the_commands[i],
350                                    the_commands[i]->cmdsize) !=                                    the_commands[i]->cmdsize) !=
351                              the_commands[i]->cmdsize) {                              the_commands[i]->cmdsize) {
352                                  fatal_unexec("cannot write output file");                                  fatal_unexec("cannot write output file");
353                                  return (0);                                  return (0);
354                          }                          }
355                  }                  }
356                    
357                  /*                  /*
358                   * Write original text                   * Write original text
359                   */                   */
360                  if (lseek(infd, the_header.sizeofcmds + sizeof(the_header),                  if (lseek(infd, the_header.sizeofcmds + sizeof(the_header),
361                            L_SET) < 0) {                            L_SET) < 0) {
362                          fatal_unexec("cannot seek input file");                          fatal_unexec("cannot seek input file");
363                          return (0);                          return (0);
364                  }                  }
365                  size = fdatastart - (sizeof(the_header) +                  size = fdatastart - (sizeof(the_header) +
366                                       the_header.sizeofcmds);                                       the_header.sizeofcmds);
367                  buf = my_malloc(size);                  buf = my_malloc(size);
368                  if (read(infd, buf, size) != size) {                  if (read(infd, buf, size) != size) {
# Line 375  unexec_doit( Line 375  unexec_doit(
375                          return (0);                          return (0);
376                  }                  }
377                  my_free(buf, size);                  my_free(buf, size);
378                    
379                    
380                  /*                  /*
381                   * Write new data                   * Write new data
382                   */                   */
383                  if (write(outfd, (char *)data_address,                  if (write(outfd, (char *)data_address,
384                            data_size) != data_size) {                            data_size) != data_size) {
385                          fatal_unexec("cannot write output file");                          fatal_unexec("cannot write output file");
386                          return (0);                          return (0);
387                  }                  }
388                    
389          }          }
390    
391          /*          /*
# Line 424  unexec_doit( Line 424  unexec_doit(
424                  fatal_unexec("cannot seek input file");                  fatal_unexec("cannot seek input file");
425                  return (0);                  return (0);
426          }          }
427            
428          for (i = 0; i < nextrel; i++)          for (i = 0; i < nextrel; i++)
429          {          {
430            long zeroval = 0;            long zeroval = 0;
# Line 482  unexec( Line 482  unexec(
482                  fatal_unexec("cannot open input file `%s'", infile);                  fatal_unexec("cannot open input file `%s'", infile);
483                  exit(1);                  exit(1);
484          }          }
485            
486          tmpnam(tmpbuf);          tmpnam(tmpbuf);
487          tmpfile = rindex(tmpbuf, '/');          tmpfile = rindex(tmpbuf, '/');
488          if (tmpfile == NULL) {          if (tmpfile == NULL) {

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.7.20.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26