]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
f427ee49 | 2 | * Copyright (c) 2004-2020 Apple Computer, Inc. All rights reserved. |
91447636 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
91447636 A |
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 | */ | |
2d21ac55 A |
50 | /* |
51 | * NOTICE: This file was modified by SPARTA, Inc. in 2006 to introduce | |
52 | * support for mandatory and extensible security protections. This notice | |
53 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
54 | * Version 2.0. | |
55 | */ | |
91447636 A |
56 | |
57 | #ifndef _SYS_PIPE_H_ | |
58 | #define _SYS_PIPE_H_ | |
59 | ||
0a7de745 | 60 | #ifdef KERNEL |
91447636 | 61 | #include <libkern/locks.h> |
f427ee49 | 62 | #include <os/base.h> |
91447636 | 63 | #endif |
0a7de745 | 64 | #include <sys/queue.h> /* for TAILQ macros */ |
91447636 A |
65 | #include <sys/ev.h> |
66 | #include <sys/cdefs.h> | |
5ba3f43e A |
67 | #include <sys/_types/_caddr_t.h> |
68 | #include <sys/_types/_u_int.h> | |
91447636 A |
69 | |
70 | /* | |
71 | * Pipe buffer size, keep moderate in value, pipes take kva space. | |
72 | */ | |
73 | #ifndef PIPE_SIZE | |
0a7de745 | 74 | #define PIPE_SIZE 16384 |
91447636 A |
75 | #endif |
76 | ||
0a7de745 | 77 | #define PIPE_KVAMAX (1024 * 1024 * 16) |
316670eb | 78 | |
91447636 | 79 | #ifndef BIG_PIPE_SIZE |
0a7de745 | 80 | #define BIG_PIPE_SIZE (64*1024) |
91447636 A |
81 | #endif |
82 | ||
83 | #ifndef SMALL_PIPE_SIZE | |
0a7de745 | 84 | #define SMALL_PIPE_SIZE PAGE_SIZE |
91447636 A |
85 | #endif |
86 | ||
87 | /* | |
88 | * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger | |
89 | * than PIPE_BUF. | |
90 | */ | |
91 | #ifndef PIPE_MINDIRECT | |
0a7de745 | 92 | #define PIPE_MINDIRECT 8192 |
91447636 A |
93 | #endif |
94 | ||
0a7de745 | 95 | #define PIPENPAGES (BIG_PIPE_SIZE / PAGE_SIZE + 1) |
91447636 A |
96 | |
97 | /* | |
98 | * Pipe buffer information. | |
99 | * Separate in, out, cnt are used to simplify calculations. | |
100 | * Buffered write is active when the buffer.cnt field is set. | |
101 | */ | |
102 | struct pipebuf { | |
0a7de745 A |
103 | u_int cnt; /* number of chars currently in buffer */ |
104 | u_int in; /* in pointer */ | |
105 | u_int out; /* out pointer */ | |
106 | u_int size; /* size of buffer */ | |
f427ee49 A |
107 | #if KERNEL |
108 | caddr_t OS_PTRAUTH_SIGNED_PTR("pipe.buffer") buffer; /* kva of buffer */ | |
109 | #else | |
110 | caddr_t buffer; /* kva of buffer */ | |
111 | #endif /* KERNEL */ | |
91447636 A |
112 | }; |
113 | ||
114 | ||
115 | #ifdef PIPE_DIRECT | |
116 | /* | |
117 | * Information to support direct transfers between processes for pipes. | |
118 | */ | |
91447636 | 119 | struct pipemapping { |
0a7de745 A |
120 | vm_offset_t kva; /* kernel virtual address */ |
121 | vm_size_t cnt; /* number of chars in buffer */ | |
122 | vm_size_t pos; /* current position of transfer */ | |
123 | int npages; /* number of pages */ | |
124 | vm_page_t ms[PIPENPAGES]; /* pages in source process */ | |
91447636 A |
125 | }; |
126 | #endif | |
127 | ||
128 | /* | |
129 | * Bits in pipe_state. | |
130 | */ | |
0a7de745 A |
131 | #define PIPE_ASYNC 0x004 /* Async? I/O. */ |
132 | #define PIPE_WANTR 0x008 /* Reader wants some characters. */ | |
133 | #define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ | |
134 | #define PIPE_WANT 0x020 /* Pipe is wanted to be run-down. */ | |
135 | #define PIPE_SEL 0x040 /* Pipe has a select active. */ | |
136 | #define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ | |
137 | #define PIPE_LOCKFL 0x100 /* Process has exclusive access to pointers/data. */ | |
138 | #define PIPE_LWANT 0x200 /* Process wants exclusive access to pointers/data. */ | |
139 | #define PIPE_DIRECTW 0x400 /* Pipe direct write active. */ | |
140 | #define PIPE_DIRECTOK 0x800 /* Direct mode ok. */ | |
cb323159 | 141 | // was PIPE_KNOTE 0x1000 |
0a7de745 A |
142 | #define PIPE_DRAIN 0x2000 /* Waiting for I/O to drop for a close. Treated like EOF; |
143 | * only separate for easier debugging. */ | |
144 | #define PIPE_WSELECT 0x4000 /* Some thread has done an FWRITE select on the pipe */ | |
145 | #define PIPE_DEAD 0x8000 /* Pipe is dead and needs garbage collection */ | |
146 | ||
147 | #ifdef KERNEL | |
2d21ac55 A |
148 | |
149 | struct label; | |
150 | ||
91447636 A |
151 | /* |
152 | * Per-pipe data structure. | |
153 | * Two of these are linked together to produce bi-directional pipes. | |
154 | */ | |
155 | struct pipe { | |
0a7de745 | 156 | struct pipebuf pipe_buffer; /* data storage */ |
91447636 | 157 | #ifdef PIPE_DIRECT |
0a7de745 | 158 | struct pipemapping pipe_map; /* pipe mapping for direct I/O */ |
91447636 | 159 | #endif |
0a7de745 A |
160 | struct selinfo pipe_sel; /* for compat with select */ |
161 | pid_t pipe_pgid; /* information for async I/O */ | |
162 | struct pipe *pipe_peer; /* link with other direction */ | |
163 | u_int pipe_state; /* pipe status info */ | |
164 | int pipe_busy; /* busy flag, mostly to handle rundown sanely */ | |
0a7de745 A |
165 | lck_mtx_t *pipe_mtxp; /* shared mutex between both pipes */ |
166 | struct timespec st_atimespec; /* time of last access */ | |
167 | struct timespec st_mtimespec; /* time of last data modification */ | |
168 | struct timespec st_ctimespec; /* time of last status change */ | |
169 | struct label *pipe_label; /* pipe MAC label - shared */ | |
91447636 A |
170 | }; |
171 | ||
0a7de745 | 172 | #define PIPE_MTX(pipe) ((pipe)->pipe_mtxp) |
91447636 | 173 | |
0a7de745 A |
174 | #define PIPE_LOCK(pipe) lck_mtx_lock(PIPE_MTX(pipe)) |
175 | #define PIPE_UNLOCK(pipe) lck_mtx_unlock(PIPE_MTX(pipe)) | |
5ba3f43e | 176 | #define PIPE_LOCK_ASSERT(pipe, type) LCK_MTX_ASSERT(PIPE_MTX(pipe), (type)) |
91447636 A |
177 | |
178 | __BEGIN_DECLS | |
2d21ac55 | 179 | extern int pipe_stat(struct pipe *, void *, int); |
f427ee49 A |
180 | #ifdef BSD_KERNEL_PRIVATE |
181 | extern uint64_t pipe_id(struct pipe *); | |
182 | #endif | |
91447636 A |
183 | __END_DECLS |
184 | ||
0a7de745 | 185 | #endif /* KERNEL */ |
91447636 A |
186 | |
187 | #endif /* !_SYS_PIPE_H_ */ |