emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/unexhp9k800.c


From: Juanma Barranquero
Subject: [Emacs-diffs] Changes to emacs/src/unexhp9k800.c
Date: Tue, 04 Feb 2003 09:03:47 -0500

Index: emacs/src/unexhp9k800.c
diff -c emacs/src/unexhp9k800.c:1.8 emacs/src/unexhp9k800.c:1.9
*** emacs/src/unexhp9k800.c:1.8 Tue Oct 19 03:24:25 1999
--- emacs/src/unexhp9k800.c     Tue Feb  4 09:03:13 2003
***************
*** 13,37 ****
    area with the current data area.  When the new file is executed, the
    process will see the same data structures and data values that the
    original process had when unexec was called.
!   
    Unlike other versions of unexec, this one copies symbol table and
    debug information to the new a.out file.  Thus, the new a.out file
    may be debugged with symbolic debuggers.
!   
    If you fix any bugs in this, I'd like to incorporate your fixes.
    Send them to uunet!hpda!hpsemc!jmorris or address@hidden
!   
    CAVEATS:
    This routine saves the current value of all static and external
    variables.  This means that any data structure that needs to be
    initialized must be explicitly reset.  Variables will not have their
    expected default values.
!   
    Unfortunately, the HP-UX signal handler has internal initialization
    flags which are not explicitly reset.  Thus, for signals to work in
    conjunction with this routine, the following code must executed when
    the new process starts up.
!   
    void _sigreturn ();
    ...
    sigsetreturn (_sigreturn);
--- 13,37 ----
    area with the current data area.  When the new file is executed, the
    process will see the same data structures and data values that the
    original process had when unexec was called.
! 
    Unlike other versions of unexec, this one copies symbol table and
    debug information to the new a.out file.  Thus, the new a.out file
    may be debugged with symbolic debuggers.
! 
    If you fix any bugs in this, I'd like to incorporate your fixes.
    Send them to uunet!hpda!hpsemc!jmorris or address@hidden
! 
    CAVEATS:
    This routine saves the current value of all static and external
    variables.  This means that any data structure that needs to be
    initialized must be explicitly reset.  Variables will not have their
    expected default values.
! 
    Unfortunately, the HP-UX signal handler has internal initialization
    flags which are not explicitly reset.  Thus, for signals to work in
    conjunction with this routine, the following code must executed when
    the new process starts up.
! 
    void _sigreturn ();
    ...
    sigsetreturn (_sigreturn);
***************
*** 54,60 ****
  /* brk value to restore, stored as a global.
     This is really used only if we used shared libraries.  */
  static long brk_on_dump = 0;
!       
  /* Called from main, if we use shared libraries.  */
  int
  run_time_remap (ignored)
--- 54,60 ----
  /* brk value to restore, stored as a global.
     This is really used only if we used shared libraries.  */
  static long brk_on_dump = 0;
! 
  /* Called from main, if we use shared libraries.  */
  int
  run_time_remap (ignored)
***************
*** 81,94 ****
    struct header hdr;
    struct som_exec_auxhdr auxhdr;
    long i;
!   
    /* For the greatest flexibility, should create a temporary file in
       the same directory as the new file.  When everything is complete,
       rename the temp file to the new name.
       This way, a program could update its own a.out file even while
       it is still executing.  If problems occur, everything is still
       intact.  NOT implemented.  */
!   
    /* Open the input and output a.out files */
    old = open (old_name, O_RDONLY);
    if (old < 0)
--- 81,94 ----
    struct header hdr;
    struct som_exec_auxhdr auxhdr;
    long i;
! 
    /* For the greatest flexibility, should create a temporary file in
       the same directory as the new file.  When everything is complete,
       rename the temp file to the new name.
       This way, a program could update its own a.out file even while
       it is still executing.  If problems occur, everything is still
       intact.  NOT implemented.  */
! 
    /* Open the input and output a.out files */
    old = open (old_name, O_RDONLY);
    if (old < 0)
***************
*** 96,131 ****
    new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777);
    if (new < 0)
      { perror (new_name); exit (1); }
!   
    /* Read the old headers */
    read_header (old, &hdr, &auxhdr);
  
    brk_on_dump = (long) sbrk (0);
!   
    /* Decide how large the new and old data areas are */
    old_size = auxhdr.exec_dsize;
    /* I suspect these two statements are separate
       to avoid a compiler bug in hpux version 8.  */
    i = (long) sbrk (0);
    new_size = i - auxhdr.exec_dmem;
!   
    /* Copy the old file to the new, up to the data space */
    lseek (old, 0, 0);
    copy_file (old, new, auxhdr.exec_dfile);
