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

Last change on this file since 5308 was 5308, checked in by sandervl, 24 years ago

removed builtin.h include + initterm update

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