1*8269e767SBrooks Davis.\" 2*8269e767SBrooks Davis.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" All rights reserved. 5*8269e767SBrooks Davis.\" 6*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 7*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 8*8269e767SBrooks Davis.\" are met: 9*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 12*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 13*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 14*8269e767SBrooks Davis.\" 15*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16*8269e767SBrooks Davis.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*8269e767SBrooks Davis.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*8269e767SBrooks Davis.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19*8269e767SBrooks Davis.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*8269e767SBrooks Davis.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*8269e767SBrooks Davis.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*8269e767SBrooks Davis.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*8269e767SBrooks Davis.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*8269e767SBrooks Davis.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*8269e767SBrooks Davis.\" 26*8269e767SBrooks Davis.Dd January 14, 2019 27*8269e767SBrooks Davis.Dt SHMAT 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm shmat , 31*8269e767SBrooks Davis.Nm shmdt 32*8269e767SBrooks Davis.Nd attach or detach shared memory 33*8269e767SBrooks Davis.Sh LIBRARY 34*8269e767SBrooks Davis.Lb libc 35*8269e767SBrooks Davis.Sh SYNOPSIS 36*8269e767SBrooks Davis.In sys/types.h 37*8269e767SBrooks Davis.In sys/ipc.h 38*8269e767SBrooks Davis.In sys/shm.h 39*8269e767SBrooks Davis.Ft void * 40*8269e767SBrooks Davis.Fn shmat "int shmid" "const void *addr" "int flag" 41*8269e767SBrooks Davis.Ft int 42*8269e767SBrooks Davis.Fn shmdt "const void *addr" 43*8269e767SBrooks Davis.Sh DESCRIPTION 44*8269e767SBrooks DavisThe 45*8269e767SBrooks Davis.Fn shmat 46*8269e767SBrooks Davissystem call 47*8269e767SBrooks Davisattaches the shared memory segment identified by 48*8269e767SBrooks Davis.Fa shmid 49*8269e767SBrooks Davisto the calling process's address space. 50*8269e767SBrooks DavisThe address where the segment 51*8269e767SBrooks Davisis attached is determined as follows: 52*8269e767SBrooks Davis.\" 53*8269e767SBrooks Davis.\" These are cribbed almost exactly from Stevens, _Advanced Programming in 54*8269e767SBrooks Davis.\" the UNIX Environment_. 55*8269e767SBrooks Davis.\" 56*8269e767SBrooks Davis.Bl -bullet 57*8269e767SBrooks Davis.It 58*8269e767SBrooks DavisIf 59*8269e767SBrooks Davis.Fa addr 60*8269e767SBrooks Davisis 0, the segment is attached at an address selected by the 61*8269e767SBrooks Daviskernel. 62*8269e767SBrooks Davis.It 63*8269e767SBrooks DavisIf 64*8269e767SBrooks Davis.Fa addr 65*8269e767SBrooks Davisis nonzero and 66*8269e767SBrooks Davis.Va SHM_RND 67*8269e767SBrooks Davisis not specified in 68*8269e767SBrooks Davis.Fa flag , 69*8269e767SBrooks Davisthe segment is attached the specified address. 70*8269e767SBrooks Davis.It 71*8269e767SBrooks DavisIf 72*8269e767SBrooks Davis.Fa addr 73*8269e767SBrooks Davisis specified and 74*8269e767SBrooks Davis.Va SHM_RND 75*8269e767SBrooks Davisis specified, 76*8269e767SBrooks Davis.Fa addr 77*8269e767SBrooks Davisis rounded down to the nearest multiple of SHMLBA. 78*8269e767SBrooks Davis.El 79*8269e767SBrooks Davis.Pp 80*8269e767SBrooks DavisIf the 81*8269e767SBrooks Davis.Va SHM_REMAP 82*8269e767SBrooks Davisflag is specified and the passed 83*8269e767SBrooks Davis.Fa addr 84*8269e767SBrooks Davisis not 85*8269e767SBrooks Davis.Dv NULL , 86*8269e767SBrooks Davisany existing mappings in the virtual addresses range are 87*8269e767SBrooks Daviscleared before the segment is attached. 88*8269e767SBrooks DavisIf the flag is not specified, 89*8269e767SBrooks Davis.Fa addr 90*8269e767SBrooks Davisis not 91*8269e767SBrooks Davis.Dv NULL , 92*8269e767SBrooks Davisand the virtual address range contains 93*8269e767SBrooks Davissome pre-existing mappings, the 94*8269e767SBrooks Davis.Fn shmat 95*8269e767SBrooks Daviscall fails. 96*8269e767SBrooks Davis.Pp 97*8269e767SBrooks DavisThe 98*8269e767SBrooks Davis.Fn shmdt 99*8269e767SBrooks Davissystem call 100*8269e767SBrooks Davisdetaches the shared memory segment at the address specified by 101*8269e767SBrooks Davis.Fa addr 102*8269e767SBrooks Davisfrom the calling process's address space. 103*8269e767SBrooks Davis.Sh RETURN VALUES 104*8269e767SBrooks DavisUpon success, 105*8269e767SBrooks Davis.Fn shmat 106*8269e767SBrooks Davisreturns the address where the segment is attached; otherwise, -1 107*8269e767SBrooks Davisis returned and 108*8269e767SBrooks Davis.Va errno 109*8269e767SBrooks Davisis set to indicate the error. 110*8269e767SBrooks Davis.Pp 111*8269e767SBrooks Davis.Rv -std shmdt 112*8269e767SBrooks Davis.Sh ERRORS 113*8269e767SBrooks DavisThe 114*8269e767SBrooks Davis.Fn shmat 115*8269e767SBrooks Davissystem call 116*8269e767SBrooks Daviswill fail if: 117*8269e767SBrooks Davis.Bl -tag -width Er 118*8269e767SBrooks Davis.It Bq Er EINVAL 119*8269e767SBrooks DavisNo shared memory segment was found corresponding to 120*8269e767SBrooks Davis.Fa shmid . 121*8269e767SBrooks Davis.It Bq Er EINVAL 122*8269e767SBrooks DavisThe 123*8269e767SBrooks Davis.Fa addr 124*8269e767SBrooks Davisargument 125*8269e767SBrooks Daviswas not an acceptable address. 126*8269e767SBrooks Davis.It Bq Er ENOMEM 127*8269e767SBrooks DavisThe specified 128*8269e767SBrooks Davis.Fa addr 129*8269e767SBrooks Daviscannot be used for mapping, for instance due to the amount of available 130*8269e767SBrooks Davisspace being smaller than the segment size, 131*8269e767SBrooks Davisor because pre-existing mappings are in the range and no 132*8269e767SBrooks Davis.Va SHM_REMAP 133*8269e767SBrooks Davisflag was provided. 134*8269e767SBrooks Davis.It Bq Er EMFILE 135*8269e767SBrooks DavisFailed to attach the shared memory segment because the per-process 136*8269e767SBrooks Davis.Va kern.ipc.shmseg 137*8269e767SBrooks Davis.Xr sysctl 3 138*8269e767SBrooks Davislimit was reached. 139*8269e767SBrooks Davis.El 140*8269e767SBrooks Davis.Pp 141*8269e767SBrooks DavisThe 142*8269e767SBrooks Davis.Fn shmdt 143*8269e767SBrooks Davissystem call 144*8269e767SBrooks Daviswill fail if: 145*8269e767SBrooks Davis.Bl -tag -width Er 146*8269e767SBrooks Davis.It Bq Er EINVAL 147*8269e767SBrooks DavisThe 148*8269e767SBrooks Davis.Fa addr 149*8269e767SBrooks Davisargument 150*8269e767SBrooks Davisdoes not point to a shared memory segment. 151*8269e767SBrooks Davis.El 152*8269e767SBrooks Davis.Sh "SEE ALSO" 153*8269e767SBrooks Davis.Xr shmctl 2 , 154*8269e767SBrooks Davis.Xr shmget 2 155