VirtualBox

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

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

*: scm --fix-header-guard-endif

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