1.\" $OpenBSD: shmat.2,v 1.16 2014/11/15 22:19:53 guenther Exp $ 2.\" $NetBSD: shmat.2,v 1.2 1997/03/27 08:20:38 mikel Exp $ 3.\" 4.\" Copyright (c) 1995 Frank van der Linden 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project 18.\" by Frank van der Linden 19.\" 4. The name of the author may not be used to endorse or promote products 20.\" derived from this software without specific prior written permission 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\"/ 33.Dd $Mdocdate: November 15 2014 $ 34.Dt SHMAT 2 35.Os 36.Sh NAME 37.Nm shmat , 38.Nm shmdt 39.Nd map/unmap shared memory 40.Sh SYNOPSIS 41.In sys/shm.h 42.Ft void * 43.Fn shmat "int shmid" "const void *shmaddr" "int shmflg" 44.Ft int 45.Fn shmdt "const void *shmaddr" 46.Sh DESCRIPTION 47.Fn shmat 48maps the shared memory segment associated with the shared memory identifier 49.Fa shmid 50into the address space of the calling process. 51The address at which the segment is mapped is determined by the 52.Fa shmaddr 53parameter. 54If it is equal to 0, the system will pick an address itself. 55Otherwise, an attempt is made to map the shared memory segment at the 56address 57.Fa shmaddr 58specifies. 59If 60.Dv SHM_RND 61is set in 62.Fa shmflg , 63the system will round the address down to a multiple of 64.Dv SHMLBA 65bytes 66.Pf ( Dv SHMLBA 67is defined in 68.In sys/shm.h ) . 69.Pp 70A shared memory segment can be mapped read-only by specifying the 71.Dv SHM_RDONLY 72flag in 73.Fa shmflg . 74.Pp 75.Fn shmdt 76unmaps the shared memory segment that is currently mapped at 77.Fa shmaddr 78from the calling process' address space. 79.Fa shmaddr 80must be a value returned by a prior 81.Fn shmat 82call. 83A shared memory segment will remain existent until it is removed by 84a call to 85.Xr shmctl 2 86with the 87.Dv IPC_RMID 88command. 89.Sh RETURN VALUES 90.Fn shmat 91returns the address at which the shared memory segment has been mapped into 92the calling process' address space when successful, 93.Fn shmdt 94returns 0 on successful completion. 95Otherwise, a value of \-1 is returned, and the global variable 96.Va errno 97is set to indicate the error. 98.Sh ERRORS 99.Fn shmat 100will fail if: 101.Bl -tag -width Er 102.It Bq Er EACCES 103The calling process has no permission to access this shared memory segment. 104.It Bq Er ENOMEM 105There is not enough available data space for the calling process to 106map the shared memory segment. 107.It Bq Er EINVAL 108.Fa shmid 109is not a valid shared memory identifier. 110.Pp 111.Fa shmaddr 112specifies an illegal address. 113.It Bq Er EMFILE 114The number of shared memory segments has reached the system-wide limit. 115.El 116.Pp 117.Fn shmdt 118will fail if: 119.Bl -tag -width Er 120.It Bq Er EINVAL 121.Fa shmaddr 122is not the start address of a mapped shared memory segment. 123.El 124.Sh SEE ALSO 125.Xr ipcrm 1 , 126.Xr ipcs 1 , 127.Xr mmap 2 , 128.Xr shmctl 2 , 129.Xr shmget 2 130