/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matthias Scheler.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <lib/libkern/libkern.h> /* for offsetof() */
/*
* On ARMv2, uregs contains R0--R15, orig_R0.
* On ARMv3 and later, it's R0--R15, CPSR, orig_R0.
* As far as I can see, Linux doesn't initialise orig_R0 on ARMv2, so we
* just produce the ARMv3 version.
*/
switch (request) {
case LINUX_PTRACE_GETREGS:
break;
case LINUX_PTRACE_SETREGS:
error = copyin((void *)SCARG(uap, data), linux_regs,
sizeof(struct linux_reg));
if (error) {
goto out;
}
break;
default:
error = EIO;
goto out;
}
/* Find the process we are supposed to be operating on. */
mutex_enter(&proc_lock);
if ((t = proc_find(SCARG(uap, pid))) == NULL) {
mutex_exit(&proc_lock);
error = ESRCH;
goto out;
}
mutex_enter(t->p_lock);
/*
* You cannot do what you want to the process if:
* 1. It is not being traced at all,
*/
if (!ISSET(t->p_slflag, PSL_TRACED)) {
mutex_exit(t->p_lock);
mutex_exit(&proc_lock);
error = EPERM;
goto out;
}
/*
* 2. It is being traced by procfs (which has different signal
* delivery semantics),
* 3. It is not being traced by _you_, or
* 4. It is not currently stopped.
*/
if (t->p_pptr != p || t->p_stat != SSTOP || !t->p_waited) {
mutex_exit(t->p_lock);
mutex_exit(&proc_lock);
error = EBUSY;
goto out;
}
mutex_exit(&proc_lock);
/* XXX: ptrace needs revamp for multi-threading support. */
if (t->p_nlwps > 1) {
mutex_exit(t->p_lock);
error = ENOSYS;
goto out;
}
lt = LIST_FIRST(&t->p_lwps);
*retval = 0;