Moved heap functions to ntdll.

Got rid of internal heap flags.
Reimplemented MapLS to not depend on the segptr heap.
This commit is contained in:
Alexandre Julliard 2001-12-19 19:16:27 +00:00
parent 024d39fcb1
commit b0f586178a
14 changed files with 1791 additions and 1785 deletions

View File

@ -500,15 +500,15 @@ debug_channels (comm debugstr dll int resource stress thunk toolhelp win32)
@ stub Heap32ListFirst
@ stub Heap32ListNext
@ stub Heap32Next
@ stdcall HeapAlloc(long long long) HeapAlloc
@ forward HeapAlloc ntdll.RtlAllocateHeap
@ stdcall HeapCompact(long long) HeapCompact
@ stdcall HeapCreate(long long long) HeapCreate
@ stdcall HeapDestroy(long) HeapDestroy
@ stdcall HeapFree(long long ptr) HeapFree
@ forward HeapFree ntdll.RtlFreeHeap
@ stdcall HeapLock(long) HeapLock
@ stdcall HeapReAlloc(long long ptr long) HeapReAlloc
@ forward HeapReAlloc ntdll.RtlReAllocateHeap
@ stub HeapSetFlags
@ stdcall HeapSize(long long ptr) HeapSize
@ forward HeapSize ntdll.RtlSizeHeap
@ stdcall HeapUnlock(long) HeapUnlock
@ stdcall HeapValidate(long long ptr) HeapValidate
@ stdcall HeapWalk(long ptr) HeapWalk

View File

@ -11,6 +11,7 @@ C_SRCS = \
exception.c \
error.c \
file.c \
heap.c \
large_int.c \
misc.c \
nt.c \

View File

@ -14,6 +14,7 @@
#include "thread.h"
#include "winbase.h"
#include "winnt.h"
#include "ntddk.h"
#include "wtypes.h"
DECLARE_DEBUG_CHANNEL(tid);
@ -50,9 +51,9 @@ static inline struct debug_info *get_info(void)
tmp.out_pos = tmp.output;
}
if (!GetProcessHeap()) return &tmp;
/* setup the temp structure in case HeapAlloc wants to print something */
/* setup the temp structure in case RtlAllocateHeap wants to print something */
NtCurrentTeb()->debug_info = &tmp;
info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) );
info->str_pos = info->strings;
info->out_pos = info->output;
NtCurrentTeb()->debug_info = info;

