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

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

codepage updates

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