From e611b132f9b8abe35b362e5870b74bce94a1e58e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 16 May 2020 20:51:50 -0700 Subject: initial commit --- private/ntos/rtl/user/alpha/sources | 15 ++ private/ntos/rtl/user/i386/sources | 19 +++ private/ntos/rtl/user/makefile | 6 + private/ntos/rtl/user/makefile.inc | 25 +++ private/ntos/rtl/user/mips/sources | 11 ++ private/ntos/rtl/user/ppc/sources | 10 ++ private/ntos/rtl/user/sources | 86 +++++++++++ private/ntos/rtl/user/theap.c | 301 ++++++++++++++++++++++++++++++++++++ 8 files changed, 473 insertions(+) create mode 100644 private/ntos/rtl/user/alpha/sources create mode 100644 private/ntos/rtl/user/i386/sources create mode 100644 private/ntos/rtl/user/makefile create mode 100644 private/ntos/rtl/user/makefile.inc create mode 100644 private/ntos/rtl/user/mips/sources create mode 100644 private/ntos/rtl/user/ppc/sources create mode 100644 private/ntos/rtl/user/sources create mode 100644 private/ntos/rtl/user/theap.c (limited to 'private/ntos/rtl/user') diff --git a/private/ntos/rtl/user/alpha/sources b/private/ntos/rtl/user/alpha/sources new file mode 100644 index 000000000..c0f256a76 --- /dev/null +++ b/private/ntos/rtl/user/alpha/sources @@ -0,0 +1,15 @@ +ALPHA_SOURCES=..\alpha\capture.s \ + ..\alpha\chkstk.s \ + ..\alpha\context.c \ + ..\alpha\debugstb.s \ + ..\alpha\exdsptch.c \ + ..\alpha\getcalr.c \ + ..\alpha\largeint.s \ + ..\alpha\lzntaxp.s \ + ..\alpha\longjmp.s \ + ..\alpha\ntcurteb.s \ + ..\alpha\mvmem.s \ + ..\alpha\setjmp.s \ + ..\alpha\trampoln.s \ + ..\alpha\unwindr.c \ + ..\alpha\xcptmisc.s diff --git a/private/ntos/rtl/user/i386/sources b/private/ntos/rtl/user/i386/sources new file mode 100644 index 000000000..5a4cd3730 --- /dev/null +++ b/private/ntos/rtl/user/i386/sources @@ -0,0 +1,19 @@ +i386_SOURCES=..\i386\context.c \ + ..\i386\debug3.c \ + ..\i386\debug2.asm \ + ..\i386\divlarge.c \ + ..\i386\exdsptch.c \ + ..\i386\stkwalk.asm \ + ..\i386\stringsp.asm \ + ..\i386\ioaccess.asm \ + ..\i386\largeint.asm \ + ..\i386\lzntx86.asm \ + ..\i386\movemem.asm \ + ..\i386\ntcurteb.asm \ + ..\i386\raise.asm \ + ..\i386\raisests.c \ + ..\i386\rtldump.c \ + ..\i386\stkwalk.asm \ + ..\i386\userdisp.asm \ + ..\i386\xcptmisc.asm \ + ..\i386\halvprnt.c diff --git a/private/ntos/rtl/user/makefile b/private/ntos/rtl/user/makefile new file mode 100644 index 000000000..6ee4f43fa --- /dev/null +++ b/private/ntos/rtl/user/makefile @@ -0,0 +1,6 @@ +# +# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source +# file to this component. This file merely indirects to the real make file +# that is shared by all the components of NT OS/2 +# +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/private/ntos/rtl/user/makefile.inc b/private/ntos/rtl/user/makefile.inc new file mode 100644 index 000000000..281b22c0b --- /dev/null +++ b/private/ntos/rtl/user/makefile.inc @@ -0,0 +1,25 @@ +theap.c: ..\heap.c ..\heapdbg.c ..\heapdll.c ..\trace.c + +t.c: ..\handle.c ..\atom.c + +..\error.c: ..\error.h + +..\error.h: ..\generr.c + set PASS0ONLY= + nmake obj\$(TARGET_DIRECTORY)\generr.obj USE_CRTDLL=1 + -link -out:obj\$(TARGET_DIRECTORY)\generr.exe @<< +-machine:$(TARGET_DIRECTORY) +-base:@$(BASEDIR)\PUBLIC\SDK\LIB\coffbase.txt,usermode +-subsystem:console +-entry:mainCRTStartup +-ignore:4001,4037,4039,4065,4070,4078,4087,4089,2001 +-force +-nodefaultlib +obj\$(TARGET_DIRECTORY)\generr.obj +$(BASEDIR)\PUBLIC\SDK\LIB\$(TARGET_DIRECTORY)\crtdll.lib +<< + -obj\$(TARGET_DIRECTORY)\generr.exe $@ + -erase obj\$(TARGET_DIRECTORY)\error.obj + -erase ..\kernel\obj\$(TARGET_DIRECTORY)\error.obj + -erase obj\$(TARGET_DIRECTORY)\generr.obj + -erase obj\$(TARGET_DIRECTORY)\generr.exe diff --git a/private/ntos/rtl/user/mips/sources b/private/ntos/rtl/user/mips/sources new file mode 100644 index 000000000..4b26230d1 --- /dev/null +++ b/private/ntos/rtl/user/mips/sources @@ -0,0 +1,11 @@ +MIPS_SOURCES=..\mips\chkstk.s \ + ..\mips\context.c \ + ..\mips\debugstb.s \ + ..\mips\exdsptch.c \ + ..\mips\getcalr.c \ + ..\mips\largeint.s \ + ..\mips\lzntmips.s \ + ..\mips\trampoln.s \ + ..\mips\xcptmisc.s \ + ..\mips\xxcaptur.s \ + ..\mips\xxmvmem.s diff --git a/private/ntos/rtl/user/ppc/sources b/private/ntos/rtl/user/ppc/sources new file mode 100644 index 000000000..c5eaa6ac2 --- /dev/null +++ b/private/ntos/rtl/user/ppc/sources @@ -0,0 +1,10 @@ +PPC_SOURCES= ..\ppc\chkstk.s \ + ..\ppc\context.c \ + ..\ppc\debugstb.s \ + ..\ppc\exdsptch.c \ + ..\ppc\getcalr.c \ + ..\ppc\largeint.s \ + ..\ppc\lzntppc.s \ + ..\ppc\trampoln.s \ + ..\ppc\xcptmisc.s \ + ..\ppc\movemem.s diff --git a/private/ntos/rtl/user/sources b/private/ntos/rtl/user/sources new file mode 100644 index 000000000..0f72a0bf3 --- /dev/null +++ b/private/ntos/rtl/user/sources @@ -0,0 +1,86 @@ +!IF 0 + +Copyright (c) 1989 Microsoft Corporation + +Module Name: + + sources. + +Abstract: + + This file specifies the target component being built and the list of + sources files needed to build that component. Also specifies optional + compiler switches and libraries that are unique for the component being + built. + + +Author: + + Steve Wood (stevewo) 12-Apr-1990 + +NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl + +!ENDIF + +MAJORCOMP=ntos +MINORCOMP=rtl + +TARGETNAME=rtl +TARGETPATH=..\obj +TARGETTYPE=LIBRARY + +INCLUDES=..;..\..\inc;..\..\..\inc + + + +C_DEFINES=$(C_DEFINES) -D_NTSYSTEM_ + +SOURCES=..\acledit.c \ + ..\assert.c \ + ..\atom.c \ + ..\bitmap.c \ + ..\compress.c \ + ..\cnvint.c \ + ..\debug.c \ + ..\eballoc.c \ + ..\environ.c \ + ..\error.c \ + ..\excptdbg.c \ + ..\gentable.c \ + ..\gen8dot3.c \ + ..\handle.c \ + ..\heap.c \ + ..\heapdll.c \ + ..\heapdbg.c \ + ..\heappage.c \ + ..\imagedir.c \ + ..\checksum.c \ + ..\ldrrsrc.c \ + ..\ldrreloc.c \ + ..\lznt1.c \ + ..\message.c \ + ..\nls.c \ + ..\pctohdr.c \ + ..\prefix.c \ + ..\prodtype.c \ + ..\random.c \ + ..\registry.c \ + ..\regutil.c \ + ..\rtlassig.c \ + ..\rtldata.c \ + ..\rtlexec.c \ + ..\rxact.c \ + ..\sertl.c \ + ..\splay.c \ + ..\string.c \ + ..\stktrace.c \ + ..\time.c \ + ..\nlsxlat.c \ + ..\eventlog.c \ + ..\trace.c + +NTTARGETFILE0=..\error.h + +UMTEST= +UMTYPE=console +UMLIBS=obj\*\bitmap.obj obj\*\eventlog.obj obj\*\stktrace.obj obj\*\stkwalk.obj \nt\public\sdk\lib\*\ntdll.lib diff --git a/private/ntos/rtl/user/theap.c b/private/ntos/rtl/user/theap.c new file mode 100644 index 000000000..38c546d14 --- /dev/null +++ b/private/ntos/rtl/user/theap.c @@ -0,0 +1,301 @@ +/*++ + +Copyright (c) 1989 Microsoft Corporation + +Module Name: + + theap.c + +Abstract: + + Test program for the Heap Procedures + +Author: + + Steven R. Wood [stevewo] + +Revision History: + +--*/ + +#define THEAP +#include "..\heap.c" +#include "..\heapdll.c" +#include "..\heapdbg.c" +#include "..\trace.c" +#include + +#include + +ULONG NtGlobalFlag = FLG_HEAP_ENABLE_TAIL_CHECK | + FLG_HEAP_ENABLE_FREE_CHECK | + FLG_HEAP_VALIDATE_PARAMETERS | + FLG_HEAP_VALIDATE_ALL | + FLG_HEAP_ENABLE_TAGGING; + +BOOLEAN +NtdllOkayToLockRoutine( + IN PVOID Lock + ) +{ + return TRUE; +} + +PRTL_INITIALIZE_LOCK_ROUTINE RtlInitializeLockRoutine = + (PRTL_INITIALIZE_LOCK_ROUTINE)RtlInitializeCriticalSection; +PRTL_ACQUIRE_LOCK_ROUTINE RtlAcquireLockRoutine = + (PRTL_ACQUIRE_LOCK_ROUTINE)RtlEnterCriticalSection; +PRTL_RELEASE_LOCK_ROUTINE RtlReleaseLockRoutine = + (PRTL_RELEASE_LOCK_ROUTINE)RtlLeaveCriticalSection; +PRTL_DELETE_LOCK_ROUTINE RtlDeleteLockRoutine = + (PRTL_DELETE_LOCK_ROUTINE)RtlDeleteCriticalSection; +PRTL_OKAY_TO_LOCK_ROUTINE RtlOkayToLockRoutine = + (PRTL_OKAY_TO_LOCK_ROUTINE)NtdllOkayToLockRoutine; + +BOOLEAN +RtlAreLogging( + IN ULONG EventClass + ) +{ + return FALSE; +} + +RTL_HEAP_PARAMETERS HeapParameters; + +ULONG RtlpHeapValidateOnCall; +ULONG RtlpHeapStopOnFree; +ULONG RtlpHeapStopOnReAlloc; + + +typedef struct _TEST_HEAP_ENTRY { + PVOID AllocatedBlock; + ULONG Size; +} TEST_HEAP_ENTRY, *PTEST_HEAP_ENTRY; + +ULONG NumberOfHeapEntries; +PTEST_HEAP_ENTRY HeapEntries; + +ULONG Seed = 14623; + +#define MAX_HEAP_ALLOC 0x120000 +#define REASONABLE_HEAP_ALLOC 0x200 + +int +_cdecl +main( + int argc, + char *argv[] + ) +{ + PVOID Heap, AllocatedBlock; + ULONG i, n; + PTEST_HEAP_ENTRY p; + BOOLEAN Result; + NTSTATUS Status; + RTL_HEAP_USAGE Usage; + PRTL_HEAP_USAGE_ENTRY pEntries; + ULONG TagBaseIndex, Tag; + + RtlInitializeHeapManager(); + memset( &Usage, 0, sizeof( Usage ) ); + +#if 0 + HeapParameters.Length = sizeof( HeapParameters ); + HeapParameters.DeCommitFreeBlockThreshold = 0x1000; + HeapParameters.DeCommitTotalFreeThreshold = 0x4000; + Heap = RtlCreateHeap( HEAP_GROWABLE | HEAP_NO_SERIALIZE, + NULL, + 256 * 4096, + 4096, + NULL, + &HeapParameters + ); +#endif + Heap = RtlCreateHeap( HEAP_GROWABLE | HEAP_NO_SERIALIZE | HEAP_CLASS_3, + NULL, + 0x100000, + 0x1000, + NULL, + NULL + ); + if (Heap == NULL) { + fprintf( stderr, "THEAP: Unable to create heap.\n" ); + exit( 1 ); + } + fprintf( stderr, "THEAP: Created heap at %x\n", Heap ); + DbgBreakPoint(); + TagBaseIndex = RtlCreateTagHeap( Heap, 0, L"THEAP!", + L"!HeapName\0" + L"Tag1\0" + L"Tag2\0" + L"Tag3\0" + L"Tag4\0" + L"Tag5\0" + L"Tag6\0" + L"Tag7\0" + L"Tag8\0" + L"Tag9\0" + L"Tag10\0" + L"Tag11\0" + L"Tag12\0" + L"Tag13\0" + L"Tag14\0" + L"Tag15\0" + L"Tag16\0" + L"Tag17\0" + L"Tag18\0" + L"Tag19\0" + L"Tag20\0" + L"Tag21\0" + L"Tag22\0" + L"Tag23\0" + L"Tag24\0" + L"Tag25\0" + L"Tag26\0" + L"Tag27\0" + L"Tag28\0" + L"Tag29\0" + L"Tag30\0" + L"Tag31\0" + L"Tag32\0" + L"Tag33\0" + L"Tag34\0" + L"Tag35\0" + L"Tag36\0" + L"Tag37\0" + L"Tag38\0" + L"Tag39\0" + L"Tag40\0" + L"Tag41\0" + L"Tag42\0" + L"Tag43\0" + L"Tag44\0" + L"Tag45\0" + L"Tag46\0" + L"Tag47\0" + L"Tag48\0" + L"Tag49\0" + L"Tag50\0" + L"Tag51\0" + L"Tag52\0" + L"Tag53\0" + L"Tag54\0" + L"Tag55\0" + L"Tag56\0" + L"Tag57\0" + L"Tag58\0" + L"Tag59\0" + L"Tag60\0" + ); + + NumberOfHeapEntries = 1000; + HeapEntries = VirtualAlloc( NULL, + NumberOfHeapEntries * sizeof( *HeapEntries ), + MEM_COMMIT, + PAGE_READWRITE + ); + if (HeapEntries == NULL) { + fprintf( stderr, "THEAP: Unable to allocate space.\n" ); + exit( 1 ); + } + + RtlpHeapValidateOnCall=TRUE; + // RtlpHeapStopOnAllocate=0x350f88; + // RtlpHeapStopOnReAlloc=0x710040; + while (TRUE) { + i = RtlUniform( &Seed ) % NumberOfHeapEntries; + if (RtlUniform( &Seed ) % 100) { + n = RtlUniform( &Seed ) % REASONABLE_HEAP_ALLOC; + } + else { + n = RtlUniform( &Seed ) % MAX_HEAP_ALLOC; + } + + Usage.Length = sizeof( Usage ); + Status = RtlUsageHeap( Heap, HEAP_USAGE_ALLOCATED_BLOCKS , &Usage ); + if (NT_SUCCESS( Status )) { + if (Status == STATUS_MORE_ENTRIES) { + pEntries = Usage.AddedEntries; + while (pEntries) { + fprintf( stderr, + "Added: %08x %06x\n", + pEntries->Address, + pEntries->Size + ); + pEntries = pEntries->Next; + } + + pEntries = Usage.RemovedEntries; + while (pEntries) { + fprintf( stderr, + "Freed: %08x %06x\n", + pEntries->Address, + pEntries->Size + ); + pEntries = pEntries->Next; + } + } + + fprintf( stderr, "%08x %08x %08x %08x ", + Usage.BytesAllocated, Usage.BytesCommitted, + Usage.BytesReserved, Usage.BytesReservedMaximum + ); + } + else { + fprintf( stderr, "RtlUsageHeap failed with status %x\n", Status ); + DebugBreak(); + } + + if (i < 60) { + Tag = (TagBaseIndex + i + 1) << 16; + } + else { + Tag = 0; + } + p = &HeapEntries[ i ]; + if (p->AllocatedBlock == NULL) { + p->AllocatedBlock = RtlAllocateHeap( Heap, Tag, n ); + fprintf( stderr, "Allocated %06x bytes at %08x\n", n, p->AllocatedBlock ); + if (p->AllocatedBlock != NULL) { + p->Size = n; + } + else { + DebugBreak(); + } + } + else + if (RtlUniform( &Seed ) & 1) { + AllocatedBlock = RtlReAllocateHeap( Heap, Tag, p->AllocatedBlock, n ); + fprintf( stderr, "ReAlloced %06x bytes at %08x to %06x bytes at %08x\n", + p->Size, + p->AllocatedBlock, + n, + AllocatedBlock + ); + if (AllocatedBlock != NULL) { + p->AllocatedBlock = AllocatedBlock; + p->Size = n; + } + else { + DebugBreak(); + } + } + else { + Result = RtlFreeHeap( Heap, 0, p->AllocatedBlock ); + fprintf( stderr, "Freed %06x bytes at %08x\n", + p->Size, + p->AllocatedBlock + ); + if (Result) { + p->AllocatedBlock = NULL; + p->Size = 0; + } + else { + DebugBreak(); + } + } + + } + + return 0; +} -- cgit v1.2.3