1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1997-2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/isa_defs.h> 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <stdlib.h> 32*0Sstevel@tonic-gate #include <unistd.h> 33*0Sstevel@tonic-gate #include <string.h> 34*0Sstevel@tonic-gate #include <errno.h> 35*0Sstevel@tonic-gate #include <sys/types.h> 36*0Sstevel@tonic-gate #include <sys/stat.h> 37*0Sstevel@tonic-gate #include <sys/sysmacros.h> 38*0Sstevel@tonic-gate #include "libproc.h" 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #ifdef _LP64 41*0Sstevel@tonic-gate /* 42*0Sstevel@tonic-gate * in case of 64-bit *stat() and *stat64 library call and 32-bit subject 43*0Sstevel@tonic-gate * process convert 64-bit struct stat/stat64 into 32-bit struct stat64 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate static void 46*0Sstevel@tonic-gate stat64_32_to_n(struct stat64_32 *src, struct stat *dest) 47*0Sstevel@tonic-gate { 48*0Sstevel@tonic-gate (void) memset(dest, 0, sizeof (*dest)); 49*0Sstevel@tonic-gate dest->st_dev = DEVEXPL(src->st_dev); 50*0Sstevel@tonic-gate dest->st_ino = (ino_t)src->st_ino; 51*0Sstevel@tonic-gate dest->st_mode = (mode_t)src->st_mode; 52*0Sstevel@tonic-gate dest->st_nlink = (nlink_t)src->st_nlink; 53*0Sstevel@tonic-gate dest->st_uid = (uid_t)src->st_uid; 54*0Sstevel@tonic-gate dest->st_gid = (gid_t)src->st_gid; 55*0Sstevel@tonic-gate dest->st_rdev = DEVEXPL(src->st_rdev); 56*0Sstevel@tonic-gate dest->st_size = (off_t)src->st_size; 57*0Sstevel@tonic-gate TIMESPEC32_TO_TIMESPEC(&dest->st_atim, &src->st_atim); 58*0Sstevel@tonic-gate TIMESPEC32_TO_TIMESPEC(&dest->st_mtim, &src->st_mtim); 59*0Sstevel@tonic-gate TIMESPEC32_TO_TIMESPEC(&dest->st_ctim, &src->st_ctim); 60*0Sstevel@tonic-gate dest->st_blksize = (blksize_t)src->st_blksize; 61*0Sstevel@tonic-gate dest->st_blocks = (blkcnt_t)src->st_blocks; 62*0Sstevel@tonic-gate (void) memcpy(dest->st_fstype, src->st_fstype, 63*0Sstevel@tonic-gate sizeof (dest->st_fstype)); 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate #endif /* _LP64 */ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate /* 68*0Sstevel@tonic-gate * stat() system call -- executed by subject process 69*0Sstevel@tonic-gate */ 70*0Sstevel@tonic-gate int 71*0Sstevel@tonic-gate pr_stat(struct ps_prochandle *Pr, const char *path, struct stat *buf) 72*0Sstevel@tonic-gate { 73*0Sstevel@tonic-gate sysret_t rval; /* return value from stat() */ 74*0Sstevel@tonic-gate argdes_t argd[3]; /* arg descriptors for stat() */ 75*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 76*0Sstevel@tonic-gate int syscall; /* stat, xstat or stat64 */ 77*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 78*0Sstevel@tonic-gate int error; 79*0Sstevel@tonic-gate #ifdef _LP64 80*0Sstevel@tonic-gate struct stat64_32 statb64_32; 81*0Sstevel@tonic-gate #endif /* _LP64 */ 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 84*0Sstevel@tonic-gate return (stat(path, buf)); 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* 87*0Sstevel@tonic-gate * This is filthy, but /proc reveals everything about the 88*0Sstevel@tonic-gate * system call interfaces, despite what the architects of the 89*0Sstevel@tonic-gate * header files may desire. We have to know here whether we 90*0Sstevel@tonic-gate * are calling stat() or xstat() in the subject. 91*0Sstevel@tonic-gate */ 92*0Sstevel@tonic-gate #if defined(_STAT_VER) 93*0Sstevel@tonic-gate syscall = SYS_xstat; 94*0Sstevel@tonic-gate nargs = 3; 95*0Sstevel@tonic-gate adp->arg_value = _STAT_VER; 96*0Sstevel@tonic-gate adp->arg_object = NULL; 97*0Sstevel@tonic-gate adp->arg_type = AT_BYVAL; 98*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 99*0Sstevel@tonic-gate adp->arg_size = 0; 100*0Sstevel@tonic-gate adp++; /* move to pathname argument */ 101*0Sstevel@tonic-gate #else 102*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel != PR_MODEL_NATIVE) { 103*0Sstevel@tonic-gate /* 64-bit process controls 32-bit subject process */ 104*0Sstevel@tonic-gate syscall = SYS_stat64; 105*0Sstevel@tonic-gate } else { 106*0Sstevel@tonic-gate syscall = SYS_stat; 107*0Sstevel@tonic-gate } 108*0Sstevel@tonic-gate #endif 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate adp->arg_value = 0; 111*0Sstevel@tonic-gate adp->arg_object = (void *)path; 112*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 113*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 114*0Sstevel@tonic-gate adp->arg_size = strlen(path) + 1; 115*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate adp->arg_value = 0; 118*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 119*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 120*0Sstevel@tonic-gate #ifdef _LP64 121*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 122*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 123*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 124*0Sstevel@tonic-gate } else { 125*0Sstevel@tonic-gate adp->arg_object = buf; 126*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate #else /* _LP64 */ 129*0Sstevel@tonic-gate adp->arg_object = buf; 130*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 131*0Sstevel@tonic-gate #endif /* _LP64 */ 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate if (error) { 136*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 137*0Sstevel@tonic-gate return (-1); 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate #ifdef _LP64 140*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 141*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, buf); 142*0Sstevel@tonic-gate #endif /* _LP64 */ 143*0Sstevel@tonic-gate return (0); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate /* 147*0Sstevel@tonic-gate * lstat() system call -- executed by subject process 148*0Sstevel@tonic-gate */ 149*0Sstevel@tonic-gate int 150*0Sstevel@tonic-gate pr_lstat(struct ps_prochandle *Pr, const char *path, struct stat *buf) 151*0Sstevel@tonic-gate { 152*0Sstevel@tonic-gate sysret_t rval; /* return value from lstat() */ 153*0Sstevel@tonic-gate argdes_t argd[3]; /* arg descriptors for lstat() */ 154*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 155*0Sstevel@tonic-gate int syscall; /* lstat, lxstat or lstat64 */ 156*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 157*0Sstevel@tonic-gate int error; 158*0Sstevel@tonic-gate #ifdef _LP64 159*0Sstevel@tonic-gate struct stat64_32 statb64_32; 160*0Sstevel@tonic-gate #endif /* _LP64 */ 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 163*0Sstevel@tonic-gate return (lstat(path, buf)); 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate /* 166*0Sstevel@tonic-gate * This is filthy, but /proc reveals everything about the 167*0Sstevel@tonic-gate * system call interfaces, despite what the architects of the 168*0Sstevel@tonic-gate * header files may desire. We have to know here whether we 169*0Sstevel@tonic-gate * are calling lstat() or lxstat() in the subject. 170*0Sstevel@tonic-gate */ 171*0Sstevel@tonic-gate #if defined(_STAT_VER) 172*0Sstevel@tonic-gate syscall = SYS_lxstat; 173*0Sstevel@tonic-gate nargs = 3; 174*0Sstevel@tonic-gate adp->arg_value = _STAT_VER; 175*0Sstevel@tonic-gate adp->arg_object = NULL; 176*0Sstevel@tonic-gate adp->arg_type = AT_BYVAL; 177*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 178*0Sstevel@tonic-gate adp->arg_size = 0; 179*0Sstevel@tonic-gate adp++; /* move to pathname argument */ 180*0Sstevel@tonic-gate #else 181*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel != PR_MODEL_NATIVE) { 182*0Sstevel@tonic-gate /* 64-bit process controls 32-bit subject process */ 183*0Sstevel@tonic-gate syscall = SYS_lstat64; 184*0Sstevel@tonic-gate } else { 185*0Sstevel@tonic-gate syscall = SYS_lstat; 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate #endif 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate adp->arg_value = 0; 190*0Sstevel@tonic-gate adp->arg_object = (void *)path; 191*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 192*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 193*0Sstevel@tonic-gate adp->arg_size = strlen(path) + 1; 194*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate adp->arg_value = 0; 197*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 198*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 199*0Sstevel@tonic-gate #ifdef _LP64 200*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 201*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 202*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 203*0Sstevel@tonic-gate } else { 204*0Sstevel@tonic-gate adp->arg_object = buf; 205*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate #else /* _LP64 */ 208*0Sstevel@tonic-gate adp->arg_object = buf; 209*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 210*0Sstevel@tonic-gate #endif /* _LP64 */ 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate if (error) { 215*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 216*0Sstevel@tonic-gate return (-1); 217*0Sstevel@tonic-gate } 218*0Sstevel@tonic-gate #ifdef _LP64 219*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 220*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, buf); 221*0Sstevel@tonic-gate #endif /* _LP64 */ 222*0Sstevel@tonic-gate return (0); 223*0Sstevel@tonic-gate } 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate /* 226*0Sstevel@tonic-gate * fstat() system call -- executed by subject process 227*0Sstevel@tonic-gate */ 228*0Sstevel@tonic-gate int 229*0Sstevel@tonic-gate pr_fstat(struct ps_prochandle *Pr, int fd, struct stat *buf) 230*0Sstevel@tonic-gate { 231*0Sstevel@tonic-gate sysret_t rval; /* return value from fstat() */ 232*0Sstevel@tonic-gate argdes_t argd[3]; /* arg descriptors for fstat() */ 233*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 234*0Sstevel@tonic-gate int syscall; /* fstat, fxstat or fstat64 */ 235*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 236*0Sstevel@tonic-gate int error; 237*0Sstevel@tonic-gate #ifdef _LP64 238*0Sstevel@tonic-gate struct stat64_32 statb64_32; 239*0Sstevel@tonic-gate #endif /* _LP64 */ 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 242*0Sstevel@tonic-gate return (fstat(fd, buf)); 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate /* 245*0Sstevel@tonic-gate * This is filthy, but /proc reveals everything about the 246*0Sstevel@tonic-gate * system call interfaces, despite what the architects of the 247*0Sstevel@tonic-gate * header files may desire. We have to know here whether we 248*0Sstevel@tonic-gate * are calling fstat() or fxstat() in the subject. 249*0Sstevel@tonic-gate */ 250*0Sstevel@tonic-gate #if defined(_STAT_VER) 251*0Sstevel@tonic-gate syscall = SYS_fxstat; 252*0Sstevel@tonic-gate nargs = 3; 253*0Sstevel@tonic-gate adp->arg_value = _STAT_VER; 254*0Sstevel@tonic-gate adp->arg_object = NULL; 255*0Sstevel@tonic-gate adp->arg_type = AT_BYVAL; 256*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 257*0Sstevel@tonic-gate adp->arg_size = 0; 258*0Sstevel@tonic-gate adp++; /* move to fd argument */ 259*0Sstevel@tonic-gate #else 260*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel != PR_MODEL_NATIVE) { 261*0Sstevel@tonic-gate /* 64-bit process controls 32-bit subject process */ 262*0Sstevel@tonic-gate syscall = SYS_fstat64; 263*0Sstevel@tonic-gate } else { 264*0Sstevel@tonic-gate syscall = SYS_fstat; 265*0Sstevel@tonic-gate } 266*0Sstevel@tonic-gate #endif 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate adp->arg_value = fd; 269*0Sstevel@tonic-gate adp->arg_object = NULL; 270*0Sstevel@tonic-gate adp->arg_type = AT_BYVAL; 271*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 272*0Sstevel@tonic-gate adp->arg_size = 0; 273*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate adp->arg_value = 0; 276*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 277*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 278*0Sstevel@tonic-gate #ifdef _LP64 279*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 280*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 281*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 282*0Sstevel@tonic-gate } else { 283*0Sstevel@tonic-gate adp->arg_object = buf; 284*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate #else /* _LP64 */ 287*0Sstevel@tonic-gate adp->arg_object = buf; 288*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 289*0Sstevel@tonic-gate #endif /* _LP64 */ 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate if (error) { 294*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 295*0Sstevel@tonic-gate return (-1); 296*0Sstevel@tonic-gate } 297*0Sstevel@tonic-gate #ifdef _LP64 298*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 299*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, buf); 300*0Sstevel@tonic-gate #endif /* _LP64 */ 301*0Sstevel@tonic-gate return (0); 302*0Sstevel@tonic-gate } 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate /* 305*0Sstevel@tonic-gate * stat64() system call -- executed by subject process 306*0Sstevel@tonic-gate */ 307*0Sstevel@tonic-gate int 308*0Sstevel@tonic-gate pr_stat64(struct ps_prochandle *Pr, const char *path, struct stat64 *buf) 309*0Sstevel@tonic-gate { 310*0Sstevel@tonic-gate sysret_t rval; /* return value from stat64() */ 311*0Sstevel@tonic-gate argdes_t argd[2]; /* arg descriptors for stat64() */ 312*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 313*0Sstevel@tonic-gate int syscall; /* stat or stat64 */ 314*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 315*0Sstevel@tonic-gate int error; 316*0Sstevel@tonic-gate #ifdef _LP64 317*0Sstevel@tonic-gate struct stat64_32 statb64_32; 318*0Sstevel@tonic-gate #endif /* _LP64 */ 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 321*0Sstevel@tonic-gate return (stat64(path, buf)); 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 324*0Sstevel@tonic-gate /* 325*0Sstevel@tonic-gate * 32-bit native and 326*0Sstevel@tonic-gate * 64-bit process controls 32-bit subject process 327*0Sstevel@tonic-gate */ 328*0Sstevel@tonic-gate syscall = SYS_stat64; 329*0Sstevel@tonic-gate } else { 330*0Sstevel@tonic-gate /* 64-bit native */ 331*0Sstevel@tonic-gate syscall = SYS_stat; 332*0Sstevel@tonic-gate } 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate adp->arg_value = 0; 335*0Sstevel@tonic-gate adp->arg_object = (void *)path; 336*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 337*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 338*0Sstevel@tonic-gate adp->arg_size = strlen(path) + 1; 339*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate adp->arg_value = 0; 342*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 343*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 344*0Sstevel@tonic-gate #ifdef _LP64 345*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 346*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 347*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 348*0Sstevel@tonic-gate } else { 349*0Sstevel@tonic-gate adp->arg_object = buf; 350*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 351*0Sstevel@tonic-gate } 352*0Sstevel@tonic-gate #else /* _LP64 */ 353*0Sstevel@tonic-gate adp->arg_object = buf; 354*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 355*0Sstevel@tonic-gate #endif /* _LP64 */ 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate if (error) { 360*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 361*0Sstevel@tonic-gate return (-1); 362*0Sstevel@tonic-gate } 363*0Sstevel@tonic-gate #ifdef _LP64 364*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 365*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, (struct stat *)buf); 366*0Sstevel@tonic-gate #endif /* _LP64 */ 367*0Sstevel@tonic-gate return (0); 368*0Sstevel@tonic-gate } 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gate /* 371*0Sstevel@tonic-gate * lstat64() system call -- executed by subject process 372*0Sstevel@tonic-gate */ 373*0Sstevel@tonic-gate int 374*0Sstevel@tonic-gate pr_lstat64(struct ps_prochandle *Pr, const char *path, struct stat64 *buf) 375*0Sstevel@tonic-gate { 376*0Sstevel@tonic-gate sysret_t rval; /* return value from lstat64() */ 377*0Sstevel@tonic-gate argdes_t argd[2]; /* arg descriptors for lstat64() */ 378*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 379*0Sstevel@tonic-gate int syscall; /* lstat or lstat64 */ 380*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 381*0Sstevel@tonic-gate int error; 382*0Sstevel@tonic-gate #ifdef _LP64 383*0Sstevel@tonic-gate struct stat64_32 statb64_32; 384*0Sstevel@tonic-gate #endif /* _LP64 */ 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 387*0Sstevel@tonic-gate return (lstat64(path, buf)); 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 390*0Sstevel@tonic-gate /* 391*0Sstevel@tonic-gate * 32-bit native and 392*0Sstevel@tonic-gate * 64-bit process controls 32-bit subject process 393*0Sstevel@tonic-gate */ 394*0Sstevel@tonic-gate syscall = SYS_lstat64; 395*0Sstevel@tonic-gate } else { 396*0Sstevel@tonic-gate /* 64-bit native */ 397*0Sstevel@tonic-gate syscall = SYS_lstat; 398*0Sstevel@tonic-gate } 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate adp->arg_value = 0; 401*0Sstevel@tonic-gate adp->arg_object = (void *)path; 402*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 403*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 404*0Sstevel@tonic-gate adp->arg_size = strlen(path) + 1; 405*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate adp->arg_value = 0; 408*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 409*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 410*0Sstevel@tonic-gate #ifdef _LP64 411*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 412*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 413*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 414*0Sstevel@tonic-gate } else { 415*0Sstevel@tonic-gate adp->arg_object = buf; 416*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 417*0Sstevel@tonic-gate } 418*0Sstevel@tonic-gate #else /* _LP64 */ 419*0Sstevel@tonic-gate adp->arg_object = buf; 420*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 421*0Sstevel@tonic-gate #endif /* _LP64 */ 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate if (error) { 426*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 427*0Sstevel@tonic-gate return (-1); 428*0Sstevel@tonic-gate } 429*0Sstevel@tonic-gate #ifdef _LP64 430*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 431*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, (struct stat *)buf); 432*0Sstevel@tonic-gate #endif /* _LP64 */ 433*0Sstevel@tonic-gate return (0); 434*0Sstevel@tonic-gate } 435*0Sstevel@tonic-gate 436*0Sstevel@tonic-gate /* 437*0Sstevel@tonic-gate * fstat64() system call -- executed by subject process 438*0Sstevel@tonic-gate */ 439*0Sstevel@tonic-gate int 440*0Sstevel@tonic-gate pr_fstat64(struct ps_prochandle *Pr, int fd, struct stat64 *buf) 441*0Sstevel@tonic-gate { 442*0Sstevel@tonic-gate sysret_t rval; /* return value from fstat64() */ 443*0Sstevel@tonic-gate argdes_t argd[2]; /* arg descriptors for fstat64() */ 444*0Sstevel@tonic-gate argdes_t *adp = &argd[0]; /* first argument */ 445*0Sstevel@tonic-gate int syscall; /* fstat or fstat64 */ 446*0Sstevel@tonic-gate int nargs = 2; /* number of actual arguments */ 447*0Sstevel@tonic-gate int error; 448*0Sstevel@tonic-gate #ifdef _LP64 449*0Sstevel@tonic-gate struct stat64_32 statb64_32; 450*0Sstevel@tonic-gate #endif /* _LP64 */ 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate if (Pr == NULL) /* no subject process */ 453*0Sstevel@tonic-gate return (fstat64(fd, buf)); 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 456*0Sstevel@tonic-gate /* 457*0Sstevel@tonic-gate * 32-bit native and 458*0Sstevel@tonic-gate * 64-bit process controls 32-bit subject process 459*0Sstevel@tonic-gate */ 460*0Sstevel@tonic-gate syscall = SYS_fstat64; 461*0Sstevel@tonic-gate } else { 462*0Sstevel@tonic-gate /* 64-bit native */ 463*0Sstevel@tonic-gate syscall = SYS_fstat; 464*0Sstevel@tonic-gate } 465*0Sstevel@tonic-gate 466*0Sstevel@tonic-gate adp->arg_value = fd; 467*0Sstevel@tonic-gate adp->arg_object = NULL; 468*0Sstevel@tonic-gate adp->arg_type = AT_BYVAL; 469*0Sstevel@tonic-gate adp->arg_inout = AI_INPUT; 470*0Sstevel@tonic-gate adp->arg_size = 0; 471*0Sstevel@tonic-gate adp++; /* move to buffer argument */ 472*0Sstevel@tonic-gate 473*0Sstevel@tonic-gate adp->arg_value = 0; 474*0Sstevel@tonic-gate adp->arg_type = AT_BYREF; 475*0Sstevel@tonic-gate adp->arg_inout = AI_OUTPUT; 476*0Sstevel@tonic-gate #ifdef _LP64 477*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 478*0Sstevel@tonic-gate adp->arg_object = &statb64_32; 479*0Sstevel@tonic-gate adp->arg_size = sizeof (statb64_32); 480*0Sstevel@tonic-gate } else { 481*0Sstevel@tonic-gate adp->arg_object = buf; 482*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 483*0Sstevel@tonic-gate } 484*0Sstevel@tonic-gate #else /* _LP64 */ 485*0Sstevel@tonic-gate adp->arg_object = buf; 486*0Sstevel@tonic-gate adp->arg_size = sizeof (*buf); 487*0Sstevel@tonic-gate #endif /* _LP64 */ 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate error = Psyscall(Pr, &rval, syscall, nargs, &argd[0]); 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate if (error) { 492*0Sstevel@tonic-gate errno = (error > 0)? error : ENOSYS; 493*0Sstevel@tonic-gate return (-1); 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate #ifdef _LP64 496*0Sstevel@tonic-gate if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) 497*0Sstevel@tonic-gate stat64_32_to_n(&statb64_32, (struct stat *)buf); 498*0Sstevel@tonic-gate #endif /* _LP64 */ 499*0Sstevel@tonic-gate return (0); 500*0Sstevel@tonic-gate } 501