Put ptrace_read_lwpstatus() and process_read_lwpstatus() to a new file

Fixes "no PTRACE" kernel build, in particular zaurus kernel=INSTALL_C700.
This commit is contained in:
kamil 2019-12-26 08:52:38 +00:00
parent 34e695ab0e
commit 3097490d1b
4 changed files with 88 additions and 36 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files.kern,v 1.40 2019/12/20 21:20:09 ad Exp $
# $NetBSD: files.kern,v 1.41 2019/12/26 08:52:38 kamil Exp $
#
# kernel sources
@ -163,6 +163,7 @@ file kern/sys_pipe.c !pipe_socketpair
file kern/sys_process.c ptrace_hooks | ktrace
file kern/sys_ptrace.c ptrace
file kern/sys_ptrace_common.c ptrace
file kern/sys_ptrace_lwpstatus.c kern
file kern/sys_pset.c kern
file kern/sys_select.c kern
file kern/sys_sig.c kern

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_ptrace_common.c,v 1.75 2019/12/25 15:54:02 kamil Exp $ */
/* $NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -118,7 +118,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.75 2019/12/25 15:54:02 kamil Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@ -790,38 +790,6 @@ ptrace_lwpinfo(struct proc *t, struct lwp **lt, void *addr, size_t data)
return copyout(&pl, addr, sizeof(pl));
}
static void
ptrace_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
{
KASSERT(l->l_lid == pls->pl_lwpid);
memcpy(&pls->pl_sigmask, &l->l_sigmask, sizeof(pls->pl_sigmask));
memcpy(&pls->pl_sigpend, &l->l_sigpend.sp_set, sizeof(pls->pl_sigpend));
if (l->l_name == NULL)
memset(&pls->pl_name, 0, PL_LNAMELEN);
else {
KASSERT(strlen(l->l_name) < PL_LNAMELEN);
strncpy(pls->pl_name, l->l_name, PL_LNAMELEN);
}
#ifdef PTRACE_LWP_GETPRIVATE
pls->pl_private = (void *)(intptr_t)PTRACE_LWP_GETPRIVATE(l);
#else
pls->pl_private = l->l_private;
#endif
}
void
process_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
{
pls->pl_lwpid = l->l_lid;
ptrace_read_lwpstatus(l, pls);
}
static int
ptrace_lwpstatus(struct proc *t, struct ptrace_methods *ptm, struct lwp **lt,
void *addr, size_t data, bool next)

View File

@ -0,0 +1,81 @@
/* $NetBSD: sys_ptrace_lwpstatus.c,v 1.1 2019/12/26 08:52:38 kamil Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* 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 <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_lwpstatus.c,v 1.1 2019/12/26 08:52:38 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
#include "opt_ktrace.h"
#include "opt_pax.h"
#include "opt_compat_netbsd32.h"
#endif
#if defined(__HAVE_COMPAT_NETBSD32) && !defined(COMPAT_NETBSD32) \
&& !defined(_RUMPKERNEL)
#define COMPAT_NETBSD32
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/lwp.h>
#include <sys/ptrace.h>
void
ptrace_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
{
KASSERT(l->l_lid == pls->pl_lwpid);
memcpy(&pls->pl_sigmask, &l->l_sigmask, sizeof(pls->pl_sigmask));
memcpy(&pls->pl_sigpend, &l->l_sigpend.sp_set, sizeof(pls->pl_sigpend));
if (l->l_name == NULL)
memset(&pls->pl_name, 0, PL_LNAMELEN);
else {
KASSERT(strlen(l->l_name) < PL_LNAMELEN);
strncpy(pls->pl_name, l->l_name, PL_LNAMELEN);
}
#ifdef PTRACE_LWP_GETPRIVATE
pls->pl_private = (void *)(intptr_t)PTRACE_LWP_GETPRIVATE(l);
#else
pls->pl_private = l->l_private;
#endif
}
void
process_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
{
pls->pl_lwpid = l->l_lid;
ptrace_read_lwpstatus(l, pls);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ptrace.h,v 1.68 2019/12/24 14:50:59 kamil Exp $ */
/* $NetBSD: ptrace.h,v 1.69 2019/12/26 08:52:38 kamil Exp $ */
/*-
* Copyright (c) 1984, 1993
@ -260,6 +260,8 @@ void proc_changeparent(struct proc *, struct proc *);
int do_ptrace(struct ptrace_methods *, struct lwp *, int, pid_t, void *,
int, register_t *);
void ptrace_read_lwpstatus(struct lwp *, struct ptrace_lwpstatus *);
void process_read_lwpstatus(struct lwp *, struct ptrace_lwpstatus *);
#ifndef process_read_lwpstatus32
#define process_read_lwpstatus32 process_read_lwpstatus