----------------------------------------------------------------------------------
--                                                                              --
-- Windows Types API interface Unit for Object Pascal                           --
--                                                                              --
-- Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          --
-- Corporation. All Rights Reserved.                                            --
--                                                                              --
-- The original file is: winnt.h, released August 2001. The original Pascal     --
-- code is: WinNT.pas, released December 2000. The initial developer of the     --
-- Pascal code is Marcel van Brakel (brakelm att chello dott nl).               --
--                                                                              --
-- Portions created by Marcel van Brakel are Copyright (C) 1999-2001            --
-- Marcel van Brakel. All Rights Reserved.                                      --
--                                                                              --
-- Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        --
--                                                                              --
-- You may retrieve the latest version of this file at the Project JEDI         --
-- APILIB home page, located at http://jedi-apilib.sourceforge.net              --
--                                                                              --
-- The contents of this file are used with permission, subject to the Mozilla   --
-- Public License Version 1.1 (the "License"); you may not use this file except --
-- in compliance with the License. You may obtain a copy of the License at      --
-- http://www.mozilla.org/MPL/MPL-1.1.html                                      --
--                                                                              --
-- Software distributed under the License is distributed on an "AS IS" basis,   --
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for --
-- the specific language governing rights and limitations under the License.    --
--                                                                              --
-- Alternatively, the contents of this file may be used under the terms of the  --
-- GNU Lesser General Public License (the  "LGPL License"), in which case the   --
-- provisions of the LGPL License are applicable instead of those above.        --
-- If you wish to allow use of your version of this file only under the terms   --
-- of the LGPL License and not to allow others to use your version of this file --
-- under the MPL, indicate your decision by deleting  the provisions above and  --
-- replace  them with the notice and other provisions required by the LGPL      --
-- License.  If you do not delete the provisions above, a recipient may use     --
-- your version of this file under either the MPL or the LGPL License.          --
--                                                                              --
-- For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html --
--                                                                              --
----------------------------------------------------------------------------------

--  $Id: Jwa.Win_NT.ads,v 1.15 2007/10/20 18:08:49 dezipaitor Exp $

with
  Interfaces, System, Jwa.Utils,
  Jwa.Win_Type;

use
  Interfaces, Jwa.Utils,
  Jwa.Win_Type;

package Jwa.Win_NT is
   Max_Byte  : constant := 16#FF#;
   Max_Word  : constant := 16#FFFF#;
   Max_DWord : constant := 16#FFFF_FFFF#;


--%% {$IFNDEF JWA_INCLUDEMODE}
   Ver_Server_NT                      : constant := 16#8000_0000#;
   Ver_Workstation_NT                 : constant := 16#4000_0000#;
   Ver_Suite_Smallbusiness            : constant := 16#0000_0001#;
   Ver_Suite_Enterprise               : constant := 16#0000_0002#;
   Ver_Suite_Backoffice               : constant := 16#0000_0004#;
   Ver_Suite_Communications           : constant := 16#0000_0008#;
   Ver_Suite_Terminal                 : constant := 16#0000_0010#;
   Ver_Suite_Smallbusiness_Restricted : constant := 16#0000_0020#;
   Ver_Suite_Embeddednt               : constant := 16#0000_0040#;
   Ver_Suite_Datacenter               : constant := 16#0000_0080#;
   Ver_Suite_Singleuserts             : constant := 16#0000_0100#;
   Ver_Suite_Personal                 : constant := 16#0000_0200#;
   Ver_Suite_Blade                    : constant := 16#0000_0400#;
--%% {$ENDIF JWA_INCLUDEMODE}
   Ver_Suite_Embedded_Restricted      : constant := 16#0000_0800#;
   Ver_Suite_Security_Appliance       : constant := 16#0000_1000#;

--
--  Language IDs.
--
--  The following two combinations of primary language ID and
--  sublanguage ID have special semantics:
--
--    Primary Language ID   Sublanguage ID      Result
--    -------------------   ---------------     ------------------------
--    LANG_NEUTRAL          SUBLANG_NEUTRAL     Language neutral
--    LANG_NEUTRAL          SUBLANG_DEFAULT     User default language
--    LANG_NEUTRAL          SUBLANG_SYS_DEFAULT System default language
--    LANG_INVARIANT        SUBLANG_NEUTRAL     Invariant locale
--

--
--  Primary language IDs.
--

   Lang_Neutral    : constant := 16#00#;
   Lang_Invariant  : constant := 16#7F#;

   Lang_Afrikaans  : constant := 16#36#;
   Lang_Albanian   : constant := 16#1C#;
   Lang_Arabic     : constant := 16#01#;
   Lang_Armenian   : constant := 16#2B#;
   Lang_Assamese   : constant := 16#4D#;
   Lang_Azeri      : constant := 16#2C#;
   Lang_Basque     : constant := 16#2D#;
   Lang_Belarusian : constant := 16#23#;
   Lang_Bengali    : constant := 16#45#;
   Lang_Bulgarian  : constant := 16#02#;
   Lang_Catalan    : constant := 16#03#;
   Lang_Chinese    : constant := 16#04#;
   Lang_Croatian   : constant := 16#1A#;
   Lang_Czech      : constant := 16#05#;
   Lang_Danish     : constant := 16#06#;
   Lang_Divehi     : constant := 16#65#;
   Lang_Dutch      : constant := 16#13#;
   Lang_English    : constant := 16#09#;
   Lang_Estonian   : constant := 16#25#;
   Lang_Faeroese   : constant := 16#38#;
   Lang_Farsi      : constant := 16#29#;
   Lang_Finnish    : constant := 16#0B#;
   Lang_French     : constant := 16#0C#;
   Lang_Galician   : constant := 16#56#;
   Lang_Georgian   : constant := 16#37#;
   Lang_German     : constant := 16#07#;
   Lang_Greek      : constant := 16#08#;
   Lang_Gujarati   : constant := 16#47#;
   Lang_Hebrew     : constant := 16#0D#;
   Lang_Hindi      : constant := 16#39#;
   Lang_Hungarian  : constant := 16#0E#;
   Lang_Icelandic  : constant := 16#0F#;
   Lang_Indonesian : constant := 16#21#;
   Lang_Italian    : constant := 16#10#;
   Lang_Japanese   : constant := 16#11#;
   Lang_Kannada    : constant := 16#4B#;
   Lang_Kashmiri   : constant := 16#60#;
   Lang_Kazak      : constant := 16#3F#;
   Lang_Konkani    : constant := 16#57#;
   Lang_Korean     : constant := 16#12#;
   Lang_Kyrgyz     : constant := 16#40#;
   Lang_Latvian    : constant := 16#26#;
   Lang_Lithuanian : constant := 16#27#;
   Lang_Macedonian : constant := 16#2F#;            -- the Former Yugoslav Republic of Macedonia
   Lang_Malay      : constant := 16#3E#;
   Lang_Malayalam  : constant := 16#4C#;
   Lang_Manipuri   : constant := 16#58#;
   Lang_Marathi    : constant := 16#4E#;
   Lang_Mongolian  : constant := 16#50#;
   Lang_Nepali     : constant := 16#61#;
   Lang_Norwegian  : constant := 16#14#;
   Lang_Oriya      : constant := 16#48#;
   Lang_Polish     : constant := 16#15#;
   Lang_Portuguese : constant := 16#16#;
   Lang_Punjabi    : constant := 16#46#;
   Lang_Romanian   : constant := 16#18#;
   Lang_Russian    : constant := 16#19#;
   Lang_Sanskrit   : constant := 16#4F#;
   Lang_Serbian    : constant := 16#1A#;
   Lang_Sindhi     : constant := 16#59#;
   Lang_Slovak     : constant := 16#1B#;
   Lang_Slovenian  : constant := 16#24#;
   Lang_Spanish    : constant := 16#0A#;
   Lang_Swahili    : constant := 16#41#;
   Lang_Swedish    : constant := 16#1D#;
   Lang_Syriac     : constant := 16#5A#;
   Lang_Tamil      : constant := 16#49#;
   Lang_Tatar      : constant := 16#44#;
   Lang_Telugu     : constant := 16#4A#;
   Lang_Thai       : constant := 16#1E#;
   Lang_Turkish    : constant := 16#1F#;
   Lang_Ukrainian  : constant := 16#22#;
   Lang_Urdu       : constant := 16#20#;
   Lang_Uzbek      : constant := 16#43#;
   Lang_Vietnamese : constant := 16#2A#;

--
--  Sublanguage IDs.
--
--  The name immediately following SUBLANG_ dictates which primary
--  language ID that sublanguage ID can be combined with to form a
--  valid language ID.
--

   Sublang_Neutral     : constant := 16#00#; -- language neutral
   Sublang_Default     : constant := 16#01#; -- user default
   Sublang_Sys_Default : constant := 16#02#; -- system default

   Sublang_Arabic_Saudi_Arabia        : constant := 16#01#; -- Arabic (Saudi Arabia)
   Sublang_Arabic_Iraq                : constant := 16#02#; -- Arabic (Iraq)
   Sublang_Arabic_Egypt               : constant := 16#03#; -- Arabic (Egypt)
   Sublang_Arabic_Libya               : constant := 16#04#; -- Arabic (Libya)
   Sublang_Arabic_Algeria             : constant := 16#05#; -- Arabic (Algeria)
   Sublang_Arabic_Morocco             : constant := 16#06#; -- Arabic (Morocco)
   Sublang_Arabic_Tunisia             : constant := 16#07#; -- Arabic (Tunisia)
   Sublang_Arabic_Oman                : constant := 16#08#; -- Arabic (Oman)
   Sublang_Arabic_Yemen               : constant := 16#09#; -- Arabic (Yemen)
   Sublang_Arabic_Syria               : constant := 16#0A#; -- Arabic (Syria)
   Sublang_Arabic_Jordan              : constant := 16#0B#; -- Arabic (Jordan)
   Sublang_Arabic_Lebanon             : constant := 16#0C#; -- Arabic (Lebanon)
   Sublang_Arabic_Kuwait              : constant := 16#0D#; -- Arabic (Kuwait)
   Sublang_Arabic_Uae                 : constant := 16#0E#; -- Arabic (U.A.E)
   Sublang_Arabic_Bahrain             : constant := 16#0F#; -- Arabic (Bahrain)
   Sublang_Arabic_Qatar               : constant := 16#10#; -- Arabic (Qatar)
   Sublang_Azeri_Latin                : constant := 16#01#; -- Azeri (Latin)
   Sublang_Azeri_Cyrillic             : constant := 16#02#; -- Azeri (Cyrillic)
   Sublang_Chinese_Traditional        : constant := 16#01#; -- Chinese (Taiwan)
   Sublang_Chinese_Simplified         : constant := 16#02#; -- Chinese (PR China)
   Sublang_Chinese_Hongkong           : constant := 16#03#; -- Chinese (Hong Kong S.A.R., P.R.C.)
   Sublang_Chinese_Singapore          : constant := 16#04#; -- Chinese (Singapore)
   Sublang_Chinese_Macau              : constant := 16#05#; -- Chinese (Macau S.A.R.)
   Sublang_Dutch                      : constant := 16#01#; -- Dutch
   Sublang_Dutch_Belgian              : constant := 16#02#; -- Dutch (Belgian)
   Sublang_English_US                 : constant := 16#01#; -- English (USA)
   Sublang_English_UK                 : constant := 16#02#; -- English (UK)
   Sublang_English_Aus                : constant := 16#03#; -- English (Australian)
   Sublang_English_Can                : constant := 16#04#; -- English (Canadian)
   Sublang_English_NZ                 : constant := 16#05#; -- English (New Zealand)
   Sublang_English_Eire               : constant := 16#06#; -- English (Irish)
   Sublang_English_South_Africa       : constant := 16#07#; -- English (South Africa)
   Sublang_English_Jamaica            : constant := 16#08#; -- English (Jamaica)
   Sublang_English_Caribbean          : constant := 16#09#; -- English (Caribbean)
   Sublang_English_Belize             : constant := 16#0A#; -- English (Belize)
   Sublang_English_Trinidad           : constant := 16#0B#; -- English (Trinidad)
   Sublang_English_Zimbabwe           : constant := 16#0C#; -- English (Zimbabwe)
   Sublang_English_Philippines        : constant := 16#0D#; -- English (Philippines)
   Sublang_French                     : constant := 16#01#; -- French
   Sublang_French_Belgian             : constant := 16#02#; -- French (Belgian)
   Sublang_French_Canadian            : constant := 16#03#; -- French (Canadian)
   Sublang_French_Swiss               : constant := 16#04#; -- French (Swiss)
   Sublang_French_Luxembourg          : constant := 16#05#; -- French (Luxembourg)
   Sublang_French_Monaco              : constant := 16#06#; -- French (Monaco)
   Sublang_German                     : constant := 16#01#; -- German
   Sublang_German_Swiss               : constant := 16#02#; -- German (Swiss)
   Sublang_German_Austrian            : constant := 16#03#; -- German (Austrian)
   Sublang_German_Luxembourg          : constant := 16#04#; -- German (Luxembourg)
   Sublang_German_Liechtenstein       : constant := 16#05#; -- German (Liechtenstein)
   Sublang_Italian                    : constant := 16#01#; -- Italian
   Sublang_Italian_Swiss              : constant := 16#02#; -- Italian (Swiss)
   Sublang_Kashmiri_Sasia             : constant := 16#02#; -- Kashmiri (South Asia)
   Sublang_Kashmiri_India             : constant := 16#02#; -- For app compatibility only
   Sublang_Korean                     : constant := 16#01#; -- Korean (Extended Wansung)
   Sublang_Lithuanian                 : constant := 16#01#; -- Lithuanian
   Sublang_Malay_Malaysia             : constant := 16#01#; -- Malay (Malaysia)
   Sublang_Malay_Brunei_Darussalam    : constant := 16#02#; -- Malay (Brunei Darussalam)
   Sublang_Nepali_India               : constant := 16#02#; -- Nepali (India)
   Sublang_Norwegian_Bokmal           : constant := 16#01#; -- Norwegian (Bokmal)
   Sublang_Norwegian_Nynorsk          : constant := 16#02#; -- Norwegian (Nynorsk)
   Sublang_Portuguese                 : constant := 16#02#; -- Portuguese
   Sublang_Portuguese_Brazilian       : constant := 16#01#; -- Portuguese (Brazilian)
   Sublang_Serbian_Latin              : constant := 16#02#; -- Serbian (Latin)
   Sublang_Serbian_Cyrillic           : constant := 16#03#; -- Serbian (Cyrillic)
   Sublang_Spanish                    : constant := 16#01#; -- Spanish (Castilian)
   Sublang_Spanish_Mexican            : constant := 16#02#; -- Spanish (Mexican)
   Sublang_Spanish_Modern             : constant := 16#03#; -- Spanish (Spain)
   Sublang_Spanish_Guatemala          : constant := 16#04#; -- Spanish (Guatemala)
   Sublang_Spanish_Costa_Rica         : constant := 16#05#; -- Spanish (Costa Rica)
   Sublang_Spanish_Panama             : constant := 16#06#; -- Spanish (Panama)
   Sublang_Spanish_Dominican_Republic : constant := 16#07#; -- Spanish (Dominican Republic)
   Sublang_Spanish_Venezuela          : constant := 16#08#; -- Spanish (Venezuela)
   Sublang_Spanish_Colombia           : constant := 16#09#; -- Spanish (Colombia)
   Sublang_Spanish_Peru               : constant := 16#0A#; -- Spanish (Peru)
   Sublang_Spanish_Argentina          : constant := 16#0B#; -- Spanish (Argentina)
   Sublang_Spanish_Ecuador            : constant := 16#0C#; -- Spanish (Ecuador)
   Sublang_Spanish_Chile              : constant := 16#0D#; -- Spanish (Chile)
   Sublang_Spanish_Uruguay            : constant := 16#0E#; -- Spanish (Uruguay)
   Sublang_Spanish_Paraguay           : constant := 16#0F#; -- Spanish (Paraguay)
   Sublang_Spanish_Bolivia            : constant := 16#10#; -- Spanish (Bolivia)
   Sublang_Spanish_El_Salvador        : constant := 16#11#; -- Spanish (El Salvador)
   Sublang_Spanish_Honduras           : constant := 16#12#; -- Spanish (Honduras)
   Sublang_Spanish_Nicaragua          : constant := 16#13#; -- Spanish (Nicaragua)
   Sublang_Spanish_Puerto_Rico        : constant := 16#14#; -- Spanish (Puerto Rico)
   Sublang_Swedish                    : constant := 16#01#; -- Swedish
   Sublang_Swedish_Finland            : constant := 16#02#; -- Swedish (Finland)
   Sublang_Urdu_Pakistan              : constant := 16#01#; -- Urdu (Pakistan)
   Sublang_Urdu_India                 : constant := 16#02#; -- Urdu (India)
   Sublang_Uzbek_Latin                : constant := 16#01#; -- Uzbek (Latin)
   Sublang_Uzbek_Cyrillic             : constant := 16#02#; -- Uzbek (Cyrillic)

--
--  Sorting IDs.
--

   Sort_Default : constant := 16#0#; -- sorting default

   Sort_Japanese_Xjis    : constant := 16#0#; -- Japanese XJIS order
   Sort_Japanese_Unicode : constant := 16#1#; -- Japanese Unicode order

   Sort_Chinese_Big5     : constant := 16#0#; -- Chinese BIG5 order
   Sort_Chinese_Prcp     : constant := 16#0#; -- PRC Chinese Phonetic order
   Sort_Chinese_Unicode  : constant := 16#1#; -- Chinese Unicode order
   Sort_Chinese_Prc      : constant := 16#2#; -- PRC Chinese Stroke Count order
   Sort_Chinese_Bopomofo : constant := 16#3#; -- Traditional Chinese Bopomofo order

   Sort_Korean_Ksc     : constant := 16#0#; -- Korean KSC order
   Sort_Korean_Unicode : constant := 16#1#; -- Korean Unicode order

   Sort_German_Phone_Book : constant := 16#1#; -- German Phone Book order

   Sort_Hungarian_Default   : constant := 16#0#; -- Hungarian Default order
   Sort_Hungarian_Technical : constant := 16#1#; -- Hungarian Technical order

   Sort_Georgian_Traditional : constant := 16#0#; -- Georgian Traditional order
   Sort_Georgian_Modern      : constant := 16#1#; -- Georgian Modern order

--
--  A language ID is a 16 bit value which is the combination of a
--  primary language ID and a secondary language ID.  The bits are
--  allocated as follows:
--
--       +-----------------------+-------------------------+
--       |     Sublanguage ID    |   Primary Language ID   |
--       +-----------------------+-------------------------+
--        15                   10 9                       0   bit
--
--
--  Language ID creation/extraction macros:
--
--    MAKELANGID    - construct language id from a primary language id and
--                    a sublanguage id.
--    PRIMARYLANGID - extract primary language id from a language id.
--    SUBLANGID     - extract sublanguage id from a language id.
--

--%% function MAKELANGID(PrimaryLang, SubLang: USHORT): WORD;
--%% {$EXTERNALSYM MAKELANGID}
--%% function PRIMARYLANGID(LangId: WORD): WORD;
--%% {$EXTERNALSYM PRIMARYLANGID}
--%% function SUBLANGID(LangId: WORD): WORD;
--%% {$EXTERNALSYM SUBLANGID}

--
--  A locale ID is a 32 bit value which is the combination of a
--  language ID, a sort ID, and a reserved area.  The bits are
--  allocated as follows:
--
--       +-------------+---------+-------------------------+
--       |   Reserved  | Sort ID |      Language ID        |
--       +-------------+---------+-------------------------+
--        31         20 19     16 15                      0   bit
--
--
--  Locale ID creation/extraction macros:
--
--    MAKELCID            - construct the locale id from a language id and a sort id.
--    MAKESORTLCID        - construct the locale id from a language id, sort id, and sort version.
--    LANGIDFROMLCID      - extract the language id from a locale id.
--    SORTIDFROMLCID      - extract the sort id from a locale id.
--    SORTVERSIONFROMLCID - extract the sort version from a locale id.
--

   Nls_Valid_Locale_Mask : constant := 16#000F_FFFF#;

--%% function MAKELCID(LangId, SortId: WORD): DWORD;
--%% {$EXTERNALSYM MAKELCID}
--%% function MAKESORTLCID(LangId, SortId, SortVersion: WORD): DWORD;
--%% {$EXTERNALSYM MAKESORTLCID}
--%% function LANGIDFROMLCID(LocaleId: LCID): WORD;
--%% {$EXTERNALSYM LANGIDFROMLCID}
--%% function SORTIDFROMLCID(LocaleId: LCID): WORD;
--%% {$EXTERNALSYM SORTIDFROMLCID}
--%% function SORTVERSIONFROMLCID(LocaleId: LCID): WORD;
--%% {$EXTERNALSYM SORTVERSIONFROMLCID}

--
--  Default System and User IDs for language and locale.
--

--%% function LANG_SYSTEM_DEFAULT: WORD;
--%% {$EXTERNALSYM LANG_SYSTEM_DEFAULT}
--%% function LANG_USER_DEFAULT: WORD;
--%% {$EXTERNALSYM LANG_USER_DEFAULT}
--%% function LOCALE_SYSTEM_DEFAULT: DWORD;
--%% {$EXTERNALSYM LOCALE_SYSTEM_DEFAULT}
--%% function LOCALE_USER_DEFAULT: DWORD;
--%% {$EXTERNALSYM LOCALE_USER_DEFAULT}
--%% function LOCALE_NEUTRAL: DWORD;
--%% {$EXTERNALSYM LOCALE_NEUTRAL}
--%% function LOCALE_INVARIANT: DWORD;
--%% {$EXTERNALSYM LOCALE_NEUTRAL}

   -- (rom) deleted status codes already in JwaWinStatus.pas
   Dbg_Command_Exception           : constant := 16#4001_0009#;
   Status_Sxs_Early_Deactivation   : constant := 16#C015_000F#;
   Status_Sxs_Invalid_Deactivation : constant := 16#C015_0010#;

   Maximum_Wait_Objects  : constant := 64;      -- Maximum number of wait objects

   Maximum_Suspend_Count : constant := Maxchar; -- Maximum times thread can be suspended

--%%   KSPIN_LOCK = ULONG_PTR;
--%%   {$EXTERNALSYM KSPIN_LOCK}
--%%   PKSPIN_LOCK = ^KSPIN_LOCK;
--%%   {$EXTERNALSYM PKSPIN_LOCK}

--
-- Define functions to get the address of the current fiber and the
-- current fiber data.
--

--
-- Disable these two pramas that evaluate to "sti" "cli" on x86 so that driver
-- writers to not leave them inadvertantly in their code.
--

--%% function GetFiberData: PVOID;
--%% {$EXTERNALSYM GetFiberData}

--%% function GetCurrentFiber: PVOID;
--%% {$EXTERNALSYM GetCurrentFiber}

--
--  Define the size of the 80387 save area, which is in the context frame.
--

   Size_Of_80387_Registers : constant := 80;

--
-- The following flags control the contents of the CONTEXT structure.
--

   Context_i386 : constant := 16#0001_0000#; -- this assumes that i386 and
   Context_i486 : constant := 16#0001_0000#; -- i486 have identical context records

--%%   CONTEXT_CONTROL            = CONTEXT_i386 or $00000001; // SS:SP, CS:IP, FLAGS, BP
--%%   {$EXTERNALSYM CONTEXT_CONTROL}
--%%   CONTEXT_INTEGER            = CONTEXT_i386 or $00000002; // AX, BX, CX, DX, SI, DI
--%%   {$EXTERNALSYM CONTEXT_INTEGER}
--%%   CONTEXT_SEGMENTS           = CONTEXT_i386 or $00000004; // DS, ES, FS, GS
--%%   {$EXTERNALSYM CONTEXT_SEGMENTS}
--%%   CONTEXT_FLOATING_POINT     = CONTEXT_i386 or $00000008; // 387 state
--%%   {$EXTERNALSYM CONTEXT_FLOATING_POINT}
--%%   CONTEXT_DEBUG_REGISTERS    = CONTEXT_i386 or $00000010; // DB 0-3,6,7
--%%   {$EXTERNALSYM CONTEXT_DEBUG_REGISTERS}
--%%   CONTEXT_EXTENDED_REGISTERS = CONTEXT_i386 or $00000020; // cpu specific extensions
--%%   {$EXTERNALSYM CONTEXT_EXTENDED_REGISTERS}

--%%   CONTEXT_FULL = CONTEXT_CONTROL or CONTEXT_INTEGER or CONTEXT_SEGMENTS;
--%%   {$EXTERNALSYM CONTEXT_FULL}

--%%   CONTEXT_ALL = CONTEXT_CONTROL or CONTEXT_INTEGER or CONTEXT_SEGMENTS or CONTEXT_FLOATING_POINT or CONTEXT_DEBUG_REGISTERS;
--%%   {$EXTERNALSYM CONTEXT_ALL}

--
-- Define initial MxCsr control.
--

   Initial_Mxcsr : constant := 16#1F80#;            -- initial MXCSR value

   Maximum_Supported_Extension : constant := 512;

--%%   PFLOATING_SAVE_AREA = ^FLOATING_SAVE_AREA;
--%%   {$EXTERNALSYM PFLOATING_SAVE_AREA}
--%%   _FLOATING_SAVE_AREA = record
--%%     ControlWord: DWORD;
--%%     StatusWord: DWORD;
--%%     TagWord: DWORD;
--%%     ErrorOffset: DWORD;
--%%     ErrorSelector: DWORD;
--%%     DataOffset: DWORD;
--%%     DataSelector: DWORD;
--%%     RegisterArea: array [0..SIZE_OF_80387_REGISTERS - 1] of BYTE;
--%%     Cr0NpxState: DWORD;
--%%   end;
--%%   {$EXTERNALSYM _FLOATING_SAVE_AREA}
--%%   FLOATING_SAVE_AREA = _FLOATING_SAVE_AREA;
--%%   {$EXTERNALSYM FLOATING_SAVE_AREA}
--%%   TFloatingSaveArea = FLOATING_SAVE_AREA;
--%%   PFloatingSaveArea = PFLOATING_SAVE_AREA;

--
-- Context Frame
--
--  This frame has a several purposes: 1) it is used as an argument to
--  NtContinue, 2) is is used to constuct a call frame for APC delivery,
--  and 3) it is used in the user level thread creation routines.
--
--  The layout of the record conforms to a standard call frame.
--

--%%   PContext = ^CONTEXT;
--%%   _CONTEXT  = record

--%%     //
--%%     // The flags values within this flag control the contents of
--%%     // a CONTEXT record.
--%%     //
--%%     // If the context record is used as an input parameter, then
--%%     // for each portion of the context record controlled by a flag
--%%     // whose value is set, it is assumed that that portion of the
--%%     // context record contains valid context. If the context record
--%%     // is being used to modify a threads context, then only that
--%%     // portion of the threads context will be modified.
--%%     //
--%%     // If the context record is used as an IN OUT parameter to capture
--%%     // the context of a thread, then only those portions of the thread's
--%%     // context corresponding to set flags will be returned.
--%%     //
--%%     // The context record is never used as an OUT only parameter.
--%%     //

--%%     ContextFlags: DWORD;

--%%     //
--%%     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
--%%     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
--%%     // included in CONTEXT_FULL.
--%%     //

--%%     Dr0: DWORD;
--%%     Dr1: DWORD;
--%%     Dr2: DWORD;
--%%     Dr3: DWORD;
--%%     Dr6: DWORD;
--%%     Dr7: DWORD;

--%%     //
--%%     // This section is specified/returned if the
--%%     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
--%%     //

--%%     FloatSave: FLOATING_SAVE_AREA;

--%%     //
--%%     // This section is specified/returned if the
--%%     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
--%%     //

--%%     SegGs: DWORD;
--%%     SegFs: DWORD;
--%%     SegEs: DWORD;
--%%     SegDs: DWORD;

--%%     //
--%%     // This section is specified/returned if the
--%%     // ContextFlags word contians the flag CONTEXT_INTEGER.
--%%     //

--%%     Edi: DWORD;
--%%     Esi: DWORD;
--%%     Ebx: DWORD;
--%%     Edx: DWORD;
--%%     Ecx: DWORD;
--%%     Eax: DWORD;

--%%     //
--%%     // This section is specified/returned if the
--%%     // ContextFlags word contians the flag CONTEXT_CONTROL.
--%%     //

--%%     Ebp: DWORD;
--%%     Eip: DWORD;
--%%     SegCs: DWORD;              // MUST BE SANITIZED
--%%     EFlags: DWORD;             // MUST BE SANITIZED
--%%     Esp: DWORD;
--%%     SegSs: DWORD;

--%%     //
--%%     // This section is specified/returned if the ContextFlags word
--%%     // contains the flag CONTEXT_EXTENDED_REGISTERS.
--%%     // The format and contexts are processor specific
--%%     //

--%%     ExtendedRegisters: array [0..MAXIMUM_SUPPORTED_EXTENSION - 1] of BYTE;
--%%   end;
--%%   {$EXTERNALSYM _CONTEXT}
--%%   CONTEXT = _CONTEXT;
--%%   {$EXTERNALSYM CONTEXT}
--%%   TContext = CONTEXT;

   Ldtentry_Flags1_Type        : constant := 16#1F#;
   Ldtentry_Flags1_Dpl         : constant := 16#60#;
   Ldtentry_Flags1_Pres        : constant := 16#80#;

   Ldtentry_Flags2_Limithi     : constant := 16#0F#;
   Ldtentry_Flags2_Sys         : constant := 16#10#;
   Ldtentry_Flags2_Reserved_0  : constant := 16#20#;
   Ldtentry_Flags2_Default_Big : constant := 16#40#;
   Ldtentry_Flags2_Granularity : constant := 16#80#;

   type Ldt_Entry_Type;
   type Ldt_Entry_Ptr is access all Ldt_Entry_Type;
   type Ldt_Entry_CPtr is access constant Ldt_Entry_Type;
   type Ldt_Entry_Type is record
      Limit_Low : Unsigned_16;
      Base_Low : Unsigned_16;
      Base_Mid : Unsigned_8;
      Flags1 : Unsigned_8;    -- Declare as bytes to avoid alignment
      Flags2 : Unsigned_8;    -- Problems.
      Base_Hi : Unsigned_8;
   end record;

-- Please contact INTEL to get IA64-specific information

   Exception_Noncontinuable     : constant := 16#1#; -- Noncontinuable exception
   Exception_Maximum_Parameters : constant := 15; -- maximum number of exception parameters

--
-- Exception record definition.
--

--%%   PEXCEPTION_RECORD = ^EXCEPTION_RECORD;
--%%   {$EXTERNALSYM PEXCEPTION_RECORD}
--%%   _EXCEPTION_RECORD = record
--%%     ExceptionCode: DWORD;
--%%     ExceptionFlags: DWORD;
--%%     ExceptionRecord: PEXCEPTION_RECORD;
--%%     ExceptionAddress: Pointer;
--%%     NumberParameters: DWORD;
--%%     ExceptionInformation: array [0..EXCEPTION_MAXIMUM_PARAMETERS - 1] of ULONG_PTR;
--%%   end;
--%%   {$EXTERNALSYM _EXCEPTION_RECORD}
--%%   EXCEPTION_RECORD = _EXCEPTION_RECORD;
--%%   {$EXTERNALSYM EXCEPTION_RECORD}
--%%   TExceptionRecord = EXCEPTION_RECORD;
--%%   PExceptionRecord = PEXCEPTION_RECORD;

--%%   PEXCEPTION_RECORD32 = ^EXCEPTION_RECORD32;
--%%   {$EXTERNALSYM PEXCEPTION_RECORD32}
--%%   _EXCEPTION_RECORD32 = record
--%%     ExceptionCode: DWORD;
--%%     ExceptionFlags: DWORD;
--%%     ExceptionRecord: DWORD;
--%%     ExceptionAddress: DWORD;
--%%     NumberParameters: DWORD;
--%%     ExceptionInformation: array [0..EXCEPTION_MAXIMUM_PARAMETERS - 1] of DWORD;
--%%   end;
--%%   {$EXTERNALSYM _EXCEPTION_RECORD32}
--%%   EXCEPTION_RECORD32 = _EXCEPTION_RECORD32;
--%%   {$EXTERNALSYM EXCEPTION_RECORD32}
--%%   TExceptionRecord32 = EXCEPTION_RECORD32;
--%%   PExceptionRecord32 = PEXCEPTION_RECORD32;

--%%   PEXCEPTION_RECORD64 = ^EXCEPTION_RECORD64;
--%%   {$EXTERNALSYM PEXCEPTION_RECORD64}
--%%   _EXCEPTION_RECORD64 = record
--%%     ExceptionCode: DWORD;
--%%     ExceptionFlags: DWORD;
--%%     ExceptionRecord: DWORD64;
--%%     ExceptionAddress: DWORD64;
--%%     NumberParameters: DWORD;
--%%     __unusedAlignment: DWORD;
--%%     ExceptionInformation: array [0..EXCEPTION_MAXIMUM_PARAMETERS - 1] of DWORD64;
--%%   end;
--%%   {$EXTERNALSYM _EXCEPTION_RECORD64}
--%%   EXCEPTION_RECORD64 = _EXCEPTION_RECORD64;
--%%   {$EXTERNALSYM EXCEPTION_RECORD64}
--%%   TExceptionRecord64 = EXCEPTION_RECORD64;
--%%   PExceptionRecord64 = PEXCEPTION_RECORD64;

--
-- Typedef for pointer returned by exception_info()
--

   type Exception_Pointers_Type;
   type Exception_Pointers_Ptr is access all Exception_Pointers_Type;
   type Exception_Pointers_CPtr is access constant Exception_Pointers_Type;
   type Exception_Pointers_Type is record
      Exception_Record : EXCEPTION_RECORD_Ptr;
      Context_Record : CONTEXT_Ptr;
   end record;

--%%   PACCESS_TOKEN = Pointer;
--%%   {$EXTERNALSYM PACCESS_TOKEN}

------------------------------------------------------------------------
--                                                                    --
--                             ACCESS MASK                            --
--                                                                    --
------------------------------------------------------------------------

--
--  Define the access mask as a longword sized structure divided up as
--  follows:
--
--       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--      +---------------+---------------+-------------------------------+
--      |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
--      |R|W|E|A|     |S|               |                               |
--      +-+-------------+---------------+-------------------------------+
--
--      typedef struct _ACCESS_MASK {
--          WORD   SpecificRights;
--          BYTE  StandardRights;
--          BYTE  AccessSystemAcl : 1;
--          BYTE  Reserved : 3;
--          BYTE  GenericAll : 1;
--          BYTE  GenericExecute : 1;
--          BYTE  GenericWrite : 1;
--          BYTE  GenericRead : 1;
--      } ACCESS_MASK;
--      typedef ACCESS_MASK *PACCESS_MASK;
--
--  but to make life simple for programmer's we'll allow them to specify
--  a desired access mask by simply OR'ing together mulitple single rights
--  and treat an access mask as a DWORD.  For example
--
--      DesiredAccess = DELETE | READ_CONTROL
--
--  So we'll declare ACCESS_MASK as DWORD
--

   subtype Access_Mask_Type is Unsigned_32;
   subtype Access_Mask_Ptr is Unsigned_32_Ptr;
   subtype Access_Mask_CPtr is Unsigned_32_CPtr;

------------------------------------------------------------------------
--                                                                    --
--                             ACCESS TYPES                           --
--                                                                    --
------------------------------------------------------------------------

--
--  The following are masks for the predefined standard access types
--

   Delete                   : constant := 16#0001_0000#;
   Read_Control             : constant := 16#0002_0000#;
   Write_DAC                : constant := 16#0004_0000#;
   Write_Owner              : constant := 16#0008_0000#;
   Synchronize              : constant := 16#0010_0000#;

   Standard_Rights_Required : constant := 16#000F_0000#;

   Standard_Rights_Read     : constant := Read_Control;
   Standard_Rights_Write    : constant := Read_Control;
   Standard_Rights_Execute  : constant := Read_Control;

   Standard_Rights_All      : constant := 16#001F_0000#;
   Specific_Rights_All      : constant := 16#0000_FFFF#;

--
-- AccessSystemAcl access type
--

   Access_System_Security : constant := 16#0100_0000#;

--
-- MaximumAllowed access type
--

   Maximum_Allowed : constant := 16#0200_0000#;

--
--  These are the generic rights.
--

   Generic_Read    : constant := 16#8000_0000#;
   Generic_Write   : constant := 16#4000_0000#;
   Generic_Execute : constant := 16#2000_0000#;
   Generic_All     : constant := 16#1000_0000#;

--
--  Define the generic mapping array.  This is used to denote the
--  mapping of each generic access right to a specific access mask.
--

   type Generic_Mapping_Type;
   type Generic_Mapping_Ptr is access all Generic_Mapping_Type;
   type Generic_Mapping_CPtr is access constant Generic_Mapping_Type;
   type Generic_Mapping_Type is record
      Generic_Read : Access_Mask_Type;
      Generic_Write : Access_Mask_Type;
      Generic_Execute : Access_Mask_Type;
      Generic_All : Access_Mask_Type;
   end record;

------------------------------------------------------------------------
--                                                                    --
--                        LUID_AND_ATTRIBUTES                         --
--                                                                    --
------------------------------------------------------------------------
--
--

-- #include <pshpack4.h>

   type LUID_And_Attributes_Type;
   type LUID_And_Attributes_Ptr is access all LUID_And_Attributes_Type;
   type LUID_And_Attributes_CPtr is access constant LUID_And_Attributes_Type;
   type LUID_And_Attributes_Type is record
      LUID : LUID;
      Attributes : Unsigned_32;
   end record;

--%%   LUID_AND_ATTRIBUTES_ARRAY = array [0..ANYSIZE_ARRAY - 1] of LUID_AND_ATTRIBUTES;
--%%   {$EXTERNALSYM LUID_AND_ATTRIBUTES_ARRAY}
--%%   PLUID_AND_ATTRIBUTES_ARRAY = ^LUID_AND_ATTRIBUTES_ARRAY;
--%%   {$EXTERNALSYM PLUID_AND_ATTRIBUTES_ARRAY}
--%%   TLuidAndAttributesArray = LUID_AND_ATTRIBUTES_ARRAY;
--%%   PLuidAndAttributesArray = ^TLuidAndAttributesArray;

-- #include <poppack.h>

------------------------------------------------------------------------
--                                                                    --
--              Security Id     (SID)                                 --
--                                                                    --
------------------------------------------------------------------------
--
--
-- Pictorially the structure of an SID is as follows:
--
--         1   1   1   1   1   1
--         5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
--      +---------------------------------------------------------------+
--      |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
--      +---------------------------------------------------------------+
--      |                   IdentifierAuthority[0]                      |
--      +---------------------------------------------------------------+
--      |                   IdentifierAuthority[1]                      |
--      +---------------------------------------------------------------+
--      |                   IdentifierAuthority[2]                      |
--      +---------------------------------------------------------------+
--      |                                                               |
--      +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
--      |                                                               |
--      +---------------------------------------------------------------+
--
--

--%%   PSID_IDENTIFIER_AUTHORITY = ^SID_IDENTIFIER_AUTHORITY;
--%%   {$EXTERNALSYM PSID_IDENTIFIER_AUTHORITY}
--%%   _SID_IDENTIFIER_AUTHORITY = record
--%%     Value: array [0..5] of Byte;
--%%   end;
--%%   {$EXTERNALSYM _SID_IDENTIFIER_AUTHORITY}
--%%   SID_IDENTIFIER_AUTHORITY = _SID_IDENTIFIER_AUTHORITY;
--%%   {$EXTERNALSYM SID_IDENTIFIER_AUTHORITY}
--%%   TSidIdentifierAuthority = SID_IDENTIFIER_AUTHORITY;
--%%   PSidIdentifierAuthority = PSID_IDENTIFIER_AUTHORITY;

--%%   PSid = ^SID;
--%%   _SID = record
--%%     Revision: Byte;
--%%     SubAuthorityCount: Byte;
--%%     IdentifierAuthority: SID_IDENTIFIER_AUTHORITY;
--%%     SubAuthority: array [0..ANYSIZE_ARRAY - 1] of DWORD;
--%%   end;
--%%   {$EXTERNALSYM _SID}
--%%   SID = _SID;
--%%   {$EXTERNALSYM SID}
--%%   PPSID = ^PSID;
--%%   {$NODEFINE PPSID}
--%%   TSid = SID;

   SID_Revision                    : constant := 1; -- Current revision level
   SID_Max_Sub_Authorities         : constant := 15;
   SID_Recommended_Sub_Authorities : constant := 1; -- Will change to around 6 in a future release.

--%%   SECURITY_MAX_SID_SIZE = SizeOf(SID) - SizeOf(DWORD) + (SID_MAX_SUB_AUTHORITIES * SizeOf(DWORD));
--%%   {$EXTERNALSYM SECURITY_MAX_SID_SIZE}

   SidTypeUser           : constant := 1;
   SidTypeGroup          : constant := 2;
   SidTypeDomain         : constant := 3;
   SidTypeAlias          : constant := 4;
   SidTypeWellKnownGroup : constant := 5;
   SidTypeDeletedAccount : constant := 6;
   SidTypeInvalid        : constant := 7;
   SidTypeUnknown        : constant := 8;
   SidTypeComputer       : constant := 9;

   subtype _SID_Name_Use_Type is Unsigned_32;
   subtype _SID_Name_Use_Ptr is Unsigned_32_Ptr;
   subtype _SID_Name_Use_CPtr is Unsigned_32_CPtr;
   subtype SID_Name_Use_Type is _SID_Name_Use_Type;
   subtype SID_Name_Use_Ptr is _SID_Name_Use_Ptr;
   subtype SID_Name_Use_CPtr is _SID_Name_Use_CPtr;
--%%   PSID_NAME_USE = ^SID_NAME_USE;
--%%   {$EXTERNALSYM PSID_NAME_USE}
--%%   TSidNameUse = SID_NAME_USE;
--%%   PSidNameUSe = PSID_NAME_USE;

   type SID_And_Attributes_Type;
   type SID_And_Attributes_Ptr is access all SID_And_Attributes_Type;
   type SID_And_Attributes_CPtr is access constant SID_And_Attributes_Type;
   type SID_And_Attributes_Type is record
      SID : SID_Ptr;
      Attributes : Unsigned_32;
   end record;

--%%   SID_AND_ATTRIBUTES_ARRAY = array [0..ANYSIZE_ARRAY - 1] of SID_AND_ATTRIBUTES;
--%%   {$EXTERNALSYM SID_AND_ATTRIBUTES_ARRAY}
--%%   PSID_AND_ATTRIBUTES_ARRAY = ^SID_AND_ATTRIBUTES_ARRAY;
--%%   {$EXTERNALSYM PSID_AND_ATTRIBUTES_ARRAY}
--%%   PSidAndAttributesArray = ^TSidAndAttributesArray;
--%%   TSidAndAttributesArray = SID_AND_ATTRIBUTES_ARRAY;

-----------------------------------------------------------------------------
--                                                                         --
-- Universal well-known SIDs                                               --
--                                                                         --
--     Null SID                     S-1-0-0                                --
--     World                        S-1-1-0                                --
--     Local                        S-1-2-0                                --
--     Creator Owner ID             S-1-3-0                                --
--     Creator Group ID             S-1-3-1                                --
--     Creator Owner Server ID      S-1-3-2                                --
--     Creator Group Server ID      S-1-3-3                                --
--                                                                         --
--     (Non-unique IDs)             S-1-4                                  --
--                                                                         --
-----------------------------------------------------------------------------

--%%   SECURITY_NULL_SID_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 0));
--%%   {$EXTERNALSYM SECURITY_NULL_SID_AUTHORITY}
--%%   SECURITY_WORLD_SID_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 1));
--%%   {$EXTERNALSYM SECURITY_WORLD_SID_AUTHORITY}
--%%   SECURITY_LOCAL_SID_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 2));
--%%   {$EXTERNALSYM SECURITY_LOCAL_SID_AUTHORITY}
--%%   SECURITY_CREATOR_SID_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 3));
--%%   {$EXTERNALSYM SECURITY_CREATOR_SID_AUTHORITY}
--%%   SECURITY_NON_UNIQUE_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 4));
--%%   {$EXTERNALSYM SECURITY_NON_UNIQUE_AUTHORITY}
--%%   SECURITY_RESOURCE_MANAGER_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 9));
--%%   {$EXTERNALSYM SECURITY_RESOURCE_MANAGER_AUTHORITY}

   Security_Null_RID                 : constant := 16#0000_0000#;
   Security_World_RID                : constant := 16#0000_0000#;
   Security_Local_RID                : constant := 16#0000_0000#;

   Security_Creator_Owner_RID        : constant := 16#0000_0000#;
   Security_Creator_Group_RID        : constant := 16#0000_0001#;

   Security_Creator_Owner_Server_RID : constant := 16#0000_0002#;
   Security_Creator_Group_Server_RID : constant := 16#0000_0003#;

-----------------------------------------------------------------------------
--                                                                         --
-- NT well-known SIDs                                                        --
--                                                                           --
--     NT Authority            S-1-5                                         --
--     Dialup                  S-1-5-1                                       --
--                                                                           --
--     Network                 S-1-5-2                                       --
--     Batch                   S-1-5-3                                       --
--     Interactive             S-1-5-4                                       --
--     (Logon IDs)             S-1-5-5-X-Y                                   --
--     Service                 S-1-5-6                                       --
--     AnonymousLogon          S-1-5-7       (aka null logon session)        --
--     Proxy                   S-1-5-8                                       --
--     Enterprise DC (EDC)     S-1-5-9       (aka domain controller account) --
--     Self                    S-1-5-10      (self RID)                      --
--     Authenticated User      S-1-5-11      (Authenticated user somewhere)  --
--     Restricted Code         S-1-5-12      (Running restricted code)       --
--     Terminal Server         S-1-5-13      (Running on Terminal Server)    --
--     Remote Logon            S-1-5-14      (Remote Interactive Logon)      --
--     This Organization       S-1-5-15                                      --
--                                                                           --
--     Local System            S-1-5-18                                      --
--     Local Service           S-1-5-19                                      --
--     Network Service         S-1-5-20                                      --
--                                                                           --
--     (NT non-unique IDs)     S-1-5-0x15-... (NT Domain Sids)               --
--                                                                           --
--     (Built-in domain)       S-1-5-0x20                                    --
--                                                                           --
--     (Security Package IDs)  S-1-5-0x40                                    --
--     NTLM Authentication     S-1-5-0x40-10                                 --
--     SChannel Authentication S-1-5-0x40-14                                 --
--     Digest Authentication   S-1-5-0x40-21                                 --
--                                                                           --
--     Other Organization      S-1-5-1000    (>=1000 can not be filtered)    --
--                                                                           --
--                                                                           --
-- NOTE: the relative identifier values (RIDs) determine which security      --
--       boundaries the SID is allowed to cross.  Before adding new RIDs,    --
--       a determination needs to be made regarding which range they should  --
--       be added to in order to ensure proper "SID filtering"               --
--                                                                           --
-------------------------------------------------------------------------------

--%%   SECURITY_NT_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
--%%   {$EXTERNALSYM SECURITY_NT_AUTHORITY}

   Security_Dialup_RID                 : constant := 16#0000_0001#;
   Security_Network_RID                : constant := 16#0000_0002#;
   Security_Batch_RID                  : constant := 16#0000_0003#;
   Security_Interactive_RID            : constant := 16#0000_0004#;
   Security_Logon_Ids_RID              : constant := 16#0000_0005#;
   Security_Logon_Ids_RID_Count        : constant := 3;
   Security_Service_RID                : constant := 16#0000_0006#;
   Security_Anonymous_Logon_RID        : constant := 16#0000_0007#;
   Security_Proxy_RID                  : constant := 16#0000_0008#;
   Security_Enterprise_Controllers_RID : constant := 16#0000_0009#;
   Security_Server_Logon_RID           : constant := Security_Enterprise_Controllers_RID;
   Security_Principal_Self_RID         : constant := 16#0000_000A#;
   Security_Authenticated_User_RID     : constant := 16#0000_000B#;
   Security_Restricted_Code_RID        : constant := 16#0000_000C#;
   Security_Terminal_Server_RID        : constant := 16#0000_000D#;
   Security_Remote_Logon_RID           : constant := 16#0000_000E#;
   Security_This_Organization_RID      : constant := 16#0000_000F#;

   Security_Local_System_RID    : constant := 16#0000_0012#;
   Security_Local_Service_RID   : constant := 16#0000_0013#;
   Security_Network_Service_RID : constant := 16#0000_0014#;

   Security_NT_Non_Unique       : constant := 16#0000_0015#;
   Security_NT_Non_Unique_Sub_Auth_Count : constant := 3;

   Security_Builtin_Domain_RID  : constant := 16#0000_0020#;

   Security_Package_Base_RID       : constant := 16#0000_0040#;
   Security_Package_RID_Count      : constant := 2;
   Security_Package_Ntlm_RID       : constant := 16#0000_000A#;
   Security_Package_Schannel_RID   : constant := 16#0000_000E#;
   Security_Package_Digest_RID     : constant := 16#0000_0015#;

   Security_Max_Always_Filtered    : constant := 16#0000_03E7#;
   Security_Min_Never_Filtered     : constant := 16#0000_03E8#;

   Security_Other_Organization_RID : constant := 16#0000_03E8#;

-----------------------------------------------------------------------------
--                                                                         --
-- well-known domain relative sub-authority values (RIDs)...               --
--                                                                         --
-----------------------------------------------------------------------------

-- Well-known users ...

   Forest_User_RID_Max    : constant := 16#0000_01F3#;

   Domain_User_RID_Admin  : constant := 16#0000_01F4#;
   Domain_User_RID_Guest  : constant := 16#0000_01F5#;
   Domain_User_RID_Krbtgt : constant := 16#0000_01F6#;

   Domain_User_RID_Max    : constant := 16#0000_03E7#;

-- well-known groups ...

   Domain_Group_RID_Admins            : constant := 16#0000_0200#;
   Domain_Group_RID_Users             : constant := 16#0000_0201#;
   Domain_Group_RID_Guests            : constant := 16#0000_0202#;
   Domain_Group_RID_Computers         : constant := 16#0000_0203#;
   Domain_Group_RID_Controllers       : constant := 16#0000_0204#;
   Domain_Group_RID_Cert_Admins       : constant := 16#0000_0205#;
   Domain_Group_RID_Schema_Admins     : constant := 16#0000_0206#;
   Domain_Group_RID_Enterprise_Admins : constant := 16#0000_0207#;
   Domain_Group_RID_Policy_Admins     : constant := 16#0000_0208#;

-- well-known aliases ...

   Domain_Alias_RID_Admins           : constant := 16#0000_0220#;
   Domain_Alias_RID_Users            : constant := 16#0000_0221#;
   Domain_Alias_RID_Guests           : constant := 16#0000_0222#;
   Domain_Alias_RID_Power_Users      : constant := 16#0000_0223#;

   Domain_Alias_RID_Account_Ops      : constant := 16#0000_0224#;
   Domain_Alias_RID_System_Ops       : constant := 16#0000_0225#;
   Domain_Alias_RID_Print_Ops        : constant := 16#0000_0226#;
   Domain_Alias_RID_Backup_Ops       : constant := 16#0000_0227#;

   Domain_Alias_RID_Replicator       : constant := 16#0000_0228#;
   Domain_Alias_RID_Ras_Servers      : constant := 16#0000_0229#;
   Domain_Alias_RID_Prew2Kcompaccess : constant := 16#0000_022A#;
   Domain_Alias_RID_Remote_Desktop_Users : constant := 16#0000_022B#;
   Domain_Alias_RID_Network_Configuration_Ops : constant := 16#0000_022C#;
   Domain_Alias_RID_Incoming_Forest_Trust_Builders : constant := 16#0000_022D#;

   Domain_Alias_RID_Monitoring_Users      : constant := 16#0000_022E#;
   Domain_Alias_RID_Logging_Users         : constant := 16#0000_022F#;
   Domain_Alias_RID_Authorizationaccess   : constant := 16#0000_0230#;
   Domain_Alias_RID_Ts_License_Servers    : constant := 16#0000_0231#;

--%%   WELL_KNOWN_SID_TYPE = (
--%%     WinNullSid,
--%%     WinWorldSid,
--%%     WinLocalSid,
--%%     WinCreatorOwnerSid,
--%%     WinCreatorGroupSid,
--%%     WinCreatorOwnerServerSid,
--%%     WinCreatorGroupServerSid,
--%%     WinNtAuthoritySid,
--%%     WinDialupSid,
--%%     WinNetworkSid,
--%%     WinBatchSid,
--%%     WinInteractiveSid,
--%%     WinServiceSid,
--%%     WinAnonymousSid,
--%%     WinProxySid,
--%%     WinEnterpriseControllersSid,
--%%     WinSelfSid,
--%%     WinAuthenticatedUserSid,
--%%     WinRestrictedCodeSid,
--%%     WinTerminalServerSid,
--%%     WinRemoteLogonIdSid,
--%%     WinLogonIdsSid,
--%%     WinLocalSystemSid,
--%%     WinLocalServiceSid,
--%%     WinNetworkServiceSid,
--%%     WinBuiltinDomainSid,
--%%     WinBuiltinAdministratorsSid,
--%%     WinBuiltinUsersSid,
--%%     WinBuiltinGuestsSid,
--%%     WinBuiltinPowerUsersSid,
--%%     WinBuiltinAccountOperatorsSid,
--%%     WinBuiltinSystemOperatorsSid,
--%%     WinBuiltinPrintOperatorsSid,
--%%     WinBuiltinBackupOperatorsSid,
--%%     WinBuiltinReplicatorSid,
--%%     WinBuiltinPreWindows2000CompatibleAccessSid,
--%%     WinBuiltinRemoteDesktopUsersSid,
--%%     WinBuiltinNetworkConfigurationOperatorsSid,
--%%     WinAccountAdministratorSid,
--%%     WinAccountGuestSid,
--%%     WinAccountKrbtgtSid,
--%%     WinAccountDomainAdminsSid,
--%%     WinAccountDomainUsersSid,
--%%     WinAccountDomainGuestsSid,
--%%     WinAccountComputersSid,
--%%     WinAccountControllersSid,
--%%     WinAccountCertAdminsSid,
--%%     WinAccountSchemaAdminsSid,
--%%     WinAccountEnterpriseAdminsSid,
--%%     WinAccountPolicyAdminsSid,
--%%     WinAccountRasAndIasServersSid,
--%%     WinNTLMAuthenticationSid,
--%%     WinDigestAuthenticationSid,
--%%     WinSChannelAuthenticationSid,
--%%     WinThisOrganizationSid,
--%%     WinOtherOrganizationSid,
--%%     WinBuiltinIncomingForestTrustBuildersSid,
--%%     WinBuiltinPerfMonitoringUsersSid,
--%%     WinBuiltinPerfLoggingUsersSid,
--%%     WinBuiltinAuthorizationAccessSid,
--%%     WinBuiltinTerminalServerLicenseServersSid);
--%%   {$EXTERNALSYM WELL_KNOWN_SID_TYPE}
--%%   TWellKnownSidType = WELL_KNOWN_SID_TYPE;

--
-- Allocate the System Luid.  The first 1000 LUIDs are reserved.
-- Use #999 here (0x3E7 = 999)
--

--%%   SYSTEM_LUID: LUID = (LowPart: $3E7; HighPart: $0);
--%%   {$EXTERNALSYM SYSTEM_LUID}
--%%   ANONYMOUS_LOGON_LUID: LUID = (LowPart: $3E6; HighPart: $0);
--%%   {$EXTERNALSYM ANONYMOUS_LOGON_LUID}
--%%   LOCALSERVICE_LUID: LUID = (LowPart: $3E5; HighPart: $0);
--%%   {$EXTERNALSYM LOCALSERVICE_LUID}
--%%   NETWORKSERVICE_LUID: LUID = (LowPart: $3E4; HighPart: $0);
--%%   {$EXTERNALSYM NETWORKSERVICE_LUID}

------------------------------------------------------------------------
--                                                                    --
--                          User and Group related SID attributes     --
--                                                                    --
------------------------------------------------------------------------

--
-- Group attributes
--

   Se_Group_Mandatory          : constant := 16#0000_0001#;
   Se_Group_Enabled_By_Default : constant := 16#0000_0002#;
   Se_Group_Enabled            : constant := 16#0000_0004#;
   Se_Group_Owner              : constant := 16#0000_0008#;
   Se_Group_Use_For_Deny_Only  : constant := 16#0000_0010#;
   Se_Group_Logon_Id           : constant := 16#C000_0000#;
   Se_Group_Resource           : constant := 16#2000_0000#;
   Se_Group_Integrity          : constant := 16#0000_0020#;
   Se_Group_Integrity_Enabled  : constant := 16#0000_0040#;




--
-- User attributes
--

-- (None yet defined.)

------------------------------------------------------------------------
--                                                                    --
--                         ACL  and  ACE                              --
--                                                                    --
------------------------------------------------------------------------

--
--  Define an ACL and the ACE format.  The structure of an ACL header
--  followed by one or more ACEs.  Pictorally the structure of an ACL header
--  is as follows:
--
--       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--      +-------------------------------+---------------+---------------+
--      |            AclSize            |      Sbz1     |  AclRevision  |
--      +-------------------------------+---------------+---------------+
--      |              Sbz2             |           AceCount            |
--      +-------------------------------+-------------------------------+
--
--  The current AclRevision is defined to be ACL_REVISION.
--
--  AclSize is the size, in bytes, allocated for the ACL.  This includes
--  the ACL header, ACES, and remaining free space in the buffer.
--
--  AceCount is the number of ACES in the ACL.
--

-- This is the *current* ACL revision

   ACL_Revision    : constant := 2;
   ACL_Revision_Ds : constant := 4;

-- This is the history of ACL revisions.  Add a new one whenever
-- ACL_REVISION is updated

   ACL_Revision1    : constant := 1;
   ACL_Revision2    : constant := 2;
   Min_ACL_Revision : constant := ACL_Revision2;
   ACL_Revision3    : constant := 3;
   ACL_Revision4    : constant := 4;
   Max_ACL_Revision : constant := ACL_Revision4;

   type ACL_Type;
   type ACL_Ptr is access all ACL_Type;
   type ACL_CPtr is access constant ACL_Type;
   type ACL_Type is record
      ACL_Revision : Byte;
      Sbz1 : Byte;
      ACL_Size : Word;
      ACE_Count : Word;
      Sbz2 : Word;
   end record;

--%%   PPACL = ^PAcl;
--%%   {$NODEFINE PPACL}

--
--  The structure of an ACE is a common ace header followed by ace type
--  specific data.  Pictorally the structure of the common ace header is
--  as follows:
--
--       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--      +---------------+-------+-------+---------------+---------------+
--      |            AceSize            |    AceFlags   |     AceType   |
--      +---------------+-------+-------+---------------+---------------+
--
--  AceType denotes the type of the ace, there are some predefined ace
--  types
--
--  AceSize is the size, in bytes, of ace.
--
--  AceFlags are the Ace flags for audit and inheritance, defined shortly.

   type ACE_Header_Type;
   type ACE_Header_Ptr is access all ACE_Header_Type;
   type ACE_Header_CPtr is access constant ACE_Header_Type;
   type ACE_Header_Type is record
      ACE_Type : Byte;
      ACE_Flags : Byte;
      ACE_Size : Word;
   end record;

--
--  The following are the predefined ace types that go into the AceType
--  field of an Ace header.
--

   Access_Min_MS_ACE_Type    : constant := 16#0#;
   Access_Allowed_ACE_Type   : constant := 16#0#;
   Access_Denied_ACE_Type    : constant := 16#1#;
   System_Audit_ACE_Type     : constant := 16#2#;
   System_Alarm_ACE_Type     : constant := 16#3#;
   Access_Max_MS_V2_ACE_Type : constant := 16#3#;

   Access_Allowed_Compound_ACE_Type : constant := 16#4#;
   Access_Max_MS_V3_ACE_Type        : constant := 16#4#;

   Access_Min_MS_Object_ACE_Type  : constant := 16#5#;
   Access_Allowed_Object_ACE_Type : constant := 16#5#;
   Access_Denied_Object_ACE_Type  : constant := 16#6#;
   System_Audit_Object_ACE_Type   : constant := 16#7#;
   System_Alarm_Object_ACE_Type   : constant := 16#8#;
   Access_Max_MS_Object_ACE_Type  : constant := 16#8#;

   Access_Max_MS_V4_ACE_Type : constant := 16#8#;
   Access_Max_MS_ACE_Type    : constant := 16#8#;

   Access_Allowed_Callback_ACE_Type        : constant := 16#9#;
   Access_Denied_Callback_ACE_Type         : constant := 16#A#;
   Access_Allowed_Callback_Object_ACE_Type : constant := 16#B#;
   Access_Denied_Callback_Object_ACE_Type  : constant := 16#C#;
   System_Audit_Callback_ACE_Type          : constant := 16#D#;
   System_Alarm_Callback_ACE_Type          : constant := 16#E#;
   System_Audit_Callback_Object_ACE_Type   : constant := 16#F#;
   System_Alarm_Callback_Object_ACE_Type   : constant := 16#10#;

   Access_Max_MS_V5_ACE_Type               : constant := 16#10#;

--
--  The following are the inherit flags that go into the AceFlags field
--  of an Ace header.
--

   Object_Inherit_ACE       : constant := 16#1#;
   Container_Inherit_ACE    : constant := 16#2#;
   No_Propagate_Inherit_ACE : constant := 16#4#;
   Inherit_Only_ACE         : constant := 16#8#;
   Inherited_ACE            : constant := 16#10#;
   Valid_Inherit_Flags      : constant := 16#1F#;

--  The following are the currently defined ACE flags that go into the
--  AceFlags field of an ACE header.  Each ACE type has its own set of
--  AceFlags.
--
--  SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
--  types to indicate that a message is generated for successful accesses.
--
--  FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
--  to indicate that a message is generated for failed accesses.
--

--
--  SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
--
--  These control the signaling of audit and alarms for success or failure.
--

   Successful_Access_ACE_Flag : constant := 16#40#;
   Failed_Access_ACE_Flag     : constant := 16#80#;

--
--  We'll define the structure of the predefined ACE types.  Pictorally
--  the structure of the predefined ACE's is as follows:
--
--       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--      +---------------+-------+-------+---------------+---------------+
--      |    AceFlags   | Resd  |Inherit|    AceSize    |     AceType   |
--      +---------------+-------+-------+---------------+---------------+
--      |                              Mask                             |
--      +---------------------------------------------------------------+
--      |                                                               |
--      +                                                               +
--      |                                                               |
--      +                              Sid                              +
--      |                                                               |
--      +                                                               +
--      |                                                               |
--      +---------------------------------------------------------------+
--
--  Mask is the access mask associated with the ACE.  This is either the
--  access allowed, access denied, audit, or alarm mask.
--
--  Sid is the Sid associated with the ACE.
--

--  The following are the four predefined ACE types.

--  Examine the AceType field in the Header to determine
--  which structure is appropriate to use for casting.

   type Access_Allowed_ACE_Type;
   type Access_Allowed_ACE_Ptr is access all Access_Allowed_ACE_Type;
   type Access_Allowed_ACE_CPtr is access constant Access_Allowed_ACE_Type;
   type Access_Allowed_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
   end record;

   type Access_Denied_ACE_Type;
   type Access_Denied_ACE_Ptr is access all Access_Denied_ACE_Type;
   type Access_Denied_ACE_CPtr is access constant Access_Denied_ACE_Type;
   type Access_Denied_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
   end record;

   type System_Audit_ACE_Type;
   type System_Audit_ACE_Ptr is access all System_Audit_ACE_Type;
   type System_Audit_ACE_CPtr is access constant System_Audit_ACE_Type;
   type System_Audit_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
   end record;

   type System_Alarm_ACE_Type;
   type System_Alarm_ACE_Ptr is access all System_Alarm_ACE_Type;
   type System_Alarm_ACE_CPtr is access constant System_Alarm_ACE_Type;
   type System_Alarm_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
   end record;

   type Access_Allowed_Object_ACE_Type;
   type Access_Allowed_Object_ACE_Ptr is access all Access_Allowed_Object_ACE_Type;
   type Access_Allowed_Object_ACE_CPtr is access constant Access_Allowed_Object_ACE_Type;
   type Access_Allowed_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
   end record;

   type Access_Denied_Object_ACE_Type;
   type Access_Denied_Object_ACE_Ptr is access all Access_Denied_Object_ACE_Type;
   type Access_Denied_Object_ACE_CPtr is access constant Access_Denied_Object_ACE_Type;
   type Access_Denied_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
   end record;

   type System_Audit_Object_ACE_Type;
   type System_Audit_Object_ACE_Ptr is access all System_Audit_Object_ACE_Type;
   type System_Audit_Object_ACE_CPtr is access constant System_Audit_Object_ACE_Type;
   type System_Audit_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
   end record;

   type System_Alarm_Object_ACE_Type;
   type System_Alarm_Object_ACE_Ptr is access all System_Alarm_Object_ACE_Type;
   type System_Alarm_Object_ACE_CPtr is access constant System_Alarm_Object_ACE_Type;
   type System_Alarm_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
   end record;

--
-- Callback ace support in post Win2000.
-- Resource managers can put their own data after Sidstart + Length of the sid
--

   type Access_Allowed_Call_Back_ACE_Type;
   type Access_Allowed_Call_Back_ACE_Ptr is access all Access_Allowed_Call_Back_ACE_Type;
   type Access_Allowed_Call_Back_ACE_CPtr is access constant Access_Allowed_Call_Back_ACE_Type;
   type Access_Allowed_Call_Back_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type Access_Denied_Call_Back_ACE_Type;
   type Access_Denied_Call_Back_ACE_Ptr is access all Access_Denied_Call_Back_ACE_Type;
   type Access_Denied_Call_Back_ACE_CPtr is access constant Access_Denied_Call_Back_ACE_Type;
   type Access_Denied_Call_Back_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type System_Audit_Call_Back_ACE_Type;
   type System_Audit_Call_Back_ACE_Ptr is access all System_Audit_Call_Back_ACE_Type;
   type System_Audit_Call_Back_ACE_CPtr is access constant System_Audit_Call_Back_ACE_Type;
   type System_Audit_Call_Back_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type System_Alarm_Call_Back_ACE_Type;
   type System_Alarm_Call_Back_ACE_Ptr is access all System_Alarm_Call_Back_ACE_Type;
   type System_Alarm_Call_Back_ACE_CPtr is access constant System_Alarm_Call_Back_ACE_Type;
   type System_Alarm_Call_Back_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type Access_Allowed_Call_Back_Object_ACE_Type;
   type Access_Allowed_Call_Back_Object_ACE_Ptr is access all Access_Allowed_Call_Back_Object_ACE_Type;
   type Access_Allowed_Call_Back_Object_ACE_CPtr is access constant Access_Allowed_Call_Back_Object_ACE_Type;
   type Access_Allowed_Call_Back_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type Access_Denied_Call_Back_Object_ACE_Type;
   type Access_Denied_Call_Back_Object_ACE_Ptr is access all Access_Denied_Call_Back_Object_ACE_Type;
   type Access_Denied_Call_Back_Object_ACE_CPtr is access constant Access_Denied_Call_Back_Object_ACE_Type;
   type Access_Denied_Call_Back_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type System_Audit_Call_Back_Object_ACE_Type;
   type System_Audit_Call_Back_Object_ACE_Ptr is access all System_Audit_Call_Back_Object_ACE_Type;
   type System_Audit_Call_Back_Object_ACE_CPtr is access constant System_Audit_Call_Back_Object_ACE_Type;
   type System_Audit_Call_Back_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

   type System_Alarm_Call_Back_Object_ACE_Type;
   type System_Alarm_Call_Back_Object_ACE_Ptr is access all System_Alarm_Call_Back_Object_ACE_Type;
   type System_Alarm_Call_Back_Object_ACE_CPtr is access constant System_Alarm_Call_Back_Object_ACE_Type;
   type System_Alarm_Call_Back_Object_ACE_Type is record
      Header : ACE_Header_Type;
      Mask : Access_Mask_Type;
      Flags : Unsigned_32;
      Object_Type : GUID_Type;
      Inherited_Object_Type : GUID_Type;
      SID_Start : Unsigned_32;
            -- Opaque resouce manager specific data
   end record;

--
-- Currently define Flags for "OBJECT" ACE types.
--

   ACE_Object_Type_Present           : constant := 16#1#;
   ACE_Inherited_Object_Type_Present : constant := 16#2#;

--
--  The following declarations are used for setting and querying information
--  about and ACL.  First are the various information classes available to
--  the user.
--

   AclRevisionInformation : constant := 1;
   AclSizeInformation : constant := 2;

   subtype _ACL_Information_Class_Type is Unsigned_32;
   subtype _ACL_Information_Class_Ptr is Unsigned_32_Ptr;
   subtype _ACL_Information_Class_CPtr is Unsigned_32_CPtr;
   subtype ACL_Information_Class_Type is _ACL_Information_Class_Type;
   subtype ACL_Information_Class_Ptr is _ACL_Information_Class_Ptr;
   subtype ACL_Information_Class_CPtr is _ACL_Information_Class_CPtr;
--%%   TAclInformationClass = ACL_INFORMATION_CLASS;

--
--  This record is returned/sent if the user is requesting/setting the
--  AclRevisionInformation
--

   type ACL_Revision_Information_Type;
   type ACL_Revision_Information_Ptr is access all ACL_Revision_Information_Type;
   type ACL_Revision_Information_CPtr is access constant ACL_Revision_Information_Type;
   type ACL_Revision_Information_Type is record
      ACL_Revision : Unsigned_32;
   end record;

--
--  This record is returned if the user is requesting AclSizeInformation
--

   type ACL_Size_Information_Type;
   type ACL_Size_Information_Ptr is access all ACL_Size_Information_Type;
   type ACL_Size_Information_CPtr is access constant ACL_Size_Information_Type;
   type ACL_Size_Information_Type is record
      ACE_Count : Unsigned_32;
      ACL_Bytes_In_Use : Unsigned_32;
      ACL_Bytes_Free : Unsigned_32;
   end record;

------------------------------------------------------------------------
--                                                                    --
--                             SECURITY_DESCRIPTOR                    --
--                                                                    --
------------------------------------------------------------------------
--
--  Define the Security Descriptor and related data types.
--  This is an opaque data structure.
--

--
-- Current security descriptor revision value
--

   Security_Descriptor_Revision  : constant := 1;
   Security_Descriptor_Revision1 : constant := 1;

   subtype Security_Descriptor_Control_Type is Unsigned_16;
   subtype Security_Descriptor_Control_Ptr is Unsigned_16_Ptr;
   subtype Security_Descriptor_Control_CPtr is Unsigned_16_CPtr;

   Se_Owner_Defaulted       : constant := 16#0001#;
   Se_Group_Defaulted       : constant := 16#0002#;
   Se_DACL_Present          : constant := 16#0004#;
   Se_DACL_Defaulted        : constant := 16#0008#;
   Se_SACL_Present          : constant := 16#0010#;
   Se_SACL_Defaulted        : constant := 16#0020#;
   Se_DACL_Auto_Inherit_Req : constant := 16#0100#;
   Se_SACL_Auto_Inherit_Req : constant := 16#0200#;
   Se_DACL_Auto_Inherited   : constant := 16#0400#;
   Se_SACL_Auto_Inherited   : constant := 16#0800#;
   Se_DACL_Protected        : constant := 16#1000#;
   Se_SACL_Protected        : constant := 16#2000#;
   Se_Rm_Control_Valid      : constant := 16#4000#;
   Se_Self_Relative         : constant := 16#8000#;

--
--  Where:
--
--      SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
--          SID pointed to by the Owner field was provided by a
--          defaulting mechanism rather than explicitly provided by the
--          original provider of the security descriptor.  This may
--          affect the treatment of the SID with respect to inheritence
--          of an owner.
--
--      SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
--          SID in the Group field was provided by a defaulting mechanism
--          rather than explicitly provided by the original provider of
--          the security descriptor.  This may affect the treatment of
--          the SID with respect to inheritence of a primary group.
--
--      SE_DACL_PRESENT - This boolean flag, when set, indicates that the
--          security descriptor contains a discretionary ACL.  If this
--          flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
--          null, then a null ACL is explicitly being specified.
--
--      SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
--          ACL pointed to by the Dacl field was provided by a defaulting
--          mechanism rather than explicitly provided by the original
--          provider of the security descriptor.  This may affect the
--          treatment of the ACL with respect to inheritence of an ACL.
--          This flag is ignored if the DaclPresent flag is not set.
--
--      SE_SACL_PRESENT - This boolean flag, when set,  indicates that the
--          security descriptor contains a system ACL pointed to by the
--          Sacl field.  If this flag is set and the Sacl field of the
--          SECURITY_DESCRIPTOR is null, then an empty (but present)
--          ACL is being specified.
--
--      SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
--          ACL pointed to by the Sacl field was provided by a defaulting
--          mechanism rather than explicitly provided by the original
--          provider of the security descriptor.  This may affect the
--          treatment of the ACL with respect to inheritence of an ACL.
--          This flag is ignored if the SaclPresent flag is not set.
--
--      SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
--          security descriptor is in self-relative form.  In this form,
--          all fields of the security descriptor are contiguous in memory
--          and all pointer fields are expressed as offsets from the
--          beginning of the security descriptor.  This form is useful
--          for treating security descriptors as opaque data structures
--          for transmission in communication protocol or for storage on
--          secondary media.
--
--
--
-- Pictorially the structure of a security descriptor is as follows:
--
--       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--      +---------------------------------------------------------------+
--      |            Control            |Reserved1 (SBZ)|   Revision    |
--      +---------------------------------------------------------------+
--      |                            Owner                              |
--      +---------------------------------------------------------------+
--      |                            Group                              |
--      +---------------------------------------------------------------+
--      |                            Sacl                               |
--      +---------------------------------------------------------------+
--      |                            Dacl                               |
--      +---------------------------------------------------------------+
--
-- In general, this data structure should be treated opaquely to ensure future
-- compatibility.
--
--

   type Security_Descriptor_Relative_Type;
   type Security_Descriptor_Relative_Ptr is access all Security_Descriptor_Relative_Type;
   type Security_Descriptor_Relative_CPtr is access constant Security_Descriptor_Relative_Type;
   type Security_Descriptor_Relative_Type is record
      Revision : Byte;
      Sbz1 : Byte;
      Control : Security_Descriptor_Control_Type;
      Owner : Unsigned_32;
      Group : Unsigned_32;
      SACL : Unsigned_32;
      DACL : Unsigned_32;
   end record;

   type Security_Descriptor_Type;
   type Security_Descriptor_Ptr is access all Security_Descriptor_Type;
   type Security_Descriptor_CPtr is access constant Security_Descriptor_Type;
   type Security_Descriptor_Type is record
      Revision : Byte;
      Sbz1 : Byte;
      Control : Security_Descriptor_Control_Type;
      Owner : SID_Ptr;
      Group : SID_Ptr;
      SACL : ACL_Ptr;
      DACL : ACL_Ptr;
   end record;

--%%   PPSECURITY_DESCRIPTOR = ^PSECURITY_DESCRIPTOR;
--%%   {$NODEFINE PPSECURITY_DESCRIPTOR}

--%%   SECURITY_DESCRIPTOR_MIN_LENGTH = SizeOf(SECURITY_DESCRIPTOR);
--%%   {$EXTERNALSYM SECURITY_DESCRIPTOR_MIN_LENGTH}

-- Where:
--
--     Revision - Contains the revision level of the security
--         descriptor.  This allows this structure to be passed between
--         systems or stored on disk even though it is expected to
--         change in the future.
--
--     Control - A set of flags which qualify the meaning of the
--         security descriptor or individual fields of the security
--         descriptor.
--
--     Owner - is a pointer to an SID representing an object's owner.
--         If this field is null, then no owner SID is present in the
--         security descriptor.  If the security descriptor is in
--         self-relative form, then this field contains an offset to
--         the SID, rather than a pointer.
--
--     Group - is a pointer to an SID representing an object's primary
--         group.  If this field is null, then no primary group SID is
--         present in the security descriptor.  If the security descriptor
--         is in self-relative form, then this field contains an offset to
--         the SID, rather than a pointer.
--
--     Sacl - is a pointer to a system ACL.  This field value is only
--         valid if the DaclPresent control flag is set.  If the
--         SaclPresent flag is set and this field is null, then a null
--         ACL  is specified.  If the security descriptor is in
--         self-relative form, then this field contains an offset to
--         the ACL, rather than a pointer.
--
--     Dacl - is a pointer to a discretionary ACL.  This field value is
--         only valid if the DaclPresent control flag is set.  If the
--         DaclPresent flag is set and this field is null, then a null
--         ACL (unconditionally granting access) is specified.  If the
--         security descriptor is in self-relative form, then this field
--         contains an offset to the ACL, rather than a pointer.
--

------------------------------------------------------------------------
--                                                                    --
--               Object Type list for AccessCheckByType               --
--                                                                    --
------------------------------------------------------------------------

   type Object_Type_List_Type;
   type Object_Type_List_Ptr is access all Object_Type_List_Type;
   type Object_Type_List_CPtr is access constant Object_Type_List_Type;
   type Object_Type_List_Type is record
      Level : Word;
      Sbz : Word;
      Object_Type : GUID_Ptr;
   end record;

--
-- DS values for Level
--

   Access_Object_GUID       : constant := 0;
   Access_Property_Set_GUID : constant := 1;
   Access_Property_GUID     : constant := 2;

   Access_Max_Level         : constant := 4;

--
-- Parameters to NtAccessCheckByTypeAndAditAlarm
--

--%%   _AUDIT_EVENT_TYPE = (AuditEventObjectAccess, AuditEventDirectoryServiceAccess);
--%%   {$EXTERNALSYM _AUDIT_EVENT_TYPE}
   subtype Audit_Event_Type_Type is _AUDIT_EVENT_TYPE;
   type Audit_Event_Type_Ptr is access all _AUDIT_EVENT_TYPE;
   type Audit_Event_Type_CPtr is access constant _AUDIT_EVENT_TYPE;

   Audit_Allow_No_Privilege : constant := 16#1#;

--
-- DS values for Source and ObjectTypeName
--

--%%   ACCESS_DS_SOURCE_A           = 'DS';
--%%   {$EXTERNALSYM ACCESS_DS_SOURCE_A}
--%%   ACCESS_DS_SOURCE_W           = WideString('DS');
--%%   {$EXTERNALSYM ACCESS_DS_SOURCE_W}
--%%   ACCESS_DS_OBJECT_TYPE_NAME_A = 'Directory Service Object';
--%%   {$EXTERNALSYM ACCESS_DS_OBJECT_TYPE_NAME_A}
--%%   ACCESS_DS_OBJECT_TYPE_NAME_W = WideString('Directory Service Object');
--%%   {$EXTERNALSYM ACCESS_DS_OBJECT_TYPE_NAME_W}

------------------------------------------------------------------------
--                                                                    --
--               Privilege Related Data Structures                    --
--                                                                    --
------------------------------------------------------------------------

--
-- Privilege attributes
--

   Se_Privilege_Enabled_By_Default : constant := 16#0000_0001#;
   Se_Privilege_Enabled            : constant := 16#0000_0002#;
   Se_Privilege_Removed            : constant := 16#0000_0004#;
   Se_Privilege_Used_For_Access    : constant := 16#8000_0000#;

--
-- Privilege Set Control flags
--

   Privilege_Set_All_Necessary : constant := 1;

--
--  Privilege Set - This is defined for a privilege set of one.
--                  If more than one privilege is needed, then this structure
--                  will need to be allocated with more space.
--
--  Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
--  structure (defined in se.h)
--

--%%   PPRIVILEGE_SET = ^PRIVILEGE_SET;
--%%   {$EXTERNALSYM PPRIVILEGE_SET}
--%%   _PRIVILEGE_SET = record
--%%     PrivilegeCount: DWORD;
--%%     Control: DWORD;
--%%     Privilege: array [0..ANYSIZE_ARRAY - 1] of LUID_AND_ATTRIBUTES;
--%%     //Privilege: LUID_AND_ATTRIBUTES;
--%%   end;
--%%   {$EXTERNALSYM _PRIVILEGE_SET}
--%%   PRIVILEGE_SET = _PRIVILEGE_SET;
--%%   {$EXTERNALSYM PRIVILEGE_SET}
--%%   TPrivilegeSet = PRIVILEGE_SET;
--%%   PPrivilegeSet = PPRIVILEGE_SET;

------------------------------------------------------------------------
--                                                                    --
--               NT Defined Privileges                                --
--                                                                    --
------------------------------------------------------------------------

--%%   SE_CREATE_TOKEN_NAME        = 'SeCreateTokenPrivilege';
--%%   {$EXTERNALSYM SE_CREATE_TOKEN_NAME}
--%%   SE_ASSIGNPRIMARYTOKEN_NAME  = 'SeAssignPrimaryTokenPrivilege';
--%%   {$EXTERNALSYM SE_ASSIGNPRIMARYTOKEN_NAME}
--%%   SE_LOCK_MEMORY_NAME         = 'SeLockMemoryPrivilege';
--%%   {$EXTERNALSYM SE_LOCK_MEMORY_NAME}
--%%   SE_INCREASE_QUOTA_NAME      = 'SeIncreaseQuotaPrivilege';
--%%   {$EXTERNALSYM SE_INCREASE_QUOTA_NAME}
--%%   SE_UNSOLICITED_INPUT_NAME   = 'SeUnsolicitedInputPrivilege';
--%%   {$EXTERNALSYM SE_UNSOLICITED_INPUT_NAME}
--%%   SE_MACHINE_ACCOUNT_NAME     = 'SeMachineAccountPrivilege';
--%%   {$EXTERNALSYM SE_MACHINE_ACCOUNT_NAME}
--%%   SE_TCB_NAME                 = 'SeTcbPrivilege';
--%%   {$EXTERNALSYM SE_TCB_NAME}
--%%   SE_SECURITY_NAME            = 'SeSecurityPrivilege';
--%%   {$EXTERNALSYM SE_SECURITY_NAME}
--%%   SE_TAKE_OWNERSHIP_NAME      = 'SeTakeOwnershipPrivilege';
--%%   {$EXTERNALSYM SE_TAKE_OWNERSHIP_NAME}
--%%   SE_LOAD_DRIVER_NAME         = 'SeLoadDriverPrivilege';
--%%   {$EXTERNALSYM SE_LOAD_DRIVER_NAME}
--%%   SE_SYSTEM_PROFILE_NAME      = 'SeSystemProfilePrivilege';
--%%   {$EXTERNALSYM SE_SYSTEM_PROFILE_NAME}
--%%   SE_SYSTEMTIME_NAME          = 'SeSystemtimePrivilege';
--%%   {$EXTERNALSYM SE_SYSTEMTIME_NAME}
--%%   SE_PROF_SINGLE_PROCESS_NAME = 'SeProfileSingleProcessPrivilege';
--%%   {$EXTERNALSYM SE_PROF_SINGLE_PROCESS_NAME}
--%%   SE_INC_BASE_PRIORITY_NAME   = 'SeIncreaseBasePriorityPrivilege';
--%%   {$EXTERNALSYM SE_INC_BASE_PRIORITY_NAME}
--%%   SE_CREATE_PAGEFILE_NAME     = 'SeCreatePagefilePrivilege';
--%%   {$EXTERNALSYM SE_CREATE_PAGEFILE_NAME}
--%%   SE_CREATE_PERMANENT_NAME    = 'SeCreatePermanentPrivilege';
--%%   {$EXTERNALSYM SE_CREATE_PERMANENT_NAME}
--%%   SE_BACKUP_NAME              = 'SeBackupPrivilege';
--%%   {$EXTERNALSYM SE_BACKUP_NAME}
--%%   SE_RESTORE_NAME             = 'SeRestorePrivilege';
--%%   {$EXTERNALSYM SE_RESTORE_NAME}
--%%   SE_SHUTDOWN_NAME            = 'SeShutdownPrivilege';
--%%   {$EXTERNALSYM SE_SHUTDOWN_NAME}
--%%   SE_DEBUG_NAME               = 'SeDebugPrivilege';
--%%   {$EXTERNALSYM SE_DEBUG_NAME}
--%%   SE_AUDIT_NAME               = 'SeAuditPrivilege';
--%%   {$EXTERNALSYM SE_AUDIT_NAME}
--%%   SE_SYSTEM_ENVIRONMENT_NAME  = 'SeSystemEnvironmentPrivilege';
--%%   {$EXTERNALSYM SE_SYSTEM_ENVIRONMENT_NAME}
--%%   SE_CHANGE_NOTIFY_NAME       = 'SeChangeNotifyPrivilege';
--%%   {$EXTERNALSYM SE_CHANGE_NOTIFY_NAME}
--%%   SE_REMOTE_SHUTDOWN_NAME     = 'SeRemoteShutdownPrivilege';
--%%   {$EXTERNALSYM SE_REMOTE_SHUTDOWN_NAME}
--%%   SE_UNDOCK_NAME              = 'SeUndockPrivilege';
--%%   {$EXTERNALSYM SE_UNDOCK_NAME}
--%%   SE_SYNC_AGENT_NAME          = 'SeSyncAgentPrivilege';
--%%   {$EXTERNALSYM SE_SYNC_AGENT_NAME}
--%%   SE_ENABLE_DELEGATION_NAME   = 'SeEnableDelegationPrivilege';
--%%   {$EXTERNALSYM SE_ENABLE_DELEGATION_NAME}
--%%   SE_MANAGE_VOLUME_NAME       = 'SeManageVolumePrivilege';
--%%   {$EXTERNALSYM SE_MANAGE_VOLUME_NAME}
--%%   SE_IMPERSONATE_NAME         = 'SeImpersonatePrivilege';
--%%   {$EXTERNALSYM SE_IMPERSONATE_NAME}
--%%   SE_CREATE_GLOBAL_NAME       = 'SeCreateGlobalPrivilege';
--%%   {$EXTERNALSYM SE_CREATE_GLOBAL_NAME}

--------------------------------------------------------------------
--                                                                --
--           Security Quality Of Service                          --
--                                                                --
--                                                                --
--------------------------------------------------------------------

--
-- Impersonation Level
--
-- Impersonation level is represented by a pair of bits in Windows.
-- If a new impersonation level is added or lowest value is changed from
-- 0 to something else, fix the Windows CreateFile call.
--

--%%   _SECURITY_IMPERSONATION_LEVEL = (SecurityAnonymous, SecurityIdentification,
--%%     SecurityImpersonation, SecurityDelegation);
--%%   {$EXTERNALSYM _SECURITY_IMPERSONATION_LEVEL}
   subtype Security_Impersonation_Level_Type is _SECURITY_IMPERSONATION_LEVEL;
   type Security_Impersonation_Level_Ptr is access all _SECURITY_IMPERSONATION_LEVEL;
   type Security_Impersonation_Level_CPtr is access constant _SECURITY_IMPERSONATION_LEVEL;

   Security_Max_Impersonation_Level : constant := SecurityDelegation;
   Security_Min_Impersonation_Level : constant := SecurityAnonymous;
   Default_Impersonation_Level      : constant := SecurityImpersonation;

--%% function VALID_IMPERSONATION_LEVEL(L: TSecurityImpersonationLevel): BOOL;
--%% {$EXTERNALSYM VALID_IMPERSONATION_LEVEL}

--------------------------------------------------------------------
--                                                                --
--           Token Object Definitions                             --
--                                                                --
--                                                                --
--------------------------------------------------------------------

--
-- Token Specific Access Rights.
--

   Token_Assign_Primary    : constant := 16#0001#;
   Token_Duplicate         : constant := 16#0002#;
   Token_Impersonate       : constant := 16#0004#;
   Token_Query             : constant := 16#0008#;
   Token_Query_Source      : constant := 16#0010#;
   Token_Adjust_Privileges : constant := 16#0020#;
   Token_Adjust_Groups     : constant := 16#0040#;
   Token_Adjust_Default    : constant := 16#0080#;
   Token_Adjust_Sessionid  : constant := 16#0100#;

--%%   TOKEN_ALL_ACCESS_P = STANDARD_RIGHTS_REQUIRED or TOKEN_ASSIGN_PRIMARY or
--%%     TOKEN_DUPLICATE or TOKEN_IMPERSONATE or TOKEN_QUERY or TOKEN_QUERY_SOURCE or
--%%     TOKEN_ADJUST_PRIVILEGES or TOKEN_ADJUST_GROUPS or TOKEN_ADJUST_DEFAULT;
--%%   {$EXTERNALSYM TOKEN_ALL_ACCESS_P}

--%%   TOKEN_ALL_ACCESS = TOKEN_ALL_ACCESS_P or TOKEN_ADJUST_SESSIONID;
--%%   {$EXTERNALSYM TOKEN_ALL_ACCESS}

--%%   TOKEN_READ = STANDARD_RIGHTS_READ or TOKEN_QUERY;
--%%   {$EXTERNALSYM TOKEN_READ}

--%%   TOKEN_WRITE = (STANDARD_RIGHTS_WRITE or TOKEN_ADJUST_PRIVILEGES or
--%%     TOKEN_ADJUST_GROUPS or TOKEN_ADJUST_DEFAULT);
--%%   {$EXTERNALSYM TOKEN_WRITE}

   Token_Execute : constant := Standard_Rights_Execute;

--
-- Token Types
--

--%%   _TOKEN_TYPE = (TokenTypePad0, TokenPrimary, TokenImpersonation);
--%%   {$EXTERNALSYM _TOKEN_TYPE}
   subtype Token_Type_Type is _TOKEN_TYPE;
   type Token_Type_Ptr is access all _TOKEN_TYPE;
   type Token_Type_CPtr is access constant _TOKEN_TYPE;

--
-- Token Information Classes.
--

--%%   _TOKEN_INFORMATION_CLASS = (TokenInfoClassPad0, TokenUser, TokenGroups,
--%%     TokenPrivileges, TokenOwner, TokenPrimaryGroup, TokenDefaultDacl, TokenSource,
--%%     TokenType, TokenImpersonationLevel, TokenStatistics, TokenRestrictedSids,
--%%     TokenSessionId, TokenGroupsAndPrivileges, TokenSessionReference,
--%%     TokenSandBoxInert, TokenAuditPolicy, TokenOrigin,
--%%     MaxTokenInfoClass); {MaxTokenInfoClass should always be the last enum}
--%%   {$EXTERNALSYM _TOKEN_INFORMATION_CLASS}
   subtype Token_Information_Class_Type is _TOKEN_INFORMATION_CLASS;
   type Token_Information_Class_Ptr is access all _TOKEN_INFORMATION_CLASS;
   type Token_Information_Class_CPtr is access constant _TOKEN_INFORMATION_CLASS;

--
-- Token information class structures
--

   type Token_User_Type;
   type Token_User_Ptr is access all Token_User_Type;
   type Token_User_CPtr is access constant Token_User_Type;
   type Token_User_Type is record
      User : SID_And_Attributes_Type;
   end record;

--%%   PTOKEN_GROUPS = ^TOKEN_GROUPS;
--%%   {$EXTERNALSYM PTOKEN_GROUPS}
--%%   _TOKEN_GROUPS = record
--%%     GroupCount: DWORD;
--%%     Groups: array [0..ANYSIZE_ARRAY - 1] of SID_AND_ATTRIBUTES;
--%%   end;
--%%   {$EXTERNALSYM _TOKEN_GROUPS}
--%%   TOKEN_GROUPS = _TOKEN_GROUPS;
--%%   {$EXTERNALSYM TOKEN_GROUPS}
--%%   TTokenGroups = TOKEN_GROUPS;
--%%   PTokenGroups = PTOKEN_GROUPS;

--%%   PTOKEN_PRIVILEGES = ^TOKEN_PRIVILEGES;
--%%   {$EXTERNALSYM PTOKEN_PRIVILEGES}
--%%   _TOKEN_PRIVILEGES = record
--%%     PrivilegeCount: DWORD;
--%%     Privileges: array [0..ANYSIZE_ARRAY - 1] of LUID_AND_ATTRIBUTES;
--%%   end;
--%%   {$EXTERNALSYM _TOKEN_PRIVILEGES}
--%%   TOKEN_PRIVILEGES = _TOKEN_PRIVILEGES;
--%%   {$EXTERNALSYM TOKEN_PRIVILEGES}
--%%   TTokenPrivileges = TOKEN_PRIVILEGES;
--%%   PTokenPrivileges = PTOKEN_PRIVILEGES;

   type Token_Owner_Type;
   type Token_Owner_Ptr is access all Token_Owner_Type;
   type Token_Owner_CPtr is access constant Token_Owner_Type;
   type Token_Owner_Type is record
      Owner : SID_Ptr;
   end record;

   type Token_Primary_Group_Type;
   type Token_Primary_Group_Ptr is access all Token_Primary_Group_Type;
   type Token_Primary_Group_CPtr is access constant Token_Primary_Group_Type;
   type Token_Primary_Group_Type is record
      Primary_Group : SID_Ptr;
   end record;

   type Token_Default_DACL_Type;
   type Token_Default_DACL_Ptr is access all Token_Default_DACL_Type;
   type Token_Default_DACL_CPtr is access constant Token_Default_DACL_Type;
   type Token_Default_DACL_Type is record
      Default_DACL : ACL_Ptr;
   end record;

   type Token_Groups_And_Privileges_Type;
   type Token_Groups_And_Privileges_Ptr is access all Token_Groups_And_Privileges_Type;
   type Token_Groups_And_Privileges_CPtr is access constant Token_Groups_And_Privileges_Type;
   type Token_Groups_And_Privileges_Type is record
      SID_Count : Unsigned_32;
      SID_Length : Unsigned_32;
      SIDs : SID_And_Attributes_Ptr;
      Restricted_SID_Count : Unsigned_32;
      Restricted_SID_Length : Unsigned_32;
      Restricted_SIDs : SID_And_Attributes_Ptr;
      Privilege_Count : Unsigned_32;
      Privilege_Length : Unsigned_32;
      Privileges : LUID_And_Attributes_Ptr;
      Authentication_Id : LUID;
   end record;

--
-- Valid bits for each TOKEN_AUDIT_POLICY policy mask field.
--

   Token_Audit_Success_Include : constant := 16#1#;
   Token_Audit_Success_Exclude : constant := 16#2#;
   Token_Audit_Failure_Include : constant := 16#4#;
   Token_Audit_Failure_Exclude : constant := 16#8#;

--%%   VALID_AUDIT_POLICY_BITS = (TOKEN_AUDIT_SUCCESS_INCLUDE or
--%%                              TOKEN_AUDIT_SUCCESS_EXCLUDE or
--%%                              TOKEN_AUDIT_FAILURE_INCLUDE or
--%%                              TOKEN_AUDIT_FAILURE_EXCLUDE);
--%%   {$EXTERNALSYM VALID_AUDIT_POLICY_BITS}

   type Token_Audit_Policy_Element_Type;
   type Token_Audit_Policy_Element_Ptr is access all Token_Audit_Policy_Element_Type;
   type Token_Audit_Policy_Element_CPtr is access constant Token_Audit_Policy_Element_Type;
   type Token_Audit_Policy_Element_Type is record
      Category : Unsigned_32;
      Policy_Mask : Unsigned_32;
   end record;

-- TODO Implementation references AuditEventMaxType, which isn't defined anywhere
-- function VALID_TOKEN_AUDIT_POLICY_ELEMENT(P: TOKEN_AUDIT_POLICY_ELEMENT): BOOL;
-- {$EXTERNALSYM VALID_TOKEN_AUDIT_POLICY_ELEMENT}

--%%   _TOKEN_AUDIT_POLICY = record
--%%     PolicyCount: DWORD;
--%%     Policy: array [0..ANYSIZE_ARRAY - 1] of TOKEN_AUDIT_POLICY_ELEMENT;
--%%   end;
--%%   {$EXTERNALSYM _TOKEN_AUDIT_POLICY}
   subtype Token_Audit_Policy_Type is _TOKEN_AUDIT_POLICY;
   type Token_Audit_Policy_Ptr is access all _TOKEN_AUDIT_POLICY;
   type Token_Audit_Policy_CPtr is access constant _TOKEN_AUDIT_POLICY;

--%% function PER_USER_AUDITING_POLICY_SIZE(p: PTOKEN_AUDIT_POLICY): DWORD;
--%% {$EXTERNALSYM PER_USER_AUDITING_POLICY_SIZE}

--%% function PER_USER_AUDITING_POLICY_SIZE_BY_COUNT(C: DWORD): DWORD;
--%% {$EXTERNALSYM PER_USER_AUDITING_POLICY_SIZE_BY_COUNT}

   Token_Source_Length : constant := 8;

--%%   PTOKEN_SOURCE = ^TOKEN_SOURCE;
--%%   {$EXTERNALSYM PTOKEN_SOURCE}
--%%   _TOKEN_SOURCE = record
--%%     SourceName: array [0..TOKEN_SOURCE_LENGTH - 1] of CHAR;
--%%     SourceIdentifier: LUID;
--%%   end;
--%%   {$EXTERNALSYM _TOKEN_SOURCE}
--%%   TOKEN_SOURCE = _TOKEN_SOURCE;
--%%   {$EXTERNALSYM TOKEN_SOURCE}
--%%   TTokenSource = TOKEN_SOURCE;
--%%   PTokenSource = PTOKEN_SOURCE;

   type Token_Statistics_Type;
   type Token_Statistics_Ptr is access all Token_Statistics_Type;
   type Token_Statistics_CPtr is access constant Token_Statistics_Type;
   type Token_Statistics_Type is record
      Token_Id : LUID;
      Authentication_Id : LUID;
      Expiration_Time : LARGE_INTEGER;
      Token_Type : Token_Type_Type;
      Impersonation_Level : Security_Impersonation_Level_Type;
      Dynamic_Charged : Unsigned_32;
      Dynamic_Available : Unsigned_32;
      Group_Count : Unsigned_32;
      Privilege_Count : Unsigned_32;
      Modified_Id : LUID;
   end record;

   type Token_Control_Type;
   type Token_Control_Ptr is access all Token_Control_Type;
   type Token_Control_CPtr is access constant Token_Control_Type;
   type Token_Control_Type is record
      Token_Id : LUID;
      Authentication_Id : LUID;
      Modified_Id : LUID;
      Token_Source : OKEN_SOURCE_Type;
   end record;

   type Token_Origin_Type;
   type Token_Origin_Ptr is access all Token_Origin_Type;
   type Token_Origin_CPtr is access constant Token_Origin_Type;
   type Token_Origin_Type is record
      Originating_Logon_Session : LUID;
   end record;

--
-- Security Tracking Mode
--

   Security_Dynamic_Tracking : constant := True;
   Security_Static_Tracking  : constant := False;

--%%   SECURITY_CONTEXT_TRACKING_MODE = ByteBool;
--%%   {$EXTERNALSYM SECURITY_CONTEXT_TRACKING_MODE}
--%%   PSECURITY_CONTEXT_TRACKING_MODE = ^SECURITY_CONTEXT_TRACKING_MODE;
--%%   {$EXTERNALSYM PSECURITY_CONTEXT_TRACKING_MODE}

--
-- Quality Of Service
--

   type Security_Quality_Of_Service_Type;
   type Security_Quality_Of_Service_Ptr is access all Security_Quality_Of_Service_Type;
   type Security_Quality_Of_Service_CPtr is access constant Security_Quality_Of_Service_Type;
   type Security_Quality_Of_Service_Type is record
      Length : Unsigned_32;
      Impersonation_Level : Security_Impersonation_Level_Type;
      Context_Tracking_Mode : SECURITY_CONTEXT_TRACKING_MODE;
      Effective_Only : Byte_Bool;
   end record;

--
-- Used to represent information related to a thread impersonation
--

   type Se_Impersonation_State_Type;
   type Se_Impersonation_State_Ptr is access all Se_Impersonation_State_Type;
   type Se_Impersonation_State_CPtr is access constant Se_Impersonation_State_Type;
   type Se_Impersonation_State_Type is record
      Token : ACCESS_TOKEN_Ptr;
      Copy_On_Open : Byte_Bool;
      Effective_Only : Byte_Bool;
      Level : Security_Impersonation_Level_Type;
   end record;

   Disable_Max_Privilege : constant := 16#1#;
   Sandbox_Inert         : constant := 16#2#;

   subtype Security_Information_Type is Unsigned_32;
   subtype Security_Information_Ptr is Unsigned_32_Ptr;
   subtype Security_Information_CPtr is Unsigned_32_CPtr;

   Owner_Security_Information : constant := 16#0000_0001#;
   Group_Security_Information : constant := 16#0000_0002#;
   DACL_Security_Information  : constant := 16#0000_0004#;
   SACL_Security_Information  : constant := 16#0000_0008#;

   Protected_DACL_Security_Information   : constant := 16#8000_0000#;
   Protected_SACL_Security_Information   : constant := 16#4000_0000#;
   Unprotected_DACL_Security_Information : constant := 16#2000_0000#;
   Unprotected_SACL_Security_Information : constant := 16#1000_0000#;

   Process_Terminate         : constant := 16#0001#;
   Process_Create_Thread     : constant := 16#0002#;
   Process_Set_Sessionid     : constant := 16#0004#;
   Process_VM_Operation      : constant := 16#0008#;
   Process_VM_Read           : constant := 16#0010#;
   Process_VM_Write          : constant := 16#0020#;
   Process_Dup_Handle        : constant := 16#0040#;
   Process_Create_Process    : constant := 16#0080#;
   Process_Set_Quota         : constant := 16#0100#;
   Process_Set_Information   : constant := 16#0200#;
   Process_Query_Information : constant := 16#0400#;
   Process_Suspend_Resume    : constant := 16#0800#;
--%%   PROCESS_ALL_ACCESS        = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $FFF;
--%%   {$EXTERNALSYM PROCESS_ALL_ACCESS}

   Maximum_Processors : constant := 32;

   Thread_Terminate            : constant := 16#0001#;
   Thread_Suspend_Resume       : constant := 16#0002#;
   Thread_Get_Context          : constant := 16#0008#;
   Thread_Set_Context          : constant := 16#0010#;
   Thread_Set_Information      : constant := 16#0020#;
   Thread_Query_Information    : constant := 16#0040#;
   Thread_Set_Thread_Token     : constant := 16#0080#;
   Thread_Impersonate          : constant := 16#0100#;
   Thread_Direct_Impersonation : constant := 16#0200#;

--%%   THREAD_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $3FF;
--%%   {$EXTERNALSYM THREAD_ALL_ACCESS}

   Job_Object_Assign_Process          : constant := 16#0001#;
   Job_Object_Set_Attributes          : constant := 16#0002#;
   Job_Object_Query                   : constant := 16#0004#;
   Job_Object_Terminate               : constant := 16#0008#;
   Job_Object_Set_Security_Attributes : constant := 16#0010#;
--%%   JOB_OBJECT_ALL_ACCESS              = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $1F ;
--%%   {$EXTERNALSYM JOB_OBJECT_ALL_ACCESS}

   type Job_Set_Array_Type;
   type Job_Set_Array_Ptr is access all Job_Set_Array_Type;
   type Job_Set_Array_CPtr is access constant Job_Set_Array_Type;
   type Job_Set_Array_Type is record
      Job_Handle : Handle_Type;  -- Handle to job object to insert
      Member_Level : Unsigned_32; -- Level of this job in the set. Must be > 0. Can be sparse.
      Flags : Unsigned_32;       -- Unused. Must be zero
   end record;

   Fls_Maximum_Available : constant := 128;
   Tls_Minimum_Available : constant := 64;

--%%   PEXCEPTION_REGISTRATION_RECORD = ^EXCEPTION_REGISTRATION_RECORD;
--%%   _EXCEPTION_REGISTRATION_RECORD = packed record
--%%     pNext: PEXCEPTION_REGISTRATION_RECORD;
--%%     pfnHandler: FARPROC;
--%%   end;
--%%   EXCEPTION_REGISTRATION_RECORD = _EXCEPTION_REGISTRATION_RECORD;
--%%   TExceptionRegistrationRecord = EXCEPTION_REGISTRATION_RECORD;
--%%   PExceptionRegistrationRecord = PEXCEPTION_REGISTRATION_RECORD;

--%%   PNT_TIB = ^NT_TIB;
--%%   {$EXTERNALSYM PNT_TIB}
--%%   _NT_TIB = record
--%%     ExceptionList: PEXCEPTION_REGISTRATION_RECORD; // 00h Head of exception record list
--%%     StackBase: PVOID;     // 04h Top of user stack
--%%     StackLimit: PVOID;    // 08h Base of user stack

--%%     //union                       // 0Ch (NT/Win95 differences)
--%%     //{
--%%     //    struct  // Win95 fields
--%%     //    {
--%%     //        WORD    pvTDB;         // 0Ch TDB
--%%     //        WORD    pvThunkSS;     // 0Eh SS selector used for thunking to 16 bits
--%%     //        DWORD   unknown1;      // 10h
--%%     //    } WIN95;
--%%     //
--%%     //    struct  // WinNT fields
--%%     //    {

--%%     SubSystemTib: PVOID;     // 0Ch

--%%     Union: record             // 10H
--%%     case Integer of
--%%       0: (FiberData: PVOID);
--%%       1: (Version: DWORD);
--%%     end;

--%%     //    } WINNT;
--%%     //} TIB_UNION1;

--%%     ArbitraryUserPointer: PVOID;      // 14h Available for application use
--%%     Self: PNT_TIB;          // 18h Linear address of TIB structure

--%%     //union                       // 1Ch (NT/Win95 differences)
--%%     //{
--%%     //    struct  // Win95 fields
--%%     //    {
--%%     //        WORD    TIBFlags;           // 1Ch
--%%     //        WORD    Win16MutexCount;    // 1Eh
--%%     //        DWORD   DebugContext;       // 20h
--%%     //        DWORD   pCurrentPriority;   // 24h
--%%     //        DWORD   pvQueue;            // 28h Message Queue selector
--%%     //    } WIN95;
--%%     //
--%%     //    struct  // WinNT fields
--%%     //    {

--%%     unknown1: DWORD;             // 1Ch
--%%     processID: DWORD;            // 20h
--%%     threadID: DWORD;             // 24h
--%%     unknown2: DWORD;             // 28h

--%%     //    } WINNT;
--%%     //} TIB_UNION2;

--%%     pvTLSArray: PVOID;          // (PPVOID!) 2Ch Thread Local Storage array

--%%     //union                      // 30h (NT/Win95 differences)
--%%     //{
--%%     //    struct  // Win95 fields
--%%     //    {
--%%     //        PVOID*  pProcess;  // 30h Pointer to owning process database
--%%     //    } WIN95;
--%%     //} TIB_UNION3;
--%%   end;
--%%   {$EXTERNALSYM _NT_TIB}
--%%   NT_TIB = _NT_TIB;
--%%   {$EXTERNALSYM NT_TIB}
--%%   TNtTib = NT_TIB;
--%%   PNtTib = ^TNtTib;

--
-- 32 and 64 bit specific version for wow64 and the debugger
--

--%%   PNT_TIB32 = ^NT_TIB32;
--%%   {$EXTERNALSYM PNT_TIB32}
--%%   _NT_TIB32 = record
--%%     ExceptionList: DWORD;
--%%     StackBase: DWORD;
--%%     StackLimit: DWORD;
--%%     SubSystemTib: DWORD;
--%%     Union: record
--%%     case Integer of
--%%       0: (FiberData: DWORD);
--%%       1: (Version: DWORD);
--%%     end;
--%%     ArbitraryUserPointer: DWORD;
--%%     Self: DWORD;
--%%   end;
--%%   {$EXTERNALSYM _NT_TIB32}
--%%   NT_TIB32 = _NT_TIB32;
--%%   {$EXTERNALSYM NT_TIB32}
--%%   TNtTib32 = NT_TIB32;
--%%   PNtTib32 = ^TNtTib32;

--%%   PNT_TIB64 = ^NT_TIB64;
--%%   {$EXTERNALSYM PNT_TIB64}
--%%   _NT_TIB64 = record
--%%     ExceptionList: DWORD64;
--%%     StackBase: DWORD64;
--%%     StackLimit: DWORD64;
--%%     SubSystemTib: DWORD64;
--%%     Union: record
--%%     case Integer of
--%%       0: (FiberData: DWORD64);
--%%       1: (Version: DWORD);
--%%     end;
--%%     ArbitraryUserPointer: DWORD64;
--%%     Self: DWORD64;
--%%   end;
--%%   {$EXTERNALSYM _NT_TIB64}
--%%   NT_TIB64 = _NT_TIB64;
--%%   {$EXTERNALSYM NT_TIB64}
--%%   TNtTib64 = NT_TIB64;
--%%   PNtTib64 = ^TNtTib64;

--
-- Define function to return the current Thread Environment Block
--

--%% {$IFNDEF JWA_INCLUDEMODE}
--%% function NtCurrentTeb: PNT_TIB;
--%% {$EXTERNALSYM NtCurrentTeb}
--%% {$ENDIF JWA_INCLUDEMODE}

   Thread_Base_Priority_Lowrt : constant := 15;         -- value that gets a thread to LowRealtime-1
   Thread_Base_Priority_Max   : constant := 2;          -- maximum thread base priority boost
--%%   THREAD_BASE_PRIORITY_MIN   = DWORD(-2);  // minimum thread base priority boost
--%%   {$EXTERNALSYM THREAD_BASE_PRIORITY_MIN}
--%%   THREAD_BASE_PRIORITY_IDLE  = DWORD(-15); // value that gets a thread to idle
--%%   {$EXTERNALSYM THREAD_BASE_PRIORITY_IDLE}

   type Quota_Limits_Type;
   type Quota_Limits_Ptr is access all Quota_Limits_Type;
   type Quota_Limits_CPtr is access constant Quota_Limits_Type;
   type Quota_Limits_Type is record
      Paged_Pool_Limit : SIZE_T;
      Non_Paged_Pool_Limit : SIZE_T;
      Minimum_Working_Set_Size : SIZE_T;
      Maximum_Working_Set_Size : SIZE_T;
      Pagefile_Limit : SIZE_T;
      Time_Limit : LARGE_INTEGER;
   end record;

   Quota_Limits_Hardws_Min_Enable  : constant := 16#0000_0001#;
   Quota_Limits_Hardws_Min_Disable : constant := 16#0000_0002#;
   Quota_Limits_Hardws_Max_Enable  : constant := 16#0000_0004#;
   Quota_Limits_Hardws_Max_Disable : constant := 16#0000_0008#;

   type Quota_Limits_Ex_Type;
   type Quota_Limits_Ex_Ptr is access all Quota_Limits_Ex_Type;
   type Quota_Limits_Ex_CPtr is access constant Quota_Limits_Ex_Type;
   type Quota_Limits_Ex_Type is record
      Paged_Pool_Limit : SIZE_T;
      Non_Paged_Pool_Limit : SIZE_T;
      Minimum_Working_Set_Size : SIZE_T;
      Maximum_Working_Set_Size : SIZE_T;
      Pagefile_Limit : SIZE_T;
      Time_Limit : LARGE_INTEGER;
      Reserved1 : SIZE_T;
      Reserved2 : SIZE_T;
      Reserved3 : SIZE_T;
      Reserved4 : SIZE_T;
      Flags : Unsigned_32;
      Reserved5 : Unsigned_32;
   end record;

   type IO_Counters_Type;
   type IO_Counters_Ptr is access all IO_Counters_Type;
   type IO_Counters_CPtr is access constant IO_Counters_Type;
   type IO_Counters_Type is record
      Read_Operation_Count : Int64;
      Write_Operation_Count : Int64;
      Other_Operation_Count : Int64;
      Read_Transfer_Count : Int64;
      Write_Transfer_Count : Int64;
      Other_Transfer_Count : Int64;
   end record;

   type Job_Object_Basic_Accounting_Information_Type;
   type Job_Object_Basic_Accounting_Information_Ptr is access all Job_Object_Basic_Accounting_Information_Type;
   type Job_Object_Basic_Accounting_Information_CPtr is access constant Job_Object_Basic_Accounting_Information_Type;
   type Job_Object_Basic_Accounting_Information_Type is record
      Total_User_Time : LARGE_INTEGER;
      Total_Kernel_Time : LARGE_INTEGER;
      This_Period_Total_User_Time : LARGE_INTEGER;
      This_Period_Total_Kernel_Time : LARGE_INTEGER;
      Total_Page_Fault_Count : Unsigned_32;
      Total_Processes : Unsigned_32;
      Active_Processes : Unsigned_32;
      Total_Terminated_Processes : Unsigned_32;
   end record;

   type Job_Object_Basic_Limit_Information_Type;
   type Job_Object_Basic_Limit_Information_Ptr is access all Job_Object_Basic_Limit_Information_Type;
   type Job_Object_Basic_Limit_Information_CPtr is access constant Job_Object_Basic_Limit_Information_Type;
   type Job_Object_Basic_Limit_Information_Type is record
      Per_Process_User_Time_Limit : LARGE_INTEGER;
      Per_Job_User_Time_Limit : LARGE_INTEGER;
      Limit_Flags : Unsigned_32;
      Minimum_Working_Set_Size : SIZE_T;
      Maximum_Working_Set_Size : SIZE_T;
      Active_Process_Limit : Unsigned_32;
      Affinity : ULONG_PTR;
      Priority_Class : Unsigned_32;
      Scheduling_Class : Unsigned_32;
   end record;

   type Job_Object_Extended_Limit_Information_Type;
   type Job_Object_Extended_Limit_Information_Ptr is access all Job_Object_Extended_Limit_Information_Type;
   type Job_Object_Extended_Limit_Information_CPtr is access constant Job_Object_Extended_Limit_Information_Type;
   type Job_Object_Extended_Limit_Information_Type is record
      Basic_Limit_Information : Job_Object_Basic_Limit_Information_Type;
      IO_Info : IO_Counters_Type;
      Process_Memory_Limit : SIZE_T;
      Job_Memory_Limit : SIZE_T;
      Peak_Process_Memory_Used : SIZE_T;
      Peak_Job_Memory_Used : SIZE_T;
   end record;

--%%   PJOBOBJECT_BASIC_PROCESS_ID_LIST = ^JOBOBJECT_BASIC_PROCESS_ID_LIST;
--%%   {$EXTERNALSYM PJOBOBJECT_BASIC_PROCESS_ID_LIST}
--%%   _JOBOBJECT_BASIC_PROCESS_ID_LIST = record
--%%     NumberOfAssignedProcesses: DWORD;
--%%     NumberOfProcessIdsInList: DWORD;
--%%     ProcessIdList: array [0..0] of ULONG_PTR;
--%%   end;
--%%   {$EXTERNALSYM _JOBOBJECT_BASIC_PROCESS_ID_LIST}
--%%   JOBOBJECT_BASIC_PROCESS_ID_LIST = _JOBOBJECT_BASIC_PROCESS_ID_LIST;
--%%   {$EXTERNALSYM JOBOBJECT_BASIC_PROCESS_ID_LIST}
--%%   TJobObjectBasicProcessIdList = JOBOBJECT_BASIC_PROCESS_ID_LIST;
--%%   PJobObjectBasicProcessIdList = PJOBOBJECT_BASIC_PROCESS_ID_LIST;

   type Job_Object_Basic_UI_Restrictions_Type;
   type Job_Object_Basic_UI_Restrictions_Ptr is access all Job_Object_Basic_UI_Restrictions_Type;
   type Job_Object_Basic_UI_Restrictions_CPtr is access constant Job_Object_Basic_UI_Restrictions_Type;
   type Job_Object_Basic_UI_Restrictions_Type is record
      UI_Restrictions_Class : Unsigned_32;
   end record;

   type Job_Object_Security_Limit_Information_Type;
   type Job_Object_Security_Limit_Information_Ptr is access all Job_Object_Security_Limit_Information_Type;
   type Job_Object_Security_Limit_Information_CPtr is access constant Job_Object_Security_Limit_Information_Type;
   type Job_Object_Security_Limit_Information_Type is record
      Security_Limit_Flags : Unsigned_32;
      Job_Token : Handle_Type;
      SIDs_To_Disable : TOKEN_GROUPS_Ptr;
      Privileges_To_Delete : TOKEN_PRIVILEGES_Ptr;
      Restricted_SIDs : TOKEN_GROUPS_Ptr;
   end record;

   type Job_Object_End_Of_Job_Time_Information_Type;
   type Job_Object_End_Of_Job_Time_Information_Ptr is access all Job_Object_End_Of_Job_Time_Information_Type;
   type Job_Object_End_Of_Job_Time_Information_CPtr is access constant Job_Object_End_Of_Job_Time_Information_Type;
   type Job_Object_End_Of_Job_Time_Information_Type is record
      End_Of_Job_Time_Action : Unsigned_32;
   end record;

   type Job_Object_Associate_Completion_Port_Type;
   type Job_Object_Associate_Completion_Port_Ptr is access all Job_Object_Associate_Completion_Port_Type;
   type Job_Object_Associate_Completion_Port_CPtr is access constant Job_Object_Associate_Completion_Port_Type;
   type Job_Object_Associate_Completion_Port_Type is record
      Completion_Key : Ointer_Ptr;
      Completion_Port : Handle_Type;
   end record;

   type Job_Object_Basic_And_IO_Accounting_Information_Type;
   type Job_Object_Basic_And_IO_Accounting_Information_Ptr is access all Job_Object_Basic_And_IO_Accounting_Information_Type;
   type Job_Object_Basic_And_IO_Accounting_Information_CPtr is access constant Job_Object_Basic_And_IO_Accounting_Information_Type;
   type Job_Object_Basic_And_IO_Accounting_Information_Type is record
      Basic_Info : Job_Object_Basic_Accounting_Information_Type;
      IO_Info : IO_Counters_Type;
   end record;

   type Job_Object_Set_Information_Type;
   type Job_Object_Set_Information_Ptr is access all Job_Object_Set_Information_Type;
   type Job_Object_Set_Information_CPtr is access constant Job_Object_Set_Information_Type;
   type Job_Object_Set_Information_Type is record
      Member_Level : Unsigned_32;
   end record;

   Job_Object_Terminate_At_End_Of_Job : constant := 0;
   Job_Object_Post_At_End_Of_Job      : constant := 1;

--
-- Completion Port Messages for job objects
--
-- These values are returned via the lpNumberOfBytesTransferred parameter
--

   Job_Object_Msg_End_Of_Job_Time       : constant := 1;
   Job_Object_Msg_End_Of_Process_Time   : constant := 2;
   Job_Object_Msg_Active_Process_Limit  : constant := 3;
   Job_Object_Msg_Active_Process_Zero   : constant := 4;
   Job_Object_Msg_New_Process           : constant := 6;
   Job_Object_Msg_Exit_Process          : constant := 7;
   Job_Object_Msg_Abnormal_Exit_Process : constant := 8;
   Job_Object_Msg_Process_Memory_Limit  : constant := 9;
   Job_Object_Msg_Job_Memory_Limit      : constant := 10;

--
-- Basic Limits
--

   Job_Object_Limit_Workingset        : constant := 16#0000_0001#;
   Job_Object_Limit_Process_Time      : constant := 16#0000_0002#;
   Job_Object_Limit_Job_Time          : constant := 16#0000_0004#;
   Job_Object_Limit_Active_Process    : constant := 16#0000_0008#;
   Job_Object_Limit_Affinity          : constant := 16#0000_0010#;
   Job_Object_Limit_Priority_Class    : constant := 16#0000_0020#;
   Job_Object_Limit_Preserve_Job_Time : constant := 16#0000_0040#;
   Job_Object_Limit_Scheduling_Class  : constant := 16#0000_0080#;

--
-- Extended Limits
--

   Job_Object_Limit_Process_Memory             : constant := 16#0000_0100#;
   Job_Object_Limit_Job_Memory                 : constant := 16#0000_0200#;
   Job_Object_Limit_Die_On_Unhandled_Exception : constant := 16#0000_0400#;
   Job_Object_Limit_Breakaway_Ok               : constant := 16#0000_0800#;
   Job_Object_Limit_Silent_Breakaway_Ok        : constant := 16#0000_1000#;
   Job_Object_Limit_Kill_On_Job_Close          : constant := 16#0000_2000#;

   Job_Object_Limit_Reserved2 : constant := 16#0000_4000#;
   Job_Object_Limit_Reserved3 : constant := 16#0000_8000#;
   Job_Object_Limit_Reserved4 : constant := 16#0001_0000#;
   Job_Object_Limit_Reserved5 : constant := 16#0002_0000#;
   Job_Object_Limit_Reserved6 : constant := 16#0004_0000#;

   Job_Object_Limit_Valid_Flags : constant := 16#0007_FFFF#;

   Job_Object_Basic_Limit_Valid_Flags    : constant := 16#0000_00FF#;
   Job_Object_Extended_Limit_Valid_Flags : constant := 16#0000_3FFF#;
   Job_Object_Reserved_Limit_Valid_Flags : constant := 16#0007_FFFF#;

--
-- UI restrictions for jobs
--

   Job_Object_Uilimit_None : constant := 16#0000_0000#;

   Job_Object_Uilimit_Handles          : constant := 16#0000_0001#;
   Job_Object_Uilimit_Readclipboard    : constant := 16#0000_0002#;
   Job_Object_Uilimit_Writeclipboard   : constant := 16#0000_0004#;
   Job_Object_Uilimit_Systemparameters : constant := 16#0000_0008#;
   Job_Object_Uilimit_Displaysettings  : constant := 16#0000_0010#;
   Job_Object_Uilimit_Globalatoms      : constant := 16#0000_0020#;
   Job_Object_Uilimit_Desktop          : constant := 16#0000_0040#;
   Job_Object_Uilimit_Exitwindows      : constant := 16#0000_0080#;

   Job_Object_Uilimit_All : constant := 16#0000_00FF#;

   Job_Object_UI_Valid_Flags : constant := 16#0000_00FF#;

   Job_Object_Security_No_Admin         : constant := 16#0000_0001#;
   Job_Object_Security_Restricted_Token : constant := 16#0000_0002#;
   Job_Object_Security_Only_Token       : constant := 16#0000_0004#;
   Job_Object_Security_Filter_Tokens    : constant := 16#0000_0008#;

   Job_Object_Security_Valid_Flags : constant := 16#0000_000F#;

--%%   _JOBOBJECTINFOCLASS = (
--%%     JobObjectInfoClassPadding0,
--%%     JobObjectBasicAccountingInformation,
--%%     JobObjectBasicLimitInformation,
--%%     JobObjectBasicProcessIdList,
--%%     JobObjectBasicUIRestrictions,
--%%     JobObjectSecurityLimitInformation,
--%%     JobObjectEndOfJobTimeInformation,
--%%     JobObjectAssociateCompletionPortInformation,
--%%     JobObjectBasicAndIoAccountingInformation,
--%%     JobObjectExtendedLimitInformation,
--%%     JobObjectJobSetInformation,
--%%     MaxJobObjectInfoClass);
--%%   {$EXTERNALSYM _JOBOBJECTINFOCLASS}
--%%   JOBOBJECTINFOCLASS = _JOBOBJECTINFOCLASS;
--%%   {$EXTERNALSYM JOBOBJECTINFOCLASS}
--%%   TJobObjectInfoClass = JOBOBJECTINFOCLASS;

   Event_Modify_State : constant := 16#0002#;
--%%   EVENT_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $3;
--%%   {$EXTERNALSYM EVENT_ALL_ACCESS}
   Mutant_Query_State : constant := 16#0001#;

--%%   MUTANT_ALL_ACCESS      = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or MUTANT_QUERY_STATE;
--%%   {$EXTERNALSYM MUTANT_ALL_ACCESS}
   Semaphore_Modify_State : constant := 16#0002#;
--%%   SEMAPHORE_ALL_ACCESS   = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $3;
--%%   {$EXTERNALSYM SEMAPHORE_ALL_ACCESS}

--
-- Timer Specific Access Rights.
--

   Timer_Query_State  : constant := 16#0001#;
   Timer_Modify_State : constant := 16#0002#;

--%%   TIMER_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or TIMER_QUERY_STATE or TIMER_MODIFY_STATE;
--%%   {$EXTERNALSYM TIMER_ALL_ACCESS}

   Time_Zone_Id_Unknown  : constant := 0;
   Time_Zone_Id_Standard : constant := 1;
   Time_Zone_Id_Daylight : constant := 2;

--%%   _LOGICAL_PROCESSOR_RELATIONSHIP = (RelationProcessorCore, RelationNumaNode);
--%%   {$EXTERNALSYM _LOGICAL_PROCESSOR_RELATIONSHIP}
--%%   LOGICAL_PROCESSOR_RELATIONSHIP = _LOGICAL_PROCESSOR_RELATIONSHIP;
--%%   {$EXTERNALSYM LOGICAL_PROCESSOR_RELATIONSHIP}
--%%   TLogicalProcessorRelationship = LOGICAL_PROCESSOR_RELATIONSHIP;

   Ltp_Pc_Smt : constant := 16#1#;

--%%   _SYSTEM_LOGICAL_PROCESSOR_INFORMATION = record
--%%     ProcessorMask: ULONG_PTR;
--%%     Relationship: LOGICAL_PROCESSOR_RELATIONSHIP;
--%%     case Integer of
--%%       0: (Flags: BYTE); // ProcessorCore
--%%       1: (NodeNumber: DWORD); // NumaNode
--%%       2: (Reserved: array [0..1] of ULONGLONG);
--%%   end;
--%%   {$EXTERNALSYM _SYSTEM_LOGICAL_PROCESSOR_INFORMATION}
--%%   SYSTEM_LOGICAL_PROCESSOR_INFORMATION = _SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
--%%   {$EXTERNALSYM SYSTEM_LOGICAL_PROCESSOR_INFORMATION}
--%%   PSYSTEM_LOGICAL_PROCESSOR_INFORMATION = ^SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
--%%   TSystemLogicalProcessorInformation = SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
--%%   PSystemLogicalProcessorInformation = PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;  

   Processor_Intel_386     : constant := 386;
   Processor_Intel_486     : constant := 486;
   Processor_Intel_Pentium : constant := 586;
   Processor_Intel_IA64    : constant := 2200;
   Processor_AMD_X8664     : constant := 8664;
   Processor_MIPS_R4000    : constant := 4000; -- incl R4101 & R3910 for Windows CE
   Processor_Alpha_21064   : constant := 21064;
   Processor_PPC_601       : constant := 601;
   Processor_PPC_603       : constant := 603;
   Processor_PPC_604       : constant := 604;
   Processor_PPC_620       : constant := 620;
   Processor_Hitachi_Sh3   : constant := 10003; -- Windows CE
   Processor_Hitachi_Sh3E  : constant := 10004; -- Windows CE
   Processor_Hitachi_Sh4   : constant := 10005; -- Windows CE
   Processor_Motorola_821  : constant := 821; -- Windows CE
   Processor_Shx_Sh3       : constant := 103; -- Windows CE
   Processor_Shx_Sh4       : constant := 104; -- Windows CE
   Processor_StrongARM     : constant := 2577; -- Windows CE - 0xA11
   Processor_ARM720        : constant := 1824; -- Windows CE - 0x720
   Processor_ARM820        : constant := 2080; -- Windows CE - 0x820
   Processor_ARM920        : constant := 2336; -- Windows CE - 0x920
   Processor_ARM_7Tdmi     : constant := 70001; -- Windows CE
   Processor_Optil         : constant := 16#494F#; -- MSIL

   Processor_Architecture_Intel   : constant := 0;
   Processor_Architecture_MIPS    : constant := 1;
   Processor_Architecture_Alpha   : constant := 2;
   Processor_Architecture_PPC     : constant := 3;
   Processor_Architecture_Shx     : constant := 4;
   Processor_Architecture_ARM     : constant := 5;
   Processor_Architecture_IA64    : constant := 6;
   Processor_Architecture_Alpha64 : constant := 7;
   Processor_Architecture_MSIL    : constant := 8;
   Processor_Architecture_AMD64         : constant := 9;
   Processor_Architecture_IA32_On_Win64 : constant := 10;

   Processor_Architecture_Unknown : constant := 16#FFFF#;

   Pf_Floating_Point_Precision_Errata : constant := 0;
   Pf_Floating_Point_Emulated         : constant := 1;
   Pf_Compare_Exchange_Double         : constant := 2;
   Pf_MMX_Instructions_Available      : constant := 3;
   Pf_PPC_Movemem_64Bit_Ok            : constant := 4;
   Pf_Alpha_Byte_Instructions         : constant := 5;
   Pf_XMMI_Instructions_Available     : constant := 6;
   Pf_3Dnow_Instructions_Available    : constant := 7;
   Pf_RDTSC_Instruction_Available     : constant := 8;
   Pf_PAE_Enabled                     : constant := 9;
   Pf_XMMI64_Instructions_Available   : constant := 10;

   type Memory_Basic_Information_Type;
   type Memory_Basic_Information_Ptr is access all Memory_Basic_Information_Type;
   type Memory_Basic_Information_CPtr is access constant Memory_Basic_Information_Type;
   type Memory_Basic_Information_Type is record
      Base_Address : Ointer_Ptr;
      Allocation_Base : Ointer_Ptr;
      Allocation_Protect : Unsigned_32;
      Region_Size : SIZE_T;
      State : Unsigned_32;
      Protect : Unsigned_32;
      Type_ : Unsigned_32;
   end record;

   type Memory_Basic_Information32_Type;
   type Memory_Basic_Information32_Ptr is access all Memory_Basic_Information32_Type;
   type Memory_Basic_Information32_CPtr is access constant Memory_Basic_Information32_Type;
   type Memory_Basic_Information32_Type is record
      Base_Address : Unsigned_32;
      Allocation_Base : Unsigned_32;
      Allocation_Protect : Unsigned_32;
      Region_Size : Unsigned_32;
      State : Unsigned_32;
      Protect : Unsigned_32;
      Type_ : Unsigned_32;
   end record;

   type Memory_Basic_Information64_Type;
   type Memory_Basic_Information64_Ptr is access all Memory_Basic_Information64_Type;
   type Memory_Basic_Information64_CPtr is access constant Memory_Basic_Information64_Type;
   type Memory_Basic_Information64_Type is record
      Base_Address : Unsigned_64;
      Allocation_Base : Unsigned_64;
      Allocation_Protect : Unsigned_32;
      __Alignment1 : Unsigned_32;
      Region_Size : Unsigned_64;
      State : Unsigned_32;
      Protect : Unsigned_32;
      Type_ : Unsigned_32;
      __Alignment2 : Unsigned_32;
   end record;

   Section_Query       : constant := 16#0001#;
   Section_Map_Write   : constant := 16#0002#;
   Section_Map_Read    : constant := 16#0004#;
   Section_Map_Execute : constant := 16#0008#;
   Section_Extend_Size : constant := 16#0010#;

--%%   SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or SECTION_QUERY or
--%%     SECTION_MAP_WRITE or SECTION_MAP_READ or SECTION_MAP_EXECUTE or
--%%     SECTION_EXTEND_SIZE);
--%%   {$EXTERNALSYM SECTION_ALL_ACCESS}

   Page_NoAccess          : constant := 16#01#;
   Page_ReadOnly          : constant := 16#02#;
   Page_ReadWrite         : constant := 16#04#;
   Page_WriteCopy         : constant := 16#08#;
   Page_Execute           : constant := 16#10#;
   Page_Execute_Read      : constant := 16#20#;
   Page_Execute_ReadWrite : constant := 16#40#;
   Page_Execute_WriteCopy : constant := 16#80#;
   Page_Guard             : constant := 16#100#;
   Page_NoCache           : constant := 16#200#;
   Page_Writecombine      : constant := 16#400#;
   Mem_Commit             : constant := 16#1000#;
   Mem_Reserve            : constant := 16#2000#;
   Mem_Decommit           : constant := 16#4000#;
   Mem_Release            : constant := 16#8000#;
   Mem_Free               : constant := 16#10000#;
   Mem_Private            : constant := 16#20000#;
   Mem_Mapped             : constant := 16#40000#;
   Mem_Reset              : constant := 16#80000#;
   Mem_Top_Down           : constant := 16#100000#;
   Mem_Write_Watch        : constant := 16#200000#;
   Mem_Physical           : constant := 16#400000#;
   Mem_Large_Pages        : constant := 16#2000_0000#;
   Mem_4Mb_Pages          : constant := 16#8000_0000#;
   Sec_File               : constant := 16#800000#;
   Sec_Image              : constant := 16#1000000#;
   Sec_Reserve            : constant := 16#4000000#;
   Sec_Commit             : constant := 16#8000000#;
   Sec_NoCache            : constant := 16#1000_0000#;
   Mem_Image              : constant := Sec_Image;
   Write_Watch_Flag_Reset : constant := 16#01#;

--
-- Define access rights to files and directories
--

--
-- The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
-- devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
-- constants *MUST* always be in sync.
-- The values are redefined in devioctl.h because they must be available to
-- both DOS and NT.
--

   File_Read_Data            : constant := 16#0001#; -- file & pipe
   File_List_Directory       : constant := 16#0001#; -- directory

   File_Write_Data           : constant := 16#0002#; -- file & pipe
   File_Add_File             : constant := 16#0002#; -- directory

   File_Append_Data          : constant := 16#0004#; -- file
   File_Add_Subdirectory     : constant := 16#0004#; -- directory
   File_Create_Pipe_Instance : constant := 16#0004#; -- named pipe

   File_Read_Ea : constant := 16#0008#; -- file & directory

   File_Write_Ea : constant := 16#0010#; -- file & directory

   File_Execute : constant := 16#0020#; -- file
   File_Traverse : constant := 16#0020#; -- directory

   File_Delete_Child : constant := 16#0040#; -- directory

   File_Read_Attributes : constant := 16#0080#; -- all

   File_Write_Attributes : constant := 16#0100#; -- all

--%%   FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $1FF;
--%%   {$EXTERNALSYM FILE_ALL_ACCESS}

--%%   FILE_GENERIC_READ = (STANDARD_RIGHTS_READ or FILE_READ_DATA or
--%%     FILE_READ_ATTRIBUTES or FILE_READ_EA or SYNCHRONIZE);
--%%   {$EXTERNALSYM FILE_GENERIC_READ}

--%%   FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE or FILE_WRITE_DATA or
--%%     FILE_WRITE_ATTRIBUTES or FILE_WRITE_EA or FILE_APPEND_DATA or SYNCHRONIZE);
--%%   {$EXTERNALSYM FILE_GENERIC_WRITE}

--%%   FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE or FILE_READ_ATTRIBUTES or
--%%     FILE_EXECUTE or SYNCHRONIZE);
--%%   {$EXTERNALSYM FILE_GENERIC_EXECUTE}

   File_Share_Read                    : constant := 16#0000_0001#;
   File_Share_Write                   : constant := 16#0000_0002#;
   File_Share_Delete                  : constant := 16#0000_0004#;
   File_Attribute_ReadOnly            : constant := 16#0000_0001#;
   File_Attribute_Hidden              : constant := 16#0000_0002#;
   File_Attribute_System              : constant := 16#0000_0004#;
   File_Attribute_Directory           : constant := 16#0000_0010#;
   File_Attribute_Archive             : constant := 16#0000_0020#;
   File_Attribute_Device              : constant := 16#0000_0040#;
   File_Attribute_Normal              : constant := 16#0000_0080#;
   File_Attribute_Temporary           : constant := 16#0000_0100#;
   File_Attribute_Sparse_File         : constant := 16#0000_0200#;
   File_Attribute_Reparse_Point       : constant := 16#0000_0400#;
   File_Attribute_Compressed          : constant := 16#0000_0800#;
   File_Attribute_Offline             : constant := 16#0000_1000#;
   File_Attribute_Not_Content_Indexed : constant := 16#0000_2000#;
   File_Attribute_Encrypted           : constant := 16#0000_4000#;
   File_Notify_Change_File_Name       : constant := 16#0000_0001#;
   File_Notify_Change_Dir_Name        : constant := 16#0000_0002#;
   File_Notify_Change_Attributes      : constant := 16#0000_0004#;
   File_Notify_Change_Size            : constant := 16#0000_0008#;
   File_Notify_Change_Last_Write      : constant := 16#0000_0010#;
   File_Notify_Change_Last_Access     : constant := 16#0000_0020#;
   File_Notify_Change_Creation        : constant := 16#0000_0040#;
   File_Notify_Change_Security        : constant := 16#0000_0100#;
   File_Action_Added                  : constant := 16#0000_0001#;
   File_Action_Removed                : constant := 16#0000_0002#;
   File_Action_Modified               : constant := 16#0000_0003#;
   File_Action_Renamed_Old_Name       : constant := 16#0000_0004#;
   File_Action_Renamed_New_Name       : constant := 16#0000_0005#;
   Mailslot_No_Message                : constant := 16#FFFF_FFFF#;
   Mailslot_Wait_Forever              : constant := 16#FFFF_FFFF#;
   File_Case_Sensitive_Search         : constant := 16#0000_0001#;
   File_Case_Preserved_Names          : constant := 16#0000_0002#;
   File_Unicode_On_Disk               : constant := 16#0000_0004#;
   File_Persistent_Acls               : constant := 16#0000_0008#;
   File_File_Compression              : constant := 16#0000_0010#;
   File_Volume_Quotas                 : constant := 16#0000_0020#;
   File_Supports_Sparse_Files         : constant := 16#0000_0040#;
   File_Supports_Reparse_Points       : constant := 16#0000_0080#;
   File_Supports_Remote_Storage       : constant := 16#0000_0100#;
   File_Volume_Is_Compressed          : constant := 16#0000_8000#;
   File_Supports_Object_Ids           : constant := 16#0001_0000#;
   File_Supports_Encryption           : constant := 16#0002_0000#;
   File_Named_Streams                 : constant := 16#0004_0000#;
   File_Read_Only_Volume              : constant := 16#0008_0000#;

--
-- Define the file notification information structure
--

--%%   PFILE_NOTIFY_INFORMATION = ^FILE_NOTIFY_INFORMATION;
--%%   {$EXTERNALSYM PFILE_NOTIFY_INFORMATION}
--%%   _FILE_NOTIFY_INFORMATION = record
--%%     NextEntryOffset: DWORD;
--%%     Action: DWORD;
--%%     FileNameLength: DWORD;
--%%     FileName: array [0..0] of WCHAR;
--%%   end;
--%%   {$EXTERNALSYM _FILE_NOTIFY_INFORMATION}
--%%   FILE_NOTIFY_INFORMATION = _FILE_NOTIFY_INFORMATION;
--%%   {$EXTERNALSYM FILE_NOTIFY_INFORMATION}
--%%   TFileNotifyInformation = FILE_NOTIFY_INFORMATION;
--%%   PFileNotifyInformation = PFILE_NOTIFY_INFORMATION;

--
-- Define segement buffer structure for scatter/gather read/write.
--

--%%   PFILE_SEGMENT_ELEMENT = ^FILE_SEGMENT_ELEMENT;
--%%   {$EXTERNALSYM PFILE_SEGMENT_ELEMENT}
--%%   _FILE_SEGMENT_ELEMENT = record
--%%     case Integer of
--%%       0: (Buffer: PVOID64);
--%%       1: (Alignment: ULONGLONG);
--%%   end;
--%%   {$EXTERNALSYM _FILE_SEGMENT_ELEMENT}
--%%   FILE_SEGMENT_ELEMENT = _FILE_SEGMENT_ELEMENT;
--%%   {$EXTERNALSYM FILE_SEGMENT_ELEMENT}
--%%   TFileSegmentElement = FILE_SEGMENT_ELEMENT;
--%%   PFileSegmentElement = PFILE_SEGMENT_ELEMENT;

--
-- The reparse GUID structure is used by all 3rd party layered drivers to
-- store data in a reparse point. For non-Microsoft tags, The GUID field
-- cannot be GUID_NULL.
-- The constraints on reparse tags are defined below.
-- Microsoft tags can also be used with this format of the reparse point buffer.
--
--%%   TGenericReparseBuffer = record
--%%     DataBuffer: array [0..0] of BYTE;
--%%   end;

   type Reparse_GUID_Data_Buffer_Type;
   type Reparse_GUID_Data_Buffer_Ptr is access all Reparse_GUID_Data_Buffer_Type;
   type Reparse_GUID_Data_Buffer_CPtr is access constant Reparse_GUID_Data_Buffer_Type;
   type Reparse_GUID_Data_Buffer_Type is record
      Reparse_Tag : Unsigned_32;
      Reparse_Data_Length : Unsigned_16;
      Reserved : Unsigned_16;
      Reparse_GUID : GUID_Type;
      Generic_Reparse_Buffer : Generic_Reparse_Buffer_Type;
   end record;

   Reparse_GUID_Data_Buffer_Header_Size : constant := 24;
--
-- Maximum allowed size of the reparse data.
--

--%%   MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024;
--%%   {$EXTERNALSYM MAXIMUM_REPARSE_DATA_BUFFER_SIZE}

--
-- Predefined reparse tags.
-- These tags need to avoid conflicting with IO_REMOUNT defined in ntos\inc\io.h
--

   IO_Reparse_Tag_Reserved_Zero : constant := 0;
   IO_Reparse_Tag_Reserved_One  : constant := 1;

--
-- The value of the following constant needs to satisfy the following conditions:
--  (1) Be at least as large as the largest of the reserved tags.
--  (2) Be strictly smaller than all the tags in use.
--

   IO_Reparse_Tag_Reserved_Range : constant := IO_Reparse_Tag_Reserved_One;

--
-- The reparse tags are a DWORD. The 32 bits are laid out as follows:
--
--   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
--   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
--  +-+-+-+-+-----------------------+-------------------------------+
--  |M|R|N|R|     Reserved bits     |       Reparse Tag Value       |
--  +-+-+-+-+-----------------------+-------------------------------+
--
-- M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
--   All ISVs must use a tag with a 0 in this position.
--   Note: If a Microsoft tag is used by non-Microsoft software, the
--   behavior is not defined.
--
-- R is reserved.  Must be zero for non-Microsoft tags.
--
-- N is name surrogate. When set to 1, the file represents another named
--   entity in the system.
--
-- The M and N bits are OR-able.
-- The following macros check for the M and N bit values:
--

--
-- Macro to determine whether a reparse point tag corresponds to a tag
-- owned by Microsoft.
--

--%% function IsReparseTagMicrosoft(Tag: ULONG): Boolean;
--%% {$EXTERNALSYM IsReparseTagMicrosoft}

--
-- Macro to determine whether a reparse point tag corresponds to a file
-- that is to be displayed with the slow icon overlay.
--

--%% function IsReparseTagHighLatency(Tag: ULONG): Boolean;
--%% {$EXTERNALSYM IsReparseTagHighLatency}

--
-- Macro to determine whether a reparse point tag is a name surrogate
--

--%% function IsReparseTagNameSurrogate(Tag: ULONG): Boolean;
--%% {$EXTERNALSYM IsReparseTagNameSurrogate}

   IO_Reparse_Tag_Mount_Point : constant := 16#A000_0003#;
   IO_Reparse_Tag_Hsm         : constant := 16#C000_0004#;
   IO_Reparse_Tag_Sis         : constant := 16#8000_0007#;
   IO_Reparse_Tag_Dfs         : constant := 16#8000_000A#;
   IO_Reparse_Tag_Filter_Manager : constant := 16#8000_000B#;
   IO_Completion_Modify_State : constant := 16#0002#;
--%%   IO_COMPLETION_ALL_ACCESS   = DWORD(STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $3);
--%%   {$EXTERNALSYM IO_COMPLETION_ALL_ACCESS}
   Duplicate_Close_Source     : constant := 16#0000_0001#;
   Duplicate_Same_Access      : constant := 16#0000_0002#;

--%%   _SYSTEM_POWER_STATE = (
--%%     PowerSystemUnspecified,
--%%     PowerSystemWorking,
--%%     PowerSystemSleeping1,
--%%     PowerSystemSleeping2,
--%%     PowerSystemSleeping3,
--%%     PowerSystemHibernate,
--%%     PowerSystemShutdown,
--%%     PowerSystemMaximum);
--%%   {$EXTERNALSYM _SYSTEM_POWER_STATE}
   subtype System_Power_State_Type is _SYSTEM_POWER_STATE;
   type System_Power_State_Ptr is access all _SYSTEM_POWER_STATE;
   type System_Power_State_CPtr is access constant _SYSTEM_POWER_STATE;

   Power_System_Maximum : constant := 7;

--%%   POWER_ACTION = (
--%%     PowerActionNone,
--%%     PowerActionReserved,
--%%     PowerActionSleep,
--%%     PowerActionHibernate,
--%%     PowerActionShutdown,
--%%     PowerActionShutdownReset,
--%%     PowerActionShutdownOff,
--%%     PowerActionWarmEject);
--%%   {$EXTERNALSYM POWER_ACTION}
--%%   PPOWER_ACTION = ^POWER_ACTION;
--%%   {$EXTERNALSYM PPOWER_ACTION}
--%%   TPowerAction = POWER_ACTION;
--%%   PPowerAction = PPOWER_ACTION;

--%%   _DEVICE_POWER_STATE = (
--%%     PowerDeviceUnspecified,
--%%     PowerDeviceD0,
--%%     PowerDeviceD1,
--%%     PowerDeviceD2,
--%%     PowerDeviceD3,
--%%     PowerDeviceMaximum);
--%%   {$EXTERNALSYM _DEVICE_POWER_STATE}
   subtype Device_Power_State_Type is _DEVICE_POWER_STATE;
   type Device_Power_State_Ptr is access all _DEVICE_POWER_STATE;
   type Device_Power_State_CPtr is access constant _DEVICE_POWER_STATE;

   Es_System_Required  : constant := 16#0000_0001#;
   Es_Display_Required : constant := 16#0000_0002#;
   Es_User_Present     : constant := 16#0000_0004#;
   Es_Continuous       : constant := 16#8000_0000#;

   subtype Execution_State_Type is Unsigned_32;
   subtype Execution_State_Ptr is Unsigned_32_Ptr;
   subtype Execution_State_CPtr is Unsigned_32_CPtr;

--%%   LATENCY_TIME = (LT_DONT_CARE, LT_LOWEST_LATENCY);
--%%   {$EXTERNALSYM LATENCY_TIME}
--%%   TLatencyTime = LATENCY_TIME;

-- -----------------------------------------------------------------------------
-- Device Power Information
-- Accessable via CM_Get_DevInst_Registry_Property_Ex(CM_DRP_DEVICE_POWER_DATA)
-- -----------------------------------------------------------------------------

   Pdcap_D0_Supported           : constant := 16#0000_0001#;
   Pdcap_D1_Supported           : constant := 16#0000_0002#;
   Pdcap_D2_Supported           : constant := 16#0000_0004#;
   Pdcap_D3_Supported           : constant := 16#0000_0008#;
   Pdcap_Wake_From_D0_Supported : constant := 16#0000_0010#;
   Pdcap_Wake_From_D1_Supported : constant := 16#0000_0020#;
   Pdcap_Wake_From_D2_Supported : constant := 16#0000_0040#;
   Pdcap_Wake_From_D3_Supported : constant := 16#0000_0080#;
   Pdcap_Warm_Eject_Supported   : constant := 16#0000_0100#;

--%%   CM_Power_Data_s = record
--%%     PD_Size: DWORD;
--%%     PD_MostRecentPowerState: DEVICE_POWER_STATE;
--%%     PD_Capabilities: DWORD;
--%%     PD_D1Latency: DWORD;
--%%     PD_D2Latency: DWORD;
--%%     PD_D3Latency: DWORD;
--%%     PD_PowerStateMapping: array [0..POWER_SYSTEM_MAXIMUM - 1] of DEVICE_POWER_STATE;
--%%     PD_DeepestSystemWake: SYSTEM_POWER_STATE;
--%%   end;
--%%   {$EXTERNALSYM CM_Power_Data_s}
   subtype Cm_Power_Data_Type is CM_Power_Data_S;
   type Cm_Power_Data_Ptr is access all CM_Power_Data_S;
   type Cm_Power_Data_CPtr is access constant CM_Power_Data_S;

--%%   POWER_INFORMATION_LEVEL = (
--%%     SystemPowerPolicyAc,
--%%     SystemPowerPolicyDc,
--%%     VerifySystemPolicyAc,
--%%     VerifySystemPolicyDc,
--%%     SystemPowerCapabilities,
--%%     SystemBatteryState,
--%%     SystemPowerStateHandler,
--%%     ProcessorStateHandler,
--%%     SystemPowerPolicyCurrent,
--%%     AdministratorPowerPolicy,
--%%     SystemReserveHiberFile,
--%%     ProcessorInformation,
--%%     SystemPowerInformation,
--%%     ProcessorStateHandler2,
--%%     LastWakeTime,                                   // Compare with KeQueryInterruptTime()
--%%     LastSleepTime,                                  // Compare with KeQueryInterruptTime()
--%%     SystemExecutionState,
--%%     SystemPowerStateNotifyHandler,
--%%     ProcessorPowerPolicyAc,
--%%     ProcessorPowerPolicyDc,
--%%     VerifyProcessorPowerPolicyAc,
--%%     VerifyProcessorPowerPolicyDc,
--%%     ProcessorPowerPolicyCurrent,
--%%     SystemPowerStateLogging,
--%%     SystemPowerLoggingEntry);
--%%   {$EXTERNALSYM POWER_INFORMATION_LEVEL}
--%%   TPowerInformationLevel = POWER_INFORMATION_LEVEL;

--
-- System power manager capabilities
--

--%%   BATTERY_REPORTING_SCALE = record
--%%     Granularity: DWORD;
--%%     Capacity: DWORD;
--%%   end;
--%%   {$EXTERNALSYM BATTERY_REPORTING_SCALE}
--%%   PBATTERY_REPORTING_SCALE = ^BATTERY_REPORTING_SCALE;
--%%   {$EXTERNALSYM PBATTERY_REPORTING_SCALE}
--%%   TBatteryReportingScale = BATTERY_REPORTING_SCALE;
--%%   PBatteryReportingScale = PBATTERY_REPORTING_SCALE;

-- Power Policy Management interfaces
--

--%%   PPOWER_ACTION_POLICY = ^POWER_ACTION_POLICY;
--%%   {$EXTERNALSYM PPOWER_ACTION_POLICY}
--%%   POWER_ACTION_POLICY = record
--%%     Action: POWER_ACTION;
--%%     Flags: DWORD;
--%%     EventCode: DWORD;
--%%   end;
--%%   {$EXTERNALSYM POWER_ACTION_POLICY}
--%%   TPowerActionPolicy = POWER_ACTION_POLICY;
--%%   PPowerActionPolicy = PPOWER_ACTION_POLICY;

-- POWER_ACTION_POLICY->Flags:

   Power_Action_Query_Allowed  : constant := 16#0000_0001#;
   Power_Action_UI_Allowed     : constant := 16#0000_0002#;
   Power_Action_Override_Apps  : constant := 16#0000_0004#;
   Power_Action_Lightest_First : constant := 16#1000_0000#;
   Power_Action_Lock_Console   : constant := 16#2000_0000#;
   Power_Action_Disable_Wakes  : constant := 16#4000_0000#;
   Power_Action_Critical       : constant := 16#8000_0000#;

-- POWER_ACTION_POLICY->EventCode flags

   Power_Level_User_Notify_Text  : constant := 16#0000_0001#;
   Power_Level_User_Notify_Sound : constant := 16#0000_0002#;
   Power_Level_User_Notify_Exec  : constant := 16#0000_0004#;
   Power_User_Notify_Button      : constant := 16#0000_0008#;
   Power_User_Notify_Shutdown    : constant := 16#0000_0010#;
   Power_Force_Trigger_Reset     : constant := 16#8000_0000#;

-- system battery drain policies

--%%   PSYSTEM_POWER_LEVEL = ^SYSTEM_POWER_LEVEL;
--%%   {$EXTERNALSYM PSYSTEM_POWER_LEVEL}
--%%   SYSTEM_POWER_LEVEL = record
--%%     Enable: BOOLEAN;
--%%     Spare: array [0..3 - 1] of BYTE;
--%%     BatteryLevel: DWORD;
--%%     PowerPolicy: POWER_ACTION_POLICY;
--%%     MinSystemState: SYSTEM_POWER_STATE;
--%%   end;
--%%   {$EXTERNALSYM SYSTEM_POWER_LEVEL}
--%%   TSystemPowerLevel = SYSTEM_POWER_LEVEL;
--%%   PSystemPowerLevel = PSYSTEM_POWER_LEVEL;

-- Discharge policy constants

   Num_Discharge_Policies    : constant := 4;
   Discharge_Policy_Critical : constant := 0;
   Discharge_Policy_Low      : constant := 1;

--
-- Throttling policies
--

   Po_Throttle_None     : constant := 0;
   Po_Throttle_Constant : constant := 1;
   Po_Throttle_Degrade  : constant := 2;
   Po_Throttle_Adaptive : constant := 3;
   Po_Throttle_Maximum  : constant := 4; -- not a policy, just a limit

-- system power policies

--%%   PSYSTEM_POWER_POLICY = ^SYSTEM_POWER_POLICY;
--%%   {$EXTERNALSYM PSYSTEM_POWER_POLICY}
--%%   _SYSTEM_POWER_POLICY = record
--%%     Revision: DWORD; // 1
--%%     // events
--%%     PowerButton: POWER_ACTION_POLICY;
--%%     SleepButton: POWER_ACTION_POLICY;
--%%     LidClose: POWER_ACTION_POLICY;
--%%     LidOpenWake: SYSTEM_POWER_STATE;
--%%     Reserved: DWORD;
--%%     // "system idle" detection
--%%     Idle: POWER_ACTION_POLICY;
--%%     IdleTimeout: DWORD;
--%%     IdleSensitivity: BYTE;
--%%     // dynamic throttling policy
--%%     //      PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
--%%     DynamicThrottle: BYTE;
--%%     Spare2: array [0..1] of BYTE;
--%%     // meaning of power action "sleep"
--%%     MinSleep: SYSTEM_POWER_STATE;
--%%     MaxSleep: SYSTEM_POWER_STATE;
--%%     ReducedLatencySleep: SYSTEM_POWER_STATE;
--%%     WinLogonFlags: DWORD;
--%%     // parameters for dozing
--%%     Spare3: DWORD;
--%%     DozeS4Timeout: DWORD;
--%%     // battery policies
--%%     BroadcastCapacityResolution: DWORD;
--%%     DischargePolicy: array [0..NUM_DISCHARGE_POLICIES - 1] of SYSTEM_POWER_LEVEL;
--%%     // video policies
--%%     VideoTimeout: DWORD;
--%%     VideoDimDisplay: BOOLEAN;
--%%     VideoReserved: array [0..2] of DWORD;
--%%     // hard disk policies
--%%     SpindownTimeout: DWORD;
--%%     // processor policies
--%%     OptimizeForPower: LongBool;
--%%     FanThrottleTolerance: BYTE;
--%%     ForcedThrottle: BYTE;
--%%     MinThrottle: BYTE;
--%%     OverThrottled: POWER_ACTION_POLICY;
--%%   end;
--%%   {$EXTERNALSYM _SYSTEM_POWER_POLICY}
--%%   SYSTEM_POWER_POLICY = _SYSTEM_POWER_POLICY;
--%%   {$EXTERNALSYM SYSTEM_POWER_POLICY}
--%%   TSystemPowerPolicy = SYSTEM_POWER_POLICY;
--%%   PSystemPowerPolicy = PSYSTEM_POWER_POLICY;

-- processor power policy state

--%%   PPROCESSOR_POWER_POLICY_INFO = ^PROCESSOR_POWER_POLICY_INFO;
--%%   {$EXTERNALSYM PPROCESSOR_POWER_POLICY_INFO}
--%%   _PROCESSOR_POWER_POLICY_INFO = record
--%%     // Time based information (will be converted to kernel units)
--%%     TimeCheck: DWORD; // in US
--%%     DemoteLimit: DWORD; // in US
--%%     PromoteLimit: DWORD; // in US
--%%     // Percentage based information
--%%     DemotePercent: BYTE;
--%%     PromotePercent: BYTE;
--%%     Spare: array [0..1] of BYTE;
--%%     // Flags
--%%     Flags: DWORD;
--%%     //DWORD                   AllowDemotion:1;
--%%     //DWORD                   AllowPromotion:1;
--%%     //DWORD                   Reserved:30;
--%%   end;
--%%   {$EXTERNALSYM _PROCESSOR_POWER_POLICY_INFO}
--%%   PROCESSOR_POWER_POLICY_INFO = _PROCESSOR_POWER_POLICY_INFO;
--%%   {$EXTERNALSYM PROCESSOR_POWER_POLICY_INFO}
--%%   TProcessorPowerPolicyInfo = PROCESSOR_POWER_POLICY_INFO;
--%%   PProcessorPowerPolicyInfo = PPROCESSOR_POWER_POLICY_INFO;

-- processor power policy

--%%   PPROCESSOR_POWER_POLICY = ^PROCESSOR_POWER_POLICY;
--%%   {$EXTERNALSYM PPROCESSOR_POWER_POLICY}
--%%   _PROCESSOR_POWER_POLICY = record
--%%     Revision: DWORD; // 1
--%%     // Dynamic Throttling Policy
--%%     DynamicThrottle: BYTE;
--%%     Spare: array [0..2] of BYTE;
--%%     // Flags
--%%     Reserved: DWORD;
--%%     //DWORD                       DisableCStates:1;
--%%     //DWORD                       Reserved:31;

--%%     // System policy information
--%%     // The Array is last, in case it needs to be grown and the structure
--%%     // revision incremented.
--%%     PolicyCount: DWORD;
--%%     Policy: array [0..2] of PROCESSOR_POWER_POLICY_INFO;
--%%   end;
--%%   {$EXTERNALSYM _PROCESSOR_POWER_POLICY}
--%%   PROCESSOR_POWER_POLICY = _PROCESSOR_POWER_POLICY;
--%%   {$EXTERNALSYM PROCESSOR_POWER_POLICY}
--%%   TProcessorPowerPolicy = PROCESSOR_POWER_POLICY;
--%%   PProcessorPowerPolicy = PPROCESSOR_POWER_POLICY;

-- administrator power policy overrides

   type Administrator_Power_Policy_Type;
   type Administrator_Power_Policy_Ptr is access all Administrator_Power_Policy_Type;
   type Administrator_Power_Policy_CPtr is access constant Administrator_Power_Policy_Type;
   type Administrator_Power_Policy_Type is record
            -- meaning of power action "sleep"
      Min_Sleep : System_Power_State_Type;
      Max_Sleep : System_Power_State_Type;
            -- video policies
      Min_Video_Timeout : Unsigned_32;
      Max_Video_Timeout : Unsigned_32;
            -- disk policies
      Min_Spindown_Timeout : Unsigned_32;
      Max_Spindown_Timeout : Unsigned_32;
   end record;

--%%   PSYSTEM_POWER_CAPABILITIES = ^SYSTEM_POWER_CAPABILITIES;
--%%   {$EXTERNALSYM PSYSTEM_POWER_CAPABILITIES}
--%%   SYSTEM_POWER_CAPABILITIES = record
--%%     // Misc supported system features
--%%     PowerButtonPresent: BOOLEAN;
--%%     SleepButtonPresent: BOOLEAN;
--%%     LidPresent: BOOLEAN;
--%%     SystemS1: BOOLEAN;
--%%     SystemS2: BOOLEAN;
--%%     SystemS3: BOOLEAN;
--%%     SystemS4: BOOLEAN; // hibernate
--%%     SystemS5: BOOLEAN; // off
--%%     HiberFilePresent: BOOLEAN;
--%%     FullWake: BOOLEAN;
--%%     VideoDimPresent: BOOLEAN;
--%%     ApmPresent: BOOLEAN;
--%%     UpsPresent: BOOLEAN;
--%%     // Processors
--%%     ThermalControl: BOOLEAN;
--%%     ProcessorThrottle: BOOLEAN;
--%%     ProcessorMinThrottle: BYTE;
--%%     ProcessorMaxThrottle: BYTE;
--%%     spare2: array [0..4 - 1] of BYTE;
--%%     // Disk
--%%     DiskSpinDown: BOOLEAN;
--%%     spare3: array [0..8 - 1] of BYTE;
--%%     // System Battery
--%%     SystemBatteriesPresent: BOOLEAN;
--%%     BatteriesAreShortTerm: BOOLEAN;
--%%     BatteryScale: array [0..3 - 1] of BATTERY_REPORTING_SCALE;
--%%     // Wake
--%%     AcOnLineWake: SYSTEM_POWER_STATE;
--%%     SoftLidWake: SYSTEM_POWER_STATE;
--%%     RtcWake: SYSTEM_POWER_STATE;
--%%     MinDeviceWakeState: SYSTEM_POWER_STATE; // note this may change on driver load
--%%     DefaultLowLatencyWake: SYSTEM_POWER_STATE;
--%%   end;
--%%   {$EXTERNALSYM SYSTEM_POWER_CAPABILITIES}
--%%   TSystemPowerCapabilities = SYSTEM_POWER_CAPABILITIES;
--%%   PSystemPowerCapabilities = PSYSTEM_POWER_CAPABILITIES;

--%%   PSYSTEM_BATTERY_STATE = ^SYSTEM_BATTERY_STATE;
--%%   {$EXTERNALSYM PSYSTEM_BATTERY_STATE}
--%%   SYSTEM_BATTERY_STATE = record
--%%     AcOnLine: BOOLEAN;
--%%     BatteryPresent: BOOLEAN;
--%%     Charging: BOOLEAN;
--%%     Discharging: BOOLEAN;
--%%     Spare1: array [0..3] of BOOLEAN;
--%%     MaxCapacity: DWORD;
--%%     RemainingCapacity: DWORD;
--%%     Rate: DWORD;
--%%     EstimatedTime: DWORD;
--%%     DefaultAlert1: DWORD;
--%%     DefaultAlert2: DWORD;
--%%   end;
--%%   {$EXTERNALSYM SYSTEM_BATTERY_STATE}
--%%   TSystemBatteryState = SYSTEM_BATTERY_STATE;
--%%   PSystemBatteryState = PSYSTEM_BATTERY_STATE;

--
-- Image Format
--

-- #include "pshpack4.h"                   // 4 byte packing is the default

   Image_Dos_Signature    : constant := 16#5A4D#; -- MZ
   Image_Os2_Signature    : constant := 16#454E#; -- NE
   Image_Os2_Signature_Le : constant := 16#454C#; -- LE
   Image_Vxd_Signature    : constant := 16#454C#; -- LE
   Image_NT_Signature     : constant := 16#0000_4550#; -- PE00

-- #include "pshpack2.h"                   // 16 bit headers are 2 byte packed


--%%   // DOS .EXE header

--%%   PIMAGE_DOS_HEADER = ^IMAGE_DOS_HEADER;
--%%   {$EXTERNALSYM PIMAGE_DOS_HEADER}
--%%   _IMAGE_DOS_HEADER = record
--%%     e_magic: Word;     // Magic number
--%%     e_cblp: Word;      // Bytes on last page of file
--%%     e_cp: Word;        // Pages in file
--%%     e_crlc: Word;      // Relocations
--%%     e_cparhdr: Word;   // Size of header in paragraphs
--%%     e_minalloc: Word;  // Minimum extra paragraphs needed
--%%     e_maxalloc: Word;  // Maximum extra paragraphs needed
--%%     e_ss: Word;        // Initial (relative) SS value
--%%     e_sp: Word;        // Initial SP value
--%%     e_csum: Word;      // Checksum
--%%     e_ip: Word;        // Initial IP value
--%%     e_cs: Word;        // Initial (relative) CS value
--%%     e_lfarlc: Word;    // File address of relocation table
--%%     e_ovno: Word;      // Overlay number
--%%     e_res: array [0..3] of Word;    // Reserved words
--%%     e_oemid: Word;     // OEM identifier (for e_oeminfo)
--%%     e_oeminfo: Word;   // OEM information; e_oemid specific
--%%     e_res2: array [0..9] of Word;  // Reserved words
--%%     e_lfanew: Longint; // File address of new exe header
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_DOS_HEADER}
--%%   IMAGE_DOS_HEADER = _IMAGE_DOS_HEADER;
--%%   {$EXTERNALSYM IMAGE_DOS_HEADER}
--%%   TImageDosHeader = IMAGE_DOS_HEADER;
--%%   PImageDosHeader = PIMAGE_DOS_HEADER;

--%%   // OS/2 .EXE header

   type Image_Os2Header_Type;
   type Image_Os2Header_Ptr is access all Image_Os2Header_Type;
   type Image_Os2Header_CPtr is access constant Image_Os2Header_Type;
   type Image_Os2Header_Type is record
      _Magic : Word;               -- Magic number
      _Ver : Char_8;               -- Version number
      _Rev : Char_8;               -- Revision number
      _Enttab : Word;              -- Offset of Entry Table
      _Cbenttab : Word;            -- Number of bytes in Entry Table
      _Crc : Longint;              -- Checksum of whole file
      _Flags : Word;               -- Flag word
      _Autodata : Word;            -- Automatic data segment number
      _Heap : Word;                -- Initial heap allocation
      _Stack : Word;               -- Initial stack allocation
      _Csip : Longint;             -- Initial CS:IP setting
      _Sssp : Longint;             -- Initial SS:SP setting
      _Cseg : Word;                -- Count of file segments
      _Cmod : Word;                -- Entries in Module Reference Table
      _Cbnrestab : Word;           -- Size of non-resident name table
      _Segtab : Word;              -- Offset of Segment Table
      _Rsrctab : Word;             -- Offset of Resource Table
      _Restab : Word;              -- Offset of resident name table
      _Modtab : Word;              -- Offset of Module Reference Table
      _Imptab : Word;              -- Offset of Imported Names Table
      _Nrestab : Longint;          -- Offset of Non-resident Names Table
      _Cmovent : Word;             -- Count of movable entries
      _Align : Word;               -- Segment alignment shift count
      _Cres : Word;                -- Count of resource segments
      _Exetyp : Byte;              -- Target Operating system
      _Flagsothers : Byte;         -- Other .EXE flags
      _Pretthunks : Word;          -- offset to return thunks
      _Psegrefbytes : Word;        -- offset to segment ref. bytes
      _Swaparea : Word;            -- Minimum code swap area size
      _Expver : Word;              -- Expected Windows version number
   end record;

--%%   // Windows VXD header

--%%   PIMAGE_VXD_HEADER = ^IMAGE_VXD_HEADER;
--%%   {$EXTERNALSYM PIMAGE_VXD_HEADER}
--%%   _IMAGE_VXD_HEADER = record
--%%     e32_magic: Word;         // Magic number
--%%     e32_border: Byte;        // The byte ordering for the VXD
--%%     e32_worder: Byte;        // The word ordering for the VXD
--%%     e32_level: DWORD;        // The EXE format level for now = 0
--%%     e32_cpu: Word;           // The CPU type
--%%     e32_os: Word;            // The OS type
--%%     e32_ver: DWORD;          // Module version
--%%     e32_mflags: DWORD;       // Module flags
--%%     e32_mpages: DWORD;       // Module # pages
--%%     e32_startobj: DWORD;     // Object # for instruction pointer
--%%     e32_eip: DWORD;          // Extended instruction pointer
--%%     e32_stackobj: DWORD;     // Object # for stack pointer
--%%     e32_esp: DWORD;          // Extended stack pointer
--%%     e32_pagesize: DWORD;     // VXD page size
--%%     e32_lastpagesize: DWORD; // Last page size in VXD
--%%     e32_fixupsize: DWORD;    // Fixup section size
--%%     e32_fixupsum: DWORD;     // Fixup section checksum
--%%     e32_ldrsize: DWORD;      // Loader section size
--%%     e32_ldrsum: DWORD;       // Loader section checksum
--%%     e32_objtab: DWORD;       // Object table offset
--%%     e32_objcnt: DWORD;       // Number of objects in module
--%%     e32_objmap: DWORD;       // Object page map offset
--%%     e32_itermap: DWORD;      // Object iterated data map offset
--%%     e32_rsrctab: DWORD;      // Offset of Resource Table
--%%     e32_rsrccnt: DWORD;      // Number of resource entries
--%%     e32_restab: DWORD;       // Offset of resident name table
--%%     e32_enttab: DWORD;       // Offset of Entry Table
--%%     e32_dirtab: DWORD;       // Offset of Module Directive Table
--%%     e32_dircnt: DWORD;       // Number of module directives
--%%     e32_fpagetab: DWORD;     // Offset of Fixup Page Table
--%%     e32_frectab: DWORD;      // Offset of Fixup Record Table
--%%     e32_impmod: DWORD;       // Offset of Import Module Name Table
--%%     e32_impmodcnt: DWORD;    // Number of entries in Import Module Name Table
--%%     e32_impproc: DWORD;      // Offset of Import Procedure Name Table
--%%     e32_pagesum: DWORD;      // Offset of Per-Page Checksum Table
--%%     e32_datapage: DWORD;     // Offset of Enumerated Data Pages
--%%     e32_preload: DWORD;      // Number of preload pages
--%%     e32_nrestab: DWORD;      // Offset of Non-resident Names Table
--%%     e32_cbnrestab: DWORD;    // Size of Non-resident Name Table
--%%     e32_nressum: DWORD;      // Non-resident Name Table Checksum
--%%     e32_autodata: DWORD;     // Object # for automatic data object
--%%     e32_debuginfo: DWORD;    // Offset of the debugging information
--%%     e32_debuglen: DWORD;     // The length of the debugging info. in bytes
--%%     e32_instpreload: DWORD;  // Number of instance pages in preload section of VXD file
--%%     e32_instdemand: DWORD;   // Number of instance pages in demand load section of VXD file
--%%     e32_heapsize: DWORD;     // Size of heap - for 16-bit apps
--%%     e32_res3: array [0..11] of Byte;      // Reserved words
--%%     e32_winresoff: DWORD;
--%%     e32_winreslen: DWORD;
--%%     e32_devid: Word;         // Device ID for VxD
--%%     e32_ddkver: Word;        // DDK version for VxD
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_VXD_HEADER}
--%%   IMAGE_VXD_HEADER = _IMAGE_VXD_HEADER;
--%%   {$EXTERNALSYM IMAGE_VXD_HEADER}
--%%   TImageVxdHeader = IMAGE_VXD_HEADER;
--%%   PImageVxdHeader = PIMAGE_VXD_HEADER;

-- #include "poppack.h"                    // Back to 4 byte packing

--
-- File header format.
--

   type Image_File_Header_Type;
   type Image_File_Header_Ptr is access all Image_File_Header_Type;
   type Image_File_Header_CPtr is access constant Image_File_Header_Type;
   type Image_File_Header_Type is record
      Machine : Unsigned_16;
      Number_Of_Sections : Unsigned_16;
      Time_Date_Stamp : Unsigned_32;
      Pointer_To_Symbol_Table : Unsigned_32;
      Number_Of_Symbols : Unsigned_32;
      Size_Of_Optional_Header : Unsigned_16;
      Characteristics : Unsigned_16;
   end record;

   Image_Sizeof_File_Header : constant := 20;

   Image_File_Relocs_Stripped         : constant := 16#0001#; -- Relocation info stripped from file.
   Image_File_Executable_Image        : constant := 16#0002#; -- File is executable  (i.e. no unresolved externel references).
   Image_File_Line_Nums_Stripped      : constant := 16#0004#; -- Line nunbers stripped from file.
   Image_File_Local_Syms_Stripped     : constant := 16#0008#; -- Local symbols stripped from file.
   Image_File_Aggresive_Ws_Trim       : constant := 16#0010#; -- Agressively trim working set
   Image_File_Large_Address_Aware     : constant := 16#0020#; -- App can handle >2gb addresses
   Image_File_Bytes_Reversed_Lo       : constant := 16#0080#; -- Bytes of machine word are reversed.
   Image_File_32Bit_Machine           : constant := 16#0100#; -- 32 bit word machine.
   Image_File_Debug_Stripped          : constant := 16#0200#; -- Debugging info stripped from file in .DBG file
   Image_File_Removable_Run_From_Swap : constant := 16#0400#; -- If Image is on removable media, copy and run from the swap file.
   Image_File_Net_Run_From_Swap       : constant := 16#0800#; -- If Image is on Net, copy and run from the swap file.
   Image_File_System                  : constant := 16#1000#; -- System File.
   Image_File_DLL                     : constant := 16#2000#; -- File is a DLL.
   Image_File_Up_System_Only          : constant := 16#4000#; -- File should only be run on a UP machine
   Image_File_Bytes_Reversed_Hi       : constant := 16#8000#; -- Bytes of machine word are reversed.

   Image_File_Machine_Unknown   : constant := 0;
   Image_File_Machine_I386      : constant := 16#014C#; -- Intel 386.
   Image_File_Machine_R3000     : constant := 16#0162#; -- MIPS little-endian, 0x160 big-endian
   Image_File_Machine_R4000     : constant := 16#0166#; -- MIPS little-endian
   Image_File_Machine_R10000    : constant := 16#0168#; -- MIPS little-endian
   Image_File_Machine_Wcemipsv2 : constant := 16#0169#; -- MIPS little-endian WCE v2
   Image_File_Machine_Alpha     : constant := 16#0184#; -- Alpha_AXP
   Image_File_Machine_Sh3       : constant := 16#01A2#; -- SH3 little-endian
   Image_File_Machine_Sh3Dsp    : constant := 16#01A3#;
   Image_File_Machine_Sh3E      : constant := 16#01A4#; -- SH3E little-endian
   Image_File_Machine_Sh4       : constant := 16#01A6#; -- SH4 little-endian
   Image_File_Machine_Sh5       : constant := 16#01A8#; -- SH5
   Image_File_Machine_ARM       : constant := 16#01C0#; -- ARM Little-Endian
   Image_File_Machine_Thumb     : constant := 16#01C2#;
   Image_File_Machine_Am33      : constant := 16#01D3#;
   Image_File_Machine_Powerpc   : constant := 16#01F0#; -- IBM PowerPC Little-Endian
   Image_File_Machine_Powerpcfp : constant := 16#01F1#;
   Image_File_Machine_IA64      : constant := 16#0200#; -- Intel 64
   Image_File_Machine_MIPS16    : constant := 16#0266#; -- MIPS
   Image_File_Machine_Alpha64   : constant := 16#0284#; -- ALPHA64
   Image_File_Machine_Mipsfpu   : constant := 16#0366#; -- MIPS
   Image_File_Machine_Mipsfpu16 : constant := 16#0466#; -- MIPS
   Image_File_Machine_Axp64     : constant := Image_File_Machine_Alpha64;
   Image_File_Machine_Tricore   : constant := 16#0520#; -- Infineon
   Image_File_Machine_Cef       : constant := 16#0CEF#;
   Image_File_Machine_Ebc       : constant := 16#0EBC#; -- EFI Byte Code
   Image_File_Machine_AMD64     : constant := 16#8664#; -- AMD64 (K8)
   Image_File_Machine_M32R      : constant := 16#9041#; -- M32R little-endian
   Image_File_Machine_Cee       : constant := 16#C0EE#;

--
-- Directory format.
--

   type Image_Data_Directory_Type;
   type Image_Data_Directory_Ptr is access all Image_Data_Directory_Type;
   type Image_Data_Directory_CPtr is access constant Image_Data_Directory_Type;
   type Image_Data_Directory_Type is record
      Virtual_Address : Unsigned_32;
      Size : Unsigned_32;
   end record;

   Image_Numberof_Directory_Entries : constant := 16;

--
-- Optional header format.
--

--%%   PIMAGE_OPTIONAL_HEADER32 = ^IMAGE_OPTIONAL_HEADER32;
--%%   {$EXTERNALSYM PIMAGE_OPTIONAL_HEADER32}
--%%   _IMAGE_OPTIONAL_HEADER = record
--%%     //
--%%     // Standard fields.
--%%     //
--%%     Magic: Word;
--%%     MajorLinkerVersion: Byte;
--%%     MinorLinkerVersion: Byte;
--%%     SizeOfCode: DWORD;
--%%     SizeOfInitializedData: DWORD;
--%%     SizeOfUninitializedData: DWORD;
--%%     AddressOfEntryPoint: DWORD;
--%%     BaseOfCode: DWORD;
--%%     BaseOfData: DWORD;
--%%     //
--%%     // NT additional fields.
--%%     //
--%%     ImageBase: DWORD;
--%%     SectionAlignment: DWORD;
--%%     FileAlignment: DWORD;
--%%     MajorOperatingSystemVersion: Word;
--%%     MinorOperatingSystemVersion: Word;
--%%     MajorImageVersion: Word;
--%%     MinorImageVersion: Word;
--%%     MajorSubsystemVersion: Word;
--%%     MinorSubsystemVersion: Word;
--%%     Win32VersionValue: DWORD;
--%%     SizeOfImage: DWORD;
--%%     SizeOfHeaders: DWORD;
--%%     CheckSum: DWORD;
--%%     Subsystem: Word;
--%%     DllCharacteristics: Word;
--%%     SizeOfStackReserve: DWORD;
--%%     SizeOfStackCommit: DWORD;
--%%     SizeOfHeapReserve: DWORD;
--%%     SizeOfHeapCommit: DWORD;
--%%     LoaderFlags: DWORD;
--%%     NumberOfRvaAndSizes: DWORD;
--%%     DataDirectory: array [0..IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1] of IMAGE_DATA_DIRECTORY;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_OPTIONAL_HEADER}
--%%   IMAGE_OPTIONAL_HEADER32 = _IMAGE_OPTIONAL_HEADER;
--%%   {$EXTERNALSYM IMAGE_OPTIONAL_HEADER32}
--%%   TImageOptionalHeader32 = IMAGE_OPTIONAL_HEADER32;
--%%   PImageOptionalHeader32 = PIMAGE_OPTIONAL_HEADER32;

--%%   PIMAGE_ROM_OPTIONAL_HEADER = ^IMAGE_ROM_OPTIONAL_HEADER;
--%%   {$EXTERNALSYM PIMAGE_ROM_OPTIONAL_HEADER}
--%%   _IMAGE_ROM_OPTIONAL_HEADER = record
--%%     Magic: Word;
--%%     MajorLinkerVersion: Byte;
--%%     MinorLinkerVersion: Byte;
--%%     SizeOfCode: DWORD;
--%%     SizeOfInitializedData: DWORD;
--%%     SizeOfUninitializedData: DWORD;
--%%     AddressOfEntryPoint: DWORD;
--%%     BaseOfCode: DWORD;
--%%     BaseOfData: DWORD;
--%%     BaseOfBss: DWORD;
--%%     GprMask: DWORD;
--%%     CprMask: array [0..3] of DWORD;
--%%     GpValue: DWORD;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_ROM_OPTIONAL_HEADER}
--%%   IMAGE_ROM_OPTIONAL_HEADER = _IMAGE_ROM_OPTIONAL_HEADER;
--%%   {$EXTERNALSYM IMAGE_ROM_OPTIONAL_HEADER}
--%%   TImageRomOptionalHeader = IMAGE_ROM_OPTIONAL_HEADER;
--%%   PImageRomOptionalHeader = PIMAGE_ROM_OPTIONAL_HEADER;

--%%   PIMAGE_OPTIONAL_HEADER64 = ^IMAGE_OPTIONAL_HEADER64;
--%%   {$EXTERNALSYM PIMAGE_OPTIONAL_HEADER64}
--%%   _IMAGE_OPTIONAL_HEADER64 = record
--%%     Magic: Word;
--%%     MajorLinkerVersion: Byte;
--%%     MinorLinkerVersion: Byte;
--%%     SizeOfCode: DWORD;
--%%     SizeOfInitializedData: DWORD;
--%%     SizeOfUninitializedData: DWORD;
--%%     AddressOfEntryPoint: DWORD;
--%%     BaseOfCode: DWORD;
--%%     ImageBase: Int64;
--%%     SectionAlignment: DWORD;
--%%     FileAlignment: DWORD;
--%%     MajorOperatingSystemVersion: Word;
--%%     MinorOperatingSystemVersion: Word;
--%%     MajorImageVersion: Word;
--%%     MinorImageVersion: Word;
--%%     MajorSubsystemVersion: Word;
--%%     MinorSubsystemVersion: Word;
--%%     Win32VersionValue: DWORD;
--%%     SizeOfImage: DWORD;
--%%     SizeOfHeaders: DWORD;
--%%     CheckSum: DWORD;
--%%     Subsystem: Word;
--%%     DllCharacteristics: Word;
--%%     SizeOfStackReserve: Int64;
--%%     SizeOfStackCommit: Int64;
--%%     SizeOfHeapReserve: Int64;
--%%     SizeOfHeapCommit: Int64;
--%%     LoaderFlags: DWORD;
--%%     NumberOfRvaAndSizes: DWORD;
--%%     DataDirectory: array [0..IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1] of IMAGE_DATA_DIRECTORY;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_OPTIONAL_HEADER64}
--%%   IMAGE_OPTIONAL_HEADER64 = _IMAGE_OPTIONAL_HEADER64;
--%%   {$EXTERNALSYM IMAGE_OPTIONAL_HEADER64}
--%%   TImageOptionalHeader64 = IMAGE_OPTIONAL_HEADER64;
--%%   PImageOptionalHeader64 = PIMAGE_OPTIONAL_HEADER64;

   Image_Sizeof_Rom_Optional_Header  : constant := 56;
   Image_Sizeof_Std_Optional_Header  : constant := 28;
   Image_Sizeof_NT_Optional32_Header : constant := 224;
   Image_Sizeof_NT_Optional64_Header : constant := 240;

   Image_NT_Optional_Hdr32_Magic : constant := 16#10B#;
   Image_NT_Optional_Hdr64_Magic : constant := 16#20B#;
   Image_Rom_Optional_Hdr_Magic  : constant := 16#107#;

--%%   IMAGE_OPTIONAL_HEADER = IMAGE_OPTIONAL_HEADER32;
--%%   {$EXTERNALSYM IMAGE_OPTIONAL_HEADER}
--%%   PIMAGE_OPTIONAL_HEADER = PIMAGE_OPTIONAL_HEADER32;
--%%   {$EXTERNALSYM PIMAGE_OPTIONAL_HEADER}

   Image_Sizeof_NT_Optional_Header : constant := Image_Sizeof_NT_Optional32_Header;
   Image_NT_Optional_Hdr_Magic     : constant := Image_NT_Optional_Hdr32_Magic;

   type Image_NT_Headers64_Type;
   type Image_NT_Headers64_Ptr is access all Image_NT_Headers64_Type;
   type Image_NT_Headers64_CPtr is access constant Image_NT_Headers64_Type;
   type Image_NT_Headers64_Type is record
      Signature : Unsigned_32;
      File_Header : Image_File_Header_Type;
      Optional_Header : IMAGE_OPTIONAL_HEADER64;
   end record;

--%%   PIMAGE_NT_HEADERS32 = ^IMAGE_NT_HEADERS32;
--%%   {$EXTERNALSYM PIMAGE_NT_HEADERS32}
--%%   _IMAGE_NT_HEADERS = record
--%%     Signature: DWORD;
--%%     FileHeader: IMAGE_FILE_HEADER;
--%%     OptionalHeader: IMAGE_OPTIONAL_HEADER32;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_NT_HEADERS}
--%%   IMAGE_NT_HEADERS32 = _IMAGE_NT_HEADERS;
--%%   {$EXTERNALSYM IMAGE_NT_HEADERS32}
--%%   TImageNtHeaders32 = IMAGE_NT_HEADERS32;
--%%   PImageNtHeaders32 = PIMAGE_NT_HEADERS32;

   type Image_Rom_Headers_Type;
   type Image_Rom_Headers_Ptr is access all Image_Rom_Headers_Type;
   type Image_Rom_Headers_CPtr is access constant Image_Rom_Headers_Type;
   type Image_Rom_Headers_Type is record
      File_Header : Image_File_Header_Type;
      Optional_Header : IMAGE_ROM_OPTIONAL_HEADER;
   end record;

--%%   IMAGE_NT_HEADERS = IMAGE_NT_HEADERS32;
--%%   {$EXTERNALSYM IMAGE_NT_HEADERS}
--%%   PIMAGE_NT_HEADERS = PIMAGE_NT_HEADERS32;
--%%   {$EXTERNALSYM PIMAGE_NT_HEADERS}

--%%   PImageNtHeaders = PIMAGE_NT_HEADERS;

-- Subsystem Values

   Image_Subsystem_Unknown                 : constant := 0; -- Unknown subsystem.
   Image_Subsystem_Native                  : constant := 1; -- Image doesn't require a subsystem.
   Image_Subsystem_Windows_Gui             : constant := 2; -- Image runs in the Windows GUI subsystem.
   Image_Subsystem_Windows_Cui             : constant := 3; -- Image runs in the Windows character subsystem.
   Image_Subsystem_Os2_Cui                 : constant := 5; -- image runs in the OS/2 character subsystem.
   Image_Subsystem_Posix_Cui               : constant := 7; -- image runs in the Posix character subsystem.
   Image_Subsystem_Native_Windows          : constant := 8; -- image is a native Win9x driver.
   Image_Subsystem_Windows_Ce_Gui          : constant := 9; -- Image runs in the Windows CE subsystem.
   Image_Subsystem_Efi_Application         : constant := 10;
   Image_Subsystem_Efi_Boot_Service_Driver : constant := 11;
   Image_Subsystem_Efi_Runtime_Driver      : constant := 12;
   Image_Subsystem_Efi_Rom                 : constant := 13;
   Image_Subsystem_Xbox                    : constant := 14;

-- DllCharacteristics Entries

--      IMAGE_LIBRARY_PROCESS_INIT           0x0001     // Reserved.
--      IMAGE_LIBRARY_PROCESS_TERM           0x0002     // Reserved.
--      IMAGE_LIBRARY_THREAD_INIT            0x0004     // Reserved.
--      IMAGE_LIBRARY_THREAD_TERM            0x0008     // Reserved.
   Image_Dllcharacteristics_No_Isolation : constant := 16#0200#;    -- Image understands isolation and doesn't want it
   Image_Dllcharacteristics_No_Seh  : constant := 16#0400#; -- Image does not use SEH.  No SE handler may reside in this image
   Image_Dllcharacteristics_No_Bind : constant := 16#0800#; -- Do not bind this image.

--                                           0x1000     // Reserved.

   Image_Dllcharacteristics_Wdm_Driver : constant := 16#2000#; -- Driver uses WDM model

--                                           0x4000     // Reserved.

   Image_Dllcharacteristics_Terminal_Server_Aware : constant := 16#8000#;

-- Directory Entries

   Image_Directory_Entry_Export    : constant := 0; -- Export Directory
   Image_Directory_Entry_Import    : constant := 1; -- Import Directory
   Image_Directory_Entry_Resource  : constant := 2; -- Resource Directory
   Image_Directory_Entry_Exception : constant := 3; -- Exception Directory
   Image_Directory_Entry_Security  : constant := 4; -- Security Directory
   Image_Directory_Entry_Basereloc : constant := 5; -- Base Relocation Table
   Image_Directory_Entry_Debug     : constant := 6; -- Debug Directory

--      IMAGE_DIRECTORY_ENTRY_COPYRIGHT       7   // (X86 usage)

   Image_Directory_Entry_Architecture   : constant := 7; -- Architecture Specific Data
   Image_Directory_Entry_Globalptr      : constant := 8; -- RVA of GP
   Image_Directory_Entry_Tls            : constant := 9; -- TLS Directory
   Image_Directory_Entry_Load_Config    : constant := 10; -- Load Configuration Directory
   Image_Directory_Entry_Bound_Import   : constant := 11; -- Bound Import Directory in headers
   Image_Directory_Entry_Iat            : constant := 12; -- Import Address Table
   Image_Directory_Entry_Delay_Import   : constant := 13; -- Delay Load Import Descriptors
   Image_Directory_Entry_COM_Descriptor : constant := 14; -- COM Runtime descriptor

--
-- Non-COFF Object file header
--

--%%   PAnonObjectHeader = ^ANON_OBJECT_HEADER;
--%%   ANON_OBJECT_HEADER = record
--%%     Sig1: Word;        // Must be IMAGE_FILE_MACHINE_UNKNOWN
--%%     Sig2: Word;        // Must be 0xffff
--%%     Version: Word;     // >= 1 (implies the CLSID field is present)
--%%     Machine: Word;
--%%     TimeDateStamp: DWORD;
--%%     ClassID: CLSID;    // Used to invoke CoCreateInstance
--%%     SizeOfData: DWORD; // Size of data that follows the header
--%%   end;
--%%   {$EXTERNALSYM ANON_OBJECT_HEADER}
--%%   TAnonObjectHeader = ANON_OBJECT_HEADER;

--
-- Section header format.
--

   Image_Sizeof_Short_Name : constant := 8;

--%%   TImgSecHdrMisc = record
--%%     case Integer of
--%%       0: (PhysicalAddress: DWORD);
--%%       1: (VirtualSize: DWORD);
--%%   end;

--%%   PIMAGE_SECTION_HEADER = ^IMAGE_SECTION_HEADER;
--%%   {$EXTERNALSYM PIMAGE_SECTION_HEADER}
--%%   _IMAGE_SECTION_HEADER = record
--%%     Name: array [0..IMAGE_SIZEOF_SHORT_NAME - 1] of BYTE;
--%%     Misc: TImgSecHdrMisc;
--%%     VirtualAddress: DWORD;
--%%     SizeOfRawData: DWORD;
--%%     PointerToRawData: DWORD;
--%%     PointerToRelocations: DWORD;
--%%     PointerToLinenumbers: DWORD;
--%%     NumberOfRelocations: WORD;
--%%     NumberOfLinenumbers: WORD;
--%%     Characteristics: DWORD;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_SECTION_HEADER}
--%%   IMAGE_SECTION_HEADER = _IMAGE_SECTION_HEADER;
--%%   {$EXTERNALSYM IMAGE_SECTION_HEADER}
--%%   TImageSectionHeader = IMAGE_SECTION_HEADER;
--%%   PImageSectionHeader = PIMAGE_SECTION_HEADER;

-- IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.

--%% function IMAGE_FIRST_SECTION(NtHeader: PImageNtHeaders): PImageSectionHeader;
--%% {$EXTERNALSYM IMAGE_FIRST_SECTION}
--%%   
   Image_Sizeof_Section_Header : constant := 40;

--
-- Section characteristics.
--
--      IMAGE_SCN_TYPE_REG                   0x00000000  // Reserved.
--      IMAGE_SCN_TYPE_DSECT                 0x00000001  // Reserved.
--      IMAGE_SCN_TYPE_NOLOAD                0x00000002  // Reserved.
--      IMAGE_SCN_TYPE_GROUP                 0x00000004  // Reserved.

   Image_Scn_Type_No_Pad : constant := 16#0000_0008#; -- Reserved.

--      IMAGE_SCN_TYPE_COPY                  0x00000010  // Reserved.

   Image_Scn_Cnt_Code               : constant := 16#0000_0020#; -- Section contains code.
   Image_Scn_Cnt_Initialized_Data   : constant := 16#0000_0040#; -- Section contains initialized data.
   Image_Scn_Cnt_Uninitialized_Data : constant := 16#0000_0080#; -- Section contains uninitialized data.

   Image_Scn_Lnk_Other : constant := 16#0000_0100#; -- Reserved.
   Image_Scn_Lnk_Info  : constant := 16#0000_0200#; -- Section contains comments or some other type of information.

--      IMAGE_SCN_TYPE_OVER                  0x00000400  // Reserved.

   Image_Scn_Lnk_Remove : constant := 16#0000_0800#; -- Section contents will not become part of image.
   Image_Scn_Lnk_Comdat : constant := 16#0000_1000#; -- Section contents comdat.

--                                           0x00002000  // Reserved.
--      IMAGE_SCN_MEM_PROTECTED - Obsolete   0x00004000

   Image_Scn_No_Defer_Spec_Exc : constant := 16#0000_4000#; -- Reset speculative exceptions handling bits in the TLB entries for this section.
   Image_Scn_Gprel             : constant := 16#0000_8000#; -- Section content can be accessed relative to GP
   Image_Scn_Mem_Fardata       : constant := 16#0000_8000#;

--      IMAGE_SCN_MEM_SYSHEAP  - Obsolete    0x00010000

   Image_Scn_Mem_Purgeable : constant := 16#0002_0000#;
   Image_Scn_Mem_16Bit     : constant := 16#0002_0000#;
   Image_Scn_Mem_Locked    : constant := 16#0004_0000#;
   Image_Scn_Mem_Preload   : constant := 16#0008_0000#;

   Image_Scn_Align_1Bytes    : constant := 16#0010_0000#;
   Image_Scn_Align_2Bytes    : constant := 16#0020_0000#;
   Image_Scn_Align_4Bytes    : constant := 16#0030_0000#;
   Image_Scn_Align_8Bytes    : constant := 16#0040_0000#;
   Image_Scn_Align_16Bytes   : constant := 16#0050_0000#; -- Default alignment if no others are specified.
   Image_Scn_Align_32Bytes   : constant := 16#0060_0000#;
   Image_Scn_Align_64Bytes   : constant := 16#0070_0000#;
   Image_Scn_Align_128Bytes  : constant := 16#0080_0000#;
   Image_Scn_Align_256Bytes  : constant := 16#0090_0000#;
   Image_Scn_Align_512Bytes  : constant := 16#00A0_0000#;
   Image_Scn_Align_1024Bytes : constant := 16#00B0_0000#;
   Image_Scn_Align_2048Bytes : constant := 16#00C0_0000#;
   Image_Scn_Align_4096Bytes : constant := 16#00D0_0000#;
   Image_Scn_Align_8192Bytes : constant := 16#00E0_0000#;

-- Unused                                    0x00F00000

   Image_Scn_Align_Mask : constant := 16#00F0_0000#;

   Image_Scn_Lnk_Nreloc_Ovfl : constant := 16#0100_0000#; -- Section contains extended relocations.
   Image_Scn_Mem_Discardable : constant := 16#0200_0000#; -- Section can be discarded.
   Image_Scn_Mem_Not_Cached  : constant := 16#0400_0000#; -- Section is not cachable.
   Image_Scn_Mem_Not_Paged   : constant := 16#0800_0000#; -- Section is not pageable.
   Image_Scn_Mem_Shared      : constant := 16#1000_0000#; -- Section is shareable.
   Image_Scn_Mem_Execute     : constant := 16#2000_0000#; -- Section is executable.
   Image_Scn_Mem_Read        : constant := 16#4000_0000#; -- Section is readable.
   Image_Scn_Mem_Write       : constant := 16#8000_0000#; -- Section is writeable.

--
-- TLS Chaacteristic Flags
--

   Image_Scn_Scale_Index : constant := 16#0000_0001#; -- Tls index is scaled

-- #include "pshpack2.h"                       // Symbols, relocs, and linenumbers are 2 byte packed

--
-- Symbol format.
--

--%%   TImageSymbolN = record
--%%     case Integer of
--%%       0: (
--%%         ShortName: array [0..7] of BYTE);
--%%       1: (
--%%         Short: DWORD;     // if 0, use LongName
--%%         Long: DWORD);     // offset into string table
--%%       2: (
--%%         LongName: array [0..1] of DWORD);
--%%   end;

   type Image_Symbol_Type;
   type Image_Symbol_Ptr is access all Image_Symbol_Type;
   type Image_Symbol_CPtr is access constant Image_Symbol_Type;
   type Image_Symbol_Type is record
      N : Image_Symbol_N_Type;
      Value : Unsigned_32;
      Section_Number : Integer_16;
      Type_ : Unsigned_16;
      Storage_Class : Unsigned_8;
      Number_Of_Aux_Symbols : Unsigned_8;
   end record;

   Image_Sizeof_Symbol : constant := 18;

--
-- Section values.
--
-- Symbols have a section number of the section in which they are
-- defined. Otherwise, section numbers have the following meanings:
--

--%%   IMAGE_SYM_UNDEFINED = SHORT(0);  // Symbol is undefined or is common.
--%%   {$EXTERNALSYM IMAGE_SYM_UNDEFINED}
--%%   IMAGE_SYM_ABSOLUTE  = SHORT(-1); // Symbol is an absolute value.
--%%   {$EXTERNALSYM IMAGE_SYM_ABSOLUTE}
--%%   IMAGE_SYM_DEBUG     = SHORT(-2); // Symbol is a special debug item.
--%%   {$EXTERNALSYM IMAGE_SYM_DEBUG}
--%%   IMAGE_SYM_SECTION_MAX = SHORT($FEFF ); // Values 0xFF00-0xFFFF are special
--%%   {$EXTERNALSYM IMAGE_SYM_SECTION_MAX}

--
-- Type (fundamental) values.
--

   Image_Sym_Type_Null   : constant := 16#0000#; -- no type.
   Image_Sym_Type_Void   : constant := 16#0001#;
   Image_Sym_Type_Char   : constant := 16#0002#; -- type character.
   Image_Sym_Type_Short  : constant := 16#0003#; -- type short integer.
   Image_Sym_Type_Int    : constant := 16#0004#;
   Image_Sym_Type_Long   : constant := 16#0005#;
   Image_Sym_Type_Float  : constant := 16#0006#;
   Image_Sym_Type_Double : constant := 16#0007#;
   Image_Sym_Type_Struct : constant := 16#0008#;
   Image_Sym_Type_Union  : constant := 16#0009#;
   Image_Sym_Type_Enum   : constant := 16#000A#; -- enumeration.
   Image_Sym_Type_Moe    : constant := 16#000B#; -- member of enumeration.
   Image_Sym_Type_Byte   : constant := 16#000C#;
   Image_Sym_Type_Word   : constant := 16#000D#;
   Image_Sym_Type_Uint   : constant := 16#000E#;
   Image_Sym_Type_DWord  : constant := 16#000F#;
   Image_Sym_Type_Pcode  : constant := 16#8000#;

--
-- Type (derived) values.
--

   Image_Sym_Dtype_Null     : constant := 0; -- no derived type.
   Image_Sym_Dtype_Pointer  : constant := 1; -- pointer.
   Image_Sym_Dtype_Function : constant := 2; -- function.
   Image_Sym_Dtype_Array    : constant := 3; -- array.

--
-- Storage classes.
--

--%%   IMAGE_SYM_CLASS_END_OF_FUNCTION  = BYTE(-1);
--%%   {$EXTERNALSYM IMAGE_SYM_CLASS_END_OF_FUNCTION}
   Image_Sym_Class_Null             : constant := 16#0000#;
   Image_Sym_Class_Automatic        : constant := 16#0001#;
   Image_Sym_Class_External         : constant := 16#0002#;
   Image_Sym_Class_Static           : constant := 16#0003#;
   Image_Sym_Class_Register         : constant := 16#0004#;
   Image_Sym_Class_External_Def     : constant := 16#0005#;
   Image_Sym_Class_Label            : constant := 16#0006#;
   Image_Sym_Class_Undefined_Label  : constant := 16#0007#;
   Image_Sym_Class_Member_Of_Struct : constant := 16#0008#;
   Image_Sym_Class_Argument         : constant := 16#0009#;
   Image_Sym_Class_Struct_Tag       : constant := 16#000A#;
   Image_Sym_Class_Member_Of_Union  : constant := 16#000B#;
   Image_Sym_Class_Union_Tag        : constant := 16#000C#;
   Image_Sym_Class_Type_Definition  : constant := 16#000D#;
   Image_Sym_Class_Undefined_Static : constant := 16#000E#;
   Image_Sym_Class_Enum_Tag         : constant := 16#000F#;
   Image_Sym_Class_Member_Of_Enum   : constant := 16#0010#;
   Image_Sym_Class_Register_Param   : constant := 16#0011#;
   Image_Sym_Class_Bit_Field        : constant := 16#0012#;

   Image_Sym_Class_Far_External : constant := 16#0044#;

   Image_Sym_Class_Block         : constant := 16#0064#;
   Image_Sym_Class_Function      : constant := 16#0065#;
   Image_Sym_Class_End_Of_Struct : constant := 16#0066#;
   Image_Sym_Class_File          : constant := 16#0067#;

-- new

   Image_Sym_Class_Section       : constant := 16#0068#;
   Image_Sym_Class_Weak_External : constant := 16#0069#;

   Image_Sym_Class_Clr_Token     : constant := 16#006B#;

-- type packing constants

   N_Btmask : constant := 16#000F#;
   N_Tmask  : constant := 16#0030#;
   N_Tmask1 : constant := 16#00C0#;
   N_Tmask2 : constant := 16#00F0#;
   N_Btshft : constant := 4;
   N_Tshift : constant := 2;

-- MACROS

-- Basic Type of  x

--%% function BTYPE(x: DWORD): DWORD;
--%% {$EXTERNALSYM BTYPE}

-- Is x a pointer?

--%% function ISPTR(x: DWORD): Boolean;
--%% {$EXTERNALSYM ISPTR}

-- Is x a function?

--%% function ISFCN(x: DWORD): Boolean;
--%% {$EXTERNALSYM ISFCN}

-- Is x an array?

--%% function ISARY(x: DWORD): Boolean;
--%% {$EXTERNALSYM ISARY}

-- Is x a structure, union, or enumeration TAG?

--%% function ISTAG(x: DWORD): Boolean;
--%% {$EXTERNALSYM ISTAG}

--
-- Auxiliary entry format.
--

--%%   TImgAuzSymSymMisc = record
--%%     case Integer of
--%%       0: (
--%%         Linenumber: WORD;             // declaration line number
--%%         Size: WORD);                  // size of struct, union, or enum
--%%       1: (
--%%         TotalSize: DWORD);
--%%   end;

--%%   TImgAuzSymSymFcnAry = record
--%%     case Integer of
--%%       0: ( // if ISFCN, tag, or .bb
--%%         PointerToLinenumber: DWORD;
--%%         PointerToNextFunction: DWORD);
--%%       1: ( // if ISARY, up to 4 dimen.
--%%         Dimension: array [0..3] of WORD);
--%%   end;

--%%   TImgAuxSymSym = record
--%%     TagIndex: DWORD;                      // struct, union, or enum tag index
--%%     Misc: TImgAuzSymSymMisc;
--%%     FcnAry: TImgAuzSymSymFcnAry;
--%%     TvIndex: WORD;                        // tv index
--%%   end;

--%%   TImgAuxSymFile = record
--%%     Name: array [0..IMAGE_SIZEOF_SYMBOL - 1] of BYTE;
--%%   end;

--%%   TImgAuxSymSection = record
--%%     Length: DWORD;                         // section length
--%%     NumberOfRelocations: WORD;             // number of relocation entries
--%%     NumberOfLinenumbers: WORD;             // number of line numbers
--%%     CheckSum: DWORD;                       // checksum for communal
--%%     Number: SHORT;                         // section number to associate with
--%%     Selection: BYTE;                       // communal selection type
--%%   end;

--%%   PIMAGE_AUX_SYMBOL = ^IMAGE_AUX_SYMBOL;
--%%   {$EXTERNALSYM PIMAGE_AUX_SYMBOL}
--%%   _IMAGE_AUX_SYMBOL = record
--%%     case Integer of
--%%       0: (Sym: TImgAuxSymSym);
--%%       1: (File_: TImgAuxSymFile);
--%%       2: (Section: TImgAuxSymSection);
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_AUX_SYMBOL}
--%%   IMAGE_AUX_SYMBOL = _IMAGE_AUX_SYMBOL;
--%%   {$EXTERNALSYM IMAGE_AUX_SYMBOL}
--%%   TImageAuxSymbol = IMAGE_AUX_SYMBOL;
--%%   PImageAuxSymbol = PIMAGE_AUX_SYMBOL;

   Image_Sizeof_Aux_Symbol : constant := 18;

   Image_Aux_Symbol_Type_Token_Def : constant := 1;

   subtype Image_Aux_Symbol_Type_Type is Unsigned_32;
   subtype Image_Aux_Symbol_Type_Ptr is Unsigned_32_Ptr;
   subtype Image_Aux_Symbol_Type_CPtr is Unsigned_32_CPtr;
--%%   TImageAuxSymbolType = IMAGE_AUX_SYMBOL_TYPE;

--%%   IMAGE_AUX_SYMBOL_TOKEN_DEF = packed record
--%%     bAuxType: BYTE;                  // IMAGE_AUX_SYMBOL_TYPE
--%%     bReserved: BYTE;                 // Must be 0
--%%     SymbolTableIndex: DWORD;
--%%     rgbReserved: array [0..11] of BYTE;           // Must be 0
--%%   end;
--%%   {$EXTERNALSYM IMAGE_AUX_SYMBOL_TOKEN_DEF}
--%%   PIMAGE_AUX_SYMBOL_TOKEN_DEF = ^IMAGE_AUX_SYMBOL_TOKEN_DEF;
--%%   {$EXTERNALSYM PIMAGE_AUX_SYMBOL_TOKEN_DEF}
--%%   TImageAuxSymbolTokenDef = IMAGE_AUX_SYMBOL_TOKEN_DEF;
--%%   PImageAuxSymbolTokenDef = PIMAGE_AUX_SYMBOL_TOKEN_DEF;

--
-- Communal selection types.
--

   Image_Comdat_Select_Noduplicates : constant := 1;
   Image_Comdat_Select_Any          : constant := 2;
   Image_Comdat_Select_Same_Size    : constant := 3;
   Image_Comdat_Select_Exact_Match  : constant := 4;
   Image_Comdat_Select_Associative  : constant := 5;
   Image_Comdat_Select_Largest      : constant := 6;
   Image_Comdat_Select_Newest       : constant := 7;

   Image_Weak_Extern_Search_Nolibrary : constant := 1;
   Image_Weak_Extern_Search_Library   : constant := 2;
   Image_Weak_Extern_Search_Alias     : constant := 3;

--
-- Relocation format.
--

--%%   TImgRelocUnion = record
--%%     case Integer of
--%%       0: (VirtualAddress: DWORD);
--%%       1: (RelocCount: DWORD);  // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
--%%   end;

   type Image_Relocation_Type;
   type Image_Relocation_Ptr is access all Image_Relocation_Type;
   type Image_Relocation_CPtr is access constant Image_Relocation_Type;
   type Image_Relocation_Type is record
      Union : Img_Reloc_Union_Type;
      Symbol_Table_Index : Unsigned_32;
      Type_ : Unsigned_16;
   end record;

   Image_Sizeof_Relocation : constant := 10;

--
-- I386 relocation types.
--

   Image_Rel_I386_Absolute : constant := 16#0000#; -- Reference is absolute, no relocation is necessary
   Image_Rel_I386_Dir16    : constant := 16#0001#; -- Direct 16-bit reference to the symbols virtual address
   Image_Rel_I386_Rel16    : constant := 16#0002#; -- PC-relative 16-bit reference to the symbols virtual address
   Image_Rel_I386_Dir32    : constant := 16#0006#; -- Direct 32-bit reference to the symbols virtual address
   Image_Rel_I386_Dir32Nb  : constant := 16#0007#; -- Direct 32-bit reference to the symbols virtual address, base not included
   Image_Rel_I386_Seg12    : constant := 16#0009#; -- Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
   Image_Rel_I386_Section  : constant := 16#000A#;
   Image_Rel_I386_Secrel   : constant := 16#000B#;
   Image_Rel_MIPS_Secrello : constant := 16#000C#; -- Low 16-bit section relative referemce (used for >32k TLS)
   Image_Rel_MIPS_Secrelhi : constant := 16#000D#; -- High 16-bit section relative reference (used for >32k TLS)
   Image_Rel_I386_Rel32    : constant := 16#0014#; -- PC-relative 32-bit reference to the symbols virtual address

--
-- MIPS relocation types.
--

   Image_Rel_MIPS_Absolute  : constant := 16#0000#; -- Reference is absolute, no relocation is necessary
   Image_Rel_MIPS_Refhalf   : constant := 16#0001#;
   Image_Rel_MIPS_Refword   : constant := 16#0002#;
   Image_Rel_MIPS_Jmpaddr   : constant := 16#0003#;
   Image_Rel_MIPS_Refhi     : constant := 16#0004#;
   Image_Rel_MIPS_Reflo     : constant := 16#0005#;
   Image_Rel_MIPS_Gprel     : constant := 16#0006#;
   Image_Rel_MIPS_Literal   : constant := 16#0007#;
   Image_Rel_MIPS_Section   : constant := 16#000A#;
   Image_Rel_MIPS_Secrel    : constant := 16#000B#;
--%%   //IMAGE_REL_MIPS_SECRELLO  = $000C; // Low 16-bit section relative referemce (used for >32k TLS)
--%%   //{$EXTERNALSYM IMAGE_REL_MIPS_SECRELLO}
--%%   //IMAGE_REL_MIPS_SECRELHI  = $000D; // High 16-bit section relative reference (used for >32k TLS)
--%%   //{$EXTERNALSYM IMAGE_REL_MIPS_SECRELHI}
   Image_Rel_MIPS_Token     : constant := 16#000E#; -- clr token
   Image_Rel_MIPS_Jmpaddr16 : constant := 16#0010#;
   Image_Rel_MIPS_Refwordnb : constant := 16#0022#;
   Image_Rel_MIPS_Pair      : constant := 16#0025#;

--
-- Alpha Relocation types.
--

   Image_Rel_Alpha_Absolute       : constant := 16#0000#;
   Image_Rel_Alpha_Reflong        : constant := 16#0001#;
   Image_Rel_Alpha_Refquad        : constant := 16#0002#;
   Image_Rel_Alpha_Gprel32        : constant := 16#0003#;
   Image_Rel_Alpha_Literal        : constant := 16#0004#;
   Image_Rel_Alpha_Lituse         : constant := 16#0005#;
   Image_Rel_Alpha_Gpdisp         : constant := 16#0006#;
   Image_Rel_Alpha_Braddr         : constant := 16#0007#;
   Image_Rel_Alpha_Hint           : constant := 16#0008#;
   Image_Rel_Alpha_Inline_Reflong : constant := 16#0009#;
   Image_Rel_Alpha_Refhi          : constant := 16#000A#;
   Image_Rel_Alpha_Reflo          : constant := 16#000B#;
   Image_Rel_Alpha_Pair           : constant := 16#000C#;
   Image_Rel_Alpha_Match          : constant := 16#000D#;
   Image_Rel_Alpha_Section        : constant := 16#000E#;
   Image_Rel_Alpha_Secrel         : constant := 16#000F#;
   Image_Rel_Alpha_Reflongnb      : constant := 16#0010#;
   Image_Rel_Alpha_Secrello       : constant := 16#0011#; -- Low 16-bit section relative reference
   Image_Rel_Alpha_Secrelhi       : constant := 16#0012#; -- High 16-bit section relative reference
   Image_Rel_Alpha_Refq3          : constant := 16#0013#; -- High 16 bits of 48 bit reference
   Image_Rel_Alpha_Refq2          : constant := 16#0014#; -- Middle 16 bits of 48 bit reference
   Image_Rel_Alpha_Refq1          : constant := 16#0015#; -- Low 16 bits of 48 bit reference
   Image_Rel_Alpha_Gprello        : constant := 16#0016#; -- Low 16-bit GP relative reference
   Image_Rel_Alpha_Gprelhi        : constant := 16#0017#; -- High 16-bit GP relative reference

--
-- IBM PowerPC relocation types.
--

   Image_Rel_PPC_Absolute : constant := 16#0000#; -- NOP
   Image_Rel_PPC_Addr64   : constant := 16#0001#; -- 64-bit address
   Image_Rel_PPC_Addr32   : constant := 16#0002#; -- 32-bit address
   Image_Rel_PPC_Addr24   : constant := 16#0003#; -- 26-bit address, shifted left 2 (branch absolute)
   Image_Rel_PPC_Addr16   : constant := 16#0004#; -- 16-bit address
   Image_Rel_PPC_Addr14   : constant := 16#0005#; -- 16-bit address, shifted left 2 (load doubleword)
   Image_Rel_PPC_Rel24    : constant := 16#0006#; -- 26-bit PC-relative offset, shifted left 2 (branch relative)
   Image_Rel_PPC_Rel14    : constant := 16#0007#; -- 16-bit PC-relative offset, shifted left 2 (br cond relative)
   Image_Rel_PPC_Tocrel16 : constant := 16#0008#; -- 16-bit offset from TOC base
   Image_Rel_PPC_Tocrel14 : constant := 16#0009#; -- 16-bit offset from TOC base, shifted left 2 (load doubleword)

   Image_Rel_PPC_Addr32Nb : constant := 16#000A#; -- 32-bit addr w/o image base
   Image_Rel_PPC_Secrel   : constant := 16#000B#; -- va of containing section (as in an image sectionhdr)
   Image_Rel_PPC_Section  : constant := 16#000C#; -- sectionheader number
   Image_Rel_PPC_Ifglue   : constant := 16#000D#; -- substitute TOC restore instruction iff symbol is glue code
   Image_Rel_PPC_Imglue   : constant := 16#000E#; -- symbol is glue code; virtual address is TOC restore instruction
   Image_Rel_PPC_Secrel16 : constant := 16#000F#; -- va of containing section (limited to 16 bits)
   Image_Rel_PPC_Refhi    : constant := 16#0010#;
   Image_Rel_PPC_Reflo    : constant := 16#0011#;
   Image_Rel_PPC_Pair     : constant := 16#0012#;
   Image_Rel_PPC_Secrello : constant := 16#0013#; -- Low 16-bit section relative reference (used for >32k TLS)
   Image_Rel_PPC_Secrelhi : constant := 16#0014#; -- High 16-bit section relative reference (used for >32k TLS)
   Image_Rel_PPC_Gprel    : constant := 16#0015#;
   Image_Rel_PPC_Token    : constant := 16#0016#; -- clr token

   Image_Rel_PPC_Typemask : constant := 16#00FF#; -- mask to isolate above values in IMAGE_RELOCATION.Type

-- Flag bits in IMAGE_RELOCATION.TYPE

   Image_Rel_PPC_Neg      : constant := 16#0100#; -- subtract reloc value rather than adding it
   Image_Rel_PPC_Brtaken  : constant := 16#0200#; -- fix branch prediction bit to predict branch taken
   Image_Rel_PPC_Brntaken : constant := 16#0400#; -- fix branch prediction bit to predict branch not taken
   Image_Rel_PPC_Tocdefn  : constant := 16#0800#; -- toc slot defined in file (or, data in toc)

--
-- Hitachi SH3 relocation types.
--

   Image_Rel_Sh3_Absolute        : constant := 16#0000#; -- No relocation
   Image_Rel_Sh3_Direct16        : constant := 16#0001#; -- 16 bit direct
   Image_Rel_Sh3_Direct32        : constant := 16#0002#; -- 32 bit direct
   Image_Rel_Sh3_Direct8         : constant := 16#0003#; -- 8 bit direct, -128..255
   Image_Rel_Sh3_Direct8_Word    : constant := 16#0004#; -- 8 bit direct .W (0 ext.)
   Image_Rel_Sh3_Direct8_Long    : constant := 16#0005#; -- 8 bit direct .L (0 ext.)
   Image_Rel_Sh3_Direct4         : constant := 16#0006#; -- 4 bit direct (0 ext.)
   Image_Rel_Sh3_Direct4_Word    : constant := 16#0007#; -- 4 bit direct .W (0 ext.)
   Image_Rel_Sh3_Direct4_Long    : constant := 16#0008#; -- 4 bit direct .L (0 ext.)
   Image_Rel_Sh3_Pcrel8_Word     : constant := 16#0009#; -- 8 bit PC relative .W
   Image_Rel_Sh3_Pcrel8_Long     : constant := 16#000A#; -- 8 bit PC relative .L
   Image_Rel_Sh3_Pcrel12_Word    : constant := 16#000B#; -- 12 LSB PC relative .W
   Image_Rel_Sh3_Startof_Section : constant := 16#000C#; -- Start of EXE section
   Image_Rel_Sh3_Sizeof_Section  : constant := 16#000D#; -- Size of EXE section
   Image_Rel_Sh3_Section         : constant := 16#000E#; -- Section table index
   Image_Rel_Sh3_Secrel          : constant := 16#000F#; -- Offset within section
   Image_Rel_Sh3_Direct32_Nb     : constant := 16#0010#; -- 32 bit direct not based
   Image_Rel_Sh3_Gprel4_Long     : constant := 16#0011#; -- GP-relative addressing
   Image_Rel_Sh3_Token           : constant := 16#0012#; -- clr token

   Image_Rel_ARM_Absolute : constant := 16#0000#; -- No relocation required
   Image_Rel_ARM_Addr32   : constant := 16#0001#; -- 32 bit address
   Image_Rel_ARM_Addr32Nb : constant := 16#0002#; -- 32 bit address w/o image base
   Image_Rel_ARM_Branch24 : constant := 16#0003#; -- 24 bit offset << 2 & sign ext.
   Image_Rel_ARM_Branch11 : constant := 16#0004#; -- Thumb: 2 11 bit offsets
   Image_Rel_ARM_Token    : constant := 16#0005#; -- clr token
   Image_Rel_ARM_Gprel12  : constant := 16#0006#; -- GP-relative addressing (ARM)
   Image_Rel_ARM_Gprel7   : constant := 16#0007#; -- GP-relative addressing (Thumb)
   Image_Rel_ARM_Blx24    : constant := 16#0008#;
   Image_Rel_ARM_Blx11    : constant := 16#0009#;
   Image_Rel_ARM_Section  : constant := 16#000E#; -- Section table index
   Image_Rel_ARM_Secrel   : constant := 16#000F#; -- Offset within section

   Image_Rel_Am_Absolute : constant := 16#0000#;
   Image_Rel_Am_Addr32   : constant := 16#0001#;
   Image_Rel_Am_Addr32Nb : constant := 16#0002#;
   Image_Rel_Am_Call32   : constant := 16#0003#;
   Image_Rel_Am_Funcinfo : constant := 16#0004#;
   Image_Rel_Am_Rel32_1  : constant := 16#0005#;
   Image_Rel_Am_Rel32_2  : constant := 16#0006#;
   Image_Rel_Am_Secrel   : constant := 16#0007#;
   Image_Rel_Am_Section  : constant := 16#0008#;
   Image_Rel_Am_Token    : constant := 16#0009#;

--
-- X86-64 relocations
--

   Image_Rel_AMD64_Absolute : constant := 16#0000#; -- Reference is absolute, no relocation is necessary
   Image_Rel_AMD64_Addr64   : constant := 16#0001#; -- 64-bit address (VA).
   Image_Rel_AMD64_Addr32   : constant := 16#0002#; -- 32-bit address (VA).
   Image_Rel_AMD64_Addr32Nb : constant := 16#0003#; -- 32-bit address w/o image base (RVA).
   Image_Rel_AMD64_Rel32    : constant := 16#0004#; -- 32-bit relative address from byte following reloc
   Image_Rel_AMD64_Rel32_1  : constant := 16#0005#; -- 32-bit relative address from byte distance 1 from reloc
   Image_Rel_AMD64_Rel32_2  : constant := 16#0006#; -- 32-bit relative address from byte distance 2 from reloc
   Image_Rel_AMD64_Rel32_3  : constant := 16#0007#; -- 32-bit relative address from byte distance 3 from reloc
   Image_Rel_AMD64_Rel32_4  : constant := 16#0008#; -- 32-bit relative address from byte distance 4 from reloc
   Image_Rel_AMD64_Rel32_5  : constant := 16#0009#; -- 32-bit relative address from byte distance 5 from reloc
   Image_Rel_AMD64_Section  : constant := 16#000A#; -- Section index
   Image_Rel_AMD64_Secrel   : constant := 16#000B#; -- 32 bit offset from base of section containing target
   Image_Rel_AMD64_Secrel7  : constant := 16#000C#; -- 7 bit unsigned offset from base of section containing target
   Image_Rel_AMD64_Token    : constant := 16#000D#; -- 32 bit metadata token
   Image_Rel_AMD64_Srel32   : constant := 16#000E#;  -- 32 bit signed span-dependent value emitted into object
   Image_Rel_AMD64_Pair     : constant := 16#000F#;
   Image_Rel_AMD64_Sspan32  : constant := 16#0010#;  -- 32 bit signed span-dependent value applied at link time

--
-- IA64 relocation types.
--

   Image_Rel_IA64_Absolute  : constant := 16#0000#;
   Image_Rel_IA64_Imm14     : constant := 16#0001#;
   Image_Rel_IA64_Imm22     : constant := 16#0002#;
   Image_Rel_IA64_Imm64     : constant := 16#0003#;
   Image_Rel_IA64_Dir32     : constant := 16#0004#;
   Image_Rel_IA64_Dir64     : constant := 16#0005#;
   Image_Rel_IA64_Pcrel21B  : constant := 16#0006#;
   Image_Rel_IA64_Pcrel21M  : constant := 16#0007#;
   Image_Rel_IA64_Pcrel21F  : constant := 16#0008#;
   Image_Rel_IA64_Gprel22   : constant := 16#0009#;
   Image_Rel_IA64_Ltoff22   : constant := 16#000A#;
   Image_Rel_IA64_Section   : constant := 16#000B#;
   Image_Rel_IA64_Secrel22  : constant := 16#000C#;
   Image_Rel_IA64_Secrel64I : constant := 16#000D#;
   Image_Rel_IA64_Secrel32  : constant := 16#000E#;

--

   Image_Rel_IA64_Dir32Nb    : constant := 16#0010#;
   Image_Rel_IA64_Srel14     : constant := 16#0011#;
   Image_Rel_IA64_Srel22     : constant := 16#0012#;
   Image_Rel_IA64_Srel32     : constant := 16#0013#;
   Image_Rel_IA64_Urel32     : constant := 16#0014#;
   Image_Rel_IA64_Pcrel60X   : constant := 16#0015#; -- This is always a BRL and never converted
   Image_Rel_IA64_Pcrel60B   : constant := 16#0016#; -- If possible, convert to MBB bundle with NOP.B in slot 1
   Image_Rel_IA64_Pcrel60F   : constant := 16#0017#; -- If possible, convert to MFB bundle with NOP.F in slot 1
   Image_Rel_IA64_Pcrel60I   : constant := 16#0018#; -- If possible, convert to MIB bundle with NOP.I in slot 1
   Image_Rel_IA64_Pcrel60M   : constant := 16#0019#; -- If possible, convert to MMB bundle with NOP.M in slot 1
   Image_Rel_IA64_Immgprel64 : constant := 16#001A#;
   Image_Rel_IA64_Token      : constant := 16#001B#; -- clr token
   Image_Rel_IA64_Gprel32    : constant := 16#001C#;
   Image_Rel_IA64_Addend     : constant := 16#001F#;

--
-- CEF relocation types.
--

   Image_Rel_Cef_Absolute : constant := 16#0000#; -- Reference is absolute, no relocation is necessary
   Image_Rel_Cef_Addr32   : constant := 16#0001#; -- 32-bit address (VA).
   Image_Rel_Cef_Addr64   : constant := 16#0002#; -- 64-bit address (VA).
   Image_Rel_Cef_Addr32Nb : constant := 16#0003#; -- 32-bit address w/o image base (RVA).
   Image_Rel_Cef_Section  : constant := 16#0004#; -- Section index
   Image_Rel_Cef_Secrel   : constant := 16#0005#; -- 32 bit offset from base of section containing target
   Image_Rel_Cef_Token    : constant := 16#0006#; -- 32 bit metadata token

--
-- clr relocation types.
--

   Image_Rel_Cee_Absolute : constant := 16#0000#; -- Reference is absolute, no relocation is necessary
   Image_Rel_Cee_Addr32   : constant := 16#0001#; -- 32-bit address (VA).
   Image_Rel_Cee_Addr64   : constant := 16#0002#; -- 64-bit address (VA).
   Image_Rel_Cee_Addr32Nb : constant := 16#0003#; -- 32-bit address w/o image base (RVA).
   Image_Rel_Cee_Section  : constant := 16#0004#; -- Section index
   Image_Rel_Cee_Secrel   : constant := 16#0005#; -- 32 bit offset from base of section containing target
   Image_Rel_Cee_Token    : constant := 16#0006#; -- 32 bit metadata token

   Image_Rel_M32R_Absolute : constant := 16#0000#; -- No relocation required
   Image_Rel_M32R_Addr32   : constant := 16#0001#; -- 32 bit address
   Image_Rel_M32R_Addr32Nb : constant := 16#0002#; -- 32 bit address w/o image base
   Image_Rel_M32R_Addr24   : constant := 16#0003#; -- 24 bit address
   Image_Rel_M32R_Gprel16  : constant := 16#0004#; -- GP relative addressing
   Image_Rel_M32R_Pcrel24  : constant := 16#0005#; -- 24 bit offset << 2 & sign ext.
   Image_Rel_M32R_Pcrel16  : constant := 16#0006#; -- 16 bit offset << 2 & sign ext.
   Image_Rel_M32R_Pcrel8   : constant := 16#0007#; -- 8 bit offset << 2 & sign ext.
   Image_Rel_M32R_Refhalf  : constant := 16#0008#; -- 16 MSBs
   Image_Rel_M32R_Refhi    : constant := 16#0009#; -- 16 MSBs; adj for LSB sign ext.
   Image_Rel_M32R_Reflo    : constant := 16#000A#; -- 16 LSBs
   Image_Rel_M32R_Pair     : constant := 16#000B#; -- Link HI and LO
   Image_Rel_M32R_Section  : constant := 16#000C#; -- Section table index
   Image_Rel_M32R_Secrel32 : constant := 16#000D#; -- 32 bit section relative reference
   Image_Rel_M32R_Token    : constant := 16#000E#; -- clr token

-- Please contact INTEL to get IA64-specific information

--%% (* TODO
--%% #define EXT_IMM64(Value, Address, Size, InstPos, ValPos)
--%%     Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos)  // Intel-IA64-Filler

--%% #define INS_IMM64(Value, Address, Size, InstPos, ValPos)  /* Intel-IA64-Filler */\
--%%     *(PDWORD)Address = (*(PDWORD)Address & ~(((1 << Size) - 1) << InstPos)) | /* Intel-IA64-Filler */\
--%%           ((DWORD)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos)  // Intel-IA64-Filler
--%% *)

   Emarch_Enc_I17_Imm7B_Inst_Word_X     : constant := 3; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm7B_Size_X          : constant := 7; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm7B_Inst_Word_Pos_X : constant := 4; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm7B_Val_Pos_X       : constant := 0; -- Intel-IA64-Filler

   Emarch_Enc_I17_Imm9D_Inst_Word_X     : constant := 3; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm9D_Size_X          : constant := 9; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm9D_Inst_Word_Pos_X : constant := 18; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm9D_Val_Pos_X       : constant := 7; -- Intel-IA64-Filler

   Emarch_Enc_I17_Imm5C_Inst_Word_X     : constant := 3; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm5C_Size_X          : constant := 5; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm5C_Inst_Word_Pos_X : constant := 13; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm5C_Val_Pos_X       : constant := 16; -- Intel-IA64-Filler

   Emarch_Enc_I17_Ic_Inst_Word_X     : constant := 3; -- Intel-IA64-Filler
   Emarch_Enc_I17_Ic_Size_X          : constant := 1; -- Intel-IA64-Filler
   Emarch_Enc_I17_Ic_Inst_Word_Pos_X : constant := 12; -- Intel-IA64-Filler
   Emarch_Enc_I17_Ic_Val_Pos_X       : constant := 21; -- Intel-IA64-Filler

   Emarch_Enc_I17_Imm41a_Inst_Word_X     : constant := 1; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41a_Size_X          : constant := 10; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41a_Inst_Word_Pos_X : constant := 14; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41a_Val_Pos_X       : constant := 22; -- Intel-IA64-Filler

   Emarch_Enc_I17_Imm41b_Inst_Word_X     : constant := 1; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41b_Size_X          : constant := 8; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41b_Inst_Word_Pos_X : constant := 24; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41b_Val_Pos_X       : constant := 32; -- Intel-IA64-Filler

   Emarch_Enc_I17_Imm41c_Inst_Word_X     : constant := 2; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41c_Size_X          : constant := 23; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41c_Inst_Word_Pos_X : constant := 0; -- Intel-IA64-Filler
   Emarch_Enc_I17_Imm41c_Val_Pos_X       : constant := 40; -- Intel-IA64-Filler

   Emarch_Enc_I17_Sign_Inst_Word_X     : constant := 3; -- Intel-IA64-Filler
   Emarch_Enc_I17_Sign_Size_X          : constant := 1; -- Intel-IA64-Filler
   Emarch_Enc_I17_Sign_Inst_Word_Pos_X : constant := 27; -- Intel-IA64-Filler
   Emarch_Enc_I17_Sign_Val_Pos_X       : constant := 63; -- Intel-IA64-Filler

--
-- Line number format.
--

--%%   TImgLineNoType = record
--%%     case Integer of
--%%       0: (SymbolTableIndex: DWORD);               // Symbol table index of function name if Linenumber is 0.
--%%       1: (VirtualAddress: DWORD);                 // Virtual address of line number.
--%%   end;

   type Image_Line_Number_Type;
   type Image_Line_Number_Ptr is access all Image_Line_Number_Type;
   type Image_Line_Number_CPtr is access constant Image_Line_Number_Type;
   type Image_Line_Number_Type is record
      Type_ : Img_Line_No_Type_Type;
      Linenumber : Unsigned_16;                       -- Line number.
   end record;

   Image_Sizeof_Linenumber : constant := 6;

-- #include "poppack.h"                        // Back to 4 byte packing

--
-- Based relocation format.
--

   type Image_Base_Relocation_Type;
   type Image_Base_Relocation_Ptr is access all Image_Base_Relocation_Type;
   type Image_Base_Relocation_CPtr is access constant Image_Base_Relocation_Type;
   type Image_Base_Relocation_Type is record
      Virtual_Address : Unsigned_32;
      Size_Of_Block : Unsigned_32;
            --  WORD    TypeOffset[1];
   end record;

   Image_Sizeof_Base_Relocation : constant := 8;

--
-- Based relocation types.
--

   Image_Rel_Based_Absolute     : constant := 0;
   Image_Rel_Based_High         : constant := 1;
   Image_Rel_Based_Low          : constant := 2;
   Image_Rel_Based_Highlow      : constant := 3;
   Image_Rel_Based_Highadj      : constant := 4;
   Image_Rel_Based_MIPS_Jmpaddr : constant := 5;

   Image_Rel_Based_MIPS_Jmpaddr16 : constant := 9;
   Image_Rel_Based_IA64_Imm64     : constant := 9;
   Image_Rel_Based_Dir64          : constant := 10;

--
-- Archive format.
--

   Image_Archive_Start_Size       : constant := 8;
--%%   IMAGE_ARCHIVE_START            = '!<arch>'#10;
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_START}
--%%   IMAGE_ARCHIVE_END              = '`'#10;
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_END}
--%%   IMAGE_ARCHIVE_PAD              = #10;
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_PAD}
--%%   IMAGE_ARCHIVE_LINKER_MEMBER    = '/               ';
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_LINKER_MEMBER}
--%%   IMAGE_ARCHIVE_LONGNAMES_MEMBER = '//              ';
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_LONGNAMES_MEMBER}

--%%   PIMAGE_ARCHIVE_MEMBER_HEADER = ^IMAGE_ARCHIVE_MEMBER_HEADER;
--%%   {$EXTERNALSYM PIMAGE_ARCHIVE_MEMBER_HEADER}
--%%   _IMAGE_ARCHIVE_MEMBER_HEADER = record
--%%     Name: array [0..15] of Byte; // File member name - `/' terminated.
--%%     Date: array [0..11] of Byte; // File member date - decimal.
--%%     UserID: array [0..5] of Byte; // File member user id - decimal.
--%%     GroupID: array [0..5] of Byte; // File member group id - decimal.
--%%     Mode: array [0..7] of Byte; // File member mode - octal.
--%%     Size: array [0..9] of Byte; // File member size - decimal.
--%%     EndHeader: array [0..1] of Byte; // String to end header.
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_ARCHIVE_MEMBER_HEADER}
--%%   IMAGE_ARCHIVE_MEMBER_HEADER = _IMAGE_ARCHIVE_MEMBER_HEADER;
--%%   {$EXTERNALSYM IMAGE_ARCHIVE_MEMBER_HEADER}
--%%   TImageArchiveMemberHeader = IMAGE_ARCHIVE_MEMBER_HEADER;
--%%   PImageArchiveMemberHeader = PIMAGE_ARCHIVE_MEMBER_HEADER;

   Image_Sizeof_Archive_Member_Hdr : constant := 60;

--
-- DLL support.
--

--
-- Export Format
--

   type Image_Export_Directory_Type;
   type Image_Export_Directory_Ptr is access all Image_Export_Directory_Type;
   type Image_Export_Directory_CPtr is access constant Image_Export_Directory_Type;
   type Image_Export_Directory_Type is record
      Characteristics : Unsigned_32;
      Time_Date_Stamp : Unsigned_32;
      Major_Version : Word;
      Minor_Version : Word;
      Name : Unsigned_32;
      Base : Unsigned_32;
      Number_Of_Functions : Unsigned_32;
      Number_Of_Names : Unsigned_32;
      Address_Of_Functions : Unsigned_32; -- RVA from base of image
      Address_Of_Names : Unsigned_32; -- RVA from base of image
      Address_Of_Name_Ordinals : Unsigned_32; -- RVA from base of image
   end record;

--
-- Import Format
--

--%%   PIMAGE_IMPORT_BY_NAME = ^IMAGE_IMPORT_BY_NAME;
--%%   {$EXTERNALSYM PIMAGE_IMPORT_BY_NAME}
--%%   _IMAGE_IMPORT_BY_NAME = record
--%%     Hint: Word;
--%%     Name: array [0..0] of Byte;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_IMPORT_BY_NAME}
--%%   IMAGE_IMPORT_BY_NAME = _IMAGE_IMPORT_BY_NAME;
--%%   {$EXTERNALSYM IMAGE_IMPORT_BY_NAME}
--%%   TImageImportByName = IMAGE_IMPORT_BY_NAME;
--%%   PImageImportByName = PIMAGE_IMPORT_BY_NAME;

-- #include "pshpack8.h"                       // Use align 8 for the 64-bit IAT.

--%%   PIMAGE_THUNK_DATA64 = ^IMAGE_THUNK_DATA64;
--%%   {$EXTERNALSYM PIMAGE_THUNK_DATA64}
--%%   _IMAGE_THUNK_DATA64 = record
--%%     case Integer of
--%%       0: (ForwarderString: ULONGLONG);   // PBYTE
--%%       1: (Function_: ULONGLONG);         // PDWORD
--%%       2: (Ordinal: ULONGLONG);
--%%       3: (AddressOfData: ULONGLONG);     // PIMAGE_IMPORT_BY_NAME
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_THUNK_DATA64}
--%%   IMAGE_THUNK_DATA64 = _IMAGE_THUNK_DATA64;
--%%   {$EXTERNALSYM IMAGE_THUNK_DATA64}
--%%   TImageThunkData64 = IMAGE_THUNK_DATA64;
--%%   PImageThunkData64 = PIMAGE_THUNK_DATA64;

-- #include "poppack.h"                        // Back to 4 byte packing

--%%   PIMAGE_THUNK_DATA32 = ^IMAGE_THUNK_DATA32;
--%%   {$EXTERNALSYM PIMAGE_THUNK_DATA32}
--%%   _IMAGE_THUNK_DATA32 = record
--%%     case Integer of
--%%       0: (ForwarderString: DWORD);   // PBYTE
--%%       1: (Function_: DWORD);         // PDWORD
--%%       2: (Ordinal: DWORD);
--%%       3: (AddressOfData: DWORD);     // PIMAGE_IMPORT_BY_NAME
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_THUNK_DATA32}
--%%   IMAGE_THUNK_DATA32 = _IMAGE_THUNK_DATA32;
--%%   {$EXTERNALSYM IMAGE_THUNK_DATA32}
--%%   TImageThunkData32 = IMAGE_THUNK_DATA32;
--%%   PImageThunkData32 = PIMAGE_THUNK_DATA32;

--%%   IMAGE_ORDINAL_FLAG64 = ULONGLONG($8000000000000000);
--%%   {$EXTERNALSYM IMAGE_ORDINAL_FLAG64}
   Image_Ordinal_Flag32 : constant := 16#8000_0000#;

--%% function IMAGE_ORDINAL64(Ordinal: ULONGLONG): ULONGLONG;
--%% {$EXTERNALSYM IMAGE_ORDINAL64}
--%% function IMAGE_ORDINAL32(Ordinal: DWORD): DWORD;
--%% {$EXTERNALSYM IMAGE_ORDINAL32}
--%% function IMAGE_SNAP_BY_ORDINAL64(Ordinal: ULONGLONG): Boolean;
--%% {$EXTERNALSYM IMAGE_SNAP_BY_ORDINAL64}
--%% function IMAGE_SNAP_BY_ORDINAL32(Ordinal: DWORD): Boolean;
--%% {$EXTERNALSYM IMAGE_SNAP_BY_ORDINAL32}

--
-- Thread Local Storage
--

--%%   PIMAGE_TLS_CALLBACK = procedure(DllHandle: Pointer; Reason: DWORD; Reserved: Pointer); stdcall;
--%%   {$EXTERNALSYM PIMAGE_TLS_CALLBACK}
--%%   TImageTlsCallback = PIMAGE_TLS_CALLBACK;

   type Image_Tls_Directory64_Type;
   type Image_Tls_Directory64_Ptr is access all Image_Tls_Directory64_Type;
   type Image_Tls_Directory64_CPtr is access constant Image_Tls_Directory64_Type;
   type Image_Tls_Directory64_Type is record
      Start_Address_Of_Raw_Data : Unsigned_64;
      End_Address_Of_Raw_Data : Unsigned_64;
      Address_Of_Index : Unsigned_64;          -- PDWORD
      Address_Of_Call_Backs : Unsigned_64;     -- PIMAGE_TLS_CALLBACK *;
      Size_Of_Zero_Fill : Unsigned_32;
      Characteristics : Unsigned_32;
   end record;

   type Image_Tls_Directory32_Type;
   type Image_Tls_Directory32_Ptr is access all Image_Tls_Directory32_Type;
   type Image_Tls_Directory32_CPtr is access constant Image_Tls_Directory32_Type;
   type Image_Tls_Directory32_Type is record
      Start_Address_Of_Raw_Data : Unsigned_32;
      End_Address_Of_Raw_Data : Unsigned_32;
      Address_Of_Index : Unsigned_32;          -- PDWORD
      Address_Of_Call_Backs : Unsigned_32;     -- PIMAGE_TLS_CALLBACK *
      Size_Of_Zero_Fill : Unsigned_32;
      Characteristics : Unsigned_32;
   end record;

   Image_Ordinal_Flag : constant := Image_Ordinal_Flag32;

--%% function IMAGE_ORDINAL(Ordinal: DWORD): DWORD;

--%%   IMAGE_THUNK_DATA = IMAGE_THUNK_DATA32;
--%%   {$EXTERNALSYM IMAGE_THUNK_DATA}
--%%   PIMAGE_THUNK_DATA = PIMAGE_THUNK_DATA32;
--%%   {$EXTERNALSYM PIMAGE_THUNK_DATA}
--%%   TImageThunkData = TImageThunkData32;
--%%   PImageThunkData = PImageThunkData32;

--%% function IMAGE_SNAP_BY_ORDINAL(Ordinal: DWORD): Boolean;
--%% {$EXTERNALSYM IMAGE_SNAP_BY_ORDINAL}

   subtype Image_Tls_Directory_Type is Image_Tls_Directory32_Type;
   subtype Image_Tls_Directory_Ptr is Image_Tls_Directory32_Ptr;
   subtype Image_Tls_Directory_CPtr is Image_Tls_Directory32_CPtr;
   subtype Pimage_Tls_Directory_Type is Image_Tls_Directory32_Ptr;
   type Pimage_Tls_Directory_Ptr is access all Image_Tls_Directory32_Ptr;
   type Pimage_Tls_Directory_CPtr is access constant Image_Tls_Directory32_Ptr;
--%%   TImageTlsDirectory = TImageTlsDirectory32;
--%%   PImageTlsDirectory = PImageTlsDirectory32;

--%%   TIIDUnion = record
--%%     case Integer of
--%%       0: (Characteristics: DWORD);         // 0 for terminating null import descriptor
--%%       1: (OriginalFirstThunk: DWORD);      // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
--%%   end;

--%%   PIMAGE_IMPORT_DESCRIPTOR = ^IMAGE_IMPORT_DESCRIPTOR;
--%%   {$EXTERNALSYM PIMAGE_IMPORT_DESCRIPTOR}
--%%   _IMAGE_IMPORT_DESCRIPTOR = record
--%%     Union: TIIDUnion;
--%%     TimeDateStamp: DWORD;                  // 0 if not bound,
--%%                                            // -1 if bound, and real date\time stamp
--%%                                            //     in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
--%%                                            // O.W. date/time stamp of DLL bound to (Old BIND)

--%%     ForwarderChain: DWORD;                 // -1 if no forwarders
--%%     Name: DWORD;
--%%     FirstThunk: DWORD;                     // RVA to IAT (if bound this IAT has actual addresses)
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_IMPORT_DESCRIPTOR}
--%%   IMAGE_IMPORT_DESCRIPTOR = _IMAGE_IMPORT_DESCRIPTOR;
--%%   {$EXTERNALSYM IMAGE_IMPORT_DESCRIPTOR}
--%%   TImageImportDecriptor = IMAGE_IMPORT_DESCRIPTOR;
--%%   PImageImportDecriptor = PIMAGE_IMPORT_DESCRIPTOR;

--
-- New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
--

   type Image_Bound_Import_Descriptor_Type;
   type Image_Bound_Import_Descriptor_Ptr is access all Image_Bound_Import_Descriptor_Type;
   type Image_Bound_Import_Descriptor_CPtr is access constant Image_Bound_Import_Descriptor_Type;
   type Image_Bound_Import_Descriptor_Type is record
      Time_Date_Stamp : Unsigned_32;
      Offset_Module_Name : Word;
      Number_Of_Module_Forwarder_Refs : Word;
            -- Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
   end record;

   type Image_Bound_Forwarder_Ref_Type;
   type Image_Bound_Forwarder_Ref_Ptr is access all Image_Bound_Forwarder_Ref_Type;
   type Image_Bound_Forwarder_Ref_CPtr is access constant Image_Bound_Forwarder_Ref_Type;
   type Image_Bound_Forwarder_Ref_Type is record
      Time_Date_Stamp : Unsigned_32;
      Offset_Module_Name : Word;
      Reserved : Word;
   end record;

--
-- Resource Format.
--

--
-- Resource directory consists of two counts, following by a variable length
-- array of directory entries.  The first count is the number of entries at
-- beginning of the array that have actual names associated with each entry.
-- The entries are in ascending order, case insensitive strings.  The second
-- count is the number of entries that immediately follow the named entries.
-- This second count identifies the number of entries that have 16-bit integer
-- Ids as their name.  These entries are also sorted in ascending order.
--
-- This structure allows fast lookup by either name or number, but for any
-- given resource entry only one form of lookup is supported, not both.
-- This is consistant with the syntax of the .RC file and the .RES file.
--

   type Image_Resource_Directory_Type;
   type Image_Resource_Directory_Ptr is access all Image_Resource_Directory_Type;
   type Image_Resource_Directory_CPtr is access constant Image_Resource_Directory_Type;
   type Image_Resource_Directory_Type is record
      Characteristics : Unsigned_32;
      Time_Date_Stamp : Unsigned_32;
      Major_Version : Word;
      Minor_Version : Word;
      Number_Of_Named_Entries : Word;
      Number_Of_Id_Entries : Word;
            -- IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
   end record;

   Image_Resource_Name_Is_String    : constant := 16#8000_0000#;
   Image_Resource_Data_Is_Directory : constant := 16#8000_0000#;

--
-- Each directory contains the 32-bit Name of the entry and an offset,
-- relative to the beginning of the resource directory of the data associated
-- with this directory entry.  If the name of the entry is an actual text
-- string instead of an integer Id, then the high order bit of the name field
-- is set to one and the low order 31-bits are an offset, relative to the
-- beginning of the resource directory of the string, which is of type
-- IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
-- low-order 16-bits are the integer Id that identify this resource directory
-- entry. If the directory entry is yet another resource directory (i.e. a
-- subdirectory), then the high order bit of the offset field will be
-- set to indicate this.  Otherwise the high bit is clear and the offset
-- field points to a resource data entry.
--

--%%   TIRDEName = record
--%%     case Integer of
--%%       0: (
--%%         NameOffset: DWORD); // 0..30: NameOffset; 31: NameIsString
--%%       1: (
--%%         Name: DWORD);
--%%       2: (
--%%         Id: WORD);
--%%   end;

--%%   TIRDEDirectory = record
--%%     case Integer of
--%%       0: (
--%%         OffsetToData: DWORD);
--%%       1: (
--%%         OffsetToDirectory: DWORD); // 0..30: OffsetToDirectory; 31: DataIsDirectory
--%%   end;

   type Image_Resource_Directory_Entry_Type;
   type Image_Resource_Directory_Entry_Ptr is access all Image_Resource_Directory_Entry_Type;
   type Image_Resource_Directory_Entry_CPtr is access constant Image_Resource_Directory_Entry_Type;
   type Image_Resource_Directory_Entry_Type is record
      Name : IRDE_Name_Type;
      Directory : IRDE_Directory_Type;
   end record;

--
-- For resource directory entries that have actual string names, the Name
-- field of the directory entry points to an object of the following type.
-- All of these string objects are stored together after the last resource
-- directory entry and before the first resource data object.  This minimizes
-- the impact of these variable length objects on the alignment of the fixed
-- size directory entry objects.
--

--%%   PIMAGE_RESOURCE_DIRECTORY_STRING = ^IMAGE_RESOURCE_DIRECTORY_STRING;
--%%   {$EXTERNALSYM PIMAGE_RESOURCE_DIRECTORY_STRING}
--%%   _IMAGE_RESOURCE_DIRECTORY_STRING = record
--%%     Length: Word;
--%%     NameString: array [0..0] of CHAR;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_RESOURCE_DIRECTORY_STRING}
--%%   IMAGE_RESOURCE_DIRECTORY_STRING = _IMAGE_RESOURCE_DIRECTORY_STRING;
--%%   {$EXTERNALSYM IMAGE_RESOURCE_DIRECTORY_STRING}
--%%   TImageResourceDirectoryString = IMAGE_RESOURCE_DIRECTORY_STRING;
--%%   PImageResourceDirectoryString = PIMAGE_RESOURCE_DIRECTORY_STRING;

--%%   PIMAGE_RESOURCE_DIR_STRING_U = ^IMAGE_RESOURCE_DIR_STRING_U;
--%%   {$EXTERNALSYM PIMAGE_RESOURCE_DIR_STRING_U}
--%%   _IMAGE_RESOURCE_DIR_STRING_U = record
--%%     Length: Word;
--%%     NameString: array [0..0] of WCHAR;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_RESOURCE_DIR_STRING_U}
--%%   IMAGE_RESOURCE_DIR_STRING_U = _IMAGE_RESOURCE_DIR_STRING_U;
--%%   {$EXTERNALSYM IMAGE_RESOURCE_DIR_STRING_U}
--%%   TImageResourceDirStringU = IMAGE_RESOURCE_DIR_STRING_U;
--%%   PImageResourceDirStringU = PIMAGE_RESOURCE_DIR_STRING_U;

--
-- Each resource data entry describes a leaf node in the resource directory
-- tree.  It contains an offset, relative to the beginning of the resource
-- directory of the data for the resource, a size field that gives the number
-- of bytes of data at that offset, a CodePage that should be used when
-- decoding code point values within the resource data.  Typically for new
-- applications the code page would be the unicode code page.
--

   type Image_Resource_Data_Entry_Type;
   type Image_Resource_Data_Entry_Ptr is access all Image_Resource_Data_Entry_Type;
   type Image_Resource_Data_Entry_CPtr is access constant Image_Resource_Data_Entry_Type;
   type Image_Resource_Data_Entry_Type is record
      Offset_To_Data : Unsigned_32;
      Size : Unsigned_32;
      Code_Page : Unsigned_32;
      Reserved : Unsigned_32;
   end record;

--
-- Load Configuration Directory Entry
--

--%%   PIMAGE_LOAD_CONFIG_DIRECTORY32 = ^IMAGE_LOAD_CONFIG_DIRECTORY32;
--%%   {$EXTERNALSYM PIMAGE_LOAD_CONFIG_DIRECTORY32}
--%%   IMAGE_LOAD_CONFIG_DIRECTORY32 = record
--%%     Size: DWORD;
--%%     TimeDateStamp: DWORD;
--%%     MajorVersion: WORD;
--%%     MinorVersion: WORD;
--%%     GlobalFlagsClear: DWORD;
--%%     GlobalFlagsSet: DWORD;
--%%     CriticalSectionDefaultTimeout: DWORD;
--%%     DeCommitFreeBlockThreshold: DWORD;
--%%     DeCommitTotalFreeThreshold: DWORD;
--%%     LockPrefixTable: DWORD;            // VA
--%%     MaximumAllocationSize: DWORD;
--%%     VirtualMemoryThreshold: DWORD;
--%%     ProcessHeapFlags: DWORD;
--%%     ProcessAffinityMask: DWORD;
--%%     CSDVersion: WORD;
--%%     Reserved1: WORD;
--%%     EditList: DWORD;                   // VA
--%%     SecurityCookie: DWORD;             // VA
--%%     SEHandlerTable: DWORD;             // VA
--%%     SEHandlerCount: DWORD;
--%%   end;
--%%   {$EXTERNALSYM IMAGE_LOAD_CONFIG_DIRECTORY32}
--%%   TImageLoadConfigDirectory32 = IMAGE_LOAD_CONFIG_DIRECTORY32;
--%%   PImageLoadConfigDirectory32 = PIMAGE_LOAD_CONFIG_DIRECTORY32;

--%%   PIMAGE_LOAD_CONFIG_DIRECTORY64 = ^IMAGE_LOAD_CONFIG_DIRECTORY64;
--%%   {$EXTERNALSYM PIMAGE_LOAD_CONFIG_DIRECTORY64}
--%%   IMAGE_LOAD_CONFIG_DIRECTORY64 = record
--%%     Size: DWORD;
--%%     TimeDateStamp: DWORD;
--%%     MajorVersion: WORD;
--%%     MinorVersion: WORD;
--%%     GlobalFlagsClear: DWORD;
--%%     GlobalFlagsSet: DWORD;
--%%     CriticalSectionDefaultTimeout: DWORD;
--%%     DeCommitFreeBlockThreshold: ULONGLONG;
--%%     DeCommitTotalFreeThreshold: ULONGLONG;
--%%     LockPrefixTable: ULONGLONG;         // VA
--%%     MaximumAllocationSize: ULONGLONG;
--%%     VirtualMemoryThreshold: ULONGLONG;
--%%     ProcessAffinityMask: ULONGLONG;
--%%     ProcessHeapFlags: DWORD;
--%%     CSDVersion: WORD;
--%%     Reserved1: WORD;
--%%     EditList: ULONGLONG;                // VA
--%%     SecurityCookie: ULONGLONG;             // VA
--%%     SEHandlerTable: ULONGLONG;             // VA
--%%     SEHandlerCount: ULONGLONG;
--%%   end;
--%%   {$EXTERNALSYM IMAGE_LOAD_CONFIG_DIRECTORY64}
--%%   TImageLoadConfigDirectory64 = IMAGE_LOAD_CONFIG_DIRECTORY64;
--%%   PImageLoadConfigDirectory64 = PIMAGE_LOAD_CONFIG_DIRECTORY64;

--%%   IMAGE_LOAD_CONFIG_DIRECTORY = IMAGE_LOAD_CONFIG_DIRECTORY32;
--%%   {$EXTERNALSYM IMAGE_LOAD_CONFIG_DIRECTORY}
--%%   PIMAGE_LOAD_CONFIG_DIRECTORY = PIMAGE_LOAD_CONFIG_DIRECTORY32;
--%%   {$EXTERNALSYM PIMAGE_LOAD_CONFIG_DIRECTORY}
--%%   TImageLoadConfigDirectory = TImageLoadConfigDirectory32;
--%%   PImageLoadConfigDirectory = PImageLoadConfigDirectory32;

--
-- WIN CE Exception table format
--

--
-- Function table entry format.  Function table is pointed to by the
-- IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
--

--%%   PIMAGE_CE_RUNTIME_FUNCTION_ENTRY = ^IMAGE_CE_RUNTIME_FUNCTION_ENTRY;
--%%   {$EXTERNALSYM PIMAGE_CE_RUNTIME_FUNCTION_ENTRY}
--%%   _IMAGE_CE_RUNTIME_FUNCTION_ENTRY = record
--%%     FuncStart: DWORD;
--%%     Flags: DWORD;
--%%     //DWORD PrologLen : 8;
--%%     //DWORD FuncLen : 22;
--%%     //DWORD ThirtyTwoBit : 1;
--%%     //DWORD ExceptionFlag : 1;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_CE_RUNTIME_FUNCTION_ENTRY}
--%%   IMAGE_CE_RUNTIME_FUNCTION_ENTRY = _IMAGE_CE_RUNTIME_FUNCTION_ENTRY;
--%%   {$EXTERNALSYM IMAGE_CE_RUNTIME_FUNCTION_ENTRY}
--%%   TImageCERuntimeFunctionEntry = IMAGE_CE_RUNTIME_FUNCTION_ENTRY;
--%%   PImageCERuntimeFunctionEntry = PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;

--
-- Debug Format
--

   type Image_Debug_Directory_Type;
   type Image_Debug_Directory_Ptr is access all Image_Debug_Directory_Type;
   type Image_Debug_Directory_CPtr is access constant Image_Debug_Directory_Type;
   type Image_Debug_Directory_Type is record
      Characteristics : Unsigned_32;
      Time_Date_Stamp : Unsigned_32;
      Major_Version : Word;
      Minor_Version : Word;
      Type_ : Unsigned_32;
      Size_Of_Data : Unsigned_32;
      Address_Of_Raw_Data : Unsigned_32;
      Pointer_To_Raw_Data : Unsigned_32;
   end record;

   Image_Debug_Type_Unknown       : constant := 0;
   Image_Debug_Type_Coff          : constant := 1;
   Image_Debug_Type_Codeview      : constant := 2;
   Image_Debug_Type_Fpo           : constant := 3;
   Image_Debug_Type_Misc          : constant := 4;
   Image_Debug_Type_Exception     : constant := 5;
   Image_Debug_Type_Fixup         : constant := 6;
   Image_Debug_Type_Omap_To_Src   : constant := 7;
   Image_Debug_Type_Omap_From_Src : constant := 8;
   Image_Debug_Type_Borland       : constant := 9;
   Image_Debug_Type_Reserved10    : constant := 10;
   Image_Debug_Type_CLSID         : constant := 11;

   type Image_Coff_Symbols_Header_Type;
   type Image_Coff_Symbols_Header_Ptr is access all Image_Coff_Symbols_Header_Type;
   type Image_Coff_Symbols_Header_CPtr is access constant Image_Coff_Symbols_Header_Type;
   type Image_Coff_Symbols_Header_Type is record
      Number_Of_Symbols : Unsigned_32;
      Lva_To_First_Symbol : Unsigned_32;
      Number_Of_Linenumbers : Unsigned_32;
      Lva_To_First_Linenumber : Unsigned_32;
      Rva_To_First_Byte_Of_Code : Unsigned_32;
      Rva_To_Last_Byte_Of_Code : Unsigned_32;
      Rva_To_First_Byte_Of_Data : Unsigned_32;
      Rva_To_Last_Byte_Of_Data : Unsigned_32;
   end record;

   Frame_Fpo    : constant := 0;
   Frame_Trap   : constant := 1;
   Frame_Tss    : constant := 2;
   Frame_Nonfpo : constant := 3;

   Fpoflags_Prolog   : constant := 16#00FF#; -- # bytes in prolog
   Fpoflags_Regs     : constant := 16#0700#; -- # regs saved
   Fpoflags_Has_Seh  : constant := 16#0800#; -- TRUE if SEH in func
   Fpoflags_Use_Bp   : constant := 16#1000#; -- TRUE if EBP has been allocated
   Fpoflags_Reserved : constant := 16#2000#; -- reserved for future use
   Fpoflags_Frame    : constant := 16#C000#; -- frame type

   type Fpo_Data_Type;
   type Fpo_Data_Ptr is access all Fpo_Data_Type;
   type Fpo_Data_CPtr is access constant Fpo_Data_Type;
   type Fpo_Data_Type is record
      Off_Start : Unsigned_32;       -- offset 1st byte of function code
      Proc_Size : Unsigned_32;       -- # bytes in function
      Locals : Unsigned_32;          -- # bytes in locals/4
      Params : Unsigned_16;          -- # bytes in params/4
      Flags : Unsigned_16;
   end record;

   Sizeof_Rfpo_Data : constant := 16;

   Image_Debug_Misc_Exename : constant := 1;

--%%   PIMAGE_DEBUG_MISC = ^IMAGE_DEBUG_MISC;
--%%   {$EXTERNALSYM PIMAGE_DEBUG_MISC}
--%%   _IMAGE_DEBUG_MISC = record
--%%     DataType: DWORD;   // type of misc data, see defines
--%%     Length: DWORD;     // total length of record, rounded to four byte multiple.
--%%     Unicode: ByteBool; // TRUE if data is unicode string
--%%     Reserved: array [0..2] of Byte;
--%%     Data: array [0..0] of Byte; // Actual data
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_DEBUG_MISC}
--%%   IMAGE_DEBUG_MISC = _IMAGE_DEBUG_MISC;
--%%   {$EXTERNALSYM IMAGE_DEBUG_MISC}
--%%   TImageDebugMisc = IMAGE_DEBUG_MISC;
--%%   PImageDebugMisc = PIMAGE_DEBUG_MISC;

--
-- Function table extracted from MIPS/ALPHA/IA64 images.  Does not contain
-- information needed only for runtime support.  Just those fields for
-- each entry needed by a debugger.
--

   type Image_Function_Entry_Type;
   type Image_Function_Entry_Ptr is access all Image_Function_Entry_Type;
   type Image_Function_Entry_CPtr is access constant Image_Function_Entry_Type;
   type Image_Function_Entry_Type is record
      Starting_Address : Unsigned_32;
      Ending_Address : Unsigned_32;
      End_Of_Prologue : Unsigned_32;
   end record;

--%%   PIMAGE_FUNCTION_ENTRY64 = ^IMAGE_FUNCTION_ENTRY64;
--%%   {$EXTERNALSYM PIMAGE_FUNCTION_ENTRY64}
--%%   _IMAGE_FUNCTION_ENTRY64 = record
--%%     StartingAddress: ULONGLONG;
--%%     EndingAddress: ULONGLONG;
--%%     case Integer of
--%%       0: (EndOfPrologue: ULONGLONG);
--%%       1: (UnwindInfoAddress: ULONGLONG);
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_FUNCTION_ENTRY64}
--%%   IMAGE_FUNCTION_ENTRY64 = _IMAGE_FUNCTION_ENTRY64;
--%%   {$EXTERNALSYM IMAGE_FUNCTION_ENTRY64}
--%%   TImageFunctionEntry64 = IMAGE_FUNCTION_ENTRY64;
--%%   PImageFunctionEntry64 = PIMAGE_FUNCTION_ENTRY64;

--
-- Debugging information can be stripped from an image file and placed
-- in a separate .DBG file, whose file name part is the same as the
-- image file name part (e.g. symbols for CMD.EXE could be stripped
-- and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
-- flag in the Characteristics field of the file header.  The beginning of
-- the .DBG file contains the following structure which captures certain
-- information from the image file.  This allows a debug to proceed even if
-- the original image file is not accessable.  This header is followed by
-- zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
-- IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
-- the image file contain file offsets relative to the beginning of the
-- .DBG file.
--
-- If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
-- is left in the image file, but not mapped.  This allows a debugger to
-- compute the name of the .DBG file, from the name of the image in the
-- IMAGE_DEBUG_MISC structure.
--

--%%   PIMAGE_SEPARATE_DEBUG_HEADER = ^IMAGE_SEPARATE_DEBUG_HEADER;
--%%   {$EXTERNALSYM PIMAGE_SEPARATE_DEBUG_HEADER}
--%%   _IMAGE_SEPARATE_DEBUG_HEADER = record
--%%     Signature: Word;
--%%     Flags: Word;
--%%     Machine: Word;
--%%     Characteristics: Word;
--%%     TimeDateStamp: DWORD;
--%%     CheckSum: DWORD;
--%%     ImageBase: DWORD;
--%%     SizeOfImage: DWORD;
--%%     NumberOfSections: DWORD;
--%%     ExportedNamesSize: DWORD;
--%%     DebugDirectorySize: DWORD;
--%%     SectionAlignment: DWORD;
--%%     Reserved: array [0..1] of DWORD;
--%%   end;
--%%   {$EXTERNALSYM _IMAGE_SEPARATE_DEBUG_HEADER}
--%%   IMAGE_SEPARATE_DEBUG_HEADER = _IMAGE_SEPARATE_DEBUG_HEADER;
--%%   {$EXTERNALSYM IMAGE_SEPARATE_DEBUG_HEADER}
--%%   TImageSeparateDebugHeader = IMAGE_SEPARATE_DEBUG_HEADER;
--%%   PImageSeparateDebugHeader = PIMAGE_SEPARATE_DEBUG_HEADER;

--%%   _NON_PAGED_DEBUG_INFO = record
--%%     Signature: WORD;
--%%     Flags: WORD;
--%%     Size: DWORD;
--%%     Machine: WORD;
--%%     Characteristics: WORD;
--%%     TimeDateStamp: DWORD;
--%%     CheckSum: DWORD;
--%%     SizeOfImage: DWORD;
--%%     ImageBase: ULONGLONG;
--%%     //DebugDirectorySize
--%%     //IMAGE_DEBUG_DIRECTORY
--%%   end;
--%%   {$EXTERNALSYM _NON_PAGED_DEBUG_INFO}
--%%   NON_PAGED_DEBUG_INFO = _NON_PAGED_DEBUG_INFO;
--%%   {$EXTERNALSYM NON_PAGED_DEBUG_INFO}
--%%   PNON_PAGED_DEBUG_INFO = ^NON_PAGED_DEBUG_INFO;
--%%   {$EXTERNALSYM PNON_PAGED_DEBUG_INFO}

   Image_Separate_Debug_Signature : constant := 16#4944#;
   Non_Paged_Debug_Signature      : constant := 16#494E#;

   Image_Separate_Debug_Flags_Mask : constant := 16#8000#;
   Image_Separate_Debug_Mismatch   : constant := 16#8000#; -- when DBG was updated, the old checksum didn't match.

--
--  The .arch section is made up of headers, each describing an amask position/value
--  pointing to an array of IMAGE_ARCHITECTURE_ENTRY's.  Each "array" (both the header
--  and entry arrays) are terminiated by a quadword of 0xffffffffL.
--
--  NOTE: There may be quadwords of 0 sprinkled around and must be skipped.
--

   Iahmask_Value : constant := 16#0000_0001#; -- 1 -> code section depends on mask bit
--%%                              // 0 -> new instruction depends on mask bit
   Iahmask_Mbz7  : constant := 16#0000_00FE#; -- MBZ
   Iahmask_Shift : constant := 16#0000_FF00#; -- Amask bit in question for this fixup
   Iahmask_Mbz16 : constant := 16#FFFF_0000#; -- MBZ

--%%   PIMAGE_ARCHITECTURE_HEADER = ^IMAGE_ARCHITECTURE_HEADER;
--%%   {$EXTERNALSYM PIMAGE_ARCHITECTURE_HEADER}
--%%   _ImageArchitectureHeader = record
--%%     Mask: DWORD;
--%%     FirstEntryRVA: DWORD;    // RVA into .arch section to array of ARCHITECTURE_ENTRY's
--%%   end;
--%%   {$EXTERNALSYM _ImageArchitectureHeader}
--%%   IMAGE_ARCHITECTURE_HEADER = _ImageArchitectureHeader;
--%%   {$EXTERNALSYM IMAGE_ARCHITECTURE_HEADER}
--%%   TImageArchitectureHeader = IMAGE_ARCHITECTURE_HEADER;
--%%   PImageArchitectureHeader = PIMAGE_ARCHITECTURE_HEADER;

--%%   PIMAGE_ARCHITECTURE_ENTRY = ^IMAGE_ARCHITECTURE_ENTRY;
--%%   {$EXTERNALSYM PIMAGE_ARCHITECTURE_ENTRY}
--%%   _ImageArchitectureEntry = record
--%%     FixupInstRVA: DWORD;                         // RVA of instruction to fixup
--%%     NewInst: DWORD;                              // fixup instruction (see alphaops.h)
--%%   end;
--%%   {$EXTERNALSYM _ImageArchitectureEntry}
--%%   IMAGE_ARCHITECTURE_ENTRY = _ImageArchitectureEntry;
--%%   {$EXTERNALSYM IMAGE_ARCHITECTURE_ENTRY}
--%%   TImageArchitectureEntry = IMAGE_ARCHITECTURE_ENTRY;
--%%   PImageArchitectureEntry = PIMAGE_ARCHITECTURE_ENTRY;

-- #include "poppack.h"                // Back to the initial value

-- The following structure defines the new import object.  Note the values of the first two fields,
-- which must be set as stated in order to differentiate old and new import members.
-- Following this structure, the linker emits two null-terminated strings used to recreate the
-- import at the time of use.  The first string is the import's name, the second is the dll's name.

   Import_Object_Hdr_Sig2 : constant := 16#FFFF#;

   Iohflags_Type : constant := 16#0003#;      -- IMPORT_TYPE
   Iahflags_Nametype : constant := 16#001C#;  -- IMPORT_NAME_TYPE
   Iahflags_Reserved : constant := 16#FFE0#;  -- Reserved. Must be zero.

--%%   PImportObjectHeader = ^IMPORT_OBJECT_HEADER;
--%%   IMPORT_OBJECT_HEADER = record
--%%     Sig1: WORD;                       // Must be IMAGE_FILE_MACHINE_UNKNOWN
--%%     Sig2: WORD;                       // Must be IMPORT_OBJECT_HDR_SIG2.
--%%     Version: WORD;
--%%     Machine: WORD;
--%%     TimeDateStamp: DWORD;             // Time/date stamp
--%%     SizeOfData: DWORD;                // particularly useful for incremental links
--%%     OrdinalOrHint: record
--%%     case Integer of
--%%       0: (Ordinal: WORD);             // if grf & IMPORT_OBJECT_ORDINAL
--%%       1: (Flags: DWORD);
--%%     end;
--%%     Flags: WORD;
--%%     //WORD    Type : 2;                   // IMPORT_TYPE
--%%     //WORD    NameType : 3;               // IMPORT_NAME_TYPE
--%%     //WORD    Reserved : 11;              // Reserved. Must be zero.
--%%   end;
--%%   {$EXTERNALSYM IMPORT_OBJECT_HEADER}
--%%   TImportObjectHeader = IMPORT_OBJECT_HEADER;

--%%   IMPORT_OBJECT_TYPE = (IMPORT_OBJECT_CODE, IMPORT_OBJECT_DATA, IMPORT_OBJECT_CONST);
--%%   {$EXTERNALSYM IMPORT_OBJECT_TYPE}
--%%   TImportObjectType = IMPORT_OBJECT_TYPE;

--%%   IMPORT_OBJECT_NAME_TYPE = (
--%%     IMPORT_OBJECT_ORDINAL,          // Import by ordinal
--%%     IMPORT_OBJECT_NAME,             // Import name == public symbol name.
--%%     IMPORT_OBJECT_NAME_NO_PREFIX,   // Import name == public symbol name skipping leading ?, @, or optionally _.
--%%     IMPORT_OBJECT_NAME_UNDECORATE); // Import name == public symbol name skipping leading ?, @, or optionally _
--%%                                     // and truncating at first @
--%%   {$EXTERNALSYM IMPORT_OBJECT_NAME_TYPE}
--%%   TImportObjectNameType = IMPORT_OBJECT_NAME_TYPE;

   subtype Replaces_Cor_Hdr_Numeric_Defines_Type is Unsigned_32;
   subtype Replaces_Cor_Hdr_Numeric_Defines_Ptr is Unsigned_32_Ptr;
   subtype Replaces_Cor_Hdr_Numeric_Defines_CPtr is Unsigned_32_CPtr;


-- COM+ Header entry point flags.

   Comimage_Flags_Ilonly               : constant := 16#0000_0001#;
   Comimage_Flags_32Bitrequired        : constant := 16#0000_0002#;
   Comimage_Flags_Il_Library           : constant := 16#0000_0004#;
   Comimage_Flags_Strongnamesigned     : constant := 16#0000_0008#;
   Comimage_Flags_Trackdebugdata       : constant := 16#0001_0000#;

-- Version flags for image.

   Cor_Version_Major_V2                : constant := 2;
   Cor_Version_Major                   : constant := Cor_Version_Major_V2;
   Cor_Version_Minor                   : constant := 0;
   Cor_Deleted_Name_Length             : constant := 8;
   Cor_Vtablegap_Name_Length           : constant := 8;

-- Maximum size of a NativeType descriptor.

   Native_Type_Max_Cb                  : constant := 1;
--%%   COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE= $FF;
--%%   {$EXTERNALSYM COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE}

-- #defines for the MIH FLAGS

   Image_Cor_Mih_Methodrva             : constant := 16#01#;
   Image_Cor_Mih_Ehrva                 : constant := 16#02#;
   Image_Cor_Mih_Basicblock            : constant := 16#08#;

-- V-table constants

   Cor_Vtable_32Bit                    : constant := 16#01#;          -- V-table slots are 32-bits in size.
   Cor_Vtable_64Bit                    : constant := 16#02#;          -- V-table slots are 64-bits in size.
   Cor_Vtable_From_Unmanaged           : constant := 16#04#;          -- If set, transition from unmanaged.
   Cor_Vtable_Call_Most_Derived        : constant := 16#10#;          -- Call most derived method described by

-- EATJ constants

   Image_Cor_Eatj_Thunk_Size           : constant := 32;            -- Size of a jump thunk reserved range.

-- Max name lengths
-- Change to unlimited name lengths.

   Max_Class_Name                      : constant := 1024;
   Max_Package_Name                    : constant := 1024;

-- COM+ 2.0 header structure.

--%%   IMAGE_COR20_HEADER = record

--%%     // Header versioning

--%%     cb: DWORD;
--%%     MajorRuntimeVersion: WORD;
--%%     MinorRuntimeVersion: WORD;

--%%     // Symbol table and startup information

--%%     MetaData: IMAGE_DATA_DIRECTORY;
--%%     Flags: DWORD;
--%%     EntryPointToken: DWORD;

--%%     // Binding information

--%%     Resources: IMAGE_DATA_DIRECTORY;
--%%     StrongNameSignature: IMAGE_DATA_DIRECTORY;

--%%     // Regular fixup and binding information

--%%     CodeManagerTable: IMAGE_DATA_DIRECTORY;
--%%     VTableFixups: IMAGE_DATA_DIRECTORY;
--%%     ExportAddressTableJumps: IMAGE_DATA_DIRECTORY;

--%%     // Precompiled image info (internal use only - set to zero)

--%%     ManagedNativeHeader: IMAGE_DATA_DIRECTORY;
--%%   end;
--%%   {$EXTERNALSYM IMAGE_COR20_HEADER}
--%%   PIMAGE_COR20_HEADER = ^IMAGE_COR20_HEADER;
--%%   {$EXTERNALSYM PIMAGE_COR20_HEADER}
--%%   TImageCor20Header = IMAGE_COR20_HEADER;
--%%   PImageCor20Header = PIMAGE_COR20_HEADER;

--
-- End Image Format
--

   subtype Slist_Entry_Type is Single_List_Entry_Type;
   subtype Slist_Entry_Ptr is Single_List_Entry_Ptr;
   subtype Slist_Entry_CPtr is Single_List_Entry_CPtr;
   subtype _Slist_Entry_Type is Single_List_Entry_Type;
   subtype _Slist_Entry_Ptr is Single_List_Entry_Ptr;
   subtype _Slist_Entry_CPtr is Single_List_Entry_CPtr;
   subtype Pslist_Entry_Type is Single_List_Entry_Ptr;
   type Pslist_Entry_Ptr is access all Single_List_Entry_Ptr;
   type Pslist_Entry_CPtr is access constant Single_List_Entry_Ptr;
--%%   TSListEntry = SLIST_ENTRY;
--%%   PSListEntry = PSLIST_ENTRY;  

--%%   _SLIST_HEADER = record
--%%   case Integer of
--%%     0: (
--%%       Alignment: ULONGLONG);
--%%     1: (
--%%       Next: SLIST_ENTRY;
--%%       Depth: WORD;
--%%       Sequence: WORD);
--%%   end;
--%%   {$EXTERNALSYM _SLIST_HEADER}
   subtype S_List_Header_Type is _SLIST_HEADER;
   type S_List_Header_Ptr is access all _SLIST_HEADER;
   type S_List_Header_CPtr is access constant _SLIST_HEADER;

--%% procedure RtlInitializeSListHead(ListHead: PSLIST_HEADER); stdcall;
--%% function RtlFirstEntrySList(ListHead: PSLIST_HEADER): PSLIST_ENTRY; stdcall;
--%% function RtlInterlockedPopEntrySList(ListHead: PSLIST_HEADER): PSLIST_ENTRY; stdcall;
--%% {$EXTERNALSYM RtlInterlockedPopEntrySList}
--%% {$IFNDEF JWA_INCLUDEMODE}
--%% function RtlInterlockedPushEntrySList(ListHead, ListEntry: PSLIST_HEADER): PSLIST_ENTRY; stdcall;
--%% {$EXTERNALSYM RtlInterlockedPushEntrySList}
--%% {$ENDIF JWA_INCLUDEMODE}
--%% function RtlInterlockedFlushSList(ListHead: PSLIST_HEADER): PSLIST_ENTRY; stdcall;
--%% {$EXTERNALSYM RtlInterlockedFlushSList}
--%% function RtlQueryDepthSList(ListHead: PSLIST_HEADER): WORD; stdcall;
--%% {$EXTERNALSYM RtlQueryDepthSList}

   Heap_No_Serialize             : constant := 16#0000_0001#;
   Heap_Growable                 : constant := 16#0000_0002#;
   Heap_Generate_Exceptions      : constant := 16#0000_0004#;
   Heap_Zero_Memory              : constant := 16#0000_0008#;
   Heap_Realloc_In_Place_Only    : constant := 16#0000_0010#;
   Heap_Tail_Checking_Enabled    : constant := 16#0000_0020#;
   Heap_Free_Checking_Enabled    : constant := 16#0000_0040#;
   Heap_Disable_Coalesce_On_Free : constant := 16#0000_0080#;
   Heap_Create_Align_16          : constant := 16#0001_0000#;
   Heap_Create_Enable_Tracing    : constant := 16#0002_0000#;
   Heap_Maximum_Tag              : constant := 16#0FFF#;
   Heap_Pseudo_Tag_Flag          : constant := 16#8000#;
   Heap_Tag_Shift                : constant := 18;

--%% function HEAP_MAKE_TAG_FLAGS(b, o: DWORD): DWORD;
--%% {$EXTERNALSYM HEAP_MAKE_TAG_FLAGS}

--%% procedure RtlCaptureContext(ContextRecord: PCONTEXT); stdcall;
--%% {$EXTERNALSYM RtlCaptureContext}

   Is_Text_Unicode_Ascii16         : constant := 16#0001#;
   Is_Text_Unicode_Reverse_Ascii16 : constant := 16#0010#;

   Is_Text_Unicode_Statistics         : constant := 16#0002#;
   Is_Text_Unicode_Reverse_Statistics : constant := 16#0020#;

   Is_Text_Unicode_Controls         : constant := 16#0004#;
   Is_Text_Unicode_Reverse_Controls : constant := 16#0040#;

   Is_Text_Unicode_Signature         : constant := 16#0008#;
   Is_Text_Unicode_Reverse_Signature : constant := 16#0080#;

   Is_Text_Unicode_Illegal_Chars : constant := 16#0100#;
   Is_Text_Unicode_Odd_Length    : constant := 16#0200#;
   Is_Text_Unicode_Dbcs_Leadbyte : constant := 16#0400#;
   Is_Text_Unicode_Null_Bytes    : constant := 16#1000#;

   Is_Text_Unicode_Unicode_Mask     : constant := 16#000F#;
   Is_Text_Unicode_Reverse_Mask     : constant := 16#00F0#;
   Is_Text_Unicode_Not_Unicode_Mask : constant := 16#0F00#;
   Is_Text_Unicode_Not_Ascii_Mask   : constant := 16#F000#;

   Compression_Format_None     : constant := 16#0000#;
   Compression_Format_Default  : constant := 16#0001#;
   Compression_Format_Lznt1    : constant := 16#0002#;
   Compression_Engine_Standard : constant := 16#0000#;
   Compression_Engine_Maximum  : constant := 16#0100#;
   Compression_Engine_Hiber    : constant := 16#0200#;

--%% function RtlCompareMemory(const Source1, Source2: Pointer; Length: SIZE_T): SIZE_T; stdcall;
--%% {$EXTERNALSYM RtlCompareMemory}

--%%   PMESSAGE_RESOURCE_ENTRY = ^MESSAGE_RESOURCE_ENTRY;
--%%   {$EXTERNALSYM PMESSAGE_RESOURCE_ENTRY}
--%%   _MESSAGE_RESOURCE_ENTRY = record
--%%     Length: Word;
--%%     Flags: Word;
--%%     Text: array [0..0] of Byte;
--%%   end;
--%%   {$EXTERNALSYM _MESSAGE_RESOURCE_ENTRY}
--%%   MESSAGE_RESOURCE_ENTRY = _MESSAGE_RESOURCE_ENTRY;
--%%   {$EXTERNALSYM MESSAGE_RESOURCE_ENTRY}
--%%   TMessageResourceEntry = MESSAGE_RESOURCE_ENTRY;
--%%   PMessageResourceEntry = PMESSAGE_RESOURCE_ENTRY;

   Message_Resource_Unicode : constant := 16#0001#;

   type Message_Resource_Block_Type;
   type Message_Resource_Block_Ptr is access all Message_Resource_Block_Type;
   type Message_Resource_Block_CPtr is access constant Message_Resource_Block_Type;
   type Message_Resource_Block_Type is record
      Low_Id : Unsigned_32;
      High_Id : Unsigned_32;
      Offset_To_Entries : Unsigned_32;
   end record;

--%%   PMESSAGE_RESOURCE_DATA = ^MESSAGE_RESOURCE_DATA;
--%%   {$EXTERNALSYM PMESSAGE_RESOURCE_DATA}
--%%   _MESSAGE_RESOURCE_DATA = record
--%%     NumberOfBlocks: DWORD;
--%%     Blocks: array [0..0] of MESSAGE_RESOURCE_BLOCK;
--%%   end;
--%%   {$EXTERNALSYM _MESSAGE_RESOURCE_DATA}
--%%   MESSAGE_RESOURCE_DATA = _MESSAGE_RESOURCE_DATA;
--%%   {$EXTERNALSYM MESSAGE_RESOURCE_DATA}
--%%   TMessageResourceData = MESSAGE_RESOURCE_DATA;
--%%   PMessageResourceData = PMESSAGE_RESOURCE_DATA;

--%%   LPOSVERSIONINFOA = ^OSVERSIONINFOA;
--%%   {$EXTERNALSYM LPOSVERSIONINFOA}
--%%   _OSVERSIONINFOA = record
--%%     dwOSVersionInfoSize: DWORD;
--%%     dwMajorVersion: DWORD;
--%%     dwMinorVersion: DWORD;
--%%     dwBuildNumber: DWORD;
--%%     dwPlatformId: DWORD;
--%%     szCSDVersion: array [0..127] of CHAR; // Maintenance string for PSS usage
--%%   end;
--%%   {$EXTERNALSYM _OSVERSIONINFOA}
--%%   OSVERSIONINFOA = _OSVERSIONINFOA;
--%%   {$EXTERNALSYM OSVERSIONINFOA}
--%%   TOsVersionInfoA = OSVERSIONINFOA;
--%%   POsVersionInfoA = LPOSVERSIONINFOA;

--%%   LPOSVERSIONINFOW = ^OSVERSIONINFOW;
--%%   {$EXTERNALSYM LPOSVERSIONINFOW}
--%%   _OSVERSIONINFOW = record
--%%     dwOSVersionInfoSize: DWORD;
--%%     dwMajorVersion: DWORD;
--%%     dwMinorVersion: DWORD;
--%%     dwBuildNumber: DWORD;
--%%     dwPlatformId: DWORD;
--%%     szCSDVersion: array [0..127] of WCHAR; // Maintenance string for PSS usage
--%%   end;
--%%   {$EXTERNALSYM _OSVERSIONINFOW}
--%%   OSVERSIONINFOW = _OSVERSIONINFOW;
--%%   {$EXTERNALSYM OSVERSIONINFOW}
--%%   TOsVersionInfoW = OSVERSIONINFOW;
--%%   POsVersionInfoW = LPOSVERSIONINFOW;

--%%   {$IFDEF UNICODE}
--%%   OSVERSIONINFO = OSVERSIONINFOW;
--%%   {$EXTERNALSYM OSVERSIONINFO}
--%%   POSVERSIONINFO = POSVERSIONINFOW;
--%%   {$EXTERNALSYM POSVERSIONINFO}
--%%   LPOSVERSIONINFO = LPOSVERSIONINFOW;
--%%   {$EXTERNALSYM LPOSVERSIONINFO}
--%%   TOSVersionInfo = TOSVersionInfoW;
--%%   {$ELSE}
--%%   OSVERSIONINFO = OSVERSIONINFOA;
--%%   {$EXTERNALSYM OSVERSIONINFO}
--%%   POSVERSIONINFO = POSVERSIONINFOA;
--%%   {$EXTERNALSYM POSVERSIONINFO}
--%%   LPOSVERSIONINFO = LPOSVERSIONINFOA;
--%%   {$EXTERNALSYM LPOSVERSIONINFO}
--%%   TOSVersionInfo = TOSVersionInfoA;
--%%   {$ENDIF UNICODE}

--%%   POSVERSIONINFOEXA = ^OSVERSIONINFOEXA;
--%%   {$EXTERNALSYM POSVERSIONINFOEXA}
--%%   _OSVERSIONINFOEXA = record
--%%     dwOSVersionInfoSize: DWORD;
--%%     dwMajorVersion: DWORD;
--%%     dwMinorVersion: DWORD;
--%%     dwBuildNumber: DWORD;
--%%     dwPlatformId: DWORD;
--%%     szCSDVersion: array [0..127] of CHAR;     // Maintenance string for PSS usage
--%%     wServicePackMajor: WORD;
--%%     wServicePackMinor: WORD;
--%%     wSuiteMask: WORD;
--%%     wProductType: BYTE;
--%%     wReserved: BYTE;
--%%   end;
--%%   {$EXTERNALSYM _OSVERSIONINFOEXA}
--%%   OSVERSIONINFOEXA = _OSVERSIONINFOEXA;
--%%   {$EXTERNALSYM OSVERSIONINFOEXA}
--%%   LPOSVERSIONINFOEXA = ^OSVERSIONINFOEXA;
--%%   {$EXTERNALSYM LPOSVERSIONINFOEXA}
--%%   TOSVersionInfoExA = _OSVERSIONINFOEXA;

--%%   POSVERSIONINFOEXW = ^OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM POSVERSIONINFOEXW}
--%%   _OSVERSIONINFOEXW = record
--%%     dwOSVersionInfoSize: DWORD;
--%%     dwMajorVersion: DWORD;
--%%     dwMinorVersion: DWORD;
--%%     dwBuildNumber: DWORD;
--%%     dwPlatformId: DWORD;
--%%     szCSDVersion: array [0..127] of WCHAR;     // Maintenance string for PSS usage
--%%     wServicePackMajor: WORD;
--%%     wServicePackMinor: WORD;
--%%     wSuiteMask: WORD;
--%%     wProductType: BYTE;
--%%     wReserved: BYTE;
--%%   end;
--%%   {$EXTERNALSYM _OSVERSIONINFOEXW}
--%%   OSVERSIONINFOEXW = _OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM OSVERSIONINFOEXW}
--%%   LPOSVERSIONINFOEXW = ^OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM LPOSVERSIONINFOEXW}
--%%   RTL_OSVERSIONINFOEXW = _OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM RTL_OSVERSIONINFOEXW}
--%%   PRTL_OSVERSIONINFOEXW = ^RTL_OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM PRTL_OSVERSIONINFOEXW}
--%%   TOSVersionInfoExW = _OSVERSIONINFOEXW;

--%%   {$IFDEF UNICODE}
--%%   OSVERSIONINFOEX = OSVERSIONINFOEXW;
--%%   {$EXTERNALSYM OSVERSIONINFOEX}
--%%   POSVERSIONINFOEX = POSVERSIONINFOEXW;
--%%   {$EXTERNALSYM POSVERSIONINFOEX}
--%%   LPOSVERSIONINFOEX = LPOSVERSIONINFOEXW;
--%%   {$EXTERNALSYM LPOSVERSIONINFOEX}
--%%   TOSVersionInfoEx = TOSVersionInfoExW;
--%%   {$ELSE}
--%%   OSVERSIONINFOEX = OSVERSIONINFOEXA;
--%%   {$EXTERNALSYM OSVERSIONINFOEX}
--%%   POSVERSIONINFOEX = POSVERSIONINFOEXA;
--%%   {$EXTERNALSYM POSVERSIONINFOEX}
--%%   LPOSVERSIONINFOEX = LPOSVERSIONINFOEXA;
--%%   {$EXTERNALSYM LPOSVERSIONINFOEX}
--%%   TOSVersionInfoEx = TOSVersionInfoExA;
--%%   {$ENDIF UNICODE}

--
-- RtlVerifyVersionInfo() conditions
--

   Ver_Equal         : constant := 1;
   Ver_Greater       : constant := 2;
   Ver_Greater_Equal : constant := 3;
   Ver_Less          : constant := 4;
   Ver_Less_Equal    : constant := 5;
   Ver_And           : constant := 6;
   Ver_Or            : constant := 7;

   Ver_Condition_Mask              : constant := 7;
   Ver_Num_Bits_Per_Condition_Mask : constant := 3;

--
-- RtlVerifyVersionInfo() type mask bits
--

   Ver_Minorversion     : constant := 16#0000001#;
   Ver_Majorversion     : constant := 16#0000002#;
   Ver_Buildnumber      : constant := 16#0000004#;
   Ver_Platformid       : constant := 16#0000008#;
   Ver_Servicepackminor : constant := 16#0000010#;
   Ver_Servicepackmajor : constant := 16#0000020#;
   Ver_Suitename        : constant := 16#0000040#;
   Ver_Product_Type     : constant := 16#0000080#;

--
-- RtlVerifyVersionInfo() os product type values
--

   Ver_NT_Workstation       : constant := 16#0000001#;
   Ver_NT_Domain_Controller : constant := 16#0000002#;
   Ver_NT_Server            : constant := 16#0000003#;

--
-- dwPlatformId defines:
--

   Ver_Platform_Win32s        : constant := 0;
   Ver_Platform_Win32_Windows : constant := 1;
   Ver_Platform_Win32_NT      : constant := 2;

--
--
-- VerifyVersionInfo() macro to set the condition mask
--
-- For documentation sakes here's the old version of the macro that got
-- changed to call an API
-- #define VER_SET_CONDITION(_m_,_t_,_c_)  _m_=(_m_|(_c_<<(1<<_t_)))
--

--%% procedure VER_SET_CONDITION(var Mask: DWORDLONG; TypeBitmask, ConditionMask: ULONG);
--%% {$EXTERNALSYM VER_SET_CONDITION}

--%% function VerSetConditionMask(ConditionMask: ULONGLONG; TypeMask: DWORD;
--%%   Condition: BYTE): ULONGLONG; stdcall;
--%% {$EXTERNALSYM VerSetConditionMask}

--%%   PRTL_CRITICAL_SECTION_DEBUG = ^RTL_CRITICAL_SECTION_DEBUG;
--%%   {$EXTERNALSYM PRTL_CRITICAL_SECTION_DEBUG}
--%%   _RTL_CRITICAL_SECTION_DEBUG = record
--%%     _Type: WORD;
--%%     CreatorBackTraceIndex: WORD;
--%%     CriticalSection: PRTL_CRITICAL_SECTION_DEBUG;
--%%     ProcessLocksList: LIST_ENTRY;
--%%     EntryCount: DWORD;
--%%     ContentionCount: DWORD;
--%%     Spare: array [0..1] of DWORD;
--%%   end;
--%%   {$EXTERNALSYM _RTL_CRITICAL_SECTION_DEBUG}
--%%   RTL_CRITICAL_SECTION_DEBUG = _RTL_CRITICAL_SECTION_DEBUG;
--%%   {$EXTERNALSYM RTL_CRITICAL_SECTION_DEBUG}
--%%   TRtlCriticalSectionDebug = RTL_CRITICAL_SECTION_DEBUG;
--%%   PRtlCriticalSectionDebug = PRTL_CRITICAL_SECTION_DEBUG;
--%%   RTL_RESOURCE_DEBUG = _RTL_CRITICAL_SECTION_DEBUG;
--%%   {$EXTERNALSYM RTL_RESOURCE_DEBUG}
--%%   PRTL_RESOURCE_DEBUG = RTL_RESOURCE_DEBUG;
--%%   {$EXTERNALSYM PRTL_RESOURCE_DEBUG}
--%%   TRtlResourceDebug = RTL_CRITICAL_SECTION_DEBUG;
--%%   PRtlResourceDebug = PRTL_CRITICAL_SECTION_DEBUG;

   Rtl_Critsect_Type : constant := 0;
   Rtl_Resource_Type : constant := 1;

--%%   PRTL_CRITICAL_SECTION = ^RTL_CRITICAL_SECTION;
--%%   {$EXTERNALSYM PRTL_CRITICAL_SECTION}
--%%   _RTL_CRITICAL_SECTION = record
--%%     DebugInfo: PRTL_CRITICAL_SECTION_DEBUG;

--%%     //
--%%     //  The following three fields control entering and exiting the critical
--%%     //  section for the resource
--%%     //

--%%     LockCount: LONG;
--%%     RecursionCount: LONG;
--%%     OwningThread: HANDLE;        // from the thread's ClientId->UniqueThread
--%%     LockSemaphore: HANDLE;
--%%     SpinCount: ULONG_PTR;        // force size on 64-bit systems when packed
--%%   end;
--%%   {$EXTERNALSYM _RTL_CRITICAL_SECTION}
--%%   RTL_CRITICAL_SECTION = _RTL_CRITICAL_SECTION;
--%%   {$EXTERNALSYM RTL_CRITICAL_SECTION}
--%%   TRtlCriticalSection = RTL_CRITICAL_SECTION;
--%%   PRtlCriticalSection = PRTL_CRITICAL_SECTION;

--%%   RTL_VERIFIER_DLL_LOAD_CALLBACK = procedure(DllName: PWSTR; DllBase: PVOID; DllSize: SIZE_T;
--%%     Reserved: PVOID); stdcall;
--%%   {$EXTERNALSYM RTL_VERIFIER_DLL_LOAD_CALLBACK}

--%%   RTL_VERIFIER_DLL_UNLOAD_CALLBACK = procedure(DllName: PWSTR; DllBase: PVOID; DllSize: SIZE_T;
--%%     Reserved: PVOID); stdcall;
--%%   {$EXTERNALSYM RTL_VERIFIER_DLL_UNLOAD_CALLBACK}

--%%   RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK = procedure(AllocationBase: PVOID; AllocationSize: SIZE_T); stdcall;
--%%   {$EXTERNALSYM RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK}

   type Rtl_Verifier_Thunk_Descriptor_Type;
   type Rtl_Verifier_Thunk_Descriptor_Ptr is access all Rtl_Verifier_Thunk_Descriptor_Type;
   type Rtl_Verifier_Thunk_Descriptor_CPtr is access constant Rtl_Verifier_Thunk_Descriptor_Type;
   type Rtl_Verifier_Thunk_Descriptor_Type is record
      Thunk_Name : Char_8_Ptr;
      Thunk_Old_Address : System.Address;
      Thunk_New_Address : System.Address;
   end record;

   type Rtl_Verifier_DLL_Descriptor_Type;
   type Rtl_Verifier_DLL_Descriptor_Ptr is access all Rtl_Verifier_DLL_Descriptor_Type;
   type Rtl_Verifier_DLL_Descriptor_CPtr is access constant Rtl_Verifier_DLL_Descriptor_Type;
   type Rtl_Verifier_DLL_Descriptor_Type is record
      DLL_Name : Char_16_Ptr;
      DLL_Flags : Unsigned_32;
      DLL_Address : System.Address;
      DLL_Thunks : Rtl_Verifier_Thunk_Descriptor_Ptr;
   end record;

--%%   PRTL_VERIFIER_PROVIDER_DESCRIPTOR = ^RTL_VERIFIER_PROVIDER_DESCRIPTOR;
--%%   {$EXTERNALSYM PRTL_VERIFIER_PROVIDER_DESCRIPTOR}
--%%   _RTL_VERIFIER_PROVIDER_DESCRIPTOR = record
--%%     //
--%%     // Filled by verifier provider DLL
--%%     //
--%%     Length: DWORD;
--%%     ProviderDlls: PRTL_VERIFIER_DLL_DESCRIPTOR;
--%%     ProviderDllLoadCallback: RTL_VERIFIER_DLL_LOAD_CALLBACK;
--%%     ProviderDllUnloadCallback: RTL_VERIFIER_DLL_UNLOAD_CALLBACK;
--%%     //
--%%     // Filled by verifier engine
--%%     //
--%%     VerifierImage: PWSTR;
--%%     VerifierFlags: DWORD;
--%%     VerifierDebug: DWORD;

--%%     RtlpGetStackTraceAddress: PVOID;
--%%     RtlpDebugPageHeapCreate: PVOID;
--%%     RtlpDebugPageHeapDestroy: PVOID;

--%%     //
--%%     // Filled by verifier provider DLL
--%%     // 
--%%     
--%%     ProviderNtdllHeapFreeCallback: RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK;
--%%   end;
--%%   {$EXTERNALSYM _RTL_VERIFIER_PROVIDER_DESCRIPTOR}
--%%   RTL_VERIFIER_PROVIDER_DESCRIPTOR = _RTL_VERIFIER_PROVIDER_DESCRIPTOR;
--%%   {$EXTERNALSYM RTL_VERIFIER_PROVIDER_DESCRIPTOR}
--%%   TRtlVerifierProviderDescriptor = RTL_VERIFIER_PROVIDER_DESCRIPTOR;
--%%   PRtlVerifierProviderDescriptor = PRTL_VERIFIER_PROVIDER_DESCRIPTOR;

--
-- Application verifier standard flags
--

   Rtl_Vrf_Flg_Full_Page_Heap                 : constant := 16#0000_0001#;
   Rtl_Vrf_Flg_Reserved_Donotuse              : constant := 16#0000_0002#; -- old RTL_VRF_FLG_LOCK_CHECKS
   Rtl_Vrf_Flg_Handle_Checks                  : constant := 16#0000_0004#;
   Rtl_Vrf_Flg_Stack_Checks                   : constant := 16#0000_0008#;
   Rtl_Vrf_Flg_Appcompat_Checks               : constant := 16#0000_0010#;
   Rtl_Vrf_Flg_Tls_Checks                     : constant := 16#0000_0020#;
   Rtl_Vrf_Flg_Dirty_Stacks                   : constant := 16#0000_0040#;
   Rtl_Vrf_Flg_RPC_Checks                     : constant := 16#0000_0080#;
   Rtl_Vrf_Flg_COM_Checks                     : constant := 16#0000_0100#;
   Rtl_Vrf_Flg_Dangerous_Apis                 : constant := 16#0000_0200#;
   Rtl_Vrf_Flg_Race_Checks                    : constant := 16#0000_0400#;
   Rtl_Vrf_Flg_Deadlock_Checks                : constant := 16#0000_0800#;
   Rtl_Vrf_Flg_First_Chance_Exception_Checks  : constant := 16#0000_1000#;
   Rtl_Vrf_Flg_Virtual_Mem_Checks             : constant := 16#0000_2000#;
   Rtl_Vrf_Flg_Enable_Logging                 : constant := 16#0000_4000#;
   Rtl_Vrf_Flg_Fast_Fill_Heap                 : constant := 16#0000_8000#;
   Rtl_Vrf_Flg_Virtual_Space_Tracking         : constant := 16#0001_0000#;
   Rtl_Vrf_Flg_Enabled_System_Wide            : constant := 16#0002_0000#;
   Rtl_Vrf_Flg_Miscellaneous_Checks           : constant := 16#0002_0000#;
   Rtl_Vrf_Flg_Lock_Checks                    : constant := 16#0004_0000#;

--
-- Application verifier standard stop codes
--

   Application_Verifier_Internal_Error    : constant := 16#8000_0000#;
   Application_Verifier_Internal_Warning  : constant := 16#4000_0000#;
   Application_Verifier_No_Break          : constant := 16#2000_0000#;
   Application_Verifier_Continuable_Break : constant := 16#1000_0000#;

   Application_Verifier_Unknown_Error         : constant := 16#0001#;
   Application_Verifier_Access_Violation      : constant := 16#0002#;
   Application_Verifier_Unsynchronized_Access : constant := 16#0003#;
   Application_Verifier_Extreme_Size_Request  : constant := 16#0004#;
   Application_Verifier_Bad_Heap_Handle       : constant := 16#0005#;
   Application_Verifier_Switched_Heap_Handle  : constant := 16#0006#;
   Application_Verifier_Double_Free           : constant := 16#0007#;
   Application_Verifier_Corrupted_Heap_Block  : constant := 16#0008#;
   Application_Verifier_Destroy_Process_Heap  : constant := 16#0009#;
   Application_Verifier_Unexpected_Exception  : constant := 16#000A#;
   Application_Verifier_Stack_Overflow        : constant := 16#000B#;

   Application_Verifier_Terminate_Thread_Call : constant := 16#0100#;
   Application_Verifier_Invalid_Exit_Process_Call : constant := 16#0101#;

   Application_Verifier_Exit_Thread_Owns_Lock        : constant := 16#0200#;
   Application_Verifier_Lock_In_Unloaded_DLL         : constant := 16#0201#;
   Application_Verifier_Lock_In_Freed_Heap           : constant := 16#0202#;
   Application_Verifier_Lock_Double_Initialize       : constant := 16#0203#;
   Application_Verifier_Lock_In_Freed_Memory         : constant := 16#0204#;
   Application_Verifier_Lock_Corrupted               : constant := 16#0205#;
   Application_Verifier_Lock_Invalid_Owner           : constant := 16#0206#;
   Application_Verifier_Lock_Invalid_Recursion_Count : constant := 16#0207#;
   Application_Verifier_Lock_Invalid_Lock_Count      : constant := 16#0208#;
   Application_Verifier_Lock_Over_Released           : constant := 16#0209#;
   Application_Verifier_Lock_Not_Initialized         : constant := 16#0210#;
   Application_Verifier_Lock_Already_Initialized     : constant := 16#0211#;

   Application_Verifier_Invalid_Handle      : constant := 16#0300#;
   Application_Verifier_Invalid_Tls_Value   : constant := 16#0301#;
   Application_Verifier_Incorrect_Wait_Call : constant := 16#0302#;
   Application_Verifier_Null_Handle         : constant := 16#0303#;
   Application_Verifier_Wait_In_Dllmain     : constant := 16#0304#;

   Application_Verifier_COM_Error                   : constant := 16#0400#;
   Application_Verifier_COM_Api_In_Dllmain          : constant := 16#0401#;
   Application_Verifier_COM_Unhandled_Exception     : constant := 16#0402#;
   Application_Verifier_COM_Unbalanced_Coinit       : constant := 16#0403#;
   Application_Verifier_COM_Unbalanced_Oleinit      : constant := 16#0404#;
   Application_Verifier_COM_Unbalanced_Swc          : constant := 16#0405#;
   Application_Verifier_COM_Null_DACL               : constant := 16#0406#;
   Application_Verifier_COM_Unsafe_Impersonation    : constant := 16#0407#;
   Application_Verifier_COM_Smuggled_Wrapper        : constant := 16#0408#;
   Application_Verifier_COM_Smuggled_Proxy          : constant := 16#0409#;
   Application_Verifier_COM_Cf_Success_With_Null    : constant := 16#040A#;
   Application_Verifier_COM_Gco_Success_With_Null   : constant := 16#040B#;
   Application_Verifier_COM_Object_In_Freed_Memory  : constant := 16#040C#;
   Application_Verifier_COM_Object_In_Unloaded_DLL  : constant := 16#040D#;
   Application_Verifier_COM_Vtbl_In_Freed_Memory    : constant := 16#040E#;
   Application_Verifier_COM_Vtbl_In_Unloaded_DLL    : constant := 16#040F#;
   Application_Verifier_COM_Holding_Locks_On_Call   : constant := 16#0410#;

   Application_Verifier_RPC_Error                  : constant := 16#0500#;

   Application_Verifier_Invalid_Freemem            : constant := 16#0600#;
   Application_Verifier_Invalid_Allocmem           : constant := 16#0601#;
   Application_Verifier_Invalid_Mapview            : constant := 16#0602#;
   Application_Verifier_Probe_Invalid_Address        : constant := 16#0603#;
   Application_Verifier_Probe_Free_Mem               : constant := 16#0604#;
   Application_Verifier_Probe_Guard_Page             : constant := 16#0605#;
   Application_Verifier_Probe_Null                   : constant := 16#0606#;
   Application_Verifier_Probe_Invalid_Start_Or_Size  : constant := 16#0607#;

--%% (* TODO
--%% #define VERIFIER_STOP(Code, Msg, P1, S1, P2, S2, P3, S3, P4, S4) {  \
--%%         RtlApplicationVerifierStop ((Code),                         \
--%%                                     (Msg),                          \
--%%                                     (ULONG_PTR)(P1),(S1),           \
--%%                                     (ULONG_PTR)(P2),(S2),           \
--%%                                     (ULONG_PTR)(P3),(S3),           \
--%%                                     (ULONG_PTR)(P4),(S4));          \
--%%   }

--%% VOID NTAPI
--%% RtlApplicationVerifierStop (
--%%     ULONG_PTR Code,
--%%     PAnsiChar Message,
--%%     ULONG_PTR Param1, PAnsiChar Description1,
--%%     ULONG_PTR Param2, PAnsiChar Description2,
--%%     ULONG_PTR Param3, PAnsiChar Description3,
--%%     ULONG_PTR Param4, PAnsiChar Description4
--%%     );
--%% *)

--%%   PVECTORED_EXCEPTION_HANDLER = function(ExceptionInfo: PEXCEPTION_POINTERS): LONG; stdcall;
--%%   {$EXTERNALSYM PVECTORED_EXCEPTION_HANDLER}
--%%   PVectoredExceptionHandler = PVECTORED_EXCEPTION_HANDLER;

   Sef_DACL_Auto_Inherit             : constant := 16#01#;
   Sef_SACL_Auto_Inherit             : constant := 16#02#;
   Sef_Default_Descriptor_For_Object : constant := 16#04#;
   Sef_Avoid_Privilege_Check         : constant := 16#08#;
   Sef_Avoid_Owner_Check             : constant := 16#10#;
   Sef_Default_Owner_From_Parent     : constant := 16#20#;
   Sef_Default_Group_From_Parent     : constant := 16#40#;

--%%   _HEAP_INFORMATION_CLASS = (HeapCompatibilityInformation);
--%%   {$EXTERNALSYM _HEAP_INFORMATION_CLASS}
--%%   HEAP_INFORMATION_CLASS = _HEAP_INFORMATION_CLASS;
--%%   {$EXTERNALSYM HEAP_INFORMATION_CLASS}
--%%   THeapInformationClass = HEAP_INFORMATION_CLASS;

--%% { TODO
--%% DWORD NTAPI
--%% RtlSetHeapInformation (
--%%     IN PVOID HeapHandle,
--%%     IN HEAP_INFORMATION_CLASS HeapInformationClass,
--%%     IN PVOID HeapInformation OPTIONAL,
--%%     IN SIZE_T HeapInformationLength OPTIONAL
--%%     );

--%% DWORD NTAPI
--%% RtlQueryHeapInformation (
--%%     IN PVOID HeapHandle,
--%%     IN HEAP_INFORMATION_CLASS HeapInformationClass,
--%%     OUT PVOID HeapInformation OPTIONAL,
--%%     IN SIZE_T HeapInformationLength OPTIONAL,
--%%     OUT PSIZE_T ReturnLength OPTIONAL
--%%     );

--
--  Multiple alloc-free APIS
--

--%% DWORD
--%% NTAPI
--%% RtlMultipleAllocateHeap (
--%%     IN PVOID HeapHandle,
--%%     IN DWORD Flags,
--%%     IN SIZE_T Size,
--%%     IN DWORD Count,
--%%     OUT PVOID * Array
--%%     );

--%% DWORD
--%% NTAPI
--%% RtlMultipleFreeHeap (
--%%     IN PVOID HeapHandle,
--%%     IN DWORD Flags,
--%%     IN DWORD Count,
--%%     OUT PVOID * Array
--%%     );
--%% }

   Wt_Executedefault                 : constant := 16#0000_0000#;
   Wt_Executeiniothread              : constant := 16#0000_0001#;
   Wt_Executeinuithread              : constant := 16#0000_0002#;
   Wt_Executeinwaitthread            : constant := 16#0000_0004#;
   Wt_Executeonlyonce                : constant := 16#0000_0008#;
   Wt_Executeintimerthread           : constant := 16#0000_0020#;
   Wt_Executelongfunction            : constant := 16#0000_0010#;
   Wt_Executeinpersistentiothread    : constant := 16#0000_0040#;
   Wt_Executeinpersistentthread      : constant := 16#0000_0080#;
   Wt_Transfer_Impersonation         : constant := 16#0000_0100#;

--%% function WT_SET_MAX_THREADPOOL_THREADS(var Flags: DWORD; Limit: DWORD): DWORD;
--%% {$EXTERNALSYM WT_SET_MAX_THREADPOOL_THREADS}

--%%   WAITORTIMERCALLBACKFUNC = procedure(P: PVOID; B: ByteBool); stdcall;
--%%   {$EXTERNALSYM WAITORTIMERCALLBACKFUNC}
--%%   WORKERCALLBACKFUNC = procedure(P: PVOID); stdcall;
--%%   {$EXTERNALSYM WORKERCALLBACKFUNC}
--%%   APC_CALLBACK_FUNCTION = procedure(D: DWORD; P1, P2: PVOID); stdcall;
--%%   {$EXTERNALSYM APC_CALLBACK_FUNCTION}

   Wt_Executeinlongthread : constant := 16#0000_0010#;
   Wt_Executedeletewait   : constant := 16#0000_0008#;

   subtype _Activation_Context_Info_Class_Type is Unsigned_32;
   subtype _Activation_Context_Info_Class_Ptr is Unsigned_32_Ptr;
   subtype _Activation_Context_Info_Class_CPtr is Unsigned_32_CPtr;
   subtype Activation_Context_Info_Class_Type is _Activation_Context_Info_Class_Type;
   subtype Activation_Context_Info_Class_Ptr is _Activation_Context_Info_Class_Ptr;
   subtype Activation_Context_Info_Class_CPtr is _Activation_Context_Info_Class_CPtr;
--%%   TActivationContextInfoClass = ACTIVATION_CONTEXT_INFO_CLASS;

   ActivationContextBasicInformation                       : constant := 1;
   ActivationContextDetailedInformation                    : constant := 2;
   AssemblyDetailedInformationInActivationContxt           : constant := 3;
   FileInformationInAssemblyOfAssemblyInActivationContxt   : constant := 4;
   MaxActivationContextInfoClass                           : constant := 5;

   type Activation_Context_Query_Index_Type;
   type Activation_Context_Query_Index_Ptr is access all Activation_Context_Query_Index_Type;
   type Activation_Context_Query_Index_CPtr is access constant Activation_Context_Query_Index_Type;
   type Activation_Context_Query_Index_Type is record
      Assembly_Index : Unsigned_32;
      File_Index_In_Assembly : Unsigned_32;
   end record;

   Activation_Context_Path_Type_None        : constant := 1;
   Activation_Context_Path_Type_Win32_File  : constant := 2;
   Activation_Context_Path_Type_Url         : constant := 3;
   Activation_Context_Path_Type_Assemblyref : constant := 4;

--%%   PASSEMBLY_FILE_DETAILED_INFORMATION = ^ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM PASSEMBLY_FILE_DETAILED_INFORMATION}
--%%   _ASSEMBLY_FILE_DETAILED_INFORMATION = record
--%%     ulFlags: DWORD;
--%%     ulFilenameLength: DWORD;
--%%     ulPathLength: DWORD;
--%%     lpFileName: LPCWSTR;
--%%     lpFilePath: LPCWSTR;
--%%   end;
--%%   {$EXTERNALSYM _ASSEMBLY_FILE_DETAILED_INFORMATION}
--%%   ASSEMBLY_FILE_DETAILED_INFORMATION = _ASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION}
--%%   PCASSEMBLY_FILE_DETAILED_INFORMATION = PASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM PCASSEMBLY_FILE_DETAILED_INFORMATION}
--%%   TAssemblyFileDetailedInformation = ASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   PAssemblyFileDetailedInformation = PASSEMBLY_FILE_DETAILED_INFORMATION;

--
-- compatibility with old names
-- The new names use "file" consistently.
--

--%%   _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = _ASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION}
--%%   ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = ASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION}
--%%   PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = PASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION}
--%%   PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION = PCASSEMBLY_FILE_DETAILED_INFORMATION;
--%%   {$EXTERNALSYM PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION}
--%%   TAssemblyDllRedirectionDetailedInformation = TAssemblyFileDetailedInformation;
--%%   PAssemblyDllRedirectionDetailedInformation = PAssemblyFileDetailedInformation;

   type Activation_Context_Assembly_Detailed_Information_Type;
   type Activation_Context_Assembly_Detailed_Information_Ptr is access all Activation_Context_Assembly_Detailed_Information_Type;
   type Activation_Context_Assembly_Detailed_Information_CPtr is access constant Activation_Context_Assembly_Detailed_Information_Type;
   type Activation_Context_Assembly_Detailed_Information_Type is record
      Flags : Unsigned_32;
      Encoded_Assembly_Identity_Length : Unsigned_32; -- in bytes
      Manifest_Path_Type : Unsigned_32;             -- ACTIVATION_CONTEXT_PATH_TYPE_*
      Manifest_Path_Length : Unsigned_32;           -- in bytes
      Manifest_Last_Write_Time : LARGE_INTEGER;     -- FILETIME
      Policy_Path_Type : Unsigned_32;               -- ACTIVATION_CONTEXT_PATH_TYPE_*
      Policy_Path_Length : Unsigned_32;             -- in bytes
      Policy_Last_Write_Time : LARGE_INTEGER;       -- FILETIME
      Metadata_Satellite_Roster_Index : Unsigned_32;
      Manifest_Version_Major : Unsigned_32;         -- 1
      Manifest_Version_Minor : Unsigned_32;         -- 0
      Policy_Version_Major : Unsigned_32;           -- 0
      Policy_Version_Minor : Unsigned_32;           -- 0
      Assembly_Directory_Name_Length : Unsigned_32; -- in bytes
      Assembly_Encoded_Assembly_Identity : Char_16_Ptr;
      Assembly_Manifest_Path : Char_16_Ptr;
      Assembly_Policy_Path : Char_16_Ptr;
      Assembly_Directory_Name : Char_16_Ptr;
      File_Count : Unsigned_32;
   end record;

   type Activation_Context_Detailed_Information_Type;
   type Activation_Context_Detailed_Information_Ptr is access all Activation_Context_Detailed_Information_Type;
   type Activation_Context_Detailed_Information_CPtr is access constant Activation_Context_Detailed_Information_Type;
   type Activation_Context_Detailed_Information_Type is record
      Flags : Unsigned_32;
      Format_Version : Unsigned_32;
      Assembly_Count : Unsigned_32;
      Root_Manifest_Path_Type : Unsigned_32;
      Root_Manifest_Path_Chars : Unsigned_32;
      Root_Configuration_Path_Type : Unsigned_32;
      Root_Configuration_Path_Chars : Unsigned_32;
      App_Dir_Path_Type : Unsigned_32;
      App_Dir_Path_Chars : Unsigned_32;
      Root_Manifest_Path : Char_16_Ptr;
      Root_Configuration_Path : Char_16_Ptr;
      App_Dir_Path : Char_16_Ptr;
   end record;

   DLL_Process_Attach     : constant := 1;
   DLL_Thread_Attach      : constant := 2;
   DLL_Thread_Detach      : constant := 3;
   DLL_Process_Detach     : constant := 0;
   DLL_Process_Verifier   : constant := 4;

--
-- Defines for the READ flags for Eventlogging
--

   Eventlog_Sequential_Read : constant := 16#0001#;
   Eventlog_Seek_Read       : constant := 16#0002#;
   Eventlog_Forwards_Read   : constant := 16#0004#;
   Eventlog_Backwards_Read  : constant := 16#0008#;

--
-- The types of events that can be logged.
--

   Eventlog_Success          : constant := 16#0000#;
   Eventlog_Error_Type       : constant := 16#0001#;
   Eventlog_Warning_Type     : constant := 16#0002#;
   Eventlog_Information_Type : constant := 16#0004#;
   Eventlog_Audit_Success    : constant := 16#0008#;
   Eventlog_Audit_Failure    : constant := 16#0010#;

--
-- Defines for the WRITE flags used by Auditing for paired events
-- These are not implemented in Product 1
--

   Eventlog_Start_Paired_Event    : constant := 16#0001#;
   Eventlog_End_Paired_Event      : constant := 16#0002#;
   Eventlog_End_All_Paired_Events : constant := 16#0004#;
   Eventlog_Paired_Event_Active   : constant := 16#0008#;
   Eventlog_Paired_Event_Inactive : constant := 16#0010#;

--
-- Structure that defines the header of the Eventlog record. This is the
-- fixed-sized portion before all the variable-length strings, binary
-- data and pad bytes.
--
-- TimeGenerated is the time it was generated at the client.
-- TimeWritten is the time it was put into the log at the server end.
--

--%%   PEventlogrecord = ^EVENTLOGRECORD;
--%%   _EVENTLOGRECORD = record
--%%     Length: DWORD; // Length of full record
--%%     Reserved: DWORD; // Used by the service
--%%     RecordNumber: DWORD; // Absolute record number
--%%     TimeGenerated: DWORD; // Seconds since 1-1-1970
--%%     TimeWritten: DWORD; // Seconds since 1-1-1970
--%%     EventID: DWORD;
--%%     EventType: Word;
--%%     NumStrings: Word;
--%%     EventCategory: Word;
--%%     ReservedFlags: Word; // For use with paired events (auditing)
--%%     ClosingRecordNumber: DWORD; // For use with paired events (auditing)
--%%     StringOffset: DWORD; // Offset from beginning of record
--%%     UserSidLength: DWORD;
--%%     UserSidOffset: DWORD;
--%%     DataLength: DWORD;
--%%     DataOffset: DWORD; // Offset from beginning of record
--%%     //
--%%     // Then follow:
--%%     //
--%%     // WCHAR SourceName[]
--%%     // WCHAR Computername[]
--%%     // SID   UserSid
--%%     // WCHAR Strings[]
--%%     // BYTE  Data[]
--%%     // CHAR  Pad[]
--%%     // DWORD Length;
--%%     //
--%%   end;
--%%   {$EXTERNALSYM _EVENTLOGRECORD}
--%%   EVENTLOGRECORD = _EVENTLOGRECORD;
--%%   {$EXTERNALSYM EVENTLOGRECORD}
--%%   TEventlogrecord = EVENTLOGRECORD;

   Maxlogicallognamesize : constant := 256;

--%%   PEventsForLogFile = ^EVENTSFORLOGFILE;
--%%   _EVENTSFORLOGFILE = record
--%%     ulSize: DWORD;
--%%     szLogicalLogFile: array [0..MAXLOGICALLOGNAMESIZE - 1] of WCHAR; // name of the logical file-security/application/system
--%%     ulNumRecords: DWORD;
--%%     pEventLogRecords: array [0..0] of EVENTLOGRECORD;
--%%   end;
--%%   {$EXTERNALSYM _EVENTSFORLOGFILE}
--%%   EVENTSFORLOGFILE = _EVENTSFORLOGFILE;
--%%   {$EXTERNALSYM EVENTSFORLOGFILE}
--%%   TEventsForLogFile = EVENTSFORLOGFILE;

--%%   PPackedEventInfo = ^PACKEDEVENTINFO;
--%%   _PACKEDEVENTINFO = record
--%%     ulSize: DWORD;                    // total size of the structure
--%%     ulNumEventsForLogFile: DWORD;     // number of EventsForLogFile structure that follow
--%%     ulOffsets: array [0..0] of DWORD; // the offsets from the start of this structure to the EVENTSFORLOGFILE structure
--%%   end;
--%%   {$EXTERNALSYM _PACKEDEVENTINFO}
--%%   PACKEDEVENTINFO = _PACKEDEVENTINFO;
--%%   {$EXTERNALSYM PACKEDEVENTINFO}
--%%   TPackedEventInfo = PACKEDEVENTINFO;

--
-- Registry Specific Access Rights.
--

   Key_Query_Value        : constant := 16#0001#;
   Key_Set_Value          : constant := 16#0002#;
   Key_Create_Sub_Key     : constant := 16#0004#;
   Key_Enumerate_Sub_Keys : constant := 16#0008#;
   Key_Notify             : constant := 16#0010#;
   Key_Create_Link        : constant := 16#0020#;
   Key_Wow64_32Key        : constant := 16#0200#;
   Key_Wow64_64Key        : constant := 16#0100#;
   Key_Wow64_Res          : constant := 16#0300#;

--%%   KEY_READ = STANDARD_RIGHTS_READ or KEY_QUERY_VALUE or KEY_ENUMERATE_SUB_KEYS or
--%%     KEY_NOTIFY  and (not SYNCHRONIZE);
--%%   {$EXTERNALSYM KEY_READ}

--%%   KEY_WRITE = STANDARD_RIGHTS_WRITE or KEY_SET_VALUE or KEY_CREATE_SUB_KEY and
--%%     (not SYNCHRONIZE);
--%%   {$EXTERNALSYM KEY_WRITE}

--%%   KEY_EXECUTE = KEY_READ and  (not SYNCHRONIZE);
--%%   {$EXTERNALSYM KEY_EXECUTE}

--%%   KEY_ALL_ACCESS = (STANDARD_RIGHTS_ALL or KEY_QUERY_VALUE or KEY_SET_VALUE or
--%%     KEY_CREATE_SUB_KEY or KEY_ENUMERATE_SUB_KEYS or KEY_NOTIFY or
--%%     KEY_CREATE_LINK) and (not SYNCHRONIZE);
--%%   {$EXTERNALSYM KEY_ALL_ACCESS}

--
-- Open/Create Options
--

   Reg_Option_Reserved : constant := 16#0000_0000#; -- Parameter is reserved

   Reg_Option_Non_Volatile : constant := 16#0000_0000#; -- Key is preserved when system is rebooted

   Reg_Option_Volatile : constant := 16#0000_0001#; -- Key is not preserved when system is rebooted

   Reg_Option_Create_Link : constant := 16#0000_0002#; -- Created key is a symbolic link

   Reg_Option_Backup_Restore : constant := 16#0000_0004#; -- open for backup or restore
--%%                                                     // special access rules
--%%                                                     // privilege required

   Reg_Option_Open_Link : constant := 16#0000_0008#; -- Open symbolic link

--%%   REG_LEGAL_OPTION = REG_OPTION_RESERVED or REG_OPTION_NON_VOLATILE or
--%%     REG_OPTION_VOLATILE or REG_OPTION_CREATE_LINK or REG_OPTION_BACKUP_RESTORE or
--%%     REG_OPTION_OPEN_LINK;
--%%   {$EXTERNALSYM REG_LEGAL_OPTION}

--
-- Key creation/open disposition
--

   Reg_Created_New_Key     : constant := 16#0000_0001#; -- New Registry Key created
   Reg_Opened_Existing_Key : constant := 16#0000_0002#; -- Existing Key opened

--
-- hive format to be used by Reg(Nt)SaveKeyEx
--

   Reg_Standard_Format    : constant := 1;
   Reg_Latest_Format      : constant := 2;
   Reg_No_Compression     : constant := 4;

--
-- Key restore flags
--

   Reg_Whole_Hive_Volatile : constant := 16#0000_0001#; -- Restore whole hive volatile
   Reg_Refresh_Hive        : constant := 16#0000_0002#; -- Unwind changes to last flush
   Reg_No_Lazy_Flush       : constant := 16#0000_0004#; -- Never lazy flush this hive
   Reg_Force_Restore       : constant := 16#0000_0008#; -- Force the restore process even when we have open handles on subkeys

--
-- Unload Flags
--

   Reg_Force_Unload : constant := 1;

-- end_ntddk end_wdm end_nthal

--
-- Notify filter values
--

   Reg_Notify_Change_Name       : constant := 16#0000_0001#; -- Create or delete (child)
   Reg_Notify_Change_Attributes : constant := 16#0000_0002#;
   Reg_Notify_Change_Last_Set   : constant := 16#0000_0004#; -- time stamp
   Reg_Notify_Change_Security   : constant := 16#0000_0008#;

--%%   REG_LEGAL_CHANGE_FILTER = REG_NOTIFY_CHANGE_NAME or REG_NOTIFY_CHANGE_ATTRIBUTES or
--%%     REG_NOTIFY_CHANGE_LAST_SET or REG_NOTIFY_CHANGE_SECURITY;
--%%   {$EXTERNALSYM REG_LEGAL_CHANGE_FILTER}

--
--
-- Predefined Value Types.
--

   Reg_None      : constant := 0; -- No value type
   Reg_Sz        : constant := 1; -- Unicode nul terminated string
   Reg_Expand_Sz : constant := 2; -- Unicode nul terminated string
--%%                                             // (with environment variable references)
   Reg_Binary                     : constant := 3; -- Free form binary
   Reg_DWord                      : constant := 4; -- 32-bit number
   Reg_DWord_Little_Endian        : constant := 4; -- 32-bit number (same as REG_DWORD)
   Reg_DWord_Big_Endian           : constant := 5; -- 32-bit number
   Reg_Link                       : constant := 6; -- Symbolic Link (unicode)
   Reg_Multi_Sz                   : constant := 7; -- Multiple Unicode strings
   Reg_Resource_List              : constant := 8; -- Resource list in the resource map
   Reg_Full_Resource_Descriptor   : constant := 9; -- Resource list in the hardware description
   Reg_Resource_Requirements_List : constant := 10;
   Reg_Qword                      : constant := 11; -- 64-bit number
   Reg_Qword_Little_Endian        : constant := 11; -- 64-bit number (same as REG_QWORD)

--
-- Service Types (Bit Mask)
--

   Service_Kernel_Driver      : constant := 16#0000_0001#;
   Service_File_System_Driver : constant := 16#0000_0002#;
   Service_Adapter            : constant := 16#0000_0004#;
   Service_Recognizer_Driver  : constant := 16#0000_0008#;

--%%   SERVICE_DRIVER = SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER or
--%%     SERVICE_RECOGNIZER_DRIVER;
--%%   {$EXTERNALSYM SERVICE_DRIVER}

   Service_Win32_Own_Process   : constant := 16#0000_0010#;
   Service_Win32_Share_Process : constant := 16#0000_0020#;

--%%   SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS;
--%%   {$EXTERNALSYM SERVICE_WIN32}

   Service_Interactive_Process : constant := 16#0000_0100#;

--%%   SERVICE_TYPE_ALL = SERVICE_WIN32 or SERVICE_ADAPTER or SERVICE_DRIVER or
--%%     SERVICE_INTERACTIVE_PROCESS;
--%%   {$EXTERNALSYM SERVICE_TYPE_ALL}

--
-- Start Type
--

   Service_Boot_Start   : constant := 16#0000_0000#;
   Service_System_Start : constant := 16#0000_0001#;
   Service_Auto_Start   : constant := 16#0000_0002#;
   Service_Demand_Start : constant := 16#0000_0003#;
   Service_Disabled     : constant := 16#0000_0004#;

--
-- Error control type
--

   Service_Error_Ignore   : constant := 16#0000_0000#;
   Service_Error_Normal   : constant := 16#0000_0001#;
   Service_Error_Severe   : constant := 16#0000_0002#;
   Service_Error_Critical : constant := 16#0000_0003#;

--
-- Define the registry driver node enumerations
--


-- SERVICE_NODE_TYPE

   DriverType               : constant := Service_Kernel_Driver;
   FileSystemType           : constant := Service_File_System_Driver;
   Win32ServiceOwnProcess   : constant := Service_Win32_Own_Process;
   Win32ServiceShareProcess : constant := Service_Win32_Share_Process;
   AdapterType              : constant := Service_Adapter;
   RecognizerType           : constant := Service_Recognizer_Driver;

-- SERVICE_LOAD_TYPE

   BootLoad    : constant := Service_Boot_Start;
   SystemLoad  : constant := Service_System_Start;
   AutoLoad    : constant := Service_Auto_Start;
   DemandLoad  : constant := Service_Demand_Start;
   DisableLoad : constant := Service_Disabled;

-- SERVICE_ERROR_TYPE

   IgnoreError   : constant := Service_Error_Ignore;
   NormalError   : constant := Service_Error_Normal;
   SevereError   : constant := Service_Error_Severe;
   CriticalError : constant := Service_Error_Critical;

--
-- IOCTL_TAPE_ERASE definitions
--

   subtype Service_Node_Type_Type is Unsigned_32;
   subtype Service_Node_Type_Ptr is Unsigned_32_Ptr;
   subtype Service_Node_Type_CPtr is Unsigned_32_CPtr;
--%%   TServiceNodeType = SERVICE_NODE_TYPE;
   subtype Service_Load_Type_Type is Unsigned_32;
   subtype Service_Load_Type_Ptr is Unsigned_32_Ptr;
   subtype Service_Load_Type_CPtr is Unsigned_32_CPtr;
--%%   TServiceLoadType = SERVICE_LOAD_TYPE;
   subtype Service_Error_Type_Type is Unsigned_32;
   subtype Service_Error_Type_Ptr is Unsigned_32_Ptr;
   subtype Service_Error_Type_CPtr is Unsigned_32_CPtr;
--%%   TServiceErrorType = SERVICE_ERROR_TYPE;

   Tape_Erase_Short : constant := 0;
   Tape_Erase_Long  : constant := 1;

   type Tape_Erase_Type;
   type Tape_Erase_Ptr is access all Tape_Erase_Type;
   type Tape_Erase_CPtr is access constant Tape_Erase_Type;
   type Tape_Erase_Type is record
      Type_ : Unsigned_32;
      Immediate : Byte_Bool;
   end record;

--
-- IOCTL_TAPE_PREPARE definitions
--

   Tape_Load    : constant := 0;
   Tape_Unload  : constant := 1;
   Tape_Tension : constant := 2;
   Tape_Lock    : constant := 3;
   Tape_Unlock  : constant := 4;
   Tape_Format  : constant := 5;

   type Tape_Prepare_Type;
   type Tape_Prepare_Ptr is access all Tape_Prepare_Type;
   type Tape_Prepare_CPtr is access constant Tape_Prepare_Type;
   type Tape_Prepare_Type is record
      Operation : Unsigned_32;
      Immediate : Byte_Bool;
   end record;

--
-- IOCTL_TAPE_WRITE_MARKS definitions
--

   Tape_Setmarks        : constant := 0;
   Tape_Filemarks       : constant := 1;
   Tape_Short_Filemarks : constant := 2;
   Tape_Long_Filemarks  : constant := 3;

   type Tape_Write_Marks_Type;
   type Tape_Write_Marks_Ptr is access all Tape_Write_Marks_Type;
   type Tape_Write_Marks_CPtr is access constant Tape_Write_Marks_Type;
   type Tape_Write_Marks_Type is record
      Type_ : Unsigned_32;
      Count : Unsigned_32;
      Immediate : Byte_Bool;
   end record;

--
-- IOCTL_TAPE_GET_POSITION definitions
--

   Tape_Absolute_Position       : constant := 0;
   Tape_Logical_Position        : constant := 1;
   Tape_Pseudo_Logical_Position : constant := 2;

   type Tape_Get_Position_Type;
   type Tape_Get_Position_Ptr is access all Tape_Get_Position_Type;
   type Tape_Get_Position_CPtr is access constant Tape_Get_Position_Type;
   type Tape_Get_Position_Type is record
      Type_ : Unsigned_32;
      Partition : Unsigned_32;
      Offset : LARGE_INTEGER;
   end record;

--
-- IOCTL_TAPE_SET_POSITION definitions
--

   Tape_Rewind                : constant := 0;
   Tape_Absolute_Block        : constant := 1;
   Tape_Logical_Block         : constant := 2;
   Tape_Pseudo_Logical_Block  : constant := 3;
   Tape_Space_End_Of_Data     : constant := 4;
   Tape_Space_Relative_Blocks : constant := 5;
   Tape_Space_Filemarks       : constant := 6;
   Tape_Space_Sequential_Fmks : constant := 7;
   Tape_Space_Setmarks        : constant := 8;
   Tape_Space_Sequential_Smks : constant := 9;

   type Tape_Set_Position_Type;
   type Tape_Set_Position_Ptr is access all Tape_Set_Position_Type;
   type Tape_Set_Position_CPtr is access constant Tape_Set_Position_Type;
   type Tape_Set_Position_Type is record
      Method : Unsigned_32;
      Partition : Unsigned_32;
      Offset : LARGE_INTEGER;
      Immediate : Byte_Bool;
   end record;

--
-- IOCTL_TAPE_GET_DRIVE_PARAMS definitions
--

--
-- Definitions for FeaturesLow parameter
--

   Tape_Drive_Fixed     : constant := 16#0000_0001#;
   Tape_Drive_Select    : constant := 16#0000_0002#;
   Tape_Drive_Initiator : constant := 16#0000_0004#;

   Tape_Drive_Erase_Short     : constant := 16#0000_0010#;
   Tape_Drive_Erase_Long      : constant := 16#0000_0020#;
   Tape_Drive_Erase_Bop_Only  : constant := 16#0000_0040#;
   Tape_Drive_Erase_Immediate : constant := 16#0000_0080#;

   Tape_Drive_Tape_Capacity  : constant := 16#0000_0100#;
   Tape_Drive_Tape_Remaining : constant := 16#0000_0200#;
   Tape_Drive_Fixed_Block    : constant := 16#0000_0400#;
   Tape_Drive_Variable_Block : constant := 16#0000_0800#;

   Tape_Drive_Write_Protect : constant := 16#0000_1000#;
   Tape_Drive_Eot_Wz_Size   : constant := 16#0000_2000#;

   Tape_Drive_Ecc         : constant := 16#0001_0000#;
   Tape_Drive_Compression : constant := 16#0002_0000#;
   Tape_Drive_Padding     : constant := 16#0004_0000#;
   Tape_Drive_Report_Smks : constant := 16#0008_0000#;

   Tape_Drive_Get_Absolute_Blk : constant := 16#0010_0000#;
   Tape_Drive_Get_Logical_Blk  : constant := 16#0020_0000#;
   Tape_Drive_Set_Eot_Wz_Size  : constant := 16#0040_0000#;

   Tape_Drive_Eject_Media      : constant := 16#0100_0000#;
   Tape_Drive_Clean_Requests   : constant := 16#0200_0000#;
   Tape_Drive_Set_Cmp_Bop_Only : constant := 16#0400_0000#;

   Tape_Drive_Reserved_Bit : constant := 16#8000_0000#; -- don't use this bit!
   --                                              //can't be a low features bit!
--                                              //reserved; high features only

--
-- Definitions for FeaturesHigh parameter
--

   Tape_Drive_Load_Unload      : constant := 16#8000_0001#;
   Tape_Drive_Tension          : constant := 16#8000_0002#;
   Tape_Drive_Lock_Unlock      : constant := 16#8000_0004#;
   Tape_Drive_Rewind_Immediate : constant := 16#8000_0008#;

   Tape_Drive_Set_Block_Size  : constant := 16#8000_0010#;
   Tape_Drive_Load_Unld_Immed : constant := 16#8000_0020#;
   Tape_Drive_Tension_Immed   : constant := 16#8000_0040#;
   Tape_Drive_Lock_Unlk_Immed : constant := 16#8000_0080#;

   Tape_Drive_Set_Ecc         : constant := 16#8000_0100#;
   Tape_Drive_Set_Compression : constant := 16#8000_0200#;
   Tape_Drive_Set_Padding     : constant := 16#8000_0400#;
   Tape_Drive_Set_Report_Smks : constant := 16#8000_0800#;

   Tape_Drive_Absolute_Blk  : constant := 16#8000_1000#;
   Tape_Drive_Abs_Blk_Immed : constant := 16#8000_2000#;
   Tape_Drive_Logical_Blk   : constant := 16#8000_4000#;
   Tape_Drive_Log_Blk_Immed : constant := 16#8000_8000#;

   Tape_Drive_End_Of_Data     : constant := 16#8001_0000#;
   Tape_Drive_Relative_Blks   : constant := 16#8002_0000#;
   Tape_Drive_Filemarks       : constant := 16#8004_0000#;
   Tape_Drive_Sequential_Fmks : constant := 16#8008_0000#;

   Tape_Drive_Setmarks         : constant := 16#8010_0000#;
   Tape_Drive_Sequential_Smks  : constant := 16#8020_0000#;
   Tape_Drive_Reverse_Position : constant := 16#8040_0000#;
   Tape_Drive_Space_Immediate  : constant := 16#8080_0000#;

   Tape_Drive_Write_Setmarks   : constant := 16#8100_0000#;
   Tape_Drive_Write_Filemarks  : constant := 16#8200_0000#;
   Tape_Drive_Write_Short_Fmks : constant := 16#8400_0000#;
   Tape_Drive_Write_Long_Fmks  : constant := 16#8800_0000#;

   Tape_Drive_Write_Mark_Immed : constant := 16#9000_0000#;
   Tape_Drive_Format           : constant := 16#A000_0000#;
   Tape_Drive_Format_Immediate : constant := 16#C000_0000#;
   Tape_Drive_High_Features    : constant := 16#8000_0000#; -- mask for high features flag

   type Tape_Get_Drive_Parameters_Type;
   type Tape_Get_Drive_Parameters_Ptr is access all Tape_Get_Drive_Parameters_Type;
   type Tape_Get_Drive_Parameters_CPtr is access constant Tape_Get_Drive_Parameters_Type;
   type Tape_Get_Drive_Parameters_Type is record
      ECC : Byte_Bool;
      Compression : Byte_Bool;
      Data_Padding : Byte_Bool;
      Report_Setmarks : Byte_Bool;
      Default_Block_Size : Unsigned_32;
      Maximum_Block_Size : Unsigned_32;
      Minimum_Block_Size : Unsigned_32;
      Maximum_Partition_Count : Unsigned_32;
      Features_Low : Unsigned_32;
      Features_High : Unsigned_32;
      EOT_Warning_Zone_Size : Unsigned_32;
   end record;

--
-- IOCTL_TAPE_SET_DRIVE_PARAMETERS definitions
--

   type Tape_Set_Drive_Parameters_Type;
   type Tape_Set_Drive_Parameters_Ptr is access all Tape_Set_Drive_Parameters_Type;
   type Tape_Set_Drive_Parameters_CPtr is access constant Tape_Set_Drive_Parameters_Type;
   type Tape_Set_Drive_Parameters_Type is record
      ECC : Byte_Bool;
      Compression : Byte_Bool;
      Data_Padding : Byte_Bool;
      Report_Setmarks : Byte_Bool;
      EOT_Warning_Zone_Size : Unsigned_32;
   end record;

--
-- IOCTL_TAPE_GET_MEDIA_PARAMETERS definitions
--

   type Tape_Get_Media_Parameters_Type;
   type Tape_Get_Media_Parameters_Ptr is access all Tape_Get_Media_Parameters_Type;
   type Tape_Get_Media_Parameters_CPtr is access constant Tape_Get_Media_Parameters_Type;
   type Tape_Get_Media_Parameters_Type is record
      Capacity : LARGE_INTEGER;
      Remaining : LARGE_INTEGER;
      Block_Size : Unsigned_32;
      Partition_Count : Unsigned_32;
      Write_Protected : Byte_Bool;
   end record;

--
-- IOCTL_TAPE_SET_MEDIA_PARAMETERS definitions
--

   type Tape_Set_Media_Parameters_Type;
   type Tape_Set_Media_Parameters_Ptr is access all Tape_Set_Media_Parameters_Type;
   type Tape_Set_Media_Parameters_CPtr is access constant Tape_Set_Media_Parameters_Type;
   type Tape_Set_Media_Parameters_Type is record
      Block_Size : Unsigned_32;
   end record;

--
-- IOCTL_TAPE_CREATE_PARTITION definitions
--

   Tape_Fixed_Partitions     : constant := 0;
   Tape_Select_Partitions    : constant := 1;
   Tape_Initiator_Partitions : constant := 2;

   type Tape_Create_Partition_Type;
   type Tape_Create_Partition_Ptr is access all Tape_Create_Partition_Type;
   type Tape_Create_Partition_CPtr is access constant Tape_Create_Partition_Type;
   type Tape_Create_Partition_Type is record
      Method : Unsigned_32;
      Count : Unsigned_32;
      Size : Unsigned_32;
   end record;

--
-- WMI Methods
--

   Tape_Query_Drive_Parameters     : constant := 0;
   Tape_Query_Media_Capacity       : constant := 1;
   Tape_Check_For_Drive_Problem    : constant := 2;
   Tape_Query_IO_Error_Data        : constant := 3;
   Tape_Query_Device_Error_Data    : constant := 4;

   type Tape_WMI_Operations_Type;
   type Tape_WMI_Operations_Ptr is access all Tape_WMI_Operations_Type;
   type Tape_WMI_Operations_CPtr is access constant Tape_WMI_Operations_Type;
   type Tape_WMI_Operations_Type is record
      Method : Unsigned_32;
      Data_Buffer_Size : Unsigned_32;
      Data_Buffer : System.Address;
   end record;

--
-- Type of drive errors
--

--%%   _TAPE_DRIVE_PROBLEM_TYPE = (
--%%     TapeDriveProblemNone, TapeDriveReadWriteWarning,
--%%     TapeDriveReadWriteError, TapeDriveReadWarning,
--%%     TapeDriveWriteWarning, TapeDriveReadError,
--%%     TapeDriveWriteError, TapeDriveHardwareError,
--%%     TapeDriveUnsupportedMedia, TapeDriveScsiConnectionError,
--%%     TapeDriveTimetoClean, TapeDriveCleanDriveNow,
--%%     TapeDriveMediaLifeExpired, TapeDriveSnappedTape);
--%%   {$EXTERNALSYM _TAPE_DRIVE_PROBLEM_TYPE}
--%%   TAPE_DRIVE_PROBLEM_TYPE = _TAPE_DRIVE_PROBLEM_TYPE;
--%%   TTapeDriveProblemType = TAPE_DRIVE_PROBLEM_TYPE;

   Activation_Context_Section_Assembly_Information         : constant := 1;
   Activation_Context_Section_DLL_Redirection              : constant := 2;
   Activation_Context_Section_Window_Class_Redirection     : constant := 3;
   Activation_Context_Section_COM_Server_Redirection       : constant := 4;
   Activation_Context_Section_COM_Interface_Redirection    : constant := 5;
   Activation_Context_Section_COM_Type_Library_Redirection : constant := 6;
   Activation_Context_Section_COM_Progid_Redirection       : constant := 7;
   Activation_Context_Section_Global_Object_Rename_Table   : constant := 8;
   Activation_Context_Section_Clr_Surrogates               : constant := 9;

--%% {$ENDIF JWA_IMPLEMENTATIONSECTION}

--%% {$IFNDEF JWA_OMIT_SECTIONS}
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--%% implementation
--%% //uses...
--%% {$ENDIF JWA_OMIT_SECTIONS}
--%%
--%% {$IFNDEF JWA_INTERFACESECTION}
--%%
--%%
--%% {$IFNDEF JWA_OMIT_SECTIONS}
--%% const
--%%   ntdll = 'ntdll.dll';
--%%   kernel32 = 'kernel32.dll';
--%% {$ENDIF JWA_OMIT_SECTIONS}
--%%
--%%
--%% function WT_SET_MAX_THREADPOOL_THREADS(var Flags: DWORD; Limit: DWORD): DWORD;
--%% begin
--%%   Flags := Flags or (Limit shl 16);
--%%   Result := Flags;
--%% end;
--%%
--%%
--%% function VALID_IMPERSONATION_LEVEL(L: TSecurityImpersonationLevel): BOOL;
--%% begin
--%%   Result := (L >= SECURITY_MIN_IMPERSONATION_LEVEL) and (L <= SECURITY_MAX_IMPERSONATION_LEVEL);
--%% end;
--%%
--%% {
--%% function VALID_TOKEN_AUDIT_POLICY_ELEMENT(P: TOKEN_AUDIT_POLICY_ELEMENT): BOOL;
--%% begin
--%%   Result := ((P.PolicyMask and (not VALID_AUDIT_POLICY_BITS) = 0) and (P.Category <= AuditEventMaxType);
--%% // ((((P).PolicyMask & ~VALID_AUDIT_POLICY_BITS) == 0) && \
--%% //                                             ((P).Category <= AuditEventMaxType))
--%% end;
--%% }
--%%
--%% function PER_USER_AUDITING_POLICY_SIZE(p: PTOKEN_AUDIT_POLICY): DWORD;
--%% begin
--%%   Result := SizeOf(TOKEN_AUDIT_POLICY);
--%%   if p^.PolicyCount > ANYSIZE_ARRAY then
--%%     Result := Result + SizeOf(TOKEN_AUDIT_POLICY_ELEMENT) * (P^.PolicyCount - ANYSIZE_ARRAY);
--%% //  ( sizeof(TOKEN_AUDIT_POLICY) + (((p)->PolicyCount > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((p)->PolicyCount - ANYSIZE_ARRAY)) : 0) )
--%% end;
--%%
--%% function PER_USER_AUDITING_POLICY_SIZE_BY_COUNT(C: DWORD): DWORD;
--%% begin
--%%   Result := SizeOf(TOKEN_AUDIT_POLICY);
--%%   if C > ANYSIZE_ARRAY then
--%%     Result := Result + SizeOf(TOKEN_AUDIT_POLICY_ELEMENT) * (C - ANYSIZE_ARRAY);
--%% //    ( sizeof(TOKEN_AUDIT_POLICY) + (((C) > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((C) - ANYSIZE_ARRAY)) : 0) )
--%% end;
--%%
--%%
--%% {$IFNDEF JWA_INCLUDEMODE}
--%%
--%% function NtCurrentTeb: PNT_TIB;
--%% asm
--%% {$ifdef cpu386}
--%%         MOV     EAX, FS:[024]   // was zero        
--%% {$endif cpu386}
--%% {$ifdef cpux86_64}
--%%         movq     RAX, GS:[48]
--%% {$endif cpux86_64}
--%% end;
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% function GetFiberData: PVOID;
--%% asm
--%% {$ifdef cpu386}
--%%         MOV     EAX, FS:[$1016]
--%%         MOV     EAX, [EAX]
--%% {$endif cpu386}
--%% {$ifdef cpux86_64}
--%%         MOV     RAX, GS:[32]
--%%         MOV     RAX, [RAX]
--%% {$endif cpux86_64}
--%% end;
--%%
--%% function GetCurrentFiber: PVOID;
--%% asm
--%% {$ifdef cpu386}
--%%         MOV     EAX, FS:[$1016]
--%% {$endif cpu386}
--%% {$ifdef cpux86_64}
--%%         MOV     RAX, GS:[32]
--%% {$endif cpux86_64}
--%% end;
--%%
--%% {$IFNDEF JWA_INCLUDEMODE}
--%%
--%% function Int32x32To64(a, b: LONG): LONGLONG;
--%% begin
--%%   Result := Int64(a) * Int64(b);
--%% end;
--%%
--%% function UInt32x32To64(a, b: DWORD): ULONGLONG;
--%% begin
--%%   Result := ULONGLONG(a) * ULONGLONG(b);
--%% end;
--%%
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% function MAKELANGID(PrimaryLang, SubLang: USHORT): WORD;
--%% begin
--%%   Result := (SubLang shl 10) or PrimaryLang;
--%% end;
--%%
--%% function PRIMARYLANGID(LangId: WORD): WORD;
--%% begin
--%%   Result := LangId and $3FF;
--%% end;
--%%
--%% function SUBLANGID(LangId: WORD): WORD;
--%% begin
--%%   Result := LangId shr 10;
--%% end;
--%%
--%% function MAKELCID(LangId, SortId: WORD): DWORD;
--%% begin
--%%   Result := (DWORD(SortId) shl 16) or DWORD(LangId);
--%% end;
--%%
--%% function MAKESORTLCID(LangId, SortId, SortVersion: WORD): DWORD;
--%% begin
--%%   Result := MAKELCID(LangId, SortId) or (SortVersion shl 20);
--%% end;
--%%
--%% function LANGIDFROMLCID(LocaleId: LCID): WORD;
--%% begin
--%%   Result := WORD(LocaleId);
--%% end;
--%%
--%% function SORTIDFROMLCID(LocaleId: LCID): WORD;
--%% begin
--%%   Result := WORD((DWORD(LocaleId) shr 16) and $F);
--%% end;
--%%
--%% function SORTVERSIONFROMLCID(LocaleId: LCID): WORD;
--%% begin
--%%   Result := WORD((DWORD(LocaleId) shr 20) and $F);
--%% end;
--%%
--%% function LANG_SYSTEM_DEFAULT: WORD;
--%% begin
--%%   Result := MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT);
--%% end;
--%%
--%% function LANG_USER_DEFAULT: WORD;
--%% begin
--%%   Result := MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
--%% end;
--%%
--%% function LOCALE_SYSTEM_DEFAULT: DWORD;
--%% begin
--%%   Result := MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT);
--%% end;
--%%
--%% function LOCALE_USER_DEFAULT: DWORD;
--%% begin
--%%   Result := MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT);
--%% end;
--%%
--%% function LOCALE_NEUTRAL: DWORD;
--%% begin
--%%   Result := MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT);
--%% end;
--%%
--%% function LOCALE_INVARIANT: DWORD;
--%% begin
--%%   Result := MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT);
--%% end;
--%%
--%% function IsReparseTagMicrosoft(Tag: ULONG): Boolean;
--%% begin
--%%   Result := (Tag and ULONG($80000000)) <> 0;
--%% end;
--%%
--%% function IsReparseTagHighLatency(Tag: ULONG): Boolean;
--%% begin
--%%   Result := (Tag and ULONG($40000000)) <> 0;
--%% end;
--%%
--%% function IsReparseTagNameSurrogate(Tag: ULONG): Boolean;
--%% begin
--%%   Result := (Tag and ULONG($20000000)) <> 0;
--%% end;
--%%
--%% // IMAGE_FIRST_SECTION by Nico Bendlin - supplied by Markus Fuchs
--%%
--%% function FieldOffset(const Struc; const Field): Cardinal;
--%% begin
--%%   Result := Cardinal(@Field) - Cardinal(@Struc);
--%% end;
--%%
--%% function IMAGE_FIRST_SECTION(NtHeader: PImageNtHeaders): PImageSectionHeader;
--%% begin
--%%   Result := PImageSectionHeader(Cardinal(NtHeader) +
--%%       FieldOffset(NtHeader^, NtHeader^.OptionalHeader) +
--%%       NtHeader^.FileHeader.SizeOfOptionalHeader);
--%% end;
--%%
--%% function BTYPE(x: DWORD): DWORD;
--%% begin
--%%   Result := x and N_BTMASK;
--%% end;
--%%
--%% function ISPTR(x: DWORD): Boolean;
--%% begin
--%%   Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_POINTER shl N_BTSHFT);
--%% end;
--%%
--%% function ISFCN(x: DWORD): Boolean;
--%% begin
--%%   Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_FUNCTION shl N_BTSHFT);
--%% end;
--%%
--%% function ISARY(x: DWORD): Boolean;
--%% begin
--%%   Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_ARRAY shl N_BTSHFT);
--%% end;
--%%
--%% function ISTAG(x: DWORD): Boolean;
--%% begin
--%%   Result := (x = IMAGE_SYM_CLASS_STRUCT_TAG) or (x = IMAGE_SYM_CLASS_UNION_TAG) or
--%%     (x = IMAGE_SYM_CLASS_ENUM_TAG);
--%% end;
--%%
--%% function IMAGE_ORDINAL64(Ordinal: ULONGLONG): ULONGLONG;
--%% begin
--%%   Result := (Ordinal and $ffff);
--%% end;
--%%
--%% function IMAGE_ORDINAL32(Ordinal: DWORD): DWORD;
--%% begin
--%%   Result := (Ordinal and $ffff);
--%% end;
--%%
--%% function IMAGE_ORDINAL(Ordinal: DWORD): DWORD;
--%% begin
--%%   Result := (Ordinal and $ffff);
--%% end;
--%%
--%% function IMAGE_SNAP_BY_ORDINAL64(Ordinal: ULONGLONG): Boolean;
--%% begin
--%%   Result := ((Ordinal and IMAGE_ORDINAL_FLAG64) <> 0);
--%% end;
--%%
--%% function IMAGE_SNAP_BY_ORDINAL32(Ordinal: DWORD): Boolean;
--%% begin
--%%   Result := ((Ordinal and IMAGE_ORDINAL_FLAG32) <> 0);
--%% end;
--%%
--%% function IMAGE_SNAP_BY_ORDINAL(Ordinal: DWORD): Boolean;
--%% begin
--%%   Result := ((Ordinal and IMAGE_ORDINAL_FLAG32) <> 0);
--%% end;
--%%
--%% function HEAP_MAKE_TAG_FLAGS(b, o: DWORD): DWORD;
--%% begin
--%%   Result := b + (o shl 18);
--%% end;
--%%
--%% procedure VER_SET_CONDITION(var Mask: DWORDLONG; TypeBitmask, ConditionMask: ULONG);
--%% begin
--%%   Mask := VerSetConditionMask(Mask, TypeBitmask, ConditionMask);
--%% end;
--%%
--%% {$IFDEF DYNAMIC_LINK}
--%%
--%% var
--%%   _RtlCaptureContext: Pointer;
--%%
--%% procedure RtlCaptureContext;
--%% begin
--%%   GetProcedureAddress(_RtlCaptureContext, ntdll, 'RtlCaptureContext');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlCaptureContext]
--%%   end;
--%% end;
--%%
--%% var
--%%   _RtlCompareMemory: Pointer;
--%%
--%% function RtlCompareMemory;
--%% begin
--%%   GetProcedureAddress(_RtlCompareMemory, ntdll, 'RtlCompareMemory');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlCompareMemory]
--%%   end;
--%% end;
--%%
--%% var
--%%   _VerSetConditionMask: Pointer;
--%%
--%% function VerSetConditionMask;
--%% begin
--%%   GetProcedureAddress(_VerSetConditionMask, kernel32, 'VerSetConditionMask');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_VerSetConditionMask]
--%%   end;
--%% end;
--%%
--%%
--%% var
--%%   _RtlInitializeSListHead: Pointer;
--%%
--%% procedure RtlInitializeSListHead;
--%% begin
--%%   GetProcedureAddress(_RtlInitializeSListHead, 'ntdll.dll', 'RtlInitializeSListHead');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlInitializeSListHead]
--%%   end;
--%% end;
--%%
--%%
--%% var
--%%   _RtlFirstEntrySList: Pointer;
--%%
--%% function RtlFirstEntrySList;
--%% begin
--%%   GetProcedureAddress(_RtlFirstEntrySList, 'ntdll.dll', 'RtlFirstEntrySList');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlFirstEntrySList]
--%%   end;
--%% end;
--%%
--%% var
--%%   _RtlInterlockedPopEntrySList: Pointer;
--%%
--%% function RtlInterlockedPopEntrySList;
--%% begin
--%%   GetProcedureAddress(_RtlInterlockedPopEntrySList, 'ntdll.dll', 'RtlInterlockedPopEntrySList');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlInterlockedPopEntrySList]
--%%   end;
--%% end;
--%%
--%% {$IFNDEF JWA_INCLUDEMODE}
--%% var
--%%   _RtlInterlockedPushEntrySList: Pointer;
--%%
--%% function RtlInterlockedPushEntrySList;
--%% begin
--%%   GetProcedureAddress(_RtlInterlockedPushEntrySList, 'ntdll.dll', 'RtlInterlockedPushEntrySList');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlInterlockedPushEntrySList]
--%%   end;
--%% end;
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% var
--%%   _RtlInterlockedFlushSList: Pointer;
--%%
--%% function RtlInterlockedFlushSList;
--%% begin
--%%   GetProcedureAddress(_RtlInterlockedFlushSList, 'ntdll.dll', 'RtlInterlockedFlushSList');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlInterlockedFlushSList]
--%%   end;
--%% end;
--%%
--%% {$IFNDEF JWA_INCLUDEMODE}
--%% var
--%%   _RtlQueryDepthSList: Pointer;
--%%
--%% function RtlQueryDepthSList;
--%% begin
--%%   GetProcedureAddress(_RtlQueryDepthSList, 'ntdll.dll', 'RtlQueryDepthSList');
--%%   asm
--%%         MOV     ESP, EBP
--%%         POP     EBP
--%%         JMP     [_RtlQueryDepthSList]
--%%   end;
--%% end;
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% {$ELSE}
--%%
--%% procedure RtlCaptureContext; external ntdll name 'RtlCaptureContext';
--%% function RtlCompareMemory; external ntdll name 'RtlCompareMemory';
--%% function VerSetConditionMask; external kernel32 name 'VerSetConditionMask';
--%%
--%% procedure RtlInitializeSListHead; external 'ntdll.dll' name 'RtlInitializeSListHead';
--%%
--%% function RtlFirstEntrySList; external 'ntdll.dll' name 'RtlFirstEntrySList';
--%% function RtlInterlockedPopEntrySList; external 'ntdll.dll' name 'RtlInterlockedPopEntrySList';
--%% {$IFNDEF JWA_INCLUDEMODE}
--%% function RtlInterlockedPushEntrySList; external 'ntdll.dll' name 'RtlInterlockedPushEntrySList';
--%% {$ENDIF JWA_INCLUDEMODE}
--%%
--%% function RtlInterlockedFlushSList; external 'ntdll.dll' name 'RtlInterlockedFlushSList';
--%% function RtlQueryDepthSList; external 'ntdll.dll' name 'RtlQueryDepthSList';
--%%
--%% {$ENDIF DYNAMIC_LINK}
--%%
--%% {$ENDIF JWA_INTERFACESECTION}
--%%
--%% {$IFNDEF JWA_OMIT_SECTIONS}
--%% end.
--%% {$ENDIF JWA_OMIT_SECTIONS}
