CVS commit: src/share/man/man3

2020-01-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jan 13 09:00:20 UTC 2020

Modified Files:
src/share/man/man3: dlinfo.3

Log Message:
Bump date in dlinfo(3)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/man/man3/dlinfo.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man3/dlinfo.3
diff -u src/share/man/man3/dlinfo.3:1.1 src/share/man/man3/dlinfo.3:1.2
--- src/share/man/man3/dlinfo.3:1.1	Mon Jan 13 08:25:02 2020
+++ src/share/man/man3/dlinfo.3	Mon Jan 13 09:00:20 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dlinfo.3,v 1.1 2020/01/13 08:25:02 kamil Exp $
+.\"	$NetBSD: dlinfo.3,v 1.2 2020/01/13 09:00:20 kamil Exp $
 .\"
 .\" Copyright (c) 2003 Alexey Zelkin 
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: head/lib/libc/gen/dlinfo.3 267774 2014-06-23 08:25:03Z bapt $
 .\"
-.Dd February 14, 2003
+.Dd January 13, 2020
 .Dt DLINFO 3
 .Os
 .Sh NAME



CVS commit: src/share/man/man3

2020-01-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jan 13 08:29:05 UTC 2020

Modified Files:
src/share/man/man3: dlfcn.3

Log Message:
Cross-Link from dlfcn(3) to dlinfo(3)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/share/man/man3/dlfcn.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man3/dlfcn.3
diff -u src/share/man/man3/dlfcn.3:1.33 src/share/man/man3/dlfcn.3:1.34
--- src/share/man/man3/dlfcn.3:1.33	Sat Jun 25 12:44:37 2011
+++ src/share/man/man3/dlfcn.3	Mon Jan 13 08:29:05 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dlfcn.3,v 1.33 2011/06/25 12:44:37 wiz Exp $
+.\"	$NetBSD: dlfcn.3,v 1.34 2020/01/13 08:29:05 kamil Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -350,6 +350,7 @@ a module that needs libpthread but isn't
 .Sh SEE ALSO
 .Xr ld 1 ,
 .Xr rtld 1 ,
+.Xr dlinfo 3 ,
 .Xr link 5
 .Sh HISTORY
 Some of the



CVS commit: src

2020-01-13 Thread Kamil Rytarowski
plicity, error checking has been omitted.
+.Bd -literal -offset indent
+Link_map *map;
+
+dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, );
+
+while (map != NULL) {
+	printf("%p: %s\\n", map->l_addr, map->l_name);
+	map = map->l_next;
+}
+.Ed
+.\" .Pp
+.\" Example 2: Using
+.\" .Fn dlinfo
+.\" to retrieve the library search paths.
+.\" .Pp
+.\" The following example shows how a dynamic object can inspect the library
+.\" search paths that would be used to locate a simple filename with
+.\" .Xr dlopen 3 .
+.\" For simplicity, error checking has been omitted.
+.\" .Bd -literal -offset indent
+.\" Dl_serinfo	 _info, *info = &_info;
+.\" Dl_serpath	*path;
+.\" unsigned int	 cnt;
+.\" 
+.\" /* determine search path count and required buffer size */
+.\" dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info);
+.\" 
+.\" /* allocate new buffer and initialize */
+.\" info = malloc(_info.dls_size);
+.\" info->dls_size = _info.dls_size;
+.\" info->dls_cnt = _info.dls_cnt;
+.\" 
+.\" /* obtain sarch path information */
+.\" dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info);
+.\" 
+.\" path = >dls_serpath[0];
+.\" 
+.\" for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
+.\" 	(void) printf("%2d: %s\\n", cnt, path->dls_name);
+.\" }
+.\" .Ed
+.Sh SEE ALSO
+.Xr rtld 1 ,
+.Xr dladdr 3 ,
+.Xr dlopen 3 ,
+.Xr dlsym 3
+.Sh HISTORY
+The
+.Fn dlinfo
+function first appeared in the Solaris operating system.
+In
+.Nx ,
+it first appeared in
+.Nx 5.1 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Fx
+implementation of the
+.Fn dlinfo
+function was originally written by
+.An Antii Kantee Aq Mt po...@netbsd.org .
+.Pp
+The manual page for this function was written by
+.An Alexey Zelkin Aq Mt phan...@freebsd.org
+and adapted to
+.Nx
+by
+.An Kamil Rytarowski Aq Mt ka...@netbsd.org .



CVS commit: src/sys/arch/i386/include

2020-01-09 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jan  9 10:46:31 UTC 2020

Modified Files:
src/sys/arch/i386/include: ptrace.h

Log Message:
Add missing compat define of PT32_GETXSTATE

Fixes i386 build.

Reviewed by 


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/i386/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/include/ptrace.h
diff -u src/sys/arch/i386/include/ptrace.h:1.24 src/sys/arch/i386/include/ptrace.h:1.25
--- src/sys/arch/i386/include/ptrace.h:1.24	Wed Jan  8 17:21:38 2020
+++ src/sys/arch/i386/include/ptrace.h	Thu Jan  9 10:46:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.24 2020/01/08 17:21:38 mgorny Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.25 2020/01/09 10:46:31 kamil Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -159,6 +159,7 @@
 	{ DT_REG, N("xmmregs"), Pmachdep_xmmregs,			\
 	  procfs_machdep_validxmmregs },
 
