]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/pipe.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / bsd / sys / pipe.h
1 /*
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1996 John S. Dyson
30 * All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice immediately at the beginning of the file, without modification,
37 * this list of conditions, and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. Absolutely no warranty of function or purpose is made by the author
42 * John S. Dyson.
43 * 4. This work was done expressly for inclusion into FreeBSD. Other use
44 * is allowed if this notation is included.
45 * 5. Modifications may be freely made to this file if the above conditions
46 * are met.
47 *
48 * $FreeBSD: src/sys/sys/pipe.h,v 1.24 2003/08/13 20:01:38 alc Exp $
49 */
50
51 #ifndef _SYS_PIPE_H_
52 #define _SYS_PIPE_H_
53
54 #ifdef KERNEL
55 #include <libkern/locks.h>
56 #endif
57 #include <sys/queue.h> /* for TAILQ macros */
58 #include <sys/ev.h>
59 #include <sys/cdefs.h>
60
61 /*
62 * Pipe buffer size, keep moderate in value, pipes take kva space.
63 */
64 #ifndef PIPE_SIZE
65 #define PIPE_SIZE 16384
66 #endif
67
68 #ifndef BIG_PIPE_SIZE
69 #define BIG_PIPE_SIZE (64*1024)
70 #endif
71
72 #ifndef SMALL_PIPE_SIZE
73 #define SMALL_PIPE_SIZE PAGE_SIZE
74 #endif
75
76 /*
77 * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger
78 * than PIPE_BUF.
79 */
80 #ifndef PIPE_MINDIRECT
81 #define PIPE_MINDIRECT 8192
82 #endif
83
84 #define PIPENPAGES (BIG_PIPE_SIZE / PAGE_SIZE + 1)
85
86 /*
87 * Pipe buffer information.
88 * Separate in, out, cnt are used to simplify calculations.
89 * Buffered write is active when the buffer.cnt field is set.
90 */
91 struct pipebuf {
92 u_int cnt; /* number of chars currently in buffer */
93 u_int in; /* in pointer */
94 u_int out; /* out pointer */
95 u_int size; /* size of buffer */
96 caddr_t buffer; /* kva of buffer */
97 };
98
99
100 #ifdef PIPE_DIRECT
101 /*
102 * Information to support direct transfers between processes for pipes.
103 */
104 /* LP64todo - not 64bit safe */
105 struct pipemapping {
106 vm_offset_t kva; /* kernel virtual address */
107 vm_size_t cnt; /* number of chars in buffer */
108 vm_size_t pos; /* current position of transfer */
109 int npages; /* number of pages */
110 vm_page_t ms[PIPENPAGES]; /* pages in source process */
111 };
112 #endif
113
114 /*
115 * Bits in pipe_state.
116 */
117 #define PIPE_ASYNC 0x004 /* Async? I/O. */
118 #define PIPE_WANTR 0x008 /* Reader wants some characters. */
119 #define PIPE_WANTW 0x010 /* Writer wants space to put characters. */
120 #define PIPE_WANT 0x020 /* Pipe is wanted to be run-down. */
121 #define PIPE_SEL 0x040 /* Pipe has a select active. */
122 #define PIPE_EOF 0x080 /* Pipe is in EOF condition. */
123 #define PIPE_LOCKFL 0x100 /* Process has exclusive access to pointers/data. */
124 #define PIPE_LWANT 0x200 /* Process wants exclusive access to pointers/data. */
125 #define PIPE_DIRECTW 0x400 /* Pipe direct write active. */
126 #define PIPE_DIRECTOK 0x800 /* Direct mode ok. */
127 #define PIPE_KNOTE 0x1000 /* Pipe has kernel events activated */
128
129 #ifdef KERNEL
130 /*
131 * Per-pipe data structure.
132 * Two of these are linked together to produce bi-directional pipes.
133 */
134 struct pipe {
135 struct pipebuf pipe_buffer; /* data storage */
136 #ifdef PIPE_DIRECT
137 struct pipemapping pipe_map; /* pipe mapping for direct I/O */
138 #endif
139 struct selinfo pipe_sel; /* for compat with select */
140 pid_t pipe_pgid; /* information for async I/O */
141 struct pipe *pipe_peer; /* link with other direction */
142 u_int pipe_state; /* pipe status info */
143 int pipe_busy; /* busy flag, mostly to handle rundown sanely */
144 #ifdef MAC
145 struct label *pipe_label; /* pipe MAC label - shared */
146 #endif
147 TAILQ_HEAD(,eventqelt) pipe_evlist;
148 lck_mtx_t *pipe_mtxp; /* shared mutex between both pipes */
149 };
150
151 #define PIPE_MTX(pipe) ((pipe)->pipe_mtxp)
152
153 #define PIPE_LOCK(pipe) lck_mtx_lock(PIPE_MTX(pipe))
154 #define PIPE_UNLOCK(pipe) lck_mtx_unlock(PIPE_MTX(pipe))
155 #define PIPE_LOCK_ASSERT(pipe, type) lck_mtx_assert(PIPE_MTX(pipe), (type))
156
157 __BEGIN_DECLS
158 extern int pipe_stat(struct pipe *, struct stat *);
159 __END_DECLS
160
161 #endif /* KERNEL */
162
163 #endif /* !_SYS_PIPE_H_ */