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

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

thread handler call workaround for app bugs + GetBinaryTypeA/W port

File size: 15.5 KB
Line 
1/* $Id: KERNEL32.CPP,v 1.60 2001-03-22 18:16:40 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}
240BOOL WIN32API Beep( DWORD arg1, DWORD arg2)
241{
242 dprintf(("KERNEL32: OS2Beep\n"));
243 return O32_Beep(arg1, arg2);
244}
245//******************************************************************************
246//******************************************************************************
247VOID WIN32API FatalAppExitA( UINT arg1, LPCSTR arg2)
248{
249 dprintf(("KERNEL32: OS2FatalAppExitA\n"));
250 O32_FatalAppExit(arg1, arg2);
251}
252//******************************************************************************
253//******************************************************************************
254VOID WIN32API FatalAppExitW(UINT arg1, LPCWSTR arg2)
255{
256 char *astring;
257
258 dprintf(("KERNEL32: OS2FatalAppExitW %x", arg1));
259 astring = UnicodeToAsciiString((LPWSTR)arg2);
260 O32_FatalAppExit(arg1, astring);
261 //probably won't return, but who cares..
262 FreeAsciiString(astring);
263}
264//******************************************************************************
265//******************************************************************************
266VOID WIN32API FatalExit( UINT arg1)
267{
268 dprintf(("KERNEL32: FatalExit %x", arg1));
269 O32_FatalExit(arg1);
270}
271//******************************************************************************
272//******************************************************************************
273BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT arg2)
274{
275 dprintf(("KERNEL32: OS2IsBadHugeReadPtr\n"));
276 return O32_IsBadHugeReadPtr(arg1, arg2);
277}
278//******************************************************************************
279//******************************************************************************
280BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT arg2)
281{
282 dprintf(("KERNEL32: IsBadHugeWritePtr\n"));
283 return O32_IsBadHugeWritePtr(arg1, arg2);
284}
285//******************************************************************************
286//******************************************************************************
287BOOL WIN32API IsDBCSLeadByte(BYTE arg1)
288{
289 dprintf2(("KERNEL32: IsDBCSLeadByte %x", arg1));
290 return O32_IsDBCSLeadByte(arg1);
291}
292//******************************************************************************
293//******************************************************************************
294int WIN32API MulDiv(int arg1, int arg2, int arg3)
295{
296 dprintf2(("KERNEL32: MulDiv %d*%d/%d\n", arg1, arg2, arg3));
297 if(arg3 == 0)
298 return 0;
299
300 return O32_MulDiv(arg1, arg2, arg3);
301}
302//******************************************************************************
303//Borrowed from Wine
304//******************************************************************************
305ODINPROCEDURE1(GetStartupInfoA,LPSTARTUPINFOA,lpStartupInfo)
306{
307 lpStartupInfo->cb = sizeof(STARTUPINFOA);
308 lpStartupInfo->lpReserved = "<Reserved>";
309 lpStartupInfo->lpDesktop = "Desktop";
310 lpStartupInfo->lpTitle = "Title";
311 lpStartupInfo->dwX = 0;
312 lpStartupInfo->dwY = 0;
313 lpStartupInfo->dwXSize = 640;
314 lpStartupInfo->dwYSize = 480;
315 lpStartupInfo->dwXCountChars = 80; // for console
316 lpStartupInfo->dwYCountChars = 25;
317 lpStartupInfo->dwFillAttribute = 0x0720;
318 lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW |
319 STARTF_USEPOSITION |
320 STARTF_USESIZE |
321 STARTF_USECOUNTCHARS |
322 STARTF_USEFILLATTRIBUTE|
323 STARTF_USESTDHANDLES;
324 lpStartupInfo->wShowWindow = SW_SHOWDEFAULT;
325 lpStartupInfo->cbReserved2 = 0;
326 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
327 /* @@@PH 98/07/13 Handlemanager support */
328 lpStartupInfo->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
329 lpStartupInfo->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
330 lpStartupInfo->hStdError = GetStdHandle(STD_ERROR_HANDLE);
331 return;
332}
333//******************************************************************************
334//Borrowed from Wine
335//******************************************************************************
336ODINPROCEDURE1(GetStartupInfoW,LPSTARTUPINFOW,lpStartupInfo)
337{
338 static WCHAR lpReserved[] = {'<', 'R','e','s','e','r','v','e','d','>', 0};
339 static WCHAR lpDesktop[] = {'D', 'e','s','k','t','o','p', 0};
340 static WCHAR lpTitle[] = {'T', 'i','t','l','e', 0};
341
342 // forward call to ascii variant
343 GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo);
344 lpStartupInfo->cb = sizeof(STARTUPINFOW);
345 lpStartupInfo->lpReserved = lpReserved;
346 lpStartupInfo->lpDesktop = lpDesktop;
347 lpStartupInfo->lpTitle = lpTitle;
348 return;
349}
350//******************************************************************************
351//******************************************************************************
352BOOL WIN32API FlushInstructionCache( /*PLF Mon 98-02-09 23:56:49 : STUB STUB STUB STUB STUB */
353 HANDLE hProcess, /* process with cache to flush */
354 LPCVOID lpvBase, /* address of region to flush */
355 DWORD cbFlush) /* length of region to flush */
356
357{
358 dprintf(("FlushInstructionCache() - NIY\n"));
359 return TRUE;
360}
361
362
363//******************************************************************************
364
365/***********************************************************************
366* RtlFillMemory (KERNEL32.441)
367*/
368VOID WIN32API RtlFillMemory(LPVOID ptr,
369 UINT len,
370 UINT fill )
371{
372#ifdef DEBUG_LOCAL
373 dprintf(("KERNEL32: RtlFillMemory(%08x,%08x,%08x)\n",
374 ptr,
375 len,
376 fill));
377#endif
378
379 memset(ptr,
380 fill,
381 len );
382}
383
384
385/***********************************************************************
386* RtlMoveMemory (KERNEL32.442)
387*/
388VOID WIN32API RtlMoveMemory(LPVOID dst,
389 LPCVOID src,
390 UINT len )
391{
392 dprintf2(("KERNEL32: RtlMoveMemory(%08x,%08x,%08x)\n",
393 dst,
394 src,
395 len));
396
397 memmove(dst,
398 src,
399 len );
400}
401
402
403/***********************************************************************
404* RtlZeroMemory (KERNEL32.444)
405*/
406VOID WIN32API RtlZeroMemory(LPVOID ptr,
407 UINT len)
408{
409 dprintf2(("KERNEL32: RtlZeroMemory(%08x,%08x)\n",
410 ptr,
411 len));
412
413 memset(ptr,
414 0,
415 len);
416}
417
418//******************************************************************************
419/*KSO Thu 21.05.1998*/
420BOOL WIN32API IsDBCSLeadByteEx(UINT CodePage, BYTE TestChar)
421{
422 dprintf(("KERNEL32: OS2IsDBCSLeadByteEx - not correctly implemented\n"));
423 return O32_IsDBCSLeadByte(TestChar);
424}
425//******************************************************************************
426
427
428
429
430
431
432
433
434/*****************************************************************************
435 * Name : BOOL GetSystemPowerStatus
436 * Purpose : The GetSystemPowerStatus function retrieves the power status of
437 * the system. The status indicates whether the system is running
438 * on AC or DC power, whether the battery is currently charging,
439 * and how much battery life currently remains.
440 * Parameters: LPSYSTEM_POWER_STATUS lpSystemPowerStatus
441 * Variables :
442 * Result : TRUE / FALSE
443 * Remark :
444 * Status : UNTESTED STUB
445 *
446 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
447 *****************************************************************************/
448
449BOOL WIN32API GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus)
450{
451 dprintf(("Kernel32: GetSystemPowerStatus(%08xh) not properly implemented.\n",
452 lpSystemPowerStatus));
453
454 if(lpSystemPowerStatus == NULL) {
455 SetLastError(ERROR_INVALID_PARAMETER);
456 return FALSE;
457 }
458 lpSystemPowerStatus->ACLineStatus = 1; //online
459 lpSystemPowerStatus->BatteryFlag = 128; //no system battery
460 lpSystemPowerStatus->BatteryLifePercent = 255; //unknown
461 lpSystemPowerStatus->reserved = 0;
462 lpSystemPowerStatus->BatteryLifeTime = -1; //unknown
463 lpSystemPowerStatus->BatteryFullLifeTime= -1; //unknown
464
465 return TRUE;
466}
Note: See TracBrowser for help on using the repository browser.