+#define PT32_GETXSTATE		PT_GETXSTATE
 #define COREDUMP_MACHDEP_LWP_NOTES(l, ns, name)\
 {	\
 	struct xstate xstate;		\



CVS commit: src/lib/libc/sys

2020-01-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Jan  4 04:40:17 UTC 2020

Modified Files:
src/lib/libc/sys: ptrace.2

Log Message:
/tmp/cvsbigmGa


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/lib/libc/sys/ptrace.2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/ptrace.2
diff -u src/lib/libc/sys/ptrace.2:1.82 src/lib/libc/sys/ptrace.2:1.83
--- src/lib/libc/sys/ptrace.2:1.82	Wed Oct  9 14:20:47 2019
+++ src/lib/libc/sys/ptrace.2	Sat Jan  4 04:40:17 2020
@@ -1,7 +1,7 @@
-.\"	$NetBSD: ptrace.2,v 1.82 2019/10/09 14:20:47 wiz Exp $
+.\"	$NetBSD: ptrace.2,v 1.83 2020/01/04 04:40:17 kamil Exp $
 .\"
 .\" This file is in the public domain.
-.Dd October 9, 2019
+.Dd January 4, 2019
 .Dt PTRACE 2
 .Os
 .Sh NAME
@@ -399,7 +399,7 @@ argument should contain the name of the 
 and the
 .Fa data
 argument should contain the length of the core filename.
-.It Dv PT_LWPINFO
+.It Dv PT_LWPSTATUS
 Returns information about a thread from the list of threads for the
 process specified in the
 .Fa pid
@@ -407,41 +407,50 @@ argument.
 The
 .Fa addr
 argument should contain a
-.Vt struct ptrace_lwpinfo
+.Vt struct ptrace_lwpstatus
 defined as:
 .Bd -literal -offset indent
-struct ptrace_lwpinfo {
+struct ptrace_lwpstatus {
 	lwpid_t pl_lwpid;
-	int pl_event;
+	sigset_t pl_sigpend;
+	sigset_t pl_sigmask;
+	char pl_name[20];
+	void *pl_private;
 };
 .Ed
 .Pp
 where
 .Fa pl_lwpid
 contains a thread LWP ID.
-Information is returned for the thread following the one with the
+Information is returned for the thread specified in
+.Fa pl_lwpid .
+.Fa pl_sigpend
+contains the signals pending on that LWP.
+.Fa pl_sigmask
+contains the signals masked on that LWP.
+.Fa pl_name
+contains printable name of the LWP.
+The string is always NUL terminated.
+.Fa pl_private
+contains the pointer to TLS base.
+.Pp
+The
+.Fa data
+argument should contain
+.Dq Li sizeof(struct ptrace_lwpinfo) .
+.It Dv PT_LWPNEXT
+Is the same as
+.Dv PT_LWPSTATUS ,
+except that information is returned for the thread following the one with the
 specified ID in the process thread list, or for the first thread
 if
 .Fa pl_lwpid
 is 0.
+.Pp
 Upon return
 .Fa pl_lwpid
 contains the LWP ID of the thread that was found, or 0 if there is
 no thread after the one whose LWP ID was supplied in the call.
-.Fa pl_event
-contains the event that stopped the thread.
-Possible values are:
-.Pp
-.Bl -tag -width 30n -offset indent -compact
-.It Dv PL_EVENT_NONE
-.It Dv PL_EVENT_SIGNAL
-.It Dv PL_EVENT_SUSPENDED
-.El
-.Pp
-The
-.Fa data
-argument should contain
-.Dq Li sizeof(struct ptrace_lwpinfo) .
 .It Dv PT_SYSCALL
 Stops a process before and after executing each system call.
 Otherwise this operation is the same as
@@ -987,10 +996,3 @@ to
 .Fn ptrace
 .Ec ,
 should be able to sidestep this.
-.Pp
-.Dv PT_SET_SIGINFO ,
-.Dv PT_RESUME
-and
-.Dv PT_SUSPEND
-can change the image of process returned by
-.Dv PT_LWPINFO .



CVS commit: src/sys/kern

2020-01-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Jan  4 03:46:19 UTC 2020

Modified Files:
src/sys/kern: files.kern
Added Files:
src/sys/kern: sys_process_lwpstatus.c
Removed Files:
src/sys/kern: sys_ptrace_lwpstatus.c

Log Message:
Rename sys_ptrace_lwpstatus.c to sys_process_lwpstatus.c

Keep the names of functions internally as ptrace intact as this code
is shared with core_elf32.c that already reaches ptrace(2) specifc symbols.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/kern/files.kern
cvs rdiff -u -r0 -r1.1 src/sys/kern/sys_process_lwpstatus.c
cvs rdiff -u -r1.1 -r0 src/sys/kern/sys_ptrace_lwpstatus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/files.kern
diff -u src/sys/kern/files.kern:1.41 src/sys/kern/files.kern:1.42
--- src/sys/kern/files.kern:1.41	Thu Dec 26 08:52:38 2019
+++ src/sys/kern/files.kern	Sat Jan  4 03:46:19 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.kern,v 1.41 2019/12/26 08:52:38 kamil Exp $
+#	$NetBSD: files.kern,v 1.42 2020/01/04 03:46:19 kamil Exp $
 
 #
 # kernel sources
@@ -161,9 +161,9 @@ file	kern/sys_mqueue.c		mqueue
 file	kern/sys_lwp.c			kern
 file	kern/sys_pipe.c			!pipe_socketpair
 file	kern/sys_process.c		ptrace_hooks | ktrace
+file	kern/sys_process_lwpstatus.c	kern
 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

Added files:

Index: src/sys/kern/sys_process_lwpstatus.c
diff -u /dev/null src/sys/kern/sys_process_lwpstatus.c:1.1
--- /dev/null	Sat Jan  4 03:46:19 2020
+++ src/sys/kern/sys_process_lwpstatus.c	Sat Jan  4 03:46:19 2020
@@ -0,0 +1,69 @@
+/*	$NetBSD: sys_process_lwpstatus.c,v 1.1 2020/01/04 03:46:19 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 
+__KERNEL_RCSID(0, "$NetBSD: sys_process_lwpstatus.c,v 1.1 2020/01/04 03:46:19 kamil Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+void
+ptrace_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
+{
+
+	KASSERT(l->l_lid == pls->pl_lwpid);
+
+	memcpy(>pl_sigmask, >l_sigmask, sizeof(pls->pl_sigmask));
+	memcpy(>pl_sigpend, >l_sigpend.sp_set, sizeof(pls->pl_sigpend));
+
+	if (l->l_name == NULL)
+		memset(>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);
+}



CVS commit: src/sys/kern

2020-01-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Jan  3 00:37:30 UTC 2020

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Correct the rule to iterate over LWPs with PT_LWPNEXT and PT_LWPINFO

Correctly exclude dead/dying/zombie and system threads.

Fixes kern/54802 (gdb -p kills the kernel) by 


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.76 src/sys/kern/sys_ptrace_common.c:1.77
--- src/sys/kern/sys_ptrace_common.c:1.76	Thu Dec 26 08:52:38 2019
+++ src/sys/kern/sys_ptrace_common.c	Fri Jan  3 00:37:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.77 2020/01/03 00:37:29 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.76 2019/12/26 08:52:38 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.77 2020/01/03 00:37:29 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -757,7 +757,8 @@ ptrace_lwpinfo(struct proc *t, struct lw
 		*lt = LIST_NEXT(*lt, l_sibling);
 	}
 
-	while (*lt != NULL && !lwp_alive(*lt))
+	while (*lt != NULL && (!lwp_alive(*lt) ||
+	   ((*lt)->l_flag & LW_SYSTEM) != 0))
 		*lt = LIST_NEXT(*lt, l_sibling);
 
 	pl.pl_lwpid = 0;
@@ -822,8 +823,8 @@ ptrace_lwpstatus(struct proc *t, struct 
 			*lt = LIST_NEXT(*lt, l_sibling);
 		}
 
-		while (*lt != NULL && !lwp_alive(*lt) &&
-		   ((*lt)->l_flag & LW_SYSTEM) != 0)
+		while (*lt != NULL && (!lwp_alive(*lt) ||
+		   ((*lt)->l_flag & LW_SYSTEM) != 0))
 			*lt = LIST_NEXT(*lt, l_sibling);
 
 		if (*lt == NULL) {



CVS commit: src/sys/sys

2020-01-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jan  2 05:18:07 UTC 2020

Modified Files:
src/sys/sys: exec_elf.h

Log Message:
Sync the e_ident[EI_OSABI] magic values with the ELF specification

source: http://www.sco.com/developers/gabi/latest/ch4.eheader.html


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/sys/exec_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/exec_elf.h
diff -u src/sys/sys/exec_elf.h:1.163 src/sys/sys/exec_elf.h:1.164
--- src/sys/sys/exec_elf.h:1.163	Thu Jan  2 04:58:07 2020
+++ src/sys/sys/exec_elf.h	Thu Jan  2 05:18:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.h,v 1.163 2020/01/02 04:58:07 kamil Exp $	*/
+/*	$NetBSD: exec_elf.h,v 1.164 2020/01/02 05:18:07 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -169,11 +169,11 @@ typedef struct {
 #define ELFOSABI_SYSV		0	/* UNIX System V ABI */
 #define ELFOSABI_HPUX		1	/* HP-UX operating system */
 #define ELFOSABI_NETBSD		2	/* NetBSD */
-#define ELFOSABI_LINUX		3	/* GNU/Linux */
-#define ELFOSABI_HURD		4	/* GNU/Hurd */
-#define ELFOSABI_86OPEN		5	/* 86Open */
+#define ELFOSABI_GNU		3	/* GNU/Linux */
+#define ELFOSABI_HURD		4	/* GNU/Hurd - historical */
+#define ELFOSABI_86OPEN		5	/* 86Open - historical */
 #define ELFOSABI_SOLARIS	6	/* Solaris */
-#define ELFOSABI_MONTEREY	7	/* Monterey */
+#define ELFOSABI_AIX		7	/* AIX */
 #define ELFOSABI_IRIX		8	/* IRIX */
 #define ELFOSABI_FREEBSD	9	/* FreeBSD */
 #define ELFOSABI_TRU64		10	/* TRU64 UNIX */
@@ -182,12 +182,18 @@ typedef struct {
 #define ELFOSABI_OPENVMS	13	/* OpenVMS */
 #define ELFOSABI_NSK		14	/* HP Non-Stop Kernel */
 #define ELFOSABI_AROS		15	/* Amiga Research OS */
+#define ELFOSABI_FENIXOS	16	/* The FenixOS highly scalable multi-core OS */
+#define ELFOSABI_CLOUDABI	17	/* Nuxi CloudABI */
+#define ELFOSABI_OPENVOS	18	/* Stratus Technologies OpenVOS */
 /* Unofficial OSABIs follow */
 #define ELFOSABI_ARM		97	/* ARM */
 #define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
 
 #define ELFOSABI_NONE		ELFOSABI_SYSV
-#define ELFOSABI_AIX		ELFOSABI_MONTEREY
+
+/* Historical aliases. */
+#define ELFOSABI_LINUX		ELFOSABI_GNU
+#define ELFOSABI_MONTEREY	ELFOSABI_AIX
 
 /* e_type */
 #define ET_NONE		0	/* No file type */



CVS commit: src/sys/sys

2020-01-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jan  2 04:58:07 UTC 2020

Modified Files:
src/sys/sys: exec_elf.h

Log Message:
Update e_machine magic values with the ELF specification

source: http://www.sco.com/developers/gabi/latest/ch4.eheader.html


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/sys/exec_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/exec_elf.h
diff -u src/sys/sys/exec_elf.h:1.162 src/sys/sys/exec_elf.h:1.163
--- src/sys/sys/exec_elf.h:1.162	Thu Jan  2 04:28:51 2020
+++ src/sys/sys/exec_elf.h	Thu Jan  2 04:58:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.h,v 1.162 2020/01/02 04:28:51 kamil Exp $	*/
+/*	$NetBSD: exec_elf.h,v 1.163 2020/01/02 04:58:07 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -224,8 +224,9 @@ typedef struct {
 #define EM_960		19	/* Intel 80960 */
 #define EM_PPC		20	/* PowerPC */
 #define EM_PPC64	21	/* 64-bit PowerPC */
-			/* 22-35 - Reserved */
-#define EM_S390		22	/* System/390 XXX reserved */
+#define EM_S390		22	/* IBM System/390 Processor */
+#define EM_SPU		23	/* IBM SPU/SPC */
+			/* 24-35 - Reserved */
 #define EM_V800		36	/* NEC V800 */
 #define EM_FR20		37	/* Fujitsu FR20 */
 #define EM_RH32		38	/* TRW RH-32 */
@@ -302,14 +303,98 @@ typedef struct {
 #define EM_SEP		108	/* Sharp embedded microprocessor */
 #define EM_ARCA		109	/* Arca RISC microprocessor */
 #define EM_UNICORE	110	/* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
+#define EM_EXCESS	111	/* eXcess: 16/32/64-bit configurable embedded CPU */
+#define EM_DXP		112	/* Icera Semiconductor Inc. Deep Execution Processor */
 #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
+#define EM_CRX		114	/* National Semiconductor CompactRISC CRX microprocessor */
+#define EM_XGATE	115	/* Motorola XGATE embedded processor */
+#define EM_C166		116	/* Infineon C16x/XC16x processor */
+#define EM_M16C		117	/* Renesas M16C series microprocessors */
+#define EM_DSPIC30F	118	/* Microchip Technology dsPIC30F Digital Signal Controller */
+#define EM_CE		119	/* Freescale Communication Engine RISC core */
+#define EM_M32C		120	/* Renesas M32C series microprocessors */
+			/* 121-130 - Reserved */
+#define EM_TSK3000	131	/* Altium TSK3000 core */
+#define EM_RS08		132	/* Freescale RS08 embedded processor */
+#define EM_SHARC	133	/* Analog Devices SHARC family of 32-bit DSP processors */
+#define EM_ECOG2	134	/* Cyan Technology eCOG2 microprocessor */
+#define EM_SCORE7	135	/* Sunplus S+core7 RISC processor */
+#define EM_DSP24	136	/* New Japan Radio (NJR) 24-bit DSP Processor */
+#define EM_VIDEOCORE3	137	/* Broadcom VideoCore III processor */
+#define EM_LATTICEMICO32	138	/* RISC processor for Lattice FPGA architecture */
+#define EM_SE_C17	139	/* Seiko Epson C17 family */
+#define EM_TI_C6000	140	/* The Texas Instruments TMS320C6000 DSP family */
+#define EM_TI_C2000	141	/* The Texas Instruments TMS320C2000 DSP family */
+#define EM_TI_C5500	142	/* The Texas Instruments TMS320C55x DSP family */
+#define EM_TI_ARP32	143	/* Texas Instruments Application Specific RISC Processor, 32bit fetch */
+#define EM_TI_PRU	144	/* Texas Instruments Programmable Realtime Unit */
+			/* 145-159 - Reserved */
+#define EM_MMDSP_PLUS	160	/* STMicroelectronics 64bit VLIW Data Signal Processor */
+#define EM_CYPRESS_M8C	161	/* Cypress M8C microprocessor */
+#define EM_R32C		162	/* Renesas R32C series microprocessors */
+#define EM_TRIMEDIA	163	/* NXP Semiconductors TriMedia architecture family */
+#define EM_QDSP6	164	/* QUALCOMM DSP6 Processor */
+#define EM_8051		165	/* Intel 8051 and variants */
+#define EM_STXP7X	166	/* STMicroelectronics STxP7x family of configurable and extensible RISC processors */
+#define EM_NDS32	167	/* Andes Technology compact code size embedded RISC processor family */
+#define EM_ECOG1	168	/* Cyan Technology eCOG1X family */
+#define EM_ECOG1X	168	/* Cyan Technology eCOG1X family */
+#define EM_MAXQ30	169	/* Dallas Semiconductor MAXQ30 Core Micro-controllers */
+#define EM_XIMO16	170	/* New Japan Radio (NJR) 16-bit DSP Processor */
+#define EM_MANIK	171	/* M2000 Reconfigurable RISC Microprocessor */
+#define EM_CRAYNV2	172	/* Cray Inc. NV2 vector architecture */
+#define EM_RX		173	/* Renesas RX family */
+#define EM_METAG	174	/* Imagination Technologies META processor architecture */
+#define EM_MCST_ELBRUS	175	/* MCST Elbrus general purpose hardware architecture */
+#define EM_ECOG16	176	/* Cyan Technology eCOG16 family */
+#define EM_CR16		177	/* National Semiconductor CompactRISC CR16 16-bit microprocessor */
+#define EM_ETPU		178	/* Freescale Extended Time Processing Unit */
+#define EM_SLE9X	179	/* Infineon Technologies SLE9X core */
+#define EM_L10M		180	/* Intel L10M */
+#define EM_K10M		181	/* Intel K10M */
+			/* 182 - Reserved */
 #define EM_AARCH64	183	/* AArch64 64-bit ARM 

CVS commit: src/sys/sys

2020-01-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jan  2 04:28:51 UTC 2020

Modified Files:
src/sys/sys: exec_elf.h

Log Message:
Fix the EM_TILEGX number in the ELF header

source: http://www.sco.com/developers/gabi/latest/ch4.eheader.html

191 is confirmed in LLVM, GNU toolchain, FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/sys/exec_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/exec_elf.h
diff -u src/sys/sys/exec_elf.h:1.161 src/sys/sys/exec_elf.h:1.162
--- src/sys/sys/exec_elf.h:1.161	Fri Jun  7 23:35:52 2019
+++ src/sys/sys/exec_elf.h	Thu Jan  2 04:28:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.h,v 1.161 2019/06/07 23:35:52 christos Exp $	*/
+/*	$NetBSD: exec_elf.h,v 1.162 2020/01/02 04:28:51 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -308,7 +308,7 @@ typedef struct {
 #define EM_TILE64	187	/* Tilera TILE64 multicore architecture family */
 #define EM_TILEPRO	188	/* Tilera TILEPro multicore architecture family */
 #define EM_MICROBLAZE	189	/* Xilinx MicroBlaze 32-bit RISC soft processor core */
-#define EM_TILEGX	192	/* Tilera TILE-GX multicore architecture family */
+#define EM_TILEGX	191	/* Tilera TILE-GX multicore architecture family */
 #define EM_Z80		220	/* Zilog Z80 */
 #define EM_RISCV	243	/* RISC-V */
 



CVS commit: src/doc

2019-12-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Dec 28 04:23:26 UTC 2019

Modified Files:
src/doc: TODO.sanitizers

Log Message:
Sync TODO.sanitizers with reality

Done:
 - compiler-rt sanitizers integration with base
 - merge TSan, MSan and libFuzzer ATF tests
 - LSan
 - finish the research of a new syscall for StopTheWorld() operation
   ptrace(2) style for self-introspection and debugging (LSan)
 - attach a NetBSD buildbot testing build of compiler-rt and executing tests
 - kernel-msan https://github.com/google/kmsan


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/doc/TODO.sanitizers

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/TODO.sanitizers
diff -u src/doc/TODO.sanitizers:1.11 src/doc/TODO.sanitizers:1.12
--- src/doc/TODO.sanitizers:1.11	Sun Mar 10 12:59:03 2019
+++ src/doc/TODO.sanitizers	Sat Dec 28 04:23:26 2019
@@ -1,8 +1,6 @@
 Sanitizer and related tasks.
 
 Short term:
- - compiler-rt sanitizers integration with base
- - merge TSan, MSan and libFuzzer ATF tests
  - prepare MKSANITIZER readme
 
 Long term:
@@ -12,20 +10,16 @@ Long term:
  - improve the framework for ioctl(2) database and handle special cases when a
part of a struct can be uninitialized and passed to the kernel (MSan)
  - port or finish the port of:
-   * LSan,
* shadowcallstack,
* cfi,
* scudo,
* DFSan.
- - finish the research of a new syscall for StopTheWorld() operation
-   ptrace(2) style for self-introspection and debugging (LSan)
  - port HWASan -- aarch64 specific, needs hardware or emulator
  - make MKSANITIZER usable with any supported by a compiler combination of
sanitizers
  - pkgsrc integration with sanitizers and MKSANITIZER (PKGSANITIZER?)
  - port what possible to !amd64
  - fixes with the signal code
- - attach a NetBSD buildbot testing build of compiler-rt and executing tests
  - make compiler-rt buildable with GCC
  - finish the support of float128 for Clang/LLVM/libstdc++/libgcc
  - merge of the libFuzzer integration with the basesystem
@@ -36,7 +30,6 @@ Long term:
 
 
 Unspecified:
- - kernel-msan https://github.com/google/kmsan
  - kernel-tsan? upstream development is stalled with patches for Linux 4.2
https://github.com/google/ktsan
  - kernel-safestack? implemented in Fuchsia/Magenta



CVS commit: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common

2019-12-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec 27 00:35:05 UTC 2019

Modified Files:
src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common:
sanitizer_linux_libcdep.cc

Log Message:
Cherry-pick LLVM upstream patch to fix build of compiler-rt

commit 52b5fe5f45b1908e140e05a4eceaaac7002be768
Author: Kamil Rytarowski 
Date:   Wed Dec 25 04:05:10 2019 +0100

[compiler-rt] [netbsd] Define _RTLD_SOURCE to fix build

The TLS base (LWP private pointer) functions are namespaced and
hidden i.e. inside the _RTLD_SOURCE namespace.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc:1.1.1.1 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc:1.2
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc:1.1.1.1	Tue Jan  8 05:40:29 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_linux_libcdep.cc	Fri Dec 27 00:35:05 2019
@@ -28,6 +28,10 @@
 #include "sanitizer_placement_new.h"
 #include "sanitizer_procmaps.h"
 
+#if SANITIZER_NETBSD
+#define _RTLD_SOURCE  // Fast LWP private pointer getters in ThreadSelfTlsTcb().
+#endif
+
 #include   // for dlsym()
 #include 
 #include 



CVS commit: src/sys/arch

2019-12-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec 27 00:32:17 UTC 2019

Modified Files:
src/sys/arch/alpha/include: mcontext.h
src/sys/arch/amd64/include: mcontext.h
src/sys/arch/hppa/include: mcontext.h
src/sys/arch/i386/include: mcontext.h
src/sys/arch/ia64/include: mcontext.h
src/sys/arch/sh3/include: mcontext.h
src/sys/arch/sparc/include: mcontext.h
src/sys/arch/vax/include: mcontext.h

Log Message:
Harmonize the namespace of fast TLS base pointer getter functions

Protect __lwp_getprivate_fast() with _RTLD_SOURCE, _LIBC_SOURCE and
__LIBPTHREAD_SOURCE__.

Include in this namespace  and use __BEGIN_DECLS/__END_DECLS
for the sake of consistency.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/alpha/include/mcontext.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/amd64/include/mcontext.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/hppa/include/mcontext.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/i386/include/mcontext.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/ia64/include/mcontext.h
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/sh3/include/mcontext.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/sparc/include/mcontext.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/vax/include/mcontext.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/include/mcontext.h
diff -u src/sys/arch/alpha/include/mcontext.h:1.9 src/sys/arch/alpha/include/mcontext.h:1.10
--- src/sys/arch/alpha/include/mcontext.h:1.9	Thu Feb 15 15:53:56 2018
+++ src/sys/arch/alpha/include/mcontext.h	Fri Dec 27 00:32:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.9 2018/02/15 15:53:56 kamil Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.10 2019/12/27 00:32:16 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -102,6 +102,11 @@ typedef struct {
 
 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
 
+#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
+defined(__LIBPTHREAD_SOURCE__)
+#include 
+
+__BEGIN_DECLS
 static __inline void *
 __lwp_getprivate_fast(void)
 {
@@ -113,5 +118,8 @@ __lwp_getprivate_fast(void)
 
 	return __tmp;
 }
+__END_DECLS
+
+#endif
 
 #endif	/* !_ALPHA_MCONTEXT_H_ */

Index: src/sys/arch/amd64/include/mcontext.h
diff -u src/sys/arch/amd64/include/mcontext.h:1.19 src/sys/arch/amd64/include/mcontext.h:1.20
--- src/sys/arch/amd64/include/mcontext.h:1.19	Thu Feb 15 15:53:56 2018
+++ src/sys/arch/amd64/include/mcontext.h	Fri Dec 27 00:32:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.19 2018/02/15 15:53:56 kamil Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.20 2019/12/27 00:32:16 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -84,6 +84,11 @@ typedef struct {
 
 #define	__UCONTEXT_SIZE	784
 
+#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
+defined(__LIBPTHREAD_SOURCE__)
+#include 
+
+__BEGIN_DECLS
 static __inline void *
 __lwp_getprivate_fast(void)
 {
@@ -93,6 +98,9 @@ __lwp_getprivate_fast(void)
 
 	return __tmp;
 }
+__END_DECLS
+
+#endif
 
 #ifdef _KERNEL
 

Index: src/sys/arch/hppa/include/mcontext.h
diff -u src/sys/arch/hppa/include/mcontext.h:1.10 src/sys/arch/hppa/include/mcontext.h:1.11
--- src/sys/arch/hppa/include/mcontext.h:1.10	Tue Feb 27 11:26:39 2018
+++ src/sys/arch/hppa/include/mcontext.h	Fri Dec 27 00:32:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.10 2018/02/27 11:26:39 kamil Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.11 2019/12/27 00:32:17 kamil Exp $	*/
 
 #ifndef _HPPA_MCONTEXT_H_
 #define	_HPPA_MCONTEXT_H_
@@ -59,6 +59,11 @@ do {	\
 } while (/*CONSTCOND*/0)
 #define	_UC_MACHINE_INTRV(uc) 	((uc)->uc_mcontext.__gregs[_REG_RET0])
 
+#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
+defined(__LIBPTHREAD_SOURCE__)
+#include 
+
+__BEGIN_DECLS
 static __inline void *
 __lwp_getprivate_fast(void)
 {
@@ -68,6 +73,9 @@ __lwp_getprivate_fast(void)
 
 	return __tmp;
 }
+__END_DECLS
+
+#endif
 
 #endif /* !__ASSEMBLER__ */
 

Index: src/sys/arch/i386/include/mcontext.h
diff -u src/sys/arch/i386/include/mcontext.h:1.14 src/sys/arch/i386/include/mcontext.h:1.15
--- src/sys/arch/i386/include/mcontext.h:1.14	Thu Feb 15 15:53:56 2018
+++ src/sys/arch/i386/include/mcontext.h	Fri Dec 27 00:32:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcontext.h,v 1.14 2018/02/15 15:53:56 kamil Exp $	*/
+/*	$NetBSD: mcontext.h,v 1.15 2019/12/27 00:32:17 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -113,6 +113,11 @@ typedef struct {
 
 #define	__UCONTEXT_SIZE	776
 
+#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
+defined(__LIBPTHREAD_SOURCE__)
+#include 
+
+__BEGIN_DECLS
 static __inline void *
 __lwp_getprivate_fast(void)
 {
@@ -122,5 +127,8 @@ __lwp_getprivate_fast(void)
 
 	return __tmp;
 }
+__END_DECLS
+
+#endif
 
 #endif	/* !_I386_MCONTEXT_H_ */

Index: src/sys/arch/ia64/include/mcontext.h
diff -u 

CVS commit: src/sys

2019-12-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 26 08:52:39 UTC 2019

Modified Files:
src/sys/kern: files.kern sys_ptrace_common.c
src/sys/sys: ptrace.h
Added Files:
src/sys/kern: sys_ptrace_lwpstatus.c

Log Message:
Put ptrace_read_lwpstatus() and process_read_lwpstatus() to a new file

Fixes "no PTRACE" kernel build, in particular zaurus kernel=INSTALL_C700.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/kern/files.kern
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/sys_ptrace_common.c
cvs rdiff -u -r0 -r1.1 src/sys/kern/sys_ptrace_lwpstatus.c
cvs rdiff -u -r1.68 -r1.69 src/sys/sys/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/files.kern
diff -u src/sys/kern/files.kern:1.40 src/sys/kern/files.kern:1.41
--- src/sys/kern/files.kern:1.40	Fri Dec 20 21:20:09 2019
+++ src/sys/kern/files.kern	Thu Dec 26 08:52:38 2019
@@ -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

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.75 src/sys/kern/sys_ptrace_common.c:1.76
--- src/sys/kern/sys_ptrace_common.c:1.75	Wed Dec 25 15:54:02 2019
+++ src/sys/kern/sys_ptrace_common.c	Thu Dec 26 08:52:38 2019
@@ -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 
-__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 lw
 	return copyout(, addr, sizeof(pl));
 }
 
-static void
-ptrace_read_lwpstatus(struct lwp *l, struct ptrace_lwpstatus *pls)
-{
-
-	KASSERT(l->l_lid == pls->pl_lwpid);
-
-	memcpy(>pl_sigmask, >l_sigmask, sizeof(pls->pl_sigmask));
-	memcpy(>pl_sigpend, >l_sigpend.sp_set, sizeof(pls->pl_sigpend));
-
-	if (l->l_name == NULL)
-		memset(>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)

Index: src/sys/sys/ptrace.h
diff -u src/sys/sys/ptrace.h:1.68 src/sys/sys/ptrace.h:1.69
--- src/sys/sys/ptrace.h:1.68	Tue Dec 24 14:50:59 2019
+++ src/sys/sys/ptrace.h	Thu Dec 26 08:52:38 2019
@@ -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 *, st
 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

Added files:

Index: src/sys/kern/sys_ptrace_lwpstatus.c
diff -u /dev/null src/sys/kern/sys_ptrace_lwpstatus.c:1.1
--- /dev/null	Thu Dec 26 08:52:39 2019
+++ src/sys/kern/sys_ptrace_lwpstatus.c	Thu Dec 26 08:52:38 2019
@@ -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, 

CVS commit: src/sys/kern

2019-12-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec 25 15:54:02 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Cast PTRACE_LWP_GETPRIVATE to (void *) through (intptr_t)

Fixes sparc build.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.74 src/sys/kern/sys_ptrace_common.c:1.75
--- src/sys/kern/sys_ptrace_common.c:1.74	Tue Dec 24 14:50:59 2019
+++ src/sys/kern/sys_ptrace_common.c	Wed Dec 25 15:54:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.74 2019/12/24 14:50:59 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.75 2019/12/25 15:54:02 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.74 2019/12/24 14:50:59 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.75 2019/12/25 15:54:02 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -807,7 +807,7 @@ ptrace_read_lwpstatus(struct lwp *l, str
 	}
 
 #ifdef PTRACE_LWP_GETPRIVATE
-	pls->pl_private = PTRACE_LWP_GETPRIVATE(l);
+	pls->pl_private = (void *)(intptr_t)PTRACE_LWP_GETPRIVATE(l);
 #else
 	pls->pl_private = l->l_private;
 #endif



CVS commit: src/tests/lib/libc/sys

2019-12-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec 25 02:23:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Read TLS base pointer with _lwp_getprivate()

This avoid usage of fast versions that are mostly internal to RTLD.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.144 src/tests/lib/libc/sys/t_ptrace_wait.c:1.145
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.144	Tue Dec 24 21:09:38 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed Dec 25 02:23:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.144 2019/12/24 21:09:38 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,10 +27,9 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.144 2019/12/24 21:09:38 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $");
 
 #define __LEGACY_PT_LWPINFO
-#define _RTLD_SOURCE
 
 #include 
 #include 
@@ -4804,19 +4803,6 @@ PTRACE_KILL(kill3, "killpg(SIGKILL)")
 
 /// 
 
-static void *
-get_private(void)
-{
-
-#ifdef __HAVE___LWP_GETTCB_FAST
-	return __lwp_gettcb_fast();
-#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
-	return __lwp_getprivate_fast();
-#else
-#error Unknown code path!
-#endif
-}
-
 static int lwpinfo_thread_sigmask[] = {SIGXCPU, SIGPIPE, SIGALRM, SIGURG};
 
 static pthread_mutex_t lwpinfo_thread_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -4831,7 +4817,7 @@ lwpinfo_thread(void *arg)
 
 	tcb = (volatile void **)arg;
 
-	*tcb = get_private();
+	*tcb = _lwp_getprivate();
 	DPRINTF("Storing tcb[] = %p from thread %d\n", *tcb, _lwp_self());
 
 	pthread_setname_np(pthread_self(), "thread %d",
@@ -4885,7 +4871,7 @@ traceme_lwpinfo(const size_t threads, co
 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
 
-		tcb[0] = get_private();
+		tcb[0] = _lwp_getprivate();
 		DPRINTF("Storing tcb[0] = %p\n", tcb[0]);
 
 		pthread_setname_np(pthread_self(), "thread %d",



CVS commit: src/tests/lib/libc/sys

2019-12-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 24 21:09:38 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Define _RTLD_SOURCE in t_ptrace_wait.c

The __lwp_gettcb_fast() and __lwp_getprivate_fast() functions are
namespaced on a selection of ports.


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.143 src/tests/lib/libc/sys/t_ptrace_wait.c:1.144
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.143	Tue Dec 24 14:50:59 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Dec 24 21:09:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.143 2019/12/24 14:50:59 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.144 2019/12/24 21:09:38 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,9 +27,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.143 2019/12/24 14:50:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.144 2019/12/24 21:09:38 kamil Exp $");
 
 #define __LEGACY_PT_LWPINFO
+#define _RTLD_SOURCE
 
 #include 
 #include 



CVS commit: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common

2019-12-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 24 19:51:00 UTC 2019

Modified Files:
src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common:
sanitizer_platform_limits_netbsd.cc
sanitizer_platform_limits_netbsd.h sanitizer_syscalls_netbsd.inc

Log Message:
Fix compiler-rt sanitizer build with >= 9.99.30

Cherry-pick (patched):
[compiler-rt] Adapt for ptrace(2) changes in NetBSD-9.99.30

Enable compat support for now legacy PT_LWPINFO.
Support PT_LWPSTATUS and PT_LWPNEXT.

https://github.com/llvm/llvm-project/commit/4b8232d4f0bf5fd9f11ebef2b0f9e8e15f130fb3


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
cvs rdiff -u -r1.1.1.1 -r1.2 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.3 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.4
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.3	Wed Dec 18 14:51:24 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc	Tue Dec 24 19:51:00 2019
@@ -18,6 +18,7 @@
 
 #define _KMEMUSER
 #define RAY_DO_SIGLEV
+#define __LEGACY_PT_LWPINFO
 
 // clang-format off
 #include 
@@ -72,6 +73,15 @@
 #include 
 #include 
 #include 
+
+// Compat for NetBSD < 9.99.30.
+#ifndef PT_LWPSTATUS
+#define PT_LWPSTATUS 24
+#endif
+#ifndef PT_LWPSTATUS
+#define PT_LWPSTATUS 25
+#endif
+
 #include 
 #include 
 #include 
@@ -292,6 +302,8 @@ int ptrace_pt_get_event_mask = PT_GET_EV
 int ptrace_pt_get_process_state = PT_GET_PROCESS_STATE;
 int ptrace_pt_set_siginfo = PT_SET_SIGINFO;
 int ptrace_pt_get_siginfo = PT_GET_SIGINFO;
+int ptrace_pt_lwpstatus = PT_LWPSTATUS;
+int ptrace_pt_lwpnext = PT_LWPNEXT;
 int ptrace_piod_read_d = PIOD_READ_D;
 int ptrace_piod_write_d = PIOD_WRITE_D;
 int ptrace_piod_read_i = PIOD_READ_I;
@@ -324,6 +336,8 @@ int ptrace_pt_getdbregs = -1;
 
 unsigned struct_ptrace_ptrace_io_desc_struct_sz = sizeof(struct ptrace_io_desc);
 unsigned struct_ptrace_ptrace_lwpinfo_struct_sz = sizeof(struct ptrace_lwpinfo);
+unsigned struct_ptrace_ptrace_lwpstatus_struct_sz =
+sizeof(struct __sanitizer_ptrace_lwpstatus);
 unsigned struct_ptrace_ptrace_event_struct_sz = sizeof(ptrace_event_t);
 unsigned struct_ptrace_ptrace_siginfo_struct_sz = sizeof(ptrace_siginfo_t);
 
Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h:1.3 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h:1.4
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h:1.3	Wed Dec 18 14:51:24 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h	Tue Dec 24 19:51:00 2019
@@ -407,6 +407,8 @@ extern int ptrace_pt_get_event_mask;
 extern int ptrace_pt_get_process_state;
 extern int ptrace_pt_set_siginfo;
 extern int ptrace_pt_get_siginfo;
+extern int ptrace_pt_lwpstatus;
+extern int ptrace_pt_lwpnext;
 extern int ptrace_piod_read_d;
 extern int ptrace_piod_write_d;
 extern int ptrace_piod_read_i;
@@ -431,8 +433,17 @@ struct __sanitizer_ptrace_lwpinfo {
   int pl_event;
 };
 
+struct __sanitizer_ptrace_lwpstatus {
+  __sanitizer_lwpid_t pl_lwpid;
+  __sanitizer_sigset_t pl_sigpend;
+  __sanitizer_sigset_t pl_sigmask;
+  char pl_name[20];
+  void *pl_private;
+};
+
 extern unsigned struct_ptrace_ptrace_io_desc_struct_sz;
 extern unsigned struct_ptrace_ptrace_lwpinfo_struct_sz;
+extern unsigned struct_ptrace_ptrace_lwpstatus_struct_sz;
 extern unsigned struct_ptrace_ptrace_event_struct_sz;
 extern unsigned struct_ptrace_ptrace_siginfo_struct_sz;
 

Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc:1.1.1.1 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc:1.2
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc:1.1.1.1	Tue Jan  8 05:40:30 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_syscalls_netbsd.inc	Tue Dec 24 19:51:00 2019
@@ -324,6 +324,16 @@ PRE_SYSCALL(ptrace)
 PRE_READ(addr_, 

CVS commit: src/sys/sys

2019-12-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 24 15:20:34 UTC 2019

Modified Files:
src/sys/sys: param.h

Log Message:
Welcome to NetBSD 9.99.30!

Addition of PT_LWPSTATUS, PT_LWPNEXT with compat32 and core(5) support.


To generate a diff of this commit:
cvs rdiff -u -r1.630 -r1.631 src/sys/sys/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.630 src/sys/sys/param.h:1.631
--- src/sys/sys/param.h:1.630	Sun Dec 22 22:24:37 2019
+++ src/sys/sys/param.h	Tue Dec 24 15:20:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.630 2019/12/22 22:24:37 ad Exp $	*/
+/*	$NetBSD: param.h,v 1.631 2019/12/24 15:20:34 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999002900	/* NetBSD 9.99.29 */
+#define	__NetBSD_Version__	999003000	/* NetBSD 9.99.30 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src

2019-12-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Dec 24 14:51:00 UTC 2019

Modified Files:
src/external/gpl3/gdb/dist/gdb: nbsd-nat.c
src/sys/arch/alpha/include: ptrace.h
src/sys/arch/hppa/include: ptrace.h
src/sys/arch/powerpc/include: ptrace.h
src/sys/arch/sh3/include: ptrace.h
src/sys/arch/sparc/include: ptrace.h
src/sys/compat/netbsd32: netbsd32.h netbsd32_ptrace.c
src/sys/kern: core_elf32.c sys_ptrace.c sys_ptrace_common.c
src/sys/sys: ptrace.h
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Introduce PT_LWPSTATUS + PT_LWPNEXT, obsolete PT_LWPINFO

PT_LWPINFO is a legacy ptrace(2) operation that was originally intended
to retrieve the thread (LWP) information inside a traced process.

It has a number of flaws and is confused with PT_LWPINFO from FreeBSD.

PT_LWPSTATUS and PT_LWPNEXT address the problems (shortly by: rename,
removal of pl_event) and introduces new features: signal context
(pl_sigpend, pl_sigmask), LWP name (pl_name), LWP TLS base address
(pl_private). The private pointer was so far missing information for
a debugger.

PT_LWPSTATUS@nnn is now shipped with core(5) files and contain LWP specific
information, so far missed in the core(5) files.

PT_LWPSTATUS retrieves LWP information for the prompted thread.
PT_LWPNEXT retrieves LWP information for the next thread, borrowing the
semantics from NetBSD specific PT_LWPINFO.

PT_LWPINFO is namespaced with __LEGACY_PT_LWPINFO and still available for
the foreseeable future, without plans of removing it.

Add ATF tests for PT_LWPSTATUS + PT_LWPNEXT.

Keep ATF tests for PT_LWPINFO.

Switch GDB to new API.

Proposed on tech-kern@.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/alpha/include/ptrace.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/hppa/include/ptrace.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/powerpc/include/ptrace.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/sh3/include/ptrace.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/sparc/include/ptrace.h
cvs rdiff -u -r1.131 -r1.132 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.7 -r1.8 src/sys/compat/netbsd32/netbsd32_ptrace.c
cvs rdiff -u -r1.60 -r1.61 src/sys/kern/core_elf32.c
cvs rdiff -u -r1.5 -r1.6 src/sys/kern/sys_ptrace.c
cvs rdiff -u -r1.73 -r1.74 src/sys/kern/sys_ptrace_common.c
cvs rdiff -u -r1.67 -r1.68 src/sys/sys/ptrace.h
cvs rdiff -u -r1.142 -r1.143 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.13 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.14
--- src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.13	Sun Jul 14 18:50:58 2019
+++ src/external/gpl3/gdb/dist/gdb/nbsd-nat.c	Tue Dec 24 14:51:00 2019
@@ -145,10 +145,10 @@ nbsd_nat_target::thread_alive (ptid_t pt
 {
   if (ptid.lwp_p ())
 {
-  struct ptrace_lwpinfo pl;
+  struct ptrace_lwpstatus pl;
 
   pl.pl_lwpid = ptid.lwp ();
-  if (ptrace (PT_LWPINFO, ptid.pid (), (caddr_t) , sizeof pl)
+  if (ptrace (PT_LWPSTATUS, ptid.pid (), (caddr_t) , sizeof pl)
 	  == -1)
 	return 0;
 }
@@ -255,10 +255,10 @@ static void
 nbsd_add_threads (pid_t pid)
 {
   int val;
-  struct ptrace_lwpinfo pl;
+  struct ptrace_lwpstatus pl;
 
   pl.pl_lwpid = 0;
-  while ((val = ptrace (PT_LWPINFO, pid, (void *), sizeof(pl))) != -1
+  while ((val = ptrace (PT_LWPNEXT, pid, (void *), sizeof(pl))) != -1
 && pl.pl_lwpid != 0)
 {
   ptid_t ptid = ptid_t (pid, pl.pl_lwpid, 0);

Index: src/sys/arch/alpha/include/ptrace.h
diff -u src/sys/arch/alpha/include/ptrace.h:1.10 src/sys/arch/alpha/include/ptrace.h:1.11
--- src/sys/arch/alpha/include/ptrace.h:1.10	Tue Jun 18 21:18:11 2019
+++ src/sys/arch/alpha/include/ptrace.h	Tue Dec 24 14:50:59 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.10 2019/06/18 21:18:11 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.11 2019/12/24 14:50:59 kamil Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -56,3 +56,7 @@
 #define PTRACE_BREAKPOINT	((const uint8_t[]) { 0x80, 0x00, 0x00, 0x00 })
 #define PTRACE_BREAKPOINT_ASM	__asm __volatile("bpt" ::: "memory")
 #define PTRACE_BREAKPOINT_SIZE	4
+
+#ifdef _KERNEL
+#define PTRACE_LWP_GETPRIVATE(l) ((struct pcb *)lwp_getpcb(l))->pcb_hw.apcb_unique
+#endif

Index: src/sys/arch/hppa/include/ptrace.h
diff -u src/sys/arch/hppa/include/ptrace.h:1.9 src/sys/arch/hppa/include/ptrace.h:1.10
--- src/sys/arch/hppa/include/ptrace.h:1.9	Tue Jun 18 21:18:12 2019
+++ src/sys/arch/hppa/include/ptrace.h	Tue Dec 24 14:50:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.9 2019/06/18 21:18:12 kamil Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.10 2019/12/24 14:50:59 kamil Exp $	*/
 
 /*	$OpenBSD: ptrace.h,v 1.2 1998/12/01 03:05:44 mickey Exp $	*/
 
@@ -61,3 +61,7 @@
 #define 

CVS commit: src/lib/libc/sys

2019-12-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Dec 23 01:46:09 UTC 2019

Modified Files:
src/lib/libc/sys: kqueue.2

Log Message:
Explain in kevent(2) the semantics of EINTR

All changes contained in the changelist are applied before returning this
error.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/lib/libc/sys/kqueue.2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/kqueue.2
diff -u src/lib/libc/sys/kqueue.2:1.49 src/lib/libc/sys/kqueue.2:1.50
--- src/lib/libc/sys/kqueue.2:1.49	Sun Dec 22 17:01:15 2019
+++ src/lib/libc/sys/kqueue.2	Mon Dec 23 01:46:09 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: kqueue.2,v 1.49 2019/12/22 17:01:15 kamil Exp $
+.\"	$NetBSD: kqueue.2,v 1.50 2019/12/23 01:46:09 kamil Exp $
 .\"
 .\" Copyright (c) 2000 Jonathan Lemon
 .\" All rights reserved.
@@ -621,6 +621,9 @@ structure.
 .It Bq Er EINTR
 A signal was delivered before the timeout expired and before any
 events were placed on the kqueue for return.
+All changes contained in the
+.Fa changelist
+are applied before returning this error.
 .It Bq Er EINVAL
 The specified time limit or filter is invalid.
 .It Bq Er ENOENT



CVS commit: src/lib/libc/sys

2019-12-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Dec 22 17:01:15 UTC 2019

Modified Files:
src/lib/libc/sys: kqueue.2

Log Message:
Document udata type switch in struct kevent in the kqueue(2)


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/lib/libc/sys/kqueue.2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/kqueue.2
diff -u src/lib/libc/sys/kqueue.2:1.48 src/lib/libc/sys/kqueue.2:1.49
--- src/lib/libc/sys/kqueue.2:1.48	Fri Apr 12 10:57:27 2019
+++ src/lib/libc/sys/kqueue.2	Sun Dec 22 17:01:15 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: kqueue.2,v 1.48 2019/04/12 10:57:27 abhinav Exp $
+.\"	$NetBSD: kqueue.2,v 1.49 2019/12/22 17:01:15 kamil Exp $
 .\"
 .\" Copyright (c) 2000 Jonathan Lemon
 .\" All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $
 .\"
-.Dd January 8, 2018
+.Dd December 22, 2019
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -168,7 +168,7 @@ struct kevent {
 	uint32_t  flags;	/* action flags for kqueue */
 	uint32_t  fflags;	/* filter flag value */
 	int64_t   data;		/* filter data value */
-	intptr_t  udata;	/* opaque user data identifier */
+	void *udata;	/* opaque user data identifier */
 };
 .Ed
 .Pp
@@ -677,3 +677,8 @@ The
 .Fn EV_SET
 macro was protected from evaluating multiple times the first argument in
 .Nx 8.0 .
+.Pp
+The
+.Va udata
+type was changed from intptr_t to void * in
+.Nx 10.0 .



CVS commit: src/sys/dev/sdmmc

2019-12-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 19 17:24:45 UTC 2019

Modified Files:
src/sys/dev/sdmmc: sdmmc_ioreg.h

Log Message:
Avoid changing signedness bit with << in sdmmc_ioreg.h

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/sdmmc/sdmmc_ioreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdmmc_ioreg.h
diff -u src/sys/dev/sdmmc/sdmmc_ioreg.h:1.5 src/sys/dev/sdmmc/sdmmc_ioreg.h:1.6
--- src/sys/dev/sdmmc/sdmmc_ioreg.h:1.5	Mon Oct 28 06:26:19 2019
+++ src/sys/dev/sdmmc/sdmmc_ioreg.h	Thu Dec 19 17:24:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdmmc_ioreg.h,v 1.5 2019/10/28 06:26:19 mlelstv Exp $	*/
+/*	$NetBSD: sdmmc_ioreg.h,v 1.6 2019/12/19 17:24:45 kamil Exp $	*/
 /*	$OpenBSD: sdmmc_ioreg.h,v 1.4 2007/06/02 01:48:37 uwe Exp $	*/
 
 /*
@@ -39,7 +39,7 @@
 
 /* CMD53 arguments */
 #define SD_ARG_CMD53_READ		(0<<31)
-#define SD_ARG_CMD53_WRITE		(1<<31)
+#define SD_ARG_CMD53_WRITE		(1U<<31)
 #define SD_ARG_CMD53_FUNC_SHIFT		28
 #define SD_ARG_CMD53_FUNC_MASK		0x7
 #define SD_ARG_CMD53_BLOCK_MODE		(1<<27)
@@ -55,7 +55,7 @@
 #define MMC_R5(resp)			((resp)[0])
 
 /* SD R4 response (IO OCR) */
-#define SD_IO_OCR_MEM_READY		(1<<31)
+#define SD_IO_OCR_MEM_READY		(1U<<31)
 #define SD_IO_OCR_NUM_FUNCTIONS(ocr)	(((ocr) >> 28) & 0x7)
 #define SD_IO_OCR_MEM_PRESENT		(1<<27)
 #define SD_IO_OCR_MASK			0x00f0



CVS commit: src/sys/net80211

2019-12-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 19 16:29:51 UTC 2019

Modified Files:
src/sys/net80211: ieee80211_crypto_tkip.c

Log Message:
Avoid changing signedness bit with << 24 in ieee80211_crypto_tkip.c

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net80211/ieee80211_crypto_tkip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_crypto_tkip.c
diff -u src/sys/net80211/ieee80211_crypto_tkip.c:1.15 src/sys/net80211/ieee80211_crypto_tkip.c:1.16
--- src/sys/net80211/ieee80211_crypto_tkip.c:1.15	Mon Sep  3 16:29:36 2018
+++ src/sys/net80211/ieee80211_crypto_tkip.c	Thu Dec 19 16:29:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.15 2018/09/03 16:29:36 riastradh Exp $	*/
+/*	$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $	*/
 
 /*
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.15 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.16 2019/12/19 16:29:50 kamil Exp $");
 #endif
 
 /*
@@ -231,7 +231,7 @@ tkip_enmic(struct ieee80211_key *k, stru
 static __inline uint64_t
 READ_6(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5)
 {
-	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);
+	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | ((u32)b3 << 24);
 	uint16_t iv16 = (b4 << 0) | (b5 << 8);
 	return (((uint64_t)iv16) << 32) | iv32;
 }
@@ -733,7 +733,7 @@ do {\
 
 static __inline u32 get_le32_split(u8 b0, u8 b1, u8 b2, u8 b3)
 {
-	return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
+	return b0 | (b1 << 8) | (b2 << 16) | ((u32)b3 << 24);
 }
 
 static __inline u32 get_le32(const u8 *p)



CVS commit: src/sys/dev/ic

2019-12-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec 19 16:25:13 UTC 2019

Modified Files:
src/sys/dev/ic: rtsx.c

Log Message:
Avoid changing signedness bit with << in rtsx_read_cfg()

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/ic/rtsx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/rtsx.c
diff -u src/sys/dev/ic/rtsx.c:1.3 src/sys/dev/ic/rtsx.c:1.4
--- src/sys/dev/ic/rtsx.c:1.3	Tue Apr 24 18:34:30 2018
+++ src/sys/dev/ic/rtsx.c	Thu Dec 19 16:25:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsx.c,v 1.3 2018/04/24 18:34:30 maya Exp $	*/
+/*	$NetBSD: rtsx.c,v 1.4 2019/12/19 16:25:13 kamil Exp $	*/
 /*	$OpenBSD: rtsx.c,v 1.10 2014/08/19 17:55:03 phessler Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtsx.c,v 1.3 2018/04/24 18:34:30 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsx.c,v 1.4 2019/12/19 16:25:13 kamil Exp $");
 
 #include 
 #include 
@@ -1044,7 +1044,7 @@ rtsx_read_cfg(struct rtsx_softc *sc, uin
 	RTSX_READ(sc, RTSX_CFGDATA1, );
 	RTSX_READ(sc, RTSX_CFGDATA2, );
 	RTSX_READ(sc, RTSX_CFGDATA3, );
-	*val = (data3 << 24) | (data2 << 16) | (data1 << 8) | data0;
+	*val = ((uint32_t)data3 << 24) | (data2 << 16) | (data1 << 8) | data0;
 
 	return 0;
 }



CVS commit: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common

2019-12-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec 18 14:51:24 UTC 2019

Modified Files:
src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common:
sanitizer_interceptors_ioctl_netbsd.inc
sanitizer_platform_limits_netbsd.cc
sanitizer_platform_limits_netbsd.h

Log Message:
Fix compiler-rt build after removal of filemon

Cherry-pick [patched locally]:
[compiler-rt] Sync NetBSD ioctl definitions with 9.99.26

Document the minimal version supported to 9.0.

https://github.com/llvm/llvm-project/commit/e14ff22694c28b5e731502bfc30192b3208d4d8d


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
 \

src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc:1.2 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc:1.3
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc:1.2	Wed Aug 14 00:51:48 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc	Wed Dec 18 14:51:24 2019
@@ -25,7 +25,7 @@ struct ioctl_desc {
   const char *name;
 };
 
-const unsigned ioctl_table_max = 1236;
+const unsigned ioctl_table_max = 1238;
 static ioctl_desc ioctl_table[ioctl_table_max];
 static unsigned ioctl_table_size = 0;
 
@@ -167,9 +167,6 @@ static void ioctl_table_fill() {
   _(FE_ENABLE_HIGH_LNB_VOLTAGE, READ, sizeof(int));
   _(FE_SET_FRONTEND_TUNE_MODE, READ, sizeof(unsigned int));
   _(FE_DISHNETWORK_SEND_LEGACY_CMD, READ, sizeof(unsigned long));
-  /* Entries from file: dev/filemon/filemon.h */
-  _(FILEMON_SET_FD, READWRITE, sizeof(int));
-  _(FILEMON_SET_PID, READWRITE, sizeof(int));
   /* Entries from file: dev/hdaudio/hdaudioio.h */
   _(HDAUDIO_FGRP_INFO, READWRITE, struct_plistref_sz);
   _(HDAUDIO_FGRP_GETCONFIG, READWRITE, struct_plistref_sz);
@@ -654,6 +651,7 @@ static void ioctl_table_fill() {
   _(NVMM_IOC_MACHINE_CONFIGURE, READ, struct_nvmm_ioc_machine_configure_sz);
   _(NVMM_IOC_VCPU_CREATE, READ, struct_nvmm_ioc_vcpu_create_sz);
   _(NVMM_IOC_VCPU_DESTROY, READ, struct_nvmm_ioc_vcpu_destroy_sz);
+  _(NVMM_IOC_VCPU_CONFIGURE, READ, struct_nvmm_ioc_vcpu_configure_sz);
   _(NVMM_IOC_VCPU_SETSTATE, READ, struct_nvmm_ioc_vcpu_setstate_sz);
   _(NVMM_IOC_VCPU_GETSTATE, READ, struct_nvmm_ioc_vcpu_getstate_sz);
   _(NVMM_IOC_VCPU_INJECT, READ, struct_nvmm_ioc_vcpu_inject_sz);
@@ -736,6 +734,7 @@ static void ioctl_table_fill() {
   _(IOC_NPF_SAVE, WRITE, struct_nvlist_ref_sz);
   _(IOC_NPF_RULE, READWRITE, struct_nvlist_ref_sz);
   _(IOC_NPF_CONN_LOOKUP, READWRITE, struct_nvlist_ref_sz);
+  _(IOC_NPF_TABLE_REPLACE, READWRITE, struct_nvlist_ref_sz);
   /* Entries from file: net/if_pppoe.h */
   _(PPPOESETPARMS, READ, struct_pppoediscparms_sz);
   _(PPPOEGETPARMS, READWRITE, struct_pppoediscparms_sz);
@@ -1404,8 +1403,11 @@ static void ioctl_table_fill() {
   _(SNDCTL_DSP_SETRECVOL, READ, sizeof(unsigned int));
   _(SNDCTL_DSP_SKIP, NONE, 0);
   _(SNDCTL_DSP_SILENCE, NONE, 0);
+  /* Entries from file: dev/filemon/filemon.h (compat <= 9.99.26) */
+  _(FILEMON_SET_FD, READWRITE, sizeof(int));
+  _(FILEMON_SET_PID, READWRITE, sizeof(int));
 #undef _
-}
+} // NOLINT
 
 static bool ioctl_initialized = false;
 
Index: src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
diff -u src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.2 src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.3
--- src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc:1.2	Wed Aug 14 00:51:48 2019
+++ src/sys/external/bsd/compiler_rt/dist/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc	Wed Dec 18 14:51:24 2019
@@ -110,7 +110,12 @@
 #include 
 #include 
 #include 
+#if !__NetBSD_Prereq__(9,9,26)
 #include 
+#else
+#define FILEMON_SET_FD  _IOWR('S', 1, int)
+#define FILEMON_SET_PID _IOWR('S', 2, pid_t)
+#endif
 #include 
 #include 
 #include 
@@ -698,6 +703,7 @@ unsigned struct_nvmm_ioc_machine_configu
 sizeof(nvmm_ioc_machine_configure);
 unsigned struct_nvmm_ioc_vcpu_create_sz = sizeof(nvmm_ioc_vcpu_create);
 unsigned struct_nvmm_ioc_vcpu_destroy_sz = sizeof(nvmm_ioc_vcpu_destroy);
+unsigned struct_nvmm_ioc_vcpu_configure_sz = sizeof(nvmm_ioc_vcpu_configure);
 

CVS commit: src/etc/mtree

2019-12-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec 18 14:44:16 UTC 2019

Modified Files:
src/etc/mtree: NetBSD.dist.base

Log Message:
Remove obsolete mtree entry of usr/share/examples/supfiles


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/etc/mtree/NetBSD.dist.base

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/mtree/NetBSD.dist.base
diff -u src/etc/mtree/NetBSD.dist.base:1.206 src/etc/mtree/NetBSD.dist.base:1.207
--- src/etc/mtree/NetBSD.dist.base:1.206	Wed Dec 18 07:37:17 2019
+++ src/etc/mtree/NetBSD.dist.base	Wed Dec 18 14:44:16 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.base,v 1.206 2019/12/18 07:37:17 maxv Exp $
+#	$NetBSD: NetBSD.dist.base,v 1.207 2019/12/18 14:44:16 kamil Exp $
 #	@(#)4.4BSD.dist	8.1 (Berkeley) 6/13/93
 
 # Do not customize this file as it may be overwritten on upgrades.
@@ -411,7 +411,6 @@
 ./usr/share/examples/rtadvd
 ./usr/share/examples/slip
 ./usr/share/examples/smbfs
-./usr/share/examples/supfiles
 ./usr/share/examples/syslogd
 ./usr/share/examples/tmux
 ./usr/share/examples/wpa_supplicant



CVS commit: src/sys/kern

2019-12-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Dec  7 19:50:34 UTC 2019

Modified Files:
src/sys/kern: subr_kcov.c

Log Message:
Revert the in_interrupt() change to use again the x86 specific code

This is prerequisite for kMSan and upcoming kernel changes.

Discussed with 


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/kern/subr_kcov.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_kcov.c
diff -u src/sys/kern/subr_kcov.c:1.10 src/sys/kern/subr_kcov.c:1.11
--- src/sys/kern/subr_kcov.c:1.10	Sun Dec  1 17:41:11 2019
+++ src/sys/kern/subr_kcov.c	Sat Dec  7 19:50:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kcov.c,v 1.10 2019/12/01 17:41:11 kamil Exp $	*/
+/*	$NetBSD: subr_kcov.c,v 1.11 2019/12/07 19:50:33 kamil Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -38,7 +38,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -343,7 +342,7 @@ out:
 static inline bool __nomsan
 in_interrupt(void)
 {
-	return cpu_intr_p();
+	return curcpu()->ci_idepth >= 0;
 }
 
 void __sanitizer_cov_trace_pc(void);



CVS commit: src/external/bsd/libproc/dist

2019-12-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Dec  7 19:38:29 UTC 2019

Modified Files:
src/external/bsd/libproc/dist: proc_util.c

Log Message:
Switch proc_getlwpstatus from PT_LWPINFO to PT_GET_SIGINFO for NetBSD

PT_LWPINFO from FreeBSD is almost never intended to be expressed with
PT_LWPINFO in NetBSD. PT_GET_SIGINFO reads siginfo_t with the signal
information about the event, on FreeBSD siginfo_t is merged into
ptrace_lwpinfo and returns the thread that received the event (not the
first one in a list like on NetBSD).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/bsd/libproc/dist/proc_util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/libproc/dist/proc_util.c
diff -u src/external/bsd/libproc/dist/proc_util.c:1.6 src/external/bsd/libproc/dist/proc_util.c:1.7
--- src/external/bsd/libproc/dist/proc_util.c:1.6	Fri Jun  9 01:17:25 2017
+++ src/external/bsd/libproc/dist/proc_util.c	Sat Dec  7 19:38:29 2019
@@ -224,42 +224,50 @@ proc_read(struct proc_handle *phdl, void
 const lwpstatus_t *
 proc_getlwpstatus(struct proc_handle *phdl)
 {
-	struct ptrace_lwpinfo lwpinfo;
 	lwpstatus_t *psp = >lwps;
 	siginfo_t *siginfo;
+
+#ifdef PT_GET_SIGINFO
+	struct ptrace_siginfo si;
+
+	if (ptrace(PT_GET_SIGINFO, phdl->pid, (void *),
+		   sizeof(si)) < 0)
+		return (NULL);
+
+	siginfo = _siginfo;
+	if (siginfo->si_signo == SIGTRAP &&
+	(siginfo->si_code == TRAP_BRKPT ||
+	siginfo->si_code == TRAP_TRACE)) {
+		psp->pr_why = PR_FAULTED;
+		psp->pr_what = FLTBPT;
+	} else if (siginfo->si_signo == SIGTRAP &&
+	(siginfo->si_code == TRAP_SCE)) {
+		psp->pr_why = PR_SYSENTRY;
+	} else if (siginfo->si_signo == SIGTRAP &&
+	(siginfo->si_code == TRAP_SCX)) {
+		psp->pr_why = PR_SYSEXIT;
+	} else {
+		psp->pr_why = PR_SIGNALLED;
+		psp->pr_what = siginfo->si_signo;
+	}
+#else
+	struct ptrace_lwpinfo lwpinfo;
 	bool have_siginfo, sysentry, sysexit;
 
 	if (phdl == NULL)
 		return (NULL);
+
 	lwpinfo.pl_lwpid = 0;
 	if (ptrace(PT_LWPINFO, phdl->pid, (void *),
 	sizeof(lwpinfo)) < 0)
 		return (NULL);
 
-#ifdef PL_FLAG_SI
 	have_siginfo = (lwpinfo.pl_flags & PL_FLAG_SI) != 0;
 	sysentry = (lwpinfo.pl_flags & PL_FLAG_SCE) != 0;
 	sysexit = (lwpinfo.pl_flags & PL_FLAG_SCX) != 0;
-#endif
-#ifdef PT_GET_SIGINFO
-	have_siginfo = 1;
-	sysentry = 0;
-	sysexit = 0;
-#endif
 
 	if (lwpinfo.pl_event == PL_EVENT_SIGNAL && have_siginfo) {
-#ifdef PL_FLAG_SI
 		siginfo = _siginfo;
-#endif
-#ifdef PT_GET_SIGINFO
-		struct ptrace_siginfo si;
-
-		if (ptrace(PT_GET_SIGINFO, phdl->pid, (void *),
-			   sizeof(si)) < 0)
-			return (NULL);
-
-		siginfo = _siginfo;
-#endif
 		if (siginfo->si_signo == SIGTRAP &&
 		(siginfo->si_code == TRAP_BRKPT ||
 		siginfo->si_code == TRAP_TRACE)) {
@@ -274,5 +282,6 @@ proc_getlwpstatus(struct proc_handle *ph
 	} else if (sysexit) {
 		psp->pr_why = PR_SYSEXIT;
 	}
+#endif
 	return (psp);
 }



CVS commit: src/sys/arch/aarch64

2019-12-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  6 18:16:23 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: sys_machdep.c
src/sys/arch/aarch64/include: types.h

Log Message:
Remove __HAVE_CPU_LWP_SETPRIVATE from aarch64

aarch64 specific cpu_lwp_setprivate() is redundant with its caller
lwp_setprivate() and there are no MD bits.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/sys_machdep.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/include/types.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/sys_machdep.c
diff -u src/sys/arch/aarch64/aarch64/sys_machdep.c:1.3 src/sys/arch/aarch64/aarch64/sys_machdep.c:1.4
--- src/sys/arch/aarch64/aarch64/sys_machdep.c:1.3	Tue Jul 17 00:36:30 2018
+++ src/sys/arch/aarch64/aarch64/sys_machdep.c	Fri Dec  6 18:16:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_machdep.c,v 1.3 2018/07/17 00:36:30 christos Exp $ */
+/* $NetBSD: sys_machdep.c,v 1.4 2019/12/06 18:16:22 kamil Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sys_machdep.c,v 1.3 2018/07/17 00:36:30 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sys_machdep.c,v 1.4 2019/12/06 18:16:22 kamil Exp $");
 
 #include 
 #include 
@@ -47,10 +47,3 @@ sys_sysarch(struct lwp *l, const struct 
 {
 	return EINVAL;
 }
-
-int
-cpu_lwp_setprivate(lwp_t *l, void *addr)
-{
-	l->l_private = addr;
-	return 0;
-}

Index: src/sys/arch/aarch64/include/types.h
diff -u src/sys/arch/aarch64/include/types.h:1.12 src/sys/arch/aarch64/include/types.h:1.13
--- src/sys/arch/aarch64/include/types.h:1.12	Sat Oct 13 08:32:36 2018
+++ src/sys/arch/aarch64/include/types.h	Fri Dec  6 18:16:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.12 2018/10/13 08:32:36 ryo Exp $ */
+/* $NetBSD: types.h,v 1.13 2019/12/06 18:16:22 kamil Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -100,7 +100,6 @@ typedef __uint64_t __register_t;
 #define __HAVE_NEW_STYLE_BUS_H
 #define __HAVE_MINIMAL_EMUL
 #define __HAVE_CPU_DATA_FIRST
-#define __HAVE_CPU_LWP_SETPRIVATE
 #define __HAVE___LWP_GETPRIVATE_FAST
 #define __HAVE_COMMON___TLS_GET_ADDR
 #define __HAVE_TLS_VARIANT_I



CVS commit: src/share/man/man5

2019-12-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  6 18:03:49 UTC 2019

Modified Files:
src/share/man/man5: core.5

Log Message:
Remove misleading comments from core(5)

netbsd_elfcore_procinfo is still in version 1.
cpi_siglwp is stored in the same netbsd_elfcore_procinfo version (1).

The size of struct is stored in cpi_cpisize and the struct can be
expanded without versioning the struct.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/share/man/man5/core.5

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man5/core.5
diff -u src/share/man/man5/core.5:1.32 src/share/man/man5/core.5:1.33
--- src/share/man/man5/core.5:1.32	Mon Sep  9 00:14:55 2019
+++ src/share/man/man5/core.5	Fri Dec  6 18:03:49 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: core.5,v 1.32 2019/09/09 00:14:55 sevan Exp $
+.\"	$NetBSD: core.5,v 1.33 2019/12/06 18:03:49 kamil Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -56,7 +56,7 @@
 .\"
 .\" @(#)core.5	8.3 (Berkeley) 12/11/93
 .\"
-.Dd September 9, 2019
+.Dd December 6, 2019
 .Dt CORE 5
 .Os
 .Sh NAME
@@ -144,7 +144,6 @@ and contains the following
 structure:
 .Bd -literal
 struct netbsd_elfcore_procinfo {
-   /* Version 1 fields start here. */
 uint32_t cpi_version;  /* netbsd_elfcore_procinfo version */
 uint32_t cpi_cpisize;  /* sizeof(netbsd_elfcore_procinfo) */
 uint32_t cpi_signo;/* killing signal */
@@ -165,8 +164,7 @@ struct netbsd_elfcore_procinfo {
 uint32_t cpi_svgid;/* saved group ID */
 uint32_t cpi_nlwps;/* number of LWPs */
 int8_t   cpi_name[32]; /* copy of p->p_comm */
-/* Add version 2 fields below here. */
-int32_t cpi_siglwp; /* LWP target of killing signal */
+int32_t  cpi_siglwp;   /* LWP target of killing signal */
 };
 .Ed
 .Pp



CVS commit: src/sys/kern

2019-12-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  6 17:41:43 UTC 2019

Modified Files:
src/sys/kern: kern_proc.c

Log Message:
Correct signals in siglist+sigmask passed in kinfo_lwp

Make the union of LWP and PROC pending signals correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/kern/kern_proc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_proc.c
diff -u src/sys/kern/kern_proc.c:1.236 src/sys/kern/kern_proc.c:1.237
--- src/sys/kern/kern_proc.c:1.236	Sat Oct 12 10:55:23 2019
+++ src/sys/kern/kern_proc.c	Fri Dec  6 17:41:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_proc.c,v 1.236 2019/10/12 10:55:23 kamil Exp $	*/
+/*	$NetBSD: kern_proc.c,v 1.237 2019/12/06 17:41:43 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.236 2019/10/12 10:55:23 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.237 2019/12/06 17:41:43 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kstack.h"
@@ -2457,7 +2457,7 @@ fill_kproc2(struct proc *p, struct kinfo
 			ki->p_estcpu += l->l_estcpu;
 		}
 	}
-	sigplusset(>p_sigpend.sp_set, );
+	sigplusset(>p_sigpend.sp_set, );
 	memcpy(>p_siglist, , sizeof(ki_sigset_t));
 	memcpy(>p_sigmask, , sizeof(ki_sigset_t));
 



CVS commit: src/tests/lib/libc/sys

2019-12-05 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Dec  6 01:09:51 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Log PID.LWP in t_ptrace_wait* tests for enabled debug

This is useful for multithreaded test scenarios.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.141 src/tests/lib/libc/sys/t_ptrace_wait.c:1.142
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.141	Tue Nov 12 18:18:04 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Fri Dec  6 01:09:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.142 2019/12/06 01:09:50 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.142 2019/12/06 01:09:50 kamil Exp $");
 
 #include 
 #include 
@@ -118,7 +118,8 @@ static int debug = 0;
 
 #define DPRINTF(a, ...)	do  \
 	if (debug) \
-	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
+	printf("%s() %d.%d %s:%d " a, \
+	__func__, getpid(), _lwp_self(), __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
 /// 



CVS commit: src/sys/sys

2019-12-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Dec  4 13:52:27 UTC 2019

Modified Files:
src/sys/sys: ptrace.h

Log Message:
Register "PT_STOP" in ptrace PT_STRINGS


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/sys/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/ptrace.h
diff -u src/sys/sys/ptrace.h:1.66 src/sys/sys/ptrace.h:1.67
--- src/sys/sys/ptrace.h:1.66	Wed Oct  9 13:19:43 2019
+++ src/sys/sys/ptrace.h	Wed Dec  4 13:52:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.66 2019/10/09 13:19:43 kamil Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.67 2019/12/04 13:52:27 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1984, 1993
@@ -85,7 +85,8 @@
 /* 19 */"PT_SET_SIGINFO", \
 /* 20 */"PT_GET_SIGINFO", \
 /* 21 */"PT_RESUME", \
-/* 22 */"PT_SUSPEND",
+/* 22 */"PT_SUSPEND", \
+/* 23 */"PT_STOP",
 
 /* PT_{G,S}EVENT_MASK */
 typedef struct ptrace_event {



CVS commit: src/sys/arch/amd64/include

2019-12-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Dec  2 19:17:27 UTC 2019

Modified Files:
src/sys/arch/amd64/include: ptrace.h

Log Message:
Define PT_GETXMMREGS and PT_SETXMMREGS in PT_MACHDEP_STRINGS/amd64


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/include/ptrace.h
diff -u src/sys/arch/amd64/include/ptrace.h:1.19 src/sys/arch/amd64/include/ptrace.h:1.20
--- src/sys/arch/amd64/include/ptrace.h:1.19	Wed Nov 27 09:16:58 2019
+++ src/sys/arch/amd64/include/ptrace.h	Mon Dec  2 19:17:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.19 2019/11/27 09:16:58 rin Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.20 2019/12/02 19:17:27 kamil Exp $	*/
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -69,7 +69,9 @@
 	"PT_SETSTEP", \
 	"PT_CLEARSTEP", \
 	"PT_GETXSTATE", \
-	"PT_SETXSTATE"
+	"PT_SETXSTATE", \
+	"PT_GETXMMREGS", \
+	"PT_SETXMMREGS"
 
 #include 
 #define PTRACE_REG_PC(r)	(r)->regs[_REG_RIP]



CVS commit: src/sys/kern

2019-12-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Dec  1 17:41:11 UTC 2019

Modified Files:
src/sys/kern: subr_kcov.c

Log Message:
Switch in_interrupt() in KCOV to cpu_intr_p()

This makes KCOV more MI friendly and removes x86-specific in_interrupt()
implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/kern/subr_kcov.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_kcov.c
diff -u src/sys/kern/subr_kcov.c:1.9 src/sys/kern/subr_kcov.c:1.10
--- src/sys/kern/subr_kcov.c:1.9	Fri Nov 15 09:44:44 2019
+++ src/sys/kern/subr_kcov.c	Sun Dec  1 17:41:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kcov.c,v 1.9 2019/11/15 09:44:44 maxv Exp $	*/
+/*	$NetBSD: subr_kcov.c,v 1.10 2019/12/01 17:41:11 kamil Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -342,7 +343,7 @@ out:
 static inline bool __nomsan
 in_interrupt(void)
 {
-	return curcpu()->ci_idepth >= 0;
+	return cpu_intr_p();
 }
 
 void __sanitizer_cov_trace_pc(void);



CVS commit: src/share/mk

2019-12-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Dec  1 17:25:47 UTC 2019

Modified Files:
src/share/mk: bsd.sys.mk

Log Message:
Disable KCOV instrumentation in x86_machdep.c

This allows to use cpu_intr_p() directly inside KCOV.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/share/mk/bsd.sys.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/mk/bsd.sys.mk
diff -u src/share/mk/bsd.sys.mk:1.296 src/share/mk/bsd.sys.mk:1.297
--- src/share/mk/bsd.sys.mk:1.296	Fri Nov 15 09:44:44 2019
+++ src/share/mk/bsd.sys.mk	Sun Dec  1 17:25:47 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.sys.mk,v 1.296 2019/11/15 09:44:44 maxv Exp $
+#	$NetBSD: bsd.sys.mk,v 1.297 2019/12/01 17:25:47 kamil Exp $
 #
 # Build definitions used for NetBSD source tree builds.
 
@@ -247,7 +247,8 @@ CFLAGS+=	${KLEAKFLAGS.${.IMPSRC:T}:U${KL
 .if ${KCOV:U0} > 0
 KCOVFLAGS=	-fsanitize-coverage=trace-pc
 .for f in subr_kcov.c subr_lwp_specificdata.c subr_specificdata.c subr_asan.c \
-	subr_csan.c subr_msan.c
+	subr_csan.c subr_msan.c x86_machdep.c
+# TODO Adapt the file list for !x86 or implement __nocov (missing in GCC 8)
 KCOVFLAGS.${f}=		# empty
 .endfor
 CFLAGS+=	${KCOVFLAGS.${.IMPSRC:T}:U${KCOVFLAGS}}



CVS commit: src/sys/kern

2019-05-09 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu May  9 20:50:14 UTC 2019

Modified Files:
src/sys/kern: kern_exec.c

Log Message:
Report TRAP_EXEC (for exec()) to a debugger in the PT_SYSCALL mode

Orignally exec() reporting was disabled in the NetBSD version as there
was no support for fine-grained reporting. Meanwhile PT_SYSCALL was broken
for years and there is no software that depends on this behavior.

There is need to catch exec() events in syscall tracers using ptrace(2).
Instead of adding workarounds of guessing that exec() happened, report the
event directly from the kernel.

All ATF ptrace(2) tests pass.


To generate a diff of this commit:
cvs rdiff -u -r1.464 -r1.465 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.464 src/sys/kern/kern_exec.c:1.465
--- src/sys/kern/kern_exec.c:1.464	Fri May  3 22:34:21 2019
+++ src/sys/kern/kern_exec.c	Thu May  9 20:50:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.465 2019/05/09 20:50:14 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.465 2019/05/09 20:50:14 kamil Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1269,7 +1269,7 @@ execve_runproc(struct lwp *l, struct exe
 
 	mutex_enter(proc_lock);
 
-	if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) {
+	if (p->p_slflag & PSL_TRACED) {
 		mutex_enter(p->p_lock);
 		eventswitch(TRAP_EXEC);
 		mutex_enter(proc_lock);



CVS commit: src/sys/arch

2019-05-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May  7 03:49:28 UTC 2019

Modified Files:
src/sys/arch/alpha/include: ansi.h
src/sys/arch/amd64/include: ansi.h
src/sys/arch/amiga/include: ansi.h
src/sys/arch/arm/include: ansi.h
src/sys/arch/atari/include: ansi.h
src/sys/arch/dreamcast/include: ansi.h
src/sys/arch/evbsh3/include: ansi.h
src/sys/arch/hp300/include: ansi.h
src/sys/arch/hpcsh/include: ansi.h
src/sys/arch/hppa/include: ansi.h
src/sys/arch/i386/include: ansi.h
src/sys/arch/landisk/include: ansi.h
src/sys/arch/luna68k/include: ansi.h
src/sys/arch/m68k/include: ansi.h
src/sys/arch/mips/include: ansi.h
src/sys/arch/mvme68k/include: ansi.h
src/sys/arch/news68k/include: ansi.h
src/sys/arch/powerpc/include: ansi.h
src/sys/arch/sh3/include: ansi.h
src/sys/arch/sparc/include: ansi.h
src/sys/arch/sparc64/include: ansi.h
src/sys/arch/usermode/include: ansi.h
src/sys/arch/vax/include: ansi.h
src/sys/arch/x68k/include: ansi.h

Log Message:
Switch all users (except ia64) of custom machine/ansi.h to common_ansi.h

Deduplicate the code among ports and poll definitions of types
directly from a compiler.

This fixes miscompilation of certain programs that instruct compilers
to generate code for different types. This bug has been detected with
-fshort-wchar in EFI firmware.

Proposed and discussed on a mailing list (twice).

Itanium uses custom !ELF fallback switch, temporarily leave it as it is.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/include/ansi.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/include/ansi.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amiga/include/ansi.h
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/include/ansi.h
cvs rdiff -u -r1.1.1.1 -r1.2 src/sys/arch/atari/include/ansi.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/dreamcast/include/ansi.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbsh3/include/ansi.h
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hp300/include/ansi.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/hpcsh/include/ansi.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/hppa/include/ansi.h
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/include/ansi.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/landisk/include/ansi.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/luna68k/include/ansi.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/m68k/include/ansi.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/mips/include/ansi.h
cvs rdiff -u -r1.1.1.1 -r1.2 src/sys/arch/mvme68k/include/ansi.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/news68k/include/ansi.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/include/ansi.h
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/sh3/include/ansi.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/sparc/include/ansi.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/sparc64/include/ansi.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/usermode/include/ansi.h
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/vax/include/ansi.h
cvs rdiff -u -r1.1.1.1 -r1.2 src/sys/arch/x68k/include/ansi.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/include/ansi.h
diff -u src/sys/arch/alpha/include/ansi.h:1.25 src/sys/arch/alpha/include/ansi.h:1.26
--- src/sys/arch/alpha/include/ansi.h:1.25	Wed Jun 17 14:02:47 2015
+++ src/sys/arch/alpha/include/ansi.h	Tue May  7 03:49:25 2019
@@ -1,62 +1,3 @@
-/* $NetBSD: ansi.h,v 1.25 2015/06/17 14:02:47 martin Exp $ */
+/* $NetBSD: ansi.h,v 1.26 2019/05/07 03:49:25 kamil Exp $ */
 
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  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.
- * 3. Neither the name of the University nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 

CVS commit: src/usr.bin/ktruss

2019-05-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon May  6 11:58:37 UTC 2019

Modified Files:
src/usr.bin/ktruss: makeerrnos.sh

Log Message:
Add support for SIGRTMIN+1..SIGRTMAX-1 signals in ktruss(1)

Generate misc.c and misc.h with entries for signals between SIGRTMIN+1
and SIGRTMAX-1.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/ktruss/makeerrnos.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ktruss/makeerrnos.sh
diff -u src/usr.bin/ktruss/makeerrnos.sh:1.6 src/usr.bin/ktruss/makeerrnos.sh:1.7
--- src/usr.bin/ktruss/makeerrnos.sh:1.6	Mon Mar 12 22:02:07 2012
+++ src/usr.bin/ktruss/makeerrnos.sh	Mon May  6 11:58:37 2019
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-#	$NetBSD: makeerrnos.sh,v 1.6 2012/03/12 22:02:07 dyoung Exp $
+#	$NetBSD: makeerrnos.sh,v 1.7 2019/05/06 11:58:37 kamil Exp $
 
 if [ $# -ne 3 ]; then
 	echo "usage: makeerrnos.sh errno.h signal.h output"
@@ -53,10 +53,22 @@ ${AWK} '
 			break;
 	i++;
 	j = i + 1;
+
+	if ($i == "SIGRTMIN") {
+		sigrtmin=$j;
+	}
+	if ($i == "SIGRTMAX") {
+		sigrtmax=$j;
+	}
+
 	#
 	printf("\t{ \"%s\", %s },\n", $i, $j);
 }
 END {
+	j = 1;
+	for (i = sigrtmin + 1; i < sigrtmax; i++) {
+		printf("\t{ \"SIGRTMIN+%s\", %s },\n", j++, i);
+	}
 	print "	{ \"0\", 0 },\n";
 }
 ' | sort -n -k 3 >> $CFILE



CVS commit: src/doc

2019-05-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon May  6 08:32:40 UTC 2019

Modified Files:
src/doc: CHANGES

Log Message:
siginfo(2): Ship with MI syscall information of a debugged process for
SIGTRAP and si_code TRAP_SCE/TRAP_SCX.


To generate a diff of this commit:
cvs rdiff -u -r1.2534 -r1.2535 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2534 src/doc/CHANGES:1.2535
--- src/doc/CHANGES:1.2534	Sat May  4 09:43:16 2019
+++ src/doc/CHANGES	Mon May  6 08:32:40 2019
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2534 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2535 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -374,3 +374,5 @@ Changes from NetBSD 8.0 to NetBSD 9.0:
 	bind: Import version 9.14.1. [christos 20190427]
 	acpi(4): Updated ACPICA to 20190405. [christos 20190428]
 	dhcpcd(8): Import dhcpcd-7.2.2 [roy 20190504]
+	siginfo(2): Ship with MI syscall information of a debugged process for
+		SIGTRAP and si_code TRAP_SCE/TRAP_SCX. [kamil 20190506]



CVS commit: src/sys/sys

2019-05-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon May  6 08:07:41 UTC 2019

Modified Files:
src/sys/sys: param.h

Log Message:
Welcome to NetBSD 8.99.38!

Signal code struct and API changes.


To generate a diff of this commit:
cvs rdiff -u -r1.585 -r1.586 src/sys/sys/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.585 src/sys/sys/param.h:1.586
--- src/sys/sys/param.h:1.585	Sat Apr  6 03:06:28 2019
+++ src/sys/sys/param.h	Mon May  6 08:07:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.585 2019/04/06 03:06:28 thorpej Exp $	*/
+/*	$NetBSD: param.h,v 1.586 2019/05/06 08:07:41 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	899003700	/* NetBSD 8.99.37 */
+#define	__NetBSD_Version__	899003800	/* NetBSD 8.99.38 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys

2019-05-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon May  6 08:05:03 UTC 2019

Modified Files:
src/sys/kern: kern_sig.c kern_syscall.c
src/sys/sys: ptrace.h siginfo.h

Log Message:
Ship with syscall information with SIGTRAP TRAP_SCE/TRAP_SCX for tracers

Expand siginfo_t (struct size not changed) to new values for
SIGTRAP TRAP_SCE/TRAP_SCX events.

 - si_sysnum  -- syscall number (int)
 - si_retval  -- return value (2 x int)
 - si_error   -- error code (int)
 - si_args-- syscall arguments (8 x uint64_t)

TRAP_SCE delivers si_sysnum and si_args.

TRAP_SCX delivers si_sysnum, si_retval, si_error and si_args.

Users: debuggers (like GDB) and syscall tracers (like strace, truss).

This MI interface is similar to the Linux kernel proposal of
PTRACE_GET_SYSCALL_INFO by the strace developer team.


To generate a diff of this commit:
cvs rdiff -u -r1.357 -r1.358 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.17 -r1.18 src/sys/kern/kern_syscall.c
cvs rdiff -u -r1.63 -r1.64 src/sys/sys/ptrace.h
cvs rdiff -u -r1.32 -r1.33 src/sys/sys/siginfo.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.357 src/sys/kern/kern_sig.c:1.358
--- src/sys/kern/kern_sig.c:1.357	Fri May  3 22:34:21 2019
+++ src/sys/kern/kern_sig.c	Mon May  6 08:05:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.358 2019/05/06 08:05:03 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.358 2019/05/06 08:05:03 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -2352,7 +2352,8 @@ proc_unstop(struct proc *p)
 }
 
 void
-proc_stoptrace(int trapno)
+proc_stoptrace(int trapno, int sysnum, const register_t args[],
+   const register_t *ret, int error)
 {
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
@@ -2360,14 +2361,36 @@ proc_stoptrace(int trapno)
 	sigset_t *mask;
 	sig_t action;
 	ksiginfo_t ksi;
+	size_t i, sy_narg;
 	const int signo = SIGTRAP;
 
 	KASSERT((trapno == TRAP_SCE) || (trapno == TRAP_SCX));
+	KASSERT(p->p_pptr != initproc);
+	KASSERT(ISSET(p->p_slflag, PSL_TRACED));
+	KASSERT(ISSET(p->p_slflag, PSL_SYSCALL));
+
+	sy_narg = p->p_emul->e_sysent[sysnum].sy_narg;
 
 	KSI_INIT_TRAP();
 	ksi.ksi_lid = l->l_lid;
-	ksi.ksi_info._signo = signo;
-	ksi.ksi_info._code = trapno;
+	ksi.ksi_signo = signo;
+	ksi.ksi_code = trapno;
+
+	ksi.ksi_sysnum = sysnum;
+	if (trapno == TRAP_SCE) {
+		ksi.ksi_retval[0] = 0;
+		ksi.ksi_retval[1] = 0;
+		ksi.ksi_error = 0;
+	} else {
+		ksi.ksi_retval[0] = ret[0];
+		ksi.ksi_retval[1] = ret[1];
+		ksi.ksi_error = error;
+	}
+
+	memset(ksi.ksi_args, 0, sizeof(ksi.ksi_args));
+
+	for (i = 0; i < sy_narg; i++)
+		ksi.ksi_args[i] = args[i];
 
 	mutex_enter(p->p_lock);
 
@@ -2385,12 +2408,6 @@ proc_stoptrace(int trapno)
 	action = SIGACTION_PS(ps, signo).sa_handler;
 	mask = >l_sigmask;
 
-	/* initproc (PID1) cannot became a debugger */
-	KASSERT(p->p_pptr != initproc);
-
-	KASSERT(ISSET(p->p_slflag, PSL_TRACED));
-	KASSERT(ISSET(p->p_slflag, PSL_SYSCALL));
-
 	p->p_xsig = signo;
 	p->p_sigctx.ps_lwp = ksi.ksi_lid;
 	p->p_sigctx.ps_info = ksi.ksi_info;

Index: src/sys/kern/kern_syscall.c
diff -u src/sys/kern/kern_syscall.c:1.17 src/sys/kern/kern_syscall.c:1.18
--- src/sys/kern/kern_syscall.c:1.17	Fri Aug 10 21:44:59 2018
+++ src/sys/kern/kern_syscall.c	Mon May  6 08:05:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_syscall.c,v 1.17 2018/08/10 21:44:59 pgoyette Exp $	*/
+/*	$NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.17 2018/08/10 21:44:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -255,7 +255,7 @@ trace_enter(register_t code, const struc
 #ifdef PTRACE
 	if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
 	(PSL_SYSCALL|PSL_TRACED)) {
-		proc_stoptrace(TRAP_SCE);
+		proc_stoptrace(TRAP_SCE, code, args, NULL, 0);
 		if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
 			/* tracer will emulate syscall for us */
 			error = EJUSTRETURN;
@@ -296,7 +296,7 @@ trace_exit(register_t code, const struct
 #ifdef PTRACE
 	if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) ==
 	(PSL_SYSCALL|PSL_TRACED)) {
-		proc_stoptrace(TRAP_SCX);
+		proc_stoptrace(TRAP_SCX, code, args, rval, error);
 	}
 	CLR(p->p_slflag, PSL_SYSCALLEMU);
 #endif

Index: src/sys/sys/ptrace.h
diff -u src/sys/sys/ptrace.h:1.63 src/sys/sys/ptrace.h:1.64
--- src/sys/sys/ptrace.h:1.63	Mon Mar  5 11:24:34 2018
+++ 

CVS commit: src/sys

2019-05-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri May  3 22:34:21 UTC 2019

Modified Files:
src/sys/kern: kern_exec.c kern_fork.c kern_lwp.c kern_sig.c sys_lwp.c
src/sys/sys: signalvar.h

Log Message:
Register KTR events for debugger related signals

Register signals for:

 - crashes (FPE, SEGV, FPE, ILL, BUS)
 - LWP events
 - CHLD (FORK/VFORK/VFORK_DONE) events -- temporarily disabled
 - EXEC events

While there refactor related functions in order to simplify the code.

Add missing comment documentation for recently added kernel functions.


To generate a diff of this commit:
cvs rdiff -u -r1.463 -r1.464 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.211 -r1.212 src/sys/kern/kern_fork.c
cvs rdiff -u -r1.199 -r1.200 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.356 -r1.357 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.66 -r1.67 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.92 -r1.93 src/sys/sys/signalvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.463 src/sys/kern/kern_exec.c:1.464
--- src/sys/kern/kern_exec.c:1.463	Wed May  1 17:21:55 2019
+++ src/sys/kern/kern_exec.c	Fri May  3 22:34:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1271,9 +1271,7 @@ execve_runproc(struct lwp *l, struct exe
 
 	if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) {
 		mutex_enter(p->p_lock);
-		eventswitch(SIGTRAP, TRAP_EXEC);
-		// XXX ktrpoint(KTR_PSIG)
-		mutex_exit(p->p_lock);
+		eventswitch(TRAP_EXEC);
 		mutex_enter(proc_lock);
 	}
 

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.211 src/sys/kern/kern_fork.c:1.212
--- src/sys/kern/kern_fork.c:1.211	Wed May  1 18:01:54 2019
+++ src/sys/kern/kern_fork.c	Fri May  3 22:34:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.212 2019/05/03 22:34:21 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.212 2019/05/03 22:34:21 kamil Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -203,6 +203,9 @@ sys___clone(struct lwp *l, const struct 
  */
 static struct timeval fork_tfmrate = { 10, 0 };
 
+/*
+ * Check if a process is traced and shall inform about FORK events.
+ */
 static inline bool
 tracefork(struct proc *p, int flags)
 {
@@ -211,6 +214,9 @@ tracefork(struct proc *p, int flags)
 	(PSL_TRACEFORK|PSL_TRACED) && (flags & FORK_PPWAIT) == 0;
 }
 
+/*
+ * Check if a process is traced and shall inform about VFORK events.
+ */
 static inline bool
 tracevfork(struct proc *p, int flags)
 {
@@ -219,6 +225,9 @@ tracevfork(struct proc *p, int flags)
 	(PSL_TRACEVFORK|PSL_TRACED) && (flags & FORK_PPWAIT) != 0;
 }
 
+/*
+ * Check if a process is traced and shall inform about VFORK_DONE events.
+ */
 static inline bool
 tracevforkdone(struct proc *p, int flags)
 {
@@ -595,9 +604,7 @@ fork1(struct lwp *l1, int flags, int exi
 	 */
 	if (tracefork(p1, flags) || tracevfork(p1, flags)) {
 		mutex_enter(p1->p_lock);
-		eventswitch(SIGTRAP, TRAP_CHLD);
-		// XXX ktrpoint(KTR_PSIG)
-		mutex_exit(p1->p_lock);
+		eventswitch(TRAP_CHLD);
 		mutex_enter(proc_lock);
 	}
 
@@ -614,16 +621,16 @@ fork1(struct lwp *l1, int flags, int exi
 	if (tracevforkdone(p1, flags)) {
 		mutex_enter(p1->p_lock);
 		p1->p_vfpid_done = retval[0];
-		eventswitch(SIGTRAP, TRAP_CHLD);
-		// XXX ktrpoint(KTR_PSIG)
-		mutex_exit(p1->p_lock);
-		// proc_lock unlocked
+		eventswitch(TRAP_CHLD);
 	} else
 		mutex_exit(proc_lock);
 
 	return 0;
 }
 
+/*
+ * MI code executed in each newly spawned process before returning to userland.
+ */
 void
 child_return(void *arg)
 {
@@ -639,9 +646,7 @@ child_return(void *arg)
 		}
 
 		mutex_enter(p->p_lock);
-		eventswitch(SIGTRAP, TRAP_CHLD);
-		// XXX ktrpoint(KTR_PSIG)
-		mutex_exit(p->p_lock);
+		eventswitch(TRAP_CHLD);
 	}
 
 my_tracer_is_gone:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.199 src/sys/kern/kern_lwp.c:1.200
--- src/sys/kern/kern_lwp.c:1.199	Thu May  2 22:23:49 2019
+++ src/sys/kern/kern_lwp.c	Fri May  3 22:34:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.199 2019/05/02 22:23:49 kamil Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.200 2019/05/03 22:34:21 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD 

CVS commit: src/external/gpl3/gdb/dist/gdb

2019-05-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri May  3 19:06:50 UTC 2019

Modified Files:
src/external/gpl3/gdb/dist/gdb: nbsd-nat.c

Log Message:
Improve comment in the GDB NetBSD code


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.8 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.9
--- src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.8	Fri May  3 19:03:57 2019
+++ src/external/gpl3/gdb/dist/gdb/nbsd-nat.c	Fri May  3 19:06:50 2019
@@ -364,8 +364,7 @@ nbsd_wait (struct target_ops *ops,
* Always perform polling on exact PID, overwrite the default polling on
* WAIT_ANY.
*
-   * This avoids events reported in random order reported for FORK / VFORK
-   * when child and parent events are otherwise reported in random order.
+   * This avoids events reported in random order reported for FORK / VFORK.
*
* Polling on traced parent always simplifies the code.
*/



CVS commit: src/external/gpl3/gdb/dist/gdb

2019-05-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri May  3 19:03:57 UTC 2019

Modified Files:
src/external/gpl3/gdb/dist/gdb: infrun.c nbsd-nat.c

Log Message:
Overwrite waiton_ptid in nbsd-nat, rather than generic core

This avoids compatibility issues with remote access to !NetBSD platform.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/gpl3/gdb/dist/gdb/infrun.c
cvs rdiff -u -r1.7 -r1.8 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/infrun.c
diff -u src/external/gpl3/gdb/dist/gdb/infrun.c:1.2 src/external/gpl3/gdb/dist/gdb/infrun.c:1.3
--- src/external/gpl3/gdb/dist/gdb/infrun.c:1.2	Fri May  3 07:05:28 2019
+++ src/external/gpl3/gdb/dist/gdb/infrun.c	Fri May  3 19:03:57 2019
@@ -3874,11 +3874,7 @@ fetch_inferior_event (void *client_data)
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   struct cleanup *ts_old_chain;
   int cmd_done = 0;
-#if defined(__NetBSD__)
-  ptid_t waiton_ptid = inferior_ptid;
-#else
   ptid_t waiton_ptid = minus_one_ptid;
-#endif
 
   memset (ecs, 0, sizeof (*ecs));
 

Index: src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.7 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.8
--- src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.7	Fri May  3 07:05:28 2019
+++ src/external/gpl3/gdb/dist/gdb/nbsd-nat.c	Fri May  3 19:03:57 2019
@@ -360,6 +360,17 @@ nbsd_wait (struct target_ops *ops,
 {
   ptid_t wptid;
 
+  /*
+   * Always perform polling on exact PID, overwrite the default polling on
+   * WAIT_ANY.
+   *
+   * This avoids events reported in random order reported for FORK / VFORK
+   * when child and parent events are otherwise reported in random order.
+   *
+   * Polling on traced parent always simplifies the code.
+   */
+  ptid = inferior_ptid;
+
   if (debug_nbsd_lwp)
 fprintf_unfiltered (gdb_stdlog, "NLWP: calling super_wait (%d, %ld, %ld) target_options=%#x\n",
 ptid_get_pid (ptid), ptid_get_lwp (ptid),



CVS commit: src/external/gpl3/gdb/dist/gdb

2019-05-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri May  3 07:05:28 UTC 2019

Modified Files:
src/external/gpl3/gdb/dist/gdb: infrun.c nbsd-nat.c

Log Message:
Quick clean up the NetBSD support in GDB

Changes:

 - always perform polling on inferior_ptid, never -1
   -1 can cause catching fork/vfork events in random order
   polling on pid will guarantee to report events in expected order

 - assume availability of KERN_PROC_PATHNAME

 - drop dead code for KERN_PROC_AUXV (FreeBSD-specific sysctl)
   AUXV on NetBSD is handled with PIOD_READ_AUXV

 - drop unused nbsd_fetch_kinfo_proc

 - drop unneeded hacks for fork/vfork code

 - drop support for FreeBSD specific flags returned for PT_LWPINFO
   NetBSD uses PT_GET_SIGINFO / PT_GET_PROCESS_STATE for most pieces of
   information

 - port nbsd_thread_name to NetBSD

 - enable LWP and FORK events in nbsd_enable_proc_events

 - use NetBSD new batteries for distinguishing event type in to_wait
   map most events into GDB types
   breakpoint, single step, hw breakpoint/watchpoint ones are still not
   used with the full power here

 - add support for EXEC events

 - clean up

This change makes GDB functional with threaded code and it is good enough
to pass t_regress / threads test.

It's possible to execute and step processes with multiple threads, use
scheduler-lock, follow-fork etc features.

What does not work:

 - the LWP EXIT event and wait() are not synchronized and can deadlock
   this has been observed with exiting go applications

 - GDB VFORK code is still disabled and awaits kernel fixing

Short term goal is to correct LWP EXIT and follow up with VFORK fixes.

Long term goal is to rewrite NetBSD GDB support and write new support in
the remote process plugin (gdb-server) framework.

PR kern/53120
PR port-arm/51677
PR bin/54060
PR bin/49662
PR kern/52548


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.7 -r1.2 src/external/gpl3/gdb/dist/gdb/infrun.c
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/infrun.c
diff -u src/external/gpl3/gdb/dist/gdb/infrun.c:1.1.1.7 src/external/gpl3/gdb/dist/gdb/infrun.c:1.2
--- src/external/gpl3/gdb/dist/gdb/infrun.c:1.1.1.7	Tue Nov 28 18:18:23 2017
+++ src/external/gpl3/gdb/dist/gdb/infrun.c	Fri May  3 07:05:28 2019
@@ -3874,7 +3874,11 @@ fetch_inferior_event (void *client_data)
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   struct cleanup *ts_old_chain;
   int cmd_done = 0;
+#if defined(__NetBSD__)
+  ptid_t waiton_ptid = inferior_ptid;
+#else
   ptid_t waiton_ptid = minus_one_ptid;
+#endif
 
   memset (ecs, 0, sizeof (*ecs));
 

Index: src/external/gpl3/gdb/dist/gdb/nbsd-nat.c
diff -u src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.6 src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.7
--- src/external/gpl3/gdb/dist/gdb/nbsd-nat.c:1.6	Sat Jun 23 03:15:55 2018
+++ src/external/gpl3/gdb/dist/gdb/nbsd-nat.c	Fri May  3 07:05:28 2019
@@ -45,7 +45,6 @@ nbsd_pid_to_exec_file (struct target_ops
   static char buf[PATH_MAX];
   char name[PATH_MAX];
 
-#ifdef KERN_PROC_PATHNAME
   size_t buflen;
   int mib[4];
 
@@ -56,7 +55,6 @@ nbsd_pid_to_exec_file (struct target_ops
   buflen = sizeof buf;
   if (sysctl (mib, 4, buf, , NULL, 0) == 0)
 return buf;
-#endif
 
   xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
   len = readlink (name, buf, PATH_MAX - 1);
@@ -131,79 +129,6 @@ nbsd_find_memory_regions (struct target_
   return 0;
 }
 
-#ifdef KERN_PROC_AUXV
-static enum target_xfer_status (*super_xfer_partial) (struct target_ops *ops,
-		  enum target_object object,
-		  const char *annex,
-		  gdb_byte *readbuf,
-		  const gdb_byte *writebuf,
-		  ULONGEST offset,
-		  ULONGEST len,
-		  ULONGEST *xfered_len);
-
-/* Implement the "to_xfer_partial target_ops" method.  */
-
-static enum target_xfer_status
-nbsd_xfer_partial (struct target_ops *ops, enum target_object object,
-		   const char *annex, gdb_byte *readbuf,
-		   const gdb_byte *writebuf,
-		   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
-{
-  pid_t pid = ptid_get_pid (inferior_ptid);
-
-  switch (object)
-{
-case TARGET_OBJECT_AUXV:
-  {
-	struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
-	unsigned char *buf;
-	size_t buflen;
-	int mib[4];
-
-	if (writebuf != NULL)
-	  return TARGET_XFER_E_IO;
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_PROC;
-	mib[2] = KERN_PROC_AUXV;
-	mib[3] = pid;
-	if (offset == 0)
-	  {
-	buf = readbuf;
-	buflen = len;
-	  }
-	else
-	  {
-	buflen = offset + len;
-	buf = XCNEWVEC (unsigned char, buflen);
-	cleanup = make_cleanup (xfree, buf);
-	  }
-	if (sysctl (mib, 4, buf, , NULL, 0) == 0)
-	  {
-	if (offset != 0)
-	  {
-		if (buflen > offset)
-		  {
-		buflen -= offset;
-		memcpy (readbuf, buf + offset, 

CVS commit: src/tests/lib/libc/sys

2019-05-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu May  2 22:52:21 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Adapt t_ptrace_wait* tests for recent kernel changes

Adapt AUXV reading loop to handle io.piod_len == 0 as EOF.

Temporarily disable trace_thread_lwpcreate until it will be verified that
it is stable.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.119 src/tests/lib/libc/sys/t_ptrace_wait.c:1.120
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.119	Thu May  2 00:34:06 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu May  2 22:52:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.119 2019/05/02 00:34:06 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.120 2019/05/02 22:52:21 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.119 2019/05/02 00:34:06 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.120 2019/05/02 22:52:21 kamil Exp $");
 
 #include 
 #include 
@@ -4063,10 +4063,10 @@ bytes_transfer_alignment(const char *ope
 		errno = 0;
 		i = 0;
 		/* Read the whole AUXV vector, it has no clear length */
-		while (errno != EIO) {
+		while (io.piod_len > 0) {
 			io.piod_offs = (void *)(intptr_t)i;
 			SYSCALL_REQUIRE(ptrace(PT_IO, child, , sizeof(io))
-			!= -1 || (errno == EIO && i > 0));
+			!= -1 || (io.piod_len == 0 && i > 0));
 			++i;
 		}
 	}
@@ -5359,7 +5359,7 @@ trace_threads(bool trace_create, bool tr
 	/* Track created and exited threads */
 	bool traced_lwps[__arraycount(t)];
 
-	if (trace_exit)
+	if (trace_create || trace_exit)
 		atf_tc_skip("PR kern/51995");
 
 	DPRINTF("Before forking process PID=%d\n", getpid());



CVS commit: src/sys/kern

2019-05-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu May  2 22:23:49 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c kern_sig.c sys_lwp.c

Log Message:
Introduce fixes for ptrace(2)

Stop disabling LWP create and exit events for PT_SYSCALL tracing.
PT_SYSCALL disabled EXEC reporting for legacy reasons, there is no need
to repeat it for LWP and CHLD events.

Pass full siginfo from trapsignal events (SEGV, BUS, ILL, TRAP, FPE).
This adds missing information about signals like fault address.

Set ps_lwp always.

Before passing siginfo to userland through p_sigctx.ps_info, make sure
that it was zeroed for unused bytes. LWP and CHLD events do not set si_addr
and si_trap, these pieces of information are passed for crashes (like
software breakpoint).

LLDB crash reporting works now correctly:

(lldb) r
Process 552 launched: '/tmp/a.out' (x86_64)
Process 552 stopped
* thread #1, stop reason = signal SIGSEGV: invalid address (fault address: 
0x123456)


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.355 -r1.356 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.198 src/sys/kern/kern_lwp.c:1.199
--- src/sys/kern/kern_lwp.c:1.198	Wed May  1 21:57:34 2019
+++ src/sys/kern/kern_lwp.c	Thu May  2 22:23:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.199 2019/05/02 22:23:49 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.199 2019/05/02 22:23:49 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1079,7 +1079,7 @@ lwp_exit(struct lwp *l)
 	 */
 	mutex_enter(proc_lock);
 
-	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT|PSL_SYSCALL)) ==
+	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT)) ==
 	(PSL_TRACED|PSL_TRACELWP_EXIT)) {
 		mutex_enter(p->p_lock);
 		p->p_lwp_exited = l->l_lid;

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.355 src/sys/kern/kern_sig.c:1.356
--- src/sys/kern/kern_sig.c:1.355	Wed May  1 21:52:35 2019
+++ src/sys/kern/kern_sig.c	Thu May  2 22:23:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.355 2019/05/01 21:52:35 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.356 2019/05/02 22:23:49 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.355 2019/05/01 21:52:35 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.356 2019/05/02 22:23:49 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -913,8 +913,14 @@ trapsignal(struct lwp *l, ksiginfo_t *ks
 	mutex_enter(p->p_lock);
 
 	if (ISSET(p->p_slflag, PSL_TRACED) &&
-	!(p->p_pptr == p->p_opptr && ISSET(p->p_lflag, PL_PPWAIT))) {
-		eventswitch(signo, ksi->ksi_code);
+	!(p->p_pptr == p->p_opptr && ISSET(p->p_lflag, PL_PPWAIT)) &&
+	p->p_xsig != SIGKILL &&
+	!sigismember(>p_sigpend.sp_set, SIGKILL)) {
+		p->p_xsig = signo;
+		p->p_sigctx.ps_faked = true;
+		p->p_sigctx.ps_lwp = ksi->ksi_lid;
+		p->p_sigctx.ps_info = ksi->ksi_info;
+		sigswitch(0, signo, false);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p->p_lock);
 		return;
@@ -1556,6 +1562,8 @@ eventswitch(int signo, int code)
 
 	p->p_xsig = signo;
 	p->p_sigctx.ps_faked = true;
+	p->p_sigctx.ps_lwp = l->l_lid;
+	memset(>p_sigctx.ps_info, 0, sizeof(p->p_sigctx.ps_info));
 	p->p_sigctx.ps_info._signo = signo;
 	p->p_sigctx.ps_info._code = code;
 

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.65 src/sys/kern/sys_lwp.c:1.66
--- src/sys/kern/sys_lwp.c:1.65	Wed May  1 22:55:55 2019
+++ src/sys/kern/sys_lwp.c	Thu May  2 22:23:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.65 2019/05/01 22:55:55 kamil Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.66 2019/05/02 22:23:49 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.65 2019/05/01 22:55:55 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.66 2019/05/02 22:23:49 kamil Exp $");
 
 #include 
 #include 
@@ -78,12 +78,12 @@ mi_startlwp(void *arg)
 	(p->p_emul->e_startlwp)(arg);
 
 	/* If the process is traced, report lwp creation to a debugger */
-	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
+	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE)) ==
 	(PSL_TRACED|PSL_TRACELWP_CREATE)) {
 		/* Paranoid check */
 		mutex_enter(proc_lock);
-		if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) !=
-		

CVS commit: src/tests/lib/libc/sys

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu May  2 00:34:06 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Rename and partially enable trace_thread ATF ptrace(2) tests

Rename trace_thrad[1234] to more meaningful names:

 - trace_thread_nolwpevents
 - trace_thread_lwpexit
 - trace_thread_lwpcreate
 - trace_thread_lwpcreate_and_exit

In my local tests LWP CREATE events work as expected.
LWP EXIT ones are still racy and keep them disabled racy.

PR kern/51995


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.118 src/tests/lib/libc/sys/t_ptrace_wait.c:1.119
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.118	Wed May  1 23:44:16 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu May  2 00:34:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.118 2019/05/01 23:44:16 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.119 2019/05/02 00:34:06 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.118 2019/05/01 23:44:16 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.119 2019/05/02 00:34:06 kamil Exp $");
 
 #include 
 #include 
@@ -5359,7 +5359,8 @@ trace_threads(bool trace_create, bool tr
 	/* Track created and exited threads */
 	bool traced_lwps[__arraycount(t)];
 
-	atf_tc_skip("PR kern/51995");
+	if (trace_exit)
+		atf_tc_skip("PR kern/51995");
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
@@ -5532,10 +5533,10 @@ ATF_TC_BODY(test, tc)			\
 trace_threads(trace_create, trace_exit);			\
 }
 
-TRACE_THREADS(trace_thread1, false, false)
-TRACE_THREADS(trace_thread2, false, true)
-TRACE_THREADS(trace_thread3, true, false)
-TRACE_THREADS(trace_thread4, true, true)
+TRACE_THREADS(trace_thread_nolwpevents, false, false)
+TRACE_THREADS(trace_thread_lwpexit, false, true)
+TRACE_THREADS(trace_thread_lwpcreate, true, false)
+TRACE_THREADS(trace_thread_lwpcreate_and_exit, true, true)
 
 /// 
 
@@ -7772,10 +7773,10 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, traceme_signalmasked_exec);
 	ATF_TP_ADD_TC(tp, traceme_signalignored_exec);
 
-	ATF_TP_ADD_TC(tp, trace_thread1);
-	ATF_TP_ADD_TC(tp, trace_thread2);
-	ATF_TP_ADD_TC(tp, trace_thread3);
-	ATF_TP_ADD_TC(tp, trace_thread4);
+	ATF_TP_ADD_TC(tp, trace_thread_nolwpevents);
+	ATF_TP_ADD_TC(tp, trace_thread_lwpexit);
+	ATF_TP_ADD_TC(tp, trace_thread_lwpcreate);
+	ATF_TP_ADD_TC(tp, trace_thread_lwpcreate_and_exit);
 
 	ATF_TP_ADD_TC(tp, signal_mask_unrelated);
 



CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu May  2 00:23:01 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Allow cancelled byte transfer in ptrace(2) again

Current GDB depends on it on NetBSD (which is probably a GDB support bug).

In future GDB will be examined for this and this code revisited.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.51 src/sys/kern/sys_ptrace_common.c:1.52
--- src/sys/kern/sys_ptrace_common.c:1.51	Wed May  1 17:02:40 2019
+++ src/sys/kern/sys_ptrace_common.c	Thu May  2 00:23:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.52 2019/05/02 00:23:01 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.52 2019/05/02 00:23:01 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1106,10 +1106,12 @@ do_ptrace(struct ptrace_methods *ptm, st
 		piod.piod_op = write ? PIOD_WRITE_D : PIOD_READ_D;
 		if ((error = ptrace_doio(l, t, lt, , addr, true)) != 0)
 			break;
+#if 0 // XXX: GDB depends on it
 		if (piod.piod_len < sizeof(tmp)) {
 			error = EIO;
 			break;
 		}
+#endif
 		if (!write)
 			*retval = tmp;
 		break;
@@ -1123,10 +1125,12 @@ do_ptrace(struct ptrace_methods *ptm, st
 		}
 		if ((error = ptrace_doio(l, t, lt, , addr, false)) != 0)
 			break;
+#if 0 // XXX: GDB depends on it
 		if (piod.piod_len < 1) {
 			error = EIO;
 			break;
 		}
+#endif
 		error = ptm->ptm_copyout_piod(, addr, data);
 		break;
 



CVS commit: src/tests/lib/libc/sys

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 23:44:16 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
ATF ptrace(2) tests suspend1 and resume1 now pass

Verified on bare metal and in qemu.

PR kern/51995


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.117 src/tests/lib/libc/sys/t_ptrace_wait.c:1.118
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.117	Wed May  1 21:59:32 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May  1 23:44:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.117 2019/05/01 21:59:32 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.118 2019/05/01 23:44:16 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.117 2019/05/01 21:59:32 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.118 2019/05/01 23:44:16 kamil Exp $");
 
 #include 
 #include 
@@ -6228,12 +6228,6 @@ ATF_TC_BODY(suspend1, tc)
 	struct ptrace_siginfo psi;
 	volatile int go = 0;
 
-	// Feature pending for refactoring
-	atf_tc_expect_fail("PR kern/51995");
-
-	// Hangs with qemu
-	ATF_REQUIRE(0 && "In order to get reliable failure, abort");
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -6355,12 +6349,6 @@ ATF_TC_BODY(suspend2, tc)
 #endif
 	struct ptrace_siginfo psi;
 
-	// Feature pending for refactoring
-	atf_tc_expect_fail("PR kern/51995");
-
-	// Hangs with qemu
-	ATF_REQUIRE(0 && "In order to get reliable failure, abort");
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -6412,7 +6400,6 @@ ATF_TC_BODY(suspend2, tc)
 ATF_TC(resume1);
 ATF_TC_HEAD(resume1, tc)
 {
-	atf_tc_set_md_var(tc, "timeout", "5");
 	atf_tc_set_md_var(tc, "descr",
 	"Verify that a thread can be suspended by a debugger and later "
 	"resumed by the debugger");
@@ -6435,12 +6422,6 @@ ATF_TC_BODY(resume1, tc)
 	struct ptrace_lwpinfo pl;
 	struct ptrace_siginfo psi;
 
-	// Feature pending for refactoring
-	atf_tc_expect_fail("PR kern/51995");
-
-	// Hangs with qemu
-	ATF_REQUIRE(0 && "In order to get reliable failure, abort");
-
 	SYSCALL_REQUIRE(msg_open() == 0);
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -6543,9 +6524,6 @@ ATF_TC_BODY(resume1, tc)
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 
 	msg_close();
-
-	DPRINTF("XXX: Test worked this time but for consistency timeout it\n");
-	sleep(10);
 }
 
 ATF_TC(syscall1);



CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 22:55:55 UTC 2019

Modified Files:
src/sys/kern: sys_lwp.c

Log Message:
Call MD code in mi_startlwp() before MI check for debugger

This allows to get initialized mcontext.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.64 src/sys/kern/sys_lwp.c:1.65
--- src/sys/kern/sys_lwp.c:1.64	Wed May  1 21:57:34 2019
+++ src/sys/kern/sys_lwp.c	Wed May  1 22:55:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.65 2019/05/01 22:55:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.65 2019/05/01 22:55:55 kamil Exp $");
 
 #include 
 #include 
@@ -75,6 +75,8 @@ mi_startlwp(void *arg)
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
 
+	(p->p_emul->e_startlwp)(arg);
+
 	/* If the process is traced, report lwp creation to a debugger */
 	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
 	(PSL_TRACED|PSL_TRACELWP_CREATE)) {
@@ -83,7 +85,7 @@ mi_startlwp(void *arg)
 		if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) !=
 		(PSL_TRACED|PSL_TRACELWP_CREATE)) {
 			mutex_exit(proc_lock);
-			goto my_tracer_is_gone;
+			return;
 		}
 
 		mutex_enter(p->p_lock);
@@ -92,9 +94,6 @@ mi_startlwp(void *arg)
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p->p_lock);
 	}
-
-my_tracer_is_gone:
-	(p->p_emul->e_startlwp)(arg);
 }
 
 int



CVS commit: src/tests/lib/libc/sys

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 21:59:32 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
ATF ptrace(2) tests signal9 and signal10 now pass

PR kern/51918


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.116 src/tests/lib/libc/sys/t_ptrace_wait.c:1.117
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.116	Wed May  1 18:20:23 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May  1 21:59:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.116 2019/05/01 18:20:23 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.117 2019/05/01 21:59:32 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.116 2019/05/01 18:20:23 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.117 2019/05/01 21:59:32 kamil Exp $");
 
 #include 
 #include 
@@ -6017,8 +6017,6 @@ ATF_TC_BODY(signal9, tc)
 	static const size_t ssize = 16*1024;
 	void *stack;
 
-	atf_tc_expect_fail("PR kern/51918");
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {
@@ -6121,8 +6119,6 @@ ATF_TC_BODY(signal10, tc)
 	static const size_t ssize = 16*1024;
 	void *stack;
 
-	atf_tc_expect_fail("PR kern/51918");
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {



CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 21:57:35 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c sys_lwp.c

Log Message:
Correct passing debugger related events for LWP create and exit

Add MI toplevel startlwp function.

Switch all userland LWPs to go through lwp_create using a shared
mi_startlwp() function between all MD ABIs.

Add debugger related event handling in mi_startlwp() and continue with
standard p->p_emul->e_startlwp at the end of this routine.

Use eventswitch() to notify the event of LWP exit in lwp_exit().

ATF ptrace(2) tests signal9 and signal10 now pass.


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.63 -r1.64 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.197 src/sys/kern/kern_lwp.c:1.198
--- src/sys/kern/kern_lwp.c:1.197	Fri Apr 19 01:52:55 2019
+++ src/sys/kern/kern_lwp.c	Wed May  1 21:57:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -969,24 +969,6 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 	if (p2->p_emul->e_lwp_fork)
 		(*p2->p_emul->e_lwp_fork)(l1, l2);
 
-	/* If the process is traced, report lwp creation to a debugger */
-	if ((p2->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
-	(PSL_TRACED|PSL_TRACELWP_CREATE)) {
-		ksiginfo_t ksi;
-
-		/* Tracing */
-		KASSERT((l2->l_flag & LW_SYSTEM) == 0);
-
-		p2->p_lwp_created = l2->l_lid;
-
-		KSI_INIT_EMPTY();
-		ksi.ksi_signo = SIGTRAP;
-		ksi.ksi_code = TRAP_LWP;
-		mutex_enter(proc_lock);
-		kpsignal(p2, , NULL);
-		mutex_exit(proc_lock);
-	}
-
 	return (0);
 }
 
@@ -1050,24 +1032,6 @@ lwp_exit(struct lwp *l)
 	 */
 	LOCKDEBUG_BARRIER(_lock, 0);
 
-	/* If the process is traced, report lwp termination to a debugger */
-	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT|PSL_SYSCALL)) ==
-	(PSL_TRACED|PSL_TRACELWP_EXIT)) {
-		ksiginfo_t ksi;
-
-		/* Tracing */
-		KASSERT((l->l_flag & LW_SYSTEM) == 0);
-
-		p->p_lwp_exited = l->l_lid;
-
-		KSI_INIT_EMPTY();
-		ksi.ksi_signo = SIGTRAP;
-		ksi.ksi_code = TRAP_LWP;
-		mutex_enter(proc_lock);
-		kpsignal(p, , NULL);
-		mutex_exit(proc_lock);
-	}
-
 	/*
 	 * If we are the last live LWP in a process, we need to exit the
 	 * entire process.  We do so with an exit status of zero, because
@@ -1108,10 +1072,23 @@ lwp_exit(struct lwp *l)
 	callout_destroy(>l_timeout_ch);
 
 	/*
+	 * If traced, report LWP exit event to the debugger.
+	 *
 	 * Remove the LWP from the global list.
 	 * Free its LID from the PID namespace if needed.
 	 */
 	mutex_enter(proc_lock);
+
+	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT|PSL_SYSCALL)) ==
+	(PSL_TRACED|PSL_TRACELWP_EXIT)) {
+		mutex_enter(p->p_lock);
+		p->p_lwp_exited = l->l_lid;
+		eventswitch(SIGTRAP, TRAP_LWP);
+		// XXX ktrpoint(KTR_PSIG)
+		mutex_exit(p->p_lock);
+		mutex_enter(proc_lock);
+	}
+
 	LIST_REMOVE(l, l_list);
 	if ((l->l_pflag & LP_PIDLID) != 0 && l->l_lid != p->p_pid) {
 		proc_free_pid(l->l_lid);

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.63 src/sys/kern/sys_lwp.c:1.64
--- src/sys/kern/sys_lwp.c:1.63	Tue Jan 30 07:52:23 2018
+++ src/sys/kern/sys_lwp.c	Wed May  1 21:57:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.63 2018/01/30 07:52:23 ozaki-r Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.63 2018/01/30 07:52:23 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $");
 
 #include 
 #include 
@@ -69,6 +69,34 @@ lwp_sys_init(void)
 	sleeptab_init(_park_tab);
 }
 
+static void
+mi_startlwp(void *arg)
+{
+	struct lwp *l = curlwp;
+	struct proc *p = l->l_proc;
+
+	/* If the process is traced, report lwp creation to a debugger */
+	if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
+	(PSL_TRACED|PSL_TRACELWP_CREATE)) {
+		/* Paranoid check */
+		mutex_enter(proc_lock);
+		if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) !=
+		(PSL_TRACED|PSL_TRACELWP_CREATE)) {
+			mutex_exit(proc_lock);
+			goto my_tracer_is_gone;
+		}
+
+		mutex_enter(p->p_lock);
+		p->p_lwp_created = l->l_lid;
+		eventswitch(SIGTRAP, TRAP_LWP);
+		// XXX ktrpoint(KTR_PSIG)
+		mutex_exit(p->p_lock);
+	}
+
+my_tracer_is_gone:
+	

CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 21:52:35 UTC 2019

Modified Files:
src/sys/kern: kern_sig.c

Log Message:
Assert that debugger event is triggered only for userland LWP

All passing ATF ptrace(2) tests still pass.


To generate a diff of this commit:
cvs rdiff -u -r1.354 -r1.355 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.354 src/sys/kern/kern_sig.c:1.355
--- src/sys/kern/kern_sig.c:1.354	Wed May  1 18:01:54 2019
+++ src/sys/kern/kern_sig.c	Wed May  1 21:52:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.354 2019/05/01 18:01:54 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.355 2019/05/01 21:52:35 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.354 2019/05/01 18:01:54 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.355 2019/05/01 21:52:35 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -1542,6 +1542,7 @@ eventswitch(int signo, int code)
 	KASSERT(mutex_owned(proc_lock));
 	KASSERT(mutex_owned(p->p_lock));
 	KASSERT(l->l_stat == LSONPROC);
+	KASSERT((l->l_flag & LW_SYSTEM) == 0);
 	KASSERT(p->p_nrlwps > 0);
 
 	/*



CVS commit: src/tests/lib/libc/sys

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 18:20:23 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new fork/vfork ATF trests in t_ptrace_wait*

Add new tests:

 - fork_detach_forker
 - vfork_detach_vforker
 - vfork_detach_vforkerdone
 - fork_kill_forker
 - vfork_kill_vforker
 - vfork_kill_vforkerdone

All tests pass with recent kernel changes.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.115 src/tests/lib/libc/sys/t_ptrace_wait.c:1.116
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.115	Tue Apr 30 22:39:31 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed May  1 18:20:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.115 2019/04/30 22:39:31 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.116 2019/05/01 18:20:23 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.115 2019/04/30 22:39:31 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.116 2019/05/01 18:20:23 kamil Exp $");
 
 #include 
 #include 
@@ -3199,6 +3199,187 @@ FORK_TEST(vfork8, vfork, true, true, tru
 
 /// 
 
+#if defined(TWAIT_HAVE_PID)
+static void
+fork_detach_forker_body(bool detachfork, bool detachvfork,
+bool detachvforkdone, bool kill_process)
+{
+	const int exitval = 5;
+	const int exitval2 = 15;
+	const int sigval = SIGSTOP;
+	pid_t child, child2 = 0, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	ptrace_state_t state;
+	const int slen = sizeof(state);
+	ptrace_event_t event;
+	const int elen = sizeof(event);
+
+	pid_t (*fn)(void);
+	int op;
+
+	ATF_REQUIRE((detachfork && !detachvfork && !detachvforkdone) ||
+	(!detachfork && detachvfork && !detachvforkdone) ||
+	(!detachfork && !detachvfork && detachvforkdone));
+
+	if (detachfork)
+		fn = fork;
+	else
+		fn = vfork;
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = fork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		FORKEE_ASSERT((child2 = (fn)()) != -1);
+
+		if (child2 == 0)
+			_exit(exitval2);
+
+		FORKEE_REQUIRE_SUCCESS
+		(wpid = TWAIT_GENERIC(child2, , 0), child2);
+
+		forkee_status_exited(status, exitval2);
+
+		DPRINTF("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	DPRINTF("Set EVENT_MASK for the child %d\n", child);
+	event.pe_set_event = PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE;
+	SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1);
+
+	DPRINTF("Before resuming the child process where it left off and "
+	"without signal to be sent\n");
+	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+	DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, SIGTRAP);
+
+	SYSCALL_REQUIRE(
+	ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
+	op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+	ATF_REQUIRE_EQ(state.pe_report_event & op, op);
+
+	child2 = state.pe_other_pid;
+	DPRINTF("Reported ptrace event with forkee %d\n", child2);
+
+	if (detachfork || detachvfork)
+		op = kill_process ? PT_KILL : PT_DETACH;
+	else
+		op = PT_CONTINUE;
+	SYSCALL_REQUIRE(ptrace(op, child, (void *)1, 0) != -1);
+
+	DPRINTF("Before calling %s() for the forkee %d of the child %d\n",
+	TWAIT_FNAME, child2, child);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, , 0), child2);
+
+	validate_status_stopped(status, SIGTRAP);
+
+	SYSCALL_REQUIRE(
+	ptrace(PT_GET_PROCESS_STATE, child2, , slen) != -1);
+	op = (fn == fork) ? PTRACE_FORK : PTRACE_VFORK;
+	ATF_REQUIRE_EQ(state.pe_report_event & op, op);
+	ATF_REQUIRE_EQ(state.pe_other_pid, child);
+
+	DPRINTF("Before resuming the forkee process where it left off "
+	"and without signal to be sent\n");
+ 	SYSCALL_REQUIRE(
+	ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
+
+	if (detachvforkdone && fn == vfork) {
+		DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
+		child);
+		TWAIT_REQUIRE_SUCCESS(
+		wpid = TWAIT_GENERIC(child, , 0), child);
+
+		

CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 18:01:54 UTC 2019

Modified Files:
src/sys/kern: kern_fork.c kern_sig.c

Log Message:
Correct handling of corner cases in fork1(9) code under a debugger

Correct detaching and SIGKILLing forker and vforker in the middle of its
operation.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/sys/kern/kern_fork.c
cvs rdiff -u -r1.353 -r1.354 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.210 src/sys/kern/kern_fork.c:1.211
--- src/sys/kern/kern_fork.c:1.210	Wed May  1 17:21:55 2019
+++ src/sys/kern/kern_fork.c	Wed May  1 18:01:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -203,6 +203,30 @@ sys___clone(struct lwp *l, const struct 
  */
 static struct timeval fork_tfmrate = { 10, 0 };
 
+static inline bool
+tracefork(struct proc *p, int flags)
+{
+
+	return (p->p_slflag & (PSL_TRACEFORK|PSL_TRACED)) ==
+	(PSL_TRACEFORK|PSL_TRACED) && (flags & FORK_PPWAIT) == 0;
+}
+
+static inline bool
+tracevfork(struct proc *p, int flags)
+{
+
+	return (p->p_slflag & (PSL_TRACEVFORK|PSL_TRACED)) ==
+	(PSL_TRACEVFORK|PSL_TRACED) && (flags & FORK_PPWAIT) != 0;
+}
+
+static inline bool
+tracevforkdone(struct proc *p, int flags)
+{
+
+	return (p->p_slflag & (PSL_TRACEVFORK_DONE|PSL_TRACED)) ==
+	(PSL_TRACEVFORK_DONE|PSL_TRACED) && (flags & FORK_PPWAIT);
+}
+
 /*
  * General fork call.  Note that another LWP in the process may call exec()
  * or exit() while we are forking.  It's safe to continue here, because
@@ -219,7 +243,7 @@ fork1(struct lwp *l1, int flags, int exi
 	int		count;
 	vaddr_t		uaddr;
 	int		tnprocs;
-	int		tracefork, tracevfork, tracevforkdone;
+	bool		trace_fork, trace_vfork;
 	int		error = 0;
 
 	p1 = l1->l_proc;
@@ -477,19 +501,15 @@ fork1(struct lwp *l1, int flags, int exi
 	/*
 	 * Trace fork(2) and vfork(2)-like events on demand in a debugger.
 	 */
-	tracefork = (p1->p_slflag & (PSL_TRACEFORK|PSL_TRACED)) ==
-	(PSL_TRACEFORK|PSL_TRACED) && (flags & FORK_PPWAIT) == 0;
-	tracevfork = (p1->p_slflag & (PSL_TRACEVFORK|PSL_TRACED)) ==
-	(PSL_TRACEVFORK|PSL_TRACED) && (flags & FORK_PPWAIT) != 0;
-	tracevforkdone = (p1->p_slflag & (PSL_TRACEVFORK_DONE|PSL_TRACED)) ==
-	(PSL_TRACEVFORK_DONE|PSL_TRACED) && (flags & FORK_PPWAIT);
-	if (tracefork || tracevfork)
+	trace_fork = tracefork(p1, flags);
+	trace_vfork = tracevfork(p1, flags);
+	if (trace_fork || trace_vfork)
 		proc_changeparent(p2, p1->p_pptr);
-	if (tracefork) {
+	if (trace_fork) {
 		p1->p_fpid = p2->p_pid;
 		p2->p_fpid = p1->p_pid;
 	}
-	if (tracevfork) {
+	if (trace_vfork) {
 		p1->p_vfpid = p2->p_pid;
 		p2->p_vfpid = p1->p_pid;
 	}
@@ -573,7 +593,7 @@ fork1(struct lwp *l1, int flags, int exi
 	/*
 	 * Let the parent know that we are tracing its child.
 	 */
-	if (tracefork || tracevfork) {
+	if (tracefork(p1, flags) || tracevfork(p1, flags)) {
 		mutex_enter(p1->p_lock);
 		eventswitch(SIGTRAP, TRAP_CHLD);
 		// XXX ktrpoint(KTR_PSIG)
@@ -591,7 +611,7 @@ fork1(struct lwp *l1, int flags, int exi
 	/*
 	 * Let the parent know that we are tracing its child.
 	 */
-	if (tracevforkdone) {
+	if (tracevforkdone(p1, flags)) {
 		mutex_enter(p1->p_lock);
 		p1->p_vfpid_done = retval[0];
 		eventswitch(SIGTRAP, TRAP_CHLD);

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.353 src/sys/kern/kern_sig.c:1.354
--- src/sys/kern/kern_sig.c:1.353	Wed May  1 17:21:55 2019
+++ src/sys/kern/kern_sig.c	Wed May  1 18:01:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.354 2019/05/01 18:01:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.354 2019/05/01 18:01:54 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -1544,6 +1544,15 @@ eventswitch(int signo, int code)
 	KASSERT(l->l_stat == LSONPROC);
 	KASSERT(p->p_nrlwps > 0);
 
+	/*
+	 * If there's a pending SIGKILL process it immediately.
+	 */
+	if (p->p_xsig == SIGKILL ||
+	sigismember(>p_sigpend.sp_set, SIGKILL)) {
+		mutex_exit(proc_lock);
+		return;
+	}
+
 	p->p_xsig = signo;
 	p->p_sigctx.ps_faked = true;
 	p->p_sigctx.ps_info._signo = signo;



CVS commit: src/sys

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 17:21:55 UTC 2019

Modified Files:
src/sys/kern: kern_exec.c kern_fork.c kern_sig.c
src/sys/sys: signalvar.h

Log Message:
Add eventswitch() in signal code

Route all crash and debugger related signal through eventswitch(), that
calls sigswitch() with preprocessed arguments.

This code avoids code duplication and allows to introduce changes that
will affect all callers of sigswitch() in debugger-related events.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.462 -r1.463 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.209 -r1.210 src/sys/kern/kern_fork.c
cvs rdiff -u -r1.352 -r1.353 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.91 -r1.92 src/sys/sys/signalvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.462 src/sys/kern/kern_exec.c:1.463
--- src/sys/kern/kern_exec.c:1.462	Sun Nov 11 10:55:58 2018
+++ src/sys/kern/kern_exec.c	Wed May  1 17:21:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1271,11 +1271,7 @@ execve_runproc(struct lwp *l, struct exe
 
 	if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) {
 		mutex_enter(p->p_lock);
-		p->p_xsig = SIGTRAP;
-		p->p_sigctx.ps_faked = true; // XXX
-		p->p_sigctx.ps_info._signo = p->p_xsig;
-		p->p_sigctx.ps_info._code = TRAP_EXEC;
-		sigswitch(0, SIGTRAP, false);
+		eventswitch(SIGTRAP, TRAP_EXEC);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p->p_lock);
 		mutex_enter(proc_lock);

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.209 src/sys/kern/kern_fork.c:1.210
--- src/sys/kern/kern_fork.c:1.209	Sun Apr  7 14:50:41 2019
+++ src/sys/kern/kern_fork.c	Wed May  1 17:21:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -575,11 +575,7 @@ fork1(struct lwp *l1, int flags, int exi
 	 */
 	if (tracefork || tracevfork) {
 		mutex_enter(p1->p_lock);
-		p1->p_xsig = SIGTRAP;
-		p1->p_sigctx.ps_faked = true; // XXX
-		p1->p_sigctx.ps_info._signo = p1->p_xsig;
-		p1->p_sigctx.ps_info._code = TRAP_CHLD;
-		sigswitch(0, SIGTRAP, false);
+		eventswitch(SIGTRAP, TRAP_CHLD);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p1->p_lock);
 		mutex_enter(proc_lock);
@@ -597,12 +593,8 @@ fork1(struct lwp *l1, int flags, int exi
 	 */
 	if (tracevforkdone) {
 		mutex_enter(p1->p_lock);
-		p1->p_xsig = SIGTRAP;
-		p1->p_sigctx.ps_faked = true; // XXX
-		p1->p_sigctx.ps_info._signo = p1->p_xsig;
-		p1->p_sigctx.ps_info._code = TRAP_CHLD;
 		p1->p_vfpid_done = retval[0];
-		sigswitch(0, SIGTRAP, false);
+		eventswitch(SIGTRAP, TRAP_CHLD);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p1->p_lock);
 		// proc_lock unlocked
@@ -627,11 +619,7 @@ child_return(void *arg)
 		}
 
 		mutex_enter(p->p_lock);
-		p->p_xsig = SIGTRAP;
-		p->p_sigctx.ps_faked = true; // XXX
-		p->p_sigctx.ps_info._signo = p->p_xsig;
-		p->p_sigctx.ps_info._code = TRAP_CHLD;
-		sigswitch(0, SIGTRAP, false);
+		eventswitch(SIGTRAP, TRAP_CHLD);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p->p_lock);
 	}

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.352 src/sys/kern/kern_sig.c:1.353
--- src/sys/kern/kern_sig.c:1.352	Wed Apr  3 08:34:33 2019
+++ src/sys/kern/kern_sig.c	Wed May  1 17:21:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.352 2019/04/03 08:34:33 kamil Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.352 2019/04/03 08:34:33 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -914,11 +914,7 @@ trapsignal(struct lwp *l, ksiginfo_t *ks
 
 	if (ISSET(p->p_slflag, PSL_TRACED) &&
 	!(p->p_pptr == p->p_opptr && ISSET(p->p_lflag, PL_PPWAIT))) {
-		p->p_xsig = signo;
-		p->p_sigctx.ps_faked = true; // XXX
-		p->p_sigctx.ps_info._signo = signo;
-		p->p_sigctx.ps_info._code = 

CVS commit: src/sys/kern

2019-05-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed May  1 17:02:40 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Disallow resuming program with PC=0x0 in ptrace(2)

If the address parameter is 0, report error.
It's a popular mistake to set Program Counter to 0x0.
In certain kernels this is allowable parameter and causes
portability issue.

Disallow explicitly zeroed PC, instead of triggering
a harder to debug crash later.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.50 src/sys/kern/sys_ptrace_common.c:1.51
--- src/sys/kern/sys_ptrace_common.c:1.50	Tue Apr 30 22:32:01 2019
+++ src/sys/kern/sys_ptrace_common.c	Wed May  1 17:02:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.50 2019/04/30 22:32:01 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.50 2019/04/30 22:32:01 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.51 2019/05/01 17:02:40 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1246,6 +1246,21 @@ do_ptrace(struct ptrace_methods *ptm, st
 			}
 		}
 
+		/*
+		 * If the address parameter is 0, report error.
+		 *
+		 * It's a popular mistake to set Program Counter to 0x0.
+		 * In certain kernels this is allowable parameter and causes
+		 * portability issue.
+		 *
+		 * Disallow explicitly zeroed PC, instead of triggering
+		 * a harder to debug crash later.
+		 */
+		if (addr == 0) {
+			error = EINVAL;
+			break;
+		}
+
 		/* If the address parameter is not (int *)1, set the pc. */
 		if ((int *)addr != (int *)1) {
 			error = process_set_pc(lt, addr);



CVS commit: src/tests/lib/libc/sys

2019-04-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Apr 30 22:39:31 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new ATF ptrace(2) tests: bytes_transfer_eof

Assert that error is returned after attempt to read or write post EOF.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.114 src/tests/lib/libc/sys/t_ptrace_wait.c:1.115
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.114	Thu Apr 25 19:15:23 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Apr 30 22:39:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.115 2019/04/30 22:39:31 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.115 2019/04/30 22:39:31 kamil Exp $");
 
 #include 
 #include 
@@ -3931,6 +3931,157 @@ BYTES_TRANSFER_ALIGNMENT(bytes_transfer_
 
 /// 
 
+static void
+bytes_transfer_eof(const char *operation)
+{
+	const int exitval = 5;
+	const int sigval = SIGSTOP;
+	pid_t child, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	FILE *fp;
+	char *p;
+	int vector;
+	int op;
+
+	struct ptrace_io_desc io;
+	struct ptrace_siginfo info;
+
+	memset(, 0, sizeof(io));
+	memset(, 0, sizeof(info));
+
+	vector = 0;
+
+	fp = tmpfile();
+	ATF_REQUIRE(fp != NULL);
+
+	p = mmap(0, 1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
+	ATF_REQUIRE(p != MAP_FAILED);
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = fork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		DPRINTF("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n");
+	SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info))
+		!= -1);
+
+	DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid);
+	DPRINTF("Signal properties: si_signo=%#x si_code=%#x "
+		"si_errno=%#x\n",
+		info.psi_siginfo.si_signo, info.psi_siginfo.si_code,
+		info.psi_siginfo.si_errno);
+
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval);
+	ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP);
+
+	if (strcmp(operation, "PT_READ_I") == 0 ||
+	strcmp(operation, "PT_READ_D") == 0) {
+		if (strcmp(operation, "PT_READ_I"))
+			op = PT_READ_I;
+		else
+			op = PT_READ_D;
+
+		errno = 0;
+		SYSCALL_REQUIRE(ptrace(op, child, p, 0) == -1);
+		ATF_REQUIRE_EQ(errno, EINVAL);
+	} else if (strcmp(operation, "PT_WRITE_I") == 0 ||
+	   strcmp(operation, "PT_WRITE_D") == 0) {
+		if (strcmp(operation, "PT_WRITE_I"))
+			op = PT_WRITE_I;
+		else
+			op = PT_WRITE_D;
+
+		errno = 0;
+		SYSCALL_REQUIRE(ptrace(op, child, p, vector) == -1);
+		ATF_REQUIRE_EQ(errno, EINVAL);
+	} else if (strcmp(operation, "PIOD_READ_I") == 0 ||
+	   strcmp(operation, "PIOD_READ_D") == 0) {
+		if (strcmp(operation, "PIOD_READ_I"))
+			op = PIOD_READ_I;
+		else
+			op = PIOD_READ_D;
+
+		io.piod_op = op;
+		io.piod_addr = 
+		io.piod_len = sizeof(int);
+		io.piod_offs = p;
+
+		errno = 0;
+		SYSCALL_REQUIRE(ptrace(PT_IO, child, , sizeof(io)) == -1);
+		ATF_REQUIRE_EQ(errno, EINVAL);
+	} else if (strcmp(operation, "PIOD_WRITE_I") == 0 ||
+	   strcmp(operation, "PIOD_WRITE_D") == 0) {
+		if (strcmp(operation, "PIOD_WRITE_I"))
+			op = PIOD_WRITE_I;
+		else
+			op = PIOD_WRITE_D;
+
+		io.piod_op = op;
+		io.piod_addr = 
+		io.piod_len = sizeof(int);
+		io.piod_offs = p;
+
+		errno = 0;
+		SYSCALL_REQUIRE(ptrace(PT_IO, child, , sizeof(io)) == -1);
+		ATF_REQUIRE_EQ(errno, EINVAL);
+	}
+
+	DPRINTF("Before resuming the child process where it left off "
+	"and without signal to be sent\n");
+	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0),
+	child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+
+#define BYTES_TRANSFER_EOF(test, operation)\

CVS commit: src/sys/kern

2019-04-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Apr 30 22:32:01 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Reject ptrace(2) PIOD_READ/WRITE operations with length 0

Return EINVAL for such invalid requests.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.49 src/sys/kern/sys_ptrace_common.c:1.50
--- src/sys/kern/sys_ptrace_common.c:1.49	Tue Apr 30 20:50:30 2019
+++ src/sys/kern/sys_ptrace_common.c	Tue Apr 30 22:32:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.50 2019/04/30 22:32:01 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.50 2019/04/30 22:32:01 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1117,6 +1117,10 @@ do_ptrace(struct ptrace_methods *ptm, st
 	case PT_IO:
 		if ((error = ptm->ptm_copyin_piod(, addr, data)) != 0)
 			break;
+		if (piod.piod_len < 1) {
+			error = EINVAL;
+			break;
+		}
 		if ((error = ptrace_doio(l, t, lt, , addr, false)) != 0)
 			break;
 		if (piod.piod_len < 1) {



CVS commit: src/sys/kern

2019-04-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Apr 30 20:50:30 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Return EIO for empty memory transfer from ptrace(2)

Certain operations of PT_READ/PT_WRITE and PIOD_READ/PIOD_WRITE can result
in 0 byte transfer and the ptrace(2) call still returned success.

GDB had a special handling of this case for PT_IO checking piod_len != 0,
but in LLDB this corner case caused infinite loop and breakage. The LLDB
case has been enhanced.

Unfortunately the status of operation of PT_READ/PT_WRITE is not
distinguishable between successful operation and empty opeartion. This
renders this call into a questionable one.

Change the behavior and return error with EIO in scenarios of
truncated/empty byte transfers by PT_READ/PT_WRITE and empty byte transfers
from PT_IO.

No code changed is needed in GDB and LLDB.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.48 src/sys/kern/sys_ptrace_common.c:1.49
--- src/sys/kern/sys_ptrace_common.c:1.48	Fri Apr 26 08:38:25 2019
+++ src/sys/kern/sys_ptrace_common.c	Tue Apr 30 20:50:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.48 2019/04/26 08:38:25 pgoyette Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.48 2019/04/26 08:38:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.49 2019/04/30 20:50:30 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1106,6 +1106,10 @@ do_ptrace(struct ptrace_methods *ptm, st
 		piod.piod_op = write ? PIOD_WRITE_D : PIOD_READ_D;
 		if ((error = ptrace_doio(l, t, lt, , addr, true)) != 0)
 			break;
+		if (piod.piod_len < sizeof(tmp)) {
+			error = EIO;
+			break;
+		}
 		if (!write)
 			*retval = tmp;
 		break;
@@ -1115,6 +1119,10 @@ do_ptrace(struct ptrace_methods *ptm, st
 			break;
 		if ((error = ptrace_doio(l, t, lt, , addr, false)) != 0)
 			break;
+		if (piod.piod_len < 1) {
+			error = EIO;
+			break;
+		}
 		error = ptm->ptm_copyout_piod(, addr, data);
 		break;
 



CVS commit: src/lib/libpthread

2019-04-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Apr 29 20:11:44 UTC 2019

Modified Files:
src/lib/libpthread: thrd.c

Log Message:
Avoid incompatible function pointer casts in thrd_create(3)

Use an intermediate function trampoline to workaround different function
pointer prototypes.

While there, correct scenario returning thrd_nomem from thrd_create(3).
In practice ENOMEM is rarely returned from pthread(3).

Older code worked on tested ports, but was depending on unneeded UB.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/thrd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/thrd.c
diff -u src/lib/libpthread/thrd.c:1.2 src/lib/libpthread/thrd.c:1.3
--- src/lib/libpthread/thrd.c:1.2	Wed Apr 24 18:47:54 2019
+++ src/lib/libpthread/thrd.c	Mon Apr 29 20:11:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
+/*	$NetBSD: thrd.c,v 1.3 2019/04/29 20:11:43 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,30 +30,67 @@
  */
 
 #include 
-__RCSID("$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $");
+__RCSID("$NetBSD: thrd.c,v 1.3 2019/04/29 20:11:43 kamil Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
+struct __thrd_tramp_data {
+	thrd_start_t func;
+	void *arg;
+};
+
+static void *
+__thrd_create_tramp(void *arg)
+{
+	struct __thrd_tramp_data *cookie;
+	int ret;
+
+	_DIAGASSERT(arg != NULL);
+
+	cookie = (struct __thrd_tramp_data *)arg;
+
+	ret = (cookie->func)(cookie->arg);
+
+	free(cookie);
+
+	return (void *)(intptr_t)ret;
+}
+
 int
 thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
 {
+	struct __thrd_tramp_data *cookie;
+	int error;
 
 	_DIAGASSERT(thr != NULL);
 	_DIAGASSERT(func != NULL);
 
-	switch(pthread_create(thr, NULL, (void *(*)(void *))func, arg)) {
+	cookie = malloc(sizeof(*cookie));
+	if (cookie == NULL)
+		return thrd_nomem;
+
+	cookie->func = func;
+	cookie->arg = arg;
+
+	switch(pthread_create(thr, NULL, __thrd_create_tramp, cookie)) {
 	case 0:
 		return thrd_success;
-	case EAGAIN:
-		return thrd_nomem;
+	case ENOMEM:
+		error = thrd_nomem;
+		break;
 	default:
-		return thrd_error;
+		error = thrd_error;
 	}
+
+	free(cookie);
+
+	return error;
 }
 
 thrd_t



CVS commit: src

2019-04-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr 27 23:04:32 UTC 2019

Modified Files:
src/distrib/sets/lists/comp: mi
src/lib/libm: Makefile
src/lib/libm/man: nextafter.3
src/lib/libm/src: s_nextafterl.c
src/usr.sbin/makemandb: nostem.txt

Log Message:
Add a C99 symbol to libm: nexttowardl

It's an alias for an already existing symbol nextafterl.

Patch obtained from 

Detected by the LLVM buildbot breakage in tests.


To generate a diff of this commit:
cvs rdiff -u -r1.2271 -r1.2272 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.209 -r1.210 src/lib/libm/Makefile
cvs rdiff -u -r1.5 -r1.6 src/lib/libm/man/nextafter.3
cvs rdiff -u -r1.5 -r1.6 src/lib/libm/src/s_nextafterl.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/makemandb/nostem.txt

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2271 src/distrib/sets/lists/comp/mi:1.2272
--- src/distrib/sets/lists/comp/mi:1.2271	Thu Apr 25 23:17:24 2019
+++ src/distrib/sets/lists/comp/mi	Sat Apr 27 23:04:31 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2271 2019/04/25 23:17:24 maya Exp $
+#	$NetBSD: mi,v 1.2272 2019/04/27 23:04:31 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -8535,6 +8535,7 @@
 ./usr/share/man/cat3/nextafterl.0		comp-c-catman		.cat
 ./usr/share/man/cat3/nexttoward.0		comp-c-catman		.cat
 ./usr/share/man/cat3/nexttowardf.0		comp-c-catman		.cat
+./usr/share/man/cat3/nexttowardl.0		comp-c-catman		.cat
 ./usr/share/man/cat3/nftw.0			comp-c-catman		.cat
 ./usr/share/man/cat3/ngettext.0			comp-c-catman		.cat
 ./usr/share/man/cat3/nice.0			comp-c-catman		.cat
@@ -16510,6 +16511,7 @@
 ./usr/share/man/html3/nextafterl.html		comp-c-htmlman		html
 ./usr/share/man/html3/nexttoward.html		comp-c-htmlman		html
 ./usr/share/man/html3/nexttowardf.html		comp-c-htmlman		html
+./usr/share/man/html3/nexttowardl.html		comp-c-htmlman		html
 ./usr/share/man/html3/nftw.html			comp-c-htmlman		html
 ./usr/share/man/html3/ngettext.html		comp-c-htmlman		html
 ./usr/share/man/html3/nice.html			comp-c-htmlman		html
@@ -24492,6 +24494,7 @@
 ./usr/share/man/man3/nextafterl.3		comp-c-man		.man
 ./usr/share/man/man3/nexttoward.3		comp-c-man		.man
 ./usr/share/man/man3/nexttowardf.3		comp-c-man		.man
+./usr/share/man/man3/nexttowardl.3		comp-c-man		.man
 ./usr/share/man/man3/nftw.3			comp-c-man		.man
 ./usr/share/man/man3/ngettext.3			comp-c-man		.man
 ./usr/share/man/man3/nice.3			comp-c-man		.man

Index: src/lib/libm/Makefile
diff -u src/lib/libm/Makefile:1.209 src/lib/libm/Makefile:1.210
--- src/lib/libm/Makefile:1.209	Thu Apr 25 23:17:24 2019
+++ src/lib/libm/Makefile	Sat Apr 27 23:04:32 2019
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.209 2019/04/25 23:17:24 maya Exp $
+#  $NetBSD: Makefile,v 1.210 2019/04/27 23:04:32 kamil Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -424,7 +424,8 @@ MLINKS+=modf.3 modff.3 \
 MLINKS+=nextafter.3 nextafterf.3 \
 	nextafter.3 nextafterl.3 \
 	nextafter.3 nexttoward.3 \
-	nextafter.3 nexttowardf.3
+	nextafter.3 nexttowardf.3 \
+	nextafter.3 nexttowardl.3
 MLINKS+=lrint.3 lrintf.3 lrint.3 llrint.3 lrint.3 llrintf.3
 MLINKS+=remainder.3 remainderf.3 \
 	remainder.3 remquo.3 \

Index: src/lib/libm/man/nextafter.3
diff -u src/lib/libm/man/nextafter.3:1.5 src/lib/libm/man/nextafter.3:1.6
--- src/lib/libm/man/nextafter.3:1.5	Sun Sep 13 10:58:30 2015
+++ src/lib/libm/man/nextafter.3	Sat Apr 27 23:04:32 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: nextafter.3,v 1.5 2015/09/13 10:58:30 he Exp $
+.\" $NetBSD: nextafter.3,v 1.6 2019/04/27 23:04:32 kamil Exp $
 .\"
 .\" Copyright (c) 2011 Jukka Ruohonen 
 .\" All rights reserved.
@@ -32,12 +32,8 @@
 .Nm nextafterf ,
 .Nm nextafterl ,
 .Nm nexttoward ,
-.Nm nexttowardf
-.\"
-.\" XXX: Not yet implemented.
-.\"
-.\" .Nm nexttowardl
-.\"
+.Nm nexttowardf ,
+.Nm nexttowardl
 .Nd next representable floating-point number
 .Sh LIBRARY
 .Lb libm
@@ -53,6 +49,8 @@
 .Fn nexttoward "double x" "long double y"
 .Ft float
 .Fn nexttowardf "float x" "long double y"
+.Ft long double
+.Fn nexttowardl "long double x" "long double y"
 .Sh DESCRIPTION
 The
 .Fn nextafter ,
@@ -80,9 +78,10 @@ The three functions differ only in the t
 .Fa x .
 .Pp
 The
-.Fn nexttoward
-and
+.Fn nexttoward ,
 .Fn nexttowardf
+and
+.Fn nexttowardl
 functions are equivalent to the
 .Fn nextafter
 family of functions with two exceptions:

Index: src/lib/libm/src/s_nextafterl.c
diff -u src/lib/libm/src/s_nextafterl.c:1.5 src/lib/libm/src/s_nextafterl.c:1.6
--- src/lib/libm/src/s_nextafterl.c:1.5	Fri Jan 31 19:38:47 2014
+++ src/lib/libm/src/s_nextafterl.c	Sat Apr 27 23:04:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: s_nextafterl.c,v 1.5 2014/01/31 19:38:47 matt Exp $	*/
+/*	$NetBSD: s_nextafterl.c,v 1.6 2019/04/27 23:04:32 kamil Exp $	*/
 
 /* @(#)s_nextafter.c 5.1 93/09/24 */
 /*

CVS commit: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common

2019-04-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr 27 00:23:18 UTC 2019

Modified Files:
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common:
sanitizer_linux.cc

Log Message:
Backport improvements into GCC's sanitizer_linux.cc from more recent LLVM

Backport fixups for syscall()/__syscall() routines from LLVM compiler-rt
dated October 1st 2018. The commit beffore switching LLVM compiler-rt
sycall calls to libc calls for NetBSD.

GCC8 will get part of these changes from upstream and GCC9 will operate on
libc calls directly for the NetBSD port.

This is intended to correct misuse of parameters of syscall()/__syscall()
that could break !x86 ports in UBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 \
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc
diff -u src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.29 src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.30
--- src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.29	Tue Apr 16 07:34:54 2019
+++ src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc	Sat Apr 27 00:23:17 2019
@@ -42,6 +42,10 @@
 
 #endif // !SANITIZER_FREEBSD && !SANITIZER_NETBSD
 
+#if SANITIZER_NETBSD
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -74,6 +78,8 @@ extern char **environ;  // provided by c
 #if SANITIZER_NETBSD
 #include 	// For NAME_MAX
 #include 
+#include 
+extern struct ps_strings *__ps_strings;
 extern char **environ;  // provided by crt1
 #endif  // SANITIZER_NETBSD
 
@@ -147,11 +153,11 @@ uptr internal_mmap(void *addr, uptr leng
 #endif // !SANITIZER_S390
 
 uptr internal_munmap(void *addr, uptr length) {
-  return internal_syscall(SYSCALL(munmap), (uptr)addr, length);
+  return internal_syscall_ptr(SYSCALL(munmap), (uptr)addr, length);
 }
 
 int internal_mprotect(void *addr, uptr length, int prot) {
-  return internal_syscall(SYSCALL(mprotect), (uptr)addr, length, prot);
+  return internal_syscall_ptr(SYSCALL(mprotect), (uptr)addr, length, prot);
 }
 
 uptr internal_close(fd_t fd) {
@@ -162,7 +168,7 @@ uptr internal_open(const char *filename,
 #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags);
 #else
-  return internal_syscall(SYSCALL(open), (uptr)filename, flags);
+  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags);
 #endif
 }
 
@@ -171,7 +177,7 @@ uptr internal_open(const char *filename,
   return internal_syscall(SYSCALL(openat), AT_FDCWD, (uptr)filename, flags,
   mode);
 #else
-  return internal_syscall(SYSCALL(open), (uptr)filename, flags, mode);
+  return internal_syscall_ptr(SYSCALL(open), (uptr)filename, flags, mode);
 #endif
 }
 
@@ -200,7 +206,7 @@ uptr internal_write(fd_t fd, const void 
 uptr internal_ftruncate(fd_t fd, uptr size) {
   sptr res;
 #ifdef SANITIZER_NETBSD
-  HANDLE_EINTR(res, internal_syscall(SYSCALL(ftruncate), fd, 0, (s64)size));
+  HANDLE_EINTR(res, internal_syscall64(SYSCALL(ftruncate), fd, 0, (s64)size));
 #else
   HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd,
(OFF_T)size));
@@ -250,7 +256,7 @@ static void kernel_stat_to_stat(struct k
 
 uptr internal_stat(const char *path, void *buf) {
 #if SANITIZER_FREEBSD || SANITIZER_NETBSD
-  return internal_syscall(SYSCALL(stat), path, buf);
+  return internal_syscall_ptr(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
 #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
   (uptr)buf, 0);
@@ -274,7 +280,7 @@ uptr internal_stat(const char *path, voi
 
 uptr internal_lstat(const char *path, void *buf) {
 #if SANITIZER_FREEBSD || SANITIZER_NETBSD
-  return internal_syscall(SYSCALL(lstat), path, buf);
+  return internal_syscall_ptr(SYSCALL(lstat), path, buf);
 #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
  (uptr)buf, AT_SYMLINK_NOFOLLOW);
@@ -298,7 +304,7 @@ uptr internal_lstat(const char *path, vo
 
 uptr internal_fstat(fd_t fd, void *buf) {
 #if SANITIZER_FREEBSD || SANITIZER_NETBSD
-  return internal_syscall(SYSCALL(fstat), fd, (uptr)buf);
+  return internal_syscall_ptr(SYSCALL(fstat), fd, (uptr)buf);
 #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
   return = internal_syscall(SYSCALL(fstat), fd, );
 #elif SANITIZER_LINUX_USES_64BIT_SYSCALLS
@@ -336,7 +342,7 @@ uptr internal_dup2(int oldfd, int newfd)
 
 uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
 #if SANITIZER_NETBSD
-  return internal_syscall_ptr(SYSCALL(readlink), path, buf, 

CVS commit: src/tests/lib

2019-04-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 25 20:48:54 UTC 2019

Modified Files:
src/tests/lib/libc/gen: t_fpsetmask.c t_siginfo.c
src/tests/lib/libm: t_fenv.c

Log Message:
Fix typo in 'exceptions'


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/lib/libc/gen/t_fpsetmask.c
cvs rdiff -u -r1.35 -r1.36 src/tests/lib/libc/gen/t_siginfo.c
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libm/t_fenv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/gen/t_fpsetmask.c
diff -u src/tests/lib/libc/gen/t_fpsetmask.c:1.19 src/tests/lib/libc/gen/t_fpsetmask.c:1.20
--- src/tests/lib/libc/gen/t_fpsetmask.c:1.19	Wed Jan 30 12:16:28 2019
+++ src/tests/lib/libc/gen/t_fpsetmask.c	Thu Apr 25 20:48:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fpsetmask.c,v 1.19 2019/01/30 12:16:28 martin Exp $ */
+/*	$NetBSD: t_fpsetmask.c,v 1.20 2019/04/25 20:48:54 kamil Exp $ */
 
 /*-
  * Copyright (c) 1995 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@ ATF_TC_BODY(no_test, tc)
 
 #if (__arm__ && !__SOFTFP__) || __aarch64__
 	/*
-	 * Some NEON fpus do not trap on IEEE 754 FP excpeptions.
+	 * Some NEON fpus do not trap on IEEE 754 FP exceptions.
 	 * skip these tests if running on them and compiled for
 	 * hard float.
 	 */

Index: src/tests/lib/libc/gen/t_siginfo.c
diff -u src/tests/lib/libc/gen/t_siginfo.c:1.35 src/tests/lib/libc/gen/t_siginfo.c:1.36
--- src/tests/lib/libc/gen/t_siginfo.c:1.35	Wed Jan 30 12:16:28 2019
+++ src/tests/lib/libc/gen/t_siginfo.c	Thu Apr 25 20:48:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_siginfo.c,v 1.35 2019/01/30 12:16:28 martin Exp $ */
+/* $NetBSD: t_siginfo.c,v 1.36 2019/04/25 20:48:54 kamil Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -311,7 +311,7 @@ ATF_TC_BODY(sigfpe_flt, tc)
 		atf_tc_skip("Test does not run correctly under QEMU");
 #if (__arm__ && !__SOFTFP__) || __aarch64__
 	/*
-	 * Some NEON fpus do not trap on IEEE 754 FP excpeptions.
+	 * Some NEON fpus do not trap on IEEE 754 FP exceptions.
 	 * skip these tests if running on them and compiled for
 	 * hard float.
 	 */

Index: src/tests/lib/libm/t_fenv.c
diff -u src/tests/lib/libm/t_fenv.c:1.5 src/tests/lib/libm/t_fenv.c:1.6
--- src/tests/lib/libm/t_fenv.c:1.5	Wed Jan 30 12:16:28 2019
+++ src/tests/lib/libm/t_fenv.c	Thu Apr 25 20:48:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fenv.c,v 1.5 2019/01/30 12:16:28 martin Exp $ */
+/* $NetBSD: t_fenv.c,v 1.6 2019/04/25 20:48:54 kamil Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_fenv.c,v 1.5 2019/01/30 12:16:28 martin Exp $");
+__RCSID("$NetBSD: t_fenv.c,v 1.6 2019/04/25 20:48:54 kamil Exp $");
 
 #include 
 
@@ -42,7 +42,7 @@ __RCSID("$NetBSD: t_fenv.c,v 1.5 2019/01
 
 #if (__arm__ && !__SOFTFP__) || __aarch64__
 	/*
-	 * Some NEON fpus  do not trap on IEEE 754 FP excpeptions.
+	 * Some NEON fpus  do not trap on IEEE 754 FP exceptions.
 	 * Skip these tests if running on them and compiled for
 	 * hard float.
 	 */



CVS commit: src/tests/kernel

2019-04-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 25 19:37:10 UTC 2019

Modified Files:
src/tests/kernel: h_segv.c

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/kernel/h_segv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/h_segv.c
diff -u src/tests/kernel/h_segv.c:1.13 src/tests/kernel/h_segv.c:1.14
--- src/tests/kernel/h_segv.c:1.13	Wed Jan 30 12:16:28 2019
+++ src/tests/kernel/h_segv.c	Thu Apr 25 19:37:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_segv.c,v 1.13 2019/01/30 12:16:28 martin Exp $	*/
+/*	$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: h_segv.c,v 1.13 2019/01/30 12:16:28 martin Exp $");
+__RCSID("$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $");
 
 #define	__TEST_FENV
 
@@ -113,7 +113,7 @@ check_fpe(void)
 {
 #if (__arm__ && !__SOFTFP__) || __aarch64__
 	/*
-	 * Some NEON fpus do not trap on IEEE 754 FP excpeptions.
+	 * Some NEON fpus do not trap on IEEE 754 FP exceptions.
 	 * Skip these tests if running on them and compiled for
 	 * hard float.
 	 */



CVS commit: src/tests/lib/libc/sys

2019-04-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 25 19:15:23 UTC 2019

Modified Files:
src/tests/lib/libc/sys: Makefile t_ptrace_wait.c t_ptrace_wait.h

Log Message:
Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.113 -r1.114 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_ptrace_wait.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.54 src/tests/lib/libc/sys/Makefile:1.55
--- src/tests/lib/libc/sys/Makefile:1.54	Sun Feb 10 02:13:45 2019
+++ src/tests/lib/libc/sys/Makefile	Thu Apr 25 19:15:23 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.54 2019/02/10 02:13:45 kamil Exp $
+# $NetBSD: Makefile,v 1.55 2019/04/25 19:15:23 kamil Exp $
 
 MKMAN=	no
 
@@ -88,12 +88,12 @@ SRCS.t_mprotect=	t_mprotect.c ${SRCS_EXE
 
 LDADD.t_getpid+=-lpthread
 
-LDFLAGS.t_ptrace_wait+=		-pthread
-LDFLAGS.t_ptrace_wait3+=	-pthread
-LDFLAGS.t_ptrace_wait4+=	-pthread
-LDFLAGS.t_ptrace_wait6+=	-pthread
-LDFLAGS.t_ptrace_waitid+=	-pthread
-LDFLAGS.t_ptrace_waitpid+=	-pthread
+LDFLAGS.t_ptrace_wait+=		-pthread -lm
+LDFLAGS.t_ptrace_wait3+=	-pthread -lm
+LDFLAGS.t_ptrace_wait4+=	-pthread -lm
+LDFLAGS.t_ptrace_wait6+=	-pthread -lm
+LDFLAGS.t_ptrace_waitid+=	-pthread -lm
+LDFLAGS.t_ptrace_waitpid+=	-pthread -lm
 
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES
@@ -102,12 +102,12 @@ LDADD.t_posix_fadvise+= -lrumpvfs -lrump
 .endif
 
 CPPFLAGS.t_lwp_create.c		+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait3.c	+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait4.c	+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait6.c	+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_waitid.c	+= -D_KERNTYPES
-CPPFLAGS.t_ptrace_waitpid.c	+= -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait3.c	+= -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait4.c	+= -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait6.c	+= -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_waitid.c	+= -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_waitpid.c	+= -D_KERNTYPES -D__TEST_FENV
 CPPFLAGS.t_ucontext.c		+= -D_KERNTYPES
 
 FILES=		truncate_test.root_owned

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.113 src/tests/lib/libc/sys/t_ptrace_wait.c:1.114
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.113	Thu Apr 25 11:47:59 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 25 19:15:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $");
 
 #include 
 #include 
@@ -53,6 +53,11 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.11
 #include 
 #include 
 
+#include 
+#if (__arm__ && !__SOFTFP__) || __aarch64__
+#include  /* only need for ARM Cortex/Neon hack */
+#endif
+
 #include 
 
 #include "h_macros.h"
@@ -413,6 +418,9 @@ traceme_crash(int sig)
 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+	if (sig == SIGFPE && !are_fpu_exceptions_supported())
+		atf_tc_skip("FP exceptions are not supported");
+
 	memset(, 0, sizeof(info));
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -537,6 +545,9 @@ traceme_signalmasked_crash(int sig)
 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+	if (sig == SIGFPE && !are_fpu_exceptions_supported())
+		atf_tc_skip("FP exceptions are not supported");
+
 	memset(, 0, sizeof(info));
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -715,6 +726,9 @@ traceme_signalignored_crash(int sig)
 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+	if (sig == SIGFPE && !are_fpu_exceptions_supported())
+		atf_tc_skip("FP exceptions are not supported");
+
 	memset(, 0, sizeof(info));
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -1523,6 +1537,9 @@ traceme_vfork_crash(int sig)
 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+	if (sig == SIGFPE && !are_fpu_exceptions_supported())
+		atf_tc_skip("FP exceptions are not supported");
+
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = vfork()) != -1);
 	if (child == 0) {
@@ -1602,6 +1619,9 @@ traceme_vfork_signalmasked_crash(int sig
 		atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+	if (sig == SIGFPE && !are_fpu_exceptions_supported())
+		atf_tc_skip("FP 

CVS commit: src/tests/lib/libc/sys

2019-04-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 25 11:47:59 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Do not allow 0 as ILL si_code as it's reserved for SI_USER


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.112 src/tests/lib/libc/sys/t_ptrace_wait.c:1.113
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.112	Thu Apr 25 11:45:12 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 25 11:47:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.112 2019/04/25 11:45:12 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.112 2019/04/25 11:45:12 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $");
 
 #include 
 #include 
@@ -471,7 +471,7 @@ traceme_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		ATF_REQUIRE(info.psi_siginfo.si_code >= ILL_ILLOPC &&
 		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
@@ -648,7 +648,7 @@ traceme_signalmasked_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		ATF_REQUIRE(info.psi_siginfo.si_code >= ILL_ILLOPC &&
 		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
@@ -828,7 +828,7 @@ traceme_signalignored_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		ATF_REQUIRE(info.psi_siginfo.si_code >= ILL_ILLOPC &&
 		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
@@ -2126,7 +2126,7 @@ unrelated_tracer_sees_crash(int sig, boo
 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 			break;
 		case SIGILL:
-			FORKEE_ASSERT(info.psi_siginfo.si_code >= 0 &&
+			FORKEE_ASSERT(info.psi_siginfo.si_code >= ILL_ILLOPC &&
 			info.psi_siginfo.si_code <= ILL_BADSTK);
 			break;
 		case SIGFPE:



CVS commit: src/tests/lib/libc/sys

2019-04-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 25 11:45:12 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
In ATF t_ptrace_wait* SIGILL tests allow any si_code

These codes are not portable between CPUs and kernels.

Change the checks to return any valid si_code in the defined range of ILL
values.

PR port-sparc/54140 by Andreas Gustafsson


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.111 src/tests/lib/libc/sys/t_ptrace_wait.c:1.112
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.111	Fri Apr 19 21:54:32 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 25 11:45:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.111 2019/04/19 21:54:32 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.112 2019/04/25 11:45:12 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.111 2019/04/19 21:54:32 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.112 2019/04/25 11:45:12 kamil Exp $");
 
 #include 
 #include 
@@ -471,7 +471,8 @@ traceme_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, ILL_PRVOPC);
+		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV);
@@ -647,7 +648,8 @@ traceme_signalmasked_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, ILL_PRVOPC);
+		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV);
@@ -826,7 +828,8 @@ traceme_signalignored_crash(int sig)
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 		break;
 	case SIGILL:
-		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, ILL_PRVOPC);
+		ATF_REQUIRE(info.psi_siginfo.si_code >= 0 &&
+		info.psi_siginfo.si_code <= ILL_BADSTK);
 		break;
 	case SIGFPE:
 		ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV);
@@ -2123,7 +2126,8 @@ unrelated_tracer_sees_crash(int sig, boo
 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SEGV_MAPERR);
 			break;
 		case SIGILL:
-			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, ILL_PRVOPC);
+			FORKEE_ASSERT(info.psi_siginfo.si_code >= 0 &&
+			info.psi_siginfo.si_code <= ILL_BADSTK);
 			break;
 		case SIGFPE:
 			FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_INTDIV);



CVS commit: src/lib/libpthread

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 21:41:15 UTC 2019

Modified Files:
src/lib/libpthread: call_once.c

Log Message:
Drop error path from C11 call_once

The original implementation of C11 threads(3) contained check for error
paths, but it was stripped in the calls that are documented to return
no status from an operation. Do the same in call_once(3).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/call_once.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/call_once.c
diff -u src/lib/libpthread/call_once.c:1.1 src/lib/libpthread/call_once.c:1.2
--- src/lib/libpthread/call_once.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/call_once.c	Wed Apr 24 21:41:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: call_once.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,12 +30,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: call_once.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $");
 
 #include 
-#include 
 #include 
-#include 
 #include 
 
 void
@@ -45,8 +43,8 @@ call_once(once_flag *flag, void (*func)(
 	_DIAGASSERT(flag != NULL);
 	_DIAGASSERT(func != NULL);
 
-	/* The call_once(3) function returns no value, this forces this code to
-	 * break as there is nothing better available. */
-	if (pthread_once(flag, func) != 0)
-		errx(EXIT_FAILURE, "pthread_once failed");
+	/*
+	 * The call_once(3) function that conforms to C11 returns no value.
+	 */
+	(void)pthread_once(flag, func);
 }



CVS commit: src/lib/libpthread

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 18:47:54 UTC 2019

Modified Files:
src/lib/libpthread: thrd.3 thrd.c threads.h

Log Message:
Introduce minor changes to the C11 threading library

Switch tss_t type from int to pthread_key_t (no functional change as
pthread_key_t was already typedefed as int).

Noted by .

Use C11 _Noreturn in thrd_exit(3) instead of NetBSD specific __dead.
The former is documented in the standard as an attribute of thrd_exit(3),
the latter is more portable to pre-C11 compilers, however C11 thread
support library needs C11 compiler for TLS anyway. __dead made a little bit
more point 3 years ago than today as 3 years ago pre-C11 compilers were
more common.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/thrd.3 src/lib/libpthread/thrd.c \
src/lib/libpthread/threads.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/thrd.3
diff -u src/lib/libpthread/thrd.3:1.1 src/lib/libpthread/thrd.3:1.2
--- src/lib/libpthread/thrd.3:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/thrd.3	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: thrd.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"	$NetBSD: thrd.3,v 1.2 2019/04/24 18:47:54 kamil Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -46,7 +46,7 @@
 .Fn thrd_detach "thrd_t thr"
 .Ft int
 .Fn thrd_equal "thrd_t t1" "thrd_t t2"
-.Ft __dead void
+.Ft _Noreturn void
 .Fn thrd_exit "int res"
 .Ft int
 .Fn thrd_join "thrd_t thr" "int *res"
@@ -191,14 +191,6 @@ otherwise it will return non-zero.
 The
 .Fn thrd_exit
 function does not return.
-The standard attributes this function with the
-.Dv _Noreturn
-keyword,
-however in the
-.Nx
-version it is attributed with the traditional and functionally equivalent
-.Dv __dead
-keyword.
 .Pp
 The
 .Fn thrd_join
Index: src/lib/libpthread/thrd.c
diff -u src/lib/libpthread/thrd.c:1.1 src/lib/libpthread/thrd.c:1.2
--- src/lib/libpthread/thrd.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/thrd.c	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: thrd.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: thrd.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $");
 
 #include 
 #include 
@@ -85,7 +85,7 @@ thrd_equal(thrd_t t1, thrd_t t2)
 	return pthread_equal(t1, t2);
 }
 
-__dead void
+_Noreturn void
 thrd_exit(int res)
 {
 
Index: src/lib/libpthread/threads.h
diff -u src/lib/libpthread/threads.h:1.1 src/lib/libpthread/threads.h:1.2
--- src/lib/libpthread/threads.h:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/threads.h	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: threads.h,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: threads.h,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 /* ISO/IEC 9899:201x 7.26.1/4 */
 typedef pthread_cond_t	  cnd_t;
 typedef pthread_t	  thrd_t;
-typedef int		  tss_t;
+typedef pthread_key_t	  tss_t;
 typedef pthread_mutex_t	  mtx_t;
 typedef void		(*tss_dtor_t)	(void *);
 typedef int		(*thrd_start_t)	(void *);
@@ -106,7 +106,7 @@ int	thrd_create(thrd_t *, thrd_start_t, 
 thrd_t	thrd_current(void);
 int	thrd_detach(thrd_t);
 int	thrd_equal(thrd_t, thrd_t);
-void	thrd_exit(int) __dead;
+_Noreturn void	thrd_exit(int);
 int	thrd_join(thrd_t, int *);
 int	thrd_sleep(const struct timespec *, struct timespec *);
 void	thrd_yield(void);



CVS commit: src/doc

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 15:04:51 UTC 2019

Modified Files:
src/doc: CHANGES

Log Message:
libpthread(3): Import C11 thread support library


To generate a diff of this commit:
cvs rdiff -u -r1.2528 -r1.2529 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2528 src/doc/CHANGES:1.2529
--- src/doc/CHANGES:1.2528	Sun Apr 21 22:32:12 2019
+++ src/doc/CHANGES	Wed Apr 24 15:04:51 2019
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2528 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2529 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -360,3 +360,4 @@ Changes from NetBSD 8.0 to NetBSD 9.0:
 	OpenSSH: Import 8.0 [christos 20180420]
 	evbarm: Add support for boot configuration (efiboot.plist) and
 		applying device tree overlays to efiboot. [thorpej 20190421]
+	libpthread(3): Import C11 thread support library [kamil 20190424]



CVS commit: src

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 13:01:52 UTC 2019

Modified Files:
src/distrib/sets/lists/base: shl.mi
src/distrib/sets/lists/debug: shl.mi
src/lib/libpthread: shlib_version

Log Message:
Bump the libpthread(3) minor number to 4

Added C11 Threading library support.


To generate a diff of this commit:
cvs rdiff -u -r1.862 -r1.863 src/distrib/sets/lists/base/shl.mi
cvs rdiff -u -r1.221 -r1.222 src/distrib/sets/lists/debug/shl.mi
cvs rdiff -u -r1.18 -r1.19 src/lib/libpthread/shlib_version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/base/shl.mi
diff -u src/distrib/sets/lists/base/shl.mi:1.862 src/distrib/sets/lists/base/shl.mi:1.863
--- src/distrib/sets/lists/base/shl.mi:1.862	Sat Apr 20 17:24:06 2019
+++ src/distrib/sets/lists/base/shl.mi	Wed Apr 24 13:01:52 2019
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.862 2019/04/20 17:24:06 christos Exp $
+# $NetBSD: shl.mi,v 1.863 2019/04/24 13:01:52 kamil Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -476,7 +476,7 @@
 ./usr/lib/libprop.so.1.1			base-sys-shlib		compatfile
 ./usr/lib/libpthread.sobase-sys-shlib		compatfile
 ./usr/lib/libpthread.so.1			base-sys-shlib		compatfile
-./usr/lib/libpthread.so.1.3			base-sys-shlib		compatfile
+./usr/lib/libpthread.so.1.4			base-sys-shlib		compatfile
 ./usr/lib/libpthread_dbg.so			base-obsolete		obsolete
 ./usr/lib/libpthread_dbg.so.2			base-obsolete		obsolete
 ./usr/lib/libpthread_dbg.so.2.0			base-obsolete		obsolete

Index: src/distrib/sets/lists/debug/shl.mi
diff -u src/distrib/sets/lists/debug/shl.mi:1.221 src/distrib/sets/lists/debug/shl.mi:1.222
--- src/distrib/sets/lists/debug/shl.mi:1.221	Sat Apr 20 17:24:06 2019
+++ src/distrib/sets/lists/debug/shl.mi	Wed Apr 24 13:01:52 2019
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.221 2019/04/20 17:24:06 christos Exp $
+# $NetBSD: shl.mi,v 1.222 2019/04/24 13:01:52 kamil Exp $
 ./usr/lib/libbfd_g.a		comp-c-debuglib	debuglib,compatfile,binutils
 ./usr/libdata/debug/lib		base-sys-usr	debug,dynamicroot,compatdir
 ./usr/libdata/debug/lib/libblacklist.so.0.0.debug		comp-sys-debug	debug,dynamicroot
@@ -165,7 +165,7 @@
 ./usr/libdata/debug/usr/lib/libppath.so.0.0.debug		comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libproc.so.1.0.debug		comp-sys-debug	debug,dtrace
 ./usr/libdata/debug/usr/lib/libprop.so.1.1.debug		comp-sys-debug	debug,compatfile
-./usr/libdata/debug/usr/lib/libpthread.so.1.3.debug		comp-sys-debug	debug,compatfile
+./usr/libdata/debug/usr/lib/libpthread.so.1.4.debug		comp-sys-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libpthread_dbg.so.2.0.debug		comp-obsolete	obsolete
 ./usr/libdata/debug/usr/lib/libpuffs.so.2.0.debug		comp-puffs-debug	debug,compatfile
 ./usr/libdata/debug/usr/lib/libquota.so.1.0.debug		comp-sys-debug	debug,compatfile

Index: src/lib/libpthread/shlib_version
diff -u src/lib/libpthread/shlib_version:1.18 src/lib/libpthread/shlib_version:1.19
--- src/lib/libpthread/shlib_version:1.18	Sun Sep  9 07:24:59 2018
+++ src/lib/libpthread/shlib_version	Wed Apr 24 13:01:52 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: shlib_version,v 1.18 2018/09/09 07:24:59 maya Exp $
+#	$NetBSD: shlib_version,v 1.19 2019/04/24 13:01:52 kamil Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 # Things to do when bumping major version:
@@ -18,5 +18,7 @@
 #	use reserved identifiers for things that shouldn't be visible,
 #	e.g. rename pthread__pagesize to __pthread_pagesize,
 #
+#	remove remnants of libpthread_dbg: pthread__dbg
+#
 major=1
-minor=3
+minor=4



CVS commit: src

2019-04-24 Thread Kamil Rytarowski
ck.3
+MLINKS+=	mtx.3 mtx_trylock.3
+MLINKS+=	mtx.3 mtx_unlock.3
+
+MLINKS+=	thrd.3 thrd_create.3
+MLINKS+=	thrd.3 thrd_current.3
+MLINKS+=	thrd.3 thrd_detach.3
+MLINKS+=	thrd.3 thrd_equal.3
+MLINKS+=	thrd.3 thrd_exit.3
+MLINKS+=	thrd.3 thrd_join.3
+MLINKS+=	thrd.3 thrd_sleep.3
+MLINKS+=	thrd.3 thrd_yield.3
+
+MLINKS+=	tss.3 TSS_DTOR_ITERATIONS.3
+MLINKS+=	tss.3 tss_create.3
+MLINKS+=	tss.3 tss_delete.3
+MLINKS+=	tss.3 tss_get.3
+MLINKS+=	tss.3 tss_set.3
+
+INCS+=		threads.h
+
 .include 
 
 .else

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.13 src/tests/lib/libpthread/Makefile:1.14
--- src/tests/lib/libpthread/Makefile:1.13	Tue Jul 11 15:21:36 2017
+++ src/tests/lib/libpthread/Makefile	Wed Apr 24 11:43:19 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.13 2017/07/11 15:21:36 joerg Exp $
+# $NetBSD: Makefile,v 1.14 2019/04/24 11:43:19 kamil Exp $
 
 NOMAN=		# defined
 
@@ -50,6 +50,8 @@ PROGS+=		h_exit
 PROGS+=		h_resolv
 PROGS_CXX+=	h_thread_local_dtor
 
+TESTS_C+=	t_call_once t_cnd t_mtx t_thrd t_tss # C11 threads(3)
+
 COPTS.h_thread_local_dtor.cpp+=	-std=c++11
 # Deal with questionable warning and header quality in libstdc++.
 COPTS.h_thread_local_dtor.cpp+=	 ${${ACTIVE_CC} == "gcc" :?  -Wno-ctor-dtor-privacy -Wno-sign-compare -Wno-shadow :}

Added files:

Index: src/lib/libpthread/call_once.3
diff -u /dev/null src/lib/libpthread/call_once.3:1.1
--- /dev/null	Wed Apr 24 11:43:20 2019
+++ src/lib/libpthread/call_once.3	Wed Apr 24 11:43:19 2019
@@ -0,0 +1,113 @@
+.\"	$NetBSD: call_once.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"
+.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Kamil Rytarowski.
+.\"
+.\" 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.
+.\"
+.Dd October 16, 2016
+.Dt CALL_ONCE 3
+.Os
+.Sh NAME
+.Nm call_once
+.Nd calls function exactly once
+.Sh LIBRARY
+.Lb libpthread
+.Sh SYNOPSIS
+.In threads.h
+.Ft void
+.Fn call_once "once_flag *flag" "void (*func)(void))"
+.Vt #define ONCE_FLAG_INIT /* implementation specified */
+.Sh DESCRIPTION
+The
+.Nm
+function uses the
+.Fa flag
+parameter to ensure that
+.Fa func
+is called exactly once,
+even if called from several threads.
+.Pp
+The
+.Dv ONCE_FLAG_INIT
+definition expands to a value that can be used to initialize an object of type
+.Dv once_flag .
+.Pp
+This portable interface is implemented on top of the
+.Xr pthread_once 3
+functionality.
+.Sh RETURN VALUES
+None.
+.Sh EXAMPLES
+The following calls
+.Nm
+from two threads using the portable
+.Xr thrd 3
+interface.
+.Bd -literal -offset indent
+#include 
+#include 
+
+static once_flag oflag = ONCE_FLAG_INIT;
+
+void
+called_once(void)
+{
+	printf("called once\n");
+}
+
+int
+tfun(void *ptr)
+{
+	call_once(, called_once);
+}
+
+int
+main(int argc, char **argv)
+{
+	thrd_t th1, th2;
+
+	thrd_create(, tfun, NULL);
+	thrd_create(, tfun, NULL);
+
+	thrd_join(th1, NULL);
+	thrd_join(th2, NULL);
+
+	return 0;
+}
+.Ed
+.Sh SEE ALSO
+.Xr pthread_once 3 ,
+.Xr threads 3
+.Sh STANDARDS
+The
+.Nm
+function conforms to
+.St -isoC-2011 .
+.Sh HISTORY
+This interface first appeared in
+.Nx 9 .
+.Sh AUTHORS
+.An Kamil Rytarowski Aq Mt ka...@netbsd.org
Index: src/lib/libpthread/call_once.c
diff -u /dev/null src/lib/libpthread/call_once.c:1.1
--- /dev/null	Wed Apr 24 11:43:20 2019
+++ src/lib/libpthread/call_once.c	Wed Apr 24 11:43:19 2019
@@ -0,0 +1,52 @@
+/*	$NetBSD: call_once.c,v 1.1 2019/04/24 11:43

CVS commit: src/share/mk

2019-04-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Apr 19 22:06:03 UTC 2019

Modified Files:
src/share/mk: bsd.README

Log Message:
Fix typo cost -> host


To generate a diff of this commit:
cvs rdiff -u -r1.390 -r1.391 src/share/mk/bsd.README

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/mk/bsd.README
diff -u src/share/mk/bsd.README:1.390 src/share/mk/bsd.README:1.391
--- src/share/mk/bsd.README:1.390	Sun Apr  7 19:32:24 2019
+++ src/share/mk/bsd.README	Fri Apr 19 22:06:03 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.README,v 1.390 2019/04/07 19:32:24 christos Exp $
+#	$NetBSD: bsd.README,v 1.391 2019/04/19 22:06:03 kamil Exp $
 #	@(#)bsd.README	8.2 (Berkeley) 4/2/94
 
 This is the README file for the make "include" files for the NetBSD
@@ -2126,7 +2126,7 @@ HOST_COMPILE.cc		The host c++ compiler l
 
 HOST_CPP		The host c pre-processor
 
-HOST_CPPFLAGS		The cost c pre-processor flags
+HOST_CPPFLAGS		The host c pre-processor flags
 
 HOST_CXX		The host c++ compiler
 



CVS commit: src/tests/lib/libc/sys

2019-04-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Apr 19 21:54:33 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix typo in TEST_VFORK_ENABLED

This allows building and running vfork(2) test scenarios correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.110 src/tests/lib/libc/sys/t_ptrace_wait.c:1.111
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.110	Wed Apr 17 15:54:55 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Fri Apr 19 21:54:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.110 2019/04/17 15:54:55 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.111 2019/04/19 21:54:32 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.110 2019/04/17 15:54:55 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.111 2019/04/19 21:54:32 kamil Exp $");
 
 #include 
 #include 
@@ -7011,7 +7011,7 @@ CLONE_TEST2(clone_vfork_signalmasked, CL
 
 /// 
 
-#if TEST_VFORK_ENABLE
+#if TEST_VFORK_ENABLED
 #if defined(TWAIT_HAVE_PID)
 static void
 traceme_vfork_clone_body(int flags)



CVS commit: src/tests/lib/libc/sys

2019-04-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 17 15:54:55 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix Clang/LLVM build in t_ptrace_wait.c

Do not compile functions that might be unused.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.109 src/tests/lib/libc/sys/t_ptrace_wait.c:1.110
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.109	Mon Apr 15 16:47:47 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed Apr 17 15:54:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.109 2019/04/15 16:47:47 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.110 2019/04/17 15:54:55 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.109 2019/04/15 16:47:47 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.110 2019/04/17 15:54:55 kamil Exp $");
 
 #include 
 #include 
@@ -87,7 +87,9 @@ static int debug = 0;
 	if (debug) printf(a,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
+#ifndef TEST_VFORK_ENABLED
 #define TEST_VFORK_ENABLED 0
+#endif
 
 /// 
 
@@ -3150,6 +3152,7 @@ FORK_TEST(fork7, fork, false, true, true
 FORK_TEST(fork8, fork, true, true, true)
 #endif
 
+#if TEST_VFORK_ENABLED
 FORK_TEST(vfork1, vfork, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 FORK_TEST(vfork2, vfork, true, false, false)
@@ -3162,9 +3165,11 @@ FORK_TEST(vfork6, vfork, true, false, tr
 FORK_TEST(vfork7, vfork, false, true, true)
 FORK_TEST(vfork8, vfork, true, true, true)
 #endif
+#endif
 
 /// 
 
+#if TEST_VFORK_ENABLED
 static void
 traceme_vfork_fork_body(pid_t (*fn)(void))
 {
@@ -3223,6 +3228,7 @@ ATF_TC_BODY(name, tc)			\
 
 TRACEME_VFORK_FORK_TEST(traceme_vfork_fork, fork)
 TRACEME_VFORK_FORK_TEST(traceme_vfork_vfork, vfork)
+#endif
 
 /// 
 
@@ -5603,11 +5609,13 @@ ATF_TC_BODY(name, tc)			\
 
 FORK2_TEST(fork_singalmasked, true, false, false, true, false)
 FORK2_TEST(fork_singalignored, true, false, false, false, true)
+#if TEST_VFORK_ENABLED
 FORK2_TEST(vfork_singalmasked, false, true, false, true, false)
 FORK2_TEST(vfork_singalignored, false, true, false, false, true)
 FORK2_TEST(vforkdone_singalmasked, false, false, true, true, false)
 FORK2_TEST(vforkdone_singalignored, false, false, true, false, true)
 #endif
+#endif
 
 /// 
 
@@ -6619,6 +6627,7 @@ CLONE_TEST(clone_files8, CLONE_FILES, tr
 //CLONE_TEST(clone_sighand8, CLONE_SIGHAND, true, true, true)
 #endif
 
+#if TEST_VFORK_ENABLED
 CLONE_TEST(clone_vfork1, CLONE_VFORK, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 CLONE_TEST(clone_vfork2, CLONE_VFORK, true, false, false)
@@ -6631,6 +6640,7 @@ CLONE_TEST(clone_vfork6, CLONE_VFORK, tr
 CLONE_TEST(clone_vfork7, CLONE_VFORK, false, true, true)
 CLONE_TEST(clone_vfork8, CLONE_VFORK, true, true, true)
 #endif
+#endif
 
 /// 
 
@@ -6993,12 +7003,15 @@ CLONE_TEST2(clone_files_signalignored, C
 CLONE_TEST2(clone_files_signalmasked, CLONE_FILES, false, true)
 //CLONE_TEST2(clone_sighand_signalignored, CLONE_SIGHAND, true, false) // XXX
 //CLONE_TEST2(clone_sighand_signalmasked, CLONE_SIGHAND, false, true)  // XXX
+#if TEST_VFORK_ENABLED
 CLONE_TEST2(clone_vfork_signalignored, CLONE_VFORK, true, false)
 CLONE_TEST2(clone_vfork_signalmasked, CLONE_VFORK, false, true)
 #endif
+#endif
 
 /// 
 
+#if TEST_VFORK_ENABLE
 #if defined(TWAIT_HAVE_PID)
 static void
 traceme_vfork_clone_body(int flags)
@@ -7079,6 +7092,7 @@ TRACEME_VFORK_CLONE_TEST(traceme_vfork_c
 //TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_sighand, CLONE_SIGHAND)  // XXX
 TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_vfork, CLONE_VFORK)
 #endif
+#endif
 
 /// 
 



CVS commit: src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common

2019-04-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Apr 16 01:44:07 UTC 2019

Modified Files:
src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common:
sanitizer_linux.cc

Log Message:
Sync gcc.old GetPcSpBp() with GCC9 (and recent LLVM)

Unify all NetBSD ports in a single ifdef.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \

src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc
diff -u src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.7 src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.8
--- src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.7	Sun Nov 11 22:49:44 2018
+++ src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc	Tue Apr 16 01:44:07 2019
@@ -1157,51 +1157,39 @@ void internal_join_thread(void *th) {}
 #endif
 
 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
-#if defined(__arm__)
-  ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
+#if SANITIZER_NETBSD
+  // This covers all NetBSD architectures
+  ucontext_t *ucontext = (ucontext_t *)context;
   *pc = _UC_MACHINE_PC(ucontext);
+  *bp = _UC_MACHINE_FP(ucontext);
   *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[_REG_R11];
-# else
+#elif defined(__arm__)
+  ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.arm_pc;
   *bp = ucontext->uc_mcontext.arm_fp;
   *sp = ucontext->uc_mcontext.arm_sp;
-# endif
 #elif defined(__aarch64__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[29]; /* XXX */
-# else
   *pc = ucontext->uc_mcontext.pc;
   *bp = ucontext->uc_mcontext.regs[29];
   *sp = ucontext->uc_mcontext.sp;
-# endif
 #elif defined(__hppa__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[3]; /* XXX */
-#else
   *pc = ucontext->uc_mcontext.sc_iaoq[0];
   /* GCC uses %r3 whenever a frame pointer is needed.  */
   *bp = ucontext->uc_mcontext.sc_gr[3];
   *sp = ucontext->uc_mcontext.sc_gr[30];
-# endif
 #elif defined(__x86_64__)
 # if SANITIZER_FREEBSD
   ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.mc_rip;
   *bp = ucontext->uc_mcontext.mc_rbp;
   *sp = ucontext->uc_mcontext.mc_rsp;
-# elif SANITIZER_NETBSD
-  ucontext_t *ucontext = (ucontext_t*)context;
-  *pc = ucontext->uc_mcontext.__gregs[_REG_RIP];
-  *bp = ucontext->uc_mcontext.__gregs[_REG_RBP];
-  *sp = ucontext->uc_mcontext.__gregs[_REG_RSP];
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_rip;
+  *bp = ucontext->sc_rbp;
+  *sp = ucontext->sc_rsp;
 # else
   ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.gregs[REG_RIP];
@@ -1214,89 +1202,73 @@ void GetPcSpBp(void *context, uptr *pc, 
   *pc = ucontext->uc_mcontext.mc_eip;
   *bp = ucontext->uc_mcontext.mc_ebp;
   *sp = ucontext->uc_mcontext.mc_esp;
-# elif SANITIZER_NETBSD
-  ucontext_t *ucontext = (ucontext_t*)context;
-  *pc = ucontext->uc_mcontext.__gregs[_REG_EIP];
-  *bp = ucontext->uc_mcontext.__gregs[_REG_EBP];
-  *sp = ucontext->uc_mcontext.__gregs[_REG_ESP];
-# else
-  ucontext_t *ucontext = (ucontext_t*)context;
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_eip;
+  *bp = ucontext->sc_ebp;
+  *sp = ucontext->sc_esp;
+# else
+  ucontext_t *ucontext = (ucontext_t*)context;
+# if SANITIZER_SOLARIS
+  /* Use the numeric values: the symbolic ones are undefined by llvm
+ include/llvm/Support/Solaris.h.  */
+# ifndef REG_EIP
+#  define REG_EIP 14 // REG_PC
+# endif
+# ifndef REG_EBP
+#  define REG_EBP  6 // REG_FP
+# endif
+# ifndef REG_ESP
+#  define REG_ESP 17 // REG_SP
+# endif
+# endif
   *pc = ucontext->uc_mcontext.gregs[REG_EIP];
   *bp = ucontext->uc_mcontext.gregs[REG_EBP];
   *sp = ucontext->uc_mcontext.gregs[REG_ESP];
 # endif
 #elif defined(__powerpc__) || defined(__powerpc64__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[_REG_R31];
-#  else
   *pc = ucontext->uc_mcontext.regs->nip;
   *sp = ucontext->uc_mcontext.regs->gpr[PT_R1];
   // The powerpc{,64}-linux ABIs do not specify r31 as the frame
   // pointer, but GCC always uses r31 when we need a frame pointer.
   *bp = ucontext->uc_mcontext.regs->gpr[PT_R31];
-# endif
 #elif defined(__sparc__)
+# if defined(__arch64__) || 

CVS commit: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common

2019-04-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Apr 16 01:40:16 UTC 2019

Modified Files:
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common:
sanitizer_linux.cc

Log Message:
Sync GetPcSpBp() with GCC9 (and recent LLVM)

Unify all NetBSD ports in a single ifdef.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 \
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc
diff -u src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.27 src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.28
--- src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc:1.27	Mon Apr 15 15:58:23 2019
+++ src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux.cc	Tue Apr 16 01:40:16 2019
@@ -1402,51 +1402,39 @@ SignalContext::WriteFlag SignalContext::
 }
 
 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
-#if defined(__arm__)
-  ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
+#if SANITIZER_NETBSD
+  // This covers all NetBSD architectures
+  ucontext_t *ucontext = (ucontext_t *)context;
   *pc = _UC_MACHINE_PC(ucontext);
+  *bp = _UC_MACHINE_FP(ucontext);
   *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[_REG_R11];
-# else
+#elif defined(__arm__)
+  ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.arm_pc;
   *bp = ucontext->uc_mcontext.arm_fp;
   *sp = ucontext->uc_mcontext.arm_sp;
-# endif
 #elif defined(__aarch64__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[29]; /* XXX */
-# else
   *pc = ucontext->uc_mcontext.pc;
   *bp = ucontext->uc_mcontext.regs[29];
   *sp = ucontext->uc_mcontext.sp;
-# endif
 #elif defined(__hppa__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[3]; /* XXX */
-#else
   *pc = ucontext->uc_mcontext.sc_iaoq[0];
   /* GCC uses %r3 whenever a frame pointer is needed.  */
   *bp = ucontext->uc_mcontext.sc_gr[3];
   *sp = ucontext->uc_mcontext.sc_gr[30];
-# endif
 #elif defined(__x86_64__)
 # if SANITIZER_FREEBSD
   ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.mc_rip;
   *bp = ucontext->uc_mcontext.mc_rbp;
   *sp = ucontext->uc_mcontext.mc_rsp;
-# elif SANITIZER_NETBSD
-  ucontext_t *ucontext = (ucontext_t*)context;
-  *pc = ucontext->uc_mcontext.__gregs[_REG_RIP];
-  *bp = ucontext->uc_mcontext.__gregs[_REG_RBP];
-  *sp = ucontext->uc_mcontext.__gregs[_REG_RSP];
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_rip;
+  *bp = ucontext->sc_rbp;
+  *sp = ucontext->sc_rsp;
 # else
   ucontext_t *ucontext = (ucontext_t*)context;
   *pc = ucontext->uc_mcontext.gregs[REG_RIP];
@@ -1459,94 +1447,64 @@ void GetPcSpBp(void *context, uptr *pc, 
   *pc = ucontext->uc_mcontext.mc_eip;
   *bp = ucontext->uc_mcontext.mc_ebp;
   *sp = ucontext->uc_mcontext.mc_esp;
-# elif SANITIZER_NETBSD
-  ucontext_t *ucontext = (ucontext_t*)context;
-  *pc = ucontext->uc_mcontext.__gregs[_REG_EIP];
-  *bp = ucontext->uc_mcontext.__gregs[_REG_EBP];
-  *sp = ucontext->uc_mcontext.__gregs[_REG_ESP];
-# else
-  ucontext_t *ucontext = (ucontext_t*)context;
+#elif SANITIZER_OPENBSD
+  sigcontext *ucontext = (sigcontext *)context;
+  *pc = ucontext->sc_eip;
+  *bp = ucontext->sc_ebp;
+  *sp = ucontext->sc_esp;
+# else
+  ucontext_t *ucontext = (ucontext_t*)context;
+# if SANITIZER_SOLARIS
+  /* Use the numeric values: the symbolic ones are undefined by llvm
+ include/llvm/Support/Solaris.h.  */
+# ifndef REG_EIP
+#  define REG_EIP 14 // REG_PC
+# endif
+# ifndef REG_EBP
+#  define REG_EBP  6 // REG_FP
+# endif
+# ifndef REG_ESP
+#  define REG_ESP 17 // REG_SP
+# endif
+# endif
   *pc = ucontext->uc_mcontext.gregs[REG_EIP];
   *bp = ucontext->uc_mcontext.gregs[REG_EBP];
   *sp = ucontext->uc_mcontext.gregs[REG_ESP];
 # endif
 #elif defined(__powerpc__) || defined(__powerpc64__)
   ucontext_t *ucontext = (ucontext_t*)context;
-# if SANITIZER_NETBSD
-  *pc = _UC_MACHINE_PC(ucontext);
-  *sp = _UC_MACHINE_SP(ucontext);
-  *bp = ucontext->uc_mcontext.__gregs[_REG_R31];
-#  else
   *pc = ucontext->uc_mcontext.regs->nip;
   *sp = ucontext->uc_mcontext.regs->gpr[PT_R1];
   // The powerpc{,64}-linux ABIs do not specify r31 as the frame
   // pointer, but GCC always uses r31 when we need a frame pointer.
   *bp = ucontext->uc_mcontext.regs->gpr[PT_R31];
-# endif
 #elif defined(__sparc__)
+# if defined(__arch64__) || defined(__sparcv9)
+#  define STACK_BIAS 

CVS commit: src/tests/lib/libc/sys

2019-04-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Apr 15 16:47:47 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Temporarily ifdef out PTRACE_VFORK and PTRACE_VFORKDONE tests

It's not reliable on all ports. sparc and evbarm are known to hang.

PR kern/54111 by Martin Husemann


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.108 src/tests/lib/libc/sys/t_ptrace_wait.c:1.109
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.108	Thu Apr 11 23:23:53 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Apr 15 16:47:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.108 2019/04/11 23:23:53 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.109 2019/04/15 16:47:47 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.108 2019/04/11 23:23:53 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.109 2019/04/15 16:47:47 kamil Exp $");
 
 #include 
 #include 
@@ -87,6 +87,8 @@ static int debug = 0;
 	if (debug) printf(a,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
+#define TEST_VFORK_ENABLED 0
+
 /// 
 
 static void
@@ -7275,18 +7277,19 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, fork7);
 	ATF_TP_ADD_TC_HAVE_PID(tp, fork8);
 
+#if TEST_VFORK_ENABLED
 	ATF_TP_ADD_TC(tp, vfork1);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork2);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork3);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork4);
 	ATF_TP_ADD_TC(tp, vfork5);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork6);
-// thes tests hang on SMP machines, disable them for now // still true?
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork7);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork8);
 
 	ATF_TP_ADD_TC(tp, traceme_vfork_fork);
 	ATF_TP_ADD_TC(tp, traceme_vfork_vfork);
+#endif
 
 	ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8);
 	ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16);
@@ -7405,10 +7408,12 @@ ATF_TP_ADD_TCS(tp)
 
 	ATF_TP_ADD_TC_HAVE_PID(tp, fork_singalmasked);
 	ATF_TP_ADD_TC_HAVE_PID(tp, fork_singalignored);
+#if TEST_VFORK_ENABLED
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork_singalmasked);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork_singalignored);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_singalmasked);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_singalignored);
+#endif
 
 	ATF_TP_ADD_TC(tp, signal9);
 	ATF_TP_ADD_TC(tp, signal10);
@@ -7467,6 +7472,7 @@ ATF_TP_ADD_TCS(tp)
 //	ATF_TP_ADD_TC_HAVE_PID(tp, clone_sighand7); // XXX
 //	ATF_TP_ADD_TC_HAVE_PID(tp, clone_sighand8); // XXX
 
+#if TEST_VFORK_ENABLED
 	ATF_TP_ADD_TC(tp, clone_vfork1);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork2);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork3);
@@ -7475,6 +7481,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork6);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork7);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork8);
+#endif
 
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_signalignored);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_signalmasked);
@@ -7486,15 +7493,19 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_files_signalmasked);
 //	ATF_TP_ADD_TC_HAVE_PID(tp, clone_sighand_signalignored); // XXX
 //	ATF_TP_ADD_TC_HAVE_PID(tp, clone_sighand_signalmasked); // XXX
+#if TEST_VFORK_ENABLED
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork_signalignored);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork_signalmasked);
+#endif
 
+#if TEST_VFORK_ENABLED
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone);
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_vm);
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_fs);
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_files);
 //	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_sighand); // XXX
 	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_vfork);
+#endif
 
 	ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_I386();



CVS commit: src/tests/lib/libc/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 23:23:53 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new tests in ATF t_prace_wait*

New tests:

 - traceme_vfork_fork
 - traceme_vfork_vfork

New tests assert that fork/vfork in vforked traced does not emit any
events.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.107 src/tests/lib/libc/sys/t_ptrace_wait.c:1.108
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.107	Thu Apr 11 23:00:01 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 11 23:23:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.107 2019/04/11 23:00:01 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.108 2019/04/11 23:23:53 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.107 2019/04/11 23:00:01 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.108 2019/04/11 23:23:53 kamil Exp $");
 
 #include 
 #include 
@@ -3163,6 +3163,67 @@ FORK_TEST(vfork8, vfork, true, true, tru
 
 /// 
 
+static void
+traceme_vfork_fork_body(pid_t (*fn)(void))
+{
+	const int exitval = 5;
+	const int exitval2 = 15;
+	pid_t child, child2 = 0, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = vfork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		FORKEE_ASSERT((child2 = (fn)()) != -1);
+
+		if (child2 == 0)
+			_exit(exitval2);
+
+		FORKEE_REQUIRE_SUCCESS
+		(wpid = TWAIT_GENERIC(child2, , 0), child2);
+
+		forkee_status_exited(status, exitval2);
+
+		DPRINTF("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child - expected exited\n",
+	TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_exited(status, exitval);
+
+	DPRINTF("Before calling %s() for the child - expected no process\n",
+	TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+
+#define TRACEME_VFORK_FORK_TEST(name,fun)\
+ATF_TC(name);\
+ATF_TC_HEAD(name, tc)			\
+{	\
+	atf_tc_set_md_var(tc, "descr", "Verify " #fun "(2) "		\
+	"called from vfork(2)ed child");\
+}	\
+	\
+ATF_TC_BODY(name, tc)			\
+{	\
+	\
+	traceme_vfork_fork_body(fun);	\
+}
+
+TRACEME_VFORK_FORK_TEST(traceme_vfork_fork, fork)
+TRACEME_VFORK_FORK_TEST(traceme_vfork_vfork, vfork)
+
+/// 
+
 enum bytes_transfer_type {
 	BYTES_TRANSFER_DATA,
 	BYTES_TRANSFER_DATAIO,
@@ -7224,6 +7285,9 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork7);
 	ATF_TP_ADD_TC_HAVE_PID(tp, vfork8);
 
+	ATF_TP_ADD_TC(tp, traceme_vfork_fork);
+	ATF_TP_ADD_TC(tp, traceme_vfork_vfork);
+
 	ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8);
 	ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16);
 	ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_32);



CVS commit: src/tests/lib/libc/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 23:00:01 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Add new tests traceme_vfork_clone* in ATF t_ptrace_wait*

Added tests:

 - traceme_vfork_clone
 - traceme_vfork_clone_vm
 - traceme_vfork_clone_fs
 - traceme_vfork_clone_files
 - traceme_vfork_clone_sighand
 - traceme_vfork_clone_vfork

All tests pass. Validate that children do not trigger any signals and dead
locks when traced by a vfork(2)ed parent.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.106 src/tests/lib/libc/sys/t_ptrace_wait.c:1.107
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.106	Thu Apr 11 19:25:31 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 11 23:00:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.106 2019/04/11 19:25:31 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.107 2019/04/11 23:00:01 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.106 2019/04/11 19:25:31 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.107 2019/04/11 23:00:01 kamil Exp $");
 
 #include 
 #include 
@@ -6936,6 +6936,89 @@ CLONE_TEST2(clone_vfork_signalmasked, CL
 
 /// 
 
+#if defined(TWAIT_HAVE_PID)
+static void
+traceme_vfork_clone_body(int flags)
+{
+	const int exitval = 5;
+	const int exitval2 = 15;
+	pid_t child, child2 = 0, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+
+	const size_t stack_size = 1024 * 1024;
+	void *stack, *stack_base;
+
+	stack = malloc(stack_size);
+	ATF_REQUIRE(stack != NULL);
+
+#ifdef __MACHINE_STACK_GROWS_UP
+	stack_base = stack;
+#else
+	stack_base = (char *)stack + stack_size;
+#endif
+
+	SYSCALL_REQUIRE((child = vfork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before forking process PID=%d flags=%#x\n", getpid(),
+		flags);
+		SYSCALL_REQUIRE((child2 = __clone(clone_func, stack_base,
+		flags|SIGCHLD, (void *)(intptr_t)exitval2)) != -1);
+
+		DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(),
+		child2);
+
+		// XXX WALLSIG?
+		FORKEE_REQUIRE_SUCCESS
+		(wpid = TWAIT_GENERIC(child2, , WALLSIG), child2);
+
+		forkee_status_exited(status, exitval2);
+
+		DPRINTF("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child - expected exited\n",
+	TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_exited(status, exitval);
+
+	DPRINTF("Before calling %s() for the child - expected no process\n",
+	TWAIT_FNAME);
+	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
+}
+
+#define TRACEME_VFORK_CLONE_TEST(name,flags)\
+ATF_TC(name);\
+ATF_TC_HEAD(name, tc)			\
+{	\
+	atf_tc_set_md_var(tc, "descr", "Verify that clone(%s) is "	\
+	"handled correctly with vfork(2)ed tracer", 		\
+	#flags);			\
+}	\
+	\
+ATF_TC_BODY(name, tc)			\
+{	\
+	\
+	traceme_vfork_clone_body(flags);\
+}
+
+TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone, 0)
+TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_vm, CLONE_VM)
+TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_fs, CLONE_FS)
+TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_files, CLONE_FILES)
+//TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_sighand, CLONE_SIGHAND)  // XXX
+TRACEME_VFORK_CLONE_TEST(traceme_vfork_clone_vfork, CLONE_VFORK)
+#endif
+
+/// 
+
 #include "t_ptrace_amd64_wait.h"
 #include "t_ptrace_i386_wait.h"
 #include "t_ptrace_x86_wait.h"
@@ -7342,6 +7425,13 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork_signalignored);
 	ATF_TP_ADD_TC_HAVE_PID(tp, clone_vfork_signalmasked);
 
+	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone);
+	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_vm);
+	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_fs);
+	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_files);
+//	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_sighand); // XXX
+	ATF_TP_ADD_TC_HAVE_PID(tp, traceme_vfork_clone_vfork);
+
 	ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_I386();
 	ATF_TP_ADD_TCS_PTRACE_WAIT_X86();



