Ignore:
Timestamp:
Sep 2, 2000, 11:08:23 PM (25 years ago)
Author:
bird
Message:

Merged in the Grace branch. New Win32k!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/ldr/ldr.cpp

    r2501 r4164  
    1 /* $Id: ldr.cpp,v 1.7 2000-01-22 18:21:01 bird Exp $
     1/* $Id: ldr.cpp,v 1.8 2000-09-02 21:08:06 bird Exp $
    22 *
    33 * ldr.cpp - Loader helpers.
     
    1414#define INCL_DOSERRORS
    1515#define INCL_NOPMAPI
    16 
     16#define INCL_OS2KRNL_SEM
     17#define INCL_OS2KRNL_PTDA
    1718
    1819/*******************************************************************************
     
    2122#include <os2.h>
    2223
     24#include "devSegDf.h"
    2325#include "malloc.h"
    2426#include "new.h"
     
    2628#include <stdlib.h>
    2729#include <stddef.h>
     30#include <string.h>
    2831
    2932#include "log.h"
     33#include "avl.h"
    3034#include <peexe.h>
    3135#include <exe386.h>
    3236#include "OS2Krnl.h"
     37#include "ldr.h"
     38#include "ldrCalls.h"
    3339#include "ModuleBase.h"
    3440#include "pe2lx.h"
    35 #include "avl.h"
    36 #include "ldr.h"
    3741#include "options.h"
    3842
     
    4145*   Global Variables                                                           *
    4246*******************************************************************************/
    43 PAVLNODECORE    pSFNRoot = NULL;
    44 PAVLNODECORE    pMTERoot = NULL;
    45 
     47static PAVLNODECORE    pSFNRoot = NULL;
     48static PAVLNODECORE    pMTERoot = NULL;
     49
     50
     51/*
     52 * Loader State. (See ldr.h for more info.)
     53 */
     54ULONG          ulLdrState = LDRSTATE_UNKNOWN;
     55
     56
     57/*
     58 * Pointer to the executable module being loaded.
     59 * This pointer is set by ldrOpen and cleared by tkExecPgm.
     60 * It's hence only valid at tkExecPgm time. (isLdrStateExecPgm() == TRUE).
     61 */
     62PMODULE         pExeModule = NULL;
     63
     64
     65/*
     66 * Filehandle bitmap.
     67 */
    4668unsigned char   achHandleStates[MAX_FILE_HANDLES/8];
     69
     70
    4771
    4872
     
    6488 * Gets a module by the MTE.
    6589 * @returns   Pointer to module node. If not found NULL.
    66  * @param     pMTE  Pointer an Module Table Entry.
     90 * @param     pMTE  Pointer a Module Table Entry.
    6791 * @sketch    Try find it in the MTE tree.
    6892 *            IF not found THEN
     
    124148
    125149/**
     150 * Gets a module by the hMTE.
     151 * @returns   Pointer to module node. If not found NULL.
     152 * @param     hMTE  Handle to a Module Table Entry.
     153 * @sketch    Convert hMte to an pMTE (pointer to MTE).
     154 *            Call getModuleByMTE with MTE pointer.
     155 * @status    completely implemented.
     156 * @author    knut st. osmundsen
     157 */
     158PMODULE     getModuleByhMTE(HMTE hMTE)
     159{
     160    PMTE pMTE;
     161
     162    pMTE = ldrValidateMteHandle(hMTE);
     163    if (pMTE != NULL)
     164        return getModuleByMTE(pMTE);
     165
     166    return NULL;
     167}
     168
     169
     170/**
    126171 * Get a module by filename.
    127172 * @returns   Pointer to module node. If not found NULL.
     
    236281            delete pMod->Data.pPe2Lx;
    237282            break;
    238 
     283/*
    239284        case MOD_TYPE_ELF2LX:
    240         case MOD_TYPE_SCRIPT:
    241         case MOD_TYPE_PE:
     285            break;
     286*/
     287#ifdef DEBUG
    242288        default:
    243289            kprintf(("removeModule: Unknown type, %#x\n", pMod->fFlags & MOD_TYPE_MASK));
     290#endif
    244291    }
    245292
     
    248295
    249296    return NO_ERROR;
     297}
     298
     299
     300/**
     301 * Gets the path of the executable being executed.
     302 * @returns     Pointer to pszPath on success. Path has _NOT_ a trailing slash.
     303 *              NULL pointer on error.
     304 * @param       pszPath     Pointer to path buffer. Expects CCHMAXPATH length.
     305 * @param       fExecChild  Use hMTE of the PTDAExecChild if present.
     306 * @sketch
     307 * @status      completely implemented.
     308 * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     309 * @remark      The path from the pExeModule might not be fully qualified.
     310 */
     311PSZ ldrGetExePath(PSZ pszPath, BOOL fExecChild)
     312{
     313    PCSZ    pszFilename;
     314    PCSZ    psz;
     315
     316    #if 0 /* getFilename not implemented */
     317    if (pExeModule != NULL)
     318        /*
     319         * We have the executable object pointer. Let's use it!
     320         */
     321        pszFilename = pExeModule->Data.pModule->getFilename();
     322    else
     323    #endif
     324    {
     325        /*
     326         * Get the hMTE for the executable using the pPTDAExecChild
     327         * Then get the pMTE, and access the smte_path to get a pointer to the executable path.
     328         */
     329        PPTDA   pPTDACur;               /* Pointer to the current (system context) PTDA */
     330        PPTDA   pPTDA;                  /* PTDA in question. */
     331        HMTE    hMTE = NULLHANDLE;      /* Modulehandle of the executable module. */
     332        PMTE    pMTE;                   /* Pointer to ModuleTableEntry of the executable module. */
     333
     334        /*
     335         *  Get the current PTDA. (Fail if this call failes.)
     336         *  IF pPTDAExecChild isn't NULL THEN get hMTE for that.
     337         *  IF no pPTDAExecChild THEN  get hMte for the current PTDA.
     338         */
     339        pPTDACur = ptdaGetCur();
     340        if (pPTDACur != NULL)
     341        {
     342            pPTDA = ptdaGet_pPTDAExecChild(pPTDACur);
     343            if (pPTDA != NULL && fExecChild)
     344                hMTE = ptdaGet_ptda_module(pPTDA);
     345            if (hMTE == NULLHANDLE)
     346                hMTE = ptdaGet_ptda_module(pPTDACur);
     347        }
     348        else
     349        {   /* Not called at task time? No current task! */
     350            kprintf(("ldrGetExePath: Failed to get current PTDA.\n"));
     351            return NULL;
     352        }
     353
     354        /* fail if hMTE is NULLHANDLE ie. not found / invalid */
     355        if (hMTE == NULLHANDLE)
     356        {
     357            kprintf(("ldrGetExePath: Failed to get hMTE from the PTDAs.\n"));
     358            return NULL;
     359        }
     360
     361        /* get the pMTE for this hMTE */
     362        pMTE = ldrASMpMTEFromHandle(hMTE);
     363        if (pMTE == NULL)
     364        {
     365            kprintf(("ldrGetExePath: ldrASMpMTEFromHandle failed for hMTE=0x%04.\n", hMTE));
     366            return NULL;
     367        }
     368        if (pMTE->mte_swapmte == NULL) /* paranoia */
     369        {
     370            kprintf(("ldrGetExePath: mte_swapmte is NULL.\n"));
     371            return NULL;
     372        }
     373
     374        /* take the filename from the swappable MTE */
     375        pszFilename = pMTE->mte_swapmte->smte_path;
     376        if (pszFilename == NULL)
     377        {
     378            kprintf(("ldrGetExePath: smte_path is NULL.\n"));
     379            return NULL;
     380        }
     381    }
     382
     383    /* paranoia... */
     384    if (*pszFilename == '\0')
     385    {
     386        kprintf(("ldrGetExePath: pszFilename is empty!\n"));
     387        return NULL;
     388    }
     389
     390    /*
     391     * Skip back over the filename. (stops pointing at the slash or ':')
     392     */
     393    psz = pszFilename + strlen(pszFilename)-1;
     394    while (psz >= pszFilename && *psz != '\\' && *psz != '/' && *psz != ':')
     395        psz--;
     396
     397    /*
     398     * If no path the fail.
     399     */
     400    if (psz <= pszFilename)
     401    {
     402        kprintf(("ldrGetExePath: Exepath is empty.\n"));
     403        return NULL;
     404    }
     405
     406    /*
     407     * Copy path and return.
     408     */
     409    memcpy(pszPath, pszFilename, psz - pszFilename);
     410    pszPath[psz - pszFilename] = '\0';
     411    return pszPath;
    250412}
    251413
Note: See TracChangeset for help on using the changeset viewer.