/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* NDR heap management. The heap is used for temporary storage by
* both the client and server side library routines. In order to
* support the different requirements of the various RPCs, the heap
* can grow dynamically if required. We start with a single block
* and perform sub-allocations from it. If an RPC requires more space
* we will continue to add it a block at a time. This means that we
* don't hog lots of memory on every call to support the few times
* that we actually need a lot heap space.
*
* Note that there is no individual free function. Once space has been
* allocated, it remains allocated until the heap is destroyed. This
* shouldn't be an issue because the heap is being filled with data to
* be marshalled or unmarshalled and we need it all to be there until
* the point that the entire heap is no longer required.
*/
#include <stdlib.h>
#include <string.h>
#include <strings.h>
/*
* Allocate a heap structure and the first heap block. For many RPC
* operations this will be the only time we need to malloc memory
* in this instance of the heap. The only point of note here is that
* we put the heap management data in the first block to avoid a
* second malloc. Make sure that sizeof(ndr_heap_t) is smaller
* than NDR_HEAP_BLKSZ.
*
* Note that the heap management data is at the start of the first block.
*
* Returns a pointer to the newly created heap, which is used like an
* opaque handle with the rest of the heap management interface..
*/
ndr_heap_create(void)
{
char *base;
return (NULL);
return (heap);
}
/*
* Deallocate all of the memory associated with a heap. This is the
* only way to deallocate heap memory, it isn't possible to free the
* space obtained by individual malloc calls.
*
* Note that the first block contains the heap management data, which
* is deleted last.
*/
void
{
int i;
char *p;
if (heap) {
for (i = 1; i < NDR_HEAP_MAXIOV; ++i) {
free(p);
}
}
}
/*
* Allocate space in the specified heap. All requests are padded, if
* required, to ensure dword alignment. If the current iov will be
* exceeded, we allocate a new block and setup the next iov. Otherwise
* all we have to do is move the next pointer and update the current
* iov length.
*
* On success, a pointer to the allocated (dword aligned) area is
* returned. Otherwise a null pointer is returned.
*/
void *
{
char *p;
int incr_size;
return (NULL);
return (NULL);
return (NULL);
}
return ((void *)p);
}
/*
* Convenience function to do heap strdup.
*/
void *
{
int len;
void *p;
if (s == NULL)
return (NULL);
/*
* We don't need to clutter the heap with empty strings.
*/
return ("");
(void) strcpy((char *)p, s);
return (p);
}
/*
* Make an ndr_mstring_t from a regular string.
*/
int
{
return (-1);
return (-1);
return (0);
}
/*
* Our regular string marshalling always creates null terminated strings
* but some Windows clients and servers are pedantic about the string
* formats they will accept and require non-null terminated strings.
* This function can be used to build a wide-char, non-null terminated
* string in the heap as a varying/conformant array. We need to do the
* wide-char conversion here because the marshalling code won't be
* aware that this is really a string.
*/
void
{
int mlen;
}
}
void
{
int mlen;
return;
}
}
}
/*
* Duplcate a SID in the heap.
*/
{
unsigned size;
return (NULL);
return (NULL);
return (new_sid);
}
int
{
int used = 0;
int i;
for (i = 0; i < NDR_HEAP_MAXIOV; ++i)
return (used);
}
int
{
int avail;
int count;
return (avail);
}