wine/misc/ntdll.c
Alexandre Julliard 17216f5637 Release 971012
Sun Oct 12 15:03:01 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [if1632/builtin.c] [if1632/relay.c]
	Relay debugging entry points are now generated on the fly for
	Win32 DLLs.

	* [include/stackframe.h]
	Added VA_LIST16 type and macros to access arguments on the 16-bit
	stack.

	* [memory/global.c]
	Fixed GlobalHandle32 to work with fixed blocks.

	* [misc/ddeml.c] (New file)
	Added a lot of stubs for DDEML functions.

	* [objects/dc.c]
	Added Get/SetGraphicsMode().

	* [objects/gdiobj.c] [windows/winpos.c]
	Added a few stubs.

	* [tools/build.c]
	Removed 'byte', 'word', 'long' and 'return' entry points for Win32.
	'register' functions can no longer take arguments in Win32.
 	The Win32 NE module is now generated by MODULE_CreateDummyModule.
	CallFrom32 callbacks removed except for register functions.

Fri Oct 10 18:22:18 1997  John Harvey <john@division.co.uk>

	* [graphics/win16drv/Makefile.in] [graphics/win16drv/brush.c]
	  [graphics/win16drv/graphics.c] [graphics/win16drv/init.c]
	  [graphics/win16drv/objects.c] [graphics/win16drv/pen.c]
	  [graphics/win16drv/prtdrv.c] [graphics/win16drv/text.c]
	  [include/callback.h] [include/win16drv.h]
	Added support for pens and brushes in SelectObject. Added support
	for LineTo, MoveToEx, PatBlt (very preliminary), Polygon and
	Rectangle. Text is drawn in the correct place more often. These
	changes may only work with the Windows Postscript driver since
	many other drivers now need more GDI support.

Tue Oct  7 21:06:23 1997  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [debugger/expr.c]
	Fixed typo for the >> operator.

	* [loader/task.c]
	Fixed SwitchStackTo(); it used to return with the new stack placed
	four bytes too high in memory.

	* [loader/ne_resource.c]
	Removed problematic nametable code introduced in Wine 970914.

Tue Oct  7 02:24:12 1997  Dimitrie O. Paun  <dimi@cs.toronto.edu>

	* [controls/commctrl.c]
	Added this files to hold functions from the comctl32.dll
	Added to this files some functions scattered in different places
	(such as InitCommonControls) and added some new ones as well.

	* [include/syscolor.h] [windows/syscolor.c]
	Added proper entries for all possible COLOR_* values.

	* [objects/brush.c]
	Modified GetSysColorBrush to return the correct brush for 
	all possible COLOR_* constants.

Sat Oct  4 23:35:20 1997  U.Bonnes <bon@elektron.ikp.physik.th-darmstadt.de>

	* [loader/module.c] [scheduler/process.c] [win32/environment.c]
	Another approach to get access to an unrestricted commandline.

	* [misc/crtdll.c]
	Make fclose work again.

	* [if1632/crtdll.spec]
	Use sprintf for crtdll-sprintf again as e.g. %g is not available
	for wsprintf.

	* [misc/wsprintf.c]
	Make WPR_STRING work in more situations.
	Added debug output for the wsprintf functions.

	* [misc/crtdll.c] [misc/main.c]
	Use argv[0] as comand with CRTDLL_system.

