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

Last change on this file since 4562 was 4534, checked in by sandervl, 25 years ago

registry fixes (heap corruption) + VirtualAlloc change

File size: 17.6 KB
Line 
1/* $Id: KERNEL32.CPP,v 1.57 2000-10-26 17:21:38 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 <builtin.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 : BOOL WIN32API CloseHandle
57 * Purpose : forward call to Open32
58 * Parameters:
59 * Variables :
60 * Result :
61 * Remark :
62 * Status :
63 *
64 * Author : Patrick Haller [Fri, 1998/06/12 03:44]
65 *****************************************************************************/
66BOOL WIN32API CloseHandle(HANDLE hHandle)
67{
68 dprintf(("KERNEL32: CloseHandle(%08xh)\n",
69 hHandle));
70
71 return HMCloseHandle(hHandle);
72}
73
74
75//******************************************************************************
76HANDLE WIN32API GetStdHandle(DWORD fdwDevice)
77{
78 HANDLE handle;
79
80 /* @@@PH 1998/02/12 Handle Manager Support */
81 handle = HMGetStdHandle(fdwDevice);
82
83 //@@@PH translate handle
84
85 /* handle = GetStdHandle(fdwDevice); */
86 dprintf(("KERNEL32: GetStdHandle for device %X returned %X\n", fdwDevice, handle));
87 return(handle);
88}
89//******************************************************************************
90//******************************************************************************
91BOOL WIN32API SetStdHandle(DWORD IDStdHandle,
92 HANDLE hHandle)
93{
94 dprintf(("KERNEL32: SetStdHandle\n"));
95
96 ///@@@PH translate handle
97
98 return (HMSetStdHandle(IDStdHandle,
99 hHandle));
100}
101//******************************************************************************
102//******************************************************************************
103BOOL WIN32API IsBadWritePtr(LPVOID lpvPtr, UINT cbBytes)
104{
105#ifdef DEBUG
106 BOOL rc;
107
108 rc = O32_IsBadWritePtr(lpvPtr, cbBytes);
109 dprintf(("KERNEL32: IsBadWritePtr: 0x%X size %d rc = %d\n", (int)lpvPtr, cbBytes, rc));
110 return(rc);
111#else
112 return(O32_IsBadWritePtr(lpvPtr, cbBytes));
113#endif
114}
115//******************************************************************************
116//******************************************************************************
117BOOL WIN32API IsBadReadPtr(CONST VOID *lpvPtr, UINT cbBytes)
118{
119#ifdef DEBUG
120 BOOL rc;
121
122 rc = O32_IsBadReadPtr(lpvPtr, cbBytes);
123 dprintf(("KERNEL32: IsBadReadPtr: 0x%X size %d rc = %d\n", (int)lpvPtr, cbBytes, rc));
124 return(rc);
125#else
126 return(O32_IsBadReadPtr(lpvPtr, cbBytes));
127#endif
128}
129//******************************************************************************
130//******************************************************************************
131BOOL WIN32API IsBadCodePtr( FARPROC arg1)
132{
133 dprintf(("KERNEL32: IsBadCodePtr\n"));
134 return O32_IsBadCodePtr(arg1);
135}
136//******************************************************************************
137//******************************************************************************
138BOOL WIN32API IsBadStringPtrA( LPCSTR arg1, UINT arg2)
139{
140 dprintf(("KERNEL32: IsBadStringPtr"));
141 return O32_IsBadStringPtr(arg1, arg2);
142}
143//******************************************************************************
144//******************************************************************************
145BOOL WIN32API IsBadStringPtrW(LPCWSTR arg1, UINT arg2)
146{
147 dprintf(("KERNEL32: OS2IsBadStringPtrW"));
148 return O32_IsBadReadPtr((CONST VOID *)arg1, arg2*2+2);
149}
150//******************************************************************************
151//******************************************************************************
152DWORD WIN32API GetLastError()
153{
154 DWORD rc;
155
156 rc = O32_GetLastError();
157 if(rc) {
158 dprintf2(("KERNEL32: GetLastError returned %d\n", rc));
159 }
160 return(rc);
161}
162//******************************************************************************
163//******************************************************************************
164VOID WIN32API SetLastError( DWORD dwError)
165{
166 if(dwError != 0) {
167 dprintf2(("KERNEL32: SetLastError to %d\n", dwError));
168 }
169 O32_SetLastError(dwError);
170}
171//******************************************************************************
172//******************************************************************************
173UINT WIN32API GetOEMCP(VOID)
174{
175 dprintf(("KERNEL32: GetOEMCP\n"));
176 return(O32_GetOEMCP());
177}
178//******************************************************************************
179//******************************************************************************
180ODINFUNCTION0(UINT, GetACP)
181{
182 return(O32_GetACP());
183}
184//******************************************************************************
185//******************************************************************************
186
187/*
188 * PH 2000/09/25 This is an experiment to overcome some problems
189 * with Open32's GMS variant.
190 */
191void _GlobalMemoryStatus(MEMORYSTATUS *lpMemStat)
192{
193 ULONG sys[5];
194 // Note: QSV_TOTPHYSMEM = 17, QSV_MAXSHMEM = 21
195 lpMemStat->dwLength = sizeof(MEMORYSTATUS);
196
197 if(!OSLibDosQuerySysInfo( 17, 21, (PVOID)sys, sizeof(sys)))
198 {
199 // Specified a number between 0 and 100 that gives a general idea of
200 // current memory utilization, in which 0 indicates no memory use and
201 // 100 indicates full memory use
202
203 //#define MB512 0x1c000000
204 //lpMemStat->dwMemoryLoad = (MB512-sys[20]) * 100 / MB512;
205 lpMemStat->dwMemoryLoad = (sys[1] * 100) / sys[0];
206
207 // bytes of physical memory
208 lpMemStat->dwTotalPhys = sys[0];
209
210 // free physical memory bytes
211 lpMemStat->dwAvailPhys = sys[0] - sys[1];
212
213 // bytes of paging file
214 // @@@PH add swapper.dat size?
215 lpMemStat->dwTotalPageFile = sys[2];
216
217 // free bytes of paging file
218 lpMemStat->dwAvailPageFile = sys[2];
219
220 // user bytes of address space
221 lpMemStat->dwTotalVirtual = max(sys[2], sys[3]);
222 lpMemStat->dwAvailVirtual = min(sys[2], sys[3]);
223 }
224}
225
226
227
228VOID WIN32API GlobalMemoryStatus(MEMORYSTATUS *arg1)
229{
230 dprintf(("KERNEL32: GlobalMemoryStatus\n"));
231 //O32_GlobalMemoryStatus(arg1);
232 _GlobalMemoryStatus(arg1);
233 dprintf(("dwMemoryLoad %X\n", arg1->dwMemoryLoad));
234 dprintf(("dwTotalPhys %X\n", arg1->dwTotalPhys));
235 dprintf(("dwAvailPhys %X\n", arg1->dwAvailPhys));
236 dprintf(("dwTotalPageFile %X\n", arg1->dwTotalPageFile));
237 dprintf(("dwAvailPageFile %X\n", arg1->dwAvailPageFile));
238 dprintf(("dwTotalVirtual %X\n", arg1->dwTotalVirtual));
239 dprintf(("dwAvailVirtual %X\n", arg1->dwAvailVirtual));
240}
241VOID WIN32API Sleep(DWORD arg1)
242{
243 dprintf2(("KERNEL32: Sleep %d\n", arg1));
244 O32_Sleep(arg1);
245}
246//******************************************************************************
247//******************************************************************************
248DWORD WIN32API GetPriorityClass(HANDLE arg1)
249{
250 dprintf(("KERNEL32: GetPriorityClass\n"));
251 return O32_GetPriorityClass(arg1);
252}
253//******************************************************************************
254//******************************************************************************
255BOOL WIN32API SetPriorityClass(HANDLE arg1, DWORD arg2)
256{
257 dprintf(("KERNEL32: SetPriorityClass\n"));
258 return O32_SetPriorityClass(arg1, arg2);
259}
260//******************************************************************************
261//******************************************************************************
262BOOL WIN32API Beep( DWORD arg1, DWORD arg2)
263{
264 dprintf(("KERNEL32: OS2Beep\n"));
265 return O32_Beep(arg1, arg2);
266}
267//******************************************************************************
268//******************************************************************************
269VOID WIN32API FatalAppExitA( UINT arg1, LPCSTR arg2)
270{
271 dprintf(("KERNEL32: OS2FatalAppExitA\n"));
272 O32_FatalAppExit(arg1, arg2);
273}
274//******************************************************************************
275//******************************************************************************
276VOID WIN32API FatalAppExitW(UINT arg1, LPCWSTR arg2)
277{
278 char *astring;
279
280 dprintf(("KERNEL32: OS2FatalAppExitW\n"));
281 astring = UnicodeToAsciiString((LPWSTR)arg2);
282 O32_FatalAppExit(arg1, astring);
283 //probably won't return, but who cares..
284 FreeAsciiString(astring);
285}
286//******************************************************************************
287//******************************************************************************
288VOID WIN32API FatalExit( UINT arg1)
289{
290 dprintf(("KERNEL32: OS2FatalExit\n"));
291 O32_FatalExit(arg1);
292}
293//******************************************************************************
294//******************************************************************************
295BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT arg2)
296{
297 dprintf(("KERNEL32: OS2IsBadHugeReadPtr\n"));
298 return O32_IsBadHugeReadPtr(arg1, arg2);
299}
300//******************************************************************************
301//******************************************************************************
302BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT arg2)
303{
304 dprintf(("KERNEL32: OS2IsBadHugeWritePtr\n"));
305 return O32_IsBadHugeWritePtr(arg1, arg2);
306}
307//******************************************************************************
308//******************************************************************************
309BOOL WIN32API IsDBCSLeadByte(BYTE arg1)
310{
311 dprintf2(("KERNEL32: OS2IsDBCSLeadByte\n"));
312 return O32_IsDBCSLeadByte(arg1);
313}
314//******************************************************************************
315//******************************************************************************
316int WIN32API MulDiv(int arg1, int arg2, int arg3)
317{
318 dprintf2(("KERNEL32: MulDiv %d*%d/%d\n", arg1, arg2, arg3));
319 if(arg3 == 0)
320 return 0;
321
322 return O32_MulDiv(arg1, arg2, arg3);
323}
324//******************************************************************************
325//Borrowed from Wine
326//******************************************************************************
327ODINPROCEDURE1(GetStartupInfoA,LPSTARTUPINFOA,lpStartupInfo)
328{
329 lpStartupInfo->cb = sizeof(STARTUPINFOA);
330 lpStartupInfo->lpReserved = "<Reserved>";
331 lpStartupInfo->lpDesktop = "Desktop";
332 lpStartupInfo->lpTitle = "Title";
333 lpStartupInfo->dwX = 0;
334 lpStartupInfo->dwY = 0;
335 lpStartupInfo->dwXSize = 640;
336 lpStartupInfo->dwYSize = 480;
337 lpStartupInfo->dwXCountChars = 80; // for console
338 lpStartupInfo->dwYCountChars = 25;
339 lpStartupInfo->dwFillAttribute = 0x0720;
340 lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW |
341 STARTF_USEPOSITION |
342 STARTF_USESIZE |
343 STARTF_USECOUNTCHARS |
344 STARTF_USEFILLATTRIBUTE|
345 STARTF_USESTDHANDLES;
346 lpStartupInfo->wShowWindow = SW_SHOWDEFAULT;
347 lpStartupInfo->cbReserved2 = 0;
348 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
349 /* @@@PH 98/07/13 Handlemanager support */
350 lpStartupInfo->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
351 lpStartupInfo->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
352 lpStartupInfo->hStdError = GetStdHandle(STD_ERROR_HANDLE);
353 return;
354}
355//******************************************************************************
356//Borrowed from Wine
357//******************************************************************************
358ODINPROCEDURE1(GetStartupInfoW,LPSTARTUPINFOW,lpStartupInfo)
359{
360 static WCHAR lpReserved[] = {'<', 'R','e','s','e','r','v','e','d','>', 0};
361 static WCHAR lpDesktop[] = {'D', 'e','s','k','t','o','p', 0};
362 static WCHAR lpTitle[] = {'T', 'i','t','l','e', 0};
363
364 // forward call to ascii variant
365 GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo);
366 lpStartupInfo->cb = sizeof(STARTUPINFOW);
367 lpStartupInfo->lpReserved = lpReserved;
368 lpStartupInfo->lpDesktop = lpDesktop;
369 lpStartupInfo->lpTitle = lpTitle;
370 return;
371}
372//******************************************************************************
373//TODO: Not complete or correct, but sufficient for now
374//******************************************************************************
375BOOL WIN32API GetBinaryTypeA(LPCTSTR lpApplicationName, LPDWORD lpBinaryType)
376{
377 dprintf(("KERNEL32: OS2GetBinaryTypeA %s\n", lpApplicationName));
378 if(strstr(lpApplicationName, ".EXE") || strstr(lpApplicationName, ".exe"))
379 *lpBinaryType = SCS_32BIT_BINARY;
380 else
381 if(strstr(lpApplicationName, ".COM") || strstr(lpApplicationName, ".com"))
382 *lpBinaryType = SCS_DOS_BINARY;
383 else
384 if(strstr(lpApplicationName, ".PIF") || strstr(lpApplicationName, ".pif"))
385 *lpBinaryType = SCS_PIF_BINARY;
386 else return(FALSE);
387 return(TRUE);
388}
389//******************************************************************************
390//******************************************************************************
391BOOL WIN32API GetBinaryTypeW(LPCWSTR lpApplicationName, LPDWORD lpBinaryType)
392{
393 BOOL rc;
394 char *astring;
395
396 dprintf(("KERNEL32: OS2GetBinaryTypeW\n"));
397 astring = UnicodeToAsciiString((LPWSTR)lpApplicationName);
398 rc = GetBinaryTypeA(astring, lpBinaryType);
399 FreeAsciiString(astring);
400 return(rc);
401}
402//******************************************************************************
403//******************************************************************************
404BOOL WIN32API FlushInstructionCache( /*PLF Mon 98-02-09 23:56:49 : STUB STUB STUB STUB STUB */
405 HANDLE hProcess, /* process with cache to flush */
406 LPCVOID lpvBase, /* address of region to flush */
407 DWORD cbFlush) /* length of region to flush */
408
409{
410 dprintf(("FlushInstructionCache() - NIY\n"));
411 return TRUE;
412}
413
414
415//******************************************************************************
416
417/***********************************************************************
418* RtlFillMemory (KERNEL32.441)
419*/
420VOID WIN32API RtlFillMemory(LPVOID ptr,
421 UINT len,
422 UINT fill )
423{
424#ifdef DEBUG_LOCAL
425 dprintf(("KERNEL32: RtlFillMemory(%08x,%08x,%08x)\n",
426 ptr,
427 len,
428 fill));
429#endif
430
431 memset(ptr,
432 fill,
433 len );
434}
435
436
437/***********************************************************************
438* RtlMoveMemory (KERNEL32.442)
439*/
440VOID WIN32API RtlMoveMemory(LPVOID dst,
441 LPCVOID src,
442 UINT len )
443{
444 dprintf2(("KERNEL32: RtlMoveMemory(%08x,%08x,%08x)\n",
445 dst,
446 src,
447 len));
448
449 memmove(dst,
450 src,
451 len );
452}
453
454
455/***********************************************************************
456* RtlZeroMemory (KERNEL32.444)
457*/
458VOID WIN32API RtlZeroMemory(LPVOID ptr,
459 UINT len)
460{
461 dprintf2(("KERNEL32: RtlZeroMemory(%08x,%08x)\n",
462 ptr,
463 len));
464
465 memset(ptr,
466 0,
467 len);
468}
469
470//******************************************************************************
471/*KSO Thu 21.05.1998*/
472BOOL WIN32API IsDBCSLeadByteEx(UINT CodePage, BYTE TestChar)
473{
474 dprintf(("KERNEL32: OS2IsDBCSLeadByteEx - not correctly implemented\n"));
475 return O32_IsDBCSLeadByte(TestChar);
476}
477//******************************************************************************
478
479
480
481
482
483
484
485
486/*****************************************************************************
487 * Name : BOOL GetSystemPowerStatus
488 * Purpose : The GetSystemPowerStatus function retrieves the power status of
489 * the system. The status indicates whether the system is running
490 * on AC or DC power, whether the battery is currently charging,
491 * and how much battery life currently remains.
492 * Parameters: LPSYSTEM_POWER_STATUS lpSystemPowerStatus
493 * Variables :
494 * Result : TRUE / FALSE
495 * Remark :
496 * Status : UNTESTED STUB
497 *
498 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
499 *****************************************************************************/
500
501BOOL WIN32API GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus)
502{
503 dprintf(("Kernel32: GetSystemPowerStatus(%08xh) not properly implemented.\n",
504 lpSystemPowerStatus));
505
506 if(lpSystemPowerStatus == NULL) {
507 SetLastError(ERROR_INVALID_PARAMETER);
508 return FALSE;
509 }
510 lpSystemPowerStatus->ACLineStatus = 1; //online
511 lpSystemPowerStatus->BatteryFlag = 128; //no system battery
512 lpSystemPowerStatus->BatteryLifePercent = 255; //unknown
513 lpSystemPowerStatus->reserved = 0;
514 lpSystemPowerStatus->BatteryLifeTime = -1; //unknown
515 lpSystemPowerStatus->BatteryFullLifeTime= -1; //unknown
516
517 return TRUE;
518}
Note: See TracBrowser for help on using the repository browser.