4 * Copyright 1996 Marcus Meissner
22 /**************************************************************************
23 * RtlLengthRequiredSid [NTDLL]
25 DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
27 return sizeof(DWORD)*nrofsubauths+sizeof(SID);
30 /**************************************************************************
31 * RtlLengthSid [NTDLL]
33 DWORD WINAPI RtlLengthSid(LPSID sid)
35 return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
38 /**************************************************************************
39 * RtlCreateAcl [NTDLL]
42 * This should return NTSTATUS
44 DWORD WINAPI RtlCreateAcl(LPACL acl,DWORD size,DWORD rev)
46 if (rev!=ACL_REVISION)
47 return STATUS_INVALID_PARAMETER;
49 return STATUS_BUFFER_TOO_SMALL;
51 return STATUS_INVALID_PARAMETER;
53 memset(acl,'\0',sizeof(ACL));
54 acl->AclRevision = rev;
60 /**************************************************************************
61 * RtlFirstFreeAce [NTDLL]
62 * looks for the AceCount+1 ACE, and if it is still within the alloced
63 * ACL, return a pointer to it
65 BOOL32 WINAPI RtlFirstFreeAce(LPACL acl,LPACE_HEADER *x)
71 ace = (LPACE_HEADER)(acl+1);
72 for (i=0;i<acl->AceCount;i++) {
73 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
75 ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
77 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
83 /**************************************************************************
86 DWORD /* NTSTATUS */ WINAPI RtlAddAce(LPACL acl,DWORD rev,DWORD xnrofaces,
87 LPACE_HEADER acestart,DWORD acelen)
89 LPACE_HEADER ace,targetace;
92 if (acl->AclRevision != ACL_REVISION)
93 return STATUS_INVALID_PARAMETER;
94 if (!RtlFirstFreeAce(acl,&targetace))
95 return STATUS_INVALID_PARAMETER;
96 nrofaces=0;ace=acestart;
97 while (((DWORD)ace-(DWORD)acestart)<acelen) {
99 ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
101 if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
102 return STATUS_INVALID_PARAMETER;
103 memcpy((LPBYTE)targetace,acestart,acelen);
104 acl->AceCount+=nrofaces;
108 /**************************************************************************
109 * RtlCreateSecurityDescriptor [NTDLL]
111 DWORD /* NTSTATUS */ WINAPI RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd,DWORD rev)
113 if (rev!=SECURITY_DESCRIPTOR_REVISION)
114 return STATUS_UNKNOWN_REVISION;
115 memset(lpsd,'\0',sizeof(*lpsd));
116 lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
120 /**************************************************************************
121 * RtlSetDaclSecurityDescriptor [NTDLL]
123 DWORD /* NTSTATUS */ WINAPI RtlSetDaclSecurityDescriptor ( LPSECURITY_DESCRIPTOR lpsd,BOOL32 daclpresent,LPACL dacl,BOOL32 dacldefaulted )
125 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
126 return STATUS_UNKNOWN_REVISION;
127 if (lpsd->Control & SE_SELF_RELATIVE)
128 return STATUS_INVALID_SECURITY_DESCR;
130 lpsd->Control &= ~SE_DACL_PRESENT;
133 lpsd->Control |= SE_DACL_PRESENT;
136 lpsd->Control |= SE_DACL_DEFAULTED;
138 lpsd->Control &= ~SE_DACL_DEFAULTED;
142 /**************************************************************************
143 * RtlSetSaclSecurityDescriptor [NTDLL]
145 DWORD /* NTSTATUS */ WINAPI RtlSetSaclSecurityDescriptor (
146 LPSECURITY_DESCRIPTOR lpsd,BOOL32 saclpresent,LPACL sacl,BOOL32 sacldefaulted
149 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
150 return STATUS_UNKNOWN_REVISION;
151 if (lpsd->Control & SE_SELF_RELATIVE)
152 return STATUS_INVALID_SECURITY_DESCR;
154 lpsd->Control &= ~SE_SACL_PRESENT;
157 lpsd->Control |= SE_SACL_PRESENT;
160 lpsd->Control |= SE_SACL_DEFAULTED;
162 lpsd->Control &= ~SE_SACL_DEFAULTED;
166 /**************************************************************************
167 * RtlSetOwnerSecurityDescriptor [NTDLL]
169 DWORD /* NTSTATUS */ WINAPI RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID owner,BOOL32 ownerdefaulted)
171 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
172 return STATUS_UNKNOWN_REVISION;
173 if (lpsd->Control & SE_SELF_RELATIVE)
174 return STATUS_INVALID_SECURITY_DESCR;
178 lpsd->Control |= SE_OWNER_DEFAULTED;
180 lpsd->Control &= ~SE_OWNER_DEFAULTED;
184 /**************************************************************************
185 * RtlSetOwnerSecurityDescriptor [NTDLL]
187 DWORD /* NTSTATUS */ WINAPI RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID group,BOOL32 groupdefaulted)
189 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
190 return STATUS_UNKNOWN_REVISION;
191 if (lpsd->Control & SE_SELF_RELATIVE)
192 return STATUS_INVALID_SECURITY_DESCR;
196 lpsd->Control |= SE_GROUP_DEFAULTED;
198 lpsd->Control &= ~SE_GROUP_DEFAULTED;
203 /**************************************************************************
204 * RtlNormalizeProcessParams [NTDLL]
206 LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
208 FIXME(ntdll,"(%p), stub\n",x);
212 /**************************************************************************
213 * RtlInitializeSid [NTDLL]
215 DWORD WINAPI RtlInitializeSid(LPSID lpsid,LPSID_IDENTIFIER_AUTHORITY lpsidauth,
220 if (a>=SID_MAX_SUB_AUTHORITIES)
222 lpsid->SubAuthorityCount = a;
223 lpsid->Revision = SID_REVISION;
224 memcpy(&(lpsid->IdentifierAuthority),lpsidauth,sizeof(SID_IDENTIFIER_AUTHORITY));
228 /**************************************************************************
229 * RtlSubAuthoritySid [NTDLL]
231 LPDWORD WINAPI RtlSubAuthoritySid(LPSID lpsid,DWORD nr)
233 return &(lpsid->SubAuthority[nr]);
236 /**************************************************************************
237 * RtlSubAuthorityCountSid [NTDLL]
239 LPBYTE WINAPI RtlSubAuthorityCountSid(LPSID lpsid)
241 return ((LPBYTE)lpsid)+1;
244 /**************************************************************************
247 DWORD WINAPI RtlCopySid(DWORD len,LPSID to,LPSID from)
249 if (len<(from->SubAuthorityCount*4+8))
250 return STATUS_BUFFER_TOO_SMALL;
251 memmove(to,from,from->SubAuthorityCount*4+8);
252 return STATUS_SUCCESS;
255 /**************************************************************************
256 * RtlAnsiStringToUnicodeString [NTDLL]
258 DWORD /* NTSTATUS */ WINAPI RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni,LPANSI_STRING ansi,BOOL32 doalloc)
260 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
263 return STATUS_INVALID_PARAMETER_2;
264 uni->Length = unilen;
266 uni->MaximumLength = unilen;
267 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
269 return STATUS_NO_MEMORY;
271 if (unilen>uni->MaximumLength)
272 return STATUS_BUFFER_OVERFLOW;
273 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
274 return STATUS_SUCCESS;
277 /**************************************************************************
278 * RtlOemStringToUnicodeString [NTDLL]
280 DWORD /* NTSTATUS */ WINAPI RtlOemStringToUnicodeString(LPUNICODE_STRING uni,LPSTRING ansi,BOOL32 doalloc)
282 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
285 return STATUS_INVALID_PARAMETER_2;
286 uni->Length = unilen;
288 uni->MaximumLength = unilen;
289 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
291 return STATUS_NO_MEMORY;
293 if (unilen>uni->MaximumLength)
294 return STATUS_BUFFER_OVERFLOW;
295 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
296 return STATUS_SUCCESS;
298 /**************************************************************************
299 * RtlMultiByteToUnicodeN [NTDLL]
300 * FIXME: multibyte support
302 DWORD /* NTSTATUS */ WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
310 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
311 lstrcpynAtoW(x,oemstr,len+1);
312 memcpy(unistr,x,len*2);
313 if (reslen) *reslen = len*2;
317 /**************************************************************************
318 * RtlOemToUnicodeN [NTDLL]
320 DWORD /* NTSTATUS */ WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
328 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
329 lstrcpynAtoW(x,oemstr,len+1);
330 memcpy(unistr,x,len*2);
331 if (reslen) *reslen = len*2;
335 /**************************************************************************
336 * RtlInitAnsiString [NTDLL]
338 VOID WINAPI RtlInitAnsiString(LPANSI_STRING target,LPCSTR source)
340 target->Length = target->MaximumLength = 0;
341 target->Buffer = (LPSTR)source;
344 target->Length = lstrlen32A(target->Buffer);
345 target->MaximumLength = target->Length+1;
347 /**************************************************************************
348 * RtlInitString [NTDLL]
350 VOID WINAPI RtlInitString(LPSTRING target,LPCSTR source)
352 target->Length = target->MaximumLength = 0;
353 target->Buffer = (LPSTR)source;
356 target->Length = lstrlen32A(target->Buffer);
357 target->MaximumLength = target->Length+1;
360 /**************************************************************************
361 * RtlInitUnicodeString [NTDLL]
363 VOID WINAPI RtlInitUnicodeString(LPUNICODE_STRING target,LPCWSTR source)
365 target->Length = target->MaximumLength = 0;
366 target->Buffer = (LPWSTR)source;
369 target->Length = lstrlen32W(target->Buffer)*2;
370 target->MaximumLength = target->Length+2;
373 /**************************************************************************
374 * RtlFreeUnicodeString [NTDLL]
376 VOID WINAPI RtlFreeUnicodeString(LPUNICODE_STRING str)
379 HeapFree(GetProcessHeap(),0,str->Buffer);
382 /**************************************************************************
383 * RtlUnicodeToOemN [NTDLL]
385 DWORD /* NTSTATUS */ WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen)
393 x=(LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+1);
394 lstrcpynWtoA(x,unistr,len+1);
395 memcpy(oemstr,x,len);
396 if (reslen) *reslen = len;
400 /**************************************************************************
401 * RtlUnicodeStringToOemString [NTDLL]
403 DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToOemString(LPANSI_STRING oem,LPUNICODE_STRING uni,BOOL32 alloc)
406 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
407 oem->MaximumLength = uni->Length/2+1;
409 oem->Length = uni->Length/2;
410 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
414 /**************************************************************************
415 * RtlUnicodeStringToAnsiString [NTDLL]
417 DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni,LPANSI_STRING oem,BOOL32 alloc)
420 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
421 oem->MaximumLength = uni->Length/2+1;
423 oem->Length = uni->Length/2;
424 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
428 /**************************************************************************
429 * RtlNtStatusToDosErro [NTDLL]
431 DWORD WINAPI RtlNtStatusToDosError(DWORD error)
433 FIXME(ntdll, "(%lx): map STATUS_ to ERROR_\n",error);
437 /**************************************************************************
438 * RtlGetNtProductType [NTDLL]
440 DWORD WINAPI RtlGetNtProductType(LPVOID x)
442 FIXME(ntdll, "(%p): stub\n", x);
446 /**************************************************************************
447 * RtlUpcaseUnicodeString [NTDLL]
449 DWORD WINAPI RtlUpcaseUnicodeString(LPUNICODE_STRING dest,LPUNICODE_STRING src,BOOL32 doalloc)
456 dest->MaximumLength = len;
457 dest->Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len);
459 return STATUS_NO_MEMORY;
462 if (dest->MaximumLength < len)
463 return STATUS_BUFFER_OVERFLOW;
464 s=dest->Buffer;t=src->Buffer;
465 /* len is in bytes */
466 for (i=0;i<len/2;i++)
467 s[i] = towupper(t[i]);
468 return STATUS_SUCCESS;
471 /**************************************************************************
472 * RtlxOemStringToUnicodeSize [NTDLL]
474 UINT32 WINAPI RtlxOemStringToUnicodeSize(LPSTRING str)
476 return str->Length*2+2;
479 /**************************************************************************
480 * RtlxAnsiStringToUnicodeSize [NTDLL]
482 UINT32 WINAPI RtlxAnsiStringToUnicodeSize(LPANSI_STRING str)
484 return str->Length*2+2;
487 /**************************************************************************
488 * RtlIsTextUnicode [NTDLL]
490 * Apply various feeble heuristics to guess whether
491 * the text buffer contains Unicode.
492 * FIXME: should implement more tests.
494 DWORD WINAPI RtlIsTextUnicode(LPVOID buf, DWORD len, DWORD *pf)
497 DWORD flags = -1, out_flags = 0;
504 * Apply various tests to the text string. According to the
505 * docs, each test "passed" sets the corresponding flag in
506 * the output flags. But some of the tests are mutually
507 * exclusive, so I don't see how you could pass all tests ...
510 /* Check for an odd length ... pass if even. */
512 out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
514 /* Check for the special unicode marker byte. */
516 out_flags |= IS_TEXT_UNICODE_SIGNATURE;
519 * Check whether the string passed all of the tests.
521 flags &= ITU_IMPLEMENTED_TESTS;
522 if ((out_flags & flags) != flags)
530 /**************************************************************************
531 * RtlDosPathNameToNtPathName_U [NTDLL]
533 * FIXME: convert to UNC or whatever is expected here
535 BOOL32 WINAPI RtlDosPathNameToNtPathName_U(
536 LPWSTR from,LPUNICODE_STRING us,DWORD x2,DWORD x3)
538 LPSTR fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
540 FIXME(ntdll,"(%s,%p,%08lx,%08lx)\n",fromA,us,x2,x3);
542 RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
546 /**************************************************************************
549 DWORD WINAPI NtOpenFile(DWORD x1,DWORD flags,DWORD x3,DWORD x4,DWORD alignment,DWORD x6)
551 FIXME(ntdll,"(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx): stub\n",
552 x1,flags,x3,x4,alignment,x6);
553 /* returns file io completion status */
558 /**************************************************************************
559 * NTDLL_chkstk (NTDLL.862)
562 * Should this be WINAPI?
564 void NTDLL_chkstk(void)
566 /* FIXME: should subtract %eax bytes from stack pointer */
567 FIXME(ntdll, "(void): stub\n");
571 /**************************************************************************
572 * NtOpenDirectoryObject [NTDLL.124]
574 DWORD WINAPI NtOpenDirectoryObject(DWORD x1,DWORD x2,DWORD x3)
576 FIXME(ntdll,"(%lx,%lx,%lx): stub\n",x1,x2,x3);
581 /******************************************************************************
582 * NtQueryDirectoryObject [NTDLL.149]
584 DWORD WINAPI NtQueryDirectoryObject( DWORD x1, DWORD x2, DWORD x3, DWORD x4,
585 DWORD x5, DWORD x6, DWORD x7 )
587 FIXME(ntdll,"(%lx,%lx,%lx,%lx,%lx,%lx,%lx): stub\n",x1,x2,x3,x4,x5,x6,x7);
592 /**************************************************************************
593 * RtlFreeAnsiString [NTDLL.373]
595 VOID WINAPI RtlFreeAnsiString(LPANSI_STRING AnsiString)
597 if( AnsiString->Buffer )
598 HeapFree( GetProcessHeap(),0,AnsiString->Buffer );
602 /******************************************************************************
603 * NtQuerySystemInformation [NTDLL.168]
605 DWORD WINAPI NtQuerySystemInformation( DWORD x1, DWORD x2, DWORD x3, DWORD x4 )
607 FIXME(ntdll,"(%lx,%lx,%lx,%lx): stub\n",x1,x2,x3,x4);
612 /******************************************************************************
613 * NtQueryObject [NTDLL.161]
615 DWORD WINAPI NtQueryObject( DWORD x1, DWORD x2 ,DWORD x3, DWORD x4, DWORD x5 )
617 FIXME(ntdll,"(%lx,%lx,%lx,%lx,%lx): stub\n",x1,x2,x3,x4,x5);
622 /******************************************************************************
623 * RtlTimeToElapsedTimeFields [NTDLL.502]
625 DWORD WINAPI RtlTimeToElapsedTimeFields( DWORD x1, DWORD x2 )
627 FIXME(ntdll,"(%lx,%lx): stub\n",x1,x2);
632 /******************************************************************************
633 * NtSetInformationProcess [NTDLL.207]
635 DWORD WINAPI NtSetInformationProcess( DWORD x1, DWORD x2, DWORD x3, DWORD x4 )
637 FIXME(ntdll,"(%lx,%lx,%lx,%lx): stub\n",x1,x2,x3,x4);
641 /******************************************************************************
642 * NtFsControlFile [NTDLL.108]
644 VOID WINAPI NtFsControlFile(VOID)
646 FIXME(ntdll,"(void): stub\n");
649 /******************************************************************************
650 * RtlExtendedLargeIntegerDivide [NTDLL.359]
652 INT32 WINAPI RtlExtendedLargeIntegerDivide(
653 LARGE_INTEGER dividend,
657 #if SIZEOF_LONG_LONG==8
658 long long x1 = *(long long*)÷nd;
661 *rest = x1 % divisor;
664 FIXME(ntdll,"((%d<<32)+%d,%d,%p), implement this using normal integer arithmetic!\n",dividend.HighPart,dividend.LowPart,divisor,rest);
669 /******************************************************************************
670 * RtlExtendedLargeIntegerMultiply [NTDLL.359]
671 * Note: This even works, since gcc returns 64bit values in eax/edx just like
672 * the caller expects. However... The relay code won't grok this I think.
674 long long /*LARGE_INTEGER*/ WINAPI RtlExtendedIntegerMultiply(
675 LARGE_INTEGER factor1,INT32 factor2
677 #if SIZEOF_LONG_LONG==8
678 return (*(long long*)&factor1)*factor2;
680 FIXME(ntdll,"((%d<<32)+%d,%ld), implement this using normal integer arithmetic!\n",factor1.HighPart,factor1.LowPart,factor2);
685 DWORD WINAPI NtOpenKey(DWORD x1,DWORD x2,DWORD x3) {
686 FIXME(ntdll,"(0x%08lx(%s),0x%08lx,0x%08lx),stub!\n",x1,
687 debugstr_w(*(LPWSTR*)x1),x2,x3);
689 return RegOpenKey32W(x2,*(LPWSTR*)x1,x3);
692 DWORD WINAPI NtQueryValueKey(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6) {
693 FIXME(ntdll,"(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx),stub!\n",
699 DWORD WINAPI NtQueryTimerResolution(DWORD x1,DWORD x2,DWORD x3) {
700 FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx), stub!\n",x1,x2,x3);
704 DWORD WINAPI NtClose(DWORD x1) {
705 FIXME(ntdll,"(0x%08lx),stub!\n",x1);
709 DWORD WINAPI NtQueryInformationProcess(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5) {
710 FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",