ReactOS  0.4.15-dev-3302-ga37d9a4
winternl.h File Reference
#include <ntdef.h>
#include <windef.h>
Include dependency graph for winternl.h:

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   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  ,
ULONG  ,
PVOID   
)

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;
2278  BOOLEAN Locked = FALSE;
2279  NTSTATUS Status;
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 */
2289  if (RtlpHeapIsSpecial(Flags))
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
2380  UNIMPLEMENTED;
2381  }
2382  }
2383  }
2384 
2385  /* Release the heap lock */
2386  if (Locked) RtlLeaveHeapLock(Heap->LockVariable);
2387 
2388  return TRUE;
2389 }
LIST_ENTRY Entry
Definition: heap.h:309
Definition: heap.h:307
#define HEAP_ENTRY_VIRTUAL_ALLOC
Definition: heap.h:43
KPROCESSOR_MODE NTAPI RtlpGetMode(VOID)
Definition: libsupp.c:53
SIZE_T TotalFreeSize
Definition: heap.h:239
PHEAP_FREE_ENTRY NTAPI RtlpCoalesceFreeBlocks(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, PSIZE_T FreeSize, BOOLEAN Remove)
Definition: heap.c:1150
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
#define HEAP_SEGMENTS
Definition: heap.h:15
NTSTATUS NTAPI RtlEnterHeapLock(IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
Definition: libsupp.c:108
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
#define HEAP_DISABLE_COALESCE_ON_FREE
Definition: nt_native.h:1699
_SEH2_TRY
Definition: create.c:4226
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FALSE
Definition: types.h:117
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:207
PHEAP_LOCK LockVariable
Definition: heap.h:260
VOID NTAPI RtlpInsertFreeBlock(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, SIZE_T BlockSize)
Definition: heap.c:357
Definition: heap.h:129
unsigned char BOOLEAN
struct _HEAP_ENTRY * PHEAP_ENTRY
BOOLEAN NTAPI RtlDebugFreeHeap(HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
Definition: heapdbg.c:267
#define HEAP_ENTRY_BUSY
Definition: heap.h:40
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
NTSTATUS NTAPI RtlLeaveHeapLock(IN OUT PHEAP_LOCK Lock)
Definition: libsupp.c:133
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static VOID RtlpDeCommitFreeBlock(PHEAP Heap, PHEAP_FREE_ENTRY FreeEntry, SIZE_T Size)
Definition: heap.c:834
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
Definition: heap.h:135
unsigned short USHORT
Definition: pedump.c:61
ULONG Flags
Definition: heap.h:226
#define DPRINT1
Definition: precomp.h:8
#define MEM_RELEASE
Definition: nt_native.h:1316
SIZE_T DeCommitFreeBlockThreshold
Definition: heap.h:237
struct _HEAP * PHEAP
#define UNIMPLEMENTED
Definition: debug.h:115
#define ULONG_PTR
Definition: config.h:101
NTSYSAPI void WINAPI RtlSetLastWin32ErrorAndNtStatusFromNtStatus(NTSTATUS)
ULONG ForceFlags
Definition: heap.h:227
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
SIZE_T DeCommitTotalFreeThreshold
Definition: heap.h:238
Definition: heap.c:51
FORCEINLINE BOOLEAN RtlpHeapIsSpecial(ULONG Flags)
Definition: heap.h:59

◆ RtlInitializeBitMap()

NTSYSAPI void WINAPI RtlInitializeBitMap ( PRTL_BITMAP  ,
PULONG  ,
ULONG   
)

◆ RtlSetBits()

NTSYSAPI void WINAPI RtlSetBits ( PRTL_BITMAP  ,
ULONG  ,
ULONG   
)