home *** CD-ROM | disk | FTP | other *** search
- [10. Kernel Memory Management]
- EMBEDDED DOS KERNEL MEMORY MANAGEMENT SERVICES
- ════════════════════════════════════════════════════════════════════════
- The pool object is an extremely fast, centralized, near heap used for
- scratch memory allocation at any time, including interrupt time. While
- system pool is limited, it helps conserve code space by keeping only one
- memory allocator in memory, and it overcommits clients' memory needs,
- thereby saving data space.
-
- Pool memory is allocated from only one segment, so that all pointers to
- objects carved out of pool have an implied and well-known segment or
- selector. The segment component of the address is passed around in the
- portable form of the requests.
-
- System pool should be used in situations where either a very small amount
- of memory (under 128 bytes) is allocated to represent some other object
- (as the kernel does to allocate mutex objects, timer objects, and so on).
- It may also be used to allocate larger blocks that will quickly leave the
- system. For example, LAN packet drivers could acquire a 2kb block of
- system pool to represent an incoming packet, and upon process completion
- a millisecond later, the block could be released back to the system.
-
- The kernel proper and all of the other Embedded DOS system components
- use system pool to build file objects, disk cache buffers, and so on.
-
- The size of the system memory pool is configurable at system build time,
- and may be up to 65535 bytes in size. The minimum allocation size is
- also configurable at build time, and is used to control fragmentation.
-
- 1. AllocatePool
-
- A block of memory is allocated from system pool with the
- AllocatePool kernel function. Once the block is allocated, it
- may be used for read/write/execute access until deallocated with
- DeallocatePool.
-
- All blocks allocated with this request are addressable in the
- same segment; therefore, the pointer to a block of pool memory is
- a near pointer relative to a well-known segment/selector. The
- system pool segment/selector is automatically returned in the
- portable form of this request to form a far pointer. The macro
- instruction form of this request returns the offset portion of
- the block in the (DI) general purpose register.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <BlockSize> ; (AX) = size of block in bytes.
- mov dl, SYS_ALLOCATE_POOL
- int 2dh ; (DI) = ofs FWA, allocated block.
- jc Failure
-
- Macro Instruction Format:
-
- label AllocatePool <BlockSize>
-
- Portable Request Format:
-
- STATUS AllocatePool(
- IN USHORT BlockSize,
- OUT PVOID * BlockPtr
- );
-
- Parameters:
-
- BlockSize - Specifies 16-bit general purpose register, a
- literal constant, or a pointer to a word in memory that
- contains the requested size of the block to be
- allocated in bytes. The kernel reserves the right to
- overallocate the block without notification.
-
- BlockPtr - Specifies a pointer to a pointer that will be
- initialized by the kernel to point to the allocated
- block of storage. In the macro instruction form of the
- request, a near pointer is passed in (DI).
-
- 2. DeallocatePool
-
- A block of allocated system pool is returned to the system with
- the DeallocatePool kernel function. Once the block is
- deallocated, it is no longer available to the caller, and the
- address of the block becomes invalid. The caller must assume
- that the system recycles the system pool at a very rapid rate,
- and upon return from this function, will have most likely already
- allocated the address to another system component.
-
- The macro instruction form of this request assumes that the
- offset pointer to the block is already in the (DI) general
- purpose register when the macro is executed. The portable form
- of this request passes the entire pointer in the calling
- convention of the high-level language.
-
- The kernel keeps a reference count on a block of pool memory.
- When the block is initially allocated, this reference count is
- set to 1. When the DeallocatePool request is executed, this
- reference count is decremented, and if the reference count drops
- to zero, the block is deallocated. Otherwise, the block remains
- locked in memory until the reference count is decremented with
- sufficient DeallocatePool requests to bring the reference count
- to zero. The reference count is incremented artificially with
- the KeepPool kernel function. This allows communicating kernel
- components to pass a data structure around without engaging in
- ownership protocol.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov di, <AllocatedBlockOffset> ; (DI) = ofs FWA, block.
- mov dl, SYS_DEALLOCATE_POOL
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label DeallocatePool
-
- Portable Request Format:
-
- STATUS DeallocatePool(
- IN PVOID BlockPtr
- );
-
- Parameters:
-
- BlockPtr - Specifies a pointer to a block of memory
- allocated with the AllocatePool kernel function. The
- address must not be normalized with segment arithmetic,
- because only the offset portion is examined by the kernel.
-
- 3. KeepPool
-
- The KeepPool kernel function increments the reference count on a
- block of previously allocated pool memory, so that ownership is
- implicitly granted to the caller of the KeepPool function instead
- of the AllocatePool function.
-
- The kernel keeps a reference count on a block of pool memory.
- When the block is initially allocated, this reference count is
- set to 1. When the DeallocatePool request is executed, this
- reference count is decremented, and if the reference count drops
- to zero, the block is deallocated. Otherwise, the block remains
- locked in memory until the reference count is decremented with
- sufficient DeallocatePool requests to bring the reference count
- to zero. The reference count is incremented artificially with
- the KeepPool kernel function. This allows communicating kernel
- components to pass a data structure around without engaging in
- ownership protocol.
-
- In the macro instruction format of this request, the offset
- address of the block to be kept is passed in the (DI) general
- purpose register. In the portable form of this request, the far
- pointer is passed according to the calling conventions of the
- high level language.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov di, <AllocatedBlockOffset> ; (DI) = ofs FWA, block.
- mov dl, SYS_KEEP_POOL
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label KeepPool <BlockPtr>
-
- Portable Request Format:
-
- STATUS KeepPool(
- IN PVOID BlockPtr
- );
-
- Parameters:
-
- BlockPtr - Specifies a pointer to a block of memory
- allocated with the AllocatePool kernel function. The
- address must not be normalized as the kernel only uses
- the offset component of the address to locate the block
- of system pool.