1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ifndef _PRB_PROC_H 27*7c478bd9Sstevel@tonic-gate #define _PRB_PROC_H 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 32*7c478bd9Sstevel@tonic-gate extern "C" { 33*7c478bd9Sstevel@tonic-gate #endif 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate /* 36*7c478bd9Sstevel@tonic-gate * Header file that gives the interfaces to the proc layer. These are the 37*7c478bd9Sstevel@tonic-gate * interfaces for "native" /proc i.e. when libtnfctl uses /proc directly 38*7c478bd9Sstevel@tonic-gate * on the target process (tnfctl_exec_open() and tnfctl_pid_open()) 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* 42*7c478bd9Sstevel@tonic-gate * Includes 43*7c478bd9Sstevel@tonic-gate */ 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/procfs.h> 48*7c478bd9Sstevel@tonic-gate #include <signal.h> 49*7c478bd9Sstevel@tonic-gate #include <note.h> 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #include <tnf/probe.h> 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* 54*7c478bd9Sstevel@tonic-gate * Typedefs 55*7c478bd9Sstevel@tonic-gate */ 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate typedef enum prb_status { 58*7c478bd9Sstevel@tonic-gate /* successful status */ 59*7c478bd9Sstevel@tonic-gate PRB_STATUS_OK = 0, 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* errors */ 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * Status values in the range 1 to -1023 are reserved for mapping 64*7c478bd9Sstevel@tonic-gate * standard errno values. 65*7c478bd9Sstevel@tonic-gate */ 66*7c478bd9Sstevel@tonic-gate PRB_STATUS_MINERRNO = 1, /* minimum errno value */ 67*7c478bd9Sstevel@tonic-gate PRB_STATUS_MAXERRNO = 1023, /* maximum errno value */ 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate PRB_STATUS_ALLOCFAIL, /* memory allocation failed */ 70*7c478bd9Sstevel@tonic-gate PRB_STATUS_BADARG, /* bad input argument */ 71*7c478bd9Sstevel@tonic-gate PRB_STATUS_BADSYNC, /* couldn't sync with rtld */ 72*7c478bd9Sstevel@tonic-gate PRB_STATUS_BADLMAPSTATE /* inconsistent link map */ 73*7c478bd9Sstevel@tonic-gate } prb_status_t; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate typedef enum prb_syscall_op { 76*7c478bd9Sstevel@tonic-gate PRB_SYS_ALL, /* turn on all system calls */ 77*7c478bd9Sstevel@tonic-gate PRB_SYS_NONE, /* clears all system calls */ 78*7c478bd9Sstevel@tonic-gate PRB_SYS_ADD, /* add a system call */ 79*7c478bd9Sstevel@tonic-gate PRB_SYS_DEL /* delete a system call */ 80*7c478bd9Sstevel@tonic-gate } prb_syscall_op_t; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * status of /proc file descriptor 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate typedef struct prb_proc_state { 86*7c478bd9Sstevel@tonic-gate boolean_t ps_isstopped; 87*7c478bd9Sstevel@tonic-gate boolean_t ps_isinsys; 88*7c478bd9Sstevel@tonic-gate boolean_t ps_isrequested; 89*7c478bd9Sstevel@tonic-gate boolean_t ps_issysexit; 90*7c478bd9Sstevel@tonic-gate boolean_t ps_issysentry; 91*7c478bd9Sstevel@tonic-gate boolean_t ps_isbptfault; 92*7c478bd9Sstevel@tonic-gate long ps_syscallnum; 93*7c478bd9Sstevel@tonic-gate } prb_proc_state_t; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate NOTE(SCHEME_PROTECTS_DATA("one thread per handle", prb_proc_state)) 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * Opaque /proc handle 99*7c478bd9Sstevel@tonic-gate */ 100*7c478bd9Sstevel@tonic-gate typedef struct prb_proc_ctl prb_proc_ctl_t; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * prb_dbgaddr() has to be called with the address of DT_DEBUG before 104*7c478bd9Sstevel@tonic-gate * most other interfaces in the prb layer can be used. 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate void prb_dbgaddr(prb_proc_ctl_t *proc_p, uintptr_t dbgaddr); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * loadobject iteration callback specification 110*7c478bd9Sstevel@tonic-gate * WARNING: keep this structure in sync with tnfctl_ind_obj_info_t 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate typedef struct prb_loadobj { 113*7c478bd9Sstevel@tonic-gate int objfd; 114*7c478bd9Sstevel@tonic-gate uintptr_t text_base; 115*7c478bd9Sstevel@tonic-gate uintptr_t data_base; 116*7c478bd9Sstevel@tonic-gate const char *objname; 117*7c478bd9Sstevel@tonic-gate } prb_loadobj_t; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate typedef int prb_loadobj_f(prb_proc_ctl_t *proc_p, const prb_loadobj_t *obj, 120*7c478bd9Sstevel@tonic-gate void *calldata); 121*7c478bd9Sstevel@tonic-gate prb_status_t prb_loadobj_iter(prb_proc_ctl_t *, prb_loadobj_f *, void *); 122*7c478bd9Sstevel@tonic-gate prb_status_t prb_mainobj_get(prb_proc_ctl_t *proc_p, int *objfd, 123*7c478bd9Sstevel@tonic-gate uintptr_t *baseaddr); 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate const char *prb_status_str(prb_status_t prbstat); 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate pid_t prb_proc_pid_get(prb_proc_ctl_t *proc_p); 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate /* rtld interfaces */ 130*7c478bd9Sstevel@tonic-gate prb_status_t prb_rtld_sync_if_needed(prb_proc_ctl_t *proc_p); 131*7c478bd9Sstevel@tonic-gate prb_status_t prb_rtld_stalk(prb_proc_ctl_t *proc_p); 132*7c478bd9Sstevel@tonic-gate prb_status_t prb_rtld_unstalk(prb_proc_ctl_t *proc_p); 133*7c478bd9Sstevel@tonic-gate prb_status_t prb_rtld_advance(prb_proc_ctl_t *proc_p); 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* generic /proc wrapper interfaces */ 136*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_open(pid_t pid, prb_proc_ctl_t **proc_pp); 137*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_reopen(pid_t pid, prb_proc_ctl_t **proc_pp); 138*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_close(prb_proc_ctl_t *proc_p); 139*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_stop(prb_proc_ctl_t *proc_p); 140*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_wait(prb_proc_ctl_t *proc_p, boolean_t use_sigmask, 141*7c478bd9Sstevel@tonic-gate sigset_t *oldmask); 142*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_cont(prb_proc_ctl_t *proc_p); 143*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_state(prb_proc_ctl_t *proc_p, 144*7c478bd9Sstevel@tonic-gate prb_proc_state_t * state_p); 145*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_setrlc(prb_proc_ctl_t *proc_p, boolean_t rlc); 146*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_setklc(prb_proc_ctl_t *proc_p, boolean_t klc); 147*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_exit(prb_proc_ctl_t *proc_p, uint_t syscall, 148*7c478bd9Sstevel@tonic-gate prb_syscall_op_t op); 149*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_entry(prb_proc_ctl_t *proc_p, uint_t syscall, 150*7c478bd9Sstevel@tonic-gate prb_syscall_op_t op); 151*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_read(prb_proc_ctl_t *proc_p, uintptr_t addr, 152*7c478bd9Sstevel@tonic-gate void *buf, size_t size); 153*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_write(prb_proc_ctl_t *proc_p, uintptr_t addr, 154*7c478bd9Sstevel@tonic-gate void *buf, size_t size); 155*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_setfork(prb_proc_ctl_t *proc_p, boolean_t inhfork); 156*7c478bd9Sstevel@tonic-gate prb_status_t prb_proc_get_r0_r1(prb_proc_ctl_t *proc_p, 157*7c478bd9Sstevel@tonic-gate prgreg_t *r0, prgreg_t *r1); 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate /* exec a child */ 160*7c478bd9Sstevel@tonic-gate prb_status_t prb_child_create(const char *cmdname, char * const *cmdargs, 161*7c478bd9Sstevel@tonic-gate const char *loption, const char *libtnfprobe_path, 162*7c478bd9Sstevel@tonic-gate char * const *envp, prb_proc_ctl_t **ret_val); 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate #endif 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate #endif /* _PRB_PROC_H */ 169