source: trunk/src/kernel32/KERNEL32.CPP@ 9752

Last change on this file since 9752 was 9653, checked in by sandervl, 23 years ago

implemented Get/SetHandleInformation; CloseHandle change for HANDLE_FLAG_PROTECT_FROM_CLOSE; inheritance support added to DuplicateHandle

File size: 16.9 KB
Line 
1/* $Id: KERNEL32.CPP,v 1.73 2003-01-10 12:57:12 sandervl Exp $ */
2
3/*
4 * Win32 compatibility file functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
7 * Copyright 1998 Patrick Haller
8 * Copyright 1998 Peter Fitzsimmons
9 * Copyright 1998 Knut St. Osmundsen
10 *
11 * @(#) KERNEL32.CPP 1.0.1 1998/06/12 PH added HandleManager support
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16
17
18/*****************************************************************************
19 * Includes *
20 *****************************************************************************/
21
22#include <odin.h>
23#include <odinwrap.h>
24#include <os2sel.h>
25
26#include <os2win.h>
27#include <winnt.h>
28#include <winnls.h>
29#include <stdlib.h>
30#include <string.h>
31#include <ctype.h>
32
33#include <misc.h>
34#include <unicode.h>
35#include "heap.h"
36#include "handlemanager.h"
37#include "wprocess.h"
38#include "oslibdos.h"
39#include <versionos2.h>
40
41#define DBG_LOCALLOG DBG_kernel32
42#include "dbglocal.h"
43
44/*****************************************************************************
45 * Defines *
46 *****************************************************************************/
47
48ODINDEBUGCHANNEL(KERNEL32-KERNEL32)
49
50 /* this define enables certain less important debug messages */
51//#define DEBUG_LOCAL 1
52
53
54
55/*****************************************************************************
56 * Name : DWORD GetHandleInformation
57 * Purpose : The GetHandleInformation function obtains information about certain
58 * properties of an object handle. The information is obtained as a set of bit flags.
59 * Parameters: HANDLE hObject
60 * LPDWORD lpdwFlags
61 * Variables :
62 * Result : TRUE / FALSE
63 * Remark :
64 * Status :
65 *
66 * Author : SvL
67 *****************************************************************************/
68
69BOOL WIN32API GetHandleInformation(HANDLE hObject,
70 LPDWORD lpdwFlags)
71{
72 return HMGetHandleInformation(hObject, lpdwFlags);
73}
74
75/*****************************************************************************
76 * Name : BOOL SetHandleInformation
77 * Purpose : The SetHandleInformation function sets certain properties of an
78 * object handle. The information is specified as a set of bit flags.
79 * Parameters: HANDLE hObject handle to an object
80 * DWORD dwMask specifies flags to change
81 * DWORD dwFlags specifies new values for flags
82 * Variables :
83 * Result : TRUE / FALSE
84 * Remark :
85 * Status :
86 *
87 * Author : SvL
88 *****************************************************************************/
89
90BOOL WIN32API SetHandleInformation(HANDLE hObject,
91 DWORD dwMask,
92 DWORD dwFlags)
93{
94 return HMSetHandleInformation(hObject, dwMask, dwFlags);
95}
96/*****************************************************************************
97 * Name : BOOL WIN32API CloseHandle
98 * Purpose : forward call to Open32
99 * Parameters:
100 * Variables :
101 * Result :
102 * Remark :
103 * Status :
104 *
105 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
106 *****************************************************************************/
107BOOL WIN32API CloseHandle(HANDLE hHandle)
108{
109 dprintf(("KERNEL32: CloseHandle(%08xh)\n",
110 hHandle));
111
112 return HMCloseHandle(hHandle);
113}
114
115
116//******************************************************************************
117HANDLE WIN32API GetStdHandle(DWORD fdwDevice)
118{
119 HANDLE handle;
120
121 /* @@@PH 1998/02/12 Handle Manager Support */
122 handle = HMGetStdHandle(fdwDevice);
123
124 //@@@PH translate handle
125
126 /* handle = GetStdHandle(fdwDevice); */
127 dprintf(("KERNEL32: GetStdHandle for device %X returned %X\n", fdwDevice, handle));
128 return(handle);
129}
130//******************************************************************************
131//******************************************************************************
132BOOL WIN32API SetStdHandle(DWORD IDStdHandle,
133 HANDLE hHandle)
134{
135 dprintf(("KERNEL32: SetStdHandle\n"));
136
137 ///@@@PH translate handle
138
139 return (HMSetStdHandle(IDStdHandle,
140 hHandle));
141}
142//******************************************************************************
143//******************************************************************************
144BOOL WIN32API IsBadWritePtr(LPVOID lpvPtr, UINT cbBytes)
145{
146#ifdef DEBUG
147 BOOL rc;
148
149 rc = O32_IsBadWritePtr(lpvPtr, cbBytes);
150 dprintf(("KERNEL32: IsBadWritePtr: 0x%X size %d rc = %d\n", (int)lpvPtr, cbBytes, rc));
151 return(rc);
152#else
153 return(O32_IsBadWritePtr(lpvPtr, cbBytes));
154#endif
155}
156//******************************************************************************
157//******************************************************************************
158BOOL WIN32API IsBadReadPtr(CONST VOID *lpvPtr, UINT cbBytes)
159{
160#ifdef DEBUG
161 BOOL rc;
162
163 rc = O32_IsBadReadPtr(lpvPtr, cbBytes);
164 dprintf(("KERNEL32: IsBadReadPtr: 0x%X size %d rc = %d\n", (int)lpvPtr, cbBytes, rc));
165 return(rc);
166#else
167 return(O32_IsBadReadPtr(lpvPtr, cbBytes));
168#endif
169}
170//******************************************************************************
171//******************************************************************************
172BOOL WIN32API IsBadCodePtr(FARPROC pCode)
173{
174 dprintf(("KERNEL32: IsBadCodePtr %x", pCode));
175 return O32_IsBadCodePtr(pCode);
176}
177//******************************************************************************
178//******************************************************************************
179BOOL WIN32API IsBadStringPtrA( LPCSTR arg1, UINT arg2)
180{
181 dprintf(("KERNEL32: IsBadStringPtr"));
182 return O32_IsBadStringPtr(arg1, arg2);
183}
184//******************************************************************************
185//******************************************************************************
186BOOL WIN32API IsBadStringPtrW(LPCWSTR arg1, UINT arg2)
187{
188 dprintf(("KERNEL32: OS2IsBadStringPtrW"));
189 return O32_IsBadReadPtr((CONST VOID *)arg1, arg2*2+2);
190}
191//******************************************************************************
192//******************************************************************************
193DWORD WIN32API GetLastError()
194{
195 DWORD rc;
196
197 rc = O32_GetLastError();
198 if(rc) {
199 dprintf(("KERNEL32: GetLastError returned %d\n", rc));
200 }
201 else dprintf(("KERNEL32: GetLastError returned no error\n", rc));
202 return(rc);
203}
204//******************************************************************************
205//******************************************************************************
206VOID WIN32API SetLastError( DWORD dwError)
207{
208 if(dwError != 0) {
209 dprintf(("KERNEL32: SetLastError to %d\n", dwError));
210 }
211 O32_SetLastError(dwError);
212}
213//******************************************************************************
214//******************************************************************************
215/*
216 * PH 2000/09/25 This is an experiment to overcome some problems
217 * with Open32's GMS variant.
218 */
219void _GlobalMemoryStatus(MEMORYSTATUS *lpMemStat)
220{
221 ULONG sys[5];
222 // Note: QSV_TOTPHYSMEM = 17, QSV_MAXSHMEM = 21
223 lpMemStat->dwLength = sizeof(MEMORYSTATUS);
224
225 if(!OSLibDosQuerySysInfo( 17, 21, (PVOID)sys, sizeof(sys)))
226 {
227 // Specified a number between 0 and 100 that gives a general idea of
228 // current memory utilization, in which 0 indicates no memory use and
229 // 100 indicates full memory use
230
231 //#define MB512 0x1c000000
232 //lpMemStat->dwMemoryLoad = (MB512-sys[20]) * 100 / MB512;
233 lpMemStat->dwMemoryLoad = (sys[1] * 100) / sys[0];
234
235 // bytes of physical memory
236 lpMemStat->dwTotalPhys = sys[0];
237
238 // free physical memory bytes
239 lpMemStat->dwAvailPhys = sys[0] - sys[1];
240
241 // bytes of paging file
242 // @@@PH add swapper.dat size?
243 // SvL: Some stupid apps interpret this as a signed long
244 lpMemStat->dwTotalPageFile = (sys[2] > 0x80000000) ? 0x7fffffff : sys[2];
245
246 // free bytes of paging file
247 lpMemStat->dwAvailPageFile = (sys[2] > 0x80000000) ? 0x7fffffff : sys[2];
248
249 // user bytes of address space
250 lpMemStat->dwTotalVirtual = max(lpMemStat->dwTotalPageFile, sys[3]);
251 lpMemStat->dwAvailVirtual = min(lpMemStat->dwAvailPageFile, sys[3]);
252 }
253}
254
255
256
257VOID WIN32API GlobalMemoryStatus(MEMORYSTATUS *arg1)
258{
259 dprintf(("KERNEL32: GlobalMemoryStatus\n"));
260 //O32_GlobalMemoryStatus(arg1);
261 _GlobalMemoryStatus(arg1);
262 dprintf(("dwMemoryLoad %X\n", arg1->dwMemoryLoad));
263 dprintf(("dwTotalPhys %X\n", arg1->dwTotalPhys));
264 dprintf(("dwAvailPhys %X\n", arg1->dwAvailPhys));
265 dprintf(("dwTotalPageFile %X\n", arg1->dwTotalPageFile));
266 dprintf(("dwAvailPageFile %X\n", arg1->dwAvailPageFile));
267 dprintf(("dwTotalVirtual %X\n", arg1->dwTotalVirtual));
268 dprintf(("dwAvailVirtual %X\n", arg1->dwAvailVirtual));
269}
270//******************************************************************************
271//******************************************************************************
272BOOL WIN32API Beep( DWORD arg1, DWORD arg2)
273{
274 dprintf(("KERNEL32: Beep %d %d", arg1, arg2));
275 return OSLibDosBeep(arg1, arg2);
276}
277//******************************************************************************
278//******************************************************************************
279
280typedef INT (WINAPI *MessageBoxA_funcptr)(HWND,LPCSTR,LPCSTR,UINT);
281typedef INT (WINAPI *MessageBoxW_funcptr)(HWND,LPCWSTR,LPCWSTR,UINT);
282
283//******************************************************************************
284//******************************************************************************
285VOID WIN32API FatalAppExitA( UINT exitCode, LPCSTR str)
286{
287 HMODULE mod = GetModuleHandleA( "user32.dll" );
288 MessageBoxA_funcptr pMessageBoxA = NULL;
289
290 dprintf(("KERNEL32: FatalAppExitA %d %s", exitCode, str));
291
292 if (mod) pMessageBoxA = (MessageBoxA_funcptr)GetProcAddress( mod, "MessageBoxA" );
293 if(pMessageBoxA) pMessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
294
295 ExitProcess(exitCode);
296}
297//******************************************************************************
298//******************************************************************************
299VOID WIN32API FatalAppExitW(UINT exitCode, LPCWSTR str)
300{
301 HMODULE mod = GetModuleHandleA( "user32.dll" );
302 MessageBoxW_funcptr pMessageBoxW = NULL;
303
304 dprintf(("KERNEL32: FatalAppExitW %d %ls", exitCode, str));
305
306 if (mod) pMessageBoxW = (MessageBoxW_funcptr)GetProcAddress( mod, "MessageBoxW" );
307 if(pMessageBoxW) pMessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
308
309 ExitProcess(exitCode);
310}
311//******************************************************************************
312//******************************************************************************
313VOID WIN32API FatalExit( UINT exitCode)
314{
315 dprintf(("KERNEL32: FatalExit %x", exitCode));
316 ExitProcess(exitCode);
317}
318//******************************************************************************
319//******************************************************************************
320BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT arg2)
321{
322 return IsBadReadPtr(arg1, arg2);
323}
324//******************************************************************************
325//******************************************************************************
326BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT arg2)
327{
328 return IsBadWritePtr(arg1, arg2);
329}
330//******************************************************************************
331//******************************************************************************
332int WIN32API MulDiv(int arg1, int arg2, int arg3)
333{
334 dprintf2(("KERNEL32: MulDiv %d*%d/%d\n", arg1, arg2, arg3));
335 if(arg3 == 0)
336 return 0;
337
338 return O32_MulDiv(arg1, arg2, arg3);
339}
340//******************************************************************************
341//Borrowed from Wine
342//******************************************************************************
343void WIN32API GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)
344{
345 lpStartupInfo->cb = sizeof(STARTUPINFOA);
346 lpStartupInfo->lpReserved = "<Reserved>";
347 lpStartupInfo->lpDesktop = "Desktop";
348 lpStartupInfo->lpTitle = "Title";
349 lpStartupInfo->dwX = 0;
350 lpStartupInfo->dwY = 0;
351 lpStartupInfo->dwXSize = 640;
352 lpStartupInfo->dwYSize = 480;
353 lpStartupInfo->dwXCountChars = 80; // for console
354 lpStartupInfo->dwYCountChars = 25;
355 lpStartupInfo->dwFillAttribute = 0x0720;
356 lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW |
357 STARTF_USEPOSITION |
358 STARTF_USESIZE |
359 STARTF_USECOUNTCHARS |
360 STARTF_USEFILLATTRIBUTE|
361 STARTF_USESTDHANDLES;
362 lpStartupInfo->wShowWindow = SW_SHOWDEFAULT;
363 lpStartupInfo->cbReserved2 = 0;
364 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
365 lpStartupInfo->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
366 lpStartupInfo->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
367 lpStartupInfo->hStdError = GetStdHandle(STD_ERROR_HANDLE);
368 return;
369}
370//******************************************************************************
371//Borrowed from Wine
372//******************************************************************************
373void WIN32API GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo)
374{
375 static WCHAR lpReserved[] = {'<', 'R','e','s','e','r','v','e','d','>', 0};
376 static WCHAR lpDesktop[] = {'D', 'e','s','k','t','o','p', 0};
377 static WCHAR lpTitle[] = {'T', 'i','t','l','e', 0};
378
379 // forward call to ascii variant
380 GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo);
381 lpStartupInfo->cb = sizeof(STARTUPINFOW);
382 lpStartupInfo->lpReserved = lpReserved;
383 lpStartupInfo->lpDesktop = lpDesktop;
384 lpStartupInfo->lpTitle = lpTitle;
385 return;
386}
387//******************************************************************************
388//******************************************************************************
389BOOL WIN32API FlushInstructionCache( /*PLF Mon 98-02-09 23:56:49 : STUB STUB STUB STUB STUB */
390 HANDLE hProcess, /* process with cache to flush */
391 LPCVOID lpvBase, /* address of region to flush */
392 DWORD cbFlush) /* length of region to flush */
393
394{
395 dprintf(("FlushInstructionCache() - NIY\n"));
396 return TRUE;
397}
398
399
400//******************************************************************************
401
402/***********************************************************************
403* RtlFillMemory (KERNEL32.441)
404*/
405VOID WIN32API RtlFillMemory(LPVOID ptr,
406 UINT len,
407 UINT fill )
408{
409#ifdef DEBUG_LOCAL
410 dprintf(("KERNEL32: RtlFillMemory(%08x,%08x,%08x)\n",
411 ptr,
412 len,
413 fill));
414#endif
415
416 memset(ptr,
417 fill,
418 len );
419}
420
421
422/***********************************************************************
423* RtlMoveMemory (KERNEL32.442)
424*/
425VOID WIN32API RtlMoveMemory(LPVOID dst,
426 LPCVOID src,
427 UINT len )
428{
429 dprintf2(("KERNEL32: RtlMoveMemory(%08x,%08x,%08x)\n",
430 dst,
431 src,
432 len));
433
434 memmove(dst,
435 src,
436 len );
437}
438
439
440/***********************************************************************
441* RtlZeroMemory (KERNEL32.444)
442*/
443VOID WIN32API RtlZeroMemory(LPVOID ptr,
444 UINT len)
445{
446 dprintf2(("KERNEL32: RtlZeroMemory(%08x,%08x)\n",
447 ptr,
448 len));
449
450 memset(ptr,
451 0,
452 len);
453}
454
455//******************************************************************************
456
457
458
459
460
461
462
463
464/*****************************************************************************
465 * Name : BOOL GetSystemPowerStatus
466 * Purpose : The GetSystemPowerStatus function retrieves the power status of
467 * the system. The status indicates whether the system is running
468 * on AC or DC power, whether the battery is currently charging,
469 * and how much battery life currently remains.
470 * Parameters: LPSYSTEM_POWER_STATUS lpSystemPowerStatus
471 * Variables :
472 * Result : TRUE / FALSE
473 * Remark :
474 * Status : UNTESTED STUB
475 *
476 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
477 *****************************************************************************/
478
479BOOL WIN32API GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus)
480{
481 dprintf(("Kernel32: GetSystemPowerStatus(%08xh) not properly implemented.\n",
482 lpSystemPowerStatus));
483
484 if(lpSystemPowerStatus == NULL) {
485 SetLastError(ERROR_INVALID_PARAMETER);
486 return FALSE;
487 }
488 lpSystemPowerStatus->ACLineStatus = AC_LINE_ONLINE;
489 lpSystemPowerStatus->BatteryFlag = BATTERY_FLAG_HIGH;
490 lpSystemPowerStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
491 lpSystemPowerStatus->Reserved1 = 0;
492 lpSystemPowerStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
493 lpSystemPowerStatus->BatteryFullLifeTime= BATTERY_LIFE_UNKNOWN;
494
495 return TRUE;
496}
Note: See TracBrowser for help on using the repository browser.