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