|
NAMEshm_map , shm_unmap —
map shared memory objects into the kernel's address space
SYNOPSIS#include <sys/types.h>
#include <sys/mman.h>
int
int
DESCRIPTIONTheshm_map () and shm_unmap ()
functions provide an API for mapping shared memory objects into the kernel.
Shared memory objects are created by
shm_open(2).
These objects can then be passed into the kernel via file descriptors.
A shared memory object cannot be shrunk while it is mapped into the kernel. This is to avoid invalidating any pages that may be wired into the kernel's address space. Shared memory objects can still be grown while mapped into the kernel. To simplify the accounting needed to enforce the above
requirement, callers of this API are required to unmap the entire region
mapped by The The Note that RETURN VALUESTheshm_map () and shm_unmap ()
functions return zero on success or an error on failure.
EXAMPLESThe following function accepts a file descriptor for a shared memory object. It maps the first sixteen kilobytes of the object into the kernel, performs some work on that address, and then unmaps the address before returning.int shm_example(int fd) { struct file *fp; void *mem; int error; error = fget(curthread, fd, CAP_MMAP, &fp); if (error) return (error); error = shm_map(fp, 16384, 0, &mem); if (error) { fdrop(fp, curthread); return (error); } /* Do something with 'mem'. */ error = shm_unmap(fp, mem, 16384); fdrop(fp, curthread); return (error); } ERRORSTheshm_map () function returns the following errors on
failure:
The
SEE ALSOshm_open(2)HISTORYThis API was first introduced in FreeBSD 10.0.
Visit the GSP FreeBSD Man Page Interface. |