VirtualBox

source: vbox/trunk/include/iprt/formats/lx.h@ 74644

Last change on this file since 74644 was 74644, checked in by vboxsync, 6 years ago

IPRT: More adjustments to the LX and Mach-O loader code from kStuff. bugref:9232

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1/* $Id: lx.h 74644 2018-10-06 19:58:37Z vboxsync $ */
2/** @file
3 * LX structures, types and defines.
4 */
5
6/*
7 * Copyright (c) 2006-2007 Knut St. Osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31#ifndef ___iprt_formats_lx_h___
32#define ___iprt_formats_lx_h___
33
34#include <iprt/types.h>
35#include <iprt/assertcompile.h>
36
37RT_C_DECLS_BEGIN
38
39#ifndef IMAGE_OS2_SIGNATURE_LX
40/** LX signature ("LX") */
41# define IMAGE_LX_SIGNATURE K_LE2H_U16('L' | ('X' << 8))
42#endif
43
44
45/**
46 * Linear eXecutable header.
47 * This structure is exactly 196 bytes long.
48 */
49typedef struct e32_exe
50{
51 uint8_t e32_magic[2];
52 uint8_t e32_border;
53 uint8_t e32_worder;
54 uint32_t e32_level;
55 uint16_t e32_cpu;
56 uint16_t e32_os;
57 uint32_t e32_ver;
58 uint32_t e32_mflags;
59 uint32_t e32_mpages;
60 uint32_t e32_startobj;
61 uint32_t e32_eip;
62 uint32_t e32_stackobj;
63 uint32_t e32_esp;
64 uint32_t e32_pagesize;
65 uint32_t e32_pageshift;
66 /** The size of the fixup section.
67 * The fixup section consists of the fixup page table, the fixup record table,
68 * the import module table, and the import procedure name table.
69 */
70 uint32_t e32_fixupsize;
71 uint32_t e32_fixupsum;
72 /** The size of the resident loader section.
73 * This includes the object table, the object page map table, the resource table, the resident name table,
74 * the entry table, the module format directives table, and the page checksum table (?). */
75 uint32_t e32_ldrsize;
76 /** The checksum of the loader section. 0 if not calculated. */
77 uint32_t e32_ldrsum;
78 /** The offset of the object table relative to this structure. */
79 uint32_t e32_objtab;
80 /** Count of objects. */
81 uint32_t e32_objcnt;
82 /** The offset of the object page map table relative to this structure. */
83 uint32_t e32_objmap;
84 /** The offset of the object iterated pages (whatever this is used for) relative to the start of the file. */
85 uint32_t e32_itermap;
86 /** The offset of the resource table relative to this structure. */
87 uint32_t e32_rsrctab;
88 /** The number of entries in the resource table. */
89 uint32_t e32_rsrccnt;
90 /** The offset of the resident name table relative to this structure. */
91 uint32_t e32_restab;
92 /** The offset of the entry (export) table relative to this structure. */
93 uint32_t e32_enttab;
94 /** The offset of the module format directives table relative to this structure. */
95 uint32_t e32_dirtab;
96 /** The number of entries in the module format directives table. */
97 uint32_t e32_dircnt;
98 /** The offset of the fixup page table relative to this structure. */
99 uint32_t e32_fpagetab;
100 /** The offset of the fixup record table relative to this structure. */
101 uint32_t e32_frectab;
102 /** The offset of the import module name table relative to this structure. */
103 uint32_t e32_impmod;
104 /** The number of entries in the import module name table. */
105 uint32_t e32_impmodcnt;
106 /** The offset of the import procedure name table relative to this structure. */
107 uint32_t e32_impproc;
108 /** The offset of the page checksum table relative to this structure. */
109 uint32_t e32_pagesum;
110 /** The offset of the data pages relative to the start of the file. */
111 uint32_t e32_datapage;
112 /** The number of preload pages (ignored). */
113 uint32_t e32_preload;
114 /** The offset of the non-resident name table relative to the start of the file. */
115 uint32_t e32_nrestab;
116 /** The size of the non-resident name table. */
117 uint32_t e32_cbnrestab;
118 uint32_t e32_nressum;
119 uint32_t e32_autodata;
120 uint32_t e32_debuginfo;
121 uint32_t e32_debuglen;
122 uint32_t e32_instpreload;
123 uint32_t e32_instdemand;
124 uint32_t e32_heapsize;
125 uint32_t e32_stacksize;
126 uint8_t e32_res3[20];
127} e32_exe;
128AssertCompileSize(struct e32_exe, 196);
129
130/** e32_magic[0] */
131#define E32MAGIC1 'L'
132/** e32_magic[1] */
133#define E32MAGIC2 'X'
134/** MAKEWORD(e32_magic[0], e32_magic[1]) */
135#define E32MAGIC 0x584c
136/** e32_border - little endian */
137#define E32LEBO 0
138/** e32_border - big endian */
139#define E32BEBO 1
140/** e32_worder - little endian */
141#define E32LEWO 0
142/** e32_worder - big endian */
143#define E32BEWO 1
144/** e32_level */
145#define E32LEVEL UINT32_C(0)
146/** e32_cpu - 80286 */
147#define E32CPU286 1
148/** e32_cpu - 80386 */
149#define E32CPU386 2
150/** e32_cpu - 80486 */
151#define E32CPU486 3
152/** e32_pagesize */
153#define OBJPAGELEN UINT32_C(0x1000)
154
155
156/** @name e32_mflags
157 * @{ */
158/** App Type: Fullscreen only. */
159#define E32NOPMW UINT32_C(0x00000100)
160/** App Type: PM API. */
161#define E32PMAPI UINT32_C(0x00000300)
162/** App Type: PM VIO compatible. */
163#define E32PMW UINT32_C(0x00000200)
164/** Application type mask. */
165#define E32APPMASK UINT32_C(0x00000300)
166/** Executable module. */
167#define E32MODEXE UINT32_C(0x00000000)
168/** Dynamic link library (DLL / library) module. */
169#define E32MODDLL UINT32_C(0x00008000)
170/** Protected memory DLL. */
171#define E32PROTDLL UINT32_C(0x00010000)
172/** Physical Device Driver. */
173#define E32MODPDEV UINT32_C(0x00020000)
174/** Virtual Device Driver. */
175#define E32MODVDEV UINT32_C(0x00028000)
176/** Device driver */
177#define E32DEVICE E32MODPDEV
178/** Dynamic link library (DLL / library) module. */
179#define E32NOTP E32MODDLL
180/** Protected memory DLL. */
181#define E32MODPROTDLL (E32MODDLL | E32PROTDLL)
182/** Module Type mask. */
183#define E32MODMASK UINT32_C(0x00038000)
184/** Not loadable (linker error). */
185#define E32NOLOAD UINT32_C(0x00002000)
186/** No internal fixups. */
187#define E32NOINTFIX UINT32_C(0x00000010)
188/** No external fixups (i.e. imports). */
189#define E32NOEXTFIX UINT32_C(0x00000020)
190/** System DLL, no internal fixups. */
191#define E32SYSDLL UINT32_C(0x00000008)
192/** Global (set) or per instance (cleared) library initialization. */
193#define E32LIBINIT UINT32_C(0x00000004)
194/** Global (set) or per instance (cleared) library termination. */
195#define E32LIBTERM UINT32_C(0x40000000)
196/** Indicates when set in an executable that the process isn't SMP safe. */
197#define E32NOTMPSAFE UINT32_C(0x00080000)
198/** @} */
199
200
201/** @name Relocations (aka Fixups).
202 * @{ */
203typedef union r32_offset
204{
205 uint16_t offset16;
206 uint32_t offset32;
207} r32_offset;
208AssertCompileSize(r32_offset, 4);
209
210/** A relocation.
211 * @remark this structure isn't very usable since LX relocations comes in too many size variations.
212 */
213#pragma pack(1)
214typedef struct r32_rlc
215{
216 uint8_t nr_stype;
217 uint8_t nr_flags;
218 int16_t r32_soff;
219 uint16_t r32_objmod;
220
221 union targetid
222 {
223 r32_offset intref;
224 union extfixup
225 {
226 r32_offset proc;
227 uint32_t ord;
228 } extref;
229 struct addfixup
230 {
231 uint16_t entry;
232 r32_offset addval;
233 } addfix;
234 } r32_target;
235 uint16_t r32_srccount;
236 uint16_t r32_chain;
237} r32_rlc;
238#pragma pack()
239AssertCompileSize(r32_rlc, 16);
240
241/** @name Some attempt at size constanstants.
242 * @{
243 */
244#define RINTSIZE16 8
245#define RINTSIZE32 10
246#define RORDSIZE 8
247#define RNAMSIZE16 8
248#define RNAMSIZE32 10
249#define RADDSIZE16 10
250#define RADDSIZE32 12
251/** @} */
252
253/** @name nr_stype (source flags)
254 * @{ */
255#define NRSBYT 0x00
256#define NRSSEG 0x02
257#define NRSPTR 0x03
258#define NRSOFF 0x05
259#define NRPTR48 0x06
260#define NROFF32 0x07
261#define NRSOFF32 0x08
262#define NRSTYP 0x0f
263#define NRSRCMASK 0x0f
264#define NRALIAS 0x10
265#define NRCHAIN 0x20
266/** @} */
267
268/** @name nr_flags (target flags)
269 * @{ */
270#define NRRINT 0x00
271#define NRRORD 0x01
272#define NRRNAM 0x02
273#define NRRENT 0x03
274#define NRRTYP 0x03
275#define NRADD 0x04
276#define NRICHAIN 0x08
277#define NR32BITOFF 0x10
278#define NR32BITADD 0x20
279#define NR16OBJMOD 0x40
280#define NR8BITORD 0x80
281/** @} */
282
283/** @} */
284
285
286/** @name The Object Table (aka segment table)
287 * @{ */
288
289/** The Object Table Entry. */
290typedef struct o32_obj
291{
292 /** The size of the object. */
293 uint32_t o32_size;
294 /** The base address of the object. */
295 uint32_t o32_base;
296 /** Object flags. */
297 uint32_t o32_flags;
298 /** Page map index. */
299 uint32_t o32_pagemap;
300 /** Page map size. (doesn't need to be o32_size >> page shift). */
301 uint32_t o32_mapsize;
302 /** Reserved */
303 uint32_t o32_reserved;
304} o32_obj;
305AssertCompileSize(o32_obj, 24);
306
307/** @name o32_flags
308 * @{ */
309/** Read access. */
310#define OBJREAD UINT32_C(0x00000001)
311/** Write access. */
312#define OBJWRITE UINT32_C(0x00000002)
313/** Execute access. */
314#define OBJEXEC UINT32_C(0x00000004)
315/** Resource object. */
316#define OBJRSRC UINT32_C(0x00000008)
317/** The object is discarable (i.e. don't swap, just load in pages from the executable).
318 * This overlaps a bit with object type. */
319#define OBJDISCARD UINT32_C(0x00000010)
320/** The object is shared. */
321#define OBJSHARED UINT32_C(0x00000020)
322/** The object has preload pages. */
323#define OBJPRELOAD UINT32_C(0x00000040)
324/** The object has invalid pages. */
325#define OBJINVALID UINT32_C(0x00000080)
326/** Non-permanent, link386 bug. */
327#define LNKNONPERM UINT32_C(0x00000600)
328/** Non-permanent, correct 'value'. */
329#define OBJNONPERM UINT32_C(0x00000000)
330/** Obj Type: The object is permanent and swappable. */
331#define OBJPERM UINT32_C(0x00000100)
332/** Obj Type: The object is permanent and resident (i.e. not swappable). */
333#define OBJRESIDENT UINT32_C(0x00000200)
334/** Obj Type: The object is resident and contigious. */
335#define OBJCONTIG UINT32_C(0x00000300)
336/** Obj Type: The object is permanent and long locable. */
337#define OBJDYNAMIC UINT32_C(0x00000400)
338/** Object type mask. */
339#define OBJTYPEMASK UINT32_C(0x00000700)
340/** x86: The object require an 16:16 alias. */
341#define OBJALIAS16 UINT32_C(0x00001000)
342/** x86: Big/Default selector setting, i.e. toggle 32-bit or 16-bit. */
343#define OBJBIGDEF UINT32_C(0x00002000)
344/** x86: conforming selector setting (weird stuff). */
345#define OBJCONFORM UINT32_C(0x00004000)
346/** x86: IOPL. */
347#define OBJIOPL UINT32_C(0x00008000)
348/** @} */
349
350/** A Object Page Map Entry. */
351typedef struct o32_map
352{
353 /** The file offset of the page. */
354 uint32_t o32_pagedataoffset;
355 /** The number of bytes of raw page data. */
356 uint16_t o32_pagesize;
357 /** Per page flags describing how the page is encoded in the file. */
358 uint16_t o32_pageflags;
359} o32_map;
360AssertCompileSize(o32_map, 8);
361
362/** @name o32 o32_pageflags
363 * @{
364 */
365/** Raw page (uncompressed) in the file. */
366#define VALID UINT16_C(0x0000)
367/** RLE encoded page in file. */
368#define ITERDATA UINT16_C(0x0001)
369/** Invalid page, nothing in the file. */
370#define INVALID UINT16_C(0x0002)
371/** Zero page, nothing in file. */
372#define ZEROED UINT16_C(0x0003)
373/** range of pages (what is this?) */
374#define RANGE UINT16_C(0x0004)
375/** Compressed page in file. */
376#define ITERDATA2 UINT16_C(0x0005)
377/** @} */
378
379
380/** Iteration Record format (RLE compressed page). */
381#pragma pack(1)
382typedef struct LX_Iter
383{
384 /** Number of iterations. */
385 uint16_t LX_nIter;
386 /** The number of bytes that's being iterated. */
387 uint16_t LX_nBytes;
388 /** The bytes. */
389 uint8_t LX_Iterdata;
390} LX_Iter;
391#pragma pack()
392AssertCompileSize(LX_Iter, 5);
393
394/** @} */
395
396
397/** A Resource Table Entry */
398#pragma pack(1)
399typedef struct rsrc32
400{
401 /** Resource Type. */
402 uint16_t type;
403 /** Resource ID. */
404 uint16_t name;
405 /** Resource size in bytes. */
406 uint32_t cb;
407 /** The index of the object containing the resource. */
408 uint16_t obj;
409 /** Offset of the resource that within the object. */
410 uint32_t offset;
411} rsrc32;
412#pragma pack()
413AssertCompileSize(rsrc32, 14);
414
415
416/** @name The Entry Table (aka Export Table)
417 * @{ */
418
419/** Entry bundle.
420 * Header descripting up to 255 entries that follows immediatly after this structure. */
421typedef struct b32_bundle
422{
423 /** The number of entries. */
424 uint8_t b32_cnt;
425 /** The type of bundle. */
426 uint8_t b32_type;
427 /** The index of the object containing these entry points. */
428 uint16_t b32_obj;
429} b32_bundle;
430AssertCompileSize(b32_bundle, 4);
431
432/** @name b32_type
433 * @{ */
434/** Empty bundle, filling up unused ranges of ordinals. */
435#define EMPTY 0x00
436/** 16-bit offset entry point. */
437#define ENTRY16 0x01
438/** 16-bit callgate entry point. */
439#define GATE16 0x02
440/** 32-bit offset entry point. */
441#define ENTRY32 0x03
442/** Forwarder entry point. */
443#define ENTRYFWD 0x04
444/** Typing information present indicator. */
445#define TYPEINFO 0x80
446/** @} */
447
448
449/** Entry point. */
450#pragma pack(1)
451typedef struct e32_entry
452{
453 /** Entry point flags */
454 uint8_t e32_flags; /* Entry point flags */
455 union entrykind
456 {
457 /** ENTRY16 or ENTRY32. */
458 r32_offset e32_offset;
459 /** GATE16 */
460 struct scallgate
461 {
462 /** Offset into segment. */
463 uint16_t offset;
464 /** The callgate selector */
465 uint16_t callgate;
466 } e32_callgate;
467 /** ENTRYFWD */
468 struct fwd
469 {
470 /** Module ordinal number (i.e. into the import module table). */
471 uint16_t modord;
472 /** Procedure name or ordinal number. */
473 uint32_t value;
474 } e32_fwd;
475 } e32_variant;
476} e32_entry;
477#pragma pack()
478
479/** @name e32_flags
480 * @{ */
481/** Exported entry (set) or private entry (clear). */
482#define E32EXPORT 0x01
483/** Uses shared data. */
484#define E32SHARED 0x02
485/** Parameter word count mask. */
486#define E32PARAMS 0xf8
487/** ENTRYFWD: Imported by ordinal (set) or by name (clear). */
488#define FWD_ORDINAL 0x01
489/** @} */
490
491/** @name dunno
492 * @{ */
493#define FIXENT16 3
494#define FIXENT32 5
495#define GATEENT16 5
496#define FWDENT 7
497/** @} */
498
499
500RT_C_DECLS_END
501
502#endif
503
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette