ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

zone.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS kernel
00004  * FILE:            ntoskrnl/ex/zone.c
00005  * PURPOSE:         Implements zone buffers
00006  * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
00007  *                  David Welch (welch@mcmail.com)
00008  */
00009 
00010 /* INCLUDES ****************************************************************/
00011 
00012 #include <ntoskrnl.h>
00013 #define NDEBUG
00014 #include <debug.h>
00015 
00016 /* FUNCTIONS ***************************************************************/
00017 
00018 /*
00019  * @implemented
00020  */
00021 NTSTATUS
00022 NTAPI
00023 ExExtendZone(PZONE_HEADER Zone,
00024              PVOID Segment,
00025              ULONG SegmentSize)
00026 {
00027     ULONG_PTR Entry;
00028     ULONG i;
00029 
00030     /*
00031      * BlockSize and Segment must be 8-byte aligned.
00032      * Blocksize cannot exceed Segment Size.
00033      */
00034     if (((ULONG_PTR)Segment & 7) ||
00035         (SegmentSize & 7) ||
00036         (Zone->BlockSize > SegmentSize))
00037     {
00038         DPRINT1("Invalid ExExtendZone Alignment and/or Size\n");
00039         return STATUS_INVALID_PARAMETER;
00040     }
00041 
00042     /* Link the Zone and Segment */
00043     PushEntryList(&Zone->SegmentList,
00044                   &((PZONE_SEGMENT_HEADER)Segment)->SegmentList);
00045 
00046     /* Get to the first entry */
00047     Entry = (ULONG_PTR)Segment + sizeof(ZONE_SEGMENT_HEADER);
00048 
00049     /* Loop through the segments */
00050     for (i = sizeof(ZONE_SEGMENT_HEADER);
00051          i <= SegmentSize - Zone->BlockSize;
00052          i+= Zone->BlockSize)
00053     {
00054         /* Link the Free and Segment Lists */
00055         PushEntryList(&Zone->FreeList, (PSINGLE_LIST_ENTRY)Entry);
00056 
00057         /* Go to the next entry */
00058         Entry += Zone->BlockSize;
00059     }
00060 
00061     /* Update Segment Size */
00062     Zone->TotalSegmentSize += i;
00063 
00064     /* Return Success */
00065     return STATUS_SUCCESS;
00066 }
00067 
00068 /*
00069  * @implemented
00070  */
00071 NTSTATUS
00072 NTAPI
00073 ExInterlockedExtendZone(PZONE_HEADER Zone,
00074                         PVOID Segment,
00075                         ULONG SegmentSize,
00076                         PKSPIN_LOCK Lock)
00077 {
00078     NTSTATUS Status;
00079     KIRQL OldIrql;
00080 
00081     /* Get the lock */
00082     KeAcquireSpinLock(Lock, &OldIrql);
00083 
00084     /* Extend the Zone */
00085     Status = ExExtendZone(Zone, Segment, SegmentSize);
00086 
00087     /* Release lock and return status */
00088     KeReleaseSpinLock(Lock, OldIrql);
00089     return Status;
00090 }
00091 
00092 /*
00093  * FUNCTION: Initalizes a zone header
00094  * ARGUMENTS:
00095  *          Zone = zone header to be initialized
00096  *          BlockSize = Size (in bytes) of the allocation size of the zone
00097  *          InitialSegment = Initial segment of storage allocated by the
00098  *                           caller
00099  *          InitialSegmentSize = Initial size of the segment
00100  *
00101  * @implemented
00102  */
00103 NTSTATUS
00104 NTAPI
00105 ExInitializeZone(PZONE_HEADER Zone,
00106                  ULONG BlockSize,
00107                  PVOID InitialSegment,
00108                  ULONG InitialSegmentSize)
00109 {
00110     ULONG i;
00111     ULONG_PTR Entry;
00112 
00113     /*
00114      * BlockSize and Segment must be 8-byte aligned.
00115      * Blocksize cannot exceed Segment Size.
00116      */
00117     if (((ULONG_PTR)InitialSegment & 7) ||
00118         (InitialSegmentSize & 7) ||
00119         (BlockSize > InitialSegmentSize))
00120     {
00121         DPRINT1("Invalid ExInitializeZone Alignment and/or Size\n");
00122         return STATUS_INVALID_PARAMETER;
00123     }
00124 
00125     /* Set the Zone Header */
00126     Zone->BlockSize = BlockSize;
00127 
00128     /* Link empty list */
00129     Zone->FreeList.Next = NULL;
00130     Zone->SegmentList.Next = NULL;
00131     PushEntryList(&Zone->SegmentList,
00132                   &((PZONE_SEGMENT_HEADER)InitialSegment)->SegmentList);
00133     ((PZONE_SEGMENT_HEADER)InitialSegment)->Reserved = NULL;
00134 
00135     /* Get first entry */
00136     Entry = (ULONG_PTR)InitialSegment + sizeof(ZONE_SEGMENT_HEADER);
00137 
00138     /* Loop through the segments */
00139     for (i = sizeof(ZONE_SEGMENT_HEADER);
00140          i <= InitialSegmentSize - BlockSize;
00141          i+= BlockSize)
00142     {
00143         /* Link the Free and Segment Lists */
00144         PushEntryList(&Zone->FreeList, (PSINGLE_LIST_ENTRY)Entry);
00145 
00146         /* Go to the next entry */
00147         Entry += Zone->BlockSize;
00148     }
00149 
00150     /* Update Segment Size */
00151     Zone->TotalSegmentSize += i;
00152 
00153     /* Return success */
00154     return STATUS_SUCCESS;
00155 }
00156 
00157 /* EOF */

Generated on Sun May 27 2012 04:37:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.