Lines Matching refs:heap

27  * NDR heap management. The heap is used for temporary storage by
29 * support the different requirements of the various RPCs, the heap
34 * that we actually need a lot heap space.
37 * allocated, it remains allocated until the heap is destroyed. This
38 * shouldn't be an issue because the heap is being filled with data to
40 * the point that the entire heap is no longer required.
54 * Allocate a heap structure and the first heap block. For many RPC
56 * in this instance of the heap. The only point of note here is that
57 * we put the heap management data in the first block to avoid a
61 * Note that the heap management data is at the start of the first block.
63 * Returns a pointer to the newly created heap, which is used like an
64 * opaque handle with the rest of the heap management interface..
69 ndr_heap_t *heap;
73 if ((heap = malloc(allocsize)) == NULL)
76 base = (char *)heap;
77 bzero(heap, sizeof (ndr_heap_t));
79 heap->iovcnt = NDR_HEAP_MAXIOV;
80 heap->iov = heap->iovec;
81 heap->iov->iov_base = base;
82 heap->iov->iov_len = sizeof (ndr_heap_t);
83 heap->top = base + allocsize;
84 heap->next = base + sizeof (ndr_heap_t);
86 return (heap);
90 * Deallocate all of the memory associated with a heap. This is the
91 * only way to deallocate heap memory, it isn't possible to free the
94 * Note that the first block contains the heap management data, which
98 ndr_heap_destroy(ndr_heap_t *heap)
103 if (heap) {
105 if ((p = heap->iovec[i].iov_base) != NULL)
109 free(heap);
114 * Allocate space in the specified heap. All requests are padded, if
124 ndr_heap_malloc(ndr_heap_t *heap, unsigned size)
131 if (heap == NULL || size == 0)
134 p = heap->next;
136 if (p + size > heap->top) {
137 if ((heap->iovcnt == 0) || ((--heap->iovcnt) == 0))
145 ++heap->iov;
146 heap->iov->iov_base = p;
147 heap->iov->iov_len = 0;
148 heap->top = p + incr_size;
151 heap->next = p + size;
152 heap->iov->iov_len += size;
157 * Convenience function to do heap strdup.
160 ndr_heap_strdup(ndr_heap_t *heap, const char *s)
169 * We don't need to clutter the heap with empty strings.
174 if ((p = ndr_heap_malloc(heap, len+1)) != NULL)
184 ndr_heap_mstring(ndr_heap_t *heap, const char *s, ndr_mstring_t *out)
192 if ((out->str = ndr_heap_strdup(heap, s)) == NULL)
203 * string in the heap as a varying/conformant array. We need to do the
208 ndr_heap_mkvcs(ndr_heap_t *heap, char *s, ndr_vcstr_t *vc)
217 vc->vcs = ndr_heap_malloc(heap, mlen);
228 ndr_heap_mkvcb(ndr_heap_t *heap, uint8_t *data, uint32_t datalen,
243 vcbuf->vcb = ndr_heap_malloc(heap, mlen);
253 * Duplcate a SID in the heap.
256 ndr_heap_siddup(ndr_heap_t *heap, smb_sid_t *sid)
266 if ((new_sid = ndr_heap_malloc(heap, size)) == NULL)
274 ndr_heap_used(ndr_heap_t *heap)
280 used += heap->iovec[i].iov_len;
286 ndr_heap_avail(ndr_heap_t *heap)
291 count = (heap->iovcnt == 0) ? 0 : (heap->iovcnt - 1);
294 avail += (heap->top - heap->next);