ReactOS  0.4.14-dev-376-gaedba84
zone.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: ntoskrnl/ex/zone.c
5  * PURPOSE: Implements zone buffers
6  * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7  * David Welch (welch@mcmail.com)
8  */
9 
10 /* INCLUDES ****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ***************************************************************/
17 
18 /*
19  * @implemented
20  */
22 NTAPI
24  PVOID Segment,
26 {
28  ULONG i;
29 
30  /*
31  * BlockSize and Segment must be 8-byte aligned.
32  * Blocksize cannot exceed Segment Size.
33  */
34  if (((ULONG_PTR)Segment & 7) ||
35  (SegmentSize & 7) ||
36  (Zone->BlockSize > SegmentSize))
37  {
38  DPRINT1("Invalid ExExtendZone Alignment and/or Size\n");
40  }
41 
42  /* Link the Zone and Segment */
44  &((PZONE_SEGMENT_HEADER)Segment)->SegmentList);
45 
46  /* Get to the first entry */
48 
49  /* Loop through the segments */
50  for (i = sizeof(ZONE_SEGMENT_HEADER);
51  i <= SegmentSize - Zone->BlockSize;
52  i+= Zone->BlockSize)
53  {
54  /* Link the Free and Segment Lists */
56 
57  /* Go to the next entry */
58  Entry += Zone->BlockSize;
59  }
60 
61  /* Update Segment Size */
62  Zone->TotalSegmentSize += i;
63 
64  /* Return Success */
65  return STATUS_SUCCESS;
66 }
67 
68 /*
69  * @implemented
70  */
72 NTAPI
74  PVOID Segment,
77 {
79  KIRQL OldIrql;
80 
81  /* Get the lock */
83 
84  /* Extend the Zone */
86 
87  /* Release lock and return status */
89  return Status;
90 }
91 
92 /*
93  * FUNCTION: Initializes a zone header
94  * ARGUMENTS:
95  * Zone = zone header to be initialized
96  * BlockSize = Size (in bytes) of the allocation size of the zone
97  * InitialSegment = Initial segment of storage allocated by the
98  * caller
99  * InitialSegmentSize = Initial size of the segment
100  *
101  * @implemented
102  */
103 NTSTATUS
104 NTAPI
106  ULONG BlockSize,
107  PVOID InitialSegment,
108  ULONG InitialSegmentSize)
109 {
110  ULONG i;
112 
113  /*
114  * BlockSize and Segment must be 8-byte aligned.
115  * Blocksize cannot exceed Segment Size.
116  */
117  if (((ULONG_PTR)InitialSegment & 7) ||
118  (InitialSegmentSize & 7) ||
119  (BlockSize > InitialSegmentSize))
120  {
121  DPRINT1("Invalid ExInitializeZone Alignment and/or Size\n");
123  }
124 
125  /* Set the Zone Header */
126  Zone->BlockSize = BlockSize;
127 
128  /* Link empty list */
129  Zone->FreeList.Next = NULL;
130  Zone->SegmentList.Next = NULL;
131  PushEntryList(&Zone->SegmentList,
132  &((PZONE_SEGMENT_HEADER)InitialSegment)->SegmentList);
133  ((PZONE_SEGMENT_HEADER)InitialSegment)->Reserved = NULL;
134 
135  /* Get first entry */
136  Entry = (ULONG_PTR)InitialSegment + sizeof(ZONE_SEGMENT_HEADER);
137 
138  /* Loop through the segments */
139  for (i = sizeof(ZONE_SEGMENT_HEADER);
140  i <= InitialSegmentSize - BlockSize;
141  i+= BlockSize)
142  {
143  /* Link the Free and Segment Lists */
145 
146  /* Go to the next entry */
147  Entry += Zone->BlockSize;
148  }
149 
150  /* Set Segment Size */
151  Zone->TotalSegmentSize = i;
152 
153  /* Return success */
154  return STATUS_SUCCESS;
155 }
156 
157 /* EOF */
ZONE_SEGMENT_HEADER
Definition: extypes.h:285
struct _Entry Entry
Definition: kefuncs.h:640
Definition: ntbasedef.h:635
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
SINGLE_LIST_ENTRY FreeList
Definition: extypes.h:288
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
ULONG BlockSize
Definition: extypes.h:290
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID PushEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY Entry)
Definition: rtlfuncs.h:253
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG TotalSegmentSize
Definition: extypes.h:291
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ExInitializeZone(PZONE_HEADER Zone, ULONG BlockSize, PVOID InitialSegment, ULONG InitialSegmentSize)
Definition: zone.c:105
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:636
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
_Inout_ PVOID _In_ ULONG SegmentSize
Definition: exfuncs.h:893
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
NTSTATUS NTAPI ExInterlockedExtendZone(PZONE_HEADER Zone, PVOID Segment, ULONG SegmentSize, PKSPIN_LOCK Lock)
Definition: zone.c:73
Status
Definition: gdiplustypes.h:24
SINGLE_LIST_ENTRY SegmentList
Definition: extypes.h:289
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
* PZONE_SEGMENT_HEADER
Definition: extypes.h:285
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI ExExtendZone(PZONE_HEADER Zone, PVOID Segment, ULONG SegmentSize)
Definition: zone.c:23
base of all file and directory entries
Definition: entries.h:82