1424
dlls/ntdll/heap.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -300,7 +300,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub RtlCheckRegistryKey
@ stub RtlClearAllBits
@ stdcall RtlClearBits(long long long) RtlClearBits
@ stub RtlCompactHeap
@ stdcall RtlCompactHeap(long long) RtlCompactHeap
@ stdcall RtlCompareMemory(ptr ptr long) RtlCompareMemory
@ stub RtlCompareMemoryUlong
@ stdcall RtlCompareString(ptr ptr long) RtlCompareString
@ -406,7 +406,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub RtlGetNtGlobalFlags
@ stdcall RtlGetNtProductType(ptr) RtlGetNtProductType
@ stdcall RtlGetOwnerSecurityDescriptor(ptr ptr ptr) RtlGetOwnerSecurityDescriptor
@ stub RtlGetProcessHeaps
@ stdcall RtlGetProcessHeaps(long ptr) RtlGetProcessHeaps
@ stdcall RtlGetSaclSecurityDescriptor(ptr ptr ptr ptr)RtlGetSaclSecurityDescriptor
@ stub RtlGetUserInfoHeap
@ stdcall RtlIdentifierAuthoritySid(ptr) RtlIdentifierAuthoritySid
@ -446,7 +446,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stdcall RtlLengthSecurityDescriptor(ptr) RtlLengthSecurityDescriptor
@ stdcall RtlLengthSid(ptr) RtlLengthSid
@ stub RtlLocalTimeToSystemTime
@ stub RtlLockHeap
@ stdcall RtlLockHeap(long) RtlLockHeap
@ stub RtlLookupElementGenericTable
@ stdcall RtlMakeSelfRelativeSD(ptr ptr ptr) RtlMakeSelfRelativeSD
@ stub RtlMapGenericMask
@ -482,7 +482,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stdcall RtlRaiseException(ptr) RtlRaiseException
@ stdcall RtlRaiseStatus(long) RtlRaiseStatus
@ stub RtlRandom
@ stub RtlReAllocateHeap
@ stdcall RtlReAllocateHeap(long long ptr long) RtlReAllocateHeap
@ stub RtlRealPredecessor
@ stub RtlRealSuccessor
@ stdcall RtlReleasePebLock() RtlReleasePebLock
@ -508,7 +508,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub RtlSetTimeZoneInformation
@ stub RtlSetUserFlagsHeap
@ stub RtlSetUserValueHeap
@ stdcall RtlSizeHeap(long long long) HeapSize
@ stdcall RtlSizeHeap(long long ptr) RtlSizeHeap
@ stub RtlSplay
@ stub RtlStartRXact
@ stdcall RtlSubAuthorityCountSid(ptr) RtlSubAuthorityCountSid
@ -532,7 +532,7 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stdcall RtlUnicodeToMultiByteSize(ptr wstr long) RtlUnicodeToMultiByteSize
@ stdcall RtlUnicodeToOemN(ptr long ptr ptr long) RtlUnicodeToOemN
@ stub RtlUniform
@ stub RtlUnlockHeap
@ stdcall RtlUnlockHeap(long) RtlUnlockHeap
@ stdcall RtlUnwind(ptr ptr ptr long) RtlUnwind
@ stub RtlUpcaseUnicodeChar
@ stdcall RtlUpcaseUnicodeString(ptr ptr long) RtlUpcaseUnicodeString
@ -548,9 +548,9 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub RtlValidAcl
@ stdcall RtlValidSecurityDescriptor(ptr) RtlValidSecurityDescriptor
@ stdcall RtlValidSid(ptr) RtlValidSid
@ stub RtlValidateHeap
@ stdcall RtlValidateHeap(long long ptr) RtlValidateHeap
@ stub RtlValidateProcessHeaps
@ stub RtlWalkHeap
@ stdcall RtlWalkHeap(long ptr) RtlWalkHeap
@ stub RtlWriteRegistryValue
@ stub RtlZeroHeap
@ stdcall RtlZeroMemory(ptr long) RtlZeroMemory

View File

@ -212,64 +212,6 @@ void WINAPI RtlDumpResource(LPRTL_RWLOCK rwl)
}
}
/*
* heap functions
*/
/******************************************************************************
* RtlCreateHeap [NTDLL.@]
*/
HANDLE WINAPI RtlCreateHeap(
ULONG Flags,
PVOID BaseAddress,
ULONG SizeToReserve,
ULONG SizeToCommit,
PVOID Unknown,
PRTL_HEAP_DEFINITION Definition)
{
FIXME("(0x%08lx, %p, 0x%08lx, 0x%08lx, %p, %p) semi-stub\n",
Flags, BaseAddress, SizeToReserve, SizeToCommit, Unknown, Definition);
return HeapCreate ( Flags, SizeToCommit, SizeToReserve);
}
/******************************************************************************
* RtlAllocateHeap [NTDLL.@]
*/
PVOID WINAPI RtlAllocateHeap(
HANDLE Heap,
ULONG Flags,
ULONG Size)
{
TRACE("(0x%08x, 0x%08lx, 0x%08lx) semi stub\n",
Heap, Flags, Size);
return HeapAlloc(Heap, Flags, Size);
}
/******************************************************************************
* RtlFreeHeap [NTDLL.@]
*/
BOOLEAN WINAPI RtlFreeHeap(
HANDLE Heap,
ULONG Flags,
PVOID Address)
{
TRACE("(0x%08x, 0x%08lx, %p) semi stub\n",
Heap, Flags, Address);
return HeapFree(Heap, Flags, Address);
}
/******************************************************************************
* RtlDestroyHeap [NTDLL.@]
*/
HANDLE WINAPI RtlDestroyHeap(
HANDLE Heap)
{
TRACE("(0x%08x) semi stub\n", Heap);
if (!HeapDestroy(Heap)) return Heap;
return 0;
}
/*
* misc functions
*/

