1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 *@@sourcefile debug.h:
30 * header file for debug.c (exception handling and debugging).
33 * Note: Version numbering in this file relates to XWorkplace version
36 *@@changed V0.9.0: included contents of newexe.h
38 *@@include #define INCL_BASE
39 *@@include #include <os2.h>
40 *@@include #include <stdio.h>
41 *@@include #include "helpers\debug.h"
45 * This file incorporates code from the following:
46 * -- Marc Fiammante, John Currier, Kim Rasmussen,
47 * Anthony Cruise (EXCEPT3.ZIP package for a generic
48 * exception handling DLL, available at Hobbes).
50 * This file Copyright (C) 1992-99 Ulrich M�ller,
56 * 2009-06-15 published under LGPL3 with Ulrich M�ller permission.
60 #ifndef DEBUG_HEADER_INCLUDED
61 #define DEBUG_HEADER_INCLUDED
63 /********************************************************************
65 * SYM file declarations
67 ********************************************************************/
69 // Pointer means offset from beginning of file or beginning of struct
74 unsigned short int ppNextMap
; // paragraph pointer to next map
75 unsigned char bFlags
; // symbol types
76 unsigned char bReserved1
; // reserved
77 unsigned short int pSegEntry
; // segment entry point value
78 unsigned short int cConsts
; // count of constants in map
79 unsigned short int pConstDef
; // pointer to constant chain
80 unsigned short int cSegs
; // count of segments in map
81 unsigned short int ppSegDef
; // paragraph pointer to first segment
82 unsigned char cbMaxSym
; // maximum symbol-name length
83 unsigned char cbModName
; // length of module name
84 char achModName
[1]; // cbModName Bytes of module-name member
89 unsigned short int ppNextMap
; // always zero
90 unsigned char release
; // release number (minor version number)
91 unsigned char version
; // major version number
96 unsigned short int ppNextSeg
; // paragraph pointer to next segment
97 unsigned short int cSymbols
; // count of symbols in list
98 unsigned short int pSymDef
; // offset of symbol chain
99 unsigned short int wReserved1
; // reserved
100 unsigned short int wReserved2
; // reserved
101 unsigned short int wReserved3
; // reserved
102 unsigned short int wReserved4
; // reserved
103 unsigned char bFlags
; // symbol types; bit 0 signals 32-bit (*UM)
104 unsigned char bReserved1
; // reserved
105 unsigned short int ppLineDef
; // offset of line number record
106 unsigned char bReserved2
; // reserved
107 unsigned char bReserved3
; // reserved
108 unsigned char cbSegName
; // length of segment name
109 char achSegName
[1]; /* cbSegName Bytes of segment-name member*/
114 unsigned short int wSymVal
; // symbol address or constant
115 unsigned char cbSymName
; // length of symbol name
116 char achSymName
[1]; // cbSymName Bytes of symbol-name member
121 unsigned int wSymVal
; // symbol address or constant
122 unsigned char cbSymName
; // length of symbol name
123 char achSymName
[1]; // cbSymName Bytes of symbol-name member
128 unsigned short int ppNextLine
; // ptr to next linedef (0 if last)
129 unsigned short int wReserved1
; // reserved
130 unsigned short int pLines
; // pointer to line numbers
131 unsigned short int cLines
; // reserved
132 unsigned char cbFileName
; // length of filename
133 char achFileName
[1];// cbFileName Bytes of filename
138 unsigned short int wCodeOffset
; // executable offset
139 unsigned short int dwFileOffset
; // source offset
142 #define SEGDEFOFFSET(MapDef) (MapDef.ppSegDef*16)
143 #define NEXTSEGDEFOFFSET(SegDef) (SegDef.ppNextSeg*16)
145 #define ASYMPTROFFSET(SegDefOffset,Segdef) (SegDefOffset+SegDef.pSymDef)
146 #define SYMDEFOFFSET(SegDefOffset,SegDef,n) (ASYMPTROFFSET(SegDefOffset,SegDef)+(n)*(sizeof(unsigned short int)))
148 #define ACONSTPTROFFSET(MapDef) (MapDef.ppConstDef)
149 #define CONSTDEFOFFSET(MapDef,n) ((MapDef.ppConstDef)+(n)*(sizeof(unsigned short int)))
151 #define LINEDEFOFFSET(SegDef) (SegDef.ppLineDef*16)
152 #define NEXTLINEDEFOFFSET(LineDef) (LineDef.ppNextLine*16)
153 #define LINESOFFSET(LinedefOffset,LineDef) ((LinedefOffset)+LineDef.pLines)
155 /********************************************************************
157 * EXE declarations taken from exe.h
159 ********************************************************************/
162 typedef unsigned short WORD
;
168 WORD eid
; // contains EXEID, below
169 WORD elast
; // # of bytes in last page
170 WORD epagsiz
; // # of pages in whole file
171 WORD erelcnt
; // # of relocation entrys
172 WORD ehdrsiz
; // size of header, in paragraphs
173 WORD eminfre
; // min # of free paragraphs needed
174 WORD emaxfre
; // max # of free paragraphs needed
175 WORD eiSS
; // initial SS value
176 WORD eiSP
; // initial SP value
177 WORD enegsum
; // negative sum of entire file
178 WORD eiIP
; // initial IP value
179 WORD eiCS
; // initial CS value
180 WORD ereloff
; // offset in file of relocation table
181 WORD eovlnum
; // number of the overlay
183 /* the following fields may not be present.
184 * ereloff = 28 not present
185 * = 30 exe.ever present and valid
186 * = 32 exe.ever field contains garbage
187 * ereloff > 32 exe.ever present and valid
188 * = 0 if "don't know"
191 WORD ever
; // version # of producing linker
194 /* the following fields may not be present - if the exe.ereloff
195 * value encompasses the fields then they are present and valid.
198 bbmask ebb
; // behavior bits
199 WORD dumy2
[7]; // must be 0 until defined
203 #define EXEID 0x5a4d // magic ID value
205 /********************************************************************
207 * Object Module Format (OMF) declarations
209 ********************************************************************/
213 BYTE signature
[2]; // Must be "MZ"
214 USHORT image_len
; // Image Length
215 USHORT pages
; // Pages
216 USHORT reloc_items
; // Relocation table items
217 USHORT min_paragraphs
; // Mininum 16-bytes paragraphs
218 USHORT max_paragraphs
; // Maximum 16-bytes paragraphs
219 USHORT stack_pos
; // Stack position
220 USHORT offset_in_sp
; // Offset in SP
221 USHORT checksum
; // Checksum
222 USHORT offset_in_ip
; // Offset in IP
223 USHORT code_pos
; // Code segment pos.
224 USHORT reloc_item_pos
; // Position of first relocation item
225 USHORT overlay_number
; // Overlay number
226 BYTE unused
[8]; // Unused bytes
227 USHORT oem_id
; // OEM Identifier
228 BYTE oem_info
[24]; // OEM Info
229 ULONG lexe_offset
; // Offset to linear header
234 BYTE signature
[2]; // Must be "LX"
235 BYTE b_ord
; // Byte ordering
236 BYTE w_ord
; // Word ordering
237 ULONG format_level
; // Format level
238 USHORT cpu_type
; // CPU Type
239 USHORT os_type
; // Operating system
240 ULONG module_version
; // Module version
241 ULONG mod_flags
; // Module flags
242 ULONG mod_pages
; // Module pages
243 ULONG EIP_object
; // EIP Object no.
244 ULONG EIP
; // EIP Value
245 ULONG ESP_object
; // ESP Object no
246 ULONG ESP
; // ESP Value
247 ULONG page_size
; // Page size
248 ULONG page_ofs_shift
; // Page offset shift
249 ULONG fixup_sect_size
; // Fixup section size
250 ULONG fixup_sect_checksum
; // Fixup section checksum
251 ULONG loader_sect_size
; // Loader section size
252 ULONG loader_sect_checksum
; // Loader section checksum
253 ULONG obj_table_ofs
; // Object table offset
254 ULONG obj_count
; // Object count
255 ULONG obj_page_tab_ofs
; // Object page table offset
256 ULONG obj_iter_page_ofs
; // Object iteration pages offset
257 ULONG res_tab_ofs
; // Resource table offset
258 ULONG res_table_entries
; // Resource table entries
259 ULONG res_name_tab_ofs
; // Resident name table offset;
260 ULONG ent_tab_ofs
; // Entry table offset
261 ULONG mod_dir_ofs
; // Module directives offset
262 ULONG mod_dir_count
; // Number of module directives
263 ULONG fixup_page_tab_ofs
; // Fixup page table offset
264 ULONG fixup_rec_tab_ofs
; // Fixup record table offset
265 ULONG imp_tab_ofs
; // Import module table offset
266 ULONG imp_mod_entries
; // Import module entries
267 ULONG imp_proc_tab_ofs
; // Import proc table offset
268 ULONG per_page_check_ofs
; // Per page checksum offset
269 ULONG data_page_offset
; // Data pages offset
270 ULONG preload_page_count
; // Preload pages count
271 ULONG nonres_tab_ofs
; // Nonresident name table offset
272 ULONG nonres_tab_len
; // Nonresident name table len
273 ULONG nonres_tab_check
; // Nonresident tables checksum
274 ULONG auto_ds_objectno
; // Auto DS object number
275 ULONG debug_info_ofs
; // Debug info offset
276 ULONG debug_info_len
; // Debug info length
277 ULONG inst_preload_count
; // Instance preload count
278 ULONG inst_demand_count
; // Instance demand count
279 ULONG heapsize
; // Heap size
280 ULONG stacksize
; // Stack size
283 struct debug_head_rec
285 BYTE signature
[3]; // Debug signature
286 BYTE type
; // Debug info type
291 USHORT dirstruct_size
; // Size of directory structure
292 USHORT number_of_entries
; // Number of dnt_rec's in the array
293 USHORT unknown
; // Unknown data
294 // Followed by an array of dnt_rec structures
299 USHORT subsect_type
; // sst Subsection type
300 USHORT mod_index
; // Module index (1-based)
301 ULONG offset
; // Offset of start of section
302 ULONG size
; // Size of section
305 // Modules subsection
308 USHORT code_seg_base
; // Code segment base
309 ULONG code_seg_offset
; // Code segment offset
310 ULONG code_seg_len
; // Code segment length
311 USHORT overlay_no
; // Overlay number
312 USHORT lib_idx
; // Index into library section or 0
313 BYTE segments
; // Number of segments
315 BYTE debug_style
[2]; // "HL" for HLL, "CV" or 0 for CodeView
316 BYTE debug_version
[2]; // 00 01 or 00 03 for HLL, 00 00 for CV
317 BYTE name_len
; // Length of name (which follows)
320 // Publics subsection
323 ULONG offset
; // Offset
324 USHORT segment
; // Segment
325 USHORT type
; // Type index
326 BYTE name_len
; // Length of name (wich follows)
330 // Linenumbers header
333 BYTE id
; // 0x95 for flat mem, 32 bit progs
334 USHORT length
; // Record length
335 USHORT base_group
; // Base group
336 USHORT base_segment
; // Base segment
340 // First linenumber record
343 USHORT lineno
; // Line number (0)
344 BYTE entry_type
; // Entry type
345 BYTE reserved
; // Reserved
346 USHORT entries_count
; // Number of table entries
347 USHORT segment_no
; // Segment number
348 ULONG filename_tabsize
; // File names table size
351 // Source line numbers
354 USHORT source_line
; // Source file line number
355 USHORT source_idx
; // Source file index
356 ULONG offset
; // Offset into segment
359 // Listing statement numbers
362 ULONG list_line
; // Listing file linenumber
363 ULONG statement
; // Listing file statement number
364 ULONG offset
; // Offset into segment
367 // Source and Listing statement numbers
368 struct linsourcelist_rec
370 USHORT source_line
; // Source file line number
371 USHORT source_idx
; // Source file index
372 ULONG list_line
; // Listing file linenumber
373 ULONG statement
; // Listing file statement number
374 ULONG offset
; // Offset into segment
380 ULONG offset
; // Offset into segment
381 USHORT path_code
; // Path code
382 USHORT source_idx
; // Source file index
388 ULONG first_char
; // First displayable char in list file
389 ULONG disp_chars
; // Number of displayable chars in list line
390 ULONG filecount
; // Number of source/listing files
394 #define SYM_BEGIN 0x00 // Begin block
395 #define SYM_PROC 0x01 // Function
396 #define SYM_END 0x02 // End block of function
397 #define SYM_AUTO 0x04 // Auto variable
398 #define SYM_STATIC 0x05 // Static variable
399 #define SYM_LABEL 0x0B // Label
400 #define SYM_WITH 0x0C // With start symbol (not used)
401 #define SYM_REG 0x0D // Register variable
402 #define SYM_CONST 0x0E // Constant
403 #define SYM_ENTRY 0x0F // Secondary entry (not in C)
404 #define SYM_SKIP 0x10 // For incremental linking (not used)
405 #define SYM_CHANGESEG 0x11 // Change segment (#pragma alloc_text)
406 #define SYM_TYPEDEF 0x12 // Typedef variable
407 #define SYM_PUBLIC 0x13 // Public reference
408 #define SYM_MEMBER 0x14 // Member of minor or major structure
409 #define SYM_BASED 0x15 // Based variable
410 #define SYM_TAG 0x16 // Tag in struct, union, enum ...
411 #define SYM_TABLE 0x17 // Table (used in RPG - not C)
412 #define SYM_MAP 0x18 // Map variable (extern in C)
413 #define SYM_CLASS 0x19 // Class symbol (C++)
414 #define SYM_MEMFUNC 0x1A // Member function
415 #define SYM_AUTOSCOPE 0x1B // Scoped auto for C++ (not used)
416 #define SYM_STATICSCOPE 0x1C // scoped static for C++ (not used)
417 #define SYM_CPPPROC 0x1D // C++ Proc
418 #define SYM_CPPSTAT 0x1E // C++ Static var
419 #define SYM_COMP 0x40 // Compiler information
421 // Symbolic begin record
424 ULONG offset
; // Segment offset
425 ULONG length
; // Length of block
426 BYTE name_len
; // Length of block name
427 // Block name follows
430 // Symbolic auto var record
433 ULONG stack_offset
; // Stack offset
434 USHORT type_idx
; // Type index
435 BYTE name_len
; // Length of name
439 // Symbolic procedure record
442 ULONG offset
; // Segment offset
443 USHORT type_idx
; // Type index
444 ULONG length
; // Length of procedure
445 USHORT pro_len
; // Length of prologue
446 ULONG pro_bodylen
; // Length of prologue + body
447 USHORT class_type
; // Class type
448 BYTE near_far
; // Near or far
449 BYTE name_len
; // Length of name
450 // Function name follows
453 // Symbolic static var record
456 ULONG offset
; // Segment offset
457 USHORT segaddr
; // Segment address
458 USHORT type_idx
; // Type index
459 BYTE name_len
; // Length of name
463 // Symbolic label var record
466 ULONG offset
; // Segment offset
467 BYTE near_far
; // Near or far
468 BYTE name_len
; // Length of name
472 // Symbolic register var record
475 USHORT type_idx
; // Type index
476 BYTE reg_no
; // Register number
477 BYTE name_len
; // Length of name
481 // Symbolic change-segment record
484 USHORT seg_no
; // Segment number
487 // Symbolic typedef record
488 struct symtypedef_rec
490 USHORT type_idx
; // Type index
491 BYTE name_len
; // Length of name
495 // Symbolic public record
498 ULONG offset
; // Segment offset
499 USHORT segaddr
; // Segment address
500 USHORT type_idx
; // Type index
501 BYTE name_len
; // Length of name
505 // Symbolic member record
508 ULONG offset
; // Offset to subrecord
509 BYTE name_len
; // Length of name
513 // Symbolic based record
516 ULONG offset
; // Offset to subrecord
517 USHORT type_idx
; // Type index
518 BYTE name_len
; // Length of name
522 // Symbolic tag record
525 USHORT type_idx
; // Type index
526 BYTE name_len
; // Length of name
530 // Symbolic table record
533 ULONG offset
; // Segment offset
534 USHORT segaddr
; // Segment address
535 USHORT type_idx
; // Type index
536 ULONG idx_ofs
; // Index offset to subrecord
537 BYTE name_len
; // Length of name
544 USHORT length
; // Length of sub-record
545 BYTE type
; // Sub-record type
546 BYTE type_qual
; // Type qualifier
550 #define TYPE_CLASS 0x40 // Class
551 #define TYPE_BASECLASS 0x41 // Base class
552 #define TYPE_FRIEND 0x42 // Friend
553 #define TYPE_CLASSDEF 0x43 // Class definition
554 #define TYPE_MEMBERFUNC 0x45 // Member function
555 #define TYPE_CLASSMEMBER 0x46 // Class member
556 #define TYPE_REF 0x48 // Reference
557 #define TYPE_MEMBERPTR 0x49 // Member pointer
558 #define TYPE_SCALARS 0x51 // Scalars
559 #define TYPE_SET 0x52 // Set
560 #define TYPE_ENTRY 0x53 // Entry
561 #define TYPE_FUNCTION 0x54 // Function
562 #define TYPE_AREA 0x55 // Area
563 #define TYPE_LOGICAL 0x56 // Logical
564 #define TYPE_STACK 0x57 // Stack
565 #define TYPE_MACRO 0x59 // Macro
566 #define TYPE_BITSTRING 0x5C // Bit string
567 #define TYPE_USERDEF 0x5D // User defined
568 #define TYPE_CHARSTR 0x60 // Character string
569 #define TYPE_PICTURE 0x61 // Picture
570 #define TYPE_GRAPHIC 0x62 // Graphic
571 #define TYPE_FORMATLAB 0x65 // Format label
572 #define TYPE_FILE 0x67 // File
573 #define TYPE_SUBRANGE 0x6F // Subrange
574 #define TYPE_CODELABEL 0x72 // Code label
575 #define TYPE_PROCEDURE 0x75 // Procedure
576 #define TYPE_ARRAY 0x78 // Array
577 #define TYPE_STRUCT 0x79 // Structure / Union / Record
578 #define TYPE_POINTER 0x7A // Pointer
579 #define TYPE_ENUM 0x7B // Enum
580 #define TYPE_LIST 0x7F // List
583 struct type_userdefrec
585 BYTE FID_index
; // Field ID
586 USHORT type_index
; // Type index
587 BYTE FID_string
; // String ID
588 BYTE name_len
; // Length of name which follows
596 BYTE FID_index
; // Field ID
597 USHORT type_index
; // Type index of return value
598 BYTE FID_index1
; // String ID
599 USHORT typelist_index
; // Index of list of params
603 struct type_structrec
605 ULONG size
; // Size of structure
606 USHORT field_count
; // Number of fields in structure
607 BYTE FID_index
; // Field ID
608 USHORT type_list_idx
; // Index to type list
609 BYTE FID_index1
; // Field ID
610 USHORT type_name_idx
; // Index to names / offsets
611 BYTE dont_know
; // Haven't a clue, but it seems to be needed
612 BYTE name_len
; // Length of structure name which follows
615 // Type list, type qualifier 1: contains types for structures
616 // This record is repeated for the number of items in the structure definition
619 BYTE FID_index
; // Field identifier for index
620 USHORT type_index
; // Type index.
623 // Type list, type qualifier 2: contains names and offsets for structure items
624 // This record is repeated for the number of items in the structure definition
627 BYTE FID_string
; // String identifier
628 BYTE name_len
; // Length of name which follows
631 // Type list, subrecord to the above, contains offset of variable in the structure
634 BYTE FID_span
; // Defines what type of variable follows
643 struct type_pointerrec
645 BYTE FID_index
; // Index identifier
646 USHORT type_index
; // Type index
647 BYTE FID_string
; // String identifier
648 BYTE name_len
; // Length of name which follows
651 /********************************************************************
655 ********************************************************************/
657 BOOL
dbgPrintStackFrame(FILE *LogFile
,
658 PSZ pszModuleName
, // in: module name (fully q'fied)
662 VOID
dbgPrintStack(FILE *file
,
666 PUSHORT ExceptionAddress
);
668 APIRET APIENTRY
DosQueryModFromEIP(HMODULE
*phMod
, // out: trapping module
669 ULONG
*pulObjNum
, // out: object/segment number
670 ULONG ulBuffLen
, // in: sizeof(*pszBuff)
671 CHAR
*pszBuff
, // out: module name
672 ULONG
*pulOffset
, // out: offset in module
673 ULONG ulAddress
); // in: address to be analyzed
675 APIRET APIENTRY
DOSQUERYMODFROMEIP(HMODULE
* phMod
,
682 typedef ULONG
*_Seg16 PULONG16
;
683 APIRET16 APIENTRY16
DOS16SIZESEG(USHORT Seg
, PULONG16 Size
);
684 typedef APIRET16(APIENTRY16 _PFN16
) (VOID
);
685 ULONG APIENTRY
DosSelToFlat(ULONG
);
687 APIRET16 APIENTRY16
DOSQPROCSTATUS(ULONG
* _Seg16 pBuf
, USHORT cbBuf
);
689 #define CONVERT(fp,QSsel) MAKEP((QSsel),OFFSETOF(fp))
691 #pragma pack() // added V0.9.0
694 /********************************************************************
696 * Executable definitions
698 ********************************************************************/
707 /*_________________________________________________________________*
710 | DOS3 .EXE FILE HEADER DEFINITION |
712 |_________________________________________________________________|
716 #define EMAGIC 0x5A4D // Old magic number
717 #define ENEWEXE sizeof(struct exe_hdr)
718 // Value of E_LFARLC for new .EXEs
719 #define ENEWHDR 0x003C // Offset in old hdr. of ptr. to new
720 #define ERESWDS 0x0010 // No. of reserved words (OLD)
721 #define ERES1WDS 0x0004 // No. of reserved words in e_res
722 #define ERES2WDS 0x000A // No. of reserved words in e_res2
723 #define ECP 0x0004 // Offset in struct of E_CP
724 #define ECBLP 0x0002 // Offset in struct of E_CBLP
725 #define EMINALLOC 0x000A // Offset in struct of E_MINALLOC
729 * DOS 1, 2, 3 .EXE header.
734 unsigned short e_magic
; // Magic number
735 unsigned short e_cblp
; // Bytes on last page of file
736 unsigned short e_cp
; // Pages in file
737 unsigned short e_crlc
; // Relocations
738 unsigned short e_cparhdr
; // Size of header in paragraphs
739 unsigned short e_minalloc
; // Minimum extra paragraphs needed
740 unsigned short e_maxalloc
; // Maximum extra paragraphs needed
741 unsigned short e_ss
; // Initial (relative) SS value
742 unsigned short e_sp
; // Initial SP value
743 unsigned short e_csum
; // Checksum
744 unsigned short e_ip
; // Initial IP value
745 unsigned short e_cs
; // Initial (relative) CS value
746 unsigned short e_lfarlc
; // File address of relocation table
747 unsigned short e_ovno
; // Overlay number
748 unsigned short e_res
[ERES1WDS
];// Reserved words
749 unsigned short e_oemid
; // OEM identifier (for e_oeminfo)
750 unsigned short e_oeminfo
; // OEM information; e_oemid specific
751 unsigned short e_res2
[ERES2WDS
];// Reserved words
752 long e_lfanew
; // File address of new exe header
755 #define E_MAGIC(x) (x).e_magic
756 #define E_CBLP(x) (x).e_cblp
757 #define E_CP(x) (x).e_cp
758 #define E_CRLC(x) (x).e_crlc
759 #define E_CPARHDR(x) (x).e_cparhdr
760 #define E_MINALLOC(x) (x).e_minalloc
761 #define E_MAXALLOC(x) (x).e_maxalloc
762 #define E_SS(x) (x).e_ss
763 #define E_SP(x) (x).e_sp
764 #define E_CSUM(x) (x).e_csum
765 #define E_IP(x) (x).e_ip
766 #define E_CS(x) (x).e_cs
767 #define E_LFARLC(x) (x).e_lfarlc
768 #define E_OVNO(x) (x).e_ovno
769 #define E_RES(x) (x).e_res
770 #define E_OEMID(x) (x).e_oemid
771 #define E_OEMINFO(x) (x).e_oeminfo
772 #define E_RES2(x) (x).e_res2
773 #define E_LFANEW(x) (x).e_lfanew
776 /*_________________________________________________________________*
779 | OS/2 & WINDOWS .EXE FILE HEADER DEFINITION - 286 version |
781 |_________________________________________________________________|
784 #define NEMAGIC 0x454E // New magic number
785 #define NERESBYTES 8 // Eight bytes reserved (now)
786 #define NECRC 8 // Offset into new header of NE_CRC
790 * New Executable (NE) header.
791 * Follows DOS header in the executable file.
796 unsigned short ne_magic
; // Magic number NE_MAGIC
797 unsigned char ne_ver
; // Version number
798 unsigned char ne_rev
; // Revision number
799 unsigned short ne_enttab
; // Offset of Entry Table
800 unsigned short ne_cbenttab
; // Number of bytes in Entry Table
801 long ne_crc
; // Checksum of whole file
802 unsigned short ne_flags
; // Flag word
803 unsigned short ne_autodata
; // Automatic data segment number
804 unsigned short ne_heap
; // Initial heap allocation
805 unsigned short ne_stack
; // Initial stack allocation
806 long ne_csip
; // Initial CS:IP setting
807 long ne_sssp
; // Initial SS:SP setting
808 unsigned short ne_cseg
; // Count of file segments
809 unsigned short ne_cmod
; // Entries in Module Reference Table
810 unsigned short ne_cbnrestab
; // Size of non-resident name table
811 unsigned short ne_segtab
; // Offset of Segment Table
812 unsigned short ne_rsrctab
; // Offset of Resource Table
813 unsigned short ne_restab
; // Offset of resident name table
814 unsigned short ne_modtab
; // Offset of Module Reference Table
815 unsigned short ne_imptab
; // Offset of Imported Names Table
816 long ne_nrestab
; // Offset of Non-resident Names Table
817 unsigned short ne_cmovent
; // Count of movable entries
818 unsigned short ne_align
; // Segment alignment shift count
819 unsigned short ne_cres
; // Count of resource entries
820 unsigned char ne_exetyp
; // Target operating system
821 unsigned char ne_flagsothers
; // Other .EXE flags
822 char ne_res
[NERESBYTES
]; // Pad structure to 64 bytes
827 #define NE_MAGIC(x) (x).ne_magic
828 #define NE_VER(x) (x).ne_ver
829 #define NE_REV(x) (x).ne_rev
830 #define NE_ENTTAB(x) (x).ne_enttab
831 #define NE_CBENTTAB(x) (x).ne_cbenttab
832 #define NE_CRC(x) (x).ne_crc
833 #define NE_FLAGS(x) (x).ne_flags
834 #define NE_AUTODATA(x) (x).ne_autodata
835 #define NE_HEAP(x) (x).ne_heap
836 #define NE_STACK(x) (x).ne_stack
837 #define NE_CSIP(x) (x).ne_csip
838 #define NE_SSSP(x) (x).ne_sssp
839 #define NE_CSEG(x) (x).ne_cseg
840 #define NE_CMOD(x) (x).ne_cmod
841 #define NE_CBNRESTAB(x) (x).ne_cbnrestab
842 #define NE_SEGTAB(x) (x).ne_segtab
843 #define NE_RSRCTAB(x) (x).ne_rsrctab
844 #define NE_RESTAB(x) (x).ne_restab
845 #define NE_MODTAB(x) (x).ne_modtab
846 #define NE_IMPTAB(x) (x).ne_imptab
847 #define NE_NRESTAB(x) (x).ne_nrestab
848 #define NE_CMOVENT(x) (x).ne_cmovent
849 #define NE_ALIGN(x) (x).ne_align
850 #define NE_CRES(x) (x).ne_cres
851 #define NE_RES(x) (x).ne_res
852 #define NE_EXETYP(x) (x).ne_exetyp
853 #define NE_FLAGSOTHERS(x) (x).ne_flagsothers
855 #define NE_USAGE(x) (WORD)*((WORD *)(x)+1)
856 #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
857 #define NE_ONEWEXE(x) (WORD)(x).ne_crc
858 #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
862 * Target operating systems
865 #define NE_UNKNOWN 0x0 /* Unknown (any "new-format" OS) */
866 #define NE_OS2 0x1 /* OS/2 (default) */
867 #define NE_WINDOWS 0x2 /* Windows */
868 #define NE_DOS4 0x3 /* DOS 4.x */
869 #define NE_DEV386 0x4 /* Windows 386 */
873 * Format of NE_FLAGS(x):
880 * ttt Application type
881 * f Floating-point instructions
884 * 0 8086 instructions
885 * P Protected mode only
886 * p Per-process library initialization
890 #define NENOTP 0x8000 /* Not a process */
891 #define NEIERR 0x2000 /* Errors in image */
892 #define NEBOUND 0x0800 /* Bound Family/API */
893 #define NEAPPTYP 0x0700 /* Application type mask */
894 #define NENOTWINCOMPAT 0x0100 /* Not compatible with P.M. Windowing */
895 #define NEWINCOMPAT 0x0200 /* Compatible with P.M. Windowing */
896 #define NEWINAPI 0x0300 /* Uses P.M. Windowing API */
897 #define NEFLTP 0x0080 /* Floating-point instructions */
898 #define NEI386 0x0040 /* 386 instructions */
899 #define NEI286 0x0020 /* 286 instructions */
900 #define NEI086 0x0010 /* 8086 instructions */
901 #define NEPROT 0x0008 /* Runs in protected mode only */
902 #define NEPPLI 0x0004 /* Per-Process Library Initialization */
903 #define NEINST 0x0002 /* Instance data */
904 #define NESOLO 0x0001 /* Solo data */
907 * Format of NE_FLAGSOTHERS(x):
909 * 7 6 5 4 3 2 1 0 - bit no
911 * | | | +---------------- Support for long file names
912 * | | +------------------ Windows 2.x app runs in prot mode
913 * | +-------------------- Windows 2.x app gets prop. font
914 * +------------------------------ WLO appl on OS/2 (markwlo.exe)
918 #define NELONGNAMES 0x01
919 #define NEWINISPROT 0x02
920 #define NEWINGETPROPFON 0x04
921 #define NEWLOAPPL 0x80
925 struct new_seg
/* New .EXE segment table entry */
927 unsigned short ns_sector
; /* File sector of start of segment */
928 unsigned short ns_cbseg
; /* Number of bytes in file */
929 unsigned short ns_flags
; /* Attribute flags */
930 unsigned short ns_minalloc
; /* Minimum allocation in bytes */
933 #define NS_SECTOR(x) (x).ns_sector
934 #define NS_CBSEG(x) (x).ns_cbseg
935 #define NS_FLAGS(x) (x).ns_flags
936 #define NS_MINALLOC(x) (x).ns_minalloc
940 * Format of NS_FLAGS(x)
942 * Flag word has the following format:
944 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
945 * | | | | | | | | | | | | | | |
946 * | | | | | | | | | | | | +-+-+--- Segment type DATA/CODE
947 * | | | | | | | | | | | +--------- Iterated segment
948 * | | | | | | | | | | +----------- Movable segment
949 * | | | | | | | | | +------------- Segment can be shared
950 * | | | | | | | | +--------------- Preload segment
951 * | | | | | | | +----------------- Execute/read-only for code/data segment
952 * | | | | | | +------------------- Segment has relocations
953 * | | | | | +--------------------- Code conforming/Data is expand down
954 * | | | +--+----------------------- I/O privilege level
955 * | | +----------------------------- Discardable segment
956 * | +-------------------------------- 32-bit code segment
957 * +----------------------------------- Huge segment/GDT allocation requested
961 #define NSTYPE 0x0007 /* Segment type mask */
964 #define NSCODE 0x0000 /* Code segment */
965 #define NSDATA 0x0001 /* Data segment */
966 #define NSITER 0x0008 /* Iterated segment flag */
967 #define NSMOVE 0x0010 /* Movable segment flag */
968 #define NSSHARED 0x0020 /* Shared segment flag */
969 #define NSPRELOAD 0x0040 /* Preload segment flag */
970 #define NSEXRD 0x0080 /* Execute-only (code segment), or
971 * read-only (data segment)
973 #define NSRELOC 0x0100 /* Segment has relocations */
974 #define NSCONFORM 0x0200 /* Conforming segment */
975 #define NSEXPDOWN 0x0200 /* Data segment is expand down */
976 #define NSDPL 0x0C00 /* I/O privilege level (286 DPL bits) */
977 #define SHIFTDPL 10 /* Left shift count for SEGDPL field */
978 #define NSDISCARD 0x1000 /* Segment is discardable */
979 #define NS32BIT 0x2000 /* 32-bit code segment */
980 #define NSHUGE 0x4000 /* Huge memory segment, length of
981 * segment and minimum allocation
982 * size are in segment sector units
984 #define NSGDT 0x8000 /* GDT allocation requested */
986 #define NSPURE NSSHARED /* For compatibility */
988 #define NSALIGN 9 /* Segment data aligned on 512 byte boundaries */
990 #define NSLOADED 0x0004 /* ns_sector field contains memory addr */
994 struct new_segdata
/* Segment data */
1000 unsigned short ns_niter
; /* number of iterations */
1001 unsigned short ns_nbytes
; /* number of bytes */
1002 char ns_iterdata
; /* iterated data bytes */
1006 char ns_data
; /* data bytes */
1011 struct new_rlcinfo
/* Relocation info */
1013 unsigned short nr_nreloc
; /* number of relocation items that */
1019 struct new_rlc
/* Relocation item */
1021 char nr_stype
; /* Source type */
1022 char nr_flags
; /* Flag byte */
1023 unsigned short nr_soff
; /* Source offset */
1028 char nr_segno
; /* Target segment number */
1029 char nr_res
; /* Reserved */
1030 unsigned short nr_entry
; /* Target Entry Table offset */
1031 } nr_intref
; /* Internal reference */
1034 unsigned short nr_mod
; /* Index into Module Reference Table */
1035 unsigned short nr_proc
; /* Procedure ordinal or name offset */
1036 } nr_import
; /* Import */
1039 unsigned short nr_ostype
; /* OSFIXUP type */
1040 unsigned short nr_osres
; /* reserved */
1041 } nr_osfix
; /* Operating system fixup */
1042 } nr_union
; /* Union */
1048 #define NR_STYPE(x) (x).nr_stype
1049 #define NR_FLAGS(x) (x).nr_flags
1050 #define NR_SOFF(x) (x).nr_soff
1051 #define NR_SEGNO(x) (x).nr_union.nr_intref.nr_segno
1052 #define NR_RES(x) (x).nr_union.nr_intref.nr_res
1053 #define NR_ENTRY(x) (x).nr_union.nr_intref.nr_entry
1054 #define NR_MOD(x) (x).nr_union.nr_import.nr_mod
1055 #define NR_PROC(x) (x).nr_union.nr_import.nr_proc
1056 #define NR_OSTYPE(x) (x).nr_union.nr_osfix.nr_ostype
1057 #define NR_OSRES(x) (x).nr_union.nr_osfix.nr_osres
1062 * Format of NR_STYPE(x) and R32_STYPE(x):
1064 * 7 6 5 4 3 2 1 0 - bit no
1066 * +-+-+-+--- source type
1070 #define NRSTYP 0x0f /* Source type mask */
1071 #define NRSBYT 0x00 /* lo byte (8-bits)*/
1072 #define NRSSEG 0x02 /* 16-bit segment (16-bits) */
1073 #define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
1074 #define NRSOFF 0x05 /* 16-bit offset (16-bits) */
1075 #define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
1076 #define NROFF32 0x07 /* 32-bit offset (32-bits) */
1077 #define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
1081 * Format of NR_FLAGS(x) and R32_FLAGS(x):
1083 * 7 6 5 4 3 2 1 0 - bit no
1085 * | +-+--- Reference type
1086 * +------- Additive fixup
1089 #define NRADD 0x04 /* Additive fixup */
1090 #define NRRTYP 0x03 /* Reference type mask */
1091 #define NRRINT 0x00 /* Internal reference */
1092 #define NRRORD 0x01 /* Import by ordinal */
1093 #define NRRNAM 0x02 /* Import by name */
1094 #define NRROSF 0x03 /* Operating system fixup */
1099 /* Resource type or name string */
1102 char rs_len
; /* number of bytes in string */
1103 char rs_string
[ 1 ]; /* text of string */
1106 #define RS_LEN( x ) (x).rs_len
1107 #define RS_STRING( x ) (x).rs_string
1109 /* Resource type information block */
1110 struct rsrc_typeinfo
1112 unsigned short rt_id
;
1113 unsigned short rt_nres
;
1117 #define RT_ID( x ) (x).rt_id
1118 #define RT_NRES( x ) (x).rt_nres
1119 #define RT_PROC( x ) (x).rt_proc
1121 /* Resource name information block */
1122 struct rsrc_nameinfo
1124 /* The following two fields must be shifted left by the value of */
1125 /* the rs_align field to compute their actual value. This allows */
1126 /* resources to be larger than 64k, but they do not need to be */
1127 /* aligned on 512 byte boundaries, the way segments are */
1128 unsigned short rn_offset
; /* file offset to resource data */
1129 unsigned short rn_length
; /* length of resource data */
1130 unsigned short rn_flags
; /* resource flags */
1131 unsigned short rn_id
; /* resource name id */
1132 unsigned short rn_handle
; /* If loaded, then global handle */
1133 unsigned short rn_usage
; /* Initially zero. Number of times */
1134 /* the handle for this resource has */
1135 /* been given out */
1138 #define RN_OFFSET( x ) (x).rn_offset
1139 #define RN_LENGTH( x ) (x).rn_length
1140 #define RN_FLAGS( x ) (x).rn_flags
1141 #define RN_ID( x ) (x).rn_id
1142 #define RN_HANDLE( x ) (x).rn_handle
1143 #define RN_USAGE( x ) (x).rn_usage
1145 #define RSORDID 0x8000 /* if high bit of ID set then integer id */
1146 /* otherwise ID is offset of string from
1147 the beginning of the resource table */
1149 /* Ideally these are the same as the */
1150 /* corresponding segment flags */
1151 #define RNMOVE 0x0010 /* Moveable resource */
1152 #define RNPURE 0x0020 /* Pure (read-only) resource */
1153 #define RNPRELOAD 0x0040 /* Preloaded resource */
1154 #define RNDISCARD 0xF000 /* Discard priority level for resource */
1156 /* Resource table */
1159 unsigned short rs_align
; /* alignment shift count for resources */
1160 struct rsrc_typeinfo rs_typeinfo
;
1163 #define RS_ALIGN( x ) (x).rs_align
1166 #endif /* NOT EXE386 */
1168 #endif /* __NEWEXE__ */
1171 #define DWORD long int
1175 #define WORD short int
1181 #pragma pack(1) /* Force byte alignment */
1183 /*_________________________________________________________________*
1186 | OS/2 .EXE FILE HEADER DEFINITION - 386 version 0:32 |
1188 |_________________________________________________________________|
1191 #define BITPERWORD 16
1192 #define BITPERBYTE 8
1193 #define OBJPAGELEN 4096
1194 #define E32MAGIC1 'L' /* New magic number "LX" */
1195 #define E32MAGIC2 'X' /* New magic number "LX" */
1196 #define E32MAGIC 0x584c /* New magic number "LX" */
1197 #define E32RESBYTES1 0 /* First bytes reserved */
1198 #define E32RESBYTES2 0 /* Second bytes reserved */
1199 #define E32RESBYTES3 20 /* Third bytes reserved */
1200 #define E32LEBO 0x00 /* Little Endian Byte Order */
1201 #define E32BEBO 0x01 /* Big Endian Byte Order */
1202 #define E32LEWO 0x00 /* Little Endian Word Order */
1203 #define E32BEWO 0x01 /* Big Endian Word Order */
1204 #define E32LEVEL 0L /* 32-bit EXE format level */
1205 #define E32CPU286 0x001 /* Intel 80286 or upwardly compatibile */
1206 #define E32CPU386 0x002 /* Intel 80386 or upwardly compatibile */
1207 #define E32CPU486 0x003 /* Intel 80486 or upwardly compatibile */
1211 struct e32_exe
/* New 32-bit .EXE header */
1213 unsigned char e32_magic
[2]; /* Magic number E32_MAGIC */
1214 unsigned char e32_border
; /* The byte ordering for the .EXE */
1215 unsigned char e32_worder
; /* The word ordering for the .EXE */
1216 unsigned long e32_level
; /* The EXE format level for now = 0 */
1217 unsigned short e32_cpu
; /* The CPU type */
1218 unsigned short e32_os
; /* The OS type */
1219 unsigned long e32_ver
; /* Module version */
1220 unsigned long e32_mflags
; /* Module flags */
1221 unsigned long e32_mpages
; /* Module # pages */
1222 unsigned long e32_startobj
; /* Object # for instruction pointer */
1223 unsigned long e32_eip
; /* Extended instruction pointer */
1224 unsigned long e32_stackobj
; /* Object # for stack pointer */
1225 unsigned long e32_esp
; /* Extended stack pointer */
1226 unsigned long e32_pagesize
; /* .EXE page size */
1227 unsigned long e32_pageshift
; /* Page alignment shift in .EXE */
1228 unsigned long e32_fixupsize
; /* Fixup section size */
1229 unsigned long e32_fixupsum
; /* Fixup section checksum */
1230 unsigned long e32_ldrsize
; /* Loader section size */
1231 unsigned long e32_ldrsum
; /* Loader section checksum */
1232 unsigned long e32_objtab
; /* Object table offset */
1233 unsigned long e32_objcnt
; /* Number of objects in module */
1234 unsigned long e32_objmap
; /* Object page map offset */
1235 unsigned long e32_itermap
; /* Object iterated data map offset */
1236 unsigned long e32_rsrctab
; /* Offset of Resource Table */
1237 unsigned long e32_rsrccnt
; /* Number of resource entries */
1238 unsigned long e32_restab
; /* Offset of resident name table */
1239 unsigned long e32_enttab
; /* Offset of Entry Table */
1240 unsigned long e32_dirtab
; /* Offset of Module Directive Table */
1241 unsigned long e32_dircnt
; /* Number of module directives */
1242 unsigned long e32_fpagetab
; /* Offset of Fixup Page Table */
1243 unsigned long e32_frectab
; /* Offset of Fixup Record Table */
1244 unsigned long e32_impmod
; /* Offset of Import Module Name Table */
1245 unsigned long e32_impmodcnt
; /* Number of entries in Import Module Name Table */
1246 unsigned long e32_impproc
; /* Offset of Import Procedure Name Table */
1247 unsigned long e32_pagesum
; /* Offset of Per-Page Checksum Table */
1248 unsigned long e32_datapage
; /* Offset of Enumerated Data Pages */
1249 unsigned long e32_preload
; /* Number of preload pages */
1250 unsigned long e32_nrestab
; /* Offset of Non-resident Names Table */
1251 unsigned long e32_cbnrestab
; /* Size of Non-resident Name Table */
1252 unsigned long e32_nressum
; /* Non-resident Name Table Checksum */
1253 unsigned long e32_autodata
; /* Object # for automatic data object */
1254 unsigned long e32_debuginfo
; /* Offset of the debugging information */
1255 unsigned long e32_debuglen
; /* The length of the debugging info. in bytes */
1256 unsigned long e32_instpreload
;/* Number of instance pages in preload section of .EXE file */
1257 unsigned long e32_instdemand
; /* Number of instance pages in demand load section of .EXE file */
1258 unsigned long e32_heapsize
; /* Size of heap - for 16-bit apps */
1259 unsigned long e32_stacksize
; /* Size of stack */
1260 unsigned char e32_res3
[E32RESBYTES3
];
1261 /* Pad structure to 196 bytes */
1266 #define E32_MAGIC1(x) (x).e32_magic[0]
1267 #define E32_MAGIC2(x) (x).e32_magic[1]
1268 #define E32_BORDER(x) (x).e32_border
1269 #define E32_WORDER(x) (x).e32_worder
1270 #define E32_LEVEL(x) (x).e32_level
1271 #define E32_CPU(x) (x).e32_cpu
1272 #define E32_OS(x) (x).e32_os
1273 #define E32_VER(x) (x).e32_ver
1274 #define E32_MFLAGS(x) (x).e32_mflags
1275 #define E32_MPAGES(x) (x).e32_mpages
1276 #define E32_STARTOBJ(x) (x).e32_startobj
1277 #define E32_EIP(x) (x).e32_eip
1278 #define E32_STACKOBJ(x) (x).e32_stackobj
1279 #define E32_ESP(x) (x).e32_esp
1280 #define E32_PAGESIZE(x) (x).e32_pagesize
1281 #define E32_PAGESHIFT(x) (x).e32_pageshift
1282 #define E32_FIXUPSIZE(x) (x).e32_fixupsize
1283 #define E32_FIXUPSUM(x) (x).e32_fixupsum
1284 #define E32_LDRSIZE(x) (x).e32_ldrsize
1285 #define E32_LDRSUM(x) (x).e32_ldrsum
1286 #define E32_OBJTAB(x) (x).e32_objtab
1287 #define E32_OBJCNT(x) (x).e32_objcnt
1288 #define E32_OBJMAP(x) (x).e32_objmap
1289 #define E32_ITERMAP(x) (x).e32_itermap
1290 #define E32_RSRCTAB(x) (x).e32_rsrctab
1291 #define E32_RSRCCNT(x) (x).e32_rsrccnt
1292 #define E32_RESTAB(x) (x).e32_restab
1293 #define E32_ENTTAB(x) (x).e32_enttab
1294 #define E32_DIRTAB(x) (x).e32_dirtab
1295 #define E32_DIRCNT(x) (x).e32_dircnt
1296 #define E32_FPAGETAB(x) (x).e32_fpagetab
1297 #define E32_FRECTAB(x) (x).e32_frectab
1298 #define E32_IMPMOD(x) (x).e32_impmod
1299 #define E32_IMPMODCNT(x) (x).e32_impmodcnt
1300 #define E32_IMPPROC(x) (x).e32_impproc
1301 #define E32_PAGESUM(x) (x).e32_pagesum
1302 #define E32_DATAPAGE(x) (x).e32_datapage
1303 #define E32_PRELOAD(x) (x).e32_preload
1304 #define E32_NRESTAB(x) (x).e32_nrestab
1305 #define E32_CBNRESTAB(x) (x).e32_cbnrestab
1306 #define E32_NRESSUM(x) (x).e32_nressum
1307 #define E32_AUTODATA(x) (x).e32_autodata
1308 #define E32_DEBUGINFO(x) (x).e32_debuginfo
1309 #define E32_DEBUGLEN(x) (x).e32_debuglen
1310 #define E32_INSTPRELOAD(x) (x).e32_instpreload
1311 #define E32_INSTDEMAND(x) (x).e32_instdemand
1312 #define E32_HEAPSIZE(x) (x).e32_heapsize
1313 #define E32_STACKSIZE(x) (x).e32_stacksize
1318 * Format of E32_MFLAGS(x):
1320 * Low word has the following format:
1322 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1324 * | | | | | | | +------- Per-Process Library Initialization
1325 * | | | | | | +--------- SystemDLL (internal fixups discarded)
1326 * | | | | | +----------- No Internal Fixups for Module in .EXE
1327 * | | | | +------------- No External Fixups for Module in .EXE
1328 * | | | +------------------- Incompatible with PM Windowing
1329 * | | +--------------------- Compatible with PM Windowing
1330 * | | Uses PM Windowing API
1331 * | +-------------------------------- Module not Loadable
1332 * +-------------------------------------- Library Module
1336 #define E32NOTP 0x8000L /* Library Module - used as NENOTP */
1337 #define E32NOLOAD 0x2000L /* Module not Loadable */
1338 #define E32PMAPI 0x0300L /* Uses PM Windowing API */
1339 #define E32PMW 0x0200L /* Compatible with PM Windowing */
1340 #define E32NOPMW 0x0100L /* Incompatible with PM Windowing */
1341 #define E32NOEXTFIX 0x0020L /* NO External Fixups in .EXE */
1342 #define E32NOINTFIX 0x0010L /* NO Internal Fixups in .EXE */
1343 #define E32SYSDLL 0x0008L /* System DLL, Internal Fixups discarded*/
1344 #define E32LIBINIT 0x0004L /* Per-Process Library Initialization */
1345 #define E32LIBTERM 0x40000000L /* Per-Process Library Termination */
1346 #define E32APPMASK 0x0300L /* Application Type Mask */
1350 * Format of E32_MFLAGS(x):
1352 * High word has the following format:
1354 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1356 * | +--- Protected memory library module
1357 * +----- Device driver
1360 #define E32PROTDLL 0x10000L /* Protected memory library module */
1361 #define E32DEVICE 0x20000L /* Device driver */
1362 #define E32MODEXE 0x00000L /* .EXE module */
1363 #define E32MODDLL 0x08000L /* .DLL module */
1364 #define E32MODPROTDLL 0x18000L /* Protected memory library module */
1365 #define E32MODPDEV 0x20000L /* Physical device driver */
1366 #define E32MODVDEV 0x28000L /* Virtual device driver */
1367 #define E32MODMASK 0x38000L /* Module type mask */
1370 * RELOCATION DEFINITIONS - RUN-TIME FIXUPS
1373 typedef union _RELOC_OFS
1375 unsigned short offset16
;
1376 unsigned long offset32
;
1377 } RELOC_OFS
; /* 16-bit or 32-bit offset */
1380 /***ET+ r32_rlc - Relocation item */
1382 struct r32_rlc
/* Relocation item */
1384 unsigned char nr_stype
; /* Source type - field shared with new_rlc */
1385 unsigned char nr_flags
; /* Flag byte - field shared with new_rlc */
1386 short r32_soff
; /* Source offset */
1387 unsigned short r32_objmod
; /* Target object number or Module ordinal */
1391 RELOC_OFS intref
; /* Internal fixup */
1395 RELOC_OFS proc
; /* Procedure name offset */
1396 unsigned long ord
; /* Procedure odrinal */
1397 } extref
; /* External fixup */
1401 unsigned short entry
; /* Entry ordinal */
1402 RELOC_OFS addval
; /* Value added to the address */
1403 } addfix
; /* Additive fixup */
1405 r32_target
; /* Target data */
1406 unsigned short r32_srccount
; /* Number of chained fixup records */
1407 unsigned short r32_chain
; /* Chain head */
1411 * In 32-bit .EXE file run-time relocations are written as varying size
1412 * records, so we need many size definitions.
1415 #define RINTSIZE16 8
1416 #define RINTSIZE32 10
1418 #define RNAMSIZE16 8
1419 #define RNAMSIZE32 10
1420 #define RADDSIZE16 10
1421 #define RADDSIZE32 12
1425 * Access macros defined in NEWEXE.H !!!
1427 #define NR_STYPE(x) (x).nr_stype
1428 #define NR_FLAGS(x) (x).nr_flags
1431 #define R32_SOFF(x) (x).r32_soff
1432 #define R32_OBJNO(x) (x).r32_objmod
1433 #define R32_MODORD(x) (x).r32_objmod
1434 #define R32_OFFSET16(x) (x).r32_target.intref.offset16
1435 #define R32_OFFSET32(x) (x).r32_target.intref.offset32
1436 #define R32_PROCOFF16(x) (x).r32_target.extref.proc.offset16
1437 #define R32_PROCOFF32(x) (x).r32_target.extref.proc.offset32
1438 #define R32_PROCORD(x) (x).r32_target.extref.ord
1439 #define R32_ENTRY(x) (x).r32_target.addfix.entry
1440 #define R32_ADDVAL16(x) (x).r32_target.addfix.addval.offset16
1441 #define R32_ADDVAL32(x) (x).r32_target.addfix.addval.offset32
1442 #define R32_SRCCNT(x) (x).r32_srccount
1443 #define R32_CHAIN(x) (x).r32_chain
1448 * Format of NR_STYPE(x)
1450 * 7 6 5 4 3 2 1 0 - bit no
1452 * | | +-+-+-+--- Source type
1453 * | +----------- Fixup to 16:16 alias
1454 * +------------- List of source offset follows fixup record
1459 /* DEFINED in newexe.h !!! */
1461 #define NRSTYP 0x0f /* Source type mask */
1462 #define NRSBYT 0x00 /* lo byte (8-bits)*/
1463 #define NRSSEG 0x02 /* 16-bit segment (16-bits) */
1464 #define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
1465 #define NRSOFF 0x05 /* 16-bit offset (16-bits) */
1466 #define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
1467 #define NROFF32 0x07 /* 32-bit offset (32-bits) */
1468 #define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
1472 #define NRSRCMASK 0x0f /* Source type mask */
1473 #define NRALIAS 0x10 /* Fixup to alias */
1474 #define NRCHAIN 0x20 /* List of source offset follows */
1475 /* fixup record, source offset field */
1476 /* in fixup record contains number */
1477 /* of elements in list */
1480 * Format of NR_FLAGS(x) and R32_FLAGS(x):
1482 * 7 6 5 4 3 2 1 0 - bit no
1484 * | | | | | +-+--- Reference type
1485 * | | | | +------- Additive fixup
1486 * | | | +----------- 32-bit Target Offset Flag (1 - 32-bit; 0 - 16-bit)
1487 * | | +------------- 32-bit Additive Flag (1 - 32-bit; 0 - 16-bit)
1488 * | +--------------- 16-bit Object/Module ordinal (1 - 16-bit; 0 - 8-bit)
1489 * +----------------- 8-bit import ordinal (1 - 8-bit;
1490 * 0 - NR32BITOFF toggles
1491 * between 16 and 32 bit
1495 #ifdef NEVER_INCLUDE_THE_FOLLWING
1496 /* DEFINED in newexe.h !!! */
1497 #define NRRTYP 0x03 /* Reference type mask */
1498 #define NRRINT 0x00 /* Internal reference */
1499 #define NRRORD 0x01 /* Import by ordinal */
1500 #define NRRNAM 0x02 /* Import by name */
1501 #define NRADD 0x04 /* Additive fixup */
1504 #define NRRENT 0x03 /* Internal entry table fixup */
1506 #define NR32BITOFF 0x10 /* 32-bit Target Offset */
1507 #define NR32BITADD 0x20 /* 32-bit Additive fixup */
1508 #define NR16OBJMOD 0x40 /* 16-bit Object/Module ordinal */
1509 #define NR8BITORD 0x80 /* 8-bit import ordinal */
1513 * Data structures for storing run-time fixups in linker virtual memory.
1515 * Each object has a list of Object Page Directories which specify
1516 * fixups for given page. Each page has its own hash table which is
1517 * used to detect fixups to the same target.
1520 #define PAGEPERDIR 62
1524 typedef struct _OBJPAGEDIR
1526 DWORD next
; /* Virtual pointer to next dir on list */
1527 WORD ht
[PAGEPERDIR
]; /* Pointers to individual hash tables */
1535 /***ET+ o32_obj Object Table Entry */
1537 struct o32_obj
/* Flat .EXE object table entry */
1539 unsigned long o32_size
; /* Object virtual size */
1540 unsigned long o32_base
; /* Object base virtual address */
1541 unsigned long o32_flags
; /* Attribute flags */
1542 unsigned long o32_pagemap
; /* Object page map index */
1543 unsigned long o32_mapsize
; /* Number of entries in object page map */
1544 unsigned long o32_reserved
; /* Reserved */
1548 #define O32_SIZE(x) (x).o32_size
1549 #define O32_BASE(x) (x).o32_base
1550 #define O32_FLAGS(x) (x).o32_flags
1551 #define O32_PAGEMAP(x) (x).o32_pagemap
1552 #define O32_MAPSIZE(x) (x).o32_mapsize
1553 #define O32_RESERVED(x) (x).o32_reserved
1556 * Format of O32_FLAGS(x)
1558 * High word of dword flag field is not used for now.
1559 * Low word has the following format:
1561 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1562 * | | | | | | | | | | | | | | |
1563 * | | | | | | | | | | | | | | +--- Readable Object
1564 * | | | | | | | | | | | | | +----- Writeable Object
1565 * | | | | | | | | | | | | +------- Executable Object
1566 * | | | | | | | | | | | +--------- Resource Object
1567 * | | | | | | | | | | +----------- Object is Discardable
1568 * | | | | | | | | | +------------- Object is Shared
1569 * | | | | | | | | +--------------- Object has preload pages
1570 * | | | | | | | +----------------- Object has invalid pages
1571 * | | | | | | +------------------- Object is permanent and swappable
1572 * | | | | | +--------------------- Object is permanent and resident
1573 * | | | | +----------------------- Object is permanent and long lockable
1574 * | | | +----------------------------- 16:16 alias required (80x86 specific)
1575 * | | +-------------------------------- Big/Default bit setting (80x86 specific)
1576 * | +----------------------------------- Object is conforming for code (80x86 specific)
1577 * +-------------------------------------- Object I/O privilege level (80x86 specific)
1581 #define OBJREAD 0x0001L /* Readable Object */
1582 #define OBJWRITE 0x0002L /* Writeable Object */
1583 #define OBJRSRC 0x0008L /* Resource Object */
1584 #define OBJINVALID 0x0080L /* Object has invalid pages */
1585 #define LNKNONPERM 0x0600L /* Object is nonpermanent - should be */
1586 #define OBJNONPERM 0x0000L /* zero in the .EXE but LINK386 uses 6 */
1587 #define OBJPERM 0x0100L /* Object is permanent and swappable */
1588 #define OBJRESIDENT 0x0200L /* Object is permanent and resident */
1589 #define OBJCONTIG 0x0300L /* Object is resident and contiguous */
1590 #define OBJDYNAMIC 0x0400L /* Object is permanent and long locable */
1591 #define OBJTYPEMASK 0x0700L /* Object type mask */
1592 #define OBJALIAS16 0x1000L /* 16:16 alias required (80x86 specific) */
1593 #define OBJBIGDEF 0x2000L /* Big/Default bit setting (80x86 specific) */
1594 #define OBJIOPL 0x8000L /* Object I/O privilege level (80x86 specific) */
1597 * Name these flags differently for EXEHDR.EXE - avoid conflicts with 286 version
1599 #define OBJDISCARD 0x0010L /* Object is Discardable */
1600 #define OBJSHARED 0x0020L /* Object is Shared */
1601 #define OBJPRELOAD 0x0040L /* Object has preload pages */
1602 #define OBJEXEC 0x0004L /* Executable Object */
1603 #define OBJCONFORM 0x4000L /* Object is conforming for code (80x86 specific) */
1606 * Life will be easier, if we keep the same names for the following flags:
1609 #define NSDISCARD 0x0010L /* Object is Discardable */
1612 #define NSMOVE NSDISCARD /* Moveable object is for sure Discardable */
1615 #define NSSHARED 0x0020L /* Object is Shared */
1618 #define NSPRELOAD 0x0040L /* Object has preload pages */
1621 #define NSEXRD 0x0004L /* Executable Object */
1624 #define NSCONFORM 0x4000L /* Object is conforming for code (80x86 specific) */
1629 /***ET+ o32_map - Object Page Map entry */
1631 struct o32_map
/* Object Page Table entry */
1633 unsigned long o32_pagedataoffset
; /* file offset of page */
1634 unsigned short o32_pagesize
; /* # bytes of page data */
1635 unsigned short o32_pageflags
; /* Per-Page attributes */
1639 #define GETPAGEIDX(x) ((x).o32_pagedataoffset)
1641 #define PUTPAGEIDX(x,i) ((x).o32_pagedataoffset = ((unsigned long)(i)))
1643 #define PUTPAGESIZ(x,i) ((x).o32_pagesize = ((unsigned int)(i)))
1645 #define GETPAGESIZ(x) ((x).o32_pagesize)
1647 #define PAGEFLAGS(x) (x).o32_pageflags
1650 #define VALID 0x0000 /* Valid Physical Page in .EXE */
1651 #define ITERDATA 0x0001 /* Iterated Data Page */
1652 #define INVALID 0x0002 /* Invalid Page */
1653 #define ZEROED 0x0003 /* Zero Filled Page */
1654 #define RANGE 0x0004 /* Range of pages */
1655 #define ITERDATA2 0x0005 /* Iterated Data Page Type II */
1662 /***ET+ rsrc32 - Resource Table Entry */
1664 struct rsrc32
/* Resource Table Entry */
1666 unsigned short type
; /* Resource type */
1667 unsigned short name
; /* Resource name */
1668 unsigned long cb
; /* Resource size */
1669 unsigned short obj
; /* Object number */
1670 unsigned long offset
; /* Offset within object */
1676 * Iteration Record format for 'EXEPACK'ed pages.
1680 unsigned short LX_nIter
; /* number of iterations */
1681 unsigned short LX_nBytes
; /* number of bytes */
1682 unsigned char LX_Iterdata
; /* iterated data byte(s) */
1687 * ENTRY TABLE DEFINITIONS
1690 /***ET+ b32_bundle - Entry Table */
1694 unsigned char b32_cnt
; /* Number of entries in this bundle */
1695 unsigned char b32_type
; /* Bundle type */
1696 unsigned short b32_obj
; /* Object number */
1697 }; /* Follows entry types */
1701 unsigned char e32_flags
; /* Entry point flags */
1704 RELOC_OFS e32_offset
; /* 16-bit/32-bit offset entry */
1707 unsigned short offset
; /* Offset in segment */
1708 unsigned short callgate
; /* Callgate selector */
1710 e32_callgate
; /* 286 (16-bit) call gate */
1713 unsigned short modord
; /* Module ordinal number */
1714 unsigned long value
; /* Proc name offset or ordinal */
1716 e32_fwd
; /* Forwarder */
1718 e32_variant
; /* Entry variant */
1723 #define B32_CNT(x) (x).b32_cnt
1724 #define B32_TYPE(x) (x).b32_type
1725 #define B32_OBJ(x) (x).b32_obj
1727 #define E32_EFLAGS(x) (x).e32_flags
1728 #define E32_OFFSET16(x) (x).e32_variant.e32_offset.offset16
1729 #define E32_OFFSET32(x) (x).e32_variant.e32_offset.offset32
1730 #define E32_GATEOFF(x) (x).e32_variant.e32_callgate.offset
1731 #define E32_GATE(x) (x).e32_variant.e32_callgate.callgate
1732 #define E32_MODORD(x) (x).e32_variant.e32_fwd.modord
1733 #define E32_VALUE(x) (x).e32_variant.e32_fwd.value
1744 #define EMPTY 0x00 /* Empty bundle */
1745 #define ENTRY16 0x01 /* 16-bit offset entry point */
1746 #define GATE16 0x02 /* 286 call gate (16-bit IOPL) */
1747 #define ENTRY32 0x03 /* 32-bit offset entry point */
1748 #define ENTRYFWD 0x04 /* Forwarder entry point */
1749 #define TYPEINFO 0x80 /* Typing information present flag */
1753 * Format for E32_EFLAGS(x)
1755 * 7 6 5 4 3 2 1 0 - bit no
1757 * | | | | | | | +--- exported entry
1758 * | | | | | | +----- uses shared data
1759 * +-+-+-+-+-+------- parameter word count
1762 #define E32EXPORT 0x01 /* Exported entry */
1763 #define E32SHARED 0x02 /* Uses shared data */
1764 #define E32PARAMS 0xf8 /* Parameter word count mask */
1767 * Flags for forwarders only:
1770 #define FWD_ORDINAL 0x01 /* Imported by ordinal */
1773 #pragma pack() /* Restore default alignment */
1777 #endif /* __EXE386__ */