VirtualBox

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

Last change on this file since 93941 was 81369, checked in by vboxsync, 5 years ago

*: doxygen fixes

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