NetBSD Problem Report #56418

From www@netbsd.org  Mon Sep 27 08:43:00 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3994C1A921F
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 27 Sep 2021 08:43:00 +0000 (UTC)
Message-Id: <20210927084258.BA6E01A9239@mollari.NetBSD.org>
Date: Mon, 27 Sep 2021 08:42:58 +0000 (UTC)
From: hashikaw@mail.ru
Reply-To: hashikaw@mail.ru
To: gnats-bugs@NetBSD.org
Subject: cannot compile INSTALL_FLOPPY kernel on current/i386
X-Send-Pr-Version: www-1.0

>Number:         56418
>Category:       kern
>Synopsis:       cannot compile INSTALL_FLOPPY kernel on current/i386
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 27 08:45:00 +0000 2021
>Last-Modified:  Thu Sep 30 06:10:02 +0000 2021
>Originator:     Kouichi Hashikawa
>Release:        9.99.88
>Organization:
>Environment:
>Description:
I cannot compile INSTALL_FLOPPY kernel (contains no option PTRACE_HOOKS)  on current/i386 with, 

#      link  INSTALL_FLOPPY/netbsd
/current/netbsd/c/build/tools/bin/i486--netbsdelf-ld -Map netbsd.map --cref -T netbsd.ldscript -Ttext c0100000 -e start -X -o netbsd ${SYSTEM_OBJ:[@]:Nswapnetbsd.o} ${EXTRA_OBJ} vers.o swapnetbsd.o
/current/netbsd/c/build/tools/bin/i486--netbsdelf-ld: sys_process_lwpstatus.o: in function `process_doregs': sys_process_lwpstatus.c:(.text+0x379): undefined reference to `process_write_regs'
/current/netbsd/c/build/tools/bin/i486--netbsdelf-ld: sys_process_lwpstatus.o: in function `process_dofpregs': sys_process_lwpstatus.c:(.text+0x3a9): undefined reference to `process_write_fpregs'
/current/netbsd/c/build/tools/bin/i486--netbsdelf-ld: sys_process_lwpstatus.o: in function `process_dodbregs': sys_process_lwpstatus.c:(.text+0x3d9): undefined reference to `process_write_dbregs'

*** Failed target:  netbsd

>How-To-Repeat:
enable to build INSTALL_FLOPPY kernel and make the kernel.
(in src/etc/etc.i386/Makefile.inc, INSTALL_FLOPPY to BUILD_KERNELS).

>Fix:
I think, 

--- src/sys/kern/sys_process_lwpstatus.c-dist   2020-12-21 16:20:40.000000000 +0900
+++ src/sys/kern/sys_process_lwpstatus.c        2021-09-26 15:19:27.982208400 +0900
@@ -144,7 +144,7 @@
 #endif
 }

-#ifdef PT_REGISTERS
+#if defined(PTRACE_HOOKS) && defined(PT_REGISTERS)
 static int
 proc_regio(struct lwp *l, struct uio *uio, size_t ks, ptrace_regrfunc_t r,
     ptrace_regwfunc_t w)
