Home | History | Annotate | Line # | Download | only in common
linux32_misc.c revision 1.12.4.1
      1  1.12.4.1     skrll /*	$NetBSD: linux32_misc.c,v 1.12.4.1 2009/01/19 13:17:31 skrll Exp $	*/
      2       1.1      manu 
      3       1.1      manu /*-
      4       1.5     njoly  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
      5       1.5     njoly  * All rights reserved.
      6       1.5     njoly  *
      7       1.5     njoly  * This code is derived from software contributed to The NetBSD Foundation
      8       1.5     njoly  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
      9       1.5     njoly  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center;
     10       1.5     njoly  * by Edgar Fu\ss, Mathematisches Institut der Uni Bonn.
     11       1.1      manu  *
     12       1.1      manu  * Redistribution and use in source and binary forms, with or without
     13       1.1      manu  * modification, are permitted provided that the following conditions
     14       1.1      manu  * are met:
     15       1.1      manu  * 1. Redistributions of source code must retain the above copyright
     16       1.1      manu  *    notice, this list of conditions and the following disclaimer.
     17       1.1      manu  * 2. Redistributions in binary form must reproduce the above copyright
     18       1.1      manu  *    notice, this list of conditions and the following disclaimer in the
     19       1.1      manu  *    documentation and/or other materials provided with the distribution.
     20       1.1      manu  *
     21       1.5     njoly  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22       1.5     njoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23       1.5     njoly  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24       1.5     njoly  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25       1.1      manu  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26       1.1      manu  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27       1.1      manu  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28       1.1      manu  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29       1.1      manu  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30       1.1      manu  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31       1.1      manu  * POSSIBILITY OF SUCH DAMAGE.
     32       1.1      manu  */
     33       1.1      manu 
     34       1.1      manu #include <sys/cdefs.h>
     35  1.12.4.1     skrll __KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.12.4.1 2009/01/19 13:17:31 skrll Exp $");
     36       1.1      manu 
     37       1.1      manu #include <sys/param.h>
     38       1.1      manu #include <sys/proc.h>
     39       1.5     njoly #include <sys/time.h>
     40       1.5     njoly #include <sys/types.h>
     41       1.5     njoly #include <sys/malloc.h>
     42       1.7       dsl #include <sys/fstypes.h>
     43       1.7       dsl #include <sys/vfs_syscalls.h>
     44      1.11  christos #include <sys/ptrace.h>
     45  1.12.4.1     skrll #include <sys/syscall.h>
     46       1.1      manu 
     47       1.1      manu #include <compat/netbsd32/netbsd32.h>
     48       1.1      manu #include <compat/netbsd32/netbsd32_syscallargs.h>
     49       1.1      manu 
     50       1.5     njoly #include <compat/linux32/common/linux32_types.h>
     51       1.5     njoly #include <compat/linux32/common/linux32_signal.h>
     52       1.5     njoly #include <compat/linux32/linux32_syscallargs.h>
     53       1.5     njoly 
     54      1.11  christos #include <compat/linux/common/linux_ptrace.h>
     55       1.1      manu #include <compat/linux/common/linux_types.h>
     56       1.1      manu #include <compat/linux/common/linux_signal.h>
     57       1.1      manu #include <compat/linux/common/linux_misc.h>
     58       1.5     njoly #include <compat/linux/common/linux_statfs.h>
     59  1.12.4.1     skrll #include <compat/linux/common/linux_ipc.h>
     60  1.12.4.1     skrll #include <compat/linux/common/linux_sem.h>
     61       1.1      manu #include <compat/linux/linux_syscallargs.h>
     62       1.1      manu 
     63       1.5     njoly extern const struct linux_mnttypes linux_fstypes[];
     64       1.5     njoly extern const int linux_fstypes_cnt;
     65       1.1      manu 
     66       1.1      manu 
     67       1.5     njoly /*
     68       1.5     njoly  * Implement the fs stat functions. Straightforward.
     69       1.5     njoly  */
     70       1.1      manu int
     71       1.9       dsl linux32_sys_statfs(struct lwp *l, const struct linux32_sys_statfs_args *uap, register_t *retval)
     72       1.1      manu {
     73       1.9       dsl 	/* {
     74       1.5     njoly 		syscallarg(const netbsd32_charp char) path;
     75       1.5     njoly 		syscallarg(linux32_statfsp) sp;
     76       1.9       dsl 	} */
     77       1.7       dsl 	struct statvfs *sb;
     78       1.5     njoly 	struct linux_statfs ltmp;
     79       1.1      manu 	int error;
     80       1.1      manu 
     81       1.7       dsl 	sb = STATVFSBUF_GET();
     82       1.7       dsl 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb);
     83       1.7       dsl 	if (error == 0) {
     84       1.7       dsl 		bsd_to_linux_statfs(sb, &ltmp);
     85       1.7       dsl 		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
     86       1.7       dsl 	}
     87       1.1      manu 
     88       1.7       dsl 	STATVFSBUF_PUT(sb);
     89       1.5     njoly 	return error;
     90       1.1      manu }
     91      1.12     njoly 
     92      1.11  christos extern const int linux_ptrace_request_map[];
     93      1.12     njoly 
     94      1.11  christos int
     95      1.11  christos linux32_sys_ptrace(struct lwp *l, const struct linux32_sys_ptrace_args *uap, register_t *retval)
     96      1.11  christos {
     97      1.11  christos 	/* {
     98      1.11  christos 		i386, m68k, powerpc: T=int
     99      1.11  christos 		alpha, amd64: T=long
    100      1.11  christos 		syscallarg(T) request;
    101      1.11  christos 		syscallarg(T) pid;
    102      1.11  christos 		syscallarg(T) addr;
    103      1.11  christos 		syscallarg(T) data;
    104      1.11  christos 	} */
    105      1.11  christos 	const int *ptr;
    106      1.11  christos 	int request;
    107      1.11  christos 	int error;
    108      1.11  christos 
    109      1.11  christos 	ptr = linux_ptrace_request_map;
    110      1.11  christos 	request = SCARG(uap, request);
    111      1.11  christos 	while (*ptr != -1)
    112      1.11  christos 		if (*ptr++ == request) {
    113      1.12     njoly 			struct sys_ptrace_args pta;
    114      1.11  christos 
    115      1.11  christos 			SCARG(&pta, req) = *ptr;
    116      1.11  christos 			SCARG(&pta, pid) = SCARG(uap, pid);
    117      1.12     njoly 			SCARG(&pta, addr) = NETBSD32IPTR64(SCARG(uap, addr));
    118      1.11  christos 			SCARG(&pta, data) = SCARG(uap, data);
    119      1.11  christos 
    120      1.11  christos 			/*
    121      1.11  christos 			 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually
    122      1.11  christos 			 * to continue where the process left off previously.
    123      1.11  christos 			 * The same thing is achieved by addr == (void *) 1
    124      1.11  christos 			 * on NetBSD, so rewrite 'addr' appropriately.
    125      1.11  christos 			 */
    126      1.11  christos 			if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0)
    127      1.11  christos 				SCARG(&pta, addr) = (void *) 1;
    128      1.11  christos 
    129  1.12.4.1     skrll 			error = sysent[SYS_ptrace].sy_call(l, &pta, retval);
    130      1.11  christos 			if (error)
    131      1.11  christos 				return error;
    132      1.11  christos 			switch (request) {
    133      1.11  christos 			case LINUX_PTRACE_PEEKTEXT:
    134      1.11  christos 			case LINUX_PTRACE_PEEKDATA:
    135      1.11  christos 				error = copyout (retval,
    136      1.12     njoly 				    NETBSD32IPTR64(SCARG(uap, data)),
    137      1.11  christos 				    sizeof *retval);
    138      1.11  christos 				*retval = SCARG(uap, data);
    139      1.11  christos 				break;
    140      1.11  christos 			default:
    141      1.11  christos 				break;
    142      1.11  christos 			}
    143      1.11  christos 			return error;
    144      1.11  christos 		}
    145      1.11  christos 		else
    146      1.11  christos 			ptr++;
    147      1.11  christos 
    148      1.12     njoly 	return EIO;
    149      1.11  christos }
    150