View File

@ -143,25 +143,32 @@ ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) {
SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
ICOM_THIS(IMalloc16Impl,iface);
TRACE("(%p)->Alloc(%ld)\n",This,cb);
return MapLS( HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, cb ) );
return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) );
}
/******************************************************************************
* IMalloc16_Realloc [COMPOBJ.504]
*/
SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) {
ICOM_THIS(IMalloc16Impl,iface);
TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
return MapLS( HeapReAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv), cb ) );
SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
{
SEGPTR ret;
ICOM_THIS(IMalloc16Impl,iface);
TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb);
ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) );
UnMapLS(pv);
return ret;
}
/******************************************************************************
* IMalloc16_Free [COMPOBJ.505]
*/
VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv) {
ICOM_THIS(IMalloc16Impl,iface);
TRACE("(%p)->Free(%08lx)\n",This,pv);
HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
{
void *ptr = MapSL(pv);
ICOM_THIS(IMalloc16Impl,iface);
TRACE("(%p)->Free(%08lx)\n",This,pv);
UnMapLS(pv);
HeapFree( GetProcessHeap(), 0, ptr );
}
/******************************************************************************
@ -171,7 +178,7 @@ DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,SEGPTR pv)
{
ICOM_CTHIS(IMalloc16Impl,iface);
TRACE("(%p)->GetSize(%08lx)\n",This,pv);
return HeapSize( GetProcessHeap(), HEAP_WINE_SEGPTR, MapSL(pv) );
return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
}
/******************************************************************************

View File

@ -95,7 +95,7 @@ HFONT WIN16DRV_FONT_SelectObject( DC * dc, HFONT hfont)
&physDev->lf, 0, 0);
if( physDev->FontInfo &&
HeapSize( GetProcessHeap(), HEAP_WINE_SEGPTR, physDev->FontInfo ) < nSize )
HeapSize( GetProcessHeap(), 0, physDev->FontInfo ) < nSize )
{
SEGPTR_FREE( physDev->FontInfo );
physDev->FontInfo = NULL;

View File

@ -14,18 +14,16 @@
#include "wine/unicode.h"
#include "wine/windef16.h" /* for SEGPTR */
extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
/* SEGPTR helper macros */
#define SEGPTR_ALLOC(size) \
(HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, (size) ))
(HeapAlloc( GetProcessHeap(), 0, (size) ))
#define SEGPTR_NEW(type) \
((type *)HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, sizeof(type) ))
((type *)HeapAlloc( GetProcessHeap(), 0, sizeof(type) ))
#define SEGPTR_STRDUP_WtoA(str) \
(HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), HEAP_WINE_SEGPTR, (str) ) : (LPSTR)(str))
(HIWORD(str) ? HEAP_strdupWtoA( GetProcessHeap(), 0, (str) ) : (LPSTR)(str))
#define SEGPTR_FREE(ptr) \
(HIWORD(ptr) ? HeapFree( GetProcessHeap(), HEAP_WINE_SEGPTR, (ptr) ) : 0)
(HIWORD(ptr) ? HeapFree( GetProcessHeap(), 0, (ptr) ) : 0)
#define SEGPTR_GET(ptr) MapLS(ptr)
inline static LPSTR SEGPTR_STRDUP( LPCSTR str )
@ -33,7 +31,7 @@ inline static LPSTR SEGPTR_STRDUP( LPCSTR str )
if (HIWORD(str))
{
INT len = strlen(str) + 1;
LPSTR p = HeapAlloc( GetProcessHeap(), HEAP_WINE_SEGPTR, len );
LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
if (p) memcpy( p, str, len );
return p;
}

