11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914482Shsu * @(#)mman.h 8.2 (Berkeley) 1/9/95 3050477Speter * $FreeBSD: stable/10/sys/sys/mman.h 321717 2017-07-30 10:36:20Z kib $ 311541Srgrimes */ 321541Srgrimes 332165Spaul#ifndef _SYS_MMAN_H_ 342165Spaul#define _SYS_MMAN_H_ 352165Spaul 36102325Smike#include <sys/cdefs.h> 37102325Smike#include <sys/_types.h> 3834319Sdufault 39102325Smike#if __BSD_VISIBLE 401541Srgrimes/* 4182295Sdillon * Inheritance for minherit() 4282295Sdillon */ 4382295Sdillon#define INHERIT_SHARE 0 4482295Sdillon#define INHERIT_COPY 1 4582295Sdillon#define INHERIT_NONE 2 46319278Sdelphij#define INHERIT_ZERO 3 47102325Smike#endif 4882295Sdillon 4982295Sdillon/* 501541Srgrimes * Protections are chosen from these bits, or-ed together 511541Srgrimes */ 5214482Shsu#define PROT_NONE 0x00 /* no permissions */ 531541Srgrimes#define PROT_READ 0x01 /* pages can be read */ 541541Srgrimes#define PROT_WRITE 0x02 /* pages can be written */ 551541Srgrimes#define PROT_EXEC 0x04 /* pages can be executed */ 561541Srgrimes 571541Srgrimes/* 581541Srgrimes * Flags contain sharing type and options. 591541Srgrimes * Sharing types; choose one. 601541Srgrimes */ 619507Sdg#define MAP_SHARED 0x0001 /* share changes */ 629507Sdg#define MAP_PRIVATE 0x0002 /* changes are private */ 63144531Sdas#if __BSD_VISIBLE 649507Sdg#define MAP_COPY MAP_PRIVATE /* Obsolete */ 65144531Sdas#endif 661541Srgrimes 671541Srgrimes/* 681541Srgrimes * Other flags 691541Srgrimes */ 701541Srgrimes#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ 71144531Sdas 72144531Sdas#if __BSD_VISIBLE 731541Srgrimes#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ 741541Srgrimes#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ 7582295Sdillon#define MAP_RESERVED0080 0x0080 /* previously misimplemented MAP_INHERIT */ 7682285Sdillon#define MAP_RESERVED0100 0x0100 /* previously unimplemented MAP_NOEXTEND */ 771541Srgrimes#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ 7842360Sjulian#define MAP_STACK 0x0400 /* region grows down, like a stack */ 7957550Sps#define MAP_NOSYNC 0x0800 /* page to but do not sync underlying file */ 801541Srgrimes 8157550Sps/* 82102325Smike * Mapping type 83102325Smike */ 84102325Smike#define MAP_FILE 0x0000 /* map from file (default) */ 85102325Smike#define MAP_ANON 0x1000 /* allocated from memory, swap space */ 86198973Sed#ifndef _KERNEL 87198973Sed#define MAP_ANONYMOUS MAP_ANON /* For compatibility. */ 88198973Sed#endif /* !_KERNEL */ 89102325Smike 90102325Smike/* 9157550Sps * Extended flags 9257550Sps */ 93321717Skib#define MAP_GUARD 0x00002000 /* reserve but don't map address range */ 94267901Skib#define MAP_EXCL 0x00004000 /* for MAP_FIXED, fail if address is used */ 9557550Sps#define MAP_NOCORE 0x00020000 /* dont include these pages in a coredump */ 96211937Salc#define MAP_PREFAULT_READ 0x00040000 /* prefault mapping for reading */ 97255426Sjhb#ifdef __LP64__ 98255426Sjhb#define MAP_32BIT 0x00080000 /* map in the low 2GB of address space */ 99255426Sjhb#endif 100254430Sjhb 101254430Sjhb/* 102254430Sjhb * Request specific alignment (n == log2 of the desired alignment). 103254430Sjhb * 104254430Sjhb * MAP_ALIGNED_SUPER requests optimal superpage alignment, but does 105254430Sjhb * not enforce a specific alignment. 106254430Sjhb */ 107254430Sjhb#define MAP_ALIGNED(n) ((n) << MAP_ALIGNMENT_SHIFT) 108254430Sjhb#define MAP_ALIGNMENT_SHIFT 24 109254430Sjhb#define MAP_ALIGNMENT_MASK MAP_ALIGNED(0xff) 110254430Sjhb#define MAP_ALIGNED_SUPER MAP_ALIGNED(1) /* align on a superpage */ 111102325Smike#endif /* __BSD_VISIBLE */ 11257550Sps 113102325Smike#if __POSIX_VISIBLE >= 199309 1141541Srgrimes/* 11534030Sdufault * Process memory locking 11634030Sdufault */ 11734030Sdufault#define MCL_CURRENT 0x0001 /* Lock only current memory */ 11834030Sdufault#define MCL_FUTURE 0x0002 /* Lock all future memory as well */ 119102325Smike#endif 12034030Sdufault 12134030Sdufault/* 12220346Salex * Error return from mmap() 12320346Salex */ 12432131Salex#define MAP_FAILED ((void *)-1) 12520346Salex 12620346Salex/* 1277358Sdg * msync() flags 1287358Sdg */ 12931497Sdyson#define MS_SYNC 0x0000 /* msync synchronously */ 1307358Sdg#define MS_ASYNC 0x0001 /* return immediately */ 1317358Sdg#define MS_INVALIDATE 0x0002 /* invalidate all cached data */ 1327358Sdg 1337358Sdg/* 1341541Srgrimes * Advice to madvise 1351541Srgrimes */ 136144531Sdas#define _MADV_NORMAL 0 /* no further special treatment */ 137144531Sdas#define _MADV_RANDOM 1 /* expect random page references */ 138144531Sdas#define _MADV_SEQUENTIAL 2 /* expect sequential page references */ 139144531Sdas#define _MADV_WILLNEED 3 /* will need these pages */ 140144531Sdas#define _MADV_DONTNEED 4 /* dont need these pages */ 141144531Sdas 142144531Sdas#if __BSD_VISIBLE 143144531Sdas#define MADV_NORMAL _MADV_NORMAL 144144531Sdas#define MADV_RANDOM _MADV_RANDOM 145144531Sdas#define MADV_SEQUENTIAL _MADV_SEQUENTIAL 146144531Sdas#define MADV_WILLNEED _MADV_WILLNEED 147144531Sdas#define MADV_DONTNEED _MADV_DONTNEED 14815873Sdyson#define MADV_FREE 5 /* dont need these pages, and junk contents */ 14954467Sdillon#define MADV_NOSYNC 6 /* try to avoid flushes to physical media */ 15054467Sdillon#define MADV_AUTOSYNC 7 /* revert to default flushing strategy */ 15157550Sps#define MADV_NOCORE 8 /* do not include these pages in a core file */ 15257550Sps#define MADV_CORE 9 /* revert to including pages in a core file */ 153112881Swes#define MADV_PROTECT 10 /* protect process from pageout kill */ 1541541Srgrimes 15515819Sdyson/* 15615819Sdyson * Return bits from mincore 15715819Sdyson */ 15815819Sdyson#define MINCORE_INCORE 0x1 /* Page is incore */ 15915819Sdyson#define MINCORE_REFERENCED 0x2 /* Page has been referenced by us */ 16015819Sdyson#define MINCORE_MODIFIED 0x4 /* Page has been modified by us */ 16115819Sdyson#define MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */ 16215819Sdyson#define MINCORE_MODIFIED_OTHER 0x10 /* Page has been modified */ 163177680Sps#define MINCORE_SUPER 0x20 /* Page is a "super" page */ 164175164Sjhb 165175164Sjhb/* 166175164Sjhb * Anonymous object constant for shm_open(). 167175164Sjhb */ 168175164Sjhb#define SHM_ANON ((char *)1) 169102325Smike#endif /* __BSD_VISIBLE */ 17015819Sdyson 171102325Smike/* 172118684Sbms * XXX missing POSIX_TYPED_MEM_* macros and 173102325Smike * posix_typed_mem_info structure. 174102325Smike */ 175118684Sbms#if __POSIX_VISIBLE >= 200112 176144531Sdas#define POSIX_MADV_NORMAL _MADV_NORMAL 177144531Sdas#define POSIX_MADV_RANDOM _MADV_RANDOM 178144531Sdas#define POSIX_MADV_SEQUENTIAL _MADV_SEQUENTIAL 179144531Sdas#define POSIX_MADV_WILLNEED _MADV_WILLNEED 180144531Sdas#define POSIX_MADV_DONTNEED _MADV_DONTNEED 181118684Sbms#endif 182102325Smike 183102325Smike#ifndef _MODE_T_DECLARED 184102325Smiketypedef __mode_t mode_t; 185102325Smike#define _MODE_T_DECLARED 186102325Smike#endif 187102325Smike 188102325Smike#ifndef _OFF_T_DECLARED 189102325Smiketypedef __off_t off_t; 190102325Smike#define _OFF_T_DECLARED 191102325Smike#endif 192102325Smike 193102325Smike#ifndef _SIZE_T_DECLARED 194102325Smiketypedef __size_t size_t; 195102325Smike#define _SIZE_T_DECLARED 196102325Smike#endif 197102325Smike 198233760Sjhb#if defined(_KERNEL) || defined(_WANT_FILE) 199254603Skib#include <sys/lock.h> 200254603Skib#include <sys/mutex.h> 201254603Skib#include <sys/queue.h> 202254603Skib#include <sys/rangelock.h> 203175164Sjhb#include <vm/vm.h> 2041541Srgrimes 205228509Sjhbstruct file; 206228509Sjhb 207175164Sjhbstruct shmfd { 208175164Sjhb size_t shm_size; 209175164Sjhb vm_object_t shm_object; 210175164Sjhb int shm_refs; 211175164Sjhb uid_t shm_uid; 212175164Sjhb gid_t shm_gid; 213175164Sjhb mode_t shm_mode; 214228509Sjhb int shm_kmappings; 215175164Sjhb 216175164Sjhb /* 217175164Sjhb * Values maintained solely to make this a better-behaved file 218175164Sjhb * descriptor for fstat() to run on. 219175164Sjhb */ 220175164Sjhb struct timespec shm_atime; 221175164Sjhb struct timespec shm_mtime; 222175164Sjhb struct timespec shm_ctime; 223175164Sjhb struct timespec shm_birthtime; 224271399Sjhb ino_t shm_ino; 225175164Sjhb 226175164Sjhb struct label *shm_label; /* MAC label */ 227233760Sjhb const char *shm_path; 228254603Skib 229254603Skib struct rangelock shm_rl; 230254603Skib struct mtx shm_mtx; 231175164Sjhb}; 232233760Sjhb#endif 233175164Sjhb 234233760Sjhb#ifdef _KERNEL 235175164Sjhbint shm_mmap(struct shmfd *shmfd, vm_size_t objsize, vm_ooffset_t foff, 236175164Sjhb vm_object_t *obj); 237228509Sjhbint shm_map(struct file *fp, size_t size, off_t offset, void **memp); 238228509Sjhbint shm_unmap(struct file *fp, void *mem, size_t size); 239233760Sjhbvoid shm_path(struct shmfd *shmfd, char *path, size_t size); 240175164Sjhb 241175164Sjhb#else /* !_KERNEL */ 242175164Sjhb 2431541Srgrimes__BEGIN_DECLS 244102325Smike/* 245128680Smux * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(), 246128680Smux * posix_typed_mem_open(). 247102325Smike */ 248102325Smike#if __BSD_VISIBLE 249197331Salcint getpagesizes(size_t *, int); 250102325Smikeint madvise(void *, size_t, int); 251102325Smikeint mincore(const void *, size_t, char *); 252102325Smikeint minherit(void *, size_t, int); 253102325Smike#endif 254102325Smikeint mlock(const void *, size_t); 25524896Sbde#ifndef _MMAP_DECLARED 25624896Sbde#define _MMAP_DECLARED 25792719Salfredvoid * mmap(void *, size_t, int, int, int, off_t); 25824896Sbde#endif 25992719Salfredint mprotect(const void *, size_t, int); 26092719Salfredint msync(void *, size_t, int); 26192719Salfredint munlock(const void *, size_t); 26292719Salfredint munmap(void *, size_t); 263118684Sbms#if __POSIX_VISIBLE >= 200112 264118684Sbmsint posix_madvise(void *, size_t, int); 265118684Sbms#endif 266102325Smike#if __POSIX_VISIBLE >= 199309 267118771Sbmsint mlockall(int); 268118771Sbmsint munlockall(void); 269102325Smikeint shm_open(const char *, int, mode_t); 270102325Smikeint shm_unlink(const char *); 27134030Sdufault#endif 2721541Srgrimes__END_DECLS 2731541Srgrimes 27455205Speter#endif /* !_KERNEL */ 2752165Spaul 276102325Smike#endif /* !_SYS_MMAN_H_ */ 277