ReactOS 0.4.15-dev-8145-ga541a46
winternl.h File Reference
#include <ntdef.h>
#include <windef.h>
Include dependency graph for winternl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _UNICODE_STRING
 
struct  _CLIENT_ID
 
struct  _CURDIR
 
struct  RTL_DRIVE_LETTER_CURDIR
 
struct  tagRTL_BITMAP
 
struct  _RTL_USER_PROCESS_PARAMETERS
 
struct  _PEB_LDR_DATA
 
struct  _GDI_TEB_BATCH
 
struct  _RTL_ACTIVATION_CONTEXT_STACK_FRAME
 
struct  _ACTIVATION_CONTEXT_STACK
 
struct  _TEB_ACTIVE_FRAME_CONTEXT
 
struct  _TEB_ACTIVE_FRAME
 
struct  _PEB
 
struct  _TEB
 

Macros

#define WINE_NTSTATUS_DECLARED
 
#define __UNICODE_STRING_DEFINED__
 
#define ARRAY_SIZE   ARRAYSIZE
 
#define MSVCRT_free   free
 
#define MSVCRT_malloc   malloc
 
#define MSVCRT__exit   exit
 
#define MSVCRT_abort   abort
 

Typedefs

typedef LONG NTSTATUS
 
typedef struct _UNICODE_STRING UNICODE_STRING
 
typedef struct _UNICODE_STRINGPUNICODE_STRING
 
typedef struct _CLIENT_ID CLIENT_ID
 
typedef struct _CLIENT_IDPCLIENT_ID
 
typedef struct _CURDIR CURDIR
 
typedef struct _CURDIRPCURDIR
 
typedef struct RTL_DRIVE_LETTER_CURDIR RTL_DRIVE_LETTER_CURDIR
 
typedef struct RTL_DRIVE_LETTER_CURDIRPRTL_DRIVE_LETTER_CURDIR
 
typedef struct tagRTL_BITMAP RTL_BITMAP
 
typedef struct tagRTL_BITMAPPRTL_BITMAP
 
typedef const RTL_BITMAPPCRTL_BITMAP
 
typedef struct _RTL_USER_PROCESS_PARAMETERS RTL_USER_PROCESS_PARAMETERS
 
typedef struct _RTL_USER_PROCESS_PARAMETERSPRTL_USER_PROCESS_PARAMETERS
 
typedef struct _PEB_LDR_DATA PEB_LDR_DATA
 
typedef struct _PEB_LDR_DATAPPEB_LDR_DATA
 
typedef struct _GDI_TEB_BATCH GDI_TEB_BATCH
 
typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME RTL_ACTIVATION_CONTEXT_STACK_FRAME
 
typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAMEPRTL_ACTIVATION_CONTEXT_STACK_FRAME
 
typedef struct _ACTIVATION_CONTEXT_STACK ACTIVATION_CONTEXT_STACK
 
typedef struct _ACTIVATION_CONTEXT_STACKPACTIVATION_CONTEXT_STACK
 
typedef struct _TEB_ACTIVE_FRAME_CONTEXT TEB_ACTIVE_FRAME_CONTEXT
 
typedef struct _TEB_ACTIVE_FRAME_CONTEXTPTEB_ACTIVE_FRAME_CONTEXT
 
typedef struct _TEB_ACTIVE_FRAME TEB_ACTIVE_FRAME
 
typedef struct _TEB_ACTIVE_FRAMEPTEB_ACTIVE_FRAME
 
typedef struct _PEB PEB
 
typedef struct _PEBPPEB
 
typedef struct _TEB TEB
 
typedef struct _TEBPTEB
 

Functions

NTSYSAPI PVOID WINAPI RtlAllocateHeap (HANDLE, ULONG, SIZE_T) __WINE_ALLOC_SIZE(3)
 
NTSYSAPI BOOLEAN WINAPI RtlAreBitsSet (PCRTL_BITMAP, ULONG, ULONG)
 
NTSYSAPI BOOLEAN WINAPI RtlAreBitsClear (PCRTL_BITMAP, ULONG, ULONG)
 
NTSYSAPI BOOLEAN WINAPI RtlFreeHeap (HANDLE, ULONG, PVOID)
 
NTSYSAPI void WINAPI RtlInitializeBitMap (PRTL_BITMAP, PULONG, ULONG)
 
NTSYSAPI void WINAPI RtlSetBits (PRTL_BITMAP, ULONG, ULONG)
 

Macro Definition Documentation

◆ __UNICODE_STRING_DEFINED__

#define __UNICODE_STRING_DEFINED__

Definition at line 41 of file winternl.h.

◆ ARRAY_SIZE

#define ARRAY_SIZE   ARRAYSIZE

Definition at line 306 of file winternl.h.

◆ MSVCRT__exit

#define MSVCRT__exit   exit

Definition at line 310 of file winternl.h.

◆ MSVCRT_abort

#define MSVCRT_abort (   void)    abort

