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

Last change on this file since 4313 was 4174, checked in by phaller, 25 years ago

WINE NLS sync

File size: 18.7 KB
Line 
1/* $Id: KERNEL32.CPP,v 1.52 2000-09-03 18:04:55 phaller 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 <builtin.h>
35#include "heap.h"
36#include "handlemanager.h"
37#include "wprocess.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: IsBadWritePtr: 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//******************************************************************************
179UINT WIN32API GetACP(VOID)
180{
181 dprintf(("KERNEL32: GetACP\n"));
182 return(O32_GetACP());
183}
184//******************************************************************************
185//******************************************************************************
186VOID WIN32API GlobalMemoryStatus( MEMORYSTATUS *arg1)
187{
188 dprintf(("KERNEL32: GlobalMemoryStatus\n"));
189 O32_GlobalMemoryStatus(arg1);
190 dprintf(("dwMemoryLoad %X\n", arg1->dwMemoryLoad));
191 dprintf(("dwTotalPhys %X\n", arg1->dwTotalPhys));
192 dprintf(("dwAvailPhys %X\n", arg1->dwAvailPhys));
193 dprintf(("dwTotalPageFile %X\n", arg1->dwTotalPageFile));
194 dprintf(("dwAvailPageFile %X\n", arg1->dwAvailPageFile));
195 dprintf(("dwTotalVirtual %X\n", arg1->dwTotalVirtual));
196 dprintf(("dwAvailVirtual %X\n", arg1->dwAvailVirtual));
197}
198VOID WIN32API Sleep(DWORD arg1)
199{
200 dprintf2(("KERNEL32: Sleep %d\n", arg1));
201 O32_Sleep(arg1);
202}
203//******************************************************************************
204//******************************************************************************
205DWORD WIN32API GetPriorityClass(HANDLE arg1)
206{
207 dprintf(("KERNEL32: GetPriorityClass\n"));
208 return O32_GetPriorityClass(arg1);
209}
210//******************************************************************************
211//******************************************************************************
212BOOL WIN32API SetPriorityClass(HANDLE arg1, DWORD arg2)
213{
214 dprintf(("KERNEL32: SetPriorityClass\n"));
215 return O32_SetPriorityClass(arg1, arg2);
216}
217//******************************************************************************
218//******************************************************************************
219BOOL WIN32API Beep( DWORD arg1, DWORD arg2)
220{
221 dprintf(("KERNEL32: OS2Beep\n"));
222 return O32_Beep(arg1, arg2);
223}
224//******************************************************************************
225//******************************************************************************
226VOID WIN32API FatalAppExitA( UINT arg1, LPCSTR arg2)
227{
228 dprintf(("KERNEL32: OS2FatalAppExitA\n"));
229 O32_FatalAppExit(arg1, arg2);
230}
231//******************************************************************************
232//******************************************************************************
233VOID WIN32API FatalAppExitW(UINT arg1, LPCWSTR arg2)
234{
235 char *astring;
236
237 dprintf(("KERNEL32: OS2FatalAppExitW\n"));
238 astring = UnicodeToAsciiString((LPWSTR)arg2);
239 O32_FatalAppExit(arg1, astring);
240 //probably won't return, but who cares..
241 FreeAsciiString(astring);
242}
243//******************************************************************************
244//******************************************************************************
245VOID WIN32API FatalExit( UINT arg1)
246{
247 dprintf(("KERNEL32: OS2FatalExit\n"));
248 O32_FatalExit(arg1);
249}
250//******************************************************************************
251//******************************************************************************
252BOOL WIN32API IsBadHugeReadPtr( const void * arg1, UINT arg2)
253{
254 dprintf(("KERNEL32: OS2IsBadHugeReadPtr\n"));
255 return O32_IsBadHugeReadPtr(arg1, arg2);
256}
257//******************************************************************************
258//******************************************************************************
259BOOL WIN32API IsBadHugeWritePtr( PVOID arg1, UINT arg2)
260{
261 dprintf(("KERNEL32: OS2IsBadHugeWritePtr\n"));
262 return O32_IsBadHugeWritePtr(arg1, arg2);
263}
264//******************************************************************************
265//******************************************************************************
266BOOL WIN32API IsDBCSLeadByte(BYTE arg1)
267{
268 dprintf2(("KERNEL32: OS2IsDBCSLeadByte\n"));
269 return O32_IsDBCSLeadByte(arg1);
270}
271//******************************************************************************
272//******************************************************************************
273DWORD WIN32API LoadModule( LPCSTR arg1, PVOID arg2)
274{
275 dprintf(("KERNEL32: OS2LoadModule\n"));
276 return O32_LoadModule(arg1, arg2);
277}
278//******************************************************************************
279//******************************************************************************
280int WIN32API MulDiv(int arg1, int arg2, int arg3)
281{
282 dprintf2(("KERNEL32: MulDiv %d*%d/%d\n", arg1, arg2, arg3));
283 if(arg3 == 0)
284 return 0;
285
286 return O32_MulDiv(arg1, arg2, arg3);
287}
288//******************************************************************************
289//Borrowed from Wine
290//******************************************************************************
291ODINPROCEDURE1(GetStartupInfoA,LPSTARTUPINFOA,lpStartupInfo)
292{
293 lpStartupInfo->cb = sizeof(STARTUPINFOA);
294 lpStartupInfo->lpReserved = "<Reserved>";
295 lpStartupInfo->lpDesktop = "Desktop";
296 lpStartupInfo->lpTitle = "Title";
297 lpStartupInfo->dwX = 0;
298 lpStartupInfo->dwY = 0;
299 lpStartupInfo->dwXSize = 640;
300 lpStartupInfo->dwYSize = 480;
301 lpStartupInfo->dwXCountChars = 80; // for console
302 lpStartupInfo->dwYCountChars = 25;
303 lpStartupInfo->dwFillAttribute = 0x0720;
304 lpStartupInfo->dwFlags = STARTF_USESHOWWINDOW |
305 STARTF_USEPOSITION |
306 STARTF_USESIZE |
307 STARTF_USECOUNTCHARS |
308 STARTF_USEFILLATTRIBUTE|
309 STARTF_USESTDHANDLES;
310 lpStartupInfo->wShowWindow = SW_SHOWDEFAULT;
311 lpStartupInfo->cbReserved2 = 0;
312 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
313 /* @@@PH 98/07/13 Handlemanager support */
314 lpStartupInfo->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
315 lpStartupInfo->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
316 lpStartupInfo->hStdError = GetStdHandle(STD_ERROR_HANDLE);
317 return;
318}
319//******************************************************************************
320//Borrowed from Wine
321//******************************************************************************
322ODINPROCEDURE1(GetStartupInfoW,LPSTARTUPINFOW,lpStartupInfo)
323{
324 static WCHAR lpReserved[] = {'<', 'R','e','s','e','r','v','e','d','>', 0};
325 static WCHAR lpDesktop[] = {'D', 'e','s','k','t','o','p', 0};
326 static WCHAR lpTitle[] = {'T', 'i','t','l','e', 0};
327
328 // forward call to ascii variant
329 GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo);
330 lpStartupInfo->cb = sizeof(STARTUPINFOW);
331 lpStartupInfo->lpReserved = lpReserved;
332 lpStartupInfo->lpDesktop = lpDesktop;
333 lpStartupInfo->lpTitle = lpTitle;
334 return;
335}
336//******************************************************************************
337//TODO: Not complete or correct, but sufficient for now
338//******************************************************************************
339BOOL WIN32API GetBinaryTypeA(LPCTSTR lpApplicationName, LPDWORD lpBinaryType)
340{
341 dprintf(("KERNEL32: OS2GetBinaryTypeA %s\n", lpApplicationName));
342 if(strstr(lpApplicationName, ".EXE") || strstr(lpApplicationName, ".exe"))
343 *lpBinaryType = SCS_32BIT_BINARY;
344 else
345 if(strstr(lpApplicationName, ".COM") || strstr(lpApplicationName, ".com"))
346 *lpBinaryType = SCS_DOS_BINARY;
347 else
348 if(strstr(lpApplicationName, ".PIF") || strstr(lpApplicationName, ".pif"))
349 *lpBinaryType = SCS_PIF_BINARY;
350 else return(FALSE);
351 return(TRUE);
352}
353//******************************************************************************
354//******************************************************************************
355BOOL WIN32API GetBinaryTypeW(LPCWSTR lpApplicationName, LPDWORD lpBinaryType)
356{
357 BOOL rc;
358 char *astring;
359
360 dprintf(("KERNEL32: OS2GetBinaryTypeW\n"));
361 astring = UnicodeToAsciiString((LPWSTR)lpApplicationName);
362 rc = GetBinaryTypeA(astring, lpBinaryType);
363 FreeAsciiString(astring);
364 return(rc);
365}
366//******************************************************************************
367//TODO: SetLastError
368//******************************************************************************
369BOOL WIN32API GetVersionExA(OSVERSIONINFOA *lpVersionInformation)
370{
371 dprintf(("KERNEL32: OS2GetVersionExA\n"));
372
373 if(lpVersionInformation == NULL || lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
374 return(FALSE);
375
376 lpVersionInformation->dwMajorVersion = ODINNT_MAJOR_VERSION; //pretend we're NT 4.0
377 lpVersionInformation->dwMinorVersion = ODINNT_MINOR_VERSION;
378 lpVersionInformation->dwBuildNumber = ODINNT_BUILD_NR;
379 lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
380 strcpy(lpVersionInformation->szCSDVersion, ODINNT_CSDVERSION);
381 return(TRUE);
382}
383//******************************************************************************
384//******************************************************************************
385BOOL WIN32API GetVersionExW(OSVERSIONINFOW *lpVersionInformation)
386{
387 dprintf(("KERNEL32: OS2GetVersionExW\n"));
388
389 if(lpVersionInformation == NULL || lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW))
390 return(FALSE);
391
392 lpVersionInformation->dwMajorVersion = ODINNT_MAJOR_VERSION; //pretend we're NT 4.0
393 lpVersionInformation->dwMinorVersion = ODINNT_MINOR_VERSION;
394 lpVersionInformation->dwBuildNumber = ODINNT_BUILD_NR;
395 lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
396 lstrcpyW(lpVersionInformation->szCSDVersion, ODINNT_CSDVERSION_W);
397 return(TRUE);
398}
399//******************************************************************************
400//******************************************************************************
401LONG WIN32API GetVersion()
402{
403 dprintf(("KERNEL32: GetVersion\n"));
404 // highword 0 = NT, lowword high byte major ver, low byte minor ver
405/* @@@PH 98/04/04 MFC30 makes assumptions about process control block */
406/* structures that lead to crashes if we don't identify as NT */
407
408 return ODINNT_VERSION;
409}
410//******************************************************************************
411//******************************************************************************
412BOOL WIN32API FlushInstructionCache( /*PLF Mon 98-02-09 23:56:49 : STUB STUB STUB STUB STUB */
413 HANDLE hProcess, /* process with cache to flush */
414 LPCVOID lpvBase, /* address of region to flush */
415 DWORD cbFlush) /* length of region to flush */
416
417{
418 dprintf(("FlushInstructionCache() - NIY\n"));
419 return TRUE;
420}
421
422
423//******************************************************************************
424
425/***********************************************************************
426* RtlFillMemory (KERNEL32.441)
427*/
428VOID WIN32API RtlFillMemory(LPVOID ptr,
429 UINT len,
430 UINT fill )
431{
432#ifdef DEBUG_LOCAL
433 dprintf(("KERNEL32: RtlFillMemory(%08x,%08x,%08x)\n",
434 ptr,
435 len,
436 fill));
437#endif
438
439 memset(ptr,
440 fill,
441 len );
442}
443
444
445/***********************************************************************
446* RtlMoveMemory (KERNEL32.442)
447*/
448VOID WIN32API RtlMoveMemory(LPVOID dst,
449 LPCVOID src,
450 UINT len )
451{
452 dprintf2(("KERNEL32: RtlMoveMemory(%08x,%08x,%08x)\n",
453 dst,
454 src,
455 len));
456
457 memmove(dst,
458 src,
459 len );
460}
461
462
463/***********************************************************************
464* RtlZeroMemory (KERNEL32.444)
465*/
466VOID WIN32API RtlZeroMemory(LPVOID ptr,
467 UINT len)
468{
469 dprintf2(("KERNEL32: RtlZeroMemory(%08x,%08x)\n",
470 ptr,
471 len));
472
473 memset(ptr,
474 0,
475 len);
476}
477
478//******************************************************************************
479/*KSO Thu 21.05.1998*/
480BOOL WIN32API IsDBCSLeadByteEx(UINT CodePage, BYTE TestChar)
481{
482 dprintf(("KERNEL32: OS2IsDBCSLeadByteEx - not correctly implemented\n"));
483 return O32_IsDBCSLeadByte(TestChar);
484}
485//******************************************************************************
486
487
488
489
490
491
492
493
494/*****************************************************************************
495 * Name : BOOL GetSystemPowerStatus
496 * Purpose : The GetSystemPowerStatus function retrieves the power status of
497 * the system. The status indicates whether the system is running
498 * on AC or DC power, whether the battery is currently charging,
499 * and how much battery life currently remains.
500 * Parameters: LPSYSTEM_POWER_STATUS lpSystemPowerStatus
501 * Variables :
502 * Result : TRUE / FALSE
503 * Remark :
504 * Status : UNTESTED STUB
505 *
506 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
507 *****************************************************************************/
508
509BOOL WIN32API GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus)
510{
511 dprintf(("Kernel32: GetSystemPowerStatus(%08xh) not properly implemented.\n",
512 lpSystemPowerStatus));
513
514 if(lpSystemPowerStatus == NULL) {
515 SetLastError(ERROR_INVALID_PARAMETER);
516 return FALSE;
517 }
518 lpSystemPowerStatus->ACLineStatus = 1; //online
519 lpSystemPowerStatus->BatteryFlag = 128; //no system battery
520 lpSystemPowerStatus->BatteryLifePercent = 255; //unknown
521 lpSystemPowerStatus->reserved = 0;
522 lpSystemPowerStatus->BatteryLifeTime = -1; //unknown
523 lpSystemPowerStatus->BatteryFullLifeTime= -1; //unknown
524
525 return TRUE;
526}
Note: See TracBrowser for help on using the repository browser.