VirtualBox

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

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

IPRT: Initial adaption of the kstuff loader code. bugref:9232

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1/* $Id: lx.h 74638 2018-10-06 18:31:59Z 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
37
38#ifndef IMAGE_OS2_SIGNATURE_LX
39/** LX signature ("LX") */
40# define IMAGE_LX_SIGNATURE K_LE2H_U16('L' | ('X' << 8))
41#endif
42
43#pragma pack(1) /** @todo mostly unnecessary. */
44
45/**
46 * Linear eXecutable header.
47 * This structure is exactly 196 bytes long.
48 */
49struct 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};
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/** @name Relocations (aka Fixups).
201 * @{ */
202typedef union _offset
203{
204 uint16_t offset16;
205 uint32_t offset32;
206} offset;
207
208/** A relocation.
209 * @remark this structure isn't very usable since LX relocations comes in too many size variations.
210 */
211struct r32_rlc
212{
213 uint8_t nr_stype;
214 uint8_t nr_flags;
215 int16_t r32_soff;
216 uint16_t r32_objmod;
217
218 union targetid
219 {
220 offset intref;
221 union extfixup
222 {
223 offset proc;
224 uint32_t ord;
225 } extref;
226 struct addfixup
227 {
228 uint16_t entry;
229 offset addval;
230 } addfix;
231 } r32_target;
232 uint16_t r32_srccount;
233 uint16_t r32_chain;
234};
235
236/** @name Some attempt at size constanstants.
237 * @{
238 */
239#define RINTSIZE16 8
240#define RINTSIZE32 10
241#define RORDSIZE 8
242#define RNAMSIZE16 8
243#define RNAMSIZE32 10
244#define RADDSIZE16 10
245#define RADDSIZE32 12
246/** @} */
247
248/** @name nr_stype (source flags)
249 * @{ */
250#define NRSBYT 0x00
251#define NRSSEG 0x02
252#define NRSPTR 0x03
253#define NRSOFF 0x05
254#define NRPTR48 0x06
255#define NROFF32 0x07
256#define NRSOFF32 0x08
257#define NRSTYP 0x0f
258#define NRSRCMASK 0x0f
259#define NRALIAS 0x10
260#define NRCHAIN 0x20
261/** @} */
262
263/** @name nr_flags (target flags)
264 * @{ */
265#define NRRINT 0x00
266#define NRRORD 0x01
267#define NRRNAM 0x02
268#define NRRENT 0x03
269#define NRRTYP 0x03
270#define NRADD 0x04
271#define NRICHAIN 0x08
272#define NR32BITOFF 0x10
273#define NR32BITADD 0x20
274#define NR16OBJMOD 0x40
275#define NR8BITORD 0x80
276/** @} */
277
278/** @} */
279
280
281/** @name The Object Table (aka segment table)
282 * @{ */
283
284/** The Object Table Entry. */
285struct o32_obj
286{
287 /** The size of the object. */
288 uint32_t o32_size;
289 /** The base address of the object. */
290 uint32_t o32_base;
291 /** Object flags. */
292 uint32_t o32_flags;
293 /** Page map index. */
294 uint32_t o32_pagemap;
295 /** Page map size. (doesn't need to be o32_size >> page shift). */
296 uint32_t o32_mapsize;
297 /** Reserved */
298 uint32_t o32_reserved;
299};
300
301/** @name o32_flags
302 * @{ */
303/** Read access. */
304#define OBJREAD UINT32_C(0x00000001)
305/** Write access. */
306#define OBJWRITE UINT32_C(0x00000002)
307/** Execute access. */
308#define OBJEXEC UINT32_C(0x00000004)
309/** Resource object. */
310#define OBJRSRC UINT32_C(0x00000008)
311/** The object is discarable (i.e. don't swap, just load in pages from the executable).
312 * This overlaps a bit with object type. */
313#define OBJDISCARD UINT32_C(0x00000010)
314/** The object is shared. */
315#define OBJSHARED UINT32_C(0x00000020)
316/** The object has preload pages. */
317#define OBJPRELOAD UINT32_C(0x00000040)
318/** The object has invalid pages. */
319#define OBJINVALID UINT32_C(0x00000080)
320/** Non-permanent, link386 bug. */
321#define LNKNONPERM UINT32_C(0x00000600)
322/** Non-permanent, correct 'value'. */
323#define OBJNONPERM UINT32_C(0x00000000)
324/** Obj Type: The object is permanent and swappable. */
325#define OBJPERM UINT32_C(0x00000100)
326/** Obj Type: The object is permanent and resident (i.e. not swappable). */
327#define OBJRESIDENT UINT32_C(0x00000200)
328/** Obj Type: The object is resident and contigious. */
329#define OBJCONTIG UINT32_C(0x00000300)
330/** Obj Type: The object is permanent and long locable. */
331#define OBJDYNAMIC UINT32_C(0x00000400)
332/** Object type mask. */
333#define OBJTYPEMASK UINT32_C(0x00000700)
334/** x86: The object require an 16:16 alias. */
335#define OBJALIAS16 UINT32_C(0x00001000)
336/** x86: Big/Default selector setting, i.e. toggle 32-bit or 16-bit. */
337#define OBJBIGDEF UINT32_C(0x00002000)
338/** x86: conforming selector setting (weird stuff). */
339#define OBJCONFORM UINT32_C(0x00004000)
340/** x86: IOPL. */
341#define OBJIOPL UINT32_C(0x00008000)
342/** @} */
343
344/** A Object Page Map Entry. */
345struct o32_map
346{
347 /** The file offset of the page. */
348 uint32_t o32_pagedataoffset;
349 /** The number of bytes of raw page data. */
350 uint16_t o32_pagesize;
351 /** Per page flags describing how the page is encoded in the file. */
352 uint16_t o32_pageflags;
353};
354
355/** @name o32 o32_pageflags
356 * @{
357 */
358/** Raw page (uncompressed) in the file. */
359#define VALID UINT16_C(0x0000)
360/** RLE encoded page in file. */
361#define ITERDATA UINT16_C(0x0001)
362/** Invalid page, nothing in the file. */
363#define INVALID UINT16_C(0x0002)
364/** Zero page, nothing in file. */
365#define ZEROED UINT16_C(0x0003)
366/** range of pages (what is this?) */
367#define RANGE UINT16_C(0x0004)
368/** Compressed page in file. */
369#define ITERDATA2 UINT16_C(0x0005)
370/** @} */
371
372
373/** Iteration Record format (RLE compressed page). */
374struct LX_Iter
375{
376 /** Number of iterations. */
377 uint16_t LX_nIter;
378 /** The number of bytes that's being iterated. */
379 uint16_t LX_nBytes;
380 /** The bytes. */
381 uint8_t LX_Iterdata;
382};
383
384/** @} */
385
386
387/** A Resource Table Entry */
388struct rsrc32
389{
390 /** Resource Type. */
391 uint16_t type;
392 /** Resource ID. */
393 uint16_t name;
394 /** Resource size in bytes. */
395 uint32_t cb;
396 /** The index of the object containing the resource. */
397 uint16_t obj;
398 /** Offset of the resource that within the object. */
399 uint32_t offset;
400};
401
402
403/** @name The Entry Table (aka Export Table)
404 * @{ */
405
406/** Entry bundle.
407 * Header descripting up to 255 entries that follows immediatly after this structure. */
408struct b32_bundle
409{
410 /** The number of entries. */
411 uint8_t b32_cnt;
412 /** The type of bundle. */
413 uint8_t b32_type;
414 /** The index of the object containing these entry points. */
415 uint16_t b32_obj;
416};
417
418/** @name b32_type
419 * @{ */
420/** Empty bundle, filling up unused ranges of ordinals. */
421#define EMPTY 0x00
422/** 16-bit offset entry point. */
423#define ENTRY16 0x01
424/** 16-bit callgate entry point. */
425#define GATE16 0x02
426/** 32-bit offset entry point. */
427#define ENTRY32 0x03
428/** Forwarder entry point. */
429#define ENTRYFWD 0x04
430/** Typing information present indicator. */
431#define TYPEINFO 0x80
432/** @} */
433
434
435/** Entry point. */
436struct e32_entry
437{
438 /** Entry point flags */
439 uint8_t e32_flags; /* Entry point flags */
440 union entrykind
441 {
442 /** ENTRY16 or ENTRY32. */
443 offset e32_offset;
444 /** GATE16 */
445 struct scallgate
446 {
447 /** Offset into segment. */
448 uint16_t offset;
449 /** The callgate selector */
450 uint16_t callgate;
451 } e32_callgate;
452 /** ENTRYFWD */
453 struct fwd
454 {
455 /** Module ordinal number (i.e. into the import module table). */
456 uint16_t modord;
457 /** Procedure name or ordinal number. */
458 uint32_t value;
459 } e32_fwd;
460 } e32_variant;
461};
462
463/** @name e32_flags
464 * @{ */
465/** Exported entry (set) or private entry (clear). */
466#define E32EXPORT 0x01
467/** Uses shared data. */
468#define E32SHARED 0x02
469/** Parameter word count mask. */
470#define E32PARAMS 0xf8
471/** ENTRYFWD: Imported by ordinal (set) or by name (clear). */
472#define FWD_ORDINAL 0x01
473/** @} */
474
475/** @name dunno
476 * @{ */
477#define FIXENT16 3
478#define FIXENT32 5
479#define GATEENT16 5
480#define FWDENT 7
481/** @} */
482
483#pragma pack()
484
485#endif
486
487
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