@@ -186,7 +186,7 @@
     struct lwp *l /*traced*/,
     struct uio *uio)
 {
-#if defined(PT_GETREGS) || defined(PT_SETREGS)
+#if defined(PTRACE_HOOKS) && (defined(PT_GETREGS) || defined(PT_SETREGS))
        size_t s;
        ptrace_regrfunc_t r;
        ptrace_regwfunc_t w;
@@ -220,7 +220,7 @@
     struct lwp *l /*traced*/,
     struct uio *uio)
 {
-#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
+#if defined(PTRACE_HOOKS) && (defined(PT_GETFPREGS) || defined(PT_SETFPREGS))
        size_t s;
        ptrace_regrfunc_t r;
        ptrace_regwfunc_t w;
@@ -255,7 +255,7 @@
     struct lwp *l /*traced*/,
     struct uio *uio)
 {
-#if defined(PT_GETDBREGS) || defined(PT_SETDBREGS)
+#if defined(PTRACE_HOOKS) && (defined(PT_GETDBREGS) || defined(PT_SETDBREGS))
        size_t s;
        ptrace_regrfunc_t r;
        ptrace_regwfunc_t w;

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: hashikaw@mail.ru
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/56418: cannot compile INSTALL_FLOPPY kernel on current/i386
Date: Mon, 27 Sep 2021 22:11:27 +0700

     Date:        Mon, 27 Sep 2021 08:45:00 +0000 (UTC)
     From:        hashikaw@mail.ru
     Message-ID:  <20210927084500.738461A921F@mollari.NetBSD.org>


   | >Fix:
   | I think, 
   |

   | -#ifdef PT_REGISTERS
   | +#if defined(PTRACE_HOOKS) && defined(PT_REGISTERS)

 I would do, earlier than that

 #ifndef PTRACE_HOOKS		/* perhaps with a comment */
 #undef PT_REGISTERS
 #undef PT_GETREGS
 #undef PT_SETREGS
 #undef PT_GETFPREGS
 #undef PT_SETFPREGS
 #undef PT_GETFPREGS
 #undef PT_SETDBREGS
 #endif

 That is, avoid cluttering already cluttered #if lines with even more

 kre

From: Kouichi Hashikawa <hashikaw@mail.ru>
To: kre@munnari.oz.au, kern-bug-people@netbsd.org, gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56418: cannot compile INSTALL_FLOPPY kernel on current/i386
Date: Thu, 30 Sep 2021 15:07:25 +0900

 =EF=BB=BFHi, Robert, thank you for checking my patch.

 I change src/sys/arch/i386/include/ptrace.h to match
 src/sys/arch/i386/i386/process_machdep.c,
 and fix other errors by changing src/sys/arch/i386/include/ptrace.h.

 I have questions.
 o on src/sys/compat/linux/arch/i386/linux_ptrace.c,
 if PT_SETREGS, PT_SETFPREGS, ... is not defined, nothing to do?
 o on src/sys/compat/linux/arch/i386/linux_ptrace.c,
 in case LINUX_PTRACE_SETFPREGS:,=20
 process_write_regs(lt, regs) -> process_write_fpregs(lt, fpregs) ?

 --- src/sys/arch/i386/include/ptrace.h-dist     2020-05-31 21:52:17.00000000=
 0=20
 +0900
 +++ src/sys/arch/i386/include/ptrace.h  2021-09-28 20:12:28.565839877 +0900
 @@ -71,6 +71,29 @@
 /*
 * i386-dependent ptrace definitions
 */
 +#if defined(_KERNEL) && !defined(PTRACE_HOOKS)
 +
 +#define        PT_GETREGS      (PT_FIRSTMACH + 1)
 +#define        PT_GETFPREGS    (PT_FIRSTMACH + 3)
 +#define        PT_GETDBREGS    (PT_FIRSTMACH + 7)
 +
 +#define PT_MACHDEP_STRINGS \
 +       "*PT_INVALID_32*", \
 +       "PT_GETREGS", \
 +       "*PT_INVALID_34*", \
 +       "PT_GETFPREGS", \
 +       "*PT_INVALID_36*", \
 +       "*PT_INVALID_37*", \
 +       "*PT_INVALID_38*", \
 +       "PT_GETDBREGS", \
 +       "*PT_INVALID_40*", \
 +       "*PT_INVALID_41*", \
 +       "*PT_INVALID_42*", \
 +       "*PT_INVALID_43*", \
 +       "*PT_INVALID_44*"
 +
 +#else
 +
 #define        PT_STEP         (PT_FIRSTMACH + 0)
 #define        PT_GETREGS      (PT_FIRSTMACH + 1)
 #define        PT_SETREGS      (PT_FIRSTMACH + 2)
 @@ -108,6 +131,8 @@
 "PT_GETXSTATE", \
 "PT_SETXSTATE"

 +#endif /* _KERNEL && !PTRACE_HOOKS */
 +
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->r_eip
 #define PTRACE_REG_FP(r)       (r)->r_ebp
 @@ -124,6 +149,7 @@

 #ifdef _KERNEL

 +#if defined(PTRACE_HOOKS)
 /*
 * These are used in sys_ptrace() to find good ptrace(2) requests.
 */
 @@ -187,6 +213,8 @@
 struct pfsnode *, struct uio *);
 int    procfs_machdep_validxmmregs(struct lwp *, struct mount *);

 +#endif /* PTRACE_HOOKS */
 +
 /*
 * The fpregs structure contains an fxsave area, which must have 16-byte
 * alignment.
 --- src/sys/kern/sys_process_lwpstatus.c-dist   2020-12-21 16:20:40.00000000=
 0=20
 +0900
 +++ src/sys/kern/sys_process_lwpstatus.c        2021-09-29 00:53:46.80245259=
 6=20
 +0900
 @@ -145,6 +145,9 @@
 }

 #ifdef PT_REGISTERS
 +#if (defined(PT_GETREGS) && defined(PT_SETREGS)) || \
 +    (defined(PT_GETFPREGS) && defined(PT_SETFPREGS)) || \
 +    (defined(PT_GETDBREGS) && defined(PT_SETDBREGS))
 static int
 proc_regio(struct lwp *l, struct uio *uio, size_t ks, ptrace_regrfunc_t r,
 ptrace_regwfunc_t w)
 @@ -180,13 +183,14 @@
 return error;
 }
 #endif
 +#endif

 int
 process_doregs(struct lwp *curl /*tracer*/,
 struct lwp *l /*traced*/,
 struct uio *uio)
 {
 -#if defined(PT_GETREGS) || defined(PT_SETREGS)
 +#if defined(PT_GETREGS) && defined(PT_SETREGS)
 size_t s;
 ptrace_regrfunc_t r;
 ptrace_regwfunc_t w;
 @@ -220,7 +224,7 @@
 struct lwp *l /*traced*/,
 struct uio *uio)
 {
 -#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
 +#if defined(PT_GETFPREGS) && defined(PT_SETFPREGS)
 size_t s;
 ptrace_regrfunc_t r;
 ptrace_regwfunc_t w;
 @@ -255,7 +259,7 @@
 struct lwp *l /*traced*/,
 struct uio *uio)
 {
 -#if defined(PT_GETDBREGS) || defined(PT_SETDBREGS)
 +#if defined(PT_GETDBREGS) && defined(PT_SETDBREGS)
 size_t s;
 ptrace_regrfunc_t r;
 ptrace_regwfunc_t w;
 --- src/sys/compat/linux/arch/i386/linux_ptrace.c-dist  2021-09-08 18:55:46.=
 33
 6270896 +0900
 +++ src/sys/compat/linux/arch/i386/linux_ptrace.c       2021-09-28 19:51:34.=
 02
 8158505 +0900
 @@ -218,6 +218,7 @@

 switch (request) {
 case LINUX_PTRACE_GETREGS:
 +#if defined(PT_GETREGS)
     error =3D process_read_regs(lt, regs);
     mutex_exit(t->p_lock);
     if (error) {
 @@ -242,9 +243,11 @@

     error =3D copyout(linux_regs, (void *)SCARG(uap, data),
         sizeof(struct linux_reg));
 +#endif
     break;

 case LINUX_PTRACE_SETREGS:
 +#if defined(PT_SETREGS)
     regs->r_ebx =3D linux_regs->ebx;
     regs->r_ecx =3D linux_regs->ecx;
     regs->r_edx =3D linux_regs->edx;
 @@ -262,9 +265,11 @@

     error =3D process_write_regs(lt, regs);
     mutex_exit(t->p_lock);
 +#endif
     break;

 case LINUX_PTRACE_GETFPREGS:
 +#if defined(PT_GETFPREGS)
     fp_size =3D sizeof fpregs;
     error =3D process_read_fpregs(lt, fpregs, &fp_size);
     mutex_exit(t->p_lock);
 @@ -279,14 +284,17 @@
         uimin(sizeof(struct linux_fpctx), fp_size));
     error =3D copyout(linux_fpregs, (void *)SCARG(uap, data),
         sizeof(struct linux_fpctx));
 +#endif
     break;

 case LINUX_PTRACE_SETFPREGS:
 +#if defined(PT_SETFPREGS)
     memset(fpregs, '\0', sizeof(struct fpreg));
     memcpy(fpregs, linux_fpregs,
         uimin(sizeof(struct linux_fpctx), sizeof(struct fpreg)));
 -               error =3D process_write_regs(lt, regs);
 +               error =3D process_write_fpregs(lt, fpregs);
     mutex_exit(t->p_lock);
 +#endif
     break;

 case LINUX_PTRACE_PEEKUSR:
 --- src/sys/secmodel/extensions/secmodel_extensions.c-dist      2020-03-17 0=
 6:
 20:12.000000000 +0900
 +++ src/sys/secmodel/extensions/secmodel_extensions.c   2021-09-28 23:11:21.=
 22
 6096353 +0900
 @@ -29,6 +29,10 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: secmodel_extensions.c,v 1.12 2020/03/16 21:20:12=
 =20
 pgoyette Exp $");

 +#ifdef _KERNEL_OPT
 +#include "opt_ptrace.h"
 +#endif
 +
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/kauth.h>

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.