Changeset 4998 for trunk/src


Ignore:
Timestamp:
Jan 21, 2001, 8:52:46 AM (25 years ago)
Author:
bird
Message:

pre-commit

Location:
trunk/src/win32k
Files:
3 edited

Legend:

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

    r4996 r4998  
    1 /* $Id: api.cpp,v 1.2 2001-01-20 23:51:06 bird Exp $
     1/* $Id: api.cpp,v 1.3 2001-01-21 07:52:46 bird Exp $
    22 *
    33 * API Overload Init and Helper Function.
     
    1414#define INCL_DOSERRORS
    1515#define INCL_NOPMAPI
    16 #define INCL_OS2KRNL_SEM
    17 #define INCL_OS2KRNL_PTDA
    18 #define INCL_OS2KRNL_IO
     16#define INCL_OS2KRNL_ALL
    1917
    2018
     
    3533#include "log.h"
    3634#include "OS2Krnl.h"
     35#include "ldrCalls.h"
    3736#include "dev32.h"
    3837#include "api.h"
    3938#include "options.h"
     39#include "locks.h"
    4040
    4141
     
    6464*   Global Variables                                                           *
    6565*******************************************************************************/
    66 APIDATAENTRY    aApiData[API_MAX];      /* Array of api info. */
     66APIDATAENTRY    aApiData[API_CENTRIES]; /* Array of api info. */
    6767PSZ             pszFile;                /* Pointer to entire file mapping. */
     68RWLOCK          ApiInfoRWLock;          /* Read/Write lock for api data. */
    6869
    6970
     
    7677int     apiInterpretApiNo(PSZ pszSection);
    7778void    apiFreeApiData(PAPIDATAENTRY paNewApiData);
    78 
    79 
     79void    apiSortApiData(PAPIDATAENTRY paApiData);
     80void    apiSortMaskArray(PMASKARRAY pMasks);
     81BOOL    apiFindNameInMaskArray(PSZ pszName, PMASKARRAY pMasks);
     82APIRET  apiGetProccessName(PSZ pszName);
     83APIRET  apiGetModuleName(PSZ pszName, USHORT usCS, ULONG ulEIP);
    8084
    8185
     
    197201            {
    198202                int iApi = apiInterpretApiNo(pszLine);
    199                 if (iApi >= 0 && iApi < API_MAX)
     203                if (iApi >= 0 && iApi < API_CENTRIES)
    200204                {
    201205                    PMASKARRAY pMaskArray = &paNewApiData[iApi].ModuleExc;
     
    271275    if (rc == NO_ERROR)
    272276    {
    273         /* add spin lock */
     277        apiSortApiData(paNewApiData);
     278        RWLockAcquireWrite(&ApiInfoRWLock);
    274279        apiFreeApiData(&aApiData[0]);
    275280        memcpy(&aApiData[0], paNewApiData, sizeof(aApiData));
    276         /* remove spin lock */
     281        RWLockReleaseWrite(&ApiInfoRWLock);
    277282    }
    278283    else
     
    391396/**
    392397 * Frees internal data in a api data structure.
    393  * @param   paNewApiData    Pointer to api data table.
     398 * @param   paApiData   Pointer to api data table.
    394399 * @sketch  Loop thru all api entries and free mask array pointers.
    395400 * @status  Completely implemented.
     
    397402 * @remark  Any serialization is not my problem.
    398403 */
    399 void    apiFreeApiData(PAPIDATAENTRY paNewApiData)
     404void    apiFreeApiData(PAPIDATAENTRY paApiData)
    400405{
    401406    int i;
    402407
    403     for (i = 0; i < API_MAX; i++)
    404     {
    405         if (paNewApiData[i].ProcessInc.cMasks)
    406             rfree(paNewApiData[i].ProcessInc.papszMasks);
    407         if (paNewApiData[i].ProcessExc.cMasks)
    408             rfree(paNewApiData[i].ProcessExc.papszMasks);
    409         if (paNewApiData[i].ModuleInc.cMasks)
    410             rfree(paNewApiData[i].ModuleInc.papszMasks);
    411         if (paNewApiData[i].ModuleExc.cMasks)
    412             rfree(paNewApiData[i].ModuleExc.papszMasks);
    413     }
    414 }
    415 
    416 
    417 
     408    for (i = 0; i < API_CENTRIES; i++)
     409    {
     410        if (paApiData[i].ProcessInc.cMasks)
     411            rfree(paApiData[i].ProcessInc.papszMasks);
     412        if (paApiData[i].ProcessExc.cMasks)
     413            rfree(paApiData[i].ProcessExc.papszMasks);
     414        if (paApiData[i].ModuleInc.cMasks)
     415            rfree(paApiData[i].ModuleInc.papszMasks);
     416        if (paApiData[i].ModuleExc.cMasks)
     417            rfree(paApiData[i].ModuleExc.papszMasks);
     418    }
     419}
     420
     421
     422/**
     423 * Sort the entire api data structure.
     424 * @param   paApiData   Pointer to api data to sort.
     425 * @sketch  Loop thru all entries and sort all four mask arrays.
     426 * @status  completely implemented.
     427 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     428 * @remark  See apiSortMaskArray.
     429 */
     430void    apiSortApiData(PAPIDATAENTRY paApiData)
     431{
     432    int i;
     433
     434    for (i = 0; i < API_CENTRIES; i++)
     435    {
     436        apiSortMaskArray(&paApiData[i].ProcessInc);
     437        apiSortMaskArray(&paApiData[i].ProcessExc);
     438        apiSortMaskArray(&paApiData[i].ModuleInc);
     439        apiSortMaskArray(&paApiData[i].ModuleExc);
     440    }
     441}
     442
     443
     444/**
     445 * Sorts the content of an mask array.
     446 * Duplicates are removed.
     447 * @param   pMasks  Pointer to a mask array structure.
     448 * @sketch  Use bouble sort.
     449 * @status  partially implemented.
     450 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     451 * @remark  Duplicate submasks aren't tested for.
     452 *          example: "DOSCALL1.DLL" is equal to "DOS*"
     453 */
     454void    apiSortMaskArray(PMASKARRAY pMasks)
     455{
     456    int i;
     457    PSZ pszTmp;
     458
     459    do
     460    {
     461        for (i = 1, pszTmp = NULL; i < pMasks->cMasks; i++)
     462        {
     463            int iDiff = strcmp(pMasks->papszMasks[i], pMasks->papszMasks[i-1]);
     464            if (iDiff == 0)
     465            {   /* remove entry */
     466                memmove(&pMasks->papszMasks[i], &pMasks->papszMasks[i+1],
     467                        (pMasks->cMasks - i - 1) * sizeof(pMasks->papszMasks[0]));
     468                i--;
     469            }
     470            else if (iDiff < 0)
     471            {   /* Swap entries. */
     472                PSZ pszTmp = pMasks->papszMasks[i];
     473                pMasks->papszMasks[i] = pMasks->papszMasks[i-1];
     474                pMasks->papszMasks[i-1] = pszTmp;
     475            }
     476        }
     477    } while (pszTmp != NULL);
     478}
     479
     480
     481/**
     482 * Searches a mask array if there is any match for the given name.
     483 * @returns TRUE if found.
     484 *          FALSE if not found.
     485 * @param   pszName     Pointer to name.
     486 * @param   pMasks      Pointer to mask array.
     487 * @sketch
     488 * @status
     489 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     490 * @remark
     491 */
     492BOOL    apiFindNameInMaskArray(PSZ pszName, PMASKARRAY pMasks)
     493{
     494    return FALSE;
     495}
     496
     497
     498/**
     499 * Get the current process executable name.
     500 * @returns OS/2 return code.
     501 * @param   pszName     Pointer to output name buffer.
     502 * @sketch  Get current ptda.
     503 *          Get module handle (hmte) from current ptda.
     504 *          Get pmte and smte from the hmte.
     505 *          Check if there is any path (full filename).
     506 *          Parse out filename+ext from full filename and copy it to pszName.
     507 *          return.
     508 * @status  completely implemented.
     509 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     510 */
     511APIRET  apiGetProccessName(PSZ pszName)
     512{
     513    PPTDA pPTDA = ptdaGetCur();
     514    if (pPTDA)
     515    {
     516        HMTE hmte = ptdaGet_ptda_module(pPTDA);
     517        if (hmte)
     518        {
     519            PMTE    pmte = ldrASMpMTEFromHandle(hmte);
     520            PSMTE   psmte;
     521            if (    pmte
     522                && (psmte = pmte->mte_swapmte)
     523                &&  psmte->smte_path
     524                &&  *psmte->smte_path)
     525            {
     526                /*
     527                 * Get executable name from swap mte.
     528                 * We parse out the filename+ext and copies it to the output buffer.
     529                 */
     530                PCHAR   psz;
     531                PCHAR   pszExt;
     532                ldrGetFileName2(psmte->smte_path, (PCHAR*)SSToDS(&psz), (PCHAR*)SSToDS(&pszExt));
     533                if (!psz) psz = psmte->smte_path;
     534                strcpy(pszName, psz);
     535                return NO_ERROR;
     536            }
     537            else
     538                kprintf(("apiGetProcessName: failed to get pmte(0x%08x) from hmte(0x%04x) or no path.\n", pmte, hmte));
     539        }
     540        else
     541            kprintf(("apiGetProcessName: This PTDA has no module handle. (pptda=0x%08x, hptda=0x%04)\n", pPTDA, ptdaGet_ptda_handle(pPTDA)));
     542    }
     543    else
     544        kprintf(("apiGetProcessName: No current PTDA!\n"));
     545
     546    return ERROR_INVALID_PARAMETER;
     547}
     548
     549/**
     550 * Gets the module name from a given CS:EIP pair.
     551 * @returns OS/2 return code.
     552 * @param   pszName     Output buffer.
     553 * @param   usCS        CS (code segment).
     554 * @param   ulEIP       EIP (Extended Instruction Pointer).
     555 * @sketch  Get hmte from cs:eip.
     556 *          Get pmte and smte from the hmte.
     557 *          Check if there is any path (full filename).
     558 *          Parse out filename+ext from full filename and copy it to pszName.
     559 *          return.
     560 * @status  completely implemented.
     561 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     562 */
     563APIRET  apiGetModuleName(PSZ pszName, USHORT usCS, ULONG ulEIP)
     564{
     565    HMTE hmte = VMGetOwner(usCS, ulEIP);
     566    if (hmte)
     567    {
     568        PMTE    pmte = ldrASMpMTEFromHandle(hmte);
     569        PSMTE   psmte;
     570        if (    pmte
     571            && (psmte = pmte->mte_swapmte)
     572            &&  psmte->smte_path
     573            &&  *psmte->smte_path)
     574        {
     575            /*
     576             * Get executable name from swap mte.
     577             * We parse out the filename+ext and copies it to the output buffer.
     578             */
     579            PCHAR   psz;
     580            PCHAR   pszExt;
     581            ldrGetFileName2(psmte->smte_path, (PCHAR*)SSToDS(&psz), (PCHAR*)SSToDS(&pszExt));
     582            if (!psz) psz = psmte->smte_path;
     583            strcpy(pszName, psz);
     584            return NO_ERROR;
     585        }
     586        else
     587            kprintf(("apiGetModuleName: failed to get pmte(0x%08x) from hmte(0x%04x) or no path.\n", pmte, hmte));
     588    }
     589    else
     590        kprintf(("apiGetModuleName: failed to get hmte from cs=%04x eip=%08x\n", usCS, ulEIP));
     591
     592    /*
     593     * We failed.
     594     */
     595    return ERROR_INVALID_PARAMETER;
     596}
     597
     598
     599
     600/**
     601 * Checks if an api enhancement is enabled for this process or/and module.
     602 * Exclusion lists rulez over inclusion.
     603 * Excluded processes rulez over included modules.
     604 * @returns TRUE (!0) if it's enabled.
     605 *          FALSE (0) if it's disabled.
     606 * @param   iApi    Api data id/index.
     607 * @param   usCS    CS of the API caller.
     608 * @param   ulEIP   EIP of the API caller.
     609 * @sketch
     610 * @status
     611 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     612 * @remark
     613 */
    418614BOOL _Optlink   APIQueryEnabled(int iApi, USHORT usCS, LONG ulEIP)
    419615{
     
    427623
    428624    /*
    429      * Aquire read lock - TODO.
    430      */
    431 
     625     * Aquire read lock.
     626     */
     627    RWLockAcquireRead(&ApiInfoRWLock);
    432628
    433629    /*
     
    435631     * Check if entry is enabled.
    436632     */
    437     pEntry = &aApiInfo[iApi];
     633    BOOL    fRet = FALSE;
     634    pEntry = &aApiData[iApi];
    438635    if (pEntry->fEnabled)
    439636    {
    440637        CHAR    szName[CCHMAXPATH];
    441 
    442     }
    443     else
    444         fRet = FALSE;
    445 
    446 
    447     /*
    448      * Release read lock - TODO.
    449      */
    450 
     638        PSZ     pszName = (PSZ)SSToDS(&szName[0]);
     639
     640        if (pEntry->ProcessExc.cMasks > 0 || pEntry->ProcessInc.cMasks > 0)
     641        {
     642            if (!apiGetProccessName(pszName))
     643            {                           /* TODO - fix this priority - it's probably wrong */
     644                if (pEntry->ProcessExc.cMasks)
     645                    fRet = !apiFindNameInMaskArray(pszName, &pEntry->ProcessExc);
     646                else if (pEntry->ProcessInc.cMasks)
     647                    fRet = apiFindNameInMaskArray(pszName, &pEntry->ProcessInc);
     648            }
     649        }
     650
     651        if (    !pEntry->ProcessExc.cMasks
     652            &&  !fRet
     653            &&  (pEntry->ModuleExc.cMasks > 0 || pEntry->ModuleInc.cMasks > 0))
     654        {
     655            if (!apiGetModuleName(pszName, usCS, ulEIP))
     656            {                           /* TODO - fix this priority - it's probably wrong */
     657                if (pEntry->ModuleExc.cMasks)
     658                    fRet = !apiFindNameInMaskArray(pszName, &pEntry->ModuleExc);
     659                else if (pEntry->ProcessInc.cMasks)
     660                    fRet = apiFindNameInMaskArray(pszName, &pEntry->ModuleInc);
     661            }
     662        }
     663    }
     664
     665
     666    /*
     667     * Release read lock.
     668     */
     669    RWLockReleaseRead(&ApiInfoRWLock);
    451670
    452671    return fRet;
  • trunk/src/win32k/api/myVR32AllocMem.asm

    r4981 r4998  
    1 ; $Id: myVR32AllocMem.asm,v 1.2 2001-01-20 15:48:54 bird Exp $
     1; $Id: myVR32AllocMem.asm,v 1.3 2001-01-21 07:52:46 bird Exp $
    22;
    33; VR32AllocMem over loader which adds the OBJ_ANY flag.
     
    2323;
    2424    include devsegdf.inc
     25    include api.inc
    2526    include bsememf.inc
    2627    ifndef OBJ_ANY
     
    3839; Externs
    3940;
    40     extrn apiApplyChange:PROC           ; system call?
     41    extrn APIQueryEnabled:PROC
    4142    extrn _VR32AllocMem@50:PROC
    4243
     
    5859    ; It was not - check if we're to set it for this calling module.
    5960    ;
     61    movzx   ecx, word  ptr [esp + SEF_CS]
     62    mov     edx, dword ptr [esp + SEF_EIP]
    6063    push    eax
    61     push    dword ptr [esp + SEF_CS]
    62     push    dword ptr [esp + SEF_EIP]
    63     push    1
    64     call    apiApplyChange
    6564    sub     esp, 0ch
     65    mov     eax, API_DOSALLOCMEM_ANY_OBJ
     66    call    APIQueryEnabled
     67    add     esp, 0ch
    6668    test    eax, eax
    6769    pop     eax
  • trunk/src/win32k/include/api.h

    r4996 r4998  
    1 /* $Id: api.h,v 1.2 2001-01-20 23:49:54 bird Exp $
     1/* $Id: api.h,v 1.3 2001-01-21 07:52:46 bird Exp $
    22 *
    33 * API Overload Init and Helper Function - public header.
     
    88 *
    99 */
     10/*NOINC*/
    1011#ifndef _API_H_
    1112#define _API_H_
     13/*INC*/
    1214
    1315
     
    1719#define API_DOSALLOCMEM_ANY_OBJ                     0
    1820#define API_DOSALLOCSHAREDMEM_ANY_OBJ               1
    19 #define API_MAX                                     2
     21#define API_MAX                                     API_DOSALLOCSHAREDMEM_ANY_OBJ
     22#define API_CENTRIES                                (API_MAX + 1)
    2023
     24/*NOINC*/
     25APIRET _Optlink APIInit(void);
     26BOOL _Optlink   APIQueryEnabled(int iApi, USHORT usCS, LONG ulEIP);
     27/*INC*/
    2128
    22 void _Optlink   APIInit(void);
    23 BOOL _Optlink   APIQueryEnabled(int iApi, USHORT usCS, LONG ulEIP);
    24 
    25 
    26 
     29/*NOINC*/
    2730#endif
     31/*INC*/
Note: See TracChangeset for help on using the changeset viewer.