Definition at line 311 of file winternl.h.

◆ MSVCRT_free

#define MSVCRT_free   free

Definition at line 307 of file winternl.h.

◆ MSVCRT_malloc

#define MSVCRT_malloc   malloc

Definition at line 308 of file winternl.h.

◆ WINE_NTSTATUS_DECLARED

#define WINE_NTSTATUS_DECLARED

Definition at line 36 of file winternl.h.

Typedef Documentation

◆ ACTIVATION_CONTEXT_STACK

◆ CLIENT_ID

◆ CURDIR

◆ GDI_TEB_BATCH

◆ NTSTATUS

typedef LONG NTSTATUS

Definition at line 37 of file winternl.h.

◆ PACTIVATION_CONTEXT_STACK

◆ PCLIENT_ID

◆ PCRTL_BITMAP

Definition at line 74 of file winternl.h.

◆ PCURDIR

typedef struct _CURDIR * PCURDIR

◆ PEB

typedef struct _PEB PEB

◆ PEB_LDR_DATA

◆ PPEB

typedef struct _PEB * PPEB

◆ PPEB_LDR_DATA

◆ PRTL_ACTIVATION_CONTEXT_STACK_FRAME

◆ PRTL_BITMAP

◆ PRTL_DRIVE_LETTER_CURDIR

◆ PRTL_USER_PROCESS_PARAMETERS

◆ PTEB

typedef struct _TEB * PTEB

◆ PTEB_ACTIVE_FRAME

◆ PTEB_ACTIVE_FRAME_CONTEXT

◆ PUNICODE_STRING

◆ RTL_ACTIVATION_CONTEXT_STACK_FRAME

◆ RTL_BITMAP

◆ RTL_DRIVE_LETTER_CURDIR

◆ RTL_USER_PROCESS_PARAMETERS

◆ TEB

typedef struct _TEB TEB

◆ TEB_ACTIVE_FRAME

◆ TEB_ACTIVE_FRAME_CONTEXT

◆ UNICODE_STRING

Function Documentation

◆ RtlAllocateHeap()

NTSYSAPI PVOID WINAPI RtlAllocateHeap ( HANDLE  ,
ULONG  ,
SIZE_T   
)

◆ RtlAreBitsClear()

NTSYSAPI BOOLEAN WINAPI RtlAreBitsClear ( PCRTL_BITMAP  ,
ULONG  ,
ULONG   
)

◆ RtlAreBitsSet()

NTSYSAPI BOOLEAN WINAPI RtlAreBitsSet ( PCRTL_BITMAP  ,
ULONG  ,
ULONG   
)

◆ RtlFreeHeap()

NTSYSAPI BOOLEAN WINAPI RtlFreeHeap ( HANDLE  HeapPtr,
ULONG  Flags,
PVOID  Ptr 
)

Definition at line 2267 of file heap.c.

