Ignore:
Timestamp:
Mar 18, 2012, 12:41:27 AM (13 years ago)
Author:
dmik
Message:

kernel32: Fix stack size interpretation in CreateThread().

It now uses the stack size parameter as a number of bytes to
pre-commit, not as a total stack size, unless
STACK_SIZE_PARAM_IS_A_RESERVATION is set.

Closes #77.

File:
1 edited

Legend:

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

    r21916 r21981  
    7979    pHMHandleData->dwUserData = (DWORD)threadobj;
    8080
     81    // round up to page size
     82    cbStack = (cbStack + 0xFFF) & ~0xFFF;
     83
     84    // per default 1MB stack per thread
     85    DWORD cbTotalStack = (WinExe) ? WinExe->getDefaultStackSize() : 0x100000;
     86    DWORD cbCommitStack = 0;
     87    if (fdwCreate & STACK_SIZE_PARAM_IS_A_RESERVATION) {
     88        if (cbStack)
     89            cbTotalStack = cbStack;
     90    } else {
     91        if (cbStack >= cbTotalStack) {
     92            // round up the new reserved size to 1MB
     93            cbTotalStack = (cbStack + 0xFFFFF) & ~0xFFFFF;
     94            cbCommitStack = cbStack;
     95        } else if (cbStack) {
     96            cbCommitStack = cbStack;
     97        }
     98    }
     99
     100    dprintf(("Thread stack size 0x%X (0x%X to commit)", cbTotalStack, cbCommitStack));
     101
    81102    //SvL: This doesn't really create a thread, but only sets up the
    82103    //     handle of the current thread.
     
    85106        return pHMHandleData->hHMHandle;
    86107    }
    87     winthread = new Win32Thread(lpStartAddr, lpvThreadParm, fdwCreate, hThread);
     108    winthread = new Win32Thread(lpStartAddr, lpvThreadParm, fdwCreate, hThread, cbCommitStack);
    88109
    89110    if(winthread == 0) {
     
    100121    }
    101122
    102     // @@@PH Note: with debug code enabled, ODIN might request more stack space!
    103     //SvL: Also need more stack in release build (RealPlayer 7 sometimes runs
    104     //     out of stack
    105     if (cbStack > 0) {
    106         cbStack <<= 1;     // double stack
    107     }
    108     else {
    109         cbStack = (WinExe) ? WinExe->getDefaultStackSize() : 0x100000; // per default 1MB stack per thread
    110     }
    111     dprintf(("Thread stack size 0x%x", cbStack));
    112 
    113123    //************************************************************************************
    114124    //NOTE: If we ever decide to allocate our own stack, then we MUST use VirtualAlloc!!!!
    115125    //      (alignment reasons)
    116126    //************************************************************************************
    117     pHMHandleData->hHMHandle = O32_CreateThread(lpsa, cbStack, winthread->GetOS2Callback(),
     127    pHMHandleData->hHMHandle = O32_CreateThread(lpsa, cbTotalStack, winthread->GetOS2Callback(),
    118128                                                (LPVOID)winthread, fdwCreate, lpIDThread);
    119129
Note: See TracChangeset for help on using the changeset viewer.