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
5d51e9074Sab196087 * Common Development and Distribution License (the "License").
6d51e9074Sab196087 * 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 /*
22d9452f23SEdward Pilatowicz * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
248f697f9aSRobert Mustacchi * Copyright 2018, Joyent, Inc.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <sys/stack.h>
287c478bd9Sstevel@tonic-gate #include <sys/regset.h>
297c478bd9Sstevel@tonic-gate #include <sys/frame.h>
307c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
317c478bd9Sstevel@tonic-gate #include <sys/trap.h>
32d9452f23SEdward Pilatowicz #include <sys/machelf.h>
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include "Pcontrol.h"
417c478bd9Sstevel@tonic-gate #include "Pstack.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate static uchar_t int_syscall_instr[] = { 0xCD, T_SYSCALLINT };
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate const char *
Ppltdest(struct ps_prochandle * P,uintptr_t pltaddr)467c478bd9Sstevel@tonic-gate Ppltdest(struct ps_prochandle *P, uintptr_t pltaddr)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate map_info_t *mp = Paddr2mptr(P, pltaddr);
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate uintptr_t r_addr;
517c478bd9Sstevel@tonic-gate file_info_t *fp;
527c478bd9Sstevel@tonic-gate Elf32_Rel r;
537c478bd9Sstevel@tonic-gate size_t i;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate if (mp == NULL || (fp = mp->map_file) == NULL ||
567c478bd9Sstevel@tonic-gate fp->file_plt_base == 0 ||
577c478bd9Sstevel@tonic-gate pltaddr - fp->file_plt_base >= fp->file_plt_size) {
587c478bd9Sstevel@tonic-gate errno = EINVAL;
597c478bd9Sstevel@tonic-gate return (NULL);
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate
62d9452f23SEdward Pilatowicz i = (pltaddr - fp->file_plt_base) / M_PLT_ENTSIZE - M_PLT_XNumber;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate r_addr = fp->file_jmp_rel + i * sizeof (r);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate if (Pread(P, &r, sizeof (r), r_addr) == sizeof (r) &&
677c478bd9Sstevel@tonic-gate (i = ELF32_R_SYM(r.r_info)) < fp->file_dynsym.sym_symn) {
687c478bd9Sstevel@tonic-gate
69d51e9074Sab196087 Elf_Data *data = fp->file_dynsym.sym_data_pri;
707c478bd9Sstevel@tonic-gate Elf32_Sym *symp = &(((Elf32_Sym *)data->d_buf)[i]);
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate return (fp->file_dynsym.sym_strs + symp->st_name);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate return (NULL);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate int
Pissyscall(struct ps_prochandle * P,uintptr_t addr)797c478bd9Sstevel@tonic-gate Pissyscall(struct ps_prochandle *P, uintptr_t addr)
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate uchar_t instr[16];
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate if (Pread(P, instr, sizeof (int_syscall_instr), addr) !=
847c478bd9Sstevel@tonic-gate sizeof (int_syscall_instr))
857c478bd9Sstevel@tonic-gate return (0);
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate if (memcmp(instr, int_syscall_instr, sizeof (int_syscall_instr)) == 0)
887c478bd9Sstevel@tonic-gate return (1);
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate return (0);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate int
Pissyscall_prev(struct ps_prochandle * P,uintptr_t addr,uintptr_t * dst)947c478bd9Sstevel@tonic-gate Pissyscall_prev(struct ps_prochandle *P, uintptr_t addr, uintptr_t *dst)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate int ret;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate if (ret = Pissyscall(P, addr - sizeof (int_syscall_instr))) {
997c478bd9Sstevel@tonic-gate if (dst)
1007c478bd9Sstevel@tonic-gate *dst = addr - sizeof (int_syscall_instr);
1017c478bd9Sstevel@tonic-gate return (ret);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate return (0);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate /* ARGSUSED */
1087c478bd9Sstevel@tonic-gate int
Pissyscall_text(struct ps_prochandle * P,const void * buf,size_t buflen)1097c478bd9Sstevel@tonic-gate Pissyscall_text(struct ps_prochandle *P, const void *buf, size_t buflen)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate if (buflen < sizeof (int_syscall_instr))
1127c478bd9Sstevel@tonic-gate return (0);
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate if (memcmp(buf, int_syscall_instr, sizeof (int_syscall_instr)) == 0)
1157c478bd9Sstevel@tonic-gate return (1);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate return (0);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate #define TR_ARG_MAX 6 /* Max args to print, same as SPARC */
1217c478bd9Sstevel@tonic-gate
1228f697f9aSRobert Mustacchi static boolean_t
argcount_ctf(struct ps_prochandle * P,long pc,uint_t * countp)1238f697f9aSRobert Mustacchi argcount_ctf(struct ps_prochandle *P, long pc, uint_t *countp)
1248f697f9aSRobert Mustacchi {
1258f697f9aSRobert Mustacchi GElf_Sym sym;
1268f697f9aSRobert Mustacchi ctf_file_t *ctfp;
1278f697f9aSRobert Mustacchi ctf_funcinfo_t finfo;
1288f697f9aSRobert Mustacchi prsyminfo_t si = { 0 };
1298f697f9aSRobert Mustacchi
1308f697f9aSRobert Mustacchi if (Pxlookup_by_addr(P, pc, NULL, 0, &sym, &si) != 0)
1318f697f9aSRobert Mustacchi return (B_FALSE);
1328f697f9aSRobert Mustacchi
1338f697f9aSRobert Mustacchi if ((ctfp = Paddr_to_ctf(P, pc)) == NULL)
1348f697f9aSRobert Mustacchi return (B_FALSE);
1358f697f9aSRobert Mustacchi
1368f697f9aSRobert Mustacchi if (ctf_func_info(ctfp, si.prs_id, &finfo) == CTF_ERR)
1378f697f9aSRobert Mustacchi return (B_FALSE);
1388f697f9aSRobert Mustacchi
1398f697f9aSRobert Mustacchi *countp = finfo.ctc_argc;
1408f697f9aSRobert Mustacchi
1418f697f9aSRobert Mustacchi return (B_TRUE);
1428f697f9aSRobert Mustacchi }
1438f697f9aSRobert Mustacchi
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * Given a return address, determine the likely number of arguments
1467c478bd9Sstevel@tonic-gate * that were pushed on the stack prior to its execution. We do this by
1477c478bd9Sstevel@tonic-gate * expecting that a typical call sequence consists of pushing arguments on
1487c478bd9Sstevel@tonic-gate * the stack, executing a call instruction, and then performing an add
1497c478bd9Sstevel@tonic-gate * on %esp to restore it to the value prior to pushing the arguments for
1507c478bd9Sstevel@tonic-gate * the call. We attempt to detect such an add, and divide the addend
1517c478bd9Sstevel@tonic-gate * by the size of a word to determine the number of pushed arguments.
1527c478bd9Sstevel@tonic-gate *
1537c478bd9Sstevel@tonic-gate * If we do not find such an add, this does not necessarily imply that the
1547c478bd9Sstevel@tonic-gate * function took no arguments. It is not possible to reliably detect such a
1557c478bd9Sstevel@tonic-gate * void function because hand-coded assembler does not always perform an add
1567c478bd9Sstevel@tonic-gate * to %esp immediately after the "call" instruction (eg. _sys_call()).
1577c478bd9Sstevel@tonic-gate * Because of this, we default to returning MIN(sz, TR_ARG_MAX) instead of 0
1587c478bd9Sstevel@tonic-gate * in the absence of an add to %esp.
1597c478bd9Sstevel@tonic-gate */
1607c478bd9Sstevel@tonic-gate static ulong_t
argcount(struct ps_prochandle * P,long pc,ssize_t sz)1617c478bd9Sstevel@tonic-gate argcount(struct ps_prochandle *P, long pc, ssize_t sz)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate uchar_t instr[6];
1647c478bd9Sstevel@tonic-gate ulong_t count, max;
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate max = MIN(sz / sizeof (long), TR_ARG_MAX);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate * Read the instruction at the return location.
1707c478bd9Sstevel@tonic-gate */
1717c478bd9Sstevel@tonic-gate if (Pread(P, instr, sizeof (instr), pc) != sizeof (instr) ||
1727c478bd9Sstevel@tonic-gate instr[1] != 0xc4)
1737c478bd9Sstevel@tonic-gate return (max);
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate switch (instr[0]) {
1767c478bd9Sstevel@tonic-gate case 0x81: /* count is a longword */
1777c478bd9Sstevel@tonic-gate count = instr[2]+(instr[3]<<8)+(instr[4]<<16)+(instr[5]<<24);
1787c478bd9Sstevel@tonic-gate break;
1797c478bd9Sstevel@tonic-gate case 0x83: /* count is a byte */
1807c478bd9Sstevel@tonic-gate count = instr[2];
1817c478bd9Sstevel@tonic-gate break;
1827c478bd9Sstevel@tonic-gate default:
1837c478bd9Sstevel@tonic-gate return (max);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate count /= sizeof (long);
1877c478bd9Sstevel@tonic-gate return (MIN(count, max));
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate static void
ucontext_n_to_prgregs(const ucontext_t * src,prgregset_t dst)1917c478bd9Sstevel@tonic-gate ucontext_n_to_prgregs(const ucontext_t *src, prgregset_t dst)
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate (void) memcpy(dst, src->uc_mcontext.gregs, sizeof (gregset_t));
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate int
Pstack_iter(struct ps_prochandle * P,const prgregset_t regs,proc_stack_f * func,void * arg)1977c478bd9Sstevel@tonic-gate Pstack_iter(struct ps_prochandle *P, const prgregset_t regs,
1987c478bd9Sstevel@tonic-gate proc_stack_f *func, void *arg)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate prgreg_t *prevfp = NULL;
2017c478bd9Sstevel@tonic-gate uint_t pfpsize = 0;
2027c478bd9Sstevel@tonic-gate int nfp = 0;
2037c478bd9Sstevel@tonic-gate struct {
2047c478bd9Sstevel@tonic-gate long fp;
2057c478bd9Sstevel@tonic-gate long pc;
2067c478bd9Sstevel@tonic-gate long args[32];
2077c478bd9Sstevel@tonic-gate } frame;
2087c478bd9Sstevel@tonic-gate uint_t argc;
2097c478bd9Sstevel@tonic-gate ssize_t sz;
2107c478bd9Sstevel@tonic-gate prgregset_t gregs;
2117c478bd9Sstevel@tonic-gate prgreg_t fp, pfp;
2128f697f9aSRobert Mustacchi prgreg_t pc, ctf_pc;
2137c478bd9Sstevel@tonic-gate int rv;
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate * Type definition for a structure corresponding to an IA32
2177c478bd9Sstevel@tonic-gate * signal frame. Refer to the comments in Pstack.c for more info
2187c478bd9Sstevel@tonic-gate */
2197c478bd9Sstevel@tonic-gate typedef struct {
2207c478bd9Sstevel@tonic-gate long fp;
2217c478bd9Sstevel@tonic-gate long pc;
2227c478bd9Sstevel@tonic-gate int signo;
2237c478bd9Sstevel@tonic-gate ucontext_t *ucp;
2247c478bd9Sstevel@tonic-gate siginfo_t *sip;
2257c478bd9Sstevel@tonic-gate } sf_t;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate uclist_t ucl;
2287c478bd9Sstevel@tonic-gate ucontext_t uc;
2297c478bd9Sstevel@tonic-gate uintptr_t uc_addr;
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate init_uclist(&ucl, P);
2327c478bd9Sstevel@tonic-gate (void) memcpy(gregs, regs, sizeof (gregs));
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate fp = regs[R_FP];
2358f697f9aSRobert Mustacchi ctf_pc = pc = regs[R_PC];
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate while (fp != 0 || pc != 0) {
2387c478bd9Sstevel@tonic-gate if (stack_loop(fp, &prevfp, &nfp, &pfpsize))
2397c478bd9Sstevel@tonic-gate break;
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate if (fp != 0 &&
2427c478bd9Sstevel@tonic-gate (sz = Pread(P, &frame, sizeof (frame), (uintptr_t)fp)
2437c478bd9Sstevel@tonic-gate >= (ssize_t)(2* sizeof (long)))) {
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate * One more trick for signal frames: the kernel sets
2467c478bd9Sstevel@tonic-gate * the return pc of the signal frame to 0xffffffff on
2477c478bd9Sstevel@tonic-gate * Intel IA32, so argcount won't work.
2487c478bd9Sstevel@tonic-gate */
2497c478bd9Sstevel@tonic-gate if (frame.pc != -1L) {
2507c478bd9Sstevel@tonic-gate sz -= 2* sizeof (long);
2518f697f9aSRobert Mustacchi if (argcount_ctf(P, ctf_pc, &argc)) {
2528f697f9aSRobert Mustacchi argc = MIN(argc, 32);
2538f697f9aSRobert Mustacchi } else {
2547c478bd9Sstevel@tonic-gate argc = argcount(P, (long)frame.pc, sz);
2558f697f9aSRobert Mustacchi }
2567c478bd9Sstevel@tonic-gate } else
2577c478bd9Sstevel@tonic-gate argc = 3; /* sighandler(signo, sip, ucp) */
2587c478bd9Sstevel@tonic-gate } else {
2597c478bd9Sstevel@tonic-gate (void) memset(&frame, 0, sizeof (frame));
2607c478bd9Sstevel@tonic-gate argc = 0;
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate
2638f697f9aSRobert Mustacchi ctf_pc = frame.pc;
2647c478bd9Sstevel@tonic-gate gregs[R_FP] = fp;
2657c478bd9Sstevel@tonic-gate gregs[R_PC] = pc;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if ((rv = func(arg, gregs, argc, frame.args)) != 0)
2687c478bd9Sstevel@tonic-gate break;
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate * In order to allow iteration over java frames (which can have
2727c478bd9Sstevel@tonic-gate * their own frame pointers), we allow the iterator to change
2737c478bd9Sstevel@tonic-gate * the contents of gregs. If we detect a change, then we assume
2747c478bd9Sstevel@tonic-gate * that the new values point to the next frame.
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate if (gregs[R_FP] != fp || gregs[R_PC] != pc) {
2777c478bd9Sstevel@tonic-gate fp = gregs[R_FP];
2787c478bd9Sstevel@tonic-gate pc = gregs[R_PC];
2797c478bd9Sstevel@tonic-gate continue;
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate pfp = fp;
2837c478bd9Sstevel@tonic-gate fp = frame.fp;
2847c478bd9Sstevel@tonic-gate pc = frame.pc;
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate if (find_uclink(&ucl, pfp + sizeof (sf_t)))
2877c478bd9Sstevel@tonic-gate uc_addr = pfp + sizeof (sf_t);
2887c478bd9Sstevel@tonic-gate else
289*c75682cdSToomas Soome uc_addr = (uintptr_t)NULL;
2907c478bd9Sstevel@tonic-gate
291*c75682cdSToomas Soome if (uc_addr != (uintptr_t)NULL &&
2927c478bd9Sstevel@tonic-gate Pread(P, &uc, sizeof (uc), uc_addr) == sizeof (uc)) {
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate ucontext_n_to_prgregs(&uc, gregs);
2957c478bd9Sstevel@tonic-gate fp = gregs[R_FP];
2967c478bd9Sstevel@tonic-gate pc = gregs[R_PC];
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate if (prevfp)
3017c478bd9Sstevel@tonic-gate free(prevfp);
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate free_uclist(&ucl);
3047c478bd9Sstevel@tonic-gate return (rv);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate uintptr_t
Psyscall_setup(struct ps_prochandle * P,int nargs,int sysindex,uintptr_t sp)3087c478bd9Sstevel@tonic-gate Psyscall_setup(struct ps_prochandle *P, int nargs, int sysindex, uintptr_t sp)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate sp -= sizeof (int) * (nargs+2); /* space for arg list + CALL parms */
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate P->status.pr_lwp.pr_reg[EAX] = sysindex;
3137c478bd9Sstevel@tonic-gate P->status.pr_lwp.pr_reg[R_SP] = sp;
3147c478bd9Sstevel@tonic-gate P->status.pr_lwp.pr_reg[R_PC] = P->sysaddr;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate return (sp);
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate int
Psyscall_copyinargs(struct ps_prochandle * P,int nargs,argdes_t * argp,uintptr_t ap)3207c478bd9Sstevel@tonic-gate Psyscall_copyinargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
3217c478bd9Sstevel@tonic-gate uintptr_t ap)
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate int32_t arglist[MAXARGS+2];
3247c478bd9Sstevel@tonic-gate int i;
3257c478bd9Sstevel@tonic-gate argdes_t *adp;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate for (i = 0, adp = argp; i < nargs; i++, adp++)
3287c478bd9Sstevel@tonic-gate arglist[1 + i] = (int32_t)adp->arg_value;
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate arglist[0] = P->status.pr_lwp.pr_reg[R_PC];
3317c478bd9Sstevel@tonic-gate if (Pwrite(P, &arglist[0], sizeof (int) * (nargs+1),
3327c478bd9Sstevel@tonic-gate (uintptr_t)ap) != sizeof (int) * (nargs+1))
3337c478bd9Sstevel@tonic-gate return (-1);
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate return (0);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate int
Psyscall_copyoutargs(struct ps_prochandle * P,int nargs,argdes_t * argp,uintptr_t ap)3397c478bd9Sstevel@tonic-gate Psyscall_copyoutargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
3407c478bd9Sstevel@tonic-gate uintptr_t ap)
3417c478bd9Sstevel@tonic-gate {
3427c478bd9Sstevel@tonic-gate uint32_t arglist[MAXARGS + 2];
3437c478bd9Sstevel@tonic-gate int i;
3447c478bd9Sstevel@tonic-gate argdes_t *adp;
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate if (Pread(P, &arglist[0], sizeof (int) * (nargs+1), (uintptr_t)ap)
3477c478bd9Sstevel@tonic-gate != sizeof (int) * (nargs+1))
3487c478bd9Sstevel@tonic-gate return (-1);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate for (i = 0, adp = argp; i < nargs; i++, adp++)
3517c478bd9Sstevel@tonic-gate adp->arg_value = arglist[i];
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate return (0);
3547c478bd9Sstevel@tonic-gate }
355