CVS commit: src/tests/lib/libc/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 20:20:54 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
Add clone_func() in t_ptrace_wait.h


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_ptrace_wait.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.14 src/tests/lib/libc/sys/t_ptrace_wait.h:1.15
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.14	Sun Feb 10 02:13:45 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Thu Apr 11 20:20:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.14 2019/02/10 02:13:45 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.15 2019/04/11 20:20:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -513,6 +513,16 @@ infinite_thread(void *arg __unused)
 __unreachable();
 }
 
+static int __used
+clone_func(void *arg)
+{
+	int ret;
+
+	ret = (int)(intptr_t)arg;
+
+	return ret;
+}
+
 #if defined(HAVE_DBREGS)
 static bool __used
 can_we_set_dbregs(void)



CVS commit: src/tests/lib/libc/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 19:25:31 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Validate that clone(2) is handled properly with more ptrace(2) ATF tests

New tests:

 - clone[1-8]
 - clone_vm[1-8]
 - clone_fs[1-8]
 - clone_files[1-8]
 - clone_sighand[1-8] // disabled temporarily
 - clone_vfork[1-8]

Assert that appropriate events are triggered for the combination of:

 - PTRACE_FORK
 - PTRACE_VFORK
 - PTRACE_VFORK_DONE


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.105 src/tests/lib/libc/sys/t_ptrace_wait.c:1.106
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.105	Sat Apr  6 15:35:09 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 11 19:25:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.105 2019/04/06 15:35:09 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.106 2019/04/11 19:25:31 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.105 2019/04/06 15:35:09 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.106 2019/04/11 19:25:31 kamil Exp $");
 
 #include 
 #include 