!   
    /* Skip the old data segment and write a new one */
    lseek (old, old_size, 1);
    save_data_space (new, &hdr, &auxhdr, new_size);
!   
    /* Copy the rest of the file */
    copy_rest (old, new);
!   
    /* Update file pointers since we probably changed size of data area */
    update_file_ptrs (new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size);
!   
    /* Save the modified header */
    write_header (new, &hdr, &auxhdr);
!   
    /* Close the binary file */
    close (old);
    close (new);
--- 96,131 ----
    new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777);
    if (new < 0)
      { perror (new_name); exit (1); }
! 
    /* Read the old headers */
    read_header (old, &hdr, &auxhdr);
  
    brk_on_dump = (long) sbrk (0);
! 
    /* Decide how large the new and old data areas are */
    old_size = auxhdr.exec_dsize;
    /* I suspect these two statements are separate
       to avoid a compiler bug in hpux version 8.  */
    i = (long) sbrk (0);
    new_size = i - auxhdr.exec_dmem;
! 
    /* Copy the old file to the new, up to the data space */
    lseek (old, 0, 0);
    copy_file (old, new, auxhdr.exec_dfile);
! 
    /* Skip the old data segment and write a new one */
    lseek (old, old_size, 1);
    save_data_space (new, &hdr, &auxhdr, new_size);
! 
    /* Copy the rest of the file */
    copy_rest (old, new);
! 
    /* Update file pointers since we probably changed size of data area */
    update_file_ptrs (new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size);
! 
    /* Save the modified header */
    write_header (new, &hdr, &auxhdr);
! 
    /* Close the binary file */
    close (old);
    close (new);
***************
*** 143,149 ****
    /* Write the entire data space out to the file */
    if (write (file, auxhdr->exec_dmem, size) != size)
      { perror ("Can't save new data space"); exit (1); }
!   
    /* Update the header to reflect the new data size */
    auxhdr->exec_dsize = size;
    auxhdr->exec_bsize = 0;
--- 143,149 ----
    /* Write the entire data space out to the file */
    if (write (file, auxhdr->exec_dmem, size) != size)
      { perror ("Can't save new data space"); exit (1); }
! 
    /* Update the header to reflect the new data size */
    auxhdr->exec_dsize = size;
    auxhdr->exec_bsize = 0;
***************
*** 160,169 ****
  {
    struct subspace_dictionary_record subspace;
    int i;
!   
    /* Increase the overall size of the module */
    hdr->som_length += offset;
!   
    /* Update the various file pointers in the header */
  #define update(ptr) if (ptr > location) ptr = ptr + offset
    update (hdr->aux_header_location);
--- 160,169 ----
  {
    struct subspace_dictionary_record subspace;
    int i;
! 
    /* Increase the overall size of the module */
    hdr->som_length += offset;
! 
    /* Update the various file pointers in the header */
  #define update(ptr) if (ptr > location) ptr = ptr + offset
    update (hdr->aux_header_location);
***************
*** 176,191 ****
    update (hdr->unloadable_sp_location);
    update (auxhdr->exec_tfile);
    update (auxhdr->exec_dfile);
!   
    /* Do for each subspace dictionary entry */
    lseek (file, hdr->subspace_location, 0);
    for (i = 0; i < hdr->subspace_total; i++)
      {
        if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace))
        { perror ("Can't read subspace record"); exit (1); }
!       
        /* If subspace has a file location, update it */
!       if (subspace.initialization_length > 0 
          && subspace.file_loc_init_value > location)
        {
          subspace.file_loc_init_value += offset;
--- 176,191 ----
    update (hdr->unloadable_sp_location);
    update (auxhdr->exec_tfile);
    update (auxhdr->exec_dfile);
! 
    /* Do for each subspace dictionary entry */
    lseek (file, hdr->subspace_location, 0);
    for (i = 0; i < hdr->subspace_total; i++)
      {
        if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace))
        { perror ("Can't read subspace record"); exit (1); }
! 
        /* If subspace has a file location, update it */
!       if (subspace.initialization_length > 0
          && subspace.file_loc_init_value > location)
        {
          subspace.file_loc_init_value += offset;
***************
*** 193,200 ****
          if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace))
            { perror ("Can't update subspace record"); exit (1); }
        }
!     } 
!   
    /* Do for each initialization pointer record */
    /* (I don't think it applies to executable files, only relocatables) */
  #undef update
--- 193,200 ----
          if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace))
            { perror ("Can't update subspace record"); exit (1); }
        }
