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