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

Last change on this file since 5890 was 5886, checked in by achimha, 24 years ago

log GetLastError in standard logging level

File size: 14.5 KB
Line 
1/* $Id: KERNEL32.CPP,v 1.66 2001-06-02 17:27:02 achimha 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 : 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 dprintf(("KERNEL32: GetLastError returned %d\n", rc));
159 } else
160 {
161 dprintf(("KERNEL32: GetLastError returned no error\n"));
162 }
163 return(rc);
164}
165//******************************************************************************
166//******************************************************************************
167VOID WIN32API SetLastError( DWORD dwError)
168{
169 if(dwError != 0) {
170 dprintf2(("KERNEL32: SetLastError to %d\n", dwError));
171 }
172 O32_SetLastError(dwError);
173}
174//******************************************************************************
175//******************************************************************************
176/*
177 * PH 2000/09/25 This is an experiment to overcome some problems
178 * with Open32's GMS variant.
179 */
180void _GlobalMemoryStatus(MEMORYSTATUS *lpMemStat)
181{
182 ULONG sys[5];
183 // Note: QSV_TOTPHYSMEM = 17, QSV_MAXSHMEM = 21
184 lpMemStat->dwLength = sizeof(MEMORYSTATUS);
185
186 if(!OSLibDosQuerySysInfo( 17, 21, (PVOID)sys, sizeof(sys)))
187 {
188 // Specified a number between 0 and 100 that gives a general idea of
189 // current memory utilization, in which 0 indicates no memory use and
190 // 100 indicates full memory use
191
192 //#define MB512 0x1c000000
193 //lpMemStat->dwMemoryLoad = (MB512-sys[20]) * 100 / MB512;
194 lpMemStat->dwMemoryLoad = (sys[1] * 100) / sys[0];
195
196 // bytes of physical memory
197 lpMemStat->dwTotalPhys = sys[0];
198
199 // free physical memory bytes
200 lpMemStat->dwAvailPhys = sys[0] - sys[1];
201
202 // bytes of paging file
203 // @@@PH add swapper.dat size?
204 lpMemStat->dwTotalPageFile = sys[2];
205
206 // free bytes of paging file
207 lpMemStat->dwAvailPageFile = sys[2];
208
209 // user bytes of address space
210 lpMemStat->dwTotalVirtual = max(sys[2], sys[3]);
211 lpMemStat->dwAvailVirtual = min(sys[2], sys[3]);
212 }
213}
214
215
216
217VOID WIN32API GlobalMemoryStatus(MEMORYSTATUS *arg1)
218{
219 dprintf(("KERNEL32: GlobalMemoryStatus\n"));
220 //O32_GlobalMemoryStatus(arg1);
221 _GlobalMemoryStatus(arg1);
222 dprintf(("dwMemoryLoad %X\n", arg1->dwMemoryLoad));
223 dprintf(("dwTotalPhys %X\n", arg1->dwTotalPhys));
224 dprintf(("dwAvailPhys %X\n", arg1->dwAvailPhys));
225 dprintf(("dwTotalPageFile %X\n", arg1->dwTotalPageFile));
226 dprintf(("dwAvailPageFile %X\n", arg1->dwAvailPageFile));
227 dprintf(("dwTotalVirtual %X\n", arg1->dwTotalVirtual));
228 dprintf(("dwAvailVirtual %X\n", arg1->dwAvailVirtual));
229}
230BOOL WIN32API Beep( DWORD arg1, DWORD arg2)
231{
232 dprintf(("KERNEL32: OS2Beep\n"));
233 return O32_Beep(arg1, arg2);
234}
235//******************************************************************************
236//******************************************************************************
237VOID WIN32API FatalAppExitA( UINT arg1, LPCSTR arg2)
238{
239 dprintf(("KERNEL32: OS2FatalAppExitA\n"));
240 O32_FatalAppExit(arg1, arg2);
241}
242//******************************************************************************
243//******************************************************************************
244VOID WIN32API FatalAppExitW(UINT arg1, LPCWSTR arg2)
245{
246 char *astring;
247
248 dprintf(("KERNEL32: OS2FatalAppExitW %x", arg1));
249 astring = UnicodeToAsciiString((LPWSTR)arg2);
250 O32_FatalAppExit(arg1, astring);
251 //probably won't return, but who cares..
252 FreeAsciiString(astring);
253}
254//******************************************************************************
255//******************************************************************************
256VOID WIN32API FatalExit( UINT arg1)
257{
258 dprintf(("KERNEL32: FatalExit %x", arg1));
259 O32_FatalExit(arg1);
260}
261//******************************************************************************
262//******************************************************************************
263BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT arg2)
264{
265 dprintf(("KERNEL32: OS2IsBadHugeReadPtr\n"));
266 return O32_IsBadHugeReadPtr(arg1, arg2);
267}
268//******************************************************************************
269//******************************************************************************
270BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT arg2)
271{
272 dprintf(("KERNEL32: IsBadHugeWritePtr\n"));
273 return O32_IsBadHugeWritePtr(arg1, arg2);
274}
275//******************************************************************************
276//******************************************************************************
277int WIN32API MulDiv(int arg1, int arg2, int arg3)
278{
279 dprintf2(("KERNEL32: MulDiv %d*%d/%d\n", arg1, arg2, arg3));
280 if(arg3 == 0)
281 return 0;
282
283 return O32_MulDiv(arg1, arg2, arg3);
284}
285//******************************************************************************
286//Borrowed from Wine
287//******************************************************************************
288ODINPROCEDURE1(GetStartupInfoA,LPSTARTUPINFOA,lpStartupInfo)
289{
290 lpStartupInfo->cb = sizeof(STARTUPINFOA);
291 lpStartupInfo->lpReserved = "<Reserved>";
292 lpStartupInfo->lpDesktop = "Desktop";
293 lpStartupInfo->lpTitle = "Title";
294 lpStartupInfo->dwX = 0;
295 lpStartupInfo->dwY = 0;
296 lpStartupInfo->dwXSize = 640;
297 lpStartupInfo->dwYSize = 480;
298 lpStartupInfo->dwXCountChars = 80; // for console
299 lpStartupInfo->dwYCountChars = 25;
300 lpStartupInfo->dwFillAttribute = 0x0720;
301 lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW |
302 STARTF_USEPOSITION |
303 STARTF_USESIZE |
304 STARTF_USECOUNTCHARS |
305 STARTF_USEFILLATTRIBUTE|
306 STARTF_USESTDHANDLES;
307 lpStartupInfo->wShowWindow = SW_SHOWDEFAULT;
308 lpStartupInfo->cbReserved2 = 0;
309 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
310 /* @@@PH 98/07/13 Handlemanager support */
311 lpStartupInfo->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
312 lpStartupInfo->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
313 lpStartupInfo->hStdError = GetStdHandle(STD_ERROR_HANDLE);
314 return;
315}
316//******************************************************************************
317//Borrowed from Wine
318//******************************************************************************
319ODINPROCEDURE1(GetStartupInfoW,LPSTARTUPINFOW,lpStartupInfo)
320{
321 static WCHAR lpReserved[] = {'<', 'R','e','s','e','r','v','e','d','>', 0};
322 static WCHAR lpDesktop[] = {'D', 'e','s','k','t','o','p', 0};
323 static WCHAR lpTitle[] = {'T', 'i','t','l','e', 0};
324
325 // forward call to ascii variant
326 GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo);
327 lpStartupInfo->cb = sizeof(STARTUPINFOW);
328 lpStartupInfo->lpReserved = lpReserved;
329 lpStartupInfo->lpDesktop = lpDesktop;
330 lpStartupInfo->lpTitle = lpTitle;
331 return;
332}
333//******************************************************************************
334//******************************************************************************
335BOOL WIN32API FlushInstructionCache( /*PLF Mon 98-02-09 23:56:49 : STUB STUB STUB STUB STUB */
336 HANDLE hProcess, /* process with cache to flush */
337 LPCVOID lpvBase, /* address of region to flush */
338 DWORD cbFlush) /* length of region to flush */
339
340{
341 dprintf(("FlushInstructionCache() - NIY\n"));
342 return TRUE;
343}
344
345
346//******************************************************************************
347
348/***********************************************************************
349* RtlFillMemory (KERNEL32.441)
350*/
351VOID WIN32API RtlFillMemory(LPVOID ptr,
352 UINT len,
353 UINT fill )
354{
355#ifdef DEBUG_LOCAL
356 dprintf(("KERNEL32: RtlFillMemory(%08x,%08x,%08x)\n",
357 ptr,
358 len,
359 fill));
360#endif
361
362 memset(ptr,
363 fill,
364 len );
365}
366
367
368/***********************************************************************
369* RtlMoveMemory (KERNEL32.442)
370*/
371VOID WIN32API RtlMoveMemory(LPVOID dst,
372 LPCVOID src,
373 UINT len )
374{
375 dprintf2(("KERNEL32: RtlMoveMemory(%08x,%08x,%08x)\n",
376 dst,
377 src,
378 len));
379
380 memmove(dst,
381 src,
382 len );
383}
384
385
386/***********************************************************************
387* RtlZeroMemory (KERNEL32.444)
388*/
389VOID WIN32API RtlZeroMemory(LPVOID ptr,
390 UINT len)
391{
392 dprintf2(("KERNEL32: RtlZeroMemory(%08x,%08x)\n",
393 ptr,
394 len));
395
396 memset(ptr,
397 0,
398 len);
399}
400
401//******************************************************************************
402
403
404
405
406
407
408
409
410/*****************************************************************************
411 * Name : BOOL GetSystemPowerStatus
412 * Purpose : The GetSystemPowerStatus function retrieves the power status of
413 * the system. The status indicates whether the system is running
414 * on AC or DC power, whether the battery is currently charging,
415 * and how much battery life currently remains.
416 * Parameters: LPSYSTEM_POWER_STATUS lpSystemPowerStatus
417 * Variables :
418 * Result : TRUE / FALSE
419 * Remark :
420 * Status : UNTESTED STUB
421 *
422 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
423 *****************************************************************************/
424
425BOOL WIN32API GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus)
426{
427 dprintf(("Kernel32: GetSystemPowerStatus(%08xh) not properly implemented.\n",
428 lpSystemPowerStatus));
429
430 if(lpSystemPowerStatus == NULL) {
431 SetLastError(ERROR_INVALID_PARAMETER);
432 return FALSE;
433 }
434 lpSystemPowerStatus->ACLineStatus = AC_LINE_ONLINE;
435 lpSystemPowerStatus->BatteryFlag = BATTERY_FLAG_HIGH;
436 lpSystemPowerStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
437 lpSystemPowerStatus->Reserved1 = 0;
438 lpSystemPowerStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
439 lpSystemPowerStatus->BatteryFullLifeTime= BATTERY_LIFE_UNKNOWN;
440
441 return TRUE;
442}
Note: See TracBrowser for help on using the repository browser.