10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52621Sllai1 * Common Development and Distribution License (the "License"). 62621Sllai1 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12613SSurya.Prakki@Sun.COM * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 250Sstevel@tonic-gate /* All Rights Reserved */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifndef _SYS_PTMS_H 290Sstevel@tonic-gate #define _SYS_PTMS_H 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 352712Snn35248 #ifdef _KERNEL 362712Snn35248 370Sstevel@tonic-gate /* 380Sstevel@tonic-gate * Structures and definitions supporting the pseudo terminal 390Sstevel@tonic-gate * drivers. This structure is private and should not be used by any 400Sstevel@tonic-gate * applications. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate struct pt_ttys { 430Sstevel@tonic-gate queue_t *ptm_rdq; /* master's read queue pointer */ 440Sstevel@tonic-gate queue_t *pts_rdq; /* slave's read queue pointer */ 450Sstevel@tonic-gate mblk_t *pt_nullmsg; /* 0-bytes message block for pts close */ 460Sstevel@tonic-gate pid_t pt_pid; /* process id (for debugging) */ 470Sstevel@tonic-gate minor_t pt_minor; /* Minor number of this pty */ 480Sstevel@tonic-gate int pt_refcnt; /* reference count for ptm_rdq/pts_rdq uses */ 490Sstevel@tonic-gate ushort_t pt_state; /* state of master/slave pair */ 500Sstevel@tonic-gate kcondvar_t pt_cv; /* condition variable for exclusive access */ 510Sstevel@tonic-gate kmutex_t pt_lock; /* Per-element lock */ 520Sstevel@tonic-gate zoneid_t pt_zoneid; /* Zone membership for this pty */ 532621Sllai1 uid_t pt_ruid; /* Real owner of pty */ 542621Sllai1 gid_t pt_rgid; /* Real group owner of pty */ 550Sstevel@tonic-gate }; 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * pt_state values 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate #define PTLOCK 0x01 /* master/slave pair is locked */ 610Sstevel@tonic-gate #define PTMOPEN 0x02 /* master side is open */ 620Sstevel@tonic-gate #define PTSOPEN 0x04 /* slave side is open */ 630Sstevel@tonic-gate #define PTSTTY 0x08 /* slave side is tty */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Multi-threading primitives. 670Sstevel@tonic-gate * Values of pt_refcnt: -1 if a writer is accessing the struct 680Sstevel@tonic-gate * 0 if no one is reading or writing 690Sstevel@tonic-gate * > 0 equals to the number of readers accessing the struct 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate #define PT_ENTER_READ(p) { \ 720Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 730Sstevel@tonic-gate while ((p)->pt_refcnt < 0) \ 740Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 750Sstevel@tonic-gate (p)->pt_refcnt++; \ 760Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate #define PT_ENTER_WRITE(p) { \ 800Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 810Sstevel@tonic-gate while ((p)->pt_refcnt != 0) \ 820Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 830Sstevel@tonic-gate (p)->pt_refcnt = -1; \ 840Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 850Sstevel@tonic-gate } 860Sstevel@tonic-gate 870Sstevel@tonic-gate #define PT_EXIT_READ(p) { \ 880Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 890Sstevel@tonic-gate ASSERT((p)->pt_refcnt > 0); \ 900Sstevel@tonic-gate if ((--((p)->pt_refcnt)) == 0) \ 910Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 920Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate #define PT_EXIT_WRITE(p) { \ 960Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 970Sstevel@tonic-gate ASSERT((p)->pt_refcnt == -1); \ 980Sstevel@tonic-gate (p)->pt_refcnt = 0; \ 990Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 1000Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * ptms_lock and pt_cnt are defined in ptms_conf.c 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate extern kmutex_t ptms_lock; 1070Sstevel@tonic-gate extern dev_info_t *pts_dip; /* private copy of devinfo ptr */ 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate extern void ptms_init(void); 1100Sstevel@tonic-gate extern struct pt_ttys *pt_ttys_alloc(void); 1110Sstevel@tonic-gate extern void ptms_close(struct pt_ttys *, uint_t); 1120Sstevel@tonic-gate extern struct pt_ttys *ptms_minor2ptty(minor_t); 1132621Sllai1 extern int ptms_attach_slave(void); 1142621Sllai1 extern int ptms_minor_valid(minor_t ptmin, uid_t *uid, gid_t *gid); 1152621Sllai1 extern int ptms_minor_exists(minor_t ptmin); 1162621Sllai1 extern void ptms_set_owner(minor_t ptmin, uid_t uid, gid_t gid); 1172621Sllai1 extern major_t ptms_slave_attached(void); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #ifdef DEBUG 1200Sstevel@tonic-gate extern void ptms_log(char *, uint_t); 1210Sstevel@tonic-gate extern void ptms_logp(char *, uintptr_t); 1220Sstevel@tonic-gate #define DDBG(a, b) ptms_log(a, b) 1230Sstevel@tonic-gate #define DDBGP(a, b) ptms_logp(a, b) 1240Sstevel@tonic-gate #else 1250Sstevel@tonic-gate #define DDBG(a, b) 1260Sstevel@tonic-gate #define DDBGP(a, b) 1270Sstevel@tonic-gate #endif 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate #endif /* _KERNEL */ 1300Sstevel@tonic-gate 1312712Snn35248 typedef struct pt_own { 1322712Snn35248 uid_t pto_ruid; 1332712Snn35248 gid_t pto_rgid; 1342712Snn35248 } pt_own_t; 1352712Snn35248 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * ioctl commands 1380Sstevel@tonic-gate * 1392712Snn35248 * ISPTM: Determines whether the file descriptor is that of an open master 1402712Snn35248 * device. Return code of zero indicates that the file descriptor 1412712Snn35248 * represents master device. 1420Sstevel@tonic-gate * 1432712Snn35248 * UNLKPT: Unlocks the master and slave devices. It returns 0 on success. On 1442712Snn35248 * failure, the errno is set to EINVAL indicating that the master 1452712Snn35248 * device is not open. 1460Sstevel@tonic-gate * 1470Sstevel@tonic-gate * ZONEPT: Sets the zoneid of the pair of master and slave devices. It 1480Sstevel@tonic-gate * returns 0 upon success. Used to force a pty 'into' a zone upon 1490Sstevel@tonic-gate * zone entry. 1502621Sllai1 * 1512621Sllai1 * PT_OWNER: Sets uid and gid for slave device. It returns 0 on success. 1522621Sllai1 * 1530Sstevel@tonic-gate */ 1542712Snn35248 #define ISPTM (('P'<<8)|1) /* query for master */ 1552712Snn35248 #define UNLKPT (('P'<<8)|2) /* unlock master/slave pair */ 1562712Snn35248 #define PTSSTTY (('P'<<8)|3) /* set tty flag */ 1572712Snn35248 #define ZONEPT (('P'<<8)|4) /* set zone of master/slave pair */ 1583442Svikram #define OWNERPT (('P'<<8)|5) /* set owner/group for slave device */ 1592621Sllai1 1600Sstevel@tonic-gate #ifdef __cplusplus 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate #endif 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #endif /* _SYS_PTMS_H */ 165