18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
25 /* All Rights Reserved */
26
27
28 #ifndef _SYS_PTMS_H
29 #define _SYS_PTMS_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #ifdef _KERNEL
36
37 /*
38 * Structures and definitions supporting the pseudo terminal
39 * drivers. This structure is private and should not be used by any
40 * applications.
41 */
42 struct pt_ttys {
43 queue_t *ptm_rdq; /* master's read queue pointer */
44 queue_t *pts_rdq; /* slave's read queue pointer */
45 mblk_t *pt_nullmsg; /* 0-bytes message block for pts close */
46 pid_t pt_pid; /* process id (for debugging) */
47 minor_t pt_minor; /* Minor number of this pty */
48 int pt_refcnt; /* reference count for ptm_rdq/pts_rdq uses */
49 ushort_t pt_state; /* state of master/slave pair */
50 kcondvar_t pt_cv; /* condition variable for exclusive access */
51 kmutex_t pt_lock; /* Per-element lock */
52 zoneid_t pt_zoneid; /* Zone membership for this pty */
53 uid_t pt_ruid; /* Real owner of pty */
54 gid_t pt_rgid; /* Real group owner of pty */
55 };
56
57 /*
58 * pt_state values
59 */
60 #define PTLOCK 0x01 /* master/slave pair is locked */
61 #define PTMOPEN 0x02 /* master side is open */
62 #define PTSOPEN 0x04 /* slave side is open */
63 #define PTSTTY 0x08 /* slave side is tty */
64
65 /*
66 * Multi-threading primitives.
67 * Values of pt_refcnt: -1 if a writer is accessing the struct
68 * 0 if no one is reading or writing
69 * > 0 equals to the number of readers accessing the struct
70 */
71 #define PT_ENTER_READ(p) { \
72 mutex_enter(&(p)->pt_lock); \
73 while ((p)->pt_refcnt < 0) \
74 cv_wait(&((p)->pt_cv), &(p)->pt_lock); \
75 (p)->pt_refcnt++; \
76 mutex_exit(&(p)->pt_lock); \
77 }
78
79 #define PT_ENTER_WRITE(p) { \
80 mutex_enter(&(p)->pt_lock); \
81 while ((p)->pt_refcnt != 0) \
82 cv_wait(&((p)->pt_cv), &(p)->pt_lock); \
83 (p)->pt_refcnt = -1; \
93 }
94
95 #define PT_EXIT_WRITE(p) { \
96 mutex_enter(&(p)->pt_lock); \
97 ASSERT((p)->pt_refcnt == -1); \
98 (p)->pt_refcnt = 0; \
99 cv_broadcast(&(p)->pt_cv); \
100 mutex_exit(&(p)->pt_lock); \
101 }
102
103 /*
104 * ptms_lock and pt_cnt are defined in ptms_conf.c
105 */
106 extern kmutex_t ptms_lock;
107 extern dev_info_t *pts_dip; /* private copy of devinfo ptr */
108
109 extern void ptms_init(void);
110 extern struct pt_ttys *pt_ttys_alloc(void);
111 extern void ptms_close(struct pt_ttys *, uint_t);
112 extern struct pt_ttys *ptms_minor2ptty(minor_t);
113 extern int ptms_attach_slave(void);
114 extern int ptms_minor_valid(minor_t ptmin, uid_t *uid, gid_t *gid);
115 extern int ptms_minor_exists(minor_t ptmin);
116 extern void ptms_set_owner(minor_t ptmin, uid_t uid, gid_t gid);
117 extern major_t ptms_slave_attached(void);
118
119 #ifdef DEBUG
120 extern void ptms_log(char *, uint_t);
121 extern void ptms_logp(char *, uintptr_t);
122 #define DDBG(a, b) ptms_log(a, b)
123 #define DDBGP(a, b) ptms_logp(a, b)
124 #else
125 #define DDBG(a, b)
126 #define DDBGP(a, b)
127 #endif
128
129 #endif /* _KERNEL */
130
131 typedef struct pt_own {
132 uid_t pto_ruid;
133 gid_t pto_rgid;
134 } pt_own_t;
135
136 /*
137 * ioctl commands
138 *
139 * ISPTM: Determines whether the file descriptor is that of an open master
140 * device. Return code of zero indicates that the file descriptor
141 * represents master device.
142 *
143 * UNLKPT: Unlocks the master and slave devices. It returns 0 on success. On
144 * failure, the errno is set to EINVAL indicating that the master
145 * device is not open.
146 *
147 * ZONEPT: Sets the zoneid of the pair of master and slave devices. It
148 * returns 0 upon success. Used to force a pty 'into' a zone upon
149 * zone entry.
150 *
151 * PT_OWNER: Sets uid and gid for slave device. It returns 0 on success.
152 *
153 */
154 #define ISPTM (('P'<<8)|1) /* query for master */
155 #define UNLKPT (('P'<<8)|2) /* unlock master/slave pair */
156 #define PTSSTTY (('P'<<8)|3) /* set tty flag */
157 #define ZONEPT (('P'<<8)|4) /* set zone of master/slave pair */
158 #define OWNERPT (('P'<<8)|5) /* set owner/group for slave device */
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* _SYS_PTMS_H */
|
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
25 /* All Rights Reserved */
26
27
28 #ifndef _SYS_PTMS_H
29 #define _SYS_PTMS_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #ifdef _KERNEL
36
37 /*
38 * Structures and definitions supporting the pseudo-terminal drivers. This
39 * structure is private and should not be used by any applications.
40 */
41 struct pt_ttys {
42 queue_t *ptm_rdq; /* manager's read queue pointer */
43 queue_t *pts_rdq; /* subsidiary's read queue pointer */
44 mblk_t *pt_nullmsg; /* 0-bytes message block for pts close */
45 pid_t pt_pid; /* process id (for debugging) */
46 minor_t pt_minor; /* Minor number of this pty */
47 int pt_refcnt; /* reference count for ptm_rdq/pts_rdq uses */
48 ushort_t pt_state; /* state of manager/subsidiary pair */
49 kcondvar_t pt_cv; /* condition variable for exclusive access */
50 kmutex_t pt_lock; /* Per-element lock */
51 zoneid_t pt_zoneid; /* Zone membership for this pty */
52 uid_t pt_ruid; /* Real owner of pty */
53 gid_t pt_rgid; /* Real group owner of pty */
54 };
55
56 /*
57 * pt_state values
58 */
59 #define PTLOCK 0x01 /* manager/subsidiary pair is locked */
60 #define PTMOPEN 0x02 /* manager side is open */
61 #define PTSOPEN 0x04 /* subsidiary side is open */
62 #define PTSTTY 0x08 /* subsidiary side is tty */
63
64 /*
65 * Multi-threading primitives.
66 * Values of pt_refcnt: -1 if a writer is accessing the struct
67 * 0 if no one is reading or writing
68 * > 0 equals to the number of readers accessing the struct
69 */
70 #define PT_ENTER_READ(p) { \
71 mutex_enter(&(p)->pt_lock); \
72 while ((p)->pt_refcnt < 0) \
73 cv_wait(&((p)->pt_cv), &(p)->pt_lock); \
74 (p)->pt_refcnt++; \
75 mutex_exit(&(p)->pt_lock); \
76 }
77
78 #define PT_ENTER_WRITE(p) { \
79 mutex_enter(&(p)->pt_lock); \
80 while ((p)->pt_refcnt != 0) \
81 cv_wait(&((p)->pt_cv), &(p)->pt_lock); \
82 (p)->pt_refcnt = -1; \
92 }
93
94 #define PT_EXIT_WRITE(p) { \
95 mutex_enter(&(p)->pt_lock); \
96 ASSERT((p)->pt_refcnt == -1); \
97 (p)->pt_refcnt = 0; \
98 cv_broadcast(&(p)->pt_cv); \
99 mutex_exit(&(p)->pt_lock); \
100 }
101
102 /*
103 * ptms_lock and pt_cnt are defined in ptms_conf.c
104 */
105 extern kmutex_t ptms_lock;
106 extern dev_info_t *pts_dip; /* private copy of devinfo ptr */
107
108 extern void ptms_init(void);
109 extern struct pt_ttys *pt_ttys_alloc(void);
110 extern void ptms_close(struct pt_ttys *, uint_t);
111 extern struct pt_ttys *ptms_minor2ptty(minor_t);
112 extern int ptms_attach_subsidiary(void);
113 extern int ptms_minor_valid(minor_t ptmin, uid_t *uid, gid_t *gid);
114 extern int ptms_minor_exists(minor_t ptmin);
115 extern void ptms_set_owner(minor_t ptmin, uid_t uid, gid_t gid);
116 extern major_t ptms_subsidiary_attached(void);
117
118 #ifdef DEBUG
119 extern void ptms_log(char *, uint_t);
120 extern void ptms_logp(char *, uintptr_t);
121 #define DDBG(a, b) ptms_log(a, b)
122 #define DDBGP(a, b) ptms_logp(a, b)
123 #else
124 #define DDBG(a, b)
125 #define DDBGP(a, b)
126 #endif
127
128 #endif /* _KERNEL */
129
130 typedef struct pt_own {
131 uid_t pto_ruid;
132 gid_t pto_rgid;
133 } pt_own_t;
134
135 /*
136 * IOCTL COMMANDS
137 *
138 * ISPTM
139 * Determines whether the file descriptor is that of an open
140 * manager device. Return code of zero indicates that the file
141 * descriptor represents a manager device.
142 *
143 * UNLKPT
144 * Unlocks the manager and subsidiary devices. It returns 0 on
145 * success. On failure, the errno is set to EINVAL indicating
146 * that the manager device is not open.
147 *
148 * ZONEPT
149 * Sets the zoneid of the pair of manager and subsidiary devices.
150 * It returns 0 upon success. Used to force a pty 'into' a zone
151 * upon zone entry.
152 *
153 * PT_OWNER
154 * Sets uid and gid for subsidiary device. It returns 0 on
155 * success.
156 */
157 #define ISPTM (('P'<<8)|1) /* query for manager */
158 #define UNLKPT (('P'<<8)|2) /* unlock manager/subsidiary pair */
159 #define PTSSTTY (('P'<<8)|3) /* set tty flag */
160 #define ZONEPT (('P'<<8)|4) /* set zone of manager/subsidiary pair */
161 #define OWNERPT (('P'<<8)|5) /* set owner/group for subsidiary */
162
163 #ifdef __cplusplus
164 }
165 #endif
166
167 #endif /* _SYS_PTMS_H */
|