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