2272{
2273 PHEAP Heap;
2274 PHEAP_ENTRY HeapEntry;
2275 USHORT TagIndex = 0;
2276 SIZE_T BlockSize;
2277 PHEAP_VIRTUAL_ALLOC_ENTRY VirtualEntry;
2280
2281 /* Freeing NULL pointer is a legal operation */
2282 if (!Ptr) return TRUE;
2283
2284 /* Get pointer to the heap and force flags */
2285 Heap = (PHEAP)HeapPtr;
2286 Flags |= Heap->ForceFlags;
2287
2288 /* Call special heap */
2290 return RtlDebugFreeHeap(Heap, Flags, Ptr);
2291
2292 /* Get pointer to the heap entry */
2293 HeapEntry = (PHEAP_ENTRY)Ptr - 1;
2294
2295 /* Protect with SEH in case the pointer is not valid */
2296 _SEH2_TRY
2297 {
2298 /* Check this entry, fail if it's invalid */
2299 if (!(HeapEntry->Flags & HEAP_ENTRY_BUSY) ||
2300 (((ULONG_PTR)Ptr & 0x7) != 0) ||
2301 (HeapEntry->SegmentOffset >= HEAP_SEGMENTS))
2302 {
2303 /* This is an invalid block */
2304 DPRINT1("HEAP: Trying to free an invalid address %p!\n", Ptr);
2306 _SEH2_YIELD(return FALSE);
2307 }
2308 }
2310 {
2311 /* The pointer was invalid */
2312 DPRINT1("HEAP: Trying to free an invalid address %p!\n", Ptr);
2314 _SEH2_YIELD(return FALSE);
2315 }
2316 _SEH2_END;
2317
2318 /* Lock if necessary */
2319 if (!(Flags & HEAP_NO_SERIALIZE))
2320 {
2322 Locked = TRUE;
2323 }
2324
2325 if (HeapEntry->Flags & HEAP_ENTRY_VIRTUAL_ALLOC)
2326 {
2327 /* Big allocation */
2328 VirtualEntry = CONTAINING_RECORD(HeapEntry, HEAP_VIRTUAL_ALLOC_ENTRY, BusyBlock);
2329
2330 /* Remove it from the list */
2331 RemoveEntryList(&VirtualEntry->Entry);
2332
2333 // TODO: Tagging
2334
2335 BlockSize = 0;
2336 Status = ZwFreeVirtualMemory(NtCurrentProcess(),
2337 (PVOID *)&VirtualEntry,
2338 &BlockSize,
2339 MEM_RELEASE);
2340
2341 if (!NT_SUCCESS(Status))
2342 {
2343 DPRINT1("HEAP: Failed releasing memory with Status 0x%08X. Heap %p, ptr %p, base address %p\n",
2344 Status, Heap, Ptr, VirtualEntry);
2346 }
2347 }
2348 else
2349 {
2350 /* Normal allocation */
2351 BlockSize = HeapEntry->Size;
2352
2353 // TODO: Tagging
2354
2355 /* Coalesce in kernel mode, and in usermode if it's not disabled */
2356 if (RtlpGetMode() == KernelMode ||
2358 {
2359 HeapEntry = (PHEAP_ENTRY)RtlpCoalesceFreeBlocks(Heap,
2360 (PHEAP_FREE_ENTRY)HeapEntry,
2361 &BlockSize,
2362 FALSE);
2363 }
2364
2365 /* See if we should decommit this block */
2366 if ((BlockSize >= Heap->DeCommitFreeBlockThreshold) ||
2367 (Heap->TotalFreeSize + BlockSize >= Heap->DeCommitTotalFreeThreshold))
2368 {
2369 RtlpDeCommitFreeBlock(Heap, (PHEAP_FREE_ENTRY)HeapEntry, BlockSize);
2370 }
2371 else
2372 {
2373 /* Insert into the free list */
2374 RtlpInsertFreeBlock(Heap, (PHEAP_FREE_ENTRY)HeapEntry, BlockSize);
2375
2376 if (RtlpGetMode() == UserMode &&
2377 TagIndex != 0)
2378 {
2379 // FIXME: Tagging
2381 }
2382 }
2383 }
2384
2385 /* Release the heap lock */
2387
2388 return TRUE;
2389}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: debug.h:118
struct _HEAP * PHEAP
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI RtlEnterHeapLock(IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
Definition: libsupp.c:110
KPROCESSOR_MODE NTAPI RtlpGetMode(VOID)
Definition: libsupp.c:55
NTSTATUS NTAPI RtlLeaveHeapLock(IN OUT PHEAP_LOCK Lock)
Definition: libsupp.c:135
#define ULONG_PTR
Definition: config.h:101
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI void WINAPI RtlSetLastWin32ErrorAndNtStatusFromNtStatus(NTSTATUS)
#define KernelMode
Definition: asm.h:34
#define UserMode
Definition: asm.h:35
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:209
#define HEAP_DISABLE_COALESCE_ON_FREE
Definition: nt_native.h:1699
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RELEASE
Definition: nt_native.h:1316
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
unsigned short USHORT
Definition: pedump.c:61
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
PHEAP_FREE_ENTRY NTAPI RtlpCoalesceFreeBlocks(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, PSIZE_T FreeSize, BOOLEAN Remove)
Definition: heap.c:1150
static VOID RtlpDeCommitFreeBlock(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, SIZE_T Size)
Definition: heap.c:834
VOID NTAPI RtlpInsertFreeBlock(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, SIZE_T BlockSize)
Definition: heap.c:357
struct _HEAP_ENTRY * PHEAP_ENTRY
FORCEINLINE BOOLEAN RtlpHeapIsSpecial(ULONG Flags)
Definition: heap.h:59
BOOLEAN NTAPI RtlDebugFreeHeap(HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
Definition: heapdbg.c:267
#define HEAP_SEGMENTS
Definition: heap.h:15
#define HEAP_ENTRY_VIRTUAL_ALLOC
Definition: heap.h:43
#define HEAP_ENTRY_BUSY
Definition: heap.h:40
Definition: heap.h:136
Definition: heap.h:130
Definition: heap.h:308
LIST_ENTRY Entry
Definition: heap.h:309
Definition: heap.c:52
ULONG Flags
Definition: heap.h:226
ULONG ForceFlags
Definition: heap.h:227
SIZE_T TotalFreeSize
Definition: heap.h:239
SIZE_T DeCommitFreeBlockThreshold
Definition: heap.h:237
PHEAP_LOCK LockVariable
Definition: heap.h:260
SIZE_T DeCommitTotalFreeThreshold
Definition: heap.h:238
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ RtlInitializeBitMap()

NTSYSAPI void WINAPI RtlInitializeBitMap ( PRTL_BITMAP  ,
PULONG  ,
ULONG   
)

◆ RtlSetBits()

NTSYSAPI void WINAPI RtlSetBits ( PRTL_BITMAP  ,
ULONG  ,
ULONG   
)