Changeset 9911 for trunk/src


Ignore:
Timestamp:
Mar 6, 2003, 11:44:34 AM (22 years ago)
Author:
sandervl
Message:

cleanup/resync

Location:
trunk/src/kernel32
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/HandleManager.cpp

    r9748 r9911  
    1 /* $Id: HandleManager.cpp,v 1.94 2003-02-04 11:28:55 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.95 2003-03-06 10:44:32 sandervl Exp $ */
    22
    33/*
     
    899899                       DWORD   fdwAccess,
    900900                       BOOL    fInherit,
    901                        DWORD   fdwOptions,
    902                        DWORD   fdwOdinOptions)
     901                       DWORD   fdwOptions)
    903902{
    904903  int             iIndex;                     /* index into the handle table */
     
    925924  /* initialize the complete HMHANDLEDATA structure */
    926925  pHMHandleData                = &TabWin32Handles[iIndexNew].hmHandleData;
    927   if (fdwOptions & DUPLICATE_SAME_ACCESS)
     926  if (fdwOptions & DUPLICATE_SAME_ACCESS) 
    928927      pHMHandleData->dwAccess    = TabWin32Handles[srchandle].hmHandleData.dwAccess;
    929928  else
    930929      pHMHandleData->dwAccess    = fdwAccess;
    931930
    932   if((fdwOdinOptions & DUPLICATE_ACCESS_READWRITE) == DUPLICATE_ACCESS_READWRITE) {
    933       pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE;
    934   }
    935   else
    936   if(fdwOdinOptions & DUPLICATE_ACCESS_READ) {
    937       pHMHandleData->dwAccess = GENERIC_READ;
    938   }
    939 
    940   if(fdwOdinOptions & DUPLICATE_SHARE_READ) {
    941       pHMHandleData->dwShare = FILE_SHARE_READ;
    942   }
    943   else
    944   if(fdwOdinOptions & DUPLICATE_SHARE_DENYNONE) {
    945       pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
    946   }
    947   else  pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare;
    948 
     931  pHMHandleData->dwShare       = TabWin32Handles[srchandle].hmHandleData.dwShare;
    949932  pHMHandleData->dwCreation    = TabWin32Handles[srchandle].hmHandleData.dwCreation;
    950933  pHMHandleData->dwFlags       = TabWin32Handles[srchandle].hmHandleData.dwFlags;
     
    967950                                       fdwAccess,
    968951                                       fInherit,
    969                                        fdwOptions & ~DUPLICATE_CLOSE_SOURCE,
    970                                        fdwOdinOptions);
     952                                       fdwOptions & ~DUPLICATE_CLOSE_SOURCE, 0);
    971953
    972954  //Don't let Open32 close it for us, but do it manually (regardless of error; see SDK docs))
  • trunk/src/kernel32/hmdisk.cpp

    r9824 r9911  
    1 /* $Id: hmdisk.cpp,v 1.61 2003-02-18 18:48:54 sandervl Exp $ */
     1/* $Id: hmdisk.cpp,v 1.62 2003-03-06 10:44:33 sandervl Exp $ */
    22
    33/*
     
    18391839    if(map) {
    18401840        lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    1841         DWORD nrpages = nNumberOfBytesToRead/4096;
    1842         if(offset & 0xfff)
    1843             nrpages++;
    1844         if(nNumberOfBytesToRead & 0xfff)
     1841        DWORD nrpages = (nNumberOfBytesToRead+offset)/4096;
     1842        if((nNumberOfBytesToRead+offset) & 0xfff)
    18451843            nrpages++;
    18461844   
    1847         map->commitPage(offset & ~0xfff, TRUE, nrpages);
     1845        map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);
    18481846        map->Release();
    18491847    }
     
    21052103    if(map) {
    21062104        lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    2107         DWORD nrpages = nNumberOfBytesToWrite/4096;
    2108         if(offset & 0xfff)
    2109             nrpages++;
    2110         if(nNumberOfBytesToWrite & 0xfff)
     2105        DWORD nrpages = (nNumberOfBytesToWrite+offset)/4096;
     2106        if((nNumberOfBytesToWrite+offset) & 0xfff)
    21112107            nrpages++;
    21122108   
    2113         map->commitPage(offset & ~0xfff, TRUE, nrpages);
     2109        map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);
    21142110        map->Release();
    21152111    }
  • trunk/src/kernel32/hmfile.cpp

    r9824 r9911  
    1 /* $Id: hmfile.cpp,v 1.40 2003-02-18 18:48:54 sandervl Exp $ */
     1/* $Id: hmfile.cpp,v 1.41 2003-03-06 10:44:33 sandervl Exp $ */
    22
    33/*
     
    527527  if(map) {
    528528       lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    529        DWORD nrpages = nNumberOfBytesToRead/4096;
    530        if(offset & 0xfff)
     529       DWORD nrpages = (nNumberOfBytesToRead+offset)/4096;
     530       if((nNumberOfBytesToRead+offset) & 0xfff)
    531531           nrpages++;
    532        if(nNumberOfBytesToRead & 0xfff)
    533            nrpages++;
    534 
    535        map->commitPage(offset & ~0xfff, TRUE, nrpages);
     532
     533       map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);
    536534       map->Release();
    537535  }
    538536  else lpRealBuf = (LPVOID)lpBuffer;
     537
     538  //If this file is also used in a memory map somewhere, then we need
     539  //to tell the map to flush all modified contents to disk right NOW
     540  map = Win32MemMap::findMapByFile(pHMHandleData->hWin32Handle);
     541  if(map) {
     542      DWORD curpos = SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT);
     543
     544      dprintf(("Flush memory maps to disk before reading!!"));
     545      map->flushView(MMAP_FLUSHVIEW_ALL, curpos, nNumberOfBytesToRead);
     546  }
    539547
    540548  if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
     
    615623  if(map) {
    616624       lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    617        DWORD nrpages = nNumberOfBytesToWrite/4096;
    618        if(offset & 0xfff)
    619            nrpages++;
    620        if(nNumberOfBytesToWrite & 0xfff)
     625       DWORD nrpages = (nNumberOfBytesToWrite+offset)/4096;
     626       if((nNumberOfBytesToWrite+offset) & 0xfff)
    621627           nrpages++;
    622628 
    623        map->commitPage(offset & ~0xfff, TRUE, nrpages);
     629       map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);
    624630       map->Release();
    625631  }
    626632  else lpRealBuf = (LPVOID)lpBuffer;
     633
     634  //If this file is also used in a memory map somewhere, then we need
     635  //to tell the map to flush all modified contents to disk right NOW
     636  DWORD curfilepos;
     637  map = Win32MemMap::findMapByFile(pHMHandleData->hWin32Handle);
     638  if(map) {
     639      curfilepos = SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT);
     640
     641      dprintf(("Flush memory maps to disk before writing!!"));
     642      map->flushView(MMAP_FLUSHVIEW_ALL, curfilepos, nNumberOfBytesToWrite);
     643  }
    627644
    628645  if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
     
    635652                            lpNumberOfBytesWritten);
    636653//  }
     654
     655  if(map && bRC) {
     656      dprintf(("Invalidate memory map after file writing!!"));
     657      map->invalidatePages(curfilepos, *lpNumberOfBytesWritten);
     658  }
    637659
    638660  dprintf(("KERNEL32: HMDeviceFileClass::WriteFile returned %08xh\n",
  • trunk/src/kernel32/kernel32.mak

    r9910 r9911  
    1 # $Id: kernel32.mak,v 1.41 2003-03-06 10:22:27 sandervl Exp $
     1# $Id: kernel32.mak,v 1.42 2003-03-06 10:44:33 sandervl Exp $
    22
    33#
     
    100100$(OBJDIR)\time.obj \
    101101$(OBJDIR)\mmap.obj \
    102 $(OBJDIR)\mmapview.obj \
    103 $(OBJDIR)\mmapdup.obj \
    104102$(OBJDIR)\winimagepe2lx.obj \
    105103$(OBJDIR)\winimagepeldr.obj \
  • trunk/src/kernel32/mmap.cpp

    r9826 r9911  
    1 /* $Id: mmap.cpp,v 1.62 2003-02-18 18:58:47 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.63 2003-03-06 10:44:34 sandervl Exp $ */
    22
    33/*
     
    126126                           &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
    127127#else
    128         DWORD dwOdinOptions;
    129 
    130         if(!(mProtFlags & PAGE_READWRITE)) {
    131                 dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE;
    132         }
    133         else    dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;
    134 
    135         if(HMDuplicateHandleOdin(GetCurrentProcess(), hMemFile, GetCurrentProcess(),
    136                            &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS, dwOdinOptions) == FALSE)
     128        if(HMDuplicateHandle(GetCurrentProcess(), hMemFile, GetCurrentProcess(),
     129                           &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
    137130#endif
    138131        {
     
    265258}
    266259//******************************************************************************
    267 //We determine whether a page has been modified by checking it's protection flags
    268 //If the write flag is set, this means commitPage had to enable this due to a pagefault
    269 //(all pages are readonly until the app tries to write to it)
    270 //******************************************************************************
    271 BOOL Win32MemMap::commitPage(ULONG offset, BOOL fWriteAccess, int nrpages)
     260// Win32MemMap::commitRange
     261//
     262// Commit a range of pages
     263//
     264// Parameters:
     265//
     266//   ULONG ulFaultAddr          - exception address
     267//   ULONG ulOffset             - offset in memory map
     268//   BOOL  fWriteAccess         - TRUE  -> write exception
     269//                                FALSE -> read exception
     270//   int   nrpages              - number of pages
     271//
     272// Returns:
     273//   TRUE                       - success
     274//   FALSE                      - failure
     275//
     276//******************************************************************************
     277BOOL Win32MemMap::commitRange(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages)
     278{
     279    LPVOID lpPageFaultAddr = (LPVOID)((ULONG)pMapping + offset);
     280    DWORD  pageAddr        = (DWORD)lpPageFaultAddr & ~0xFFF;
     281
     282    dprintf(("Win32MemMap::commitRange %x (faultaddr %x)", pageAddr, lpPageFaultAddr));
     283
     284    if(fWriteAccess)
     285    {//writes are handled on a per-page basis
     286        for(int i=i;i<nrpages;i++)
     287        {
     288            if(commitPage(ulFaultAddr, offset, TRUE, 1) == FALSE) {
     289                dprintf(("Win32MemMap::commit: commitPage failed!!"));
     290                return FALSE;
     291            }
     292            ulFaultAddr += PAGE_SIZE;
     293            offset      += PAGE_SIZE;
     294        }
     295        return TRUE;
     296    }
     297    else    return commitPage(ulFaultAddr, offset, FALSE, nrpages);
     298}
     299//******************************************************************************
     300// Win32MemMap::commitPage
     301//
     302// Handle a pagefault for a memory map
     303//
     304// Parameters:
     305//
     306//   ULONG ulFaultAddr          - exception address
     307//   ULONG ulOffset             - offset in memory map
     308//   BOOL  fWriteAccess         - TRUE  -> write exception
     309//                                FALSE -> read exception
     310//   int   nrpages              - number of pages
     311//
     312// Returns:
     313//   TRUE                       - success
     314//   FALSE                      - failure
     315//
     316// NOTE:
     317//   We handle only one pages for write access!
     318//
     319// REMARKS:
     320//   We determine whether a page has been modified by checking it's protection flags
     321//   If the write flag is set, this means commitPage had to enable this due to a pagefault
     322//   (all pages are readonly until the app tries to write to it)
     323//******************************************************************************
     324BOOL Win32MemMap::commitPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages)
    272325{
    273326 MEMORY_BASIC_INFORMATION memInfo;
     
    365418}
    366419//******************************************************************************
     420// Win32MemMap::commitGuardPage
     421//
     422// Handle a guard page exception for a copy-on-write view (one page only)
     423//
     424// Parameters:
     425//
     426//   ULONG ulFaultAddr          - exception address
     427//   ULONG ulOffset             - offset in memory map
     428//   BOOL  fWriteAccess         - TRUE  -> write exception
     429//                                FALSE -> read exception
     430//
     431// Returns:
     432//   TRUE                       - success
     433//   FALSE                      - failure
     434//
     435//******************************************************************************
     436BOOL Win32MemMap::commitGuardPage(ULONG ulFaultAddr, ULONG ulOffset, BOOL fWriteAccess)
     437{
     438    return FALSE;
     439}
     440//******************************************************************************
     441// Win32MemMap::invalidatePages
     442//
     443// Invalidate map pages. (called by WriteFile)
     444//
     445// Parameters:
     446//
     447//   ULONG offset               - offset in memory map
     448//   ULONG size                 - invalid range size
     449//
     450// Returns:
     451//   TRUE                       - success
     452//   FALSE                      - failure
     453//
     454//******************************************************************************
     455BOOL Win32MemMap::invalidatePages(ULONG offset, ULONG size)
     456{
     457    return FALSE;
     458}
     459//******************************************************************************
    367460// Win32MemMap::unmapViewOfFile
    368461//
     
    517610//      I'm assuming they aren't for now.
    518611//******************************************************************************
    519 BOOL Win32MemMap::flushView(ULONG offset, ULONG cbFlush)
     612BOOL Win32MemMap::flushView(ULONG viewaddr, ULONG offset, ULONG cbFlush)
    520613{
    521614 LPVOID lpvBase = (LPVOID)((ULONG)pMapping+offset);
     
    767860
    768861    if(mfAccess & MEMMAP_ACCESS_WRITE)
    769         mParentMap->flushView(mOffset, mSize);
     862        mParentMap->flushView(MMAP_FLUSHVIEW_ALL, mOffset, mSize);
    770863
    771864    //Don't free memory for executable image map views (only used internally)
  • trunk/src/kernel32/mmap.h

    r9824 r9911  
    1 /* $Id: mmap.h,v 1.25 2003-02-18 18:48:55 sandervl Exp $ */
     1/* $Id: mmap.h,v 1.26 2003-03-06 10:44:34 sandervl Exp $ */
    22
    33/*
     
    2828#define NRPAGES_TOCOMMIT        16
    2929
    30 #define MEMMAP_ACCESS_READ      1
    31 #define MEMMAP_ACCESS_WRITE     2
    32 #define MEMMAP_ACCESS_EXECUTE   4
     30#define MEMMAP_ACCESS_INVALID           0
     31#define MEMMAP_ACCESS_READ              1
     32#define MEMMAP_ACCESS_WRITE             2
     33#define MEMMAP_ACCESS_EXECUTE           4
     34#define MEMMAP_ACCESS_COPYONWRITE       8
     35
     36#define MMAP_FLUSHVIEW_ALL              0xFFFFFFFF
    3337
    3438class Win32MemMapView;
     
    4549  ~Win32MemMap();
    4650
    47   BOOL   Init(DWORD aMSize=0);
    48    BOOL   flushView(ULONG offset, ULONG cbFlush);
    49   LPVOID mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess);
    50   BOOL   unmapViewOfFile(LPVOID addr);
     51virtual BOOL   Init(DWORD aMSize=0);
     52virtual BOOL   flushView(ULONG viewaddr, ULONG offset, ULONG cbFlush);
     53virtual LPVOID mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess);
     54virtual BOOL   unmapViewOfFile(LPVOID addr);
    5155
    5256   HFILE  getFileHandle()                { return hMemFile; };
     
    6367   void   Release();
    6468
    65    BOOL   commitPage(ULONG offset, BOOL fWriteAccess, int nrpages = NRPAGES_TOCOMMIT);
     69virtual BOOL   invalidatePages(ULONG offset, ULONG size);
     70virtual BOOL   commitPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages = NRPAGES_TOCOMMIT);
     71virtual BOOL   commitGuardPage(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess);
     72        BOOL   commitRange(ULONG ulFaultAddr, ULONG offset, BOOL fWriteAccess, int nrpages);
    6673
    6774static Win32MemMap *findMap(LPSTR lpszName);
  • trunk/src/kernel32/oslibmem.cpp

    r9292 r9911  
    1 /* $Id: oslibmem.cpp,v 1.5 2002-09-24 15:15:27 sandervl Exp $ */
     1/* $Id: oslibmem.cpp,v 1.6 2003-03-06 10:44:34 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    4343
    4444//******************************************************************************
    45 //TODO: Assumes entire memory range has the same protection flags!
    4645//TODO: Check if this works for code aliases...
    4746//******************************************************************************
     
    5554    cb+= PAGE_SIZE;
    5655
    57     rc = DosQueryMem(pb, &size, &attr);
    58     if(rc) {
    59         dprintf(("!ERROR!: OSLibDosAliasMem: DosQueryMem %x %x return %d", pb, size, rc));
    60         return rc;
    61     }
    62     size = (size-1) & ~0xfff;
    63     size+= PAGE_SIZE;
    64     if(size != cb) {
    65         dprintf(("!WARNING!: OSLibDosAliasMem: size != cb (%x!=%x)!!!!!!!!", size, cb));
    66         //ignore this and continue return 5;
    67         attr = fl; //just use original protection flags (NOT CORRECT)
    68     }
    69     attr &= (PAG_READ|PAG_WRITE|PAG_EXECUTE|PAG_GUARD|PAG_DEFAULT);
    70     if(attr != fl) {
    71         rc = DosSetMem(pb, size, fl);
    72         if(rc) {
    73                 dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem %x %x return %d", pb, size, rc));
    74                 attr = fl;
    75                 //just continue for now
    76                 //return rc;
    77         }
    78     }
    7956    rc = DosAliasMem(pb, cb, ppbAlias, 2);
    8057    if(rc) {
     
    8259        return rc;
    8360    }
    84     if(attr != fl) {
    85         rc = DosSetMem(pb, size, attr);
    86         if(rc) {
    87             dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem (2) %x %x return %d", pb, size, rc));
     61    //Now try to change the protection flags of all pages in the aliased range
     62    DWORD pAlias = (DWORD)*ppbAlias;
     63
     64    while(pAlias < (DWORD)*ppbAlias + cb)
     65    {
     66        rc = DosQueryMem((PVOID)pAlias, &size, &attr);
     67        if(rc != NO_ERROR) {
     68            dprintf(("!ERROR!: OSLibDosAliasMem: DosQueryMem %x returned %d", pAlias, rc));
     69            DebugInt3();
    8870            return rc;
    8971        }
     72        //Don't bother if the pages are not committed. DosSetMem will return
     73        //ERROR_ACCESS_DENIED.
     74        if(attr & PAG_COMMIT) {
     75            rc = DosSetMem((PVOID)pAlias, size, fl);
     76            if(rc) {
     77                dprintf(("!ERROR!: OSLibDosAliasMem: DosSetMem %x %x return %d", *ppbAlias, size, rc));
     78                DebugInt3();
     79                return rc;
     80            }
     81        }
     82        pAlias += size;
    9083    }
    9184    return 0;
  • trunk/src/kernel32/profile.h

    r4752 r9911  
    1 /* $Id: profile.h,v 1.8 2000-12-04 12:41:48 bird Exp $ */
     1/* $Id: profile.h,v 1.9 2003-03-06 10:44:34 sandervl Exp $ */
    22/*
    33 * Profile header for initterm
     
    1414#define ODINININAME "ODIN.INI"
    1515
    16 void WINAPI WriteOutProfiles(void);
    17 int WINAPI PROFILE_LoadOdinIni(void);
    18 
    19 #ifdef DEBUG
    20 
    21 INT ODIN_EXTERN(GetPrivateProfileStringA)(LPCSTR section, LPCSTR entry,
    22                                           LPCSTR def_val, LPSTR buffer,
    23                                           UINT len, LPCSTR filename);
    24 
    25 int ODIN_EXTERN(PROFILE_GetOdinIniString)(LPCSTR section, LPCSTR entry,
    26                                           LPCSTR def_val, LPSTR buffer,
    27                                           UINT len);
    28 
    29 int ODIN_EXTERN(PROFILE_SetOdinIniString)(LPCSTR section_name, LPCSTR key_name,
    30                                           LPCSTR value);
    31 
    32 int ODIN_EXTERN(PROFILE_GetOdinIniInt)(LPCSTR section_name, LPCSTR key_name,
    33                                           int value);
    34 
    35 int ODIN_EXTERN(PROFILE_GetOdinIniBool)(LPCSTR section, LPCSTR key_name,
    36                                           int def);
    37 
    38 UINT ODIN_EXTERN(GetPrivateProfileIntA)(LPCSTR, LPCSTR, INT, LPCSTR);
    39 UINT ODIN_EXTERN(GetPrivateProfileIntW)(LPCWSTR, LPCWSTR, INT, LPCWSTR);
    40 INT  ODIN_EXTERN(GetPrivateProfileStringW)(LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, UINT, LPCWSTR);
    41 BOOL ODIN_EXTERN(WritePrivateProfileStringA)(LPCSTR, LPCSTR, LPCSTR, LPCSTR);
    42 BOOL ODIN_EXTERN(WritePrivateProfileStringW)(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR);
    43 
    44 #endif
    45 
    4616#include <win\options.h> //for odin profile apis
    4717
  • trunk/src/kernel32/virtual.cpp

    r9884 r9911  
    1 /* $Id: virtual.cpp,v 1.53 2003-03-03 16:30:44 sandervl Exp $ */
     1/* $Id: virtual.cpp,v 1.54 2003-03-06 10:44:34 sandervl Exp $ */
    22
    33/*
     
    180180        return FALSE;
    181181    }
    182     ret = map->flushView(offset, cbFlush);
     182    ret = map->flushView((ULONG)base, offset, cbFlush);
    183183    map->Release();
    184184    return ret;
     
    365365        if(map) {
    366366            //TODO: We don't allow protection flag changes for mmaped files now
    367             map->commitPage(offset, FALSE, nrpages);
     367            map->commitPage((ULONG)lpvAddress, offset, FALSE, nrpages);
    368368            map->Release();
    369369            return lpvAddress;
Note: See TracChangeset for help on using the changeset viewer.