source: trunk/src/NTDLL/rtl.cpp@ 560

Last change on this file since 560 was 560, checked in by phaller, 26 years ago

Add: added more stubs

File size: 16.7 KB
Line 
1/* $Id: rtl.cpp,v 1.5 1999-08-18 22:08:34 phaller Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 * Win32 NT Runtime / NTDLL for OS/2
6 *
7 * Copyright 1998 original WINE Author
8 * Copyright 1998, 1999 Patrick Haller (phaller@gmx.net)
9 *
10 * NT basis DLL
11 *
12 * This file contains the Rtl* API functions. These should be implementable.
13 *
14 * Copyright 1996-1998 Marcus Meissner
15 * 1999 Alex Korobka
16 */
17
18#include <stdlib.h>
19#include <string.h>
20
21#include "ntdll.h"
22
23#include "winuser.h"
24#include "winerror.h"
25#include "winreg.h"
26
27
28
29/*
30 * resource functions
31 */
32
33/***********************************************************************
34 * RtlInitializeResource (NTDLL.409)
35 *
36 * xxxResource() functions implement multiple-reader-single-writer lock.
37 * The code is based on information published in WDJ January 1999 issue.
38 */
39void WINAPI RtlInitializeResource(LPRTL_RWLOCK rwl)
40{
41 dprintf(("NTDLL: RtlInitializeResource(%08xh)\n",
42 rwl));
43
44 if( rwl )
45 {
46 rwl->iNumberActive = 0;
47 rwl->uExclusiveWaiters = 0;
48 rwl->uSharedWaiters = 0;
49 rwl->hOwningThreadId = 0;
50 rwl->dwTimeoutBoost = 0; /* no info on this one, default value is 0 */
51 InitializeCriticalSection( &rwl->rtlCS );
52 rwl->hExclusiveReleaseSemaphore = CreateSemaphoreA( NULL, 0, 65535, NULL );
53 rwl->hSharedReleaseSemaphore = CreateSemaphoreA( NULL, 0, 65535, NULL );
54 }
55}
56
57
58/***********************************************************************
59 * RtlDeleteResource (NTDLL.330)
60 */
61void WINAPI RtlDeleteResource(LPRTL_RWLOCK rwl)
62{
63 dprintf(("NTDLL: RtlDeleteResource(%08xh)\n",
64 rwl));
65
66 if( rwl )
67 {
68 EnterCriticalSection( &rwl->rtlCS );
69 if( rwl->iNumberActive || rwl->uExclusiveWaiters || rwl->uSharedWaiters )
70 dprintf(("NTDLL: RtlDeleteResource active MRSW lock (%p), expect failure\n",
71 rwl));
72
73 rwl->hOwningThreadId = 0;
74 rwl->uExclusiveWaiters = rwl->uSharedWaiters = 0;
75 rwl->iNumberActive = 0;
76 CloseHandle( rwl->hExclusiveReleaseSemaphore );
77 CloseHandle( rwl->hSharedReleaseSemaphore );
78 LeaveCriticalSection( &rwl->rtlCS );
79 DeleteCriticalSection( &rwl->rtlCS );
80 }
81}
82
83
84/***********************************************************************
85 * RtlAcquireResourceExclusive (NTDLL.256)
86 */
87BYTE WINAPI RtlAcquireResourceExclusive(LPRTL_RWLOCK rwl,
88 BYTE fWait)
89{
90 BYTE retVal = 0;
91
92 if( !rwl )
93 return 0;
94
95 dprintf(("NTDLL: RtlAcquireResourceExclusive(%08xh,%08xh)\n",
96 rwl,
97 fWait));
98
99start:
100 EnterCriticalSection( &rwl->rtlCS );
101 if( rwl->iNumberActive == 0 ) /* lock is free */
102 {
103 rwl->iNumberActive = -1;
104 retVal = 1;
105 }
106 else if( rwl->iNumberActive < 0 ) /* exclusive lock in progress */
107 {
108 if( rwl->hOwningThreadId == GetCurrentThreadId() )
109 {
110 retVal = 1;
111 rwl->iNumberActive--;
112 goto done;
113 }
114wait:
115 if( fWait )
116 {
117 rwl->uExclusiveWaiters++;
118
119 LeaveCriticalSection( &rwl->rtlCS );
120 if( WaitForSingleObject( rwl->hExclusiveReleaseSemaphore, INFINITE ) == WAIT_FAILED )
121 goto done;
122 goto start; /* restart the acquisition to avoid deadlocks */
123 }
124 }
125 else /* one or more shared locks are in progress */
126 if( fWait )
127 goto wait;
128
129 if( retVal == 1 )
130 rwl->hOwningThreadId = GetCurrentThreadId();
131done:
132 LeaveCriticalSection( &rwl->rtlCS );
133 return retVal;
134}
135
136/***********************************************************************
137 * RtlAcquireResourceShared (NTDLL.257)
138 */
139BYTE WINAPI RtlAcquireResourceShared(LPRTL_RWLOCK rwl,
140 BYTE fWait)
141{
142 DWORD dwWait = WAIT_FAILED;
143 BYTE retVal = 0;
144
145 if( !rwl )
146 return 0;
147
148 dprintf(("NTDLL: RtlAcquireResourceShared(%08xh,%08xh)\n",
149 rwl,
150 fWait));
151
152start:
153 EnterCriticalSection( &rwl->rtlCS );
154 if( rwl->iNumberActive < 0 )
155 {
156 if( rwl->hOwningThreadId == GetCurrentThreadId() )
157 {
158 rwl->iNumberActive--;
159 retVal = 1;
160 goto done;
161 }
162
163 if( fWait )
164 {
165 rwl->uSharedWaiters++;
166 LeaveCriticalSection( &rwl->rtlCS );
167 if( (dwWait = WaitForSingleObject( rwl->hSharedReleaseSemaphore, INFINITE )) == WAIT_FAILED )
168 goto done;
169 goto start;
170 }
171 }
172 else
173 {
174 if( dwWait != WAIT_OBJECT_0 ) /* otherwise RtlReleaseResource() has already done it */
175 rwl->iNumberActive++;
176 retVal = 1;
177 }
178done:
179 LeaveCriticalSection( &rwl->rtlCS );
180 return retVal;
181}
182
183
184/***********************************************************************
185 * RtlReleaseResource (NTDLL.471)
186 */
187void WINAPI RtlReleaseResource(LPRTL_RWLOCK rwl)
188{
189 dprintf(("NTDLL: RtlReleaseResource(%08xh)\n",
190 rwl));
191
192 EnterCriticalSection( &rwl->rtlCS );
193
194 if( rwl->iNumberActive > 0 ) /* have one or more readers */
195 {
196 if( --rwl->iNumberActive == 0 )
197 {
198 if( rwl->uExclusiveWaiters )
199 {
200wake_exclusive:
201 rwl->uExclusiveWaiters--;
202 ReleaseSemaphore( rwl->hExclusiveReleaseSemaphore, 1, NULL );
203 }
204 }
205 }
206 else
207 if( rwl->iNumberActive < 0 ) /* have a writer, possibly recursive */
208 {
209 if( ++rwl->iNumberActive == 0 )
210 {
211 rwl->hOwningThreadId = 0;
212 if( rwl->uExclusiveWaiters )
213 goto wake_exclusive;
214 else
215 if( rwl->uSharedWaiters )
216 {
217 UINT n = rwl->uSharedWaiters;
218 rwl->iNumberActive = rwl->uSharedWaiters; /* prevent new writers from joining until
219 * all queued readers have done their thing */
220 rwl->uSharedWaiters = 0;
221 ReleaseSemaphore( rwl->hSharedReleaseSemaphore, n, NULL );
222 }
223 }
224 }
225 LeaveCriticalSection( &rwl->rtlCS );
226}
227
228
229/***********************************************************************
230 * RtlDumpResource (NTDLL.340)
231 */
232void WINAPI RtlDumpResource(LPRTL_RWLOCK rwl)
233{
234 dprintf(("NTDLL: RtlDumpResource(%08x)\n",
235 rwl));
236
237 if( rwl )
238 {
239 dprintf(("NTDLL: RtlDumpResource(%p):\n\tactive count = %i\n\twaiting readers = %i\n\twaiting writers = %i\n",
240 rwl,
241 rwl->iNumberActive,
242 rwl->uSharedWaiters,
243 rwl->uExclusiveWaiters));
244
245 if( rwl->iNumberActive )
246 dprintf(("NTDLL: \towner thread = %08x\n",
247 rwl->hOwningThreadId ));
248 }
249}
250
251
252/*
253 * heap functions
254 */
255
256/******************************************************************************
257 * RtlCreateHeap [NTDLL]
258 */
259HANDLE WINAPI RtlCreateHeap(ULONG Flags,
260 PVOID BaseAddress,
261 ULONG SizeToReserve,
262 ULONG SizeToCommit,
263 PVOID Unknown,
264 PRTL_HEAP_DEFINITION Definition)
265{
266 dprintf(("NTDLL: RtlCreateHeap(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh).\n",
267 Flags,
268 BaseAddress,
269 SizeToReserve,
270 SizeToCommit,
271 Unknown,
272 Definition));
273
274 return HeapCreate(Flags,
275 SizeToCommit,
276 SizeToReserve);
277}
278
279
280/******************************************************************************
281 * RtlAllocateHeap [NTDLL]
282 */
283PVOID WINAPI RtlAllocateHeap(HANDLE Heap,
284 ULONG Flags,
285 ULONG Size)
286{
287 dprintf(("NTDLL: RtlAllocateHeap(%08xh,%08xh,%08xh).\n",
288 Heap,
289 Flags,
290 Size));
291
292 return HeapAlloc(Heap,
293 Flags,
294 Size);
295}
296
297
298/******************************************************************************
299 * RtlFreeHeap [NTDLL]
300 */
301BOOLEAN WINAPI RtlFreeHeap(HANDLE Heap,
302 ULONG Flags,
303 PVOID Address)
304{
305 dprintf(("NTDLL: RtlFreeHeap(%08xh,%08xh,%08xh)\n",
306 Heap,
307 Flags,
308 Address));
309
310 return HeapFree(Heap, Flags, Address);
311}
312
313
314/******************************************************************************
315 * RtlDestroyHeap [NTDLL]
316 *
317 * FIXME: prototype guessed
318 */
319BOOLEAN WINAPI RtlDestroyHeap(HANDLE Heap)
320{
321 dprintf(("NTDLL: RtlDestroyHeap(%08xh)\n",
322 Heap));
323
324 return HeapDestroy(Heap);
325}
326
327
328/*
329 * misc functions
330 */
331
332
333/******************************************************************************
334 * RtlAcquirePebLock [NTDLL]
335 */
336VOID WINAPI RtlAcquirePebLock(void)
337{
338 dprintf(("NTDLL: RtlAcquirePebLock() not implemented.\n"));
339
340 /* enter critical section ? */
341}
342
343
344/******************************************************************************
345 * RtlReleasePebLock [NTDLL]
346 */
347VOID WINAPI RtlReleasePebLock(void)
348{
349 dprintf(("NTDLL: RtlReleasePebLock() not implemented.\n"));
350
351 /* leave critical section ? */
352}
353
354
355/******************************************************************************
356 * RtlIntegerToChar [NTDLL]
357 */
358DWORD WINAPI RtlIntegerToChar(DWORD x1,
359 DWORD x2,
360 DWORD x3,
361 DWORD x4)
362{
363 dprintf(("NTDLL: RtlIntegerToChar(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
364 x1,
365 x2,
366 x3,
367 x4));
368
369 return 0;
370}
371
372
373/******************************************************************************
374 * RtlSetEnvironmentVariable [NTDLL]
375 */
376DWORD WINAPI RtlSetEnvironmentVariable(DWORD x1,
377 PUNICODE_STRING key,
378 PUNICODE_STRING val)
379{
380 dprintf(("NTDLL: RtlSetEnvironmentVariable(%08xh,%08xh,%08xh) not implemented.\n",
381 x1,
382 key,
383 val));
384
385 return 0;
386}
387
388
389/******************************************************************************
390 * RtlNewSecurityObject [NTDLL]
391 */
392DWORD WINAPI RtlNewSecurityObject(DWORD x1,
393 DWORD x2,
394 DWORD x3,
395 DWORD x4,
396 DWORD x5,
397 DWORD x6)
398{
399 dprintf(("NTDLL: RtlNewSecurityObject(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n",
400 x1,
401 x2,
402 x3,
403 x4,
404 x5,
405 x6));
406
407 return 0;
408}
409
410
411/******************************************************************************
412 * RtlDeleteSecurityObject [NTDLL]
413 */
414DWORD WINAPI RtlDeleteSecurityObject(DWORD x1)
415{
416 dprintf(("NTDLL: RtlDeleteSecurityObject(%08xh) not implemented.\n",
417 x1));
418
419 return 0;
420}
421
422
423/**************************************************************************
424 * RtlNormalizeProcessParams [NTDLL.441]
425 */
426LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
427{
428 dprintf(("NTDLL: RtlNormalizeProcessParams(%08xh) not implemented.\n",
429 x));
430
431 return x;
432}
433
434
435/**************************************************************************
436 * RtlNtStatusToDosError [NTDLL.442]
437 */
438DWORD WINAPI RtlNtStatusToDosError(DWORD error)
439{
440 dprintf(("NTDLL: RtlNtStatusToDosError(%08xh) partially implemented.\n",
441 error));
442
443 switch (error)
444 {
445 case STATUS_SUCCESS: return ERROR_SUCCESS;
446 case STATUS_INVALID_PARAMETER: return ERROR_BAD_ARGUMENTS;
447 case STATUS_BUFFER_TOO_SMALL: return ERROR_INSUFFICIENT_BUFFER;
448/* case STATUS_INVALID_SECURITY_DESCR: return ERROR_INVALID_SECURITY_DESCR;*/
449 case STATUS_NO_MEMORY: return ERROR_NOT_ENOUGH_MEMORY;
450/* case STATUS_UNKNOWN_REVISION:
451 case STATUS_BUFFER_OVERFLOW:*/
452 }
453
454 dprintf(("NTDLL: RtlNtStatusToDosError(%08xh is unknown !)\n",
455 error));
456
457 return ERROR_SUCCESS;
458}
459
460
461/**************************************************************************
462 * RtlGetNtProductType [NTDLL.390]
463 */
464BOOLEAN WINAPI RtlGetNtProductType(LPDWORD type)
465{
466 dprintf(("NTDLL: RtlGetNtProductType(%08xh) not correctly implemented.\n",
467 type));
468
469 *type=3; /* dunno. 1 for client, 3 for server? */
470 return 1;
471}
472
473
474/******************************************************************************
475 * RtlEnlargedIntegerMultiply [NTDLL.341]
476 * Note: This even works, since gcc returns 64bit values in eax/edx just like
477 * the caller expects. However... The relay code won't grok this I think.
478 *
479 * @@@PH: Parameters are unknown
480 */
481/* longlong in VAC++ ? */
482
483INT WINAPI RtlEnlargedIntegerMultiply(INT factor1,
484 INT factor2)
485{
486 dprintf(("NTDLL: RtlEnlargedIntegerMultiply(%08xh,%08xh) not implemented.\n",
487 factor1,
488 factor2));
489
490 return factor1 * factor2;
491}
492
493
494/******************************************************************************
495 * RtlExtendedLargeIntegerDivide [NTDLL.359]
496 */
497INT WINAPI RtlExtendedLargeIntegerDivide(LARGE_INTEGER dividend,
498 DWORD divisor,
499 LPDWORD rest)
500{
501#if SIZEOF_LONG_LONG==8
502 long long x1 = *(long long*)&dividend;
503
504 if (*rest)
505 *rest = x1 % divisor;
506 return x1/divisor;
507#else
508 dprintf(("NTDLL: RtlExtendedLargeIntegerDevice(%08xh,%08xh,%08xh) not implemented.\n",
509 dividend,
510 divisor,
511 rest));
512
513 return 0;
514#endif
515}
516
517/******************************************************************************
518 * RtlExtendedLargeIntegerMultiply [NTDLL.358]
519 * Note: This even works, since gcc returns 64bit values in eax/edx just like
520 * the caller expects. However... The relay code won't grok this I think.
521 */
522/* longlong in VAC++ ? */
523
524LARGE_INTEGER WINAPI RtlExtendedIntegerMultiply(LARGE_INTEGER factor1,
525 INT factor2)
526{
527 LARGE_INTEGER li;
528
529 dprintf(("NTDLL: RtlExtendedIntegerMultiply(%08xh,%08xh) not implemented.\n",
530 factor1,
531 factor2));
532
533 li.LowPart = factor1.LowPart * factor2;
534 li.HighPart = factor1.HighPart * factor2;
535 // note: overflow from LowPart To HighPart NOT handled !
536
537 return li;
538}
539
540
541/******************************************************************************
542 * RtlFormatCurrentUserKeyPath [NTDLL.371]
543 */
544DWORD WINAPI RtlFormatCurrentUserKeyPath(DWORD x)
545{
546 dprintf(("NTDLL: RtlFormatCurrentUserKeyPath(%08xh) not implemented.\n",
547 x));
548
549 return 1;
550}
551
552
553/******************************************************************************
554 * RtlOpenCurrentUser [NTDLL]
555 */
556DWORD WINAPI RtlOpenCurrentUser(DWORD x1,
557 DWORD *x2)
558{
559 /* Note: this is not the correct solution,
560 * But this works pretty good on wine and NT4.0 binaries
561 */
562 if (x1 == 0x2000000 )
563 {
564 *x2 = HKEY_CURRENT_USER;
565 return TRUE;
566 }
567
568 return FALSE;
569}
570
571
572/**************************************************************************
573 * RtlDosPathNameToNtPathName_U [NTDLL.338]
574 *
575 * FIXME: convert to UNC or whatever is expected here
576 */
577BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(LPWSTR from,
578 PUNICODE_STRING us,
579 DWORD x2,
580 DWORD x3)
581{
582 LPSTR fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
583
584 dprintf(("NTDLL: RtlDosPathNameToNtPathName_U(%08xh,%08h,%08xh,%08xh) not implemented.\n",
585 from,
586 us,
587 x2,
588 x3));
589
590 if (us)
591 RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
592
593 return TRUE;
594}
595
596
597/******************************************************************************
598 * RtlCreateEnvironment [NTDLL]
599 */
600DWORD WINAPI RtlCreateEnvironment(DWORD x1,
601 DWORD x2)
602{
603 dprintf(("NTDLL: RtlCreateEnvironment(%08xh, %08xh) not implemented.\n",
604 x1,
605 x2));
606
607 return 0;
608}
609
610
611/******************************************************************************
612 * RtlDestroyEnvironment [NTDLL]
613 */
614DWORD WINAPI RtlDestroyEnvironment(DWORD x)
615{
616 dprintf(("NTDLL: RtlDestroyEnvironment(%08xh) not implemented.\n",
617 x));
618
619 return 0;
620}
621
622
623/******************************************************************************
624 * RtlQueryEnvironmentVariable_U [NTDLL]
625 */
626DWORD WINAPI RtlQueryEnvironmentVariable_U(DWORD x1,
627 PUNICODE_STRING key,
628 PUNICODE_STRING val)
629{
630 dprintf(("NTDLL: RtlQueryEnvironmentVariable_U(%08xh,%08xh,%08xh) not implemented.\n",
631 x1,
632 key,
633 val));
634
635 return 0;
636}
637
Note: See TracBrowser for help on using the repository browser.