1 /* $Id: heap.h,v 1.2 1993/07/04 04:04:21 root Exp root $
4 * Copyright Robert J. Amstadt, 1993
11 #include "stackframe.h"
13 /**********************************************************************
14 * LOCAL HEAP STRUCTURES AND FUNCTIONS
16 typedef struct heap_mem_desc_s
18 struct heap_mem_desc_s *prev, *next;
19 unsigned short length;
24 typedef struct heap_local_heap_s
26 struct heap_local_heap_s *next;
28 ATOMTABLE *local_table;
29 unsigned short selector;
30 unsigned short delta; /* Number saved for Windows compat. */
33 extern void HEAP_Init(MDESC **free_list, void *start, int length);
34 extern void *HEAP_Alloc(MDESC **free_list, int flags, int bytes);
35 extern int HEAP_Free(MDESC **free_list, void *block);
36 extern void *HEAP_ReAlloc(MDESC **free_list, void *old_block,
37 int new_size, unsigned int flags);
39 extern LHEAP *HEAP_LocalFindHeap(unsigned short owner);
40 extern unsigned int HEAP_LocalSize(MDESC **free_list, unsigned int handle);
41 extern void HEAP_LocalInit(unsigned short owner, void *start, int length);
43 extern void *WIN16_LocalAlloc(int flags, int bytes);
44 extern int WIN16_LocalCompact(int min_free);
45 extern unsigned int WIN16_LocalFlags(unsigned int handle);
46 extern unsigned int WIN16_LocalFree(unsigned int handle);
47 extern void *WIN16_LocalLock(unsigned int handle);
48 extern void *WIN16_LocalReAlloc(unsigned int handle, int flags, int bytes);
49 extern unsigned int WIN16_LocalUnlock(unsigned int handle);
51 /* Use ds instead of owner of cs */
52 #define HEAP_OWNER (pStack16Frame->ds)
53 #define LOCALHEAP() (&HEAP_LocalFindHeap(HEAP_OWNER)->free_list)
54 #define LOCALATOMTABLE() (&HEAP_LocalFindHeap(HEAP_OWNER)->local_table)
56 /**********************************************************************
57 * GLOBAL HEAP STRUCTURES AND FUNCTIONS:
59 * Global memory pool descriptor. Segments MUST be maintained in segment
60 * ascending order. If not the reallocation routine will die a horrible
63 * handle = 0, this descriptor contains the address of a free pool.
64 * != 0, this describes an allocated block.
66 * sequence = 0, this is not a huge block
67 * > 0, this is a portion of a huge block
68 * =-1, this is a free segment
70 * addr - address of this memory block.
72 * length - used to maintain huge blocks.
74 typedef struct global_mem_desc_s
76 struct global_mem_desc_s *next; /* Next GDESC in list */
77 struct global_mem_desc_s *prev; /* Previous GDESC in list */
78 unsigned short handle; /* Handle of this block. */
79 short sequence; /* Block sequence # in huge block */
80 void *addr; /* Address allocated with mmap() */
81 int length; /* Length of block */
82 int lock_count; /* Block lock count */
83 unsigned short alias; /* Offset-zero alias selector */
84 unsigned int alias_key; /* Offset-zero alias sh. mem. key */
85 void *linear_addr; /* Linear address of huge block */
86 int linear_key; /* Linear shared memory key */
87 int linear_count; /* Linear lock count */
90 extern GDESC *GlobalList;
92 extern void *GlobalQuickAlloc(int size);
93 extern unsigned int GlobalHandleFromPointer(void *block);
94 extern GDESC *GlobalGetGDesc(unsigned int block);
95 extern void *GlobalLinearLock(unsigned int block);
96 extern unsigned int GlobalLinearUnlock(unsigned int block);