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 5a5f69788Scraigm * Common Development and Distribution License (the "License"). 6a5f69788Scraigm * 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 /* 22ae115bc7Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28ebb8ac07SRobert Mustacchi /* 29*2428aad8SPatrick Mooney * Copyright 2016 Joyent, Inc. 30ebb8ac07SRobert Mustacchi */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifndef _SYS_USER_H 347c478bd9Sstevel@tonic-gate #define _SYS_USER_H 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/signal.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 407c478bd9Sstevel@tonic-gate extern "C" { 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * struct exdata is visible in and out of the kernel. This is because it 457c478bd9Sstevel@tonic-gate * is referenced in <sys/core.h> which doesn't have this kind of magic. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate struct exdata { 487c478bd9Sstevel@tonic-gate struct vnode *vp; 497c478bd9Sstevel@tonic-gate size_t ux_tsize; /* text size */ 507c478bd9Sstevel@tonic-gate size_t ux_dsize; /* data size */ 517c478bd9Sstevel@tonic-gate size_t ux_bsize; /* bss size */ 527c478bd9Sstevel@tonic-gate size_t ux_lsize; /* lib size */ 537c478bd9Sstevel@tonic-gate long ux_nshlibs; /* number of shared libs needed */ 547c478bd9Sstevel@tonic-gate short ux_mach; /* machine type */ 557c478bd9Sstevel@tonic-gate short ux_mag; /* magic number MUST be here */ 567c478bd9Sstevel@tonic-gate off_t ux_toffset; /* file offset to raw text */ 577c478bd9Sstevel@tonic-gate off_t ux_doffset; /* file offset to raw data */ 587c478bd9Sstevel@tonic-gate off_t ux_loffset; /* file offset to lib sctn */ 597c478bd9Sstevel@tonic-gate caddr_t ux_txtorg; /* start addr of text in mem */ 607c478bd9Sstevel@tonic-gate caddr_t ux_datorg; /* start addr of data in mem */ 617c478bd9Sstevel@tonic-gate caddr_t ux_entloc; /* entry location */ 627c478bd9Sstevel@tonic-gate }; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #ifdef __cplusplus 657c478bd9Sstevel@tonic-gate } 667c478bd9Sstevel@tonic-gate #endif 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #include <sys/param.h> 717c478bd9Sstevel@tonic-gate #include <sys/pcb.h> 727c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 737c478bd9Sstevel@tonic-gate #include <sys/resource.h> 747c478bd9Sstevel@tonic-gate #include <sys/time.h> 757c478bd9Sstevel@tonic-gate #include <sys/auxv.h> 767c478bd9Sstevel@tonic-gate #include <sys/errno.h> 777c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 787c478bd9Sstevel@tonic-gate #include <sys/refstr.h> 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #ifdef __cplusplus 817c478bd9Sstevel@tonic-gate extern "C" { 827c478bd9Sstevel@tonic-gate #endif 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Entry in the per-process list of open files. 867c478bd9Sstevel@tonic-gate * Note: only certain fields are copied in flist_grow() and flist_fork(). 877c478bd9Sstevel@tonic-gate * This is indicated in brackets in the structure member comments. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate typedef struct uf_entry { 907c478bd9Sstevel@tonic-gate kmutex_t uf_lock; /* per-fd lock [never copied] */ 917c478bd9Sstevel@tonic-gate struct file *uf_file; /* file pointer [grow, fork] */ 927c478bd9Sstevel@tonic-gate struct fpollinfo *uf_fpollinfo; /* poll state [grow] */ 937c478bd9Sstevel@tonic-gate int uf_refcnt; /* LWPs accessing this file [grow] */ 947c478bd9Sstevel@tonic-gate int uf_alloc; /* right subtree allocs [grow, fork] */ 957c478bd9Sstevel@tonic-gate short uf_flag; /* fcntl F_GETFD flags [grow, fork] */ 967c478bd9Sstevel@tonic-gate short uf_busy; /* file is allocated [grow, fork] */ 977c478bd9Sstevel@tonic-gate kcondvar_t uf_wanted_cv; /* waiting for setf() [never copied] */ 987c478bd9Sstevel@tonic-gate kcondvar_t uf_closing_cv; /* waiting for close() [never copied] */ 997c478bd9Sstevel@tonic-gate struct portfd *uf_portfd; /* associated with port [grow] */ 1007c478bd9Sstevel@tonic-gate /* Avoid false sharing - pad to coherency granularity (64 bytes) */ 1017c478bd9Sstevel@tonic-gate char uf_pad[64 - sizeof (kmutex_t) - 2 * sizeof (void*) - 1027c478bd9Sstevel@tonic-gate 2 * sizeof (int) - 2 * sizeof (short) - 1037c478bd9Sstevel@tonic-gate 2 * sizeof (kcondvar_t) - sizeof (struct portfd *)]; 1047c478bd9Sstevel@tonic-gate } uf_entry_t; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Retired file lists -- see flist_grow() for details. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate typedef struct uf_rlist { 1107c478bd9Sstevel@tonic-gate struct uf_rlist *ur_next; 1117c478bd9Sstevel@tonic-gate uf_entry_t *ur_list; 1127c478bd9Sstevel@tonic-gate int ur_nfiles; 1137c478bd9Sstevel@tonic-gate } uf_rlist_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * Per-process file information. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate typedef struct uf_info { 1197c478bd9Sstevel@tonic-gate kmutex_t fi_lock; /* see below */ 120a5f69788Scraigm int fi_badfd; /* bad file descriptor # */ 121a5f69788Scraigm int fi_action; /* action to take on bad fd use */ 1227c478bd9Sstevel@tonic-gate int fi_nfiles; /* number of entries in fi_list[] */ 1237c478bd9Sstevel@tonic-gate uf_entry_t *volatile fi_list; /* current file list */ 1247c478bd9Sstevel@tonic-gate uf_rlist_t *fi_rlist; /* retired file lists */ 1257c478bd9Sstevel@tonic-gate } uf_info_t; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * File list locking. 1297c478bd9Sstevel@tonic-gate * 1307c478bd9Sstevel@tonic-gate * Each process has a list of open files, fi_list, indexed by fd. 1317c478bd9Sstevel@tonic-gate * fi_list is an array of uf_entry_t structures, each with its own lock. 1327c478bd9Sstevel@tonic-gate * One might think that the correct way to lock a file descriptor would be: 1337c478bd9Sstevel@tonic-gate * 1347c478bd9Sstevel@tonic-gate * ufp = fip->fi_list[fd]; 1357c478bd9Sstevel@tonic-gate * mutex_enter(&ufp->uf_lock); 1367c478bd9Sstevel@tonic-gate * 1377c478bd9Sstevel@tonic-gate * However, that construct is only safe if fi_lock is already held. If not, 1387c478bd9Sstevel@tonic-gate * fi_list can change in the window between loading ufp and entering uf_lock. 1397c478bd9Sstevel@tonic-gate * The UF_ENTER() macro deals with this possibility. UF_ENTER(ufp, fip, fd) 1407c478bd9Sstevel@tonic-gate * locks fd and sets ufp to fd's uf_entry. The locking rules are as follows: 1417c478bd9Sstevel@tonic-gate * 1427c478bd9Sstevel@tonic-gate * (1) fi_lock protects fi_list and fi_nfiles. It also protects the 1437c478bd9Sstevel@tonic-gate * uf_alloc and uf_busy fields of every fd's ufp; see fd_find() for 1447c478bd9Sstevel@tonic-gate * details on file descriptor allocation. 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * (2) UF_ENTER(ufp, fip, fd) locks descriptor fd and sets ufp to point 1477c478bd9Sstevel@tonic-gate * to the uf_entry_t for fd. UF_ENTER() protects all fields in ufp 1487c478bd9Sstevel@tonic-gate * except uf_alloc and uf_busy. UF_ENTER(ufp, fip, fd) also prevents 1497c478bd9Sstevel@tonic-gate * ufp->uf_alloc, ufp->uf_busy, fip->fi_list and fip->fi_nfiles from 1507c478bd9Sstevel@tonic-gate * changing. 1517c478bd9Sstevel@tonic-gate * 1527c478bd9Sstevel@tonic-gate * (3) The lock ordering is (1), (2). 1537c478bd9Sstevel@tonic-gate * 1547c478bd9Sstevel@tonic-gate * (4) Note that fip->fi_list and fip->fi_nfiles cannot change while *any* 1557c478bd9Sstevel@tonic-gate * file list lock is held. Thus flist_grow() must acquire all such 1567c478bd9Sstevel@tonic-gate * locks -- fi_lock and every fd's uf_lock -- to install a new file list. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate #define UF_ENTER(ufp, fip, fd) \ 1597c478bd9Sstevel@tonic-gate for (;;) { \ 1607c478bd9Sstevel@tonic-gate uf_entry_t *_flist = (fip)->fi_list; \ 1617c478bd9Sstevel@tonic-gate ufp = &_flist[fd]; \ 1627c478bd9Sstevel@tonic-gate ASSERT((fd) < (fip)->fi_nfiles); \ 1637c478bd9Sstevel@tonic-gate mutex_enter(&ufp->uf_lock); \ 1647c478bd9Sstevel@tonic-gate if (_flist == (fip)->fi_list) \ 1657c478bd9Sstevel@tonic-gate break; \ 1667c478bd9Sstevel@tonic-gate mutex_exit(&ufp->uf_lock); \ 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define UF_EXIT(ufp) mutex_exit(&ufp->uf_lock) 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #define PSARGSZ 80 /* Space for exec arguments (used by ps(1)) */ 1727c478bd9Sstevel@tonic-gate #define MAXCOMLEN 16 /* <= MAXNAMLEN, >= sizeof (ac_comm) */ 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate typedef struct { /* kernel syscall set type */ 1757c478bd9Sstevel@tonic-gate uint_t word[9]; /* space for syscall numbers [1..288] */ 1767c478bd9Sstevel@tonic-gate } k_sysset_t; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate /* 1797c478bd9Sstevel@tonic-gate * __KERN_NAUXV_IMPL is defined as a convenience sizing mechanism 1807c478bd9Sstevel@tonic-gate * for the portions of the kernel that care about aux vectors. 1817c478bd9Sstevel@tonic-gate * 1827c478bd9Sstevel@tonic-gate * Applications that need to know how many aux vectors the kernel 1837c478bd9Sstevel@tonic-gate * supplies should use the proc(4) interface to read /proc/PID/auxv. 1847c478bd9Sstevel@tonic-gate * 1857c478bd9Sstevel@tonic-gate * This value should not be changed in a patch. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate #if defined(__sparc) 188ebb8ac07SRobert Mustacchi #define __KERN_NAUXV_IMPL 20 1897c478bd9Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 190ebb8ac07SRobert Mustacchi #define __KERN_NAUXV_IMPL 22 1917c478bd9Sstevel@tonic-gate #endif 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate struct execsw; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* 1967c478bd9Sstevel@tonic-gate * The user structure; one allocated per process. Contains all the 1977c478bd9Sstevel@tonic-gate * per-process data that doesn't need to be referenced while the 1987c478bd9Sstevel@tonic-gate * process is swapped. 1997c478bd9Sstevel@tonic-gate */ 2007c478bd9Sstevel@tonic-gate typedef struct user { 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * These fields are initialized at process creation time and never 2037c478bd9Sstevel@tonic-gate * modified. They can be accessed without acquiring locks. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate struct execsw *u_execsw; /* pointer to exec switch entry */ 2067c478bd9Sstevel@tonic-gate auxv_t u_auxv[__KERN_NAUXV_IMPL]; /* aux vector from exec */ 2077c478bd9Sstevel@tonic-gate timestruc_t u_start; /* hrestime at process start */ 2087c478bd9Sstevel@tonic-gate clock_t u_ticks; /* lbolt at process start */ 2097c478bd9Sstevel@tonic-gate char u_comm[MAXCOMLEN + 1]; /* executable file name from exec */ 2107c478bd9Sstevel@tonic-gate char u_psargs[PSARGSZ]; /* arguments from exec */ 2117c478bd9Sstevel@tonic-gate int u_argc; /* value of argc passed to main() */ 2127c478bd9Sstevel@tonic-gate uintptr_t u_argv; /* value of argv passed to main() */ 2137c478bd9Sstevel@tonic-gate uintptr_t u_envp; /* value of envp passed to main() */ 214*2428aad8SPatrick Mooney uintptr_t u_commpagep; /* address of mapped comm page */ 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * These fields are protected by p_lock: 2187c478bd9Sstevel@tonic-gate */ 2197c478bd9Sstevel@tonic-gate struct vnode *u_cdir; /* current directory */ 2207c478bd9Sstevel@tonic-gate struct vnode *u_rdir; /* root directory */ 2217c478bd9Sstevel@tonic-gate uint64_t u_mem; /* accumulated memory usage */ 2227c478bd9Sstevel@tonic-gate size_t u_mem_max; /* peak RSS (K) */ 2237c478bd9Sstevel@tonic-gate mode_t u_cmask; /* mask for file creation */ 2247c478bd9Sstevel@tonic-gate char u_acflag; /* accounting flag */ 2257c478bd9Sstevel@tonic-gate char u_systrap; /* /proc: any syscall mask bits set? */ 2267c478bd9Sstevel@tonic-gate refstr_t *u_cwd; /* cached string for cwd */ 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate k_sysset_t u_entrymask; /* /proc syscall stop-on-entry mask */ 2297c478bd9Sstevel@tonic-gate k_sysset_t u_exitmask; /* /proc syscall stop-on-exit mask */ 2307c478bd9Sstevel@tonic-gate k_sigset_t u_signodefer; /* signals defered when caught */ 2317c478bd9Sstevel@tonic-gate k_sigset_t u_sigonstack; /* signals taken on alternate stack */ 2327c478bd9Sstevel@tonic-gate k_sigset_t u_sigresethand; /* signals reset when caught */ 2337c478bd9Sstevel@tonic-gate k_sigset_t u_sigrestart; /* signals that restart system calls */ 2347c478bd9Sstevel@tonic-gate k_sigset_t u_sigmask[MAXSIG]; /* signals held while in catcher */ 2357c478bd9Sstevel@tonic-gate void (*u_signal[MAXSIG])(); /* Disposition of signals */ 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * Resource controls provide the backend for process resource limits, 2397c478bd9Sstevel@tonic-gate * the interfaces for which are maintained for compatibility. To 2407c478bd9Sstevel@tonic-gate * preserve the behaviour associated with the RLIM_SAVED_CUR and 2417c478bd9Sstevel@tonic-gate * RLIM_SAVED_MAX tokens, we retain the "saved" rlimits. 2427c478bd9Sstevel@tonic-gate */ 2437c478bd9Sstevel@tonic-gate struct rlimit64 u_saved_rlimit[RLIM_NSAVED]; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate uf_info_t u_finfo; /* open file information */ 2467c478bd9Sstevel@tonic-gate } user_t; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate #include <sys/proc.h> /* cannot include before user defined */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate #ifdef _KERNEL 2517c478bd9Sstevel@tonic-gate #define P_FINFO(p) (&(p)->p_user.u_finfo) 2527c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate #endif 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate #else /* defined(_KERNEL) || defined(_KMEMUSER) */ 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 2617c478bd9Sstevel@tonic-gate * Here, we define a fake version of struct user for programs 2627c478bd9Sstevel@tonic-gate * (debuggers) that use ptrace() to read and modify the saved 2637c478bd9Sstevel@tonic-gate * registers directly in the u-area. ptrace() has been removed 2647c478bd9Sstevel@tonic-gate * from the operating system and now exists as a library function 2657c478bd9Sstevel@tonic-gate * in libc, built on the /proc process filesystem. The ptrace() 2667c478bd9Sstevel@tonic-gate * library function provides access only to the members of the 2677c478bd9Sstevel@tonic-gate * fake struct user defined here. 2687c478bd9Sstevel@tonic-gate * 2697c478bd9Sstevel@tonic-gate * User-level programs that must know the real contents of struct 2707c478bd9Sstevel@tonic-gate * user will have to define _KMEMUSER before including <sys/user.h>. 2717c478bd9Sstevel@tonic-gate * Such programs also become machine specific. Carefully consider 2727c478bd9Sstevel@tonic-gate * the consequences of your actions. 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate #include <sys/regset.h> 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2787c478bd9Sstevel@tonic-gate extern "C" { 2797c478bd9Sstevel@tonic-gate #endif 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate #define PSARGSZ 80 /* Space for exec arguments (used by ps(1)) */ 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate typedef struct user { 2847c478bd9Sstevel@tonic-gate gregset_t u_reg; /* user's saved registers */ 2857c478bd9Sstevel@tonic-gate greg_t *u_ar0; /* address of user's saved R0 */ 2867c478bd9Sstevel@tonic-gate char u_psargs[PSARGSZ]; /* arguments from exec */ 2877c478bd9Sstevel@tonic-gate void (*u_signal[MAXSIG])(); /* Disposition of signals */ 2887c478bd9Sstevel@tonic-gate int u_code; /* fault code on trap */ 2897c478bd9Sstevel@tonic-gate caddr_t u_addr; /* fault PC on trap */ 2907c478bd9Sstevel@tonic-gate } user_t; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate #endif 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate #endif /* _SYS_USER_H */ 299