Lines Matching refs:heap
26 * NDR heap management. The heap is used for temporary storage by
28 * support the different requirements of the various RPCs, the heap
33 * that we actually need a lot heap space.
36 * allocated, it remains allocated until the heap is destroyed. This
37 * shouldn't be an issue because the heap is being filled with data to
39 * the point that the entire heap is no longer required.
53 * Allocate a heap structure and the first heap block. For many RPC
55 * in this instance of the heap. The only point of note here is that
56 * we put the heap management data in the first block to avoid a
60 * Note that the heap management data is at the start of the first block.
62 * Returns a pointer to the newly created heap, which is used like an
63 * opaque handle with the rest of the heap management interface..
68 ndr_heap_t *heap;
72 if ((heap = malloc(allocsize)) == NULL)
75 base = (char *)heap;
76 bzero(heap, sizeof (ndr_heap_t));
78 heap->iovcnt = NDR_HEAP_MAXIOV;
79 heap->iov = heap->iovec;
80 heap->iov->iov_base = base;
81 heap->iov->iov_len = sizeof (ndr_heap_t);
82 heap->top = base + allocsize;
83 heap->next = base + sizeof (ndr_heap_t);
85 return (heap);
89 * Deallocate all of the memory associated with a heap. This is the
90 * only way to deallocate heap memory, it isn't possible to free the
93 * Note that the first block contains the heap management data, which
97 ndr_heap_destroy(ndr_heap_t *heap)
102 if (heap) {
104 if ((p = heap->iovec[i].iov_base) != NULL)
108 free(heap);
113 * Allocate space in the specified heap. All requests are padded, if
123 ndr_heap_malloc(ndr_heap_t *heap, unsigned size)
130 if (heap == NULL || size == 0)
133 p = heap->next;
135 if (p + size > heap->top) {
136 if ((heap->iovcnt == 0) || ((--heap->iovcnt) == 0))
144 ++heap->iov;
145 heap->iov->iov_base = p;
146 heap->iov->iov_len = 0;
147 heap->top = p + incr_size;
150 heap->next = p + size;
151 heap->iov->iov_len += size;
156 * Convenience function to do heap strdup.
159 ndr_heap_strdup(ndr_heap_t *heap, const char *s)
168 * We don't need to clutter the heap with empty strings.
173 if ((p = ndr_heap_malloc(heap, len+1)) != NULL)
183 ndr_heap_mstring(ndr_heap_t *heap, const char *s, ndr_mstring_t *out)
191 if ((out->str = ndr_heap_strdup(heap, s)) == NULL)
202 * string in the heap as a varying/conformant array. We need to do the
207 ndr_heap_mkvcs(ndr_heap_t *heap, char *s, ndr_vcstr_t *vc)
216 vc->vcs = ndr_heap_malloc(heap, mlen);
227 ndr_heap_mkvcb(ndr_heap_t *heap, uint8_t *data, uint32_t datalen,
242 vcbuf->vcb = ndr_heap_malloc(heap, mlen);
252 * Duplcate a SID in the heap.
255 ndr_heap_siddup(ndr_heap_t *heap, smb_sid_t *sid)
265 if ((new_sid = ndr_heap_malloc(heap, size)) == NULL)
273 ndr_heap_used(ndr_heap_t *heap)
279 used += heap->iovec[i].iov_len;
285 ndr_heap_avail(ndr_heap_t *heap)
290 count = (heap->iovcnt == 0) ? 0 : (heap->iovcnt - 1);
293 avail += (heap->top - heap->next);