Changeset 1924 for trunk/src


Ignore:
Timestamp:
Dec 1, 1999, 7:40:49 PM (26 years ago)
Author:
sandervl
Message:

added GetProcessTimes + several fixes

Location:
trunk/src/kernel32
Files:
1 added
9 edited

Legend:

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

    r1893 r1924  
    1 /* $Id: Fileio.cpp,v 1.17 1999-11-30 19:40:25 sandervl Exp $ */
     1/* $Id: Fileio.cpp,v 1.18 1999-12-01 18:40:47 sandervl Exp $ */
    22
    33/*
     
    9494  rc = FindFirstFileA(astring, &wfda);
    9595
    96   // convert back the result structure
    97   memcpy(arg2,
    98          &wfda,
    99          sizeof(WIN32_FIND_DATAA));
    100 
    101   lstrcpynAtoW (arg2->cFileName,
    102                 wfda.cFileName,
    103                 sizeof(wfda.cFileName));
    104 
    105   lstrcpynAtoW (arg2->cAlternateFileName,
    106                 wfda.cAlternateFileName,
    107                 sizeof(wfda.cAlternateFileName));
    108 
     96  if(rc == -1) {
     97        memset(arg2, 0, sizeof(WIN32_FIND_DATAW));
     98  }
     99  else {
     100        // convert back the result structure
     101        memcpy(arg2,
     102                 &wfda,
     103                 sizeof(WIN32_FIND_DATAA));
     104       
     105        lstrcpynAtoW (arg2->cFileName,
     106                      wfda.cFileName,
     107                      sizeof(wfda.cFileName));
     108       
     109        lstrcpynAtoW (arg2->cAlternateFileName,
     110                      wfda.cAlternateFileName,
     111                      sizeof(wfda.cAlternateFileName));
     112  }     
    109113  FreeAsciiString(astring);
    110114  return(rc);
     
    119123}
    120124//******************************************************************************
    121 //TODO: convert string in WIN32_FIND_DATAW * structure
    122125//******************************************************************************
    123126ODINFUNCTION2(BOOL, FindNextFileW,
     
    130133  rc = FindNextFileA(arg1, &wfda);
    131134
    132   // convert back the result structure
    133   memcpy(arg2,
    134          &wfda,
    135          sizeof(WIN32_FIND_DATAA));
    136 
    137   lstrcpynAtoW (arg2->cFileName,
    138                 wfda.cFileName,
    139                 sizeof(wfda.cFileName));
    140 
    141   lstrcpynAtoW (arg2->cAlternateFileName,
    142                 wfda.cAlternateFileName,
    143                 sizeof(wfda.cAlternateFileName));
    144 
     135  if(rc == 0) {
     136        memset(arg2, 0, sizeof(WIN32_FIND_DATAW));
     137  }
     138  else {
     139        // convert back the result structure
     140        memcpy(arg2,
     141               &wfda,
     142               sizeof(WIN32_FIND_DATAA));
     143
     144        lstrcpynAtoW (arg2->cFileName,
     145                      wfda.cFileName,
     146                      sizeof(wfda.cFileName));
     147
     148        lstrcpynAtoW (arg2->cAlternateFileName,
     149                      wfda.cAlternateFileName,
     150                      sizeof(wfda.cAlternateFileName));
     151  }
    145152  return rc;
    146153}
  • trunk/src/kernel32/KERNEL32.DEF

    r1885 r1924  
    1 ; $Id: KERNEL32.DEF,v 1.53 1999-11-30 14:15:53 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.54 1999-12-01 18:40:47 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    1919  _DosAliasMem                 =  DOSCALLS.298
    2020   DosQuerySysState            =  DOSCALLS.368
     21  _DosQuerySysState            =  DOSCALLS.368
    2122
    2223  _O32_RegCloseKey             = PMWINX.541
  • trunk/src/kernel32/makefile

    r1885 r1924  
    1 # $Id: makefile,v 1.65 1999-11-30 14:15:54 sandervl Exp $
     1# $Id: makefile,v 1.66 1999-12-01 18:40:48 sandervl Exp $
    22
    33#
     
    9797process.obj: process.cpp \
    9898    $(PDWIN32_INCLUDE)\misc.h \
     99    oslibdos.h \
     100    $(PDWIN32_INCLUDE)\winimagebase.h \
    99101    $(PDWIN32_INCLUDE)\wprocess.h
    100102
  • trunk/src/kernel32/oslibdos.cpp

    r1914 r1924  
    1 /* $Id: oslibdos.cpp,v 1.11 1999-12-01 10:47:51 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.12 1999-12-01 18:40:48 sandervl Exp $ */
    22
    33/*
     
    2323#include "initterm.h"
    2424#include "oslibdos.h"
     25#include "dosqss.h"
    2526
    2627APIRET APIENTRY DosAliasMem(PVOID pb, ULONG cb, PPVOID ppbAlias, ULONG fl);
     
    548549}
    549550//******************************************************************************
    550 //******************************************************************************
     551//Returns time spent in kernel & user mode in milliseconds
     552//******************************************************************************
     553BOOL OSLibDosQueryProcTimes(DWORD procid, ULONG *kerneltime, ULONG *usertime)
     554{
     555 APIRET rc;
     556 char *buf;
     557 ULONG size;
     558 ULONG nrthreads = 4;
     559
     560tryagain:
     561  size = sizeof(QTOPLEVEL)+sizeof(QGLOBAL)+sizeof(QPROCESS) + nrthreads*sizeof(QTHREAD);
     562  buf = (char *)malloc(size);
     563  rc = DosQuerySysState(0x1, RESERVED, procid, RESERVED, (PCHAR)buf, size);
     564
     565  if(rc) {
     566        free(buf);
     567        if(rc == ERROR_BUFFER_OVERFLOW) {
     568                nrthreads += 4;
     569                goto tryagain;
     570        }
     571        return FALSE;
     572  }
     573  PQTOPLEVEL top = (PQTOPLEVEL)buf;
     574
     575  *kerneltime = 0;
     576  *usertime = 0;
     577  for(int i=0;i<top->procdata->threadcnt;i++) {
     578        *kerneltime += top->procdata->threads[i].systime;
     579        *usertime   += top->procdata->threads[i].usertime;
     580  }
     581  free(buf);
     582  return TRUE;
     583}
     584//******************************************************************************
     585//******************************************************************************
  • trunk/src/kernel32/oslibdos.h

    r1811 r1924  
    1 /* $Id: oslibdos.h,v 1.8 1999-11-22 20:35:50 sandervl Exp $ */
     1/* $Id: oslibdos.h,v 1.9 1999-12-01 18:40:48 sandervl Exp $ */
    22
    33/*
     
    9898#endif
    9999
     100void OSLibDosDisableHardError(BOOL fTurnOff);
     101BOOL OSLibDosQueryProcTimes(DWORD procid, ULONG *kerneltime, ULONG *usertime);
     102
    100103#endif
  • trunk/src/kernel32/process.cpp

    r1893 r1924  
    1 /* $Id: process.cpp,v 1.2 1999-11-30 19:40:26 sandervl Exp $ */
     1/* $Id: process.cpp,v 1.3 1999-12-01 18:40:48 sandervl Exp $ */
    22
    33/*
     
    2929#include <win\task.h>
    3030#include <winimagebase.h>
     31#include "oslibdos.h"
    3132
    3233#define SHUTDOWN_NORETRY 1
     
    390391    }
    391392}
    392 //******************************************************************************
    393 //******************************************************************************
     393/*****************************************************************************
     394 * Name      : BOOL GetProcessTimes
     395 * Purpose   : The GetProcessTimes function obtains timing information about a specified process.
     396 * Parameters: HANDLE     hProcess       specifies the process of interest
     397 *             LPFILETIME lpCreationTime when the process was created
     398 *             LPFILETIME lpExitTime     when the process exited
     399 *             LPFILETIME lpKernelTime   time the process has spent in kernel mode
     400 *             LPFILETIME lpUserTime     time the process has spent in user mode
     401 * Variables :
     402 * Result    : TRUE / FALSE
     403 * Remark    :
     404 * Status    : UNTESTED STUB
     405 *
     406 * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
     407 *****************************************************************************/
     408
     409ULONG (WINAPI *NtdllRtlExtendedIntegerMultiply)(LARGE_INTEGER factor1,
     410                                                INT    factor2) = 0;
     411
     412BOOL WIN32API GetProcessTimes(HANDLE     hProcess,
     413                              LPFILETIME lpCreationTime,
     414                              LPFILETIME lpExitTime,
     415                              LPFILETIME lpKernelTime,
     416                              LPFILETIME lpUserTime)
     417{
     418 LARGE_INTEGER *kerneltime, *usertime;
     419
     420  dprintf(("Kernel32: GetProcessTimes(%08xh,%08xh,%08xh,%08xh,%08xh) partly implemented",
     421           hProcess,
     422           lpCreationTime,
     423           lpExitTime,
     424           lpKernelTime,
     425           lpUserTime));
     426
     427  if(!NtdllRtlExtendedIntegerMultiply) {
     428        HINSTANCE hInstance = LoadLibraryA("NTDLL.DLL");
     429        if(hInstance)
     430                *(VOID **)&NtdllRtlExtendedIntegerMultiply=(void*)GetProcAddress(hInstance, (LPCSTR)"RtlExtendedIntegerMultiply");
     431  }
     432  if(!lpCreationTime || !lpExitTime || !lpKernelTime || !lpUserTime) {
     433        SetLastError(ERROR_INVALID_PARAMETER);
     434        return FALSE;
     435  }
     436  if(hProcess != GetCurrentProcess()) {
     437        dprintf(("GetProcessTimes unknown process"));
     438        return FALSE;
     439  }
     440
     441  SystemTimeToFileTime(&ProcessPDB.creationTime, lpCreationTime);
     442  memset(lpExitTime, 0, sizeof(FILETIME));
     443  memset(lpKernelTime, 0, sizeof(FILETIME));
     444  memset(lpUserTime, 0, sizeof(FILETIME));
     445
     446  kerneltime = (LARGE_INTEGER *)lpKernelTime;
     447  usertime   = (LARGE_INTEGER *)lpUserTime;
     448  OSLibDosQueryProcTimes(GetCurrentProcessId(), &lpKernelTime->dwLowDateTime, &lpUserTime->dwLowDateTime);
     449  //TODO: Isn't correct -> (if result's high dword != 0)
     450  kerneltime->u.LowPart = NtdllRtlExtendedIntegerMultiply(*kerneltime, 10);
     451  usertime->u.LowPart   = NtdllRtlExtendedIntegerMultiply(*usertime, 10);
     452  return TRUE;
     453}
     454//******************************************************************************
     455//******************************************************************************
  • trunk/src/kernel32/stubs.cpp

    r1885 r1924  
    1 /* $Id: stubs.cpp,v 1.10 1999-11-30 14:15:54 sandervl Exp $ */
     1/* $Id: stubs.cpp,v 1.11 1999-12-01 18:40:48 sandervl Exp $ */
    22
    33/*
     
    21362136}
    21372137
    2138 /*****************************************************************************
    2139  * Name      : BOOL GetProcessTimes
    2140  * Purpose   : The GetProcessTimes function obtains timing information about a specified process.
    2141  * Parameters: HANDLE     hProcess       specifies the process of interest
    2142  *             LPFILETIME lpCreationTime when the process was created
    2143  *             LPFILETIME lpExitTime     when the process exited
    2144  *             LPFILETIME lpKernelTime   time the process has spent in kernel mode
    2145  *             LPFILETIME lpUserTime     time the process has spent in user mode
    2146  * Variables :
    2147  * Result    : TRUE / FALSE
    2148  * Remark    :
    2149  * Status    : UNTESTED STUB
    2150  *
    2151  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    2152  *****************************************************************************/
    2153 
    2154 BOOL WIN32API GetProcessTimes(HANDLE     hProcess,
    2155                                  LPFILETIME lpCreationTime,
    2156                                  LPFILETIME lpExitTime,
    2157                                  LPFILETIME lpKernelTime,
    2158                                  LPFILETIME lpUserTime)
    2159 {
    2160   dprintf(("Kernel32: GetProcessTimes(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
    2161            hProcess,
    2162            lpCreationTime,
    2163            lpExitTime,
    2164            lpKernelTime,
    2165            lpUserTime));
    2166 
    2167   return (FALSE);
    2168 }
    2169 
    21702138
    21712139
  • trunk/src/kernel32/unicode.cpp

    r1871 r1924  
    1 /* $Id: unicode.cpp,v 1.16 1999-11-28 23:23:46 bird Exp $ */
     1/* $Id: unicode.cpp,v 1.17 1999-12-01 18:40:49 sandervl Exp $ */
    22
    33/*
     
    207207{
    208208  int i;
    209   int rc;
     209  int rc, length;
    210210  size_t uni_chars_left;
    211211  size_t out_bytes_left;
     
    223223
    224224//  dprintf(("KERNEL32: UnicodeToAsciiN\n"));
     225
     226  length = UniStrlen(ustring)+1;
     227  unilen = min(length, unilen);
     228
    225229  if (getUconvObject())
    226230  {
  • trunk/src/kernel32/wprocess.cpp

    r1893 r1924  
    1 /* $Id: wprocess.cpp,v 1.53 1999-11-30 19:40:27 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.54 1999-12-01 18:40:49 sandervl Exp $ */
    22
    33/*
     
    158158        ProcessPDB.winver          = 0xffff; /* to be determined */
    159159        ProcessPDB.server_pid      = (void *)GetCurrentProcessId();
     160
     161        GetSystemTime(&ProcessPDB.creationTime);
    160162
    161163        /* Initialize the critical section */
Note: See TracChangeset for help on using the changeset viewer.