Ignore:
Timestamp:
Jul 17, 2000, 12:43:41 AM (25 years ago)
Author:
bird
Message:

Checkin of current code in the Grace brance for backup purpose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GRACE/src/win32k/include/ldr.h

    r2501 r3834  
    1 /* $Id: ldr.h,v 1.5 2000-01-22 18:20:59 bird Exp $
    2  *
    3  * ldr - loader header file.
    4  *
    5  * Copyright (c)  1999 knut  St.  osmundsen
     1/* $Id: ldr.h,v 1.5.4.1 2000-07-16 22:43:29 bird Exp $
     2 *
     3 * ldr - Our loader "subsystem" public header file.
     4 *
     5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    66 *
    77 * Project Odin Software License can be found in LICENSE.TXT
     
    1212#ifndef _ldr_h_
    1313#define _ldr_h_
    14     #ifndef LDR_INCL_INITONLY
    15         /* state variable */
    16         extern BOOL fQAppType;
    17 
    18         /*
    19          * handle state - Array of handle states. Eight state per byte!
    20          */
    21         #define MAX_FILE_HANDLES 0x10000
    22 
    23         extern unsigned char achHandleStates[MAX_FILE_HANDLES/8];
    24 
    25         #define HSTATE_UNUSED       0x00    /* Handle not used (or OS/2). */
    26         #define HSTATE_OS2          0x00    /* OS/2 module filehandle. */
    27         #define HSTATE_OUR          0x01    /* Our module filehandle. */
    28         #define HSTATE_MASK         0xFE
    29         #define HSTATE_UMASK        0x01
    30 
    31         #define GetState(a)         (HSTATE_UMASK & (achHandleStates[(a)/8] >> ((a)%8)))
    32         #define SetState(a,b)       (achHandleStates[(a)/8] = (achHandleStates[(a)/8] & (HSTATE_MASK << ((a)%8) | HSTATE_MASK >> 8-((a)%8)) | ((b) & 0x1) << ((a)%8)))
    33 
    34 
    35         /*
    36          * Module struct.
    37          */
    38         typedef struct _Module
    39         {
    40             AVLNODECORE     coreKey;    /* Key is hFile. */
    41             AVLNODECORE     coreMTE;    /* Key is pMTE. */
    42 
    43             SFN             hFile;      /* System file number or file handle if you prefer that. */
    44             PMTE            pMTE;       /* Pointer to MTE if we got one - NULL is allowed. */
    45 
    46             ULONG           fFlags;     /* Flags. Flags if coreMte is in use and what Data contains. */
    47             union
    48             {
    49                 ModuleBase *pModule;    /* Pointer to a Pe2Lx object. (Win32 executables) */
    50                 #if defined(_PE2LX_H_)
    51                 Pe2Lx *     pPe2Lx;     /* Pointer to a Pe2Lx object. (Win32 executables) */
    52                 #endif
    53                 #if defined(_ELF2LX_H_)
    54                 Elf2Lx *    pElf2Lx;    /* Pointer to a Elf2Lx object. (ELF executables) */
    55                 #endif
    56                 #if defined(_SCRIPT_H_)
    57                 Script *    pScript;    /* Pointer to a Script object. (Shell scripts) */
    58                 #endif
    59                 #if defined(_PE_H_)
    60                 Pe *        pPe;        /* Pointer to a Pe object. (Ring3 loader) */
    61                 #endif
    62             } Data;                     /* Pointer to data. Currently it's allways a Pe2Lx object! */
    63         } MODULE, *PMODULE;
    64 
    65         #define MOD_FLAGS_IN_MTETREE    0x00000010UL /* The node is present in the MTE-tree. */
    66         #define MOD_TYPE_MASK           0x0000000FUL /* Type mask. */
    67         #define MOD_TYPE_PE2LX          0x00000001UL /* Pe2Lx module. */
    68         #define MOD_TYPE_ELF2LX         0x00000002UL /* Elf2Lx module. */
    69         #define MOD_TYPE_SCRIPT         0x00000003UL /* Script module. */
    70         #define MOD_TYPE_PE             0x00000004UL /* Pe module. */
    71 
    72 
    73         /*
    74          * Modules operations.
    75          */
    76         PMODULE     getModuleBySFN(SFN hFile);
    77         PMODULE     getModuleByMTE(PMTE pMTE);
    78         PMODULE     getModuleByFilename(PCSZ pszFilename);
    79 
    80         ULONG       addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj);
    81         ULONG       removeModule(SFN hFile);
    82 
    83     #endif
    84 
    85     /*************/
    86     /* functions */
    87     /*************/
    88     #ifdef __cplusplus
    89     extern "C" {
    90     #endif
    91 
    92     ULONG ldrInit(void);
    93 
    94     #ifdef __cplusplus
     14
     15#ifdef __cplusplus
     16extern "C" {
     17#endif
     18
     19
     20#ifndef LDR_INCL_INITONLY
     21
     22/*
     23 * Fail if dependent header files is missing
     24 */
     25#ifndef _AVL_H_
     26#error "You'll have to include avl.h before ldr.h!"
     27#endif
     28
     29
     30/** @design
     31 * Loader State.
     32 *
     33 * Used to determin behaviour in different cases.
     34 * Use the isLdrState<State> macros to query current state.
     35 * IMPORTANT! Don't change this variable if you don't really mean it!
     36 *            And only change it thru the setLdrState* macros!
     37 *
     38 * The state is changing as follows:
     39 *    1) Load a new program
     40 *      mytkExecPgm will set the state to LDRSTATE_TKEXECPGM on successful overloading.
     41 *          myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
     42 *          (NB! myldrOpenPath is called several times. First for the EXE then for imported modules.)
     43 *              IF executable THEN myLdrOpen might set the LDRSTATE_OUR flag.
     44 *          myldrOpenPath will reset the type part of the loaderbits upon return.
     45 *      mytkExecPgm resets the state to LDRSTATE_UNKNOWN upon return.
     46 *
     47 *    2) Query program type.
     48 *      myLDRQAppType will set the state to LDRSTATE_LDRQAPPTYPE on entry.
     49 *          myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
     50 *          (NB! myldrOpenPath may be called several times.)
     51 *              IF executable THEN myLdrOpen might set the LDRSTATE_OUR flag.
     52 *          myldrOpenPath will reset the type part of the loaderbits upon return.
     53 *      myLDRQAppType resets the state to LDRSTATE_UNKNOWN upon return.
     54 *
     55 *    3) Unknown invocation - probably DosLoadModule. Base state is LDRSTATE_UNKNOWN.
     56 *          myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
     57 *          (NB! myldrOpenPath is probably called several times. Import modules.)
     58 *          myldrOpenPath will reset the type part of the loaderbits upon return.
     59 *
     60 */
     61extern ULONG    ulLdrState;
     62
     63#define LDRSTATE_UNKNOWN        0       /* Default state - undertermined. */
     64#define LDRSTATE_TKEXECPGM      1       /* A program is being loaded. */
     65#define LDRSTATE_LDRQAPPTYPE    2       /* Loader called from LDRQAPPTYPE */
     66/*#define LDRSTATE_LOADMODULE     3 */  /* A module is being loaded by DosLoadModule. Not implemented! */
     67#define LDRSTATE_MASK           0x00FF  /* State mask. */
     68
     69/*
     70 * The following flags are only valid when myldrOpenPath is on the stack!, ie. in ldrOpen.
     71 * These flags is the "loading-bits".
     72 */
     73#define LDRSTATE_EXE            0x0100  /* Flags telling that an executable is being opened. */
     74#define LDRSTATE_DLL            0x0200  /* Flags telling that an dll is being opened. */
     75#define LDRSTATE_UNSUPPORTED    0x0300  /* Flags telling to not override this open call. */
     76#define LDRSTATE_TYPE_MASK      0x0f00  /* Load Type Mask. */
     77/* The following flag will tell us if the executable which is loading is ours or not. */
     78#define LDRSTATE_OUREXE         0x1000
     79#define LDRSTATE_LOADERBITS     0xff00  /* Mask */
     80
     81
     82/*
     83 * Query macros.
     84 */
     85#define isLdrStateUnknown()             ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_UNKNOWN)
     86#define isLdrStateExecPgm()             ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_TKEXECPGM)
     87#define isLdrStateQAppType()            ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_LDRQAPPTYPE)
     88/*#define isLdrStateLoadModule()        ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_LOADMODULE)*/
     89
     90#define isLdrStateLoadingEXE()          ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_EXE)
     91#define isLdrStateLoadingDLL()          ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_DLL)
     92#define isLdrStateLoadingUnsupported()  ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_UNSUPPORTED)
     93
     94#define isLdrStateLoadingOurEXE()       (ulLdrState & LDRSTATE_OUREXE)
     95
     96
     97/*
     98 * Set macros.
     99 */
     100#define setLdrStateQAppType()           ulLdrState = LDRSTATE_LDRQAPPTYPE
     101#define setLdrStateUnknown()            ulLdrState = LDRSTATE_UNKNOWN
     102/*      setLdrStateExecPgm() isn't needed as this is in assembly source! */
     103/*#define setLdrStateLoadModule()         ulLdrState = LDRSTATE_LOADMODULE */
     104
     105#define setLdrStateLoadingEXE()         ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_EXE
     106#define setLdrStateLoadingDLL()         ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_DLL
     107#define setLdrStateLoadingUnsupported() ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_UNSUPPORTED
     108#define setLdrStateClearLoadingType()   ulLdrState &= (ULONG)(~LDRSTATE_TYPE_MASK)
     109
     110#define setLdrStateLoadingOurEXE()      ulLdrState |= LDRSTATE_OUREXE
     111
     112
     113/*
     114 * Loader State assert macros.
     115 */
     116#define ASSERT_LdrStateUnknown(fn)      ASSERT_LdrState(fn, LDRSTATE_UNKNOWN)
     117#define ASSERT_LdrStateExecPgm(fn)      ASSERT_LdrState(fn, LDRSTATE_TKEXECPGM)
     118#define ASSERT_LdrStateQAppType(fn)     ASSERT_LdrState(fn, LDRSTATE_LDRQAPPTYPE)
     119
     120#define ASSERT_LdrState(fn, state) \
     121    {                              \
     122        if ((ulLdrState & LDRSTATE_MASK) != (state)) \
     123        {                          \
     124            kprintf((fn ": assertion incorrect loader state. ulLdrState (%d) != " #state "(%d)", \
     125                     ulLdrState, state)); \
     126        }                          \
    95127    }
    96     #endif
    97 
    98     #pragma pack()
    99 
    100 #endif
     128
     129
     130/*
     131 * handle state - Array of handle states. Eight state per byte!
     132 */
     133#define MAX_FILE_HANDLES 0x10000
     134
     135extern unsigned char achHandleStates[MAX_FILE_HANDLES/8];
     136
     137#define HSTATE_UNUSED       0x00    /* Handle not used (or OS/2). */
     138#define HSTATE_OS2          0x00    /* OS/2 module filehandle. */
     139#define HSTATE_OUR          0x01    /* Our module filehandle. */
     140#define HSTATE_MASK         0xFE
     141#define HSTATE_UMASK        0x01
     142
     143#define GetState(a)         (HSTATE_UMASK & (achHandleStates[(a)/8] >> ((a)%8)))
     144#define SetState(a,b)       (achHandleStates[(a)/8] = (achHandleStates[(a)/8] & (HSTATE_MASK << ((a)%8) | HSTATE_MASK >> 8-((a)%8)) | ((b) & 0x1) << ((a)%8)))
     145
     146
     147/*
     148 * Declare the module classes used below in case they aren't declared yet.
     149 */
     150class ModuleBase;
     151class Pe2Lx;
     152class Elf2Lx;
     153
     154
     155/*
     156 * Module struct.
     157 */
     158typedef struct _Module
     159{
     160    AVLNODECORE     coreKey;    /* Key is hFile. */
     161    AVLNODECORE     coreMTE;    /* Key is pMTE. */
     162
     163    SFN             hFile;      /* System file number or file handle if you prefer that. */
     164    PMTE            pMTE;       /* Pointer to MTE if we got one - NULL is allowed. */
     165
     166    ULONG           fFlags;     /* Flags. Flags if coreMte is in use and what Data contains. */
     167    union
     168    {
     169        ModuleBase *pModule;    /* Pointer to base module. */
     170        Pe2Lx *     pPe2Lx;     /* Pointer to a Pe2Lx object. (Win32 executables) */
     171        Elf2Lx *    pElf2Lx;    /* Pointer to a Elf2Lx object. (ELF executables) */
     172        #if 0
     173        Script *    pScript;    /* Pointer to a Script object. (Shell scripts) */
     174        Pe *        pPe;        /* Pointer to a Pe object. (Ring3 loader) */
     175        #endif
     176    } Data;                     /* Pointer to data. Currently it's allways a Pe2Lx object! */
     177} MODULE, *PMODULE;
     178
     179#define MOD_FLAGS_IN_MTETREE    0x00000010UL /* The node is present in the MTE-tree. */
     180#define MOD_TYPE_MASK           0x0000000FUL /* Type mask. */
     181#define MOD_TYPE_PE2LX          0x00000001UL /* Pe2Lx module. */
     182#define MOD_TYPE_ELF2LX         0x00000002UL /* Elf2Lx module. */
     183#define MOD_TYPE_SCRIPT         0x00000003UL /* Script module. */
     184#define MOD_TYPE_PE             0x00000004UL /* Pe module. */
     185
     186
     187/*
     188 * Pointer to the currently loading executable module.
     189 * Available at tkExecPgm time when loading a converted module.
     190 */
     191extern PMODULE pExeModule;
     192
     193
     194/*
     195 * Modules operations.
     196 */
     197PMODULE     getModuleBySFN(SFN hFile);
     198PMODULE     getModuleByMTE(PMTE pMTE);
     199PMODULE     getModuleByhMTE(HMTE hMTE);
     200PMODULE     getModuleByFilename(PCSZ pszFilename);
     201
     202ULONG       addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj);
     203ULONG       removeModule(SFN hFile);
     204
     205
     206
     207/*
     208 * mytkExecPgm variables and functions
     209 *
     210 * (See ldr\mytkExecPgm.asm for further info on these variabels and functions.)
     211 */
     212#define CCHFILENAME     261             /* This is defined in mytkExecPgm.asm too. */
     213#define CCHARGUMENTS   1536             /* This is defined in mytkExecPgm.asm too. */
     214extern const char   fTkExecPgm;
     215extern char         achTkExecPgmFilename[CCHFILENAME];
     216extern char         achTkExecPgmArguments[CCHARGUMENTS];
     217#endif
     218ULONG _Optlink  tkExecPgmEnvLength(void);
     219ULONG _Optlink  tkExecPgmCopyEnv(char *pachBuffer, unsigned cchBuffer);
     220
     221
     222
     223/*
     224 * functions
     225 */
     226ULONG ldrInit(void);
     227
     228#ifdef __cplusplus
     229}
     230#endif
     231
     232#pragma pack()
     233
     234#endif
Note: See TracChangeset for help on using the changeset viewer.