MEMALLC(2) — HP-UX
Series 500 Only
NAME
memallc, memfree − allocate and free address space
SYNOPSIS
#include <sys/ems.h>
#include <sys/types.h>
caddr_tmemallc(fileid, offset, len, maxlen, type, mode);
intfileid, offset, len;
intmaxlen, type, mode;
intmemfree(addr);
caddr_taddr;
DESCRIPTION
Memallc allocates a memory segment (i.e. a contiguous piece of process address space) and returns a pointer to it. The memory segment may be shared (i.e. accessible by other processes) or private. Private segments are copied on fork(2), giving separate, per-process images of the segment. Shared segments are not copied across fork(2) but, instead, both processes have access to the same memory space. The segment may optionally be initialized to the contents of a specific open file (private mapped file) or can be made equivalent to a specific file (shared mapped file).
Fileid is the HP-UX file id of an open file which will be mapped into the process’s address space. Fileid must refer to a file on a CS-80 disk. If fileid is −1, the allocated address space will be initialized to zeros. A mapping of a file (either shared or private) generates an implicit reference to the file (similar to the result of dup(2)). Subsequent to the mapping, fileid may safely be closed.
Offset specifies the starting point in fileid (i.e. byte offset) where mapping is to begin. The value returned by memallc is a pointer to the byte in the new address space that corresponds to byte offset. If fileid is not specified (i.e. set to -1), offset is ignored.
Len specifies the size (in bytes) of the address space. The guaranteed range of accessibility is from ptr thru ptr+len-1 (where ptr is the value returned by the memallc call). Depending on the value of offset, len, and the specific implementation, additional data space MAY be accessible at addresses less than ptr and/or greater than ptr+len-1 but the effects of reading and/or writing these areas are undefined.
If len+offset is greater than the size of the file, the additional address space is initialized to zeros. If the segment is shared, the file is extended to the required size (if fileid is not writable, the call fails). A creat(2) call on a file that has a shared mapping applied to it will zero the file but will not alter the file size.
Maxlen specifies the maximum length to which a segment may grow using memvary(2).
Type specifies the attributes assigned to the segment, which is constructed by taking the union of the desired attributes: MEM_SHARED, MEM_PRIVATE, MEM_PAGED, MEM_DATA, or MEM_CODE (see ems(2)).
Mode specifies the access permissions assigned to the segment for the requesting process.
MEM_R, MEM_W, MEM_X:
Initial access modes to be assigned to segment (see memchmd(2)).
Note that all MEM_SHARED mappings of a specific file must use identical access modes. An attempt to map a file with access modes different than those already in effect will return an error [EACCES].
Memfree deallocates a memory segment created by memallc. It takes, as an argument, a pointer returned by memallc. When the segment is shared, the memory will not be deallocated until the last reference to the memory is removed.
The number of segments allocated to a given process at any one time may be limited to a system dependent maximum of MAXSEGS found in ems.h.
RETURN VALUE
Upon successful completion, memallc returns the byte pointer to the address space. Otherwise, a value of -1 is returned and errno is set to indicate error.
AUTHOR
Memallc was developed by the Hewlett-Packard Company.
SEE ALSO
ems(2), memchmd(2), memvary(2), shmget(2), shmop(2).
Hewlett-Packard Company — Version B.1, April 12, 1993