Fri Oct  3 14:00:29 MET DST 1997  Jan Willamowius  <jan@janhh.shnet.org>

	* [*/*]
        Removed some compiler warnings.

	* [msdos/int15.c]
        New INT 15 handler.
1997-10-12 16:30:17 +00:00

522 lines
15 KiB
C

/*
* NT basis DLL
*
* Copyright 1996 Marcus Meissner
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
#include "win.h"
#include "windows.h"
#include "ntdll.h"
#include "heap.h"
#include "stddebug.h"
#include "debug.h"
#include "module.h"
#include "heap.h"
/**************************************************************************
* RtlLengthRequiredSid [NTDLL]
*/
DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
{
return sizeof(DWORD)*nrofsubauths+sizeof(SID);
}
/**************************************************************************
* RtlLengthSid [NTDLL]
*/
DWORD WINAPI RtlLengthSid(LPSID sid)
{
return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
}
/**************************************************************************
* RtlCreateAcl [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlCreateAcl(LPACL acl,DWORD size,DWORD rev)
{
if (rev!=ACL_REVISION)
return STATUS_INVALID_PARAMETER;
if (size<sizeof(ACL))
return STATUS_BUFFER_TOO_SMALL;
if (size>0xFFFF)
return STATUS_INVALID_PARAMETER;
memset(acl,'\0',sizeof(ACL));
acl->AclRevision = rev;
acl->AclSize = size;
acl->AceCount = 0;
return 0;
}
/**************************************************************************
* RtlFirstFreeAce [NTDLL]
* looks for the AceCount+1 ACE, and if it is still within the alloced
* ACL, return a pointer to it
*/
BOOL32 WINAPI RtlFirstFreeAce(LPACL acl,LPACE_HEADER *x)
{
LPACE_HEADER ace;
int i;
*x = 0;
ace = (LPACE_HEADER)(acl+1);
for (i=0;i<acl->AceCount;i++) {
if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
return 0;
ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
}
if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
return 0;
*x = ace;
return 1;
}
/**************************************************************************
* RtlAddAce [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlAddAce(LPACL acl,DWORD rev,DWORD xnrofaces,
LPACE_HEADER acestart,DWORD acelen)
{
LPACE_HEADER ace,targetace;
int nrofaces;
if (acl->AclRevision != ACL_REVISION)
return STATUS_INVALID_PARAMETER;
if (!RtlFirstFreeAce(acl,&targetace))
return STATUS_INVALID_PARAMETER;
nrofaces=0;ace=acestart;
while (((DWORD)ace-(DWORD)acestart)<acelen) {
nrofaces++;
ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
}
if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
return STATUS_INVALID_PARAMETER;
memcpy((LPBYTE)targetace,acestart,acelen);
acl->AceCount+=nrofaces;
return 0;
}
/**************************************************************************
* RtlCreateSecurityDescriptor [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd,DWORD rev)
{
if (rev!=SECURITY_DESCRIPTOR_REVISION)
return STATUS_UNKNOWN_REVISION;
memset(lpsd,'\0',sizeof(*lpsd));
lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
return 0;
}
/**************************************************************************
* RtlSetDaclSecurityDescriptor [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlSetDaclSecurityDescriptor ( LPSECURITY_DESCRIPTOR lpsd,BOOL32 daclpresent,LPACL dacl,BOOL32 dacldefaulted )
{
if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
return STATUS_UNKNOWN_REVISION;
if (lpsd->Control & SE_SELF_RELATIVE)
return STATUS_INVALID_SECURITY_DESCR;
if (!daclpresent) {
lpsd->Control &= ~SE_DACL_PRESENT;
return 0;
}
lpsd->Control |= SE_DACL_PRESENT;
lpsd->Dacl = dacl;
if (dacldefaulted)
lpsd->Control |= SE_DACL_DEFAULTED;
else
lpsd->Control &= ~SE_DACL_DEFAULTED;
return 0;
}
/**************************************************************************
* RtlSetSaclSecurityDescriptor [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlSetSaclSecurityDescriptor (
LPSECURITY_DESCRIPTOR lpsd,BOOL32 saclpresent,LPACL sacl,BOOL32 sacldefaulted
)
{
if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
return STATUS_UNKNOWN_REVISION;
if (lpsd->Control & SE_SELF_RELATIVE)
return STATUS_INVALID_SECURITY_DESCR;
if (!saclpresent) {
lpsd->Control &= ~SE_SACL_PRESENT;
return 0;
}
lpsd->Control |= SE_SACL_PRESENT;
lpsd->Sacl = sacl;
if (sacldefaulted)
lpsd->Control |= SE_SACL_DEFAULTED;
else
lpsd->Control &= ~SE_SACL_DEFAULTED;
return 0;
}
/**************************************************************************
* RtlSetOwnerSecurityDescriptor [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID owner,BOOL32 ownerdefaulted)
{
if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
return STATUS_UNKNOWN_REVISION;
if (lpsd->Control & SE_SELF_RELATIVE)
return STATUS_INVALID_SECURITY_DESCR;
lpsd->Owner = owner;
if (ownerdefaulted)
lpsd->Control |= SE_OWNER_DEFAULTED;
else
lpsd->Control &= ~SE_OWNER_DEFAULTED;
return 0;
}
/**************************************************************************
* RtlSetOwnerSecurityDescriptor [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID group,BOOL32 groupdefaulted)
{
if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
return STATUS_UNKNOWN_REVISION;
if (lpsd->Control & SE_SELF_RELATIVE)
return STATUS_INVALID_SECURITY_DESCR;
lpsd->Group = group;
if (groupdefaulted)
lpsd->Control |= SE_GROUP_DEFAULTED;
else
lpsd->Control &= ~SE_GROUP_DEFAULTED;
return 0;
}
/**************************************************************************
* RtlNormalizeProcessParams [NTDLL]
*/
LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
{
fprintf(stdnimp,"RtlNormalizeProcessParams(%p), stub.\n",x);
return x;
}
/**************************************************************************
* RtlInitializeSid [NTDLL]
*/
DWORD WINAPI RtlInitializeSid(LPSID lpsid,LPSID_IDENTIFIER_AUTHORITY lpsidauth,
DWORD c)
{
BYTE a = c&0xff;
if (a>=SID_MAX_SUB_AUTHORITIES)
return a;
lpsid->SubAuthorityCount = a;
lpsid->Revision = SID_REVISION;
memcpy(&(lpsid->IdentifierAuthority),lpsidauth,sizeof(SID_IDENTIFIER_AUTHORITY));
return 0;
}
/**************************************************************************
* RtlSubAuthoritySid [NTDLL]
*/
LPDWORD WINAPI RtlSubAuthoritySid(LPSID lpsid,DWORD nr)
{
return &(lpsid->SubAuthority[nr]);
}
/**************************************************************************
* RtlSubAuthorityCountSid [NTDLL]
*/
LPBYTE WINAPI RtlSubAuthorityCountSid(LPSID lpsid)
{
return ((LPBYTE)lpsid)+1;
}
/**************************************************************************
* RtlCopySid [NTDLL]
*/
DWORD WINAPI RtlCopySid(DWORD len,LPSID to,LPSID from)
{
if (len<(from->SubAuthorityCount*4+8))
return STATUS_BUFFER_TOO_SMALL;
memmove(to,from,from->SubAuthorityCount*4+8);
return STATUS_SUCCESS;
}
/**************************************************************************
* RtlAnsiStringToUnicodeString [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni,LPANSI_STRING ansi,BOOL32 doalloc)
{
DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
if (unilen>0xFFFF)
return STATUS_INVALID_PARAMETER_2;
uni->Length = unilen;
if (doalloc) {
uni->MaximumLength = unilen;
uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
if (!uni->Buffer)
return STATUS_NO_MEMORY;
}
if (unilen>uni->MaximumLength)
return STATUS_BUFFER_OVERFLOW;
lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
return STATUS_SUCCESS;
}
/**************************************************************************
* RtlOemStringToUnicodeString [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlOemStringToUnicodeString(LPUNICODE_STRING uni,LPSTRING ansi,BOOL32 doalloc)
{
DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
if (unilen>0xFFFF)
return STATUS_INVALID_PARAMETER_2;
uni->Length = unilen;
if (doalloc) {
uni->MaximumLength = unilen;
uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
if (!uni->Buffer)
return STATUS_NO_MEMORY;
}
if (unilen>uni->MaximumLength)
return STATUS_BUFFER_OVERFLOW;
lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
return STATUS_SUCCESS;
}
/**************************************************************************
* RtlMultiByteToUnicodeN [NTDLL]
* FIXME: multibyte support
*/
DWORD /* NTSTATUS */ WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
{
DWORD len;
LPWSTR x;
len = oemlen;
if (unilen/2 < len)
len = unilen/2;
x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
lstrcpynAtoW(x,oemstr,len+1);
memcpy(unistr,x,len*2);
if (reslen) *reslen = len*2;
return 0;
}
/**************************************************************************
* RtlOemToUnicodeN [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
{
DWORD len;
LPWSTR x;
len = oemlen;
if (unilen/2 < len)
len = unilen/2;
x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
lstrcpynAtoW(x,oemstr,len+1);
memcpy(unistr,x,len*2);
if (reslen) *reslen = len*2;
return 0;
}
/**************************************************************************
* RtlInitString [NTDLL]
*/
VOID WINAPI RtlInitAnsiString(LPANSI_STRING target,LPCSTR source)
{
target->Length = target->MaximumLength = 0;
target->Buffer = (LPSTR)source;
if (!source)
return;
target->Length = lstrlen32A(target->Buffer);
target->MaximumLength = target->Length+1;
}
/**************************************************************************
* RtlInitString [NTDLL]
*/
VOID WINAPI RtlInitString(LPSTRING target,LPCSTR source)
{
target->Length = target->MaximumLength = 0;
target->Buffer = (LPSTR)source;
if (!source)
return;
target->Length = lstrlen32A(target->Buffer);
target->MaximumLength = target->Length+1;
}
/**************************************************************************
* RtlInitUnicodeString [NTDLL]
*/
VOID WINAPI RtlInitUnicodeString(LPUNICODE_STRING target,LPCWSTR source)
{
target->Length = target->MaximumLength = 0;
target->Buffer = (LPWSTR)source;
if (!source)
return;
target->Length = lstrlen32W(target->Buffer)*2;
target->MaximumLength = target->Length+2;
}
/**************************************************************************
* RtlFreeUnicodeString [NTDLL]
*/
VOID WINAPI RtlFreeUnicodeString(LPUNICODE_STRING str)
{
if (str->Buffer)
HeapFree(GetProcessHeap(),0,str->Buffer);
}
/**************************************************************************
* RtlUnicodeToOemN [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen)
{
DWORD len;
LPSTR x;
len = oemlen;
if (unilen/2 < len)
len = unilen/2;
x=(LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+1);
lstrcpynWtoA(x,unistr,len+1);
memcpy(oemstr,x,len);
if (reslen) *reslen = len;
return 0;
}
/**************************************************************************
* RtlUnicodeStringToOemString [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToOemString(LPANSI_STRING oem,LPUNICODE_STRING uni,BOOL32 alloc)
{
if (alloc) {
oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
oem->MaximumLength = uni->Length/2+1;
}
oem->Length = uni->Length/2;
lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
return 0;
}
/**************************************************************************
* RtlUnicodeStringToAnsiString [NTDLL]
*/
DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni,LPANSI_STRING oem,BOOL32 alloc)
{
if (alloc) {
oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
oem->MaximumLength = uni->Length/2+1;
}
oem->Length = uni->Length/2;
lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
return 0;
}
/**************************************************************************
* RtlNtStatusToDosErro [NTDLL]
*/
DWORD WINAPI RtlNtStatusToDosError(DWORD error)
{
/* FIXME: map STATUS_ to ERROR_ */
return error;
}
/**************************************************************************
* RtlGetNtProductType [NTDLL]
*/
DWORD WINAPI RtlGetNtProductType(LPVOID x)
{
/* FIXME : find documentation for this one */
return 0;
}
/**************************************************************************
* RtlUpcaseUnicodeString [NTDLL]
*/
DWORD WINAPI RtlUpcaseUnicodeString(LPUNICODE_STRING dest,LPUNICODE_STRING src,BOOL32 doalloc)
{
LPWSTR s,t;
DWORD i,len;
len = src->Length;
if (doalloc) {
dest->MaximumLength = len;
dest->Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len);
if (!dest->Buffer)
return STATUS_NO_MEMORY;
}
if (dest->MaximumLength < len)
return STATUS_BUFFER_OVERFLOW;
s=dest->Buffer;t=src->Buffer;
/* len is in bytes */
for (i=0;i<len/2;i++)
s[i]=toupper(t[i]);
return STATUS_SUCCESS;
}
/**************************************************************************
* RtlxOemStringToUnicodeSize [NTDLL]
*/
UINT32 WINAPI RtlxOemStringToUnicodeSize(LPSTRING str)
{
return str->Length*2+2;
}
/**************************************************************************
* RtlxAnsiStringToUnicodeSize [NTDLL]
*/
UINT32 WINAPI RtlxAnsiStringToUnicodeSize(LPANSI_STRING str)
{
return str->Length*2+2;
}
/**************************************************************************
* RtlDosPathNameToNtPathName_U [NTDLL]
*
* FIXME: convert to UNC or whatever is expected here
*/
BOOL32 WINAPI RtlDosPathNameToNtPathName_U(
LPWSTR from,LPUNICODE_STRING us,DWORD x2,DWORD x3)
{
LPSTR fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
fprintf(stderr,"RtlDosPathNameToNtPathName_U(%s,%p,%08lx,%08lx)\n",
fromA,us,x2,x3
);
if (us)
RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
return TRUE;
}
/**************************************************************************
* NtOpenFile [NTDLL]
*/
DWORD WINAPI NtOpenFile(DWORD x1,DWORD flags,DWORD x3,DWORD x4,DWORD alignment,DWORD x6)
{
fprintf(stderr,"NtOpenFile(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx)\n",
x1,flags,x3,x4,alignment,x6
);
/* returns file io completion status */
return 0;
}
/**************************************************************************
* NTDLL_chkstk (NTDLL.862)
*/
void NTDLL_chkstk(void)
{
/* FIXME: should subtract %eax bytes from stack pointer */
}