Changeset 8773 for trunk/src


Ignore:
Timestamp:
Jun 26, 2002, 9:13:00 AM (23 years ago)
Author:
sandervl
Message:

KSO: Console Ctrl Handlers updates; GetFileType on std files doesn't always return TYPE_CHAR; Enable writing to STDERRconodin32.cpp

Location:
trunk/src/kernel32
Files:
4 edited

Legend:

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

    r7476 r8773  
    1 /* $Id: console.cpp,v 1.29 2001-11-29 00:20:46 phaller Exp $ */
     1/* $Id: console.cpp,v 1.30 2002-06-26 07:13:00 sandervl Exp $ */
    22
    33/*
     
    416416      dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONOUT$ failed with %u.\n",
    417417               rc));
    418  
     418
    419419  // add standard symbolic links
    420420  HandleNamesAddSymbolicLink("CON",        "CONOUT$");
    421421  HandleNamesAddSymbolicLink("CON:",       "CONOUT$");
    422422  HandleNamesAddSymbolicLink("\\\\.\\CON", "CONOUT$");
    423  
     423
    424424  if(flVioConsole == TRUE)
    425425  {
     
    25932593 *****************************************************************************/
    25942594
    2595 BOOL WIN32API GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
    2596                                        DWORD dwProcessGroupId)
    2597 {
    2598 #ifdef DEBUG_LOCAL2
    2599   WriteLog("KERNEL32/CONSOLE: OS2GenerateConsoleCtrlEvent(%08x,%08x) not implemented.\n",
    2600            dwCtrlEvent,
    2601            dwProcessGroupId);
    2602 #endif
    2603 
    2604   return TRUE;
    2605 }
    2606 
    2607 
    2608 /*****************************************************************************
    2609  * Name      :
    2610  * Purpose   :
    2611  * Parameters:
    2612  * Variables :
    2613  * Result    :
    2614  * Remark    :
    2615  * Status    :
    2616  *
    2617  * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
    2618  *****************************************************************************/
    2619 
    26202595UINT WIN32API GetConsoleCP(VOID)
    26212596{
     
    35033478 *****************************************************************************/
    35043479
    3505 BOOL WIN32API SetConsoleCtrlHandler(PHANDLER_ROUTINE pHandlerRoutine,
    3506                                        BOOL             fAdd)
    3507 {
    3508 #ifdef DEBUG_LOCAL2
    3509   WriteLog("KERNEL32/CONSOLE: OS2SetConsoleCtrlHandler(%08x,%08x) not implemented.\n",
    3510            pHandlerRoutine,
    3511            fAdd);
    3512 #endif
    3513 
    3514   return TRUE;
    3515 }
    3516 
    3517 
    3518 /*****************************************************************************
    3519  * Name      :
    3520  * Purpose   :
    3521  * Parameters:
    3522  * Variables :
    3523  * Result    :
    3524  * Remark    :
    3525  * Status    :
    3526  *
    3527  * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
    3528  *****************************************************************************/
    3529 
    35303480BOOL WIN32API SetConsoleCursorInfo(HANDLE               hConsoleOutput,
    35313481                                      PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
  • trunk/src/kernel32/console.h

    r4502 r8773  
    1 /* $Id: console.h,v 1.4 2000-10-20 11:46:46 sandervl Exp $ */
     1/* $Id: console.h,v 1.5 2002-06-26 07:13:00 sandervl Exp $ */
    22
    33/*
     
    3939ULONG iConsoleTerminate(void);/* termination of the console subsystem */
    4040
     41BOOL InternalGenerateConsoleCtrlEvent(DWORD dwCtrlEvent, DWORD dwProcessGroupID);
     42BOOL WIN32API DefaultConsoleCtrlHandler(DWORD dwEvent);
     43
    4144#ifdef __cplusplus
    4245  }
  • trunk/src/kernel32/hmstd.cpp

    r8464 r8773  
    1 /* $Id: hmstd.cpp,v 1.8 2002-05-22 12:57:23 sandervl Exp $ */
     1/* $Id: hmstd.cpp,v 1.9 2002-06-26 07:13:00 sandervl Exp $ */
    22
    33/*
     
    120120                                      LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
    121121{
    122  DWORD  byteswritten;
    123  LPVOID lpLowMemBuffer;
     122    DWORD  byteswritten;
     123    LPVOID lpLowMemBuffer;
    124124
    125   dprintf(("KERNEL32: HMDeviceStandardClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
    126            lpHMDeviceName,
    127            pHMHandleData,
    128            lpBuffer,
    129            nNumberOfBytesToWrite,
    130            lpNumberOfBytesWritten,
    131            lpOverlapped));
    132   if(lpNumberOfBytesWritten == NULL) {
    133      lpNumberOfBytesWritten = &byteswritten;
    134   }
    135   if(lpCompletionRoutine) {
    136       dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    137   }
     125    dprintf(("KERNEL32: HMDeviceStandardClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
     126             lpHMDeviceName,
     127             pHMHandleData,
     128             lpBuffer,
     129             nNumberOfBytesToWrite,
     130             lpNumberOfBytesWritten,
     131             lpOverlapped));
     132    if (lpNumberOfBytesWritten == NULL)
     133        lpNumberOfBytesWritten = &byteswritten;
     134    if (lpCompletionRoutine)
     135    {
     136        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     137    }
    138138
    139   if(pHMHandleData->dwUserData == STD_INPUT_HANDLE) {
    140      return FALSE;
    141   }
    142   lpLowMemBuffer = alloca(nNumberOfBytesToWrite);
    143   if(lpLowMemBuffer == NULL) {
    144      DebugInt3();
    145      return FALSE;
    146   }
    147   memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
    148   if(pHMHandleData->dwUserData == STD_ERROR_HANDLE) {
    149      dprintf(("STDERR: %s", lpLowMemBuffer));
    150      return TRUE;
    151   }
    152   if(WinExe && !WinExe->isConsoleApp()) {
    153      //DosWrite returns error 436 when PM apps try to write to std out
    154      dprintf(("STDOUT (GUI): %s", lpLowMemBuffer));
    155      return TRUE;
    156   }
    157   dprintf(("STDOUT: %*s", nNumberOfBytesToWrite, lpLowMemBuffer));
    158   return O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
    159                        lpNumberOfBytesWritten, lpOverlapped);
     139    if (pHMHandleData->dwUserData == STD_INPUT_HANDLE)
     140        return FALSE;
     141    lpLowMemBuffer = alloca(nNumberOfBytesToWrite);
     142    if (lpLowMemBuffer == NULL)
     143    {
     144        DebugInt3();
     145        return FALSE;
     146    }
     147    memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
     148
     149    if (    WinExe
     150        &&  !WinExe->isConsoleApp()
     151        &&  O32_GetFileType(pHMHandleData->hHMHandle) == FILE_TYPE_UNKNOWN) /* kso */
     152    {
     153        //DosWrite returns error 436 when PM apps try to write to std out
     154        //kso - Jun 23 2002 2:54am:
     155        //Yeah, cause PM programs doesn't have working STD* handles unless you redirect them!
     156        //So, we should rather check if valid handle than !console.
     157        dprintf(("%s (GUI): %*s", pHMHandleData->dwUserData == STD_ERROR_HANDLE ? "STDERR" : "STDOUT",
     158                 nNumberOfBytesToWrite, lpLowMemBuffer));
     159        return TRUE;
     160    }
     161
     162    dprintf(("%s: %*s", pHMHandleData->dwUserData == STD_ERROR_HANDLE ? "STDERR" : "STDOUT",
     163             nNumberOfBytesToWrite, lpLowMemBuffer));
     164    if (!O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
     165                       lpNumberOfBytesWritten, lpOverlapped))
     166    {
     167        /* Open32 wasn't made for console apps... */
     168        dprintf(("STD*: failed with lasterror=%d\n", GetLastError()));
     169        return FALSE;
     170    }
     171    return TRUE;
    160172}
    161173
     
    178190           lpHMDeviceName,
    179191           pHMHandleData));
    180 
     192  #if 0
    181193  return FILE_TYPE_CHAR;
     194  #else
     195  return O32_GetFileType(pHMHandleData->hHMHandle);
     196  #endif
    182197}
  • trunk/src/kernel32/wprocess.cpp

    r8694 r8773  
    1 /* $Id: wprocess.cpp,v 1.155 2002-06-16 08:20:36 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.156 2002-06-26 07:13:00 sandervl Exp $ */
    22
    33/*
     
    4141
    4242#include "console.h"
     43#include "wincon.h"
    4344#include "cio.h"
    4445#include "versionos2.h"    /*PLF Wed  98-03-18 02:36:51*/
     
    7273//Process database
    7374PDB          ProcessPDB = {0};
     75ENVDB        ProcessENVDB = {0};
     76CONCTRLDATA  ProcessConCtrlData = {0};
    7477STARTUPINFOA StartupInfo = {0};
    7578CHAR         unknownPDBData[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ,0 ,0};
     
    193196}
    194197//******************************************************************************
    195 // Set up the TIB selector and memory for the main thread 
     198// Set up the TIB selector and memory for the main thread
    196199//******************************************************************************
    197200TEB *WIN32API InitializeMainThread()
     
    240243    ProcessPDB.tls_bits[1]     = 0;
    241244
    242     GetSystemTime(&ProcessPDB.creationTime) ;
     245    GetSystemTime(&ProcessPDB.creationTime);
    243246
    244247    /* Initialize the critical section */
    245     InitializeCriticalSection( &ProcessPDB.crit_section );
     248    InitializeCriticalSection(&ProcessPDB.crit_section );
     249
     250    //initialize the environment db entry.
     251    ProcessPDB.env_db          = &ProcessENVDB;
     252    ProcessENVDB.startup_info  = &StartupInfo;
     253    ProcessENVDB.environ       = GetEnvironmentStringsA();
     254    ProcessENVDB.cmd_line      = (CHAR*)(void*)pszCmdLineA;
     255    ProcessENVDB.cmd_lineW     = (WCHAR*)(void*)pszCmdLineW;
     256    ProcessENVDB.break_handlers = &ProcessConCtrlData;
     257    ProcessConCtrlData.fIgnoreCtrlC = FALSE; /* TODO! Should be inherited from parent. */
     258    ProcessConCtrlData.pHead = ProcessConCtrlData.pTail = (PCONCTRL)malloc(sizeof(CONCTRL));
     259    ProcessConCtrlData.pHead->pfnHandler = (void*)DefaultConsoleCtrlHandler;
     260    ProcessConCtrlData.pHead->pNext = ProcessConCtrlData.pHead->pPrev = NULL;
     261    ProcessConCtrlData.pHead->flFlags = ODIN32_CONCTRL_FLAGS_INIT;
     262    InitializeCriticalSection(&ProcessENVDB.section);
    246263
    247264//         ProcessPDB.startup_info    = &StartupInfo;
    248265    ProcessPDB.unknown10       = (PVOID)&unknownPDBData[0];
    249266    StartupInfo.cb             = sizeof(StartupInfo);
    250     StartupInfo.hStdInput      = GetStdHandle(STD_INPUT_HANDLE);
    251     StartupInfo.hStdOutput    = GetStdHandle(STD_OUTPUT_HANDLE);
    252     StartupInfo.hStdError      = GetStdHandle(STD_ERROR_HANDLE);
     267    ProcessENVDB.hStdin  = StartupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
     268    ProcessENVDB.hStdout = StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     269    ProcessENVDB.hStderr = StartupInfo.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
    253270
    254271    return teb;
     
    295312    SID_IDENTIFIER_AUTHORITY sidIdAuth = {0};
    296313    winteb->o.odin.threadinfo.dwType = SECTYPE_PROCESS | SECTYPE_INITIALIZED;
    297  
     314
    298315    if (NULL != RtlAllocateAndInitializeSid) {
    299316        RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &winteb->o.odin.threadinfo.SidUser.User.Sid);
     
    305322    winteb->o.odin.threadinfo.pTokenGroups = (TOKEN_GROUPS*)malloc(sizeof(TOKEN_GROUPS));
    306323    winteb->o.odin.threadinfo.pTokenGroups->GroupCount = 1;
    307  
     324
    308325    if (NULL != RtlAllocateAndInitializeSid) {
    309326         RtlAllocateAndInitializeSid(&sidIdAuth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &winteb->o.odin.threadinfo.PrimaryGroup.PrimaryGroup);
    310327    }
    311328    else DebugInt3();
    312  
     329
    313330    winteb->o.odin.threadinfo.pTokenGroups->Groups[0].Sid = winteb->o.odin.threadinfo.PrimaryGroup.PrimaryGroup;
    314331    winteb->o.odin.threadinfo.pTokenGroups->Groups[0].Attributes = 0; //????
     
    475492    }
    476493    threadListMutex.leave();
    477  
    478  
     494
     495
    479496#ifdef PROFILE
    480497    // Note: after this point we do not expect any more Win32-API calls,
     
    485502    ProfilerTerminate();
    486503#endif /* PROFILE */
    487  
     504
    488505    //Restore original OS/2 TIB selector
    489506    teb = GetThreadTEB();
     
    12231240         */
    12241241        cch = strlen(pszPeExe)+1;
    1225      
     1242
    12261243        // PH 2002-04-11
    12271244        // Note: intentional memory leak, pszCmdLineW will not be freed
     
    14661483    Win32ImageBase *    pMod;           /* Pointer to the module object. */
    14671484    DWORD               cch = 0;        /* Length of the  */
    1468  
     1485
    14691486    // PH 2002-04-24 Note:
    14701487    // WIN2k just crashes in NTDLL if lpszPath is invalid!
     
    14901507              // write it additionally, uncounted
    14911508              lpszPath[cch] = '\0';
    1492              
     1509
    14931510            memcpy(lpszPath, pszFn, cch);
    14941511        }
     
    16121629        if(WinExe)
    16131630                hMod = WinExe->getInstanceHandle();
    1614         else   
     1631        else
    16151632        {
    16161633          // // Just fail this API
     
    16591676  if (NULL != lpwszModuleName)
    16601677    astring = UnicodeToAsciiString((LPWSTR)lpwszModuleName);
    1661  
     1678
    16621679  rc = GetModuleHandleA(astring);
    16631680  dprintf(("KERNEL32:  OS2GetModuleHandleW %s returned %X\n", astring, rc));
    1664  
     1681
    16651682  if (NULL != astring)
    16661683    FreeAsciiString(astring);
    1667  
     1684
    16681685  return(rc);
    16691686}
     
    18441861      // calculate base length for the new command line
    18451862      iNewCommandLineLength = strlen(szAppName) + strlen(lpCommandLine);
    1846      
     1863
    18471864      if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
    18481865        lpszExecutable = "PEC.EXE";
    18491866      else
    18501867        lpszExecutable = "PE.EXE";
    1851      
     1868
    18521869      lpszPE = lpszExecutable;
    1853      
     1870
    18541871      // 2002-04-24 PH
    18551872      // set the ODIN32.DEBUG_CHILD environment variable to start new PE processes
     
    18641881        strcat(debug_szPE, " ");
    18651882        strcat(debug_szPE, lpszExecutable);
    1866        
     1883
    18671884        // we require more space in the new command line
    18681885        iNewCommandLineLength += strlen( debug_szPE );
    1869        
     1886
    18701887        // only launch the specified executable (ICSDEBUG.EXE)
    18711888        lpszPE = debug_szPE;
     
    18731890      }
    18741891#endif
    1875      
     1892
    18761893        //SvL: Allright. Before we call O32_CreateProcess, we must take care of
    18771894        //     lpCurrentDirectory ourselves. (Open32 ignores it!)
     
    18921909            cmdline = newcmdline;
    18931910        }
    1894      
     1911
    18951912        dprintf(("KERNEL32: CreateProcess starting [%s],[%s]",
    18961913                 lpszExecutable,
    18971914                 cmdline));
    1898      
     1915
    18991916        rc = O32_CreateProcess(lpszExecutable, (LPCSTR)cmdline,lpProcessAttributes,
    19001917                               lpThreadAttributes, bInheritHandles, dwCreationFlags,
     
    19441961        free(cmdline);
    19451962
    1946     if(lpProcessInfo) 
     1963    if(lpProcessInfo)
    19471964    {
    19481965        lpProcessInfo->dwThreadId = MAKE_THREADID(lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId);
     
    20422059  if(fVersionWarp3) {
    20432060        Sleep(1000);
    2044         return 0;       
     2061        return 0;
    20452062  }
    20462063  else  return O32_WaitForInputIdle(hProcess, dwTimeOut);
Note: See TracChangeset for help on using the changeset viewer.