View File

@ -723,6 +723,7 @@ BOOLEAN WINAPI RtlUnlockHeap(HANDLE);
ULONG WINAPI RtlSizeHeap(HANDLE,ULONG,PVOID);
BOOLEAN WINAPI RtlValidateHeap(HANDLE,ULONG,PCVOID);
ULONG WINAPI RtlGetProcessHeaps(ULONG,HANDLE*);
NTSTATUS WINAPI RtlWalkHeap(HANDLE,PVOID);
/* exception */

View File

@ -985,20 +985,33 @@ BOOL WINAPI GetVersionExW(OSVERSIONINFOW*);
/*int WinMain(HINSTANCE, HINSTANCE prev, char *cmd, int show);*/
LONG WINAPI RtlEnterCriticalSection( CRITICAL_SECTION *crit );
LONG WINAPI RtlLeaveCriticalSection( CRITICAL_SECTION *crit );
LONG WINAPI RtlDeleteCriticalSection( CRITICAL_SECTION *crit );
BOOL WINAPI RtlTryEnterCriticalSection( CRITICAL_SECTION *crit );
/* FIXME: need to use defines because we don't have proper imports yet */
/* FIXME: need to use defines because we don't have proper imports everywhere yet */
#ifndef have_proper_imports
LONG WINAPI RtlEnterCriticalSection( CRITICAL_SECTION *crit );
LONG WINAPI RtlLeaveCriticalSection( CRITICAL_SECTION *crit );
LONG WINAPI RtlDeleteCriticalSection( CRITICAL_SECTION *crit );
BOOL WINAPI RtlTryEnterCriticalSection( CRITICAL_SECTION *crit );
PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,ULONG);
BOOLEAN WINAPI RtlFreeHeap(HANDLE,ULONG,PVOID);
PVOID WINAPI RtlReAllocateHeap(HANDLE,ULONG,PVOID,ULONG);
ULONG WINAPI RtlSizeHeap(HANDLE,ULONG,PVOID);
#define HeapAlloc(heap,flags,size) RtlAllocateHeap(heap,flags,size)
#define HeapFree(heap,flags,ptr) RtlFreeHeap(heap,flags,ptr)
#define HeapReAlloc(heap,flags,ptr,size) RtlReAllocateHeap(heap,flags,ptr,size)
#define HeapSize(heap,flags,ptr) RtlSizeHeap(heap,flags,ptr)
#define EnterCriticalSection(crit) RtlEnterCriticalSection(crit)
#define LeaveCriticalSection(crit) RtlLeaveCriticalSection(crit)
#define DeleteCriticalSection(crit) RtlDeleteCriticalSection(crit)
#define TryEnterCriticalSection(crit) RtlTryEnterCriticalSection(crit)
#if 0
void WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCrit);
void WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCrit);
BOOL WINAPI TryEnterCriticalSection(CRITICAL_SECTION *lpCrit);
void WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCrit);
#else
LPVOID WINAPI HeapAlloc(HANDLE,DWORD,DWORD);
BOOL WINAPI HeapFree(HANDLE,DWORD,LPVOID);
LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,DWORD);
DWORD WINAPI HeapSize(HANDLE,DWORD,LPVOID);
void WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCrit);
void WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCrit);
BOOL WINAPI TryEnterCriticalSection(CRITICAL_SECTION *lpCrit);
void WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCrit);
#endif
void WINAPI InitializeCriticalSection(CRITICAL_SECTION *lpCrit);
@ -1237,14 +1250,10 @@ BOOL WINAPI GetUserNameA(LPSTR,LPDWORD);
BOOL WINAPI GetUserNameW(LPWSTR,LPDWORD);
#define GetUserName WINELIB_NAME_AW(GetUserName)
VOID WINAPI GlobalMemoryStatus(LPMEMORYSTATUS);
LPVOID WINAPI HeapAlloc(HANDLE,DWORD,DWORD);
DWORD WINAPI HeapCompact(HANDLE,DWORD);
HANDLE WINAPI HeapCreate(DWORD,DWORD,DWORD);
BOOL WINAPI HeapDestroy(HANDLE);
BOOL WINAPI HeapFree(HANDLE,DWORD,LPVOID);
BOOL WINAPI HeapLock(HANDLE);
LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,DWORD);
DWORD WINAPI HeapSize(HANDLE,DWORD,LPVOID);
BOOL WINAPI HeapUnlock(HANDLE);
BOOL WINAPI HeapValidate(HANDLE,DWORD,LPCVOID);
BOOL WINAPI HeapWalk(HANDLE,LPPROCESS_HEAP_ENTRY);

