Home | History | Annotate | Line # | Download | only in kern
kern_syscall.c revision 1.9
      1  1.9  pgoyette /*	$NetBSD: kern_syscall.c,v 1.9 2013/12/14 06:27:57 pgoyette Exp $	*/
      2  1.1     pooka 
      3  1.1     pooka /*-
      4  1.1     pooka  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.1     pooka  * All rights reserved.
      6  1.1     pooka  *
      7  1.1     pooka  * This code is derived from software developed for The NetBSD Foundation
      8  1.1     pooka  * by Andrew Doran.
      9  1.1     pooka  *
     10  1.1     pooka  * Redistribution and use in source and binary forms, with or without
     11  1.1     pooka  * modification, are permitted provided that the following conditions
     12  1.1     pooka  * are met:
     13  1.1     pooka  * 1. Redistributions of source code must retain the above copyright
     14  1.1     pooka  *    notice, this list of conditions and the following disclaimer.
     15  1.1     pooka  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     pooka  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     pooka  *    documentation and/or other materials provided with the distribution.
     18  1.1     pooka  *
     19  1.1     pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1     pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1     pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1     pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1     pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1     pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1     pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1     pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1     pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1     pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1     pooka  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1     pooka  */
     31  1.1     pooka 
     32  1.1     pooka #include <sys/cdefs.h>
     33  1.9  pgoyette __KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.9 2013/12/14 06:27:57 pgoyette Exp $");
     34  1.2     pooka 
     35  1.8     pooka #ifdef _KERNEL_OPT
     36  1.2     pooka #include "opt_modular.h"
     37  1.8     pooka #include "opt_syscall_debug.h"
     38  1.8     pooka #include "opt_ktrace.h"
     39  1.8     pooka #include "opt_ptrace.h"
     40  1.8     pooka #endif
     41  1.1     pooka 
     42  1.3     pooka /* XXX To get syscall prototypes. */
     43  1.3     pooka #define SYSVSHM
     44  1.3     pooka #define SYSVSEM
     45  1.3     pooka #define SYSVMSG
     46  1.3     pooka 
     47  1.1     pooka #include <sys/param.h>
     48  1.1     pooka #include <sys/module.h>
     49  1.4     pooka #include <sys/sched.h>
     50  1.1     pooka #include <sys/syscall.h>
     51  1.1     pooka #include <sys/syscallargs.h>
     52  1.1     pooka #include <sys/syscallvar.h>
     53  1.5  pgoyette #include <sys/systm.h>
     54  1.1     pooka #include <sys/xcall.h>
     55  1.8     pooka #include <sys/ktrace.h>
     56  1.8     pooka #include <sys/ptrace.h>
     57  1.1     pooka 
     58  1.1     pooka int
     59  1.1     pooka sys_nomodule(struct lwp *l, const void *v, register_t *retval)
     60  1.1     pooka {
     61  1.1     pooka #ifdef MODULAR
     62  1.1     pooka 	static struct {
     63  1.1     pooka 		u_int		al_code;
     64  1.1     pooka 		const char	*al_module;
     65  1.1     pooka 	} const autoload[] = {
     66  1.1     pooka 	    { SYS_aio_cancel, "aio" },
     67  1.1     pooka 	    { SYS_aio_error, "aio" },
     68  1.1     pooka 	    { SYS_aio_fsync, "aio" },
     69  1.1     pooka 	    { SYS_aio_read, "aio" },
     70  1.1     pooka 	    { SYS_aio_return, "aio" },
     71  1.1     pooka 	    { SYS___aio_suspend50, "aio" },
     72  1.1     pooka 	    { SYS_aio_write, "aio" },
     73  1.1     pooka 	    { SYS_lio_listio, "aio" },
     74  1.1     pooka 	    { SYS_mq_open, "mqueue" },
     75  1.1     pooka 	    { SYS_mq_close, "mqueue" },
     76  1.1     pooka 	    { SYS_mq_unlink, "mqueue" },
     77  1.1     pooka 	    { SYS_mq_getattr, "mqueue" },
     78  1.1     pooka 	    { SYS_mq_setattr, "mqueue" },
     79  1.1     pooka 	    { SYS_mq_notify, "mqueue" },
     80  1.1     pooka 	    { SYS_mq_send, "mqueue" },
     81  1.1     pooka 	    { SYS_mq_receive, "mqueue" },
     82  1.1     pooka 	    { SYS___mq_timedsend50, "mqueue" },
     83  1.1     pooka 	    { SYS___mq_timedreceive50, "mqueue" },
     84  1.1     pooka 	    { SYS_compat_43_fstat43, "compat" },
     85  1.1     pooka 	    { SYS_compat_43_lstat43, "compat" },
     86  1.1     pooka 	    { SYS_compat_43_oaccept, "compat" },
     87  1.1     pooka 	    { SYS_compat_43_ocreat, "compat" },
     88  1.1     pooka 	    { SYS_compat_43_oftruncate, "compat" },
     89  1.1     pooka 	    { SYS_compat_43_ogetdirentries, "compat" },
     90  1.1     pooka 	    { SYS_compat_43_ogetdtablesize, "compat" },
     91  1.1     pooka 	    { SYS_compat_43_ogethostid, "compat" },
     92  1.1     pooka 	    { SYS_compat_43_ogethostname, "compat" },
     93  1.1     pooka 	    { SYS_compat_43_ogetkerninfo, "compat" },
     94  1.1     pooka 	    { SYS_compat_43_ogetpagesize, "compat" },
     95  1.1     pooka 	    { SYS_compat_43_ogetpeername, "compat" },
     96  1.1     pooka 	    { SYS_compat_43_ogetrlimit, "compat" },
     97  1.1     pooka 	    { SYS_compat_43_ogetsockname, "compat" },
     98  1.1     pooka 	    { SYS_compat_43_okillpg, "compat" },
     99  1.1     pooka 	    { SYS_compat_43_olseek, "compat" },
    100  1.1     pooka 	    { SYS_compat_43_ommap, "compat" },
    101  1.1     pooka 	    { SYS_compat_43_oquota, "compat" },
    102  1.1     pooka 	    { SYS_compat_43_orecv, "compat" },
    103  1.1     pooka 	    { SYS_compat_43_orecvfrom, "compat" },
    104  1.1     pooka 	    { SYS_compat_43_orecvmsg, "compat" },
    105  1.1     pooka 	    { SYS_compat_43_osend, "compat" },
    106  1.1     pooka 	    { SYS_compat_43_osendmsg, "compat" },
    107  1.1     pooka 	    { SYS_compat_43_osethostid, "compat" },
    108  1.1     pooka 	    { SYS_compat_43_osethostname, "compat" },
    109  1.1     pooka 	    { SYS_compat_43_osetrlimit, "compat" },
    110  1.1     pooka 	    { SYS_compat_43_osigblock, "compat" },
    111  1.1     pooka 	    { SYS_compat_43_osigsetmask, "compat" },
    112  1.1     pooka 	    { SYS_compat_43_osigstack, "compat" },
    113  1.1     pooka 	    { SYS_compat_43_osigvec, "compat" },
    114  1.1     pooka 	    { SYS_compat_43_otruncate, "compat" },
    115  1.1     pooka 	    { SYS_compat_43_owait, "compat" },
    116  1.1     pooka 	    { SYS_compat_43_stat43, "compat" },
    117  1.1     pooka 	    { SYS_compat_09_ogetdomainname, "compat" },
    118  1.1     pooka 	    { SYS_compat_09_osetdomainname, "compat" },
    119  1.1     pooka 	    { SYS_compat_09_ouname, "compat" },
    120  1.1     pooka #ifndef _LP64
    121  1.1     pooka 	    { SYS_compat_10_omsgsys, "compat" },
    122  1.1     pooka 	    { SYS_compat_10_osemsys, "compat" },
    123  1.1     pooka 	    { SYS_compat_10_oshmsys, "compat" },
    124  1.1     pooka #endif
    125  1.1     pooka 	    { SYS_compat_12_fstat12, "compat" },
    126  1.1     pooka 	    { SYS_compat_12_getdirentries, "compat" },
    127  1.1     pooka 	    { SYS_compat_12_lstat12, "compat" },
    128  1.1     pooka 	    { SYS_compat_12_msync, "compat" },
    129  1.1     pooka 	    { SYS_compat_12_oreboot, "compat" },
    130  1.1     pooka 	    { SYS_compat_12_oswapon, "compat" },
    131  1.1     pooka 	    { SYS_compat_12_stat12, "compat" },
    132  1.1     pooka 	    { SYS_compat_13_sigaction13, "compat" },
    133  1.1     pooka 	    { SYS_compat_13_sigaltstack13, "compat" },
    134  1.1     pooka 	    { SYS_compat_13_sigpending13, "compat" },
    135  1.1     pooka 	    { SYS_compat_13_sigprocmask13, "compat" },
    136  1.1     pooka 	    { SYS_compat_13_sigreturn13, "compat" },
    137  1.1     pooka 	    { SYS_compat_13_sigsuspend13, "compat" },
    138  1.1     pooka 	    { SYS_compat_14___semctl, "compat" },
    139  1.1     pooka 	    { SYS_compat_14_msgctl, "compat" },
    140  1.1     pooka 	    { SYS_compat_14_shmctl, "compat" },
    141  1.1     pooka 	    { SYS_compat_16___sigaction14, "compat" },
    142  1.1     pooka 	    { SYS_compat_16___sigreturn14, "compat" },
    143  1.1     pooka 	    { SYS_compat_20_fhstatfs, "compat" },
    144  1.1     pooka 	    { SYS_compat_20_fstatfs, "compat" },
    145  1.1     pooka 	    { SYS_compat_20_getfsstat, "compat" },
    146  1.1     pooka 	    { SYS_compat_20_statfs, "compat" },
    147  1.1     pooka 	    { SYS_compat_30___fhstat30, "compat" },
    148  1.1     pooka 	    { SYS_compat_30___fstat13, "compat" },
    149  1.1     pooka 	    { SYS_compat_30___lstat13, "compat" },
    150  1.1     pooka 	    { SYS_compat_30___stat13, "compat" },
    151  1.1     pooka 	    { SYS_compat_30_fhopen, "compat" },
    152  1.1     pooka 	    { SYS_compat_30_fhstat, "compat" },
    153  1.1     pooka 	    { SYS_compat_30_fhstatvfs1, "compat" },
    154  1.1     pooka 	    { SYS_compat_30_getdents, "compat" },
    155  1.1     pooka 	    { SYS_compat_30_getfh, "compat" },
    156  1.1     pooka 	    { SYS_compat_30_socket, "compat" },
    157  1.1     pooka 	    { SYS_compat_40_mount, "compat" },
    158  1.1     pooka 	    { SYS_compat_50_wait4, "compat" },
    159  1.1     pooka 	    { SYS_compat_50_mknod, "compat" },
    160  1.1     pooka 	    { SYS_compat_50_setitimer, "compat" },
    161  1.1     pooka 	    { SYS_compat_50_getitimer, "compat" },
    162  1.1     pooka 	    { SYS_compat_50_select, "compat" },
    163  1.1     pooka 	    { SYS_compat_50_gettimeofday, "compat" },
    164  1.1     pooka 	    { SYS_compat_50_getrusage, "compat" },
    165  1.1     pooka 	    { SYS_compat_50_settimeofday, "compat" },
    166  1.1     pooka 	    { SYS_compat_50_utimes, "compat" },
    167  1.1     pooka 	    { SYS_compat_50_adjtime, "compat" },
    168  1.1     pooka 	    { SYS_compat_50_lfs_segwait, "compat" },
    169  1.1     pooka 	    { SYS_compat_50_futimes, "compat" },
    170  1.1     pooka 	    { SYS_compat_50_clock_gettime, "compat" },
    171  1.1     pooka 	    { SYS_compat_50_clock_settime, "compat" },
    172  1.1     pooka 	    { SYS_compat_50_clock_getres, "compat" },
    173  1.1     pooka 	    { SYS_compat_50_timer_settime, "compat" },
    174  1.1     pooka 	    { SYS_compat_50_timer_gettime, "compat" },
    175  1.1     pooka 	    { SYS_compat_50_nanosleep, "compat" },
    176  1.1     pooka 	    { SYS_compat_50___sigtimedwait, "compat" },
    177  1.1     pooka 	    { SYS_compat_50_mq_timedsend, "compat" },
    178  1.1     pooka 	    { SYS_compat_50_mq_timedreceive, "compat" },
    179  1.1     pooka 	    { SYS_compat_50_lutimes, "compat" },
    180  1.1     pooka 	    { SYS_compat_50_____semctl13, "compat" },
    181  1.1     pooka 	    { SYS_compat_50___msgctl13, "compat" },
    182  1.1     pooka 	    { SYS_compat_50___shmctl13, "compat" },
    183  1.1     pooka 	    { SYS_compat_50__lwp_park, "compat" },
    184  1.1     pooka 	    { SYS_compat_50_kevent, "compat" },
    185  1.1     pooka 	    { SYS_compat_50_pselect, "compat" },
    186  1.1     pooka 	    { SYS_compat_50_pollts, "compat" },
    187  1.1     pooka 	    { SYS_compat_50___stat30, "compat" },
    188  1.1     pooka 	    { SYS_compat_50___fstat30, "compat" },
    189  1.1     pooka 	    { SYS_compat_50___lstat30, "compat" },
    190  1.1     pooka 	    { SYS_compat_50___ntp_gettime30, "compat" },
    191  1.1     pooka 	    { SYS_compat_50___fhstat40, "compat" },
    192  1.1     pooka 	    { SYS_compat_50_aio_suspend, "compat" },
    193  1.9  pgoyette 	    { SYS_compat_60__lwp_park, "compat" },
    194  1.1     pooka 	    { SYS__ksem_init, "ksem" },
    195  1.1     pooka 	    { SYS__ksem_open, "ksem" },
    196  1.1     pooka 	    { SYS__ksem_unlink, "ksem" },
    197  1.1     pooka 	    { SYS__ksem_close, "ksem" },
    198  1.1     pooka 	    { SYS__ksem_post, "ksem" },
    199  1.1     pooka 	    { SYS__ksem_wait, "ksem" },
    200  1.1     pooka 	    { SYS__ksem_trywait, "ksem" },
    201  1.1     pooka 	    { SYS__ksem_getvalue, "ksem" },
    202  1.1     pooka 	    { SYS__ksem_destroy, "ksem" },
    203  1.6     joerg 	    { SYS__ksem_timedwait, "ksem" },
    204  1.1     pooka 	    { SYS_nfssvc, "nfsserver" },
    205  1.7  christos 	    { SYS_afssys, "openafs" },
    206  1.1     pooka 	};
    207  1.1     pooka 	const struct sysent *sy;
    208  1.1     pooka 	const struct emul *em;
    209  1.1     pooka 	int code, i;
    210  1.1     pooka 
    211  1.1     pooka 	/*
    212  1.1     pooka 	 * Restart the syscall if we interrupted a module unload that
    213  1.5  pgoyette 	 * failed.  Acquiring kernconfig_lock delays us until any unload
    214  1.1     pooka 	 * has been completed or rolled back.
    215  1.1     pooka 	 */
    216  1.5  pgoyette 	kernconfig_lock();
    217  1.1     pooka 	sy = l->l_sysent;
    218  1.1     pooka 	if (sy->sy_call != sys_nomodule) {
    219  1.5  pgoyette 		kernconfig_unlock();
    220  1.1     pooka 		return ERESTART;
    221  1.1     pooka 	}
    222  1.1     pooka 	/*
    223  1.1     pooka 	 * Try to autoload a module to satisfy the request.  If it
    224  1.1     pooka 	 * works, retry the request.
    225  1.1     pooka 	 */
    226  1.1     pooka 	em = l->l_proc->p_emul;
    227  1.1     pooka 	if (em == &emul_netbsd) {
    228  1.1     pooka 		code = sy - em->e_sysent;
    229  1.1     pooka 		for (i = 0; i < __arraycount(autoload); i++) {
    230  1.1     pooka 			if (autoload[i].al_code != code) {
    231  1.1     pooka 				continue;
    232  1.1     pooka 			}
    233  1.1     pooka 			if (module_autoload(autoload[i].al_module,
    234  1.1     pooka 			    MODULE_CLASS_ANY) != 0 ||
    235  1.1     pooka 			    sy->sy_call == sys_nomodule) {
    236  1.1     pooka 			    	break;
    237  1.1     pooka 			}
    238  1.5  pgoyette 			kernconfig_unlock();
    239  1.1     pooka 			return ERESTART;
    240  1.1     pooka 		}
    241  1.1     pooka 	}
    242  1.5  pgoyette 	kernconfig_unlock();
    243  1.1     pooka #endif	/* MODULAR */
    244  1.1     pooka 
    245  1.1     pooka 	return sys_nosys(l, v, retval);
    246  1.1     pooka }
    247  1.1     pooka 
    248  1.1     pooka int
    249  1.1     pooka syscall_establish(const struct emul *em, const struct syscall_package *sp)
    250  1.1     pooka {
    251  1.1     pooka 	struct sysent *sy;
    252  1.1     pooka 	int i;
    253  1.1     pooka 
    254  1.5  pgoyette 	KASSERT(kernconfig_is_held());
    255  1.1     pooka 
    256  1.1     pooka 	if (em == NULL) {
    257  1.1     pooka 		em = &emul_netbsd;
    258  1.1     pooka 	}
    259  1.1     pooka 	sy = em->e_sysent;
    260  1.1     pooka 
    261  1.1     pooka 	/*
    262  1.1     pooka 	 * Ensure that all preconditions are valid, since this is
    263  1.1     pooka 	 * an all or nothing deal.  Once a system call is entered,
    264  1.1     pooka 	 * it can become busy and we could be unable to remove it
    265  1.1     pooka 	 * on error.
    266  1.1     pooka 	 */
    267  1.1     pooka 	for (i = 0; sp[i].sp_call != NULL; i++) {
    268  1.1     pooka 		if (sy[sp[i].sp_code].sy_call != sys_nomodule) {
    269  1.1     pooka #ifdef DIAGNOSTIC
    270  1.1     pooka 			printf("syscall %d is busy\n", sp[i].sp_code);
    271  1.1     pooka #endif
    272  1.1     pooka 			return EBUSY;
    273  1.1     pooka 		}
    274  1.1     pooka 	}
    275  1.1     pooka 	/* Everything looks good, patch them in. */
    276  1.1     pooka 	for (i = 0; sp[i].sp_call != NULL; i++) {
    277  1.1     pooka 		sy[sp[i].sp_code].sy_call = sp[i].sp_call;
    278  1.1     pooka 	}
    279  1.1     pooka 
    280  1.1     pooka 	return 0;
    281  1.1     pooka }
    282  1.1     pooka 
    283  1.1     pooka int
    284  1.1     pooka syscall_disestablish(const struct emul *em, const struct syscall_package *sp)
    285  1.1     pooka {
    286  1.1     pooka 	struct sysent *sy;
    287  1.1     pooka 	uint64_t where;
    288  1.1     pooka 	lwp_t *l;
    289  1.1     pooka 	int i;
    290  1.1     pooka 
    291  1.5  pgoyette 	KASSERT(kernconfig_is_held());
    292  1.1     pooka 
    293  1.1     pooka 	if (em == NULL) {
    294  1.1     pooka 		em = &emul_netbsd;
    295  1.1     pooka 	}
    296  1.1     pooka 	sy = em->e_sysent;
    297  1.1     pooka 
    298  1.1     pooka 	/*
    299  1.1     pooka 	 * First, patch the system calls to sys_nomodule to gate further
    300  1.1     pooka 	 * activity.
    301  1.1     pooka 	 */
    302  1.1     pooka 	for (i = 0; sp[i].sp_call != NULL; i++) {
    303  1.1     pooka 		KASSERT(sy[sp[i].sp_code].sy_call == sp[i].sp_call);
    304  1.1     pooka 		sy[sp[i].sp_code].sy_call = sys_nomodule;
    305  1.1     pooka 	}
    306  1.1     pooka 
    307  1.1     pooka 	/*
    308  1.1     pooka 	 * Run a cross call to cycle through all CPUs.  This does two
    309  1.1     pooka 	 * things: lock activity provides a barrier and makes our update
    310  1.1     pooka 	 * of sy_call visible to all CPUs, and upon return we can be sure
    311  1.1     pooka 	 * that we see pertinent values of l_sysent posted by remote CPUs.
    312  1.1     pooka 	 */
    313  1.1     pooka 	where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL);
    314  1.1     pooka 	xc_wait(where);
    315  1.1     pooka 
    316  1.1     pooka 	/*
    317  1.1     pooka 	 * Now it's safe to check l_sysent.  Run through all LWPs and see
    318  1.1     pooka 	 * if anyone is still using the system call.
    319  1.1     pooka 	 */
    320  1.1     pooka 	for (i = 0; sp[i].sp_call != NULL; i++) {
    321  1.1     pooka 		mutex_enter(proc_lock);
    322  1.1     pooka 		LIST_FOREACH(l, &alllwp, l_list) {
    323  1.1     pooka 			if (l->l_sysent == &sy[sp[i].sp_code]) {
    324  1.1     pooka 				break;
    325  1.1     pooka 			}
    326  1.1     pooka 		}
    327  1.1     pooka 		mutex_exit(proc_lock);
    328  1.1     pooka 		if (l == NULL) {
    329  1.1     pooka 			continue;
    330  1.1     pooka 		}
    331  1.1     pooka 		/*
    332  1.1     pooka 		 * We lose: one or more calls are still in use.  Put back
    333  1.1     pooka 		 * the old entrypoints and act like nothing happened.
    334  1.5  pgoyette 		 * When we drop kernconfig_lock, any system calls held in
    335  1.1     pooka 		 * sys_nomodule() will be restarted.
    336  1.1     pooka 		 */
    337  1.1     pooka 		for (i = 0; sp[i].sp_call != NULL; i++) {
    338  1.1     pooka 			sy[sp[i].sp_code].sy_call = sp[i].sp_call;
    339  1.1     pooka 		}
    340  1.1     pooka 		return EBUSY;
    341  1.1     pooka 	}
    342  1.1     pooka 
    343  1.1     pooka 	return 0;
    344  1.1     pooka }
    345  1.8     pooka 
    346  1.8     pooka /*
    347  1.8     pooka  * Return true if system call tracing is enabled for the specified process.
    348  1.8     pooka  */
    349  1.8     pooka bool
    350  1.8     pooka trace_is_enabled(struct proc *p)
    351  1.8     pooka {
    352  1.8     pooka #ifdef SYSCALL_DEBUG
    353  1.8     pooka 	return (true);
    354  1.8     pooka #endif
    355  1.8     pooka #ifdef KTRACE
    356  1.8     pooka 	if (ISSET(p->p_traceflag, (KTRFAC_SYSCALL | KTRFAC_SYSRET)))
    357  1.8     pooka 		return (true);
    358  1.8     pooka #endif
    359  1.8     pooka #ifdef PTRACE
    360  1.8     pooka 	if (ISSET(p->p_slflag, PSL_SYSCALL))
    361  1.8     pooka 		return (true);
    362  1.8     pooka #endif
    363  1.8     pooka 
    364  1.8     pooka 	return (false);
    365  1.8     pooka }
    366  1.8     pooka 
    367  1.8     pooka /*
    368  1.8     pooka  * Start trace of particular system call. If process is being traced,
    369  1.8     pooka  * this routine is called by MD syscall dispatch code just before
    370  1.8     pooka  * a system call is actually executed.
    371  1.8     pooka  */
    372  1.8     pooka int
    373  1.8     pooka trace_enter(register_t code, const register_t *args, int narg)
    374  1.8     pooka {
    375  1.8     pooka 	int error = 0;
    376  1.8     pooka 
    377  1.8     pooka #ifdef SYSCALL_DEBUG
    378  1.8     pooka 	scdebug_call(code, args);
    379  1.8     pooka #endif /* SYSCALL_DEBUG */
    380  1.8     pooka 
    381  1.8     pooka 	ktrsyscall(code, args, narg);
    382  1.8     pooka 
    383  1.8     pooka #ifdef PTRACE
    384  1.8     pooka 	if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
    385  1.8     pooka 	    (PSL_SYSCALL|PSL_TRACED)) {
    386  1.8     pooka 		process_stoptrace();
    387  1.8     pooka 		if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
    388  1.8     pooka 			/* tracer will emulate syscall for us */
    389  1.8     pooka 			error = EJUSTRETURN;
    390  1.8     pooka 		}
    391  1.8     pooka 	}
    392  1.8     pooka #endif
    393  1.8     pooka 	return error;
    394  1.8     pooka }
    395  1.8     pooka 
    396  1.8     pooka /*
    397  1.8     pooka  * End trace of particular system call. If process is being traced,
    398  1.8     pooka  * this routine is called by MD syscall dispatch code just after
    399  1.8     pooka  * a system call finishes.
    400  1.8     pooka  * MD caller guarantees the passed 'code' is within the supported
    401  1.8     pooka  * system call number range for emulation the process runs under.
    402  1.8     pooka  */
    403  1.8     pooka void
    404  1.8     pooka trace_exit(register_t code, register_t rval[], int error)
    405  1.8     pooka {
    406  1.8     pooka #ifdef PTRACE
    407  1.8     pooka 	struct proc *p = curlwp->l_proc;
    408  1.8     pooka #endif
    409  1.8     pooka 
    410  1.8     pooka #ifdef SYSCALL_DEBUG
    411  1.8     pooka 	scdebug_ret(code, error, rval);
    412  1.8     pooka #endif /* SYSCALL_DEBUG */
    413  1.8     pooka 
    414  1.8     pooka 	ktrsysret(code, error, rval);
    415  1.8     pooka 
    416  1.8     pooka #ifdef PTRACE
    417  1.8     pooka 	if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) ==
    418  1.8     pooka 	    (PSL_SYSCALL|PSL_TRACED))
    419  1.8     pooka 		process_stoptrace();
    420  1.8     pooka 	CLR(p->p_slflag, PSL_SYSCALLEMU);
    421  1.8     pooka #endif
    422  1.8     pooka }
    423