xref: /dflybsd-src/lib/libc/sysvipc/sysvipc_shm.h (revision ff86f40163b90743b832c47e55fc6ca83aa45121)
182657471SMarkus Pfeiffer /*
282657471SMarkus Pfeiffer  * Copyright (c) 2013 Larisa Grigore <larisagrigore@gmail.com>.
382657471SMarkus Pfeiffer  *
482657471SMarkus Pfeiffer  * Redistribution and use in source and binary forms, with or without
582657471SMarkus Pfeiffer  * modification, are permitted provided that the following conditions
682657471SMarkus Pfeiffer  * are met:
782657471SMarkus Pfeiffer  * 1. Redistributions of source code must retain the above copyright
882657471SMarkus Pfeiffer  *    notice, this list of conditions and the following disclaimer.
982657471SMarkus Pfeiffer  * 2. Redistributions in binary form must reproduce the above copyright
1082657471SMarkus Pfeiffer  *    notice, this list of conditions and the following disclaimer in the
1182657471SMarkus Pfeiffer  *    documentation and/or other materials provided with the distribution.
1282657471SMarkus Pfeiffer  * 3. All advertising materials mentioning features or use of this software
1382657471SMarkus Pfeiffer  *    must display the following acknowledgement:
1482657471SMarkus Pfeiffer  *	This product includes software developed by Adam Glass and Charles
1582657471SMarkus Pfeiffer  *	Hannum.
1682657471SMarkus Pfeiffer  * 4. The names of the authors may not be used to endorse or promote products
1782657471SMarkus Pfeiffer  *    derived from this software without specific prior written permission.
1882657471SMarkus Pfeiffer  *
1982657471SMarkus Pfeiffer  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
2082657471SMarkus Pfeiffer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2182657471SMarkus Pfeiffer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2282657471SMarkus Pfeiffer  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2382657471SMarkus Pfeiffer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2482657471SMarkus Pfeiffer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2582657471SMarkus Pfeiffer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2682657471SMarkus Pfeiffer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2782657471SMarkus Pfeiffer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2882657471SMarkus Pfeiffer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2982657471SMarkus Pfeiffer  */
3082657471SMarkus Pfeiffer 
31*ff86f401SSascha Wildner #ifndef _SYSVIPC_SHM_H_
32*ff86f401SSascha Wildner #define _SYSVIPC_SHM_H_
3382657471SMarkus Pfeiffer 
3482657471SMarkus Pfeiffer #include <sys/ipc.h>
3582657471SMarkus Pfeiffer 
3682657471SMarkus Pfeiffer /* This flag is used to mark a semaphore group
3782657471SMarkus Pfeiffer  * as removed by another process.
3882657471SMarkus Pfeiffer  */
3982657471SMarkus Pfeiffer #define SEG_ALREADY_REMOVED	2
4082657471SMarkus Pfeiffer 
4182657471SMarkus Pfeiffer struct shm_data {
4282657471SMarkus Pfeiffer 	int fd;		/* The file descriptor of the file used as
4382657471SMarkus Pfeiffer 			   shared memory. */
4482657471SMarkus Pfeiffer 	size_t size;
4582657471SMarkus Pfeiffer 	int shmid;
4682657471SMarkus Pfeiffer 	int type;	/* shm, sem, msg or undo;
4782657471SMarkus Pfeiffer 			undo segments are used for semops with UNDO flag set. */
4882657471SMarkus Pfeiffer 	void *internal;
4982657471SMarkus Pfeiffer 	int used;	/* Number of thread that use this segment. */
5082657471SMarkus Pfeiffer 	int removed;	/* The segment was mark for removal by a thread. */
5182657471SMarkus Pfeiffer 	int access;	/* Used only for sems to avoid a segfault when try to
5282657471SMarkus Pfeiffer 			access a semaphore wthout permission. */
5382657471SMarkus Pfeiffer };
5482657471SMarkus Pfeiffer 
5582657471SMarkus Pfeiffer int _shmget(key_t, size_t, int, int);
5682657471SMarkus Pfeiffer void shmchild(void);
5782657471SMarkus Pfeiffer 
5882657471SMarkus Pfeiffer int sysvipc_shmget(key_t, size_t, int);
5982657471SMarkus Pfeiffer int sysvipc_shmctl(int, int, struct shmid_ds *);
6082657471SMarkus Pfeiffer void *sysvipc_shmat(int, const void *, int);
6182657471SMarkus Pfeiffer int sysvipc_shmdt(const void *);
6282657471SMarkus Pfeiffer 
6382657471SMarkus Pfeiffer struct shm_data *get_shmdata(int, int, int);
6482657471SMarkus Pfeiffer int set_shmdata_access(int, int);
6582657471SMarkus Pfeiffer 
66*ff86f401SSascha Wildner #endif /* !_SYSVIPC_SHM_H_ */
67