Mercurial > hg > xemacs-beta
annotate src/unexhp9k800.c @ 5127:a9c41067dd88 ben-lisp-object
more cleanups, terminology clarification, lots of doc work
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* internals/internals.texi (Introduction to Allocation):
* internals/internals.texi (Integers and Characters):
* internals/internals.texi (Allocation from Frob Blocks):
* internals/internals.texi (lrecords):
* internals/internals.texi (Low-level allocation):
Rewrite section on allocation of Lisp objects to reflect the new
reality. Remove references to nonexistent XSETINT and XSETCHAR.
modules/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* postgresql/postgresql.c (allocate_pgconn):
* postgresql/postgresql.c (allocate_pgresult):
* postgresql/postgresql.h (struct Lisp_PGconn):
* postgresql/postgresql.h (struct Lisp_PGresult):
* ldap/eldap.c (allocate_ldap):
* ldap/eldap.h (struct Lisp_LDAP):
Same changes as in src/ dir. See large log there in ChangeLog,
but basically:
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
../hlo/src/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (old_alloc_sized_lcrecord):
* alloc.c (very_old_free_lcrecord):
* alloc.c (copy_lisp_object):
* alloc.c (zero_sized_lisp_object):
* alloc.c (zero_nonsized_lisp_object):
* alloc.c (lisp_object_storage_size):
* alloc.c (free_normal_lisp_object):
* alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC):
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT):
* alloc.c (Fcons):
* alloc.c (noseeum_cons):
* alloc.c (make_float):
* alloc.c (make_bignum):
* alloc.c (make_bignum_bg):
* alloc.c (make_ratio):
* alloc.c (make_ratio_bg):
* alloc.c (make_ratio_rt):
* alloc.c (make_bigfloat):
* alloc.c (make_bigfloat_bf):
* alloc.c (size_vector):
* alloc.c (make_compiled_function):
* alloc.c (Fmake_symbol):
* alloc.c (allocate_extent):
* alloc.c (allocate_event):
* alloc.c (make_key_data):
* alloc.c (make_button_data):
* alloc.c (make_motion_data):
* alloc.c (make_process_data):
* alloc.c (make_timeout_data):
* alloc.c (make_magic_data):
* alloc.c (make_magic_eval_data):
* alloc.c (make_eval_data):
* alloc.c (make_misc_user_data):
* alloc.c (Fmake_marker):
* alloc.c (noseeum_make_marker):
* alloc.c (size_string_direct_data):
* alloc.c (make_uninit_string):
* alloc.c (make_string_nocopy):
* alloc.c (mark_lcrecord_list):
* alloc.c (alloc_managed_lcrecord):
* alloc.c (free_managed_lcrecord):
* alloc.c (sweep_lcrecords_1):
* alloc.c (malloced_storage_size):
* buffer.c (allocate_buffer):
* buffer.c (compute_buffer_usage):
* buffer.c (DEFVAR_BUFFER_LOCAL_1):
* buffer.c (nuke_all_buffer_slots):
* buffer.c (common_init_complex_vars_of_buffer):
* buffer.h (struct buffer_text):
* buffer.h (struct buffer):
* bytecode.c:
* bytecode.c (make_compiled_function_args):
* bytecode.c (size_compiled_function_args):
* bytecode.h (struct compiled_function_args):
* casetab.c (allocate_case_table):
* casetab.h (struct Lisp_Case_Table):
* charset.h (struct Lisp_Charset):
* chartab.c (fill_char_table):
* chartab.c (Fmake_char_table):
* chartab.c (make_char_table_entry):
* chartab.c (copy_char_table_entry):
* chartab.c (Fcopy_char_table):
* chartab.c (put_char_table):
* chartab.h (struct Lisp_Char_Table_Entry):
* chartab.h (struct Lisp_Char_Table):
* console-gtk-impl.h (struct gtk_device):
* console-gtk-impl.h (struct gtk_frame):
* console-impl.h (struct console):
* console-msw-impl.h (struct Lisp_Devmode):
* console-msw-impl.h (struct mswindows_device):
* console-msw-impl.h (struct msprinter_device):
* console-msw-impl.h (struct mswindows_frame):
* console-msw-impl.h (struct mswindows_dialog_id):
* console-stream-impl.h (struct stream_console):
* console-stream.c (stream_init_console):
* console-tty-impl.h (struct tty_console):
* console-tty-impl.h (struct tty_device):
* console-tty.c (allocate_tty_console_struct):
* console-x-impl.h (struct x_device):
* console-x-impl.h (struct x_frame):
* console.c (allocate_console):
* console.c (nuke_all_console_slots):
* console.c (DEFVAR_CONSOLE_LOCAL_1):
* console.c (common_init_complex_vars_of_console):
* data.c (make_weak_list):
* data.c (make_weak_box):
* data.c (make_ephemeron):
* database.c:
* database.c (struct Lisp_Database):
* database.c (allocate_database):
* database.c (finalize_database):
* device-gtk.c (allocate_gtk_device_struct):
* device-impl.h (struct device):
* device-msw.c:
* device-msw.c (mswindows_init_device):
* device-msw.c (msprinter_init_device):
* device-msw.c (finalize_devmode):
* device-msw.c (allocate_devmode):
* device-tty.c (allocate_tty_device_struct):
* device-x.c (allocate_x_device_struct):
* device.c:
* device.c (nuke_all_device_slots):
* device.c (allocate_device):
* dialog-msw.c (handle_question_dialog_box):
* elhash.c:
* elhash.c (struct Lisp_Hash_Table):
* elhash.c (finalize_hash_table):
* elhash.c (make_general_lisp_hash_table):
* elhash.c (Fcopy_hash_table):
* elhash.h (htentry):
* emacs.c (main_1):
* eval.c:
* eval.c (size_multiple_value):
* event-stream.c (finalize_command_builder):
* event-stream.c (allocate_command_builder):
* event-stream.c (free_command_builder):
* event-stream.c (event_stream_generate_wakeup):
* event-stream.c (event_stream_resignal_wakeup):
* event-stream.c (event_stream_disable_wakeup):
* event-stream.c (event_stream_wakeup_pending_p):
* events.h (struct Lisp_Timeout):
* events.h (struct command_builder):
* extents-impl.h:
* extents-impl.h (struct extent_auxiliary):
* extents-impl.h (struct extent_info):
* extents-impl.h (set_extent_no_chase_aux_field):
* extents-impl.h (set_extent_no_chase_normal_field):
* extents.c:
* extents.c (gap_array_marker):
* extents.c (gap_array):
* extents.c (extent_list_marker):
* extents.c (extent_list):
* extents.c (stack_of_extents):
* extents.c (gap_array_make_marker):
* extents.c (extent_list_make_marker):
* extents.c (allocate_extent_list):
* extents.c (SLOT):
* extents.c (mark_extent_auxiliary):
* extents.c (allocate_extent_auxiliary):
* extents.c (attach_extent_auxiliary):
* extents.c (size_gap_array):
* extents.c (finalize_extent_info):
* extents.c (allocate_extent_info):
* extents.c (uninit_buffer_extents):
* extents.c (allocate_soe):
* extents.c (copy_extent):
* extents.c (vars_of_extents):
* extents.h:
* faces.c (allocate_face):
* faces.h (struct Lisp_Face):
* faces.h (struct face_cachel):
* file-coding.c:
* file-coding.c (finalize_coding_system):
* file-coding.c (sizeof_coding_system):
* file-coding.c (Fcopy_coding_system):
* file-coding.h (struct Lisp_Coding_System):
* file-coding.h (MARKED_SLOT):
* fns.c (size_bit_vector):
* font-mgr.c:
* font-mgr.c (finalize_fc_pattern):
* font-mgr.c (print_fc_pattern):
* font-mgr.c (Ffc_pattern_p):
* font-mgr.c (Ffc_pattern_create):
* font-mgr.c (Ffc_name_parse):
* font-mgr.c (Ffc_name_unparse):
* font-mgr.c (Ffc_pattern_duplicate):
* font-mgr.c (Ffc_pattern_add):
* font-mgr.c (Ffc_pattern_del):
* font-mgr.c (Ffc_pattern_get):
* font-mgr.c (fc_config_create_using):
* font-mgr.c (fc_strlist_to_lisp_using):
* font-mgr.c (fontset_to_list):
* font-mgr.c (Ffc_config_p):
* font-mgr.c (Ffc_config_up_to_date):
* font-mgr.c (Ffc_config_build_fonts):
* font-mgr.c (Ffc_config_get_cache):
* font-mgr.c (Ffc_config_get_fonts):
* font-mgr.c (Ffc_config_set_current):
* font-mgr.c (Ffc_config_get_blanks):
* font-mgr.c (Ffc_config_get_rescan_interval):
* font-mgr.c (Ffc_config_set_rescan_interval):
* font-mgr.c (Ffc_config_app_font_add_file):
* font-mgr.c (Ffc_config_app_font_add_dir):
* font-mgr.c (Ffc_config_app_font_clear):
* font-mgr.c (size):
* font-mgr.c (Ffc_config_substitute):
* font-mgr.c (Ffc_font_render_prepare):
* font-mgr.c (Ffc_font_match):
* font-mgr.c (Ffc_font_sort):
* font-mgr.c (finalize_fc_config):
* font-mgr.c (print_fc_config):
* font-mgr.h:
* font-mgr.h (struct fc_pattern):
* font-mgr.h (XFC_PATTERN):
* font-mgr.h (struct fc_config):
* font-mgr.h (XFC_CONFIG):
* frame-gtk.c (allocate_gtk_frame_struct):
* frame-impl.h (struct frame):
* frame-msw.c (mswindows_init_frame_1):
* frame-x.c (allocate_x_frame_struct):
* frame.c (nuke_all_frame_slots):
* frame.c (allocate_frame_core):
* gc.c:
* gc.c (GC_CHECK_NOT_FREE):
* glyphs.c (finalize_image_instance):
* glyphs.c (allocate_image_instance):
* glyphs.c (Fcolorize_image_instance):
* glyphs.c (allocate_glyph):
* glyphs.c (unmap_subwindow_instance_cache_mapper):
* glyphs.c (register_ignored_expose):
* glyphs.h (struct Lisp_Image_Instance):
* glyphs.h (struct Lisp_Glyph):
* glyphs.h (struct glyph_cachel):
* glyphs.h (struct expose_ignore):
* gui.c (allocate_gui_item):
* gui.h (struct Lisp_Gui_Item):
* keymap.c (struct Lisp_Keymap):
* keymap.c (make_keymap):
* lisp.h:
* lisp.h (struct Lisp_String_Direct_Data):
* lisp.h (struct Lisp_String_Indirect_Data):
* lisp.h (struct Lisp_Vector):
* lisp.h (struct Lisp_Bit_Vector):
* lisp.h (DECLARE_INLINE_LISP_BIT_VECTOR):
* lisp.h (struct weak_box):
* lisp.h (struct ephemeron):
* lisp.h (struct weak_list):
* lrecord.h:
* lrecord.h (struct lrecord_implementation):
* lrecord.h (MC_ALLOC_CALL_FINALIZER):
* lrecord.h (struct lcrecord_list):
* lstream.c (finalize_lstream):
* lstream.c (sizeof_lstream):
* lstream.c (Lstream_new):
* lstream.c (Lstream_delete):
* lstream.h (struct lstream):
* marker.c:
* marker.c (finalize_marker):
* marker.c (compute_buffer_marker_usage):
* mule-charset.c:
* mule-charset.c (make_charset):
* mule-charset.c (compute_charset_usage):
* objects-impl.h (struct Lisp_Color_Instance):
* objects-impl.h (struct Lisp_Font_Instance):
* objects-tty-impl.h (struct tty_color_instance_data):
* objects-tty-impl.h (struct tty_font_instance_data):
* objects-tty.c (tty_initialize_color_instance):
* objects-tty.c (tty_initialize_font_instance):
* objects.c (finalize_color_instance):
* objects.c (Fmake_color_instance):
* objects.c (finalize_font_instance):
* objects.c (Fmake_font_instance):
* objects.c (reinit_vars_of_objects):
* opaque.c:
* opaque.c (sizeof_opaque):
* opaque.c (make_opaque_ptr):
* opaque.c (free_opaque_ptr):
* opaque.h:
* opaque.h (Lisp_Opaque):
* opaque.h (Lisp_Opaque_Ptr):
* print.c (printing_unreadable_lcrecord):
* print.c (external_object_printer):
* print.c (debug_p4):
* process.c (finalize_process):
* process.c (make_process_internal):
* procimpl.h (struct Lisp_Process):
* rangetab.c (Fmake_range_table):
* rangetab.c (Fcopy_range_table):
* rangetab.h (struct Lisp_Range_Table):
* scrollbar.c:
* scrollbar.c (create_scrollbar_instance):
* scrollbar.c (compute_scrollbar_instance_usage):
* scrollbar.h (struct scrollbar_instance):
* specifier.c (finalize_specifier):
* specifier.c (sizeof_specifier):
* specifier.c (set_specifier_caching):
* specifier.h (struct Lisp_Specifier):
* specifier.h (struct specifier_caching):
* symeval.h:
* symeval.h (SYMBOL_VALUE_MAGIC_P):
* symeval.h (DEFVAR_SYMVAL_FWD):
* symsinit.h:
* syntax.c (init_buffer_syntax_cache):
* syntax.h (struct syntax_cache):
* toolbar.c:
* toolbar.c (allocate_toolbar_button):
* toolbar.c (update_toolbar_button):
* toolbar.h (struct toolbar_button):
* tooltalk.c (struct Lisp_Tooltalk_Message):
* tooltalk.c (make_tooltalk_message):
* tooltalk.c (struct Lisp_Tooltalk_Pattern):
* tooltalk.c (make_tooltalk_pattern):
* ui-gtk.c:
* ui-gtk.c (allocate_ffi_data):
* ui-gtk.c (emacs_gtk_object_finalizer):
* ui-gtk.c (allocate_emacs_gtk_object_data):
* ui-gtk.c (allocate_emacs_gtk_boxed_data):
* ui-gtk.h:
* window-impl.h (struct window):
* window-impl.h (struct window_mirror):
* window.c (finalize_window):
* window.c (allocate_window):
* window.c (new_window_mirror):
* window.c (mark_window_as_deleted):
* window.c (make_dummy_parent):
* window.c (compute_window_mirror_usage):
* window.c (compute_window_usage):
Overall point of this change and previous ones in this repository:
(1) Introduce new, clearer terminology: everything other than int
or char is a "record" object, which comes in two types: "normal
objects" and "frob-block objects". Fix up all places that
referred to frob-block objects as "simple", "basic", etc.
(2) Provide an advertised interface for doing operations on Lisp
objects, including creating new types, that is clean and
consistent in its naming, uses the above-referenced terms and
avoids referencing "lrecords", "old lcrecords", etc., which should
hide under the surface.
(3) Make the size_in_bytes and finalizer methods take a
Lisp_Object rather than a void * for consistency with other methods.
(4) Separate finalizer method into finalizer and disksaver, so
that normal finalize methods don't have to worry about disksaving.
Other specifics:
(1) Renaming:
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
implementation->basic_p -> implementation->frob_block_p
ALLOCATE_FIXED_TYPE_AND_SET_IMPL -> ALLOC_FROB_BLOCK_LISP_OBJECT
*FCCONFIG*, wrap_fcconfig -> *FC_CONFIG*, wrap_fc_config
*FCPATTERN*, wrap_fcpattern -> *FC_PATTERN*, wrap_fc_pattern
(the last two changes make the naming of these macros consistent
with the naming of all other macros, since the objects are named
fc-config and fc-pattern with a hyphen)
(2) Lots of documentation fixes in lrecord.h.
(3) Eliminate macros for copying, freeing, zeroing objects, getting
their storage size. Instead, new functions:
zero_sized_lisp_object()
zero_nonsized_lisp_object()
lisp_object_storage_size()
free_normal_lisp_object()
(copy_lisp_object() already exists)
LISP_OBJECT_FROB_BLOCK_P() (actually a macro)
Eliminated:
free_lrecord()
zero_lrecord()
copy_lrecord()
copy_sized_lrecord()
old_copy_lcrecord()
old_copy_sized_lcrecord()
old_zero_lcrecord()
old_zero_sized_lcrecord()
LISP_OBJECT_STORAGE_SIZE()
COPY_SIZED_LISP_OBJECT()
COPY_SIZED_LCRECORD()
COPY_LISP_OBJECT()
ZERO_LISP_OBJECT()
FREE_LISP_OBJECT()
(4) Catch the remaining places where lrecord stuff was used directly
and use the advertised interface, e.g. alloc_sized_lrecord() ->
ALLOC_SIZED_LISP_OBJECT().
(5) Make certain statically-declared pseudo-objects
(buffer_local_flags, console_local_flags) have their lheader
initialized correctly, so things like copy_lisp_object() can work
on them. Make extent_auxiliary_defaults a proper heap object
Vextent_auxiliary_defaults, and make extent auxiliaries dumpable
so that this object can be dumped. allocate_extent_auxiliary()
now just creates the object, and attach_extent_auxiliary()
creates an extent auxiliary and attaches to an extent, like the
old allocate_extent_auxiliary().
(6) Create EXTENT_AUXILIARY_SLOTS macro, similar to the foo-slots.h
files but in a macro instead of a file. The purpose is to avoid
duplication when iterating over all the slots in an extent auxiliary.
Use it.
(7) In lstream.c, don't zero out object after allocation because
allocation routines take care of this.
(8) In marker.c, fix a mistake in computing marker overhead.
(9) In print.c, clean up printing_unreadable_lcrecord(),
external_object_printer() to avoid lots of ifdef NEW_GC's.
(10) Separate toolbar-button allocation into a separate
allocate_toolbar_button() function for use in the example code
in lrecord.h.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 05 Mar 2010 04:08:17 -0600 |
parents | facf3239ba30 |
children | 308d34e9f07d |
rev | line source |
---|---|
428 | 1 /* Unexec for HP 9000 Series 800 machines. |
2 Bob Desinger <hpsemc!bd@hplabs.hp.com> | |
3 | |
4 This file is part of XEmacs. | |
5 | |
6 XEmacs is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) any | |
9 later version. | |
10 | |
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with XEmacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Synched up with: Not synched with FSF. */ | |
22 | |
23 /* | |
24 | |
25 Unexec creates a copy of the old a.out file, and replaces the old data | |
26 area with the current data area. When the new file is executed, the | |
27 process will see the same data structures and data values that the | |
28 original process had when unexec was called. | |
29 | |
30 Unlike other versions of unexec, this one copies symbol table and | |
31 debug information to the new a.out file. Thus, the new a.out file | |
32 may be debugged with symbolic debuggers. | |
33 | |
34 If you fix any bugs in this, I'd like to incorporate your fixes. | |
35 Send them to uunet!hpda!hpsemc!jmorris or jmorris%hpsemc@hplabs.HP.COM. | |
36 | |
37 CAVEATS: | |
38 This routine saves the current value of all static and external | |
39 variables. This means that any data structure that needs to be | |
40 initialized must be explicitly reset. Variables will not have their | |
41 expected default values. | |
42 | |
43 Unfortunately, the HP-UX signal handler has internal initialization | |
44 flags which are not explicitly reset. Thus, for signals to work in | |
45 conjunction with this routine, the following code must executed when | |
46 the new process starts up. | |
47 | |
48 void _sigreturn(); | |
49 ... | |
50 sigsetreturn(_sigreturn); | |
51 */ | |
52 | |
53 | |
54 #include <config.h> | |
430 | 55 #include <stdlib.h> |
428 | 56 #include <stdio.h> |
57 #include <fcntl.h> | |
58 #include <errno.h> | |
59 | |
60 #include <a.out.h> | |
442 | 61 #include "lisp.h" |
428 | 62 |
63 /* | |
64 * Minor modification to enable dumping with shared libraries added by | |
65 * Dipankar Gupta (dg@hplb.hpl.hp.com). I studied Oliver Laumann's | |
66 * more elaborate dynamic loading scheme in ELK while implementing | |
67 * this, but don't use any of his machinery. | |
68 * | |
69 * Stores the BRK value at dump time, and uses the RUN_TIME_REMAP hook | |
70 * to break back to the stored value when the dumped executable is restarted. | |
71 * | |
72 * CAVEATS (addenda): | |
73 * 1. Text area of the shlibs are not stored. Thus, if a shared library is | |
74 * replaced between the time of dump and execution, all bets are off. | |
75 * | |
76 * 2. Assumes that the data and bss area are adjacent, which is true of the | |
77 * current VM implementation. | |
78 * | |
79 * 3. Any setup that defines HPUX_USE_SHLIBS *must* also define | |
80 * RUN_TIME_REMAP. | |
81 */ | |
82 | |
83 #ifdef HPUX_USE_SHLIBS | |
84 #include <dl.h> /* User-space dynamic loader entry points */ | |
442 | 85 static void Save_Shared_Data (void); |
86 static void Restore_Shared_Data (void); | |
428 | 87 #endif |
88 | |
89 void write_header(int file, struct header *hdr, struct som_exec_auxhdr *auxhdr); | |
90 void read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr); | |
91 void save_data_space (int file, struct header *hdr, | |
92 struct som_exec_auxhdr *auxhdr, int size); | |
3025 | 93 void copy_rest (int old, int new_); |
94 void copy_file (int old, int new_, int size); | |
428 | 95 void update_file_ptrs(int file, struct header *hdr, |
96 struct som_exec_auxhdr *auxhdr, | |
97 unsigned int location, int offset); | |
98 int calculate_checksum(struct header *hdr); | |
99 | |
100 /* Create a new a.out file, same as old but with current data space */ | |
101 int | |
442 | 102 unexec (char *new_name, /* name of the new a.out file to be created */ |
103 char *old_name, /* name of the old a.out file */ | |
2286 | 104 uintptr_t UNUSED (new_end_of_text), /* ptr to new edata/etext */ |
105 uintptr_t UNUSED (dummy1), /* not used by emacs */ | |
106 uintptr_t UNUSED (dummy2)) | |
428 | 107 { |
3025 | 108 int old, new_; |
428 | 109 int old_size, new_size; |
110 struct header hdr; | |
111 struct som_exec_auxhdr auxhdr; | |
112 long i; | |
113 | |
114 /* For the greatest flexibility, should create a temporary file in | |
115 the same directory as the new file. When everything is complete, | |
116 rename the temp file to the new name. | |
117 This way, a program could update its own a.out file even while | |
118 it is still executing. If problems occur, everything is still | |
119 intact. NOT implemented. */ | |
120 | |
121 /* Open the input and output a.out files */ | |
122 old = open (old_name, O_RDONLY); | |
123 if (old < 0) | |
124 { perror(old_name); exit(1); } | |
3025 | 125 new_ = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); |
126 if (new_ < 0) | |
428 | 127 { perror(new_name); exit(1); } |
128 | |
129 /* Read the old headers */ | |
130 read_header(old, &hdr, &auxhdr); | |
131 | |
132 #ifdef HPUX_USE_SHLIBS | |
133 Save_Shared_Data(); /* Save break value (added: dg@hplb.hpl.hp.com) */ | |
134 #endif | |
135 /* Decide how large the new and old data areas are */ | |
136 old_size = auxhdr.exec_dsize; | |
137 /* I suspect these two statements are separate | |
138 to avoid a compiler bug in hpux version 8. */ | |
139 i = (long) sbrk (0); | |
140 new_size = i - auxhdr.exec_dmem; | |
141 | |
142 /* Copy the old file to the new, up to the data space */ | |
143 lseek(old, 0, 0); | |
3025 | 144 copy_file(old, new_, auxhdr.exec_dfile); |
428 | 145 |
146 /* Skip the old data segment and write a new one */ | |
147 lseek(old, old_size, 1); | |
3025 | 148 save_data_space(new_, &hdr, &auxhdr, new_size); |
428 | 149 |
150 /* Copy the rest of the file */ | |
3025 | 151 copy_rest(old, new_); |
428 | 152 |
153 /* Update file pointers since we probably changed size of data area */ | |
3025 | 154 update_file_ptrs(new_, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size); |
428 | 155 |
156 /* Save the modified header */ | |
3025 | 157 write_header(new_, &hdr, &auxhdr); |
428 | 158 |
159 /* Close the binary file */ | |
160 close (old); | |
3025 | 161 close (new_); |
428 | 162 return 0; |
163 } | |
164 | |
165 /* Save current data space in the file, update header. */ | |
166 | |
167 void | |
2286 | 168 save_data_space (int file, struct header *UNUSED (hdr), |
428 | 169 struct som_exec_auxhdr *auxhdr, int size) |
170 { | |
171 /* Write the entire data space out to the file */ | |
172 if (write(file, (void *)auxhdr->exec_dmem, size) != size) | |
173 { perror("Can't save new data space"); exit(1); } | |
174 | |
175 /* Update the header to reflect the new data size */ | |
176 auxhdr->exec_dsize = size; | |
177 auxhdr->exec_bsize = 0; | |
178 } | |
179 | |
180 /* Update the values of file pointers when something is inserted. */ | |
181 | |
182 void | |
183 update_file_ptrs(int file, struct header *hdr, | |
184 struct som_exec_auxhdr *auxhdr, | |
185 unsigned int location, int offset) | |
186 { | |
187 struct subspace_dictionary_record subspace; | |
188 int i; | |
189 | |
190 /* Increase the overall size of the module */ | |
191 hdr->som_length += offset; | |
192 | |
193 /* Update the various file pointers in the header */ | |
194 #define update(ptr) if (ptr > location) ptr = ptr + offset | |
195 update(hdr->aux_header_location); | |
196 update(hdr->space_strings_location); | |
197 update(hdr->init_array_location); | |
198 update(hdr->compiler_location); | |
199 update(hdr->symbol_location); | |
200 update(hdr->fixup_request_location); | |
201 update(hdr->symbol_strings_location); | |
202 update(hdr->unloadable_sp_location); | |
203 update(auxhdr->exec_tfile); | |
204 update(auxhdr->exec_dfile); | |
205 | |
206 /* Do for each subspace dictionary entry */ | |
207 lseek(file, hdr->subspace_location, 0); | |
208 for (i = 0; i < hdr->subspace_total; i++) | |
209 { | |
210 if (read(file, &subspace, sizeof(subspace)) != sizeof(subspace)) | |
211 { perror("Can't read subspace record"); exit(1); } | |
212 | |
213 /* If subspace has a file location, update it */ | |
214 if (subspace.initialization_length > 0 | |
215 && subspace.file_loc_init_value > location) | |
216 { | |
217 subspace.file_loc_init_value += offset; | |
218 lseek(file, -sizeof(subspace), 1); | |
219 if (write(file, &subspace, sizeof(subspace)) != sizeof(subspace)) | |
220 { perror("Can't update subspace record"); exit(1); } | |
221 } | |
222 } | |
223 | |
224 /* Do for each initialization pointer record */ | |
225 /* (I don't think it applies to executable files, only relocatables) */ | |
226 #undef update | |
227 } | |
228 | |
229 /* Read in the header records from an a.out file. */ | |
230 | |
231 void | |
232 read_header(int file, struct header *hdr, struct som_exec_auxhdr *auxhdr) | |
233 { | |
234 | |
235 /* Read the header in */ | |
236 lseek(file, 0, 0); | |
237 if (read(file, hdr, sizeof(*hdr)) != sizeof(*hdr)) | |
238 { perror("Couldn't read header from a.out file"); exit(1); } | |
239 | |
240 if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC | |
241 && hdr->a_magic != DEMAND_MAGIC) | |
242 { | |
243 fprintf(stderr, "a.out file doesn't have legal magic number\n"); | |
244 exit(1); | |
245 } | |
246 | |
247 lseek(file, hdr->aux_header_location, 0); | |
248 if (read(file, auxhdr, sizeof(*auxhdr)) != sizeof(*auxhdr)) | |
249 { | |
250 perror("Couldn't read auxiliary header from a.out file"); | |
251 exit(1); | |
252 } | |
253 } | |
254 | |
255 /* Write out the header records into an a.out file. */ | |
256 void | |
257 write_header(int file, struct header *hdr, struct som_exec_auxhdr *auxhdr) | |
258 { | |
259 /* Update the checksum */ | |
260 hdr->checksum = calculate_checksum(hdr); | |
261 | |
262 /* Write the header back into the a.out file */ | |
263 lseek(file, 0, 0); | |
264 if (write(file, hdr, sizeof(*hdr)) != sizeof(*hdr)) | |
265 { perror("Couldn't write header to a.out file"); exit(1); } | |
266 lseek(file, hdr->aux_header_location, 0); | |
267 if (write(file, auxhdr, sizeof(*auxhdr)) != sizeof(*auxhdr)) | |
268 { perror("Couldn't write auxiliary header to a.out file"); exit(1); } | |
269 } | |
270 | |
271 /* Calculate the checksum of a SOM header record. */ | |
272 int | |
273 calculate_checksum(struct header *hdr) | |
274 { | |
275 int checksum, i, *ptr; | |
276 | |
277 checksum = 0; ptr = (int *) hdr; | |
278 | |
279 for (i=0; i<sizeof(*hdr)/sizeof(int)-1; i++) | |
280 checksum ^= ptr[i]; | |
281 | |
282 return(checksum); | |
283 } | |
284 | |
285 /* Copy size bytes from the old file to the new one. */ | |
286 void | |
3025 | 287 copy_file (int old, int new_, int size) |
428 | 288 { |
289 int len; | |
290 int buffer[8192]; /* word aligned will be faster */ | |
291 | |
292 for (; size > 0; size -= len) | |
293 { | |
442 | 294 len = size < sizeof (buffer) ? size : sizeof (buffer); |
295 if (read (old, buffer, len) != len) | |
296 { | |
297 perror ("Read failure on a.out file"); | |
298 exit (1); | |
299 } | |
3025 | 300 if (write (new_, buffer, len) != len) |
442 | 301 { |
302 perror ("Write failure in a.out file"); | |
303 exit (1); | |
304 } | |
428 | 305 } |
306 } | |
307 | |
308 /* Copy the rest of the file, up to EOF. */ | |
309 void | |
3025 | 310 copy_rest (int old, int new_) |
428 | 311 { |
312 int buffer[4096]; | |
313 int len; | |
314 | |
315 /* Copy bytes until end of file or error */ | |
316 while ( (len = read(old, buffer, sizeof(buffer))) > 0) | |
3025 | 317 if (write(new_, buffer, len) != len) break; |
428 | 318 |
319 if (len != 0) | |
320 { perror("Unable to copy the rest of the file"); exit(1); } | |
321 } | |
322 | |
323 #ifdef DEBUG | |
324 display_header(struct header *hdr, struct som_exec_auxhdr *auxhdr) | |
325 { | |
326 /* Display the header information (debug) */ | |
327 printf("\n\nFILE HEADER\n"); | |
328 printf("magic number %d \n", hdr->a_magic); | |
329 printf("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); | |
330 printf("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); | |
331 printf("entry %x \n", auxhdr->exec_entry); | |
332 printf("Bss segment size %u\n", auxhdr->exec_bsize); | |
333 printf("\n"); | |
334 printf("data file loc %d size %d\n", | |
335 auxhdr->exec_dfile, auxhdr->exec_dsize); | |
336 printf("som_length %d\n", hdr->som_length); | |
337 printf("unloadable sploc %d size %d\n", | |
338 hdr->unloadable_sp_location, hdr->unloadable_sp_size); | |
339 } | |
340 #endif /* DEBUG */ | |
341 | |
342 #ifdef HPUX_USE_SHLIBS | |
343 /* Added machinery for shared libs... see comments at the beginning of this file. */ | |
344 | |
345 void *Brk_On_Dump = 0; /* Brk value to restore... stored as a global */ | |
346 | |
442 | 347 static void |
348 Save_Shared_Data (void) | |
349 { | |
350 Brk_On_Dump = sbrk (0); | |
428 | 351 } |
352 | |
442 | 353 static void |
354 Restore_Shared_Data (void) | |
355 { | |
356 brk (Brk_On_Dump); | |
428 | 357 } |
358 | |
359 /* run_time_remap is the magic called by startup code in the dumped executable | |
442 | 360 if RUN_TIME_REMAP is set. */ |
361 int | |
2286 | 362 run_time_remap (char *UNUSED (dummy)) |
442 | 363 { |
364 Restore_Shared_Data (); | |
365 return 0; | |
366 } | |
428 | 367 #endif /* HPUX_USE_SHLIBS */ |