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

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

codepage workaround (default = 0 isntead of 1252)

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