17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5facf4a8dSllai1 * Common Development and Distribution License (the "License"). 6facf4a8dSllai1 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22facf4a8dSllai1 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 267c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SYS_PTMS_H 307c478bd9Sstevel@tonic-gate #define _SYS_PTMS_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 38*9acbbeafSnn35248 #ifdef _KERNEL 39*9acbbeafSnn35248 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Structures and definitions supporting the pseudo terminal 427c478bd9Sstevel@tonic-gate * drivers. This structure is private and should not be used by any 437c478bd9Sstevel@tonic-gate * applications. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate struct pt_ttys { 467c478bd9Sstevel@tonic-gate queue_t *ptm_rdq; /* master's read queue pointer */ 477c478bd9Sstevel@tonic-gate queue_t *pts_rdq; /* slave's read queue pointer */ 487c478bd9Sstevel@tonic-gate mblk_t *pt_nullmsg; /* 0-bytes message block for pts close */ 497c478bd9Sstevel@tonic-gate pid_t pt_pid; /* process id (for debugging) */ 507c478bd9Sstevel@tonic-gate minor_t pt_minor; /* Minor number of this pty */ 517c478bd9Sstevel@tonic-gate int pt_refcnt; /* reference count for ptm_rdq/pts_rdq uses */ 527c478bd9Sstevel@tonic-gate ushort_t pt_state; /* state of master/slave pair */ 537c478bd9Sstevel@tonic-gate kcondvar_t pt_cv; /* condition variable for exclusive access */ 547c478bd9Sstevel@tonic-gate kmutex_t pt_lock; /* Per-element lock */ 557c478bd9Sstevel@tonic-gate zoneid_t pt_zoneid; /* Zone membership for this pty */ 56facf4a8dSllai1 uid_t pt_ruid; /* Real owner of pty */ 57facf4a8dSllai1 gid_t pt_rgid; /* Real group owner of pty */ 587c478bd9Sstevel@tonic-gate }; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * pt_state values 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define PTLOCK 0x01 /* master/slave pair is locked */ 647c478bd9Sstevel@tonic-gate #define PTMOPEN 0x02 /* master side is open */ 657c478bd9Sstevel@tonic-gate #define PTSOPEN 0x04 /* slave side is open */ 667c478bd9Sstevel@tonic-gate #define PTSTTY 0x08 /* slave side is tty */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Multi-threading primitives. 707c478bd9Sstevel@tonic-gate * Values of pt_refcnt: -1 if a writer is accessing the struct 717c478bd9Sstevel@tonic-gate * 0 if no one is reading or writing 727c478bd9Sstevel@tonic-gate * > 0 equals to the number of readers accessing the struct 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate #define PT_ENTER_READ(p) { \ 757c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 767c478bd9Sstevel@tonic-gate while ((p)->pt_refcnt < 0) \ 777c478bd9Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 787c478bd9Sstevel@tonic-gate (p)->pt_refcnt++; \ 797c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define PT_ENTER_WRITE(p) { \ 837c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 847c478bd9Sstevel@tonic-gate while ((p)->pt_refcnt != 0) \ 857c478bd9Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 867c478bd9Sstevel@tonic-gate (p)->pt_refcnt = -1; \ 877c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #define PT_EXIT_READ(p) { \ 917c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 927c478bd9Sstevel@tonic-gate ASSERT((p)->pt_refcnt > 0); \ 937c478bd9Sstevel@tonic-gate if ((--((p)->pt_refcnt)) == 0) \ 947c478bd9Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 957c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define PT_EXIT_WRITE(p) { \ 997c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 1007c478bd9Sstevel@tonic-gate ASSERT((p)->pt_refcnt == -1); \ 1017c478bd9Sstevel@tonic-gate (p)->pt_refcnt = 0; \ 1027c478bd9Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 1037c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * ptms_lock and pt_cnt are defined in ptms_conf.c 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate extern kmutex_t ptms_lock; 1107c478bd9Sstevel@tonic-gate extern dev_info_t *pts_dip; /* private copy of devinfo ptr */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate extern void ptms_init(void); 1137c478bd9Sstevel@tonic-gate extern struct pt_ttys *pt_ttys_alloc(void); 1147c478bd9Sstevel@tonic-gate extern void ptms_close(struct pt_ttys *, uint_t); 1157c478bd9Sstevel@tonic-gate extern struct pt_ttys *ptms_minor2ptty(minor_t); 116facf4a8dSllai1 extern int ptms_attach_slave(void); 117facf4a8dSllai1 extern int ptms_minor_valid(minor_t ptmin, uid_t *uid, gid_t *gid); 118facf4a8dSllai1 extern int ptms_minor_exists(minor_t ptmin); 119facf4a8dSllai1 extern void ptms_set_owner(minor_t ptmin, uid_t uid, gid_t gid); 120facf4a8dSllai1 extern major_t ptms_slave_attached(void); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #ifdef DEBUG 1237c478bd9Sstevel@tonic-gate extern void ptms_log(char *, uint_t); 1247c478bd9Sstevel@tonic-gate extern void ptms_logp(char *, uintptr_t); 1257c478bd9Sstevel@tonic-gate #define DDBG(a, b) ptms_log(a, b) 1267c478bd9Sstevel@tonic-gate #define DDBGP(a, b) ptms_logp(a, b) 1277c478bd9Sstevel@tonic-gate #else 1287c478bd9Sstevel@tonic-gate #define DDBG(a, b) 1297c478bd9Sstevel@tonic-gate #define DDBGP(a, b) 1307c478bd9Sstevel@tonic-gate #endif 1317c478bd9Sstevel@tonic-gate 132*9acbbeafSnn35248 typedef struct __ptmptsopencb_arg *ptmptsopencb_arg_t; 133*9acbbeafSnn35248 typedef struct ptmptsopencb { 134*9acbbeafSnn35248 boolean_t (*ppocb_func)(ptmptsopencb_arg_t); 135*9acbbeafSnn35248 ptmptsopencb_arg_t ppocb_arg; 136*9acbbeafSnn35248 } ptmptsopencb_t; 137*9acbbeafSnn35248 1387c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1397c478bd9Sstevel@tonic-gate 140*9acbbeafSnn35248 typedef struct pt_own { 141*9acbbeafSnn35248 uid_t pto_ruid; 142*9acbbeafSnn35248 gid_t pto_rgid; 143*9acbbeafSnn35248 } pt_own_t; 144*9acbbeafSnn35248 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * ioctl commands 1477c478bd9Sstevel@tonic-gate * 1487c478bd9Sstevel@tonic-gate * ISPTM: Determines whether the file descriptor is that of an open master 1497c478bd9Sstevel@tonic-gate * device. Return code of zero indicates that the file descriptor 1507c478bd9Sstevel@tonic-gate * represents master device. 1517c478bd9Sstevel@tonic-gate * 1527c478bd9Sstevel@tonic-gate * UNLKPT: Unlocks the master and slave devices. It returns 0 on success. On 1537c478bd9Sstevel@tonic-gate * failure, the errno is set to EINVAL indicating that the master 1547c478bd9Sstevel@tonic-gate * device is not open. 1557c478bd9Sstevel@tonic-gate * 1567c478bd9Sstevel@tonic-gate * ZONEPT: Sets the zoneid of the pair of master and slave devices. It 1577c478bd9Sstevel@tonic-gate * returns 0 upon success. Used to force a pty 'into' a zone upon 1587c478bd9Sstevel@tonic-gate * zone entry. 159facf4a8dSllai1 * 160facf4a8dSllai1 * PT_OWNER: Sets uid and gid for slave device. It returns 0 on success. 161facf4a8dSllai1 * 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate #define ISPTM (('P'<<8)|1) /* query for master */ 1647c478bd9Sstevel@tonic-gate #define UNLKPT (('P'<<8)|2) /* unlock master/slave pair */ 1657c478bd9Sstevel@tonic-gate #define PTSSTTY (('P'<<8)|3) /* set tty flag */ 1667c478bd9Sstevel@tonic-gate #define ZONEPT (('P'<<8)|4) /* set zone of master/slave pair */ 167*9acbbeafSnn35248 #define PT_OWNER (('P'<<8)|5) /* set owner/group for slave device */ 168facf4a8dSllai1 169*9acbbeafSnn35248 #ifdef _KERNEL 170*9acbbeafSnn35248 /* 171*9acbbeafSnn35248 * kernel ioctl commands 172*9acbbeafSnn35248 * 173*9acbbeafSnn35248 * PTMPTSOPENCB: Returns a callback function pointer and opaque argument. 174*9acbbeafSnn35248 * The return value of the callback function when it's invoked 175*9acbbeafSnn35248 * with the opaque argument passed to it will indicate if the 176*9acbbeafSnn35248 * pts slave device is currently open. 177*9acbbeafSnn35248 */ 178*9acbbeafSnn35248 #define PTMPTSOPENCB (('P'<<8)|6) /* check if the slave is open */ 179*9acbbeafSnn35248 180*9acbbeafSnn35248 #endif /* _KERNEL */ 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate #endif 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #endif /* _SYS_PTMS_H */ 187