View File

@ -524,11 +524,7 @@ typedef struct _SINGLE_LIST_ENTRY {
/* This flag allows it to create heaps shared by all processes under win95,
FIXME: correct name */
#define HEAP_SHARED 0x04000000
#define HEAP_WINE_SEGPTR 0x10000000 /* Not a Win32 flag */
#define HEAP_WINE_CODESEG 0x20000000 /* Not a Win32 flag */
#define HEAP_WINE_CODE16SEG 0x40000000 /* Not a Win32 flag */
#define HEAP_SHARED 0x04000000
/* Processor feature flags. */
#define PF_FLOATING_POINT_PRECISION_ERRATA 0

File diff suppressed because it is too large Load Diff

View File

@ -518,6 +518,84 @@ DWORD WINAPI MemoryWrite16( WORD sel, DWORD offset, void *buffer, DWORD count )
*
*/
struct mapls_entry
{
struct mapls_entry *next;
void *addr; /* linear address */
int count; /* ref count */
WORD sel; /* selector */
};
static struct mapls_entry *first_entry;
/***********************************************************************
* MapLS (KERNEL32.@)
* MapLS (KERNEL.358)
*
* Maps linear pointer to segmented.
*/
SEGPTR WINAPI MapLS( LPCVOID ptr )
{
struct mapls_entry *entry, *free = NULL;
void *base;
SEGPTR ret = 0;
if (!HIWORD(ptr)) return (SEGPTR)ptr;
base = (char *)ptr - ((unsigned int)ptr & 0x7fff);
HeapLock( GetProcessHeap() );
for (entry = first_entry; entry; entry = entry->next)
{
if (entry->addr == base) break;
if (!entry->count) free = entry;
}
if (!entry)
{
if (!free) /* no free entry found, create a new one */
{
if (!(free = HeapAlloc( GetProcessHeap(), 0, sizeof(*free) ))) goto done;
if (!(free->sel = SELECTOR_AllocBlock( base, 0x10000, WINE_LDT_FLAGS_DATA )))
{
HeapFree( GetProcessHeap(), 0, free );
goto done;
}
free->count = 0;
free->next = first_entry;
first_entry = free;
}
SetSelectorBase( free->sel, (DWORD)base );
free->addr = base;
entry = free;
}
entry->count++;
ret = MAKESEGPTR( entry->sel, (char *)ptr - (char *)entry->addr );
done:
HeapUnlock( GetProcessHeap() );
return ret;
}
/***********************************************************************
* UnMapLS (KERNEL32.@)
* UnMapLS (KERNEL.359)
*
* Free mapped selector.
*/
void WINAPI UnMapLS( SEGPTR sptr )
{
struct mapls_entry *entry;
WORD sel = SELECTOROF(sptr);
if (sel)
{
HeapLock( GetProcessHeap() );
for (entry = first_entry; entry; entry = entry->next) if (entry->sel == sel) break;
if (entry && entry->count > 0) entry->count--;
HeapUnlock( GetProcessHeap() );
}
}
/***********************************************************************
* MapSL (KERNEL32.@)
* MapSL (KERNEL.357)