!     }
! 
    /* Do for each initialization pointer record */
    /* (I don't think it applies to executable files, only relocatables) */
  #undef update
***************
*** 207,231 ****
       struct header *hdr;
       struct som_exec_auxhdr *auxhdr;
  {
!   
    /* Read the header in */
    lseek (file, 0, 0);
    if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
      { perror ("Couldn't read header from a.out file"); exit (1); }
!   
    if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC
        &&  hdr->a_magic != DEMAND_MAGIC)
      {
!       fprintf (stderr, "a.out file doesn't have legal magic number\n"); 
!       exit (1);  
      }
!   
    lseek (file, hdr->aux_header_location, 0);
    if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr))
      {
        perror ("Couldn't read auxiliary header from a.out file");
        exit (1);
!     }  
  }
  
  /* Write out the header records into an a.out file.  */
--- 207,231 ----
       struct header *hdr;
       struct som_exec_auxhdr *auxhdr;
  {
! 
    /* Read the header in */
    lseek (file, 0, 0);
    if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
      { perror ("Couldn't read header from a.out file"); exit (1); }
! 
    if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC
        &&  hdr->a_magic != DEMAND_MAGIC)
      {
!       fprintf (stderr, "a.out file doesn't have legal magic number\n");
!       exit (1);
      }
! 
    lseek (file, hdr->aux_header_location, 0);
    if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr))
      {
        perror ("Couldn't read auxiliary header from a.out file");
        exit (1);
!     }
  }
  
  /* Write out the header records into an a.out file.  */
***************
*** 237,243 ****
  {
    /* Update the checksum */
    hdr->checksum = calculate_checksum (hdr);
!   
    /* Write the header back into the a.out file */
    lseek (file, 0, 0);
    if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
--- 237,243 ----
  {
    /* Update the checksum */
    hdr->checksum = calculate_checksum (hdr);
! 
    /* Write the header back into the a.out file */
    lseek (file, 0, 0);
    if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr))
***************
*** 253,264 ****
       struct header *hdr;
  {
    int checksum, i, *ptr;
!   
    checksum = 0;  ptr = (int *) hdr;
!   
    for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++)
      checksum ^= ptr[i];
!   
    return (checksum);
  }
  
--- 253,264 ----
       struct header *hdr;
  {
    int checksum, i, *ptr;
! 
    checksum = 0;  ptr = (int *) hdr;
! 
    for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++)
      checksum ^= ptr[i];
! 
    return (checksum);
  }
  
***************
*** 270,276 ****
  {
    int len;
    int buffer[8192];  /* word aligned will be faster */
!   
    for (; size > 0; size -= len)
      {
        len = min (size, sizeof (buffer));
--- 270,276 ----
  {
    int len;
    int buffer[8192];  /* word aligned will be faster */
! 
    for (; size > 0; size -= len)
      {
        len = min (size, sizeof (buffer));
***************
*** 288,298 ****
  {
    int buffer[4096];
    int len;
!   
    /* Copy bytes until end of file or error */
    while ((len = read (old, buffer, sizeof (buffer))) > 0)
      if (write (new, buffer, len) != len) break;
!   
    if (len != 0)
      { perror ("Unable to copy the rest of the file"); exit (1); }
  }
--- 288,298 ----
  {
    int buffer[4096];
    int len;
! 
    /* Copy bytes until end of file or error */
    while ((len = read (old, buffer, sizeof (buffer))) > 0)
      if (write (new, buffer, len) != len) break;
! 
    if (len != 0)
      { perror ("Unable to copy the rest of the file"); exit (1); }
  }
***************
*** 304,310 ****
  {
    /* Display the header information (debug) */
    printf ("\n\nFILE HEADER\n");
!   printf ("magic number %d \n", hdr->a_magic); 
    printf ("text loc %.8x   size %d \n", auxhdr->exec_tmem, 
auxhdr->exec_tsize);
    printf ("data loc %.8x   size %d \n", auxhdr->exec_dmem, 
auxhdr->exec_dsize);
    printf ("entry     %x \n",   auxhdr->exec_entry);
--- 304,310 ----
  {
    /* Display the header information (debug) */
    printf ("\n\nFILE HEADER\n");
!   printf ("magic number %d \n", hdr->a_magic);
    printf ("text loc %.8x   size %d \n", auxhdr->exec_tmem, 
auxhdr->exec_tsize);
    printf ("data loc %.8x   size %d \n", auxhdr->exec_dmem, 
auxhdr->exec_dsize);
    printf ("entry     %x \n",   auxhdr->exec_entry);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]