@@ -6283,19 +6283,297 @@ ATF_TC_BODY(syscallemu1, tc)
 
 /// 
 
-#if defined(TWAIT_HAVE_PID)
-static int
-clone_func(void *arg)
+static void
+clone_body(int flags, bool trackfork, bool trackvfork,
+bool trackvforkdone)
 {
-	int ret;
+	const int exitval = 5;
+	const int exitval2 = 15;
+	const int sigval = SIGSTOP;
+	pid_t child, child2 = 0, wpid;
+#if defined(TWAIT_HAVE_STATUS)
+	int status;
+#endif
+	ptrace_state_t state;
+	const int slen = sizeof(state);
+	ptrace_event_t event;
+	const int elen = sizeof(event);
+
+	const size_t stack_size = 1024 * 1024;
+	void *stack, *stack_base;
+
+	stack = malloc(stack_size);
+	ATF_REQUIRE(stack != NULL);
+
+#ifdef __MACHINE_STACK_GROWS_UP
+	stack_base = stack;
+#else
+	stack_base = (char *)stack + stack_size;
+#endif
+
+	DPRINTF("Before forking process PID=%d\n", getpid());
+	SYSCALL_REQUIRE((child = fork()) != -1);
+	if (child == 0) {
+		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
+		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+
+		DPRINTF("Before raising %s from child\n", strsignal(sigval));
+		FORKEE_ASSERT(raise(sigval) == 0);
+
+		SYSCALL_REQUIRE((child2 = __clone(clone_func, stack_base,
+		flags|SIGCHLD, (void *)(intptr_t)exitval2)) != -1);
+
+		DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(),
+		child2);
+
+		// XXX WALLSIG?
+		FORKEE_REQUIRE_SUCCESS
+		(wpid = TWAIT_GENERIC(child2, , WALLSIG), child2);
+
+		forkee_status_exited(status, exitval2);
+
+		DPRINTF("Before exiting of the child process\n");
+		_exit(exitval);
+	}
+	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
+
+	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
+
+	validate_status_stopped(status, sigval);
+
+	DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n",
+	trackfork ? "|PTRACE_FORK" : "",
+	trackvfork ? "|PTRACE_VFORK" : "",
+	trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child);
+	event.pe_set_event = 0;
+	if (trackfork)
+		event.pe_set_event |= PTRACE_FORK;
+	if (trackvfork)
+		event.pe_set_event |= PTRACE_VFORK;
+	if (trackvforkdone)
+		event.pe_set_event |= PTRACE_VFORK_DONE;
+	SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1);
+
+	DPRINTF("Before resuming the child process where it left off and "
+	"without signal to be sent\n");
+	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+
+#if defined(TWAIT_HAVE_PID)
+	if ((trackfork && !(flags & CLONE_VFORK)) ||
+	(trackvfork && (flags & CLONE_VFORK))) {
+		DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME,
+		child);
+		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0),
+		child);
+
+		validate_status_stopped(status, SIGTRAP);
+
+		SYSCALL_REQUIRE(
+		ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1);
+		if (trackfork && !(flags & CLONE_VFORK)) {
+			ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK,
+			   PTRACE_FORK);
+		}
+		if (trackvfork && (flags & CLONE_VFORK)) {
+			ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK,
+			   PTRACE_VFORK);
+		}
+
+		child2 = state.pe_other_pid;
+		DPRINTF("Reported ptrace event with forkee %d\n", child2);
+
+		DPRINTF("Before calling %s() for the forkee %d of the child "
+		"%d\n", TWAIT_FNAME, child2, child);
+		TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, , 0),
+		child2);
+
+		validate_status_stopped(status, 

CVS commit: src/share/man/man4

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 17:46:32 UTC 2019

Modified Files:
src/share/man/man4: acpifan.4

Log Message:
Fix CVS Id


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/share/man/man4/acpifan.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/acpifan.4
diff -u src/share/man/man4/acpifan.4:1.3 src/share/man/man4/acpifan.4:1.4
--- src/share/man/man4/acpifan.4:1.3	Sun Jan  9 16:07:45 2011
+++ src/share/man/man4/acpifan.4	Thu Apr 11 17:46:32 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD
+.\" $NetBSD: acpifan.4,v 1.4 2019/04/11 17:46:32 kamil Exp $
 .\"
 .\" Copyright (c) 2011 Jukka Ruohonen 
 .\" All rights reserved.



CVS commit: src/sys/arch/evbppc/mpc85xx

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 14:47:06 UTC 2019

Modified Files:
src/sys/arch/evbppc/mpc85xx: machdep.c

Log Message:
Fix incorrect CVS Id


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/evbppc/mpc85xx/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbppc/mpc85xx/machdep.c
diff -u src/sys/arch/evbppc/mpc85xx/machdep.c:1.43 src/sys/arch/evbppc/mpc85xx/machdep.c:1.44
--- src/sys/arch/evbppc/mpc85xx/machdep.c:1.43	Sat Jan 27 10:07:41 2018
+++ src/sys/arch/evbppc/mpc85xx/machdep.c	Thu Apr 11 14:47:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.43 2018/01/27 10:07:41 flxd Exp $	*/
+/*	$NetBSD: machdep.c,v 1.44 2019/04/11 14:47:06 kamil Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,7 +36,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetSBD$");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.44 2019/04/11 14:47:06 kamil Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"



CVS commit: src/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 14:38:06 UTC 2019

Modified Files:
src/sys/arch/arm/at91: at91pmc.c
src/sys/arch/arm/mpcore: mpcore_a2x_space.c
src/sys/arch/evbppc/virtex/dev: cdmacreg.h temacvar.h
src/sys/arch/ia64/include: elf_machdep.h
src/sys/arch/m68k/m68k: sys_machdep.c
src/sys/arch/mips/alchemy: au1000.c
src/sys/arch/riscv/conf: std.riscv64
src/sys/dev/pci: if_bnxvar.h
src/sys/dev/pci/cxgb: cxgb_include.h
src/sys/net/npf: npf_rproc.c
src/sys/rump/net/lib/libvlan: VLAN.ioconf

Log Message:
Fix CVS Id usage


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/at91/at91pmc.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/mpcore/mpcore_a2x_space.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbppc/virtex/dev/cdmacreg.h \
src/sys/arch/evbppc/virtex/dev/temacvar.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/ia64/include/elf_machdep.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/m68k/m68k/sys_machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/mips/alchemy/au1000.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/conf/std.riscv64
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/if_bnxvar.h
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/pci/cxgb/cxgb_include.h
cvs rdiff -u -r1.17 -r1.18 src/sys/net/npf/npf_rproc.c
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libvlan/VLAN.ioconf

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/at91/at91pmc.c
diff -u src/sys/arch/arm/at91/at91pmc.c:1.6 src/sys/arch/arm/at91/at91pmc.c:1.7
--- src/sys/arch/arm/at91/at91pmc.c:1.6	Mon Nov 12 18:00:36 2012
+++ src/sys/arch/arm/at91/at91pmc.c	Thu Apr 11 14:38:05 2019
@@ -1,5 +1,5 @@
-/*	$Id: at91pmc.c,v 1.6 2012/11/12 18:00:36 skrll Exp $	*/
-/*	$NetBSD: at91pmc.c,v 1.6 2012/11/12 18:00:36 skrll Exp $	*/
+/*	$Id: at91pmc.c,v 1.7 2019/04/11 14:38:05 kamil Exp $	*/
+/*	$NetBSD: at91pmc.c,v 1.7 2019/04/11 14:38:05 kamil Exp $	*/
 
 /*
  * Copyright (c) 2007 Embedtronics Oy
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD");
+__KERNEL_RCSID(0, "$NetBSD: at91pmc.c,v 1.7 2019/04/11 14:38:05 kamil Exp $");
 
 #include 
 #include 

Index: src/sys/arch/arm/mpcore/mpcore_a2x_space.c
diff -u src/sys/arch/arm/mpcore/mpcore_a2x_space.c:1.3 src/sys/arch/arm/mpcore/mpcore_a2x_space.c:1.4
--- src/sys/arch/arm/mpcore/mpcore_a2x_space.c:1.3	Fri Mar 16 17:56:32 2018
+++ src/sys/arch/arm/mpcore/mpcore_a2x_space.c	Thu Apr 11 14:38:05 2019
@@ -1,4 +1,4 @@
-/* $NetBSD */
+/*	$NetBSD: mpcore_a2x_space.c,v 1.4 2019/04/11 14:38:05 kamil Exp $	*/
 
 /* derived from:
NetBSD: pxa2x0_a4x_space.c,v 1.4 2006/07/28 08:15:29 simonb Exp */
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpcore_a2x_space.c,v 1.3 2018/03/16 17:56:32 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpcore_a2x_space.c,v 1.4 2019/04/11 14:38:05 kamil Exp $");
 
 #include 
 #include 

Index: src/sys/arch/evbppc/virtex/dev/cdmacreg.h
diff -u src/sys/arch/evbppc/virtex/dev/cdmacreg.h:1.1 src/sys/arch/evbppc/virtex/dev/cdmacreg.h:1.2
--- src/sys/arch/evbppc/virtex/dev/cdmacreg.h:1.1	Sat Dec  2 22:18:47 2006
+++ src/sys/arch/evbppc/virtex/dev/cdmacreg.h	Thu Apr 11 14:38:05 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD */
+/* 	$NetBSD: cdmacreg.h,v 1.2 2019/04/11 14:38:05 kamil Exp $	*/
 
 /*
  * Copyright (c) 2006 Jachym Holecek
Index: src/sys/arch/evbppc/virtex/dev/temacvar.h
diff -u src/sys/arch/evbppc/virtex/dev/temacvar.h:1.1 src/sys/arch/evbppc/virtex/dev/temacvar.h:1.2
--- src/sys/arch/evbppc/virtex/dev/temacvar.h:1.1	Sat Dec  2 22:18:47 2006
+++ src/sys/arch/evbppc/virtex/dev/temacvar.h	Thu Apr 11 14:38:05 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD */
+/* 	$NetBSD: temacvar.h,v 1.2 2019/04/11 14:38:05 kamil Exp $	*/
 
 /*
  * Copyright (c) 2006 Jachym Holecek

Index: src/sys/arch/ia64/include/elf_machdep.h
diff -u src/sys/arch/ia64/include/elf_machdep.h:1.3 src/sys/arch/ia64/include/elf_machdep.h:1.4
--- src/sys/arch/ia64/include/elf_machdep.h:1.3	Mon Nov  6 03:47:47 2017
+++ src/sys/arch/ia64/include/elf_machdep.h	Thu Apr 11 14:38:06 2019
@@ -1,4 +1,4 @@
-/*$NetBSD */
+/*$NetBSD: elf_machdep.h,v 1.4 2019/04/11 14:38:06 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1996-1997 John D. Polstra.

Index: src/sys/arch/m68k/m68k/sys_machdep.c
diff -u src/sys/arch/m68k/m68k/sys_machdep.c:1.15 src/sys/arch/m68k/m68k/sys_machdep.c:1.16
--- src/sys/arch/m68k/m68k/sys_machdep.c:1.15	Sun Jun  6 04:50:07 2010
+++ src/sys/arch/m68k/m68k/sys_machdep.c	Thu Apr 11 14:38:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_machdep.c,v 1.15 2010/06/06 04:50:07 mrg Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.16 2019/04/11 14:38:06 kamil Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -34,7 +34,7 @@
 #include "opt_m68k_arch.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.16 2019/04/11 14:38:06 kamil Exp $");
 
 #include 
 #include 

Index: 

CVS commit: src/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 11:40:58 UTC 2019

Modified Files:
src/sys/arch/mips/cavium/dev: octeon_pow.c octeon_uartreg.h
src/sys/dev/iscsi: iscsi_main.c
src/sys/net80211: ieee80211_ioctl.c

Log Message:
Fix CVS Id

NFCI


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/mips/cavium/dev/octeon_pow.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/mips/cavium/dev/octeon_uartreg.h
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/iscsi/iscsi_main.c
cvs rdiff -u -r1.64 -r1.65 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/cavium/dev/octeon_pow.c
diff -u src/sys/arch/mips/cavium/dev/octeon_pow.c:1.2 src/sys/arch/mips/cavium/dev/octeon_pow.c:1.3
--- src/sys/arch/mips/cavium/dev/octeon_pow.c:1.2	Mon Jun  1 22:55:12 2015
+++ src/sys/arch/mips/cavium/dev/octeon_pow.c	Thu Apr 11 11:40:58 2019
@@ -1,4 +1,4 @@
-/*	$NetbBSD$	*/
+/*	$NetBSD: octeon_pow.c,v 1.3 2019/04/11 11:40:58 kamil Exp $	*/
 
 /*
  * Copyright (c) 2007 Internet Initiative Japan, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: octeon_pow.c,v 1.2 2015/06/01 22:55:12 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: octeon_pow.c,v 1.3 2019/04/11 11:40:58 kamil Exp $");
 
 #include "opt_octeon.h"	/* OCTEON_ETH_DEBUG */
 

Index: src/sys/arch/mips/cavium/dev/octeon_uartreg.h
diff -u src/sys/arch/mips/cavium/dev/octeon_uartreg.h:1.1 src/sys/arch/mips/cavium/dev/octeon_uartreg.h:1.2
--- src/sys/arch/mips/cavium/dev/octeon_uartreg.h:1.1	Wed Apr 29 08:32:01 2015
+++ src/sys/arch/mips/cavium/dev/octeon_uartreg.h	Thu Apr 11 11:40:58 2019
@@ -1,4 +1,4 @@
-/*	$NetbSD$	*/
+/*	$NetBSD: octeon_uartreg.h,v 1.2 2019/04/11 11:40:58 kamil Exp $	*/
 
 /*
  * Copyright (c) 2007 Internet Initiative Japan, Inc.

Index: src/sys/dev/iscsi/iscsi_main.c
diff -u src/sys/dev/iscsi/iscsi_main.c:1.27 src/sys/dev/iscsi/iscsi_main.c:1.28
--- src/sys/dev/iscsi/iscsi_main.c:1.27	Sun Dec  3 19:07:10 2017
+++ src/sys/dev/iscsi/iscsi_main.c	Thu Apr 11 11:40:58 2019
@@ -1,4 +1,4 @@
-/*	$netBSD: iscsi_main.c,v 1.1.1.1 2011/05/02 07:01:11 agc Exp $	*/
+/*	$NetBSD: iscsi_main.c,v 1.28 2019/04/11 11:40:58 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.64 src/sys/net80211/ieee80211_ioctl.c:1.65
--- src/sys/net80211/ieee80211_ioctl.c:1.64	Fri Mar  1 11:06:57 2019
+++ src/sys/net80211/ieee80211_ioctl.c	Thu Apr 11 11:40:58 2019
@@ -1,4 +1,4 @@
-/*	$netBSD: ieee80211_ioctl.c,v 1.60.16.1 2018/03/28 00:30:05 pgoyette Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.65 2019/04/11 11:40:58 kamil Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.64 2019/03/01 11:06:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.65 2019/04/11 11:40:58 kamil Exp $");
 #endif
 
 /*



CVS commit: src/sys/arch/hpcsh/dev/hd64461

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 11:26:13 UTC 2019

Modified Files:
src/sys/arch/hpcsh/dev/hd64461: hd64461videoreg.h

Log Message:
Fix a typo in a comment

NFCI


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h
diff -u src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h:1.4 src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h:1.5
--- src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h:1.4	Mon Apr 28 20:23:22 2008
+++ src/sys/arch/hpcsh/dev/hd64461/hd64461videoreg.h	Thu Apr 11 11:26:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hd64461videoreg.h,v 1.4 2008/04/28 20:23:22 martin Exp $	*/
+/*	$NetBSD: hd64461videoreg.h,v 1.5 2019/04/11 11:26:13 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -287,7 +287,7 @@
 #define HD64461_LCDLNAXLR_REG16			0xb000104a
 #define HD64461_LCDLNAXLR_MASK		0x07ff
 
-/* Diagonal Regsiter */
+/* Diagonal Register */
 #define HD64461_LCDLNDGR_REG16			0xb000104c
 #define HD64461_LCDLNDGR_LNDGR_SIGN		0x8000
 #define HD64461_LCDLNDGR_LNDGR_MASK	0x07ff



CVS commit: src/sys/dev/ic

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 11:25:33 UTC 2019

Modified Files:
src/sys/dev/ic: mc6854reg.h

Log Message:
Fix a typo in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/ic/mc6854reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/mc6854reg.h
diff -u src/sys/dev/ic/mc6854reg.h:1.1 src/sys/dev/ic/mc6854reg.h:1.2
--- src/sys/dev/ic/mc6854reg.h:1.1	Mon Sep 10 23:41:49 2001
+++ src/sys/dev/ic/mc6854reg.h	Thu Apr 11 11:25:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mc6854reg.h,v 1.1 2001/09/10 23:41:49 bjh21 Exp $	*/
+/*	$NetBSD: mc6854reg.h,v 1.2 2019/04/11 11:25:33 kamil Exp $	*/
 
 /*
  * Ben Harris, 2001
@@ -23,7 +23,7 @@
 #define MC6854_SR2	1 /* Status Register #2 (R) */
 #define MC6854_RXFIFO	2 /* Receiver FIFO (R) */
 
-/* Control Regsiter #1 bits */
+/* Control Register #1 bits */
 #define MC6854_CR1_AC		0x01 /* Address Control */
 #define MC6854_CR1_RIE		0x02 /* Receiver Interrupt Enable */
 #define MC6854_CR1_TIE		0x04 /* Transmitter Interrupt Enable */
@@ -100,4 +100,3 @@
 #define MC6854_SR2_RDA		0x80 /* Receiver Data Available */
 
 #define MC6854_SR2_BITS "\20\1AP\2FV\3RX_IDLE\4RXABT\5ERR\6NDCD\7OVRN\10RDA"
-



CVS commit: src/sys/arch/riscv/include

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 11:23:52 UTC 2019

Modified Files:
src/sys/arch/riscv/include: locore.h

Log Message:
Fix a typo in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/riscv/include/locore.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/riscv/include/locore.h
diff -u src/sys/arch/riscv/include/locore.h:1.3 src/sys/arch/riscv/include/locore.h:1.4
--- src/sys/arch/riscv/include/locore.h:1.3	Thu Mar 16 16:13:21 2017
+++ src/sys/arch/riscv/include/locore.h	Thu Apr 11 11:23:51 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.h,v 1.3 2017/03/16 16:13:21 chs Exp $ */
+/* $NetBSD: locore.h,v 1.4 2019/04/11 11:23:51 kamil Exp $ */
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -77,7 +77,7 @@ struct trapframe {
 #define tf_t6		tf_reg[_X_T6]
 };
 
-// For COMPAT_NETBDS32 coredumps
+// For COMPAT_NETBSD32 coredumps
 struct trapframe32 {
 	struct reg32 tf_regs;
 	register32_t tf_badaddr;	



CVS commit: src/sys/sys

2019-04-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Apr 11 11:20:46 UTC 2019

Modified Files:
src/sys/sys: kcov.h

Log Message:
Rely on volatile operations in KCOV data types

Extra atomicity isn't needed and makes maintenance burden between CPUs.

Fixes build issue on NetBSD/i386 reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/kcov.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/kcov.h
diff -u src/sys/sys/kcov.h:1.4 src/sys/sys/kcov.h:1.5
--- src/sys/sys/kcov.h:1.4	Sun Mar 10 17:51:00 2019
+++ src/sys/sys/kcov.h	Thu Apr 11 11:20:46 2019
@@ -1,4 +1,4 @@
-/*  $NetBSD: kcov.h,v 1.4 2019/03/10 17:51:00 kamil Exp $*/
+/*  $NetBSD: kcov.h,v 1.5 2019/04/11 11:20:46 kamil Exp $*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -47,19 +47,7 @@
 typedef volatile uint64_t kcov_int_t;
 #define KCOV_ENTRY_SIZE sizeof(kcov_int_t)
 
-/*
- * Always prefer 64-bit atomic operations whenever accessible.
- *
- * As a fallback keep regular volatile move operation that it's not known
- * to have negative effect in KCOV even if interrupted in the middle of
- * operation.
- */
-#ifdef __HAVE_ATOMIC64_OPS
-#define KCOV_STORE(x,v)	__atomic_store_n(&(x), (v), __ATOMIC_RELAXED)
-#define KCOV_LOAD(x)	__atomic_load_n(&(x), __ATOMIC_RELAXED)
-#else
 #define KCOV_STORE(x,v)	(x) = (v)
 #define KCOV_LOAD(x)	(x)
-#endif
 
 #endif /* !_SYS_KCOV_H_ */



CVS commit: src/sys/kern

2019-04-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Apr  7 21:01:43 UTC 2019

Modified Files:
src/sys/kern: subr_kcov.c

Log Message:
Switch kcov module class to MODULE_CLASS_MISC

MODULE_CLASS_ANY is not intended to be used by modules.

Noted by 


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/kern/subr_kcov.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_kcov.c
diff -u src/sys/kern/subr_kcov.c:1.6 src/sys/kern/subr_kcov.c:1.7
--- src/sys/kern/subr_kcov.c:1.6	Sun Mar 10 22:34:14 2019
+++ src/sys/kern/subr_kcov.c	Sun Apr  7 21:01:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kcov.c,v 1.6 2019/03/10 22:34:14 kamil Exp $	*/
+/*	$NetBSD: subr_kcov.c,v 1.7 2019/04/07 21:01:43 kamil Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -547,7 +547,7 @@ __sanitizer_cov_trace_switch(uint64_t va
 
 /* -- */
 
-MODULE(MODULE_CLASS_ANY, kcov, NULL);
+MODULE(MODULE_CLASS_MISC, kcov, NULL);
 
 static void
 kcov_init(void)



CVS commit: src/sys/kern

2019-04-07 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Apr  7 14:50:41 UTC 2019

Modified Files:
src/sys/kern: kern_fork.c

Log Message:
Add a paranoid racy lock check in child_return()

In theory a child could be detached for some reason or another during
the time window between checking for PSL_TRACED and acquiring proc_lock.

Acquire the proc_lock mutex and recheck for PSL_TRACED before emitting
SIGTRAP. sigswitch() must acquite it internally anyway so this does not
have a negative impact and adds an extra sanity check.

For !PSL_TRACED case there is no impact.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/kern_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.208 src/sys/kern/kern_fork.c:1.209
--- src/sys/kern/kern_fork.c:1.208	Sat Apr  6 11:54:21 2019
+++ src/sys/kern/kern_fork.c	Sun Apr  7 14:50:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_fork.c,v 1.208 2019/04/06 11:54:21 kamil Exp $	*/
+/*	$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.208 2019/04/06 11:54:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -619,16 +619,24 @@ child_return(void *arg)
 	struct proc *p = l->l_proc;
 
 	if (p->p_slflag & PSL_TRACED) {
+		/* Paranoid check */
+		mutex_enter(proc_lock);
+		if (!(p->p_slflag & PSL_TRACED)) {
+			mutex_exit(proc_lock);
+			goto my_tracer_is_gone;
+		}
+
 		mutex_enter(p->p_lock);
 		p->p_xsig = SIGTRAP;
 		p->p_sigctx.ps_faked = true; // XXX
 		p->p_sigctx.ps_info._signo = p->p_xsig;
 		p->p_sigctx.ps_info._code = TRAP_CHLD;
-		sigswitch(0, SIGTRAP, true);
+		sigswitch(0, SIGTRAP, false);
 		// XXX ktrpoint(KTR_PSIG)
 		mutex_exit(p->p_lock);
 	}
 
+my_tracer_is_gone:
 	md_child_return(l);
 
 	/*



CVS commit: src/regress/libexec/ld.elf_so

2019-04-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr  6 16:25:52 UTC 2019

Modified Files:
src/regress/libexec/ld.elf_so: Makefile
Removed Files:
src/regress/libexec/ld.elf_so/expand: Makefile

Log Message:
Eliminate regress/libexec/ld.elf_so/expand

This test does not contain any code.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/regress/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.3 -r0 src/regress/libexec/ld.elf_so/expand/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/libexec/ld.elf_so/Makefile
diff -u src/regress/libexec/ld.elf_so/Makefile:1.2 src/regress/libexec/ld.elf_so/Makefile:1.3
--- src/regress/libexec/ld.elf_so/Makefile:1.2	Fri May 18 21:41:38 2007
+++ src/regress/libexec/ld.elf_so/Makefile	Sat Apr  6 16:25:52 2019
@@ -1,7 +1,7 @@
-#	$NetBSD: Makefile,v 1.2 2007/05/18 21:41:38 christos Exp $
+#	$NetBSD: Makefile,v 1.3 2019/04/06 16:25:52 kamil Exp $
 
 .include 
 
-SUBDIR+= expand origin
+SUBDIR+= origin
 
 .include 



CVS commit: src/tests/lib/libc/sys

2019-04-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr  6 15:41:54 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_fork.c

Log Message:
Add new tests in ATF t_fork/t_vfork

Verify whether nested fork(2)/vfork(2)/clone(2) calls are supported in a
fork(2)ed/vforked(2) child.

The interesting ones are non-forked parent and non-forked child scenarios,
in particular double vfork(2).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_fork.c
diff -u src/tests/lib/libc/sys/t_fork.c:1.3 src/tests/lib/libc/sys/t_fork.c:1.4
--- src/tests/lib/libc/sys/t_fork.c:1.3	Sat May 19 05:10:16 2018
+++ src/tests/lib/libc/sys/t_fork.c	Sat Apr  6 15:41:54 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: t_fork.c,v 1.3 2018/05/19 05:10:16 kamil Exp $	*/
+/*	$NetBSD: t_fork.c,v 1.4 2019/04/06 15:41:54 kamil Exp $	*/
 
 /*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,15 +27,17 @@
  */
 
 #include 
-__COPYRIGHT("@(#) Copyright (c) 2018\
+__COPYRIGHT("@(#) Copyright (c) 2018, 2019\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_fork.c,v 1.3 2018/05/19 05:10:16 kamil Exp $");
+__RCSID("$NetBSD: t_fork.c,v 1.4 2019/04/06 15:41:54 kamil Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -242,7 +244,7 @@ ATF_TC_HEAD(test, tc)\
 {		\
 		\
 	atf_tc_set_md_var(tc, "descr",		\
-	"raise " #sig " in vfork(2)ed child");\
+	"raise " #sig " in a child");	\
 }		\
 		\
 ATF_TC_BODY(test, tc)\
@@ -260,6 +262,97 @@ RAISE(raise6, SIGABRT) /* regular abort 
 RAISE(raise7, SIGHUP)  /* hangup */
 RAISE(raise8, SIGCONT) /* continued? */
 
+/// 
+
+static int
+clone_func(void *arg __unused)
+{
+
+	return 0;
+}
+
+static void
+nested_raw(const char *fn, volatile int flags)
+{
+	int status;
+	pid_t child, child2, wpid;
+	const size_t stack_size = 1024 * 1024;
+	void *stack, *stack_base;
+
+	stack = malloc(stack_size);
+	ATF_REQUIRE(stack != NULL);
+
+#ifdef __MACHINE_STACK_GROWS_UP
+	stack_base = stack;
+#else
+	stack_base = (char *)stack + stack_size;
+#endif
+
+	flags |= SIGCHLD;
+
+	child = FORK();
+	ATF_REQUIRE(child != 1);
+	if (child == 0) {
+		if (strcmp(fn, "fork") == 0)
+			child2 = fork();
+		else if (strcmp(fn, "vfork") == 0)
+			child2 = vfork();
+		else if (strcmp(fn, "clone") == 0)
+			child2 = __clone(clone_func, stack_base, flags, NULL);
+		else
+			__unreachable();
+
+		ASSERT_NEQ(child2, -1);
+
+		if ((strcmp(fn, "fork") == 0) || (strcmp(fn, "vfork") == 0)) {
+			if (child2 == 0)
+_exit(0);
+		}
+
+		wpid = waitpid(child2, , 0);
+		ASSERT_EQ(child2, wpid);
+		ASSERT_EQ(!!WIFEXITED(status), true);
+		ASSERT_EQ(!!WIFCONTINUED(status), false);
+		ASSERT_EQ(!!WIFSIGNALED(status), false);
+		ASSERT_EQ(!!WIFSTOPPED(status), false);
+		ASSERT_EQ(WEXITSTATUS(status), 0);
+
+		_exit(0);
+	}
+	wpid = waitpid(child, , 0);
+
+	ATF_REQUIRE_EQ(wpid, child);
+	ATF_REQUIRE_EQ(!!WIFEXITED(status), true);
+	ATF_REQUIRE_EQ(!!WIFCONTINUED(status), false);
+	ATF_REQUIRE_EQ(!!WIFSIGNALED(status), false);
+	ATF_REQUIRE_EQ(!!WIFSTOPPED(status), false);
+	ATF_REQUIRE_EQ(WEXITSTATUS(status), 0);
+}
+
+#define NESTED(test, fn, flags)			\
+ATF_TC(test);	\
+ATF_TC_HEAD(test, tc)\
+{		\
+		\
+	atf_tc_set_md_var(tc, "descr",		\
+	"Test nested " #fn " in a child");	\
+}		\
+		\
+ATF_TC_BODY(test, tc)\
+{		\
+		\
+	nested_raw(#fn, flags);			\
+}
+
+NESTED(nested_fork, fork, 0)
+NESTED(nested_vfork, vfork, 0)
+NESTED(nested_clone, clone, 0)
+NESTED(nested_clone_vm, clone, CLONE_VM)
+NESTED(nested_clone_fs, clone, CLONE_FS)
+NESTED(nested_clone_files, clone, CLONE_FILES)
+//NESTED(nested_clone_sighand, clone, CLONE_SIGHAND) // XXX
+NESTED(nested_clone_vfork, clone, CLONE_VFORK)
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, raise1);
@@ -271,5 +364,14 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, raise7);
 	ATF_TP_ADD_TC(tp, raise8);
 
+	ATF_TP_ADD_TC(tp, nested_fork);
+	ATF_TP_ADD_TC(tp, nested_vfork);
+	ATF_TP_ADD_TC(tp, nested_clone);
+	ATF_TP_ADD_TC(tp, nested_clone_vm);
+	ATF_TP_ADD_TC(tp, nested_clone_fs);
+	ATF_TP_ADD_TC(tp, nested_clone_files);
+//	ATF_TP_ADD_TC(tp, nested_clone_sighand); // XXX
+	ATF_TP_ADD_TC(tp, nested_clone_vfork);
+
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2019-04-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr  6 15:35:09 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Simplify FORK_TEST in ATF t_ptrace_wait*

Reduce the scope of combinations that were planned to be tested from the
same function body.

NFCI


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/tests/lib/libc/sys/t_ptrace_wait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.104 src/tests/lib/libc/sys/t_ptrace_wait.c:1.105
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.104	Fri Apr  5 23:01:09 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Sat Apr  6 15:35:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.104 2019/04/05 23:01:09 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.105 2019/04/06 15:35:09 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.104 2019/04/05 23:01:09 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.105 2019/04/06 15:35:09 kamil Exp $");
 
 #include 
 #include 
@@ -2946,7 +2946,7 @@ EVENTMASK_PRESERVED(eventmask_preserved_
 
 static void
 fork_body(pid_t (*fn)(void), bool trackfork, bool trackvfork,
-bool trackvforkdone, bool detachchild, bool detachparent)
+bool trackvforkdone)
 {
 	const int exitval = 5;
 	const int exitval2 = 15;
@@ -3118,61 +3118,47 @@ fork_body(pid_t (*fn)(void), bool trackf
 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
 }
 
-#define FORK_TEST(name,descr,fun,tfork,tvfork,tvforkdone,detchild,detparent) \
+#define FORK_TEST(name,fun,tfork,tvfork,tvforkdone)			\
 ATF_TC(name);\
 ATF_TC_HEAD(name, tc)			\
 {	\
-	atf_tc_set_md_var(tc, "descr", descr);\
+	atf_tc_set_md_var(tc, "descr", "Verify " #fun "(2) "		\
+	"called with 0%s%s%s in EVENT_MASK",			\
+	tfork ? "|PTRACE_FORK" : "",\
+	tvfork ? "|PTRACE_VFORK" : "",\
+	tvforkdone ? "|PTRACE_VFORK_DONE" : "");			\
 }	\
 	\
 ATF_TC_BODY(name, tc)			\
 {	\
 	\
-	fork_body(fun, tfork, tvfork, tvforkdone, detchild, detparent);	\
+	fork_body(fun, tfork, tvfork, tvforkdone);			\
 }
 
-#define F false
-#define T true
-
-#define F_IF__0(x)
-#define F_IF__1(x) x
-#define F_IF__(x,y) F_IF__ ## x (y)
-#define F_IF_(x,y) F_IF__(x,y)
-#define F_IF(x,y) F_IF_(x,y)
-
-#define DSCR(function,forkbit,vforkbit,vforkdonebit,dchildbit,dparentbit) \
-	"Verify " #function "(2) called with 0"\
-	F_IF(forkbit,"|PTRACE_FORK")	\
-	F_IF(vforkbit,"|PTRACE_VFORK")	\
-	F_IF(vforkdonebit,"|PTRACE_VFORK_DONE")\
-	" in EVENT_MASK."		\
-	F_IF(dchildbit," Detach child in this test.")			\
-	F_IF(dparentbit," Detach parent in this test.")
-
-FORK_TEST(fork1, DSCR(fork,0,0,0,0,0), fork, F, F, F, F, F)
+FORK_TEST(fork1, fork, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork2, DSCR(fork,1,0,0,0,0), fork, T, F, F, F, F)
-FORK_TEST(fork3, DSCR(fork,0,1,0,0,0), fork, F, T, F, F, F)
-FORK_TEST(fork4, DSCR(fork,1,1,0,0,0), fork, T, T, F, F, F)
+FORK_TEST(fork2, fork, true, false, false)
+FORK_TEST(fork3, fork, false, true, false)
+FORK_TEST(fork4, fork, true, true, false)
 #endif
-FORK_TEST(fork5, DSCR(fork,0,0,1,0,0), fork, F, F, T, F, F)
+FORK_TEST(fork5, fork, false, false, true)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(fork6, DSCR(fork,1,0,1,0,0), fork, T, F, T, F, F)
-FORK_TEST(fork7, DSCR(fork,0,1,1,0,0), fork, F, T, T, F, F)
-FORK_TEST(fork8, DSCR(fork,1,1,1,0,0), fork, T, T, T, F, F)
+FORK_TEST(fork6, fork, true, false, true)
+FORK_TEST(fork7, fork, false, true, true)
+FORK_TEST(fork8, fork, true, true, true)
 #endif
 
-FORK_TEST(vfork1, DSCR(vfork,0,0,0,0,0), vfork, F, F, F, F, F)
+FORK_TEST(vfork1, vfork, false, false, false)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork2, DSCR(vfork,1,0,0,0,0), vfork, T, F, F, F, F)
-FORK_TEST(vfork3, DSCR(vfork,0,1,0,0,0), vfork, F, T, F, F, F)
-FORK_TEST(vfork4, DSCR(vfork,1,1,0,0,0), vfork, T, T, F, F, F)
+FORK_TEST(vfork2, vfork, true, false, false)
+FORK_TEST(vfork3, vfork, false, true, false)
+FORK_TEST(vfork4, vfork, true, true, false)
 #endif
-FORK_TEST(vfork5, DSCR(vfork,0,0,1,0,0), vfork, F, F, T, F, F)
+FORK_TEST(vfork5, vfork, false, false, true)
 #if defined(TWAIT_HAVE_PID)
-FORK_TEST(vfork6, DSCR(vfork,1,0,1,0,0), vfork, T, F, T, F, F)
-FORK_TEST(vfork7, DSCR(vfork,0,1,1,0,0), vfork, F, T, T, F, F)
-FORK_TEST(vfork8, DSCR(vfork,1,1,1,0,0), vfork, T, T, T, F, F)
+FORK_TEST(vfork6, vfork, true, false, true)
+FORK_TEST(vfork7, vfork, false, true, true)
+FORK_TEST(vfork8, vfork, true, true, true)
 #endif
 
 /// 



CVS commit: src/distrib/sets/lists/debug

2019-04-06 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Apr  6 12:34:30 UTC 2019

Modified Files:
src/distrib/sets/lists/debug: module.mi

Log Message:
Register t_ufetchstore.debug in distrib files


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/distrib/sets/lists/debug/module.mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/module.mi
diff -u src/distrib/sets/lists/debug/module.mi:1.2 src/distrib/sets/lists/debug/module.mi:1.3
--- src/distrib/sets/lists/debug/module.mi:1.2	Sat Feb 23 11:23:07 2019
+++ src/distrib/sets/lists/debug/module.mi	Sat Apr  6 12:34:30 2019
@@ -1,5 +1,6 @@
-# $NetBSD: module.mi,v 1.2 2019/02/23 11:23:07 mlelstv Exp $
+# $NetBSD: module.mi,v 1.3 2019/04/06 12:34:30 kamil Exp $
 ./usr/libdata/debug/usr/tests/modules/k_helper3.debug	tests-sys-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/modules/t_builtin.debug	tests-sys-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/modules/t_kcov.debug	tests-sys-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/modules/t_modctl.debug	tests-sys-debug		debug,atf,rump
+./usr/libdata/debug/usr/tests/modules/t_ufetchstore.debug	tests-sys-debug		debug,atf,rump



<    1   2   3   4   5   6   7   8   9   10   >