CVS commit: src/external/gpl3/gcc/lib/liblto_plugin

2017-11-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Nov  5 02:36:00 UTC 2017

Modified Files:
src/external/gpl3/gcc/lib/liblto_plugin: Makefile

Log Message:
Backport patch from gcc.old for liblto_plugin

Correct resolution of xstrerror(). Switch from -liberty (which has PIC
problems as a local library) to directly linking xstrerror.c with
liblto_plugin.

Fix in gcc.old by 

PR 52674 by myself


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/gpl3/gcc/lib/liblto_plugin/Makefile

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/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.6 src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.7
--- src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.6	Sat Nov  4 16:21:49 2017
+++ src/external/gpl3/gcc/lib/liblto_plugin/Makefile	Sun Nov  5 02:36:00 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.6 2017/11/04 16:21:49 kamil Exp $
+#	$NetBSD: Makefile,v 1.7 2017/11/05 02:36:00 kamil Exp $
 
 .include 
 .include 
@@ -11,7 +11,7 @@ GNUHOSTDIST=	${DIST}
 SRCS=		lto-plugin.c hashtab.c simple-object.c pex-unix.c \
 		pex-common.c argv.c make-temp-file.c concat.c \
 		simple-object-elf.c simple-object-mach-o.c \
-		simple-object-coff.c simple-object-xcoff.c
+		simple-object-coff.c simple-object-xcoff.c xstrerror.c
 
 CPPFLAGS+=	-I${DIST}/include -I. 
 CPPFLAGS+=	-DHAVE_CONFIG_H
@@ -31,10 +31,6 @@ LIBDIR=		/usr/libexec
 SHLIB_MAJOR=	0
 SHLIB_MINOR=	1
 
-LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
-LDADD+=		-L${LIBIBERTYDIR} -liberty
-DPADD+=		${LIBIBERTYDIR}/libiberty.a
-
 # Yuck, we have to run configure to generate this one...
 CLEANFILES+=	config.h
 HOST_CFLAGS+= -I${.OBJDIR}



CVS commit: src/sys/arch/sparc/sparc

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov  5 01:18:15 UTC 2017

Modified Files:
src/sys/arch/sparc/sparc: kobj_machdep.c

Log Message:
fix type of addr.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/sparc/sparc/kobj_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/sparc/sparc/kobj_machdep.c
diff -u src/sys/arch/sparc/sparc/kobj_machdep.c:1.4 src/sys/arch/sparc/sparc/kobj_machdep.c:1.5
--- src/sys/arch/sparc/sparc/kobj_machdep.c:1.4	Fri Nov  3 05:59:08 2017
+++ src/sys/arch/sparc/sparc/kobj_machdep.c	Sat Nov  4 21:18:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kobj_machdep.c,v 1.4 2017/11/03 09:59:08 maxv Exp $	*/
+/*	$NetBSD: kobj_machdep.c,v 1.5 2017/11/05 01:18:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc.
@@ -126,9 +126,9 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 	   bool isrela, bool local)
 {
 	const Elf_Rela *rela;
-	Elf_Addr *where;
+	Elf_Addr *where, addr;
 	Elf_Word value, mask;
-	uintptr_t tmp, addr;
+	uintptr_t tmp;
 	u_int symidx, type;
 	int error;
 



CVS commit: src/external/gpl3/gcc.old/lib/liblto_plugin

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov  5 01:16:16 UTC 2017

Modified Files:
src/external/gpl3/gcc.old/lib/liblto_plugin: Makefile

Log Message:
undo previous; we can't link with libiberty because it is a private library
and not build as pic. Instead just bring in the xstrerror.c source from it.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile

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/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.5 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.6
--- src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.5	Sat Nov  4 12:21:49 2017
+++ src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile	Sat Nov  4 21:16:16 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.5 2017/11/04 16:21:49 kamil Exp $
+#	$NetBSD: Makefile,v 1.6 2017/11/05 01:16:16 christos Exp $
 
 .include 
 .include 
@@ -11,7 +11,7 @@ GNUHOSTDIST=	${DIST}
 SRCS=		lto-plugin.c hashtab.c simple-object.c pex-unix.c \
 		pex-common.c argv.c make-temp-file.c concat.c \
 		simple-object-elf.c simple-object-mach-o.c \
-		simple-object-coff.c simple-object-xcoff.c
+		simple-object-coff.c simple-object-xcoff.c xstrerror.c
 
 CPPFLAGS+=	-I${DIST}/include -I. 
 CPPFLAGS+=	-DHAVE_CONFIG_H
@@ -31,10 +31,6 @@ LIBDIR=		/usr/libexec
 SHLIB_MAJOR=	0
 SHLIB_MINOR=	1
 
-LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
-LDADD+=		-L${LIBIBERTYDIR} -liberty
-DPADD+=		${LIBIBERTYDIR}/libiberty.a
-
 # Yuck, we have to run configure to generate this one...
 CLEANFILES+=	config.h
 HOST_CFLAGS+= -I${.OBJDIR}



CVS commit: src/sys

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  4 22:17:55 UTC 2017

Modified Files:
src/sys/ddb: db_elf.c
src/sys/kern: kern_ksyms.c subr_kobj.c
src/sys/sys: ksyms.h

Log Message:
use Elf_Sym ** instead of casting.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/ddb/db_elf.c
cvs rdiff -u -r1.86 -r1.87 src/sys/kern/kern_ksyms.c
cvs rdiff -u -r1.64 -r1.65 src/sys/kern/subr_kobj.c
cvs rdiff -u -r1.34 -r1.35 src/sys/sys/ksyms.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/ddb/db_elf.c
diff -u src/sys/ddb/db_elf.c:1.27 src/sys/ddb/db_elf.c:1.28
--- src/sys/ddb/db_elf.c:1.27	Sat Mar 14 11:36:16 2009
+++ src/sys/ddb/db_elf.c	Sat Nov  4 18:17:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_elf.c,v 1.27 2009/03/14 15:36:16 dsl Exp $	*/
+/*	$NetBSD: db_elf.c,v 1.28 2017/11/04 22:17:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2009 The NetBSD Foundation, Inc.
@@ -31,14 +31,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_elf.c,v 1.27 2009/03/14 15:36:16 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_elf.c,v 1.28 2017/11/04 22:17:55 christos Exp $");
 
 #include 
 #include 
 #include 
 
-#include 
 
+#include 
 #include 
 #include 
 
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_elf.c,v 1
 
 #define	ELFSIZE		DB_ELFSIZE
 
+#include 
 #include 
 
 static char	*db_elf_find_strtab(db_symtab_t *);

Index: src/sys/kern/kern_ksyms.c
diff -u src/sys/kern/kern_ksyms.c:1.86 src/sys/kern/kern_ksyms.c:1.87
--- src/sys/kern/kern_ksyms.c:1.86	Fri Nov  3 05:59:07 2017
+++ src/sys/kern/kern_ksyms.c	Sat Nov  4 18:17:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.86 2017/11/03 09:59:07 maxv Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.87 2017/11/04 22:17:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.86 2017/11/03 09:59:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.87 2017/11/04 22:17:55 christos Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -566,7 +566,7 @@ ksyms_addsyms_explicit(void *ehdr, void 
  * Call with ksyms_lock, unless known that the symbol table can't change.
  */
 int
-ksyms_getval_unlocked(const char *mod, const char *sym, void **symp,
+ksyms_getval_unlocked(const char *mod, const char *sym, Elf_Sym **symp,
 unsigned long *val, int type)
 {
 	struct ksyms_symtab *st;
@@ -574,8 +574,7 @@ ksyms_getval_unlocked(const char *mod, c
 
 #ifdef KSYMS_DEBUG
 	if (ksyms_debug & FOLLOW_CALLS)
-		printf("ksyms_getval_unlocked: mod %s sym %s valp %p\n",
-		mod, sym, val);
+		printf("%s: mod %s sym %s valp %p\n", __func__, mod, sym, val);
 #endif
 
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
@@ -586,7 +585,7 @@ ksyms_getval_unlocked(const char *mod, c
 		if ((es = findsym(sym, st, type)) != NULL) {
 			*val = es->st_value;
 			if (symp)
-*symp = (void *)es;
+*symp = es;
 			return 0;
 		}
 	}

Index: src/sys/kern/subr_kobj.c
diff -u src/sys/kern/subr_kobj.c:1.64 src/sys/kern/subr_kobj.c:1.65
--- src/sys/kern/subr_kobj.c:1.64	Sat Nov  4 08:14:41 2017
+++ src/sys/kern/subr_kobj.c	Sat Nov  4 18:17:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kobj.c,v 1.64 2017/11/04 12:14:41 martin Exp $	*/
+/*	$NetBSD: subr_kobj.c,v 1.65 2017/11/04 22:17:55 christos Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.64 2017/11/04 12:14:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.65 2017/11/04 22:17:55 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -980,7 +980,7 @@ kobj_checksyms(kobj_t ko, bool undefined
 		 * module_lock).
 		 */
 		name = ko->ko_strtab + sym->st_name;
-		if (ksyms_getval_unlocked(NULL, name, (void **), ,
+		if (ksyms_getval_unlocked(NULL, name, , ,
 		KSYMS_EXTERN) != 0) {
 			if (undefined) {
 kobj_error(ko, "symbol `%s' not found",

Index: src/sys/sys/ksyms.h
diff -u src/sys/sys/ksyms.h:1.34 src/sys/sys/ksyms.h:1.35
--- src/sys/sys/ksyms.h:1.34	Fri Nov  3 05:59:07 2017
+++ src/sys/sys/ksyms.h	Sat Nov  4 18:17:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ksyms.h,v 1.34 2017/11/03 09:59:07 maxv Exp $	*/
+/*	$NetBSD: ksyms.h,v 1.35 2017/11/04 22:17:55 christos Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003 Anders Magnusson (ra...@ludd.luth.se).
@@ -30,8 +30,12 @@
 #ifndef _SYS_KSYMS_H_
 #define _SYS_KSYMS_H_
 
-#ifdef _KSYMS_PRIVATE
+#ifndef ELFSIZE
+#define ELFSIZE ARCH_ELFSIZE
+#endif
 #include 
+
+#ifdef _KSYMS_PRIVATE
 #include 
 #include 
 
@@ -131,7 +135,7 @@ typedef int (*ksyms_callback_t)(const ch
 
 int ksyms_getname(const char **, const char **, vaddr_t, int);
 int ksyms_getval(const char *, const char *, unsigned long *, int);
-int ksyms_getval_unlocked(const char *, const char *, void **,
+int ksyms_getval_unlocked(const char *, 

CVS commit: xsrc/external/mit/xorg-server.old/dist

2017-11-04 Thread matthew green
Module Name:xsrc
Committed By:   mrg
Date:   Sat Nov  4 21:50:46 UTC 2017

Modified Files:
xsrc/external/mit/xorg-server.old/dist/Xext: panoramiX.c saver.c
xvdisp.c
xsrc/external/mit/xorg-server.old/dist/Xi: xichangehierarchy.c
xsrc/external/mit/xorg-server.old/dist/dbe: dbe.c
xsrc/external/mit/xorg-server.old/dist/dix: dispatch.c
xsrc/external/mit/xorg-server.old/dist/hw/dmx: dmxpict.c
xsrc/external/mit/xorg-server.old/dist/hw/xfree86/dixmods/extmod:
xf86dga2.c
xsrc/external/mit/xorg-server.old/dist/hw/xfree86/dri: xf86dri.c
xsrc/external/mit/xorg-server.old/dist/render: render.c
xsrc/external/mit/xorg-server.old/dist/xfixes: cursor.c region.c
saveset.c xfixes.c

Log Message:
apply fixes for CVEs 2017-12176 to 2017-12187 to xorg-server 1.10.
several of the changes were in new code, and the DGA code had moved.

--
>From 1b1d4c04695dced2463404174b50b3581dbd857b Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Sun, 21 Dec 2014 01:10:03 -0500
Subject: hw/xfree86: unvalidated lengths

This addresses:
CVE-2017-12180 in XFree86-VidModeExtension
CVE-2017-12181 in XFree86-DGA
CVE-2017-12182 in XFree86-DRI
--
>From 211e05ac85a294ef361b9f80d689047fa52b9076 Mon Sep 17 00:00:00 2001
From: Michal Srb 
Date: Fri, 7 Jul 2017 17:21:46 +0200
Subject: Xi: Test exact size of XIBarrierReleasePointer

Otherwise a client can send any value of num_barriers and cause reading or 
swapping of values on heap behind the receive buffer.
--
>From 4ca68b878e851e2136c234f40a25008297d8d831 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 10:09:14 -0500
Subject: dbe: Unvalidated variable-length request in ProcDbeGetVisualInfo
 (CVE-2017-12177)

v2: Protect against integer overflow (Alan Coopersmith)
--
>From 55caa8b08c84af2b50fbc936cf334a5a93dd7db5 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 11:43:05 -0500
Subject: xfixes: unvalidated lengths (CVE-2017-12183)

v2: Use before swap (Jeremy Huddleston Sequoia)

v3: Fix wrong XFixesCopyRegion checks (Alan Coopersmith)
--
>From 859b08d523307eebde7724fd1a0789c44813e821 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Wed, 24 Dec 2014 16:22:18 -0500
Subject: Xi: fix wrong extra length check in ProcXIChangeHierarchy
 (CVE-2017-12178)
--
>From 9c23685009aa96f4b861dcc5d2e01dbee00c4dd9 Mon Sep 17 00:00:00 2001
From: Michal Srb 
Date: Fri, 7 Jul 2017 17:04:03 +0200
Subject: os: Make sure big requests have sufficient length.

A client can send a big request where the 32B "length" field has value
0. When the big request header is removed and the length corrected,
the value will underflow to 0x.  Functions processing the
request later will think that the client sent much more data and may
touch memory beyond the receive buffer.
--
>From b747da5e25be944337a9cd1415506fc06b70aa81 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 10:15:46 -0500
Subject: Unvalidated extra length in ProcEstablishConnection (CVE-2017-12176)


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c \
xsrc/external/mit/xorg-server.old/dist/Xext/saver.c \
xsrc/external/mit/xorg-server.old/dist/Xext/xvdisp.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/Xi/xichangehierarchy.c
cvs rdiff -u -r1.1.1.1 -r1.2 xsrc/external/mit/xorg-server.old/dist/dbe/dbe.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/dix/dispatch.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/hw/dmx/dmxpict.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/hw/xfree86/dixmods/extmod/xf86dga2.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/hw/xfree86/dri/xf86dri.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/render/render.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server.old/dist/xfixes/cursor.c \
xsrc/external/mit/xorg-server.old/dist/xfixes/region.c \
xsrc/external/mit/xorg-server.old/dist/xfixes/saveset.c \
xsrc/external/mit/xorg-server.old/dist/xfixes/xfixes.c

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

Modified files:

Index: xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c
diff -u xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c:1.1.1.1 xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c:1.2
--- xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c:1.1.1.1	Thu Jun  9 09:07:56 2016
+++ xsrc/external/mit/xorg-server.old/dist/Xext/panoramiX.c	Sat Nov  4 21:50:45 2017
@@ -990,10 +990,11 @@ ProcPanoramiXGetScreenSize(ClientPtr cli
 	xPanoramiXGetScreenSizeReply	rep;
 	int			n, rc;
 	
+	

CVS commit: xsrc/external/mit/xorg-server/dist

2017-11-04 Thread matthew green
Module Name:xsrc
Committed By:   mrg
Date:   Sat Nov  4 21:49:33 UTC 2017

Modified Files:
xsrc/external/mit/xorg-server/dist/Xext: panoramiX.c saver.c vidmode.c
xres.c xvdisp.c
xsrc/external/mit/xorg-server/dist/Xi: xibarriers.c xichangehierarchy.c
xsrc/external/mit/xorg-server/dist/dbe: dbe.c
xsrc/external/mit/xorg-server/dist/dix: dispatch.c
xsrc/external/mit/xorg-server/dist/hw/dmx: dmxpict.c
xsrc/external/mit/xorg-server/dist/hw/xfree86/common: xf86DGA.c
xsrc/external/mit/xorg-server/dist/hw/xfree86/dri: xf86dri.c
xsrc/external/mit/xorg-server/dist/pseudoramiX: pseudoramiX.c
xsrc/external/mit/xorg-server/dist/render: render.c
xsrc/external/mit/xorg-server/dist/xfixes: cursor.c region.c saveset.c
xfixes.c

Log Message:
apply fixes for CVEs 2017-12176 to 2017-12187.

--
>From 1b1d4c04695dced2463404174b50b3581dbd857b Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Sun, 21 Dec 2014 01:10:03 -0500
Subject: hw/xfree86: unvalidated lengths

This addresses:
CVE-2017-12180 in XFree86-VidModeExtension
CVE-2017-12181 in XFree86-DGA
CVE-2017-12182 in XFree86-DRI
--
>From 211e05ac85a294ef361b9f80d689047fa52b9076 Mon Sep 17 00:00:00 2001
From: Michal Srb 
Date: Fri, 7 Jul 2017 17:21:46 +0200
Subject: Xi: Test exact size of XIBarrierReleasePointer

Otherwise a client can send any value of num_barriers and cause reading or 
swapping of values on heap behind the receive buffer.
--
>From 4ca68b878e851e2136c234f40a25008297d8d831 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 10:09:14 -0500
Subject: dbe: Unvalidated variable-length request in ProcDbeGetVisualInfo
 (CVE-2017-12177)

v2: Protect against integer overflow (Alan Coopersmith)
--
>From 55caa8b08c84af2b50fbc936cf334a5a93dd7db5 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 11:43:05 -0500
Subject: xfixes: unvalidated lengths (CVE-2017-12183)

v2: Use before swap (Jeremy Huddleston Sequoia)

v3: Fix wrong XFixesCopyRegion checks (Alan Coopersmith)
--
>From 859b08d523307eebde7724fd1a0789c44813e821 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Wed, 24 Dec 2014 16:22:18 -0500
Subject: Xi: fix wrong extra length check in ProcXIChangeHierarchy
 (CVE-2017-12178)
--
>From 9c23685009aa96f4b861dcc5d2e01dbee00c4dd9 Mon Sep 17 00:00:00 2001
From: Michal Srb 
Date: Fri, 7 Jul 2017 17:04:03 +0200
Subject: os: Make sure big requests have sufficient length.

A client can send a big request where the 32B "length" field has value
0. When the big request header is removed and the length corrected,
the value will underflow to 0x.  Functions processing the
request later will think that the client sent much more data and may
touch memory beyond the receive buffer.
--
>From b747da5e25be944337a9cd1415506fc06b70aa81 Mon Sep 17 00:00:00 2001
From: Nathan Kidd 
Date: Fri, 9 Jan 2015 10:15:46 -0500
Subject: Unvalidated extra length in ProcEstablishConnection (CVE-2017-12176)


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.6 -r1.2 \
xsrc/external/mit/xorg-server/dist/Xext/panoramiX.c
cvs rdiff -u -r1.1.1.7 -r1.2 xsrc/external/mit/xorg-server/dist/Xext/saver.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server/dist/Xext/vidmode.c
cvs rdiff -u -r1.1.1.4 -r1.2 xsrc/external/mit/xorg-server/dist/Xext/xres.c
cvs rdiff -u -r1.6 -r1.7 xsrc/external/mit/xorg-server/dist/Xext/xvdisp.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server/dist/Xi/xibarriers.c
cvs rdiff -u -r1.3 -r1.4 \
xsrc/external/mit/xorg-server/dist/Xi/xichangehierarchy.c
cvs rdiff -u -r1.3 -r1.4 xsrc/external/mit/xorg-server/dist/dbe/dbe.c
cvs rdiff -u -r1.3 -r1.4 xsrc/external/mit/xorg-server/dist/dix/dispatch.c
cvs rdiff -u -r1.1.1.5 -r1.2 \
xsrc/external/mit/xorg-server/dist/hw/dmx/dmxpict.c
cvs rdiff -u -r1.1.1.7 -r1.2 \
xsrc/external/mit/xorg-server/dist/hw/xfree86/common/xf86DGA.c
cvs rdiff -u -r1.1.1.5 -r1.2 \
xsrc/external/mit/xorg-server/dist/hw/xfree86/dri/xf86dri.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
xsrc/external/mit/xorg-server/dist/pseudoramiX/pseudoramiX.c
cvs rdiff -u -r1.3 -r1.4 xsrc/external/mit/xorg-server/dist/render/render.c
cvs rdiff -u -r1.1.1.7 -r1.2 \
xsrc/external/mit/xorg-server/dist/xfixes/cursor.c
cvs rdiff -u -r1.1.1.6 -r1.2 \
xsrc/external/mit/xorg-server/dist/xfixes/region.c
cvs rdiff -u -r1.1.1.4 -r1.2 \
xsrc/external/mit/xorg-server/dist/xfixes/saveset.c
cvs rdiff -u -r1.1.1.5 -r1.2 \
xsrc/external/mit/xorg-server/dist/xfixes/xfixes.c

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

Modified files:

Index: xsrc/external/mit/xorg-server/dist/Xext/panoramiX.c
diff -u xsrc/external/mit/xorg-server/dist/Xext/panoramiX.c:1.1.1.6 

CVS commit: src/sys/dev/scsipi

2017-11-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Nov  4 21:02:37 UTC 2017

Modified Files:
src/sys/dev/scsipi: scsipi_disk.h

Log Message:
fix comment - scsipi_rw_big was renamed to scsipi_rw_10 a while ago


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/scsipi/scsipi_disk.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/scsipi/scsipi_disk.h
diff -u src/sys/dev/scsipi/scsipi_disk.h:1.22 src/sys/dev/scsipi/scsipi_disk.h:1.23
--- src/sys/dev/scsipi/scsipi_disk.h:1.22	Wed Apr  5 20:15:49 2017
+++ src/sys/dev/scsipi/scsipi_disk.h	Sat Nov  4 21:02:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_disk.h,v 1.22 2017/04/05 20:15:49 jdolecek Exp $	*/
+/*	$NetBSD: scsipi_disk.h,v 1.23 2017/11/04 21:02:37 jdolecek Exp $	*/
 
 /*
  * SCSI and SCSI-like interfaces description
@@ -77,7 +77,7 @@ struct scsipi_rw_10 {
 #define	WRITE_12		0xaa
 struct scsipi_rw_12 {
 	u_int8_t opcode;
-	u_int8_t byte2;		/* see scsipi_rw_big bits */
+	u_int8_t byte2;		/* see scsipi_rw_10 bits */
 	u_int8_t addr[4];
 	u_int8_t length[4];
 	u_int8_t byte11;
@@ -88,7 +88,7 @@ struct scsipi_rw_12 {
 #define	WRITE_16		0x8a
 struct scsipi_rw_16 {
 	u_int8_t opcode;
-	u_int8_t byte2;		/* see scsipi_rw_big bits */
+	u_int8_t byte2;		/* see scsipi_rw_10 bits */
 	u_int8_t addr[8];
 	u_int8_t length[4];
 	u_int8_t byte15;



CVS commit: src/sys/arch/arm/cortex

2017-11-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Nov  4 17:09:55 UTC 2017

Modified Files:
src/sys/arch/arm/cortex: a9_mpsubr.S

Log Message:
Ensure CNTVOFF is 0 before dropping out of Hyp mode
CVS --


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/arm/cortex/a9_mpsubr.S

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/cortex/a9_mpsubr.S
diff -u src/sys/arch/arm/cortex/a9_mpsubr.S:1.51 src/sys/arch/arm/cortex/a9_mpsubr.S:1.52
--- src/sys/arch/arm/cortex/a9_mpsubr.S:1.51	Fri Sep 22 06:31:02 2017
+++ src/sys/arch/arm/cortex/a9_mpsubr.S	Sat Nov  4 17:09:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: a9_mpsubr.S,v 1.51 2017/09/22 06:31:02 skrll Exp $	*/
+/*	$NetBSD: a9_mpsubr.S,v 1.52 2017/11/04 17:09:55 skrll Exp $	*/
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -357,6 +357,10 @@ cortex_init:
 	teq	r0, #(PSR_HYP32_MODE)	/* Hyp Mode? */
 	bne	1f
 
+	/* Set CNTVOFF to 0 */
+	mov	r0, #0
+	mcrr	p15, 4, r0, r0, c14
+
 	/* Ensure that IRQ, and FIQ will be disabled after eret */
 	mrs	r0, cpsr
 	bic	r0, r0, #(PSR_MODE)



CVS commit: src

2017-11-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Nov  4 16:21:50 UTC 2017

Modified Files:
src/distrib/sets/lists/comp: shl.mi
src/distrib/sets/lists/debug: shl.mi
src/external/gpl3/gcc.old/lib/liblto_plugin: Makefile
src/external/gpl3/gcc/lib/liblto_plugin: Makefile

Log Message:
Bump lib minor for liblto_plugin.so link with -liberty

PR 52674 by myself


To generate a diff of this commit:
cvs rdiff -u -r1.308 -r1.309 src/distrib/sets/lists/comp/shl.mi
cvs rdiff -u -r1.186 -r1.187 src/distrib/sets/lists/debug/shl.mi
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile
cvs rdiff -u -r1.5 -r1.6 src/external/gpl3/gcc/lib/liblto_plugin/Makefile

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/shl.mi
diff -u src/distrib/sets/lists/comp/shl.mi:1.308 src/distrib/sets/lists/comp/shl.mi:1.309
--- src/distrib/sets/lists/comp/shl.mi:1.308	Tue Oct 10 19:31:56 2017
+++ src/distrib/sets/lists/comp/shl.mi	Sat Nov  4 16:21:49 2017
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.308 2017/10/10 19:31:56 christos Exp $
+# $NetBSD: shl.mi,v 1.309 2017/11/04 16:21:49 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -277,4 +277,4 @@
 ./usr/lib/libzpool_pic.a			comp-zfs-piclib		compatfile,zfs,picinstall
 ./usr/libexec/liblto_plugin.so			comp-c-bin  gcc
 ./usr/libexec/liblto_plugin.so.0		comp-c-bin  gcc
-./usr/libexec/liblto_plugin.so.0.0		comp-c-bin  gcc
+./usr/libexec/liblto_plugin.so.0.1		comp-c-bin  gcc

Index: src/distrib/sets/lists/debug/shl.mi
diff -u src/distrib/sets/lists/debug/shl.mi:1.186 src/distrib/sets/lists/debug/shl.mi:1.187
--- src/distrib/sets/lists/debug/shl.mi:1.186	Wed Oct 25 06:32:59 2017
+++ src/distrib/sets/lists/debug/shl.mi	Sat Nov  4 16:21:49 2017
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.186 2017/10/25 06:32:59 kre Exp $
+# $NetBSD: shl.mi,v 1.187 2017/11/04 16:21:49 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
@@ -297,7 +297,7 @@
 ./usr/libdata/debug/usr/lib/npf/libext_normalise.so.0.0.debug	comp-obsolete	debug,compatfile,npf,obsolete
 ./usr/libdata/debug/usr/lib/npf/libext_rndblock.so.0.0.debug	comp-obsolete	debug,compatfile,npf,obsolete
 ./usr/libdata/debug/usr/libexec/ld.elf_so.debug			comp-sys-debug	debug,dynamicroot
-./usr/libdata/debug/usr/libexec/liblto_plugin.so.0.0.debug	comp-sys-debug	debug,gcc
+./usr/libdata/debug/usr/libexec/liblto_plugin.so.0.1.debug	comp-sys-debug	debug,gcc
 ./usr/libdata/debug/usr/tests/lib/csu/h_initfini3_dso.so.1.debug	tests-lib-debug		debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/csu/libh_initfini3_dso.so.1.debug	tests-obsolete		debug,compattestfile,atf,obsolete
 ./usr/libdata/debug/usr/tests/lib/libc/tls/h_tls_dlopen.so.1.debug	tests-lib-debug		debug,compattestfile,atf
@@ -320,4 +320,3 @@
 ./usr/tests/libexec/ld.elf_so/libh_helper_dso2_g.a			comp-c-debuglib	atf,debuglib,compattestfile
 ./usr/tests/libexec/ld.elf_so/libh_helper_dso3_g.a			comp-c-debuglib	atf,debuglib,compattestfile
 ./usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso_g.a			comp-c-debuglib	atf,debuglib,compattestfile
-

Index: src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.4 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.5
--- src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.4	Sat Nov  4 15:59:16 2017
+++ src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile	Sat Nov  4 16:21:49 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2017/11/04 15:59:16 kamil Exp $
+#	$NetBSD: Makefile,v 1.5 2017/11/04 16:21:49 kamil Exp $
 
 .include 
 .include 
@@ -29,7 +29,7 @@ LIBDIR=		/usr/libexec
 .if ${MKGCC} != "no"
 
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	0
+SHLIB_MINOR=	1
 
 LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
 LDADD+=		-L${LIBIBERTYDIR} -liberty

Index: src/external/gpl3/gcc/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.5 src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.6
--- src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.5	Sat Nov  4 16:03:12 2017
+++ src/external/gpl3/gcc/lib/liblto_plugin/Makefile	Sat Nov  4 16:21:49 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.5 2017/11/04 16:03:12 kamil Exp $
+#	$NetBSD: Makefile,v 1.6 2017/11/04 16:21:49 kamil Exp $
 
 .include 
 .include 
@@ -29,7 +29,7 @@ LIBDIR=		/usr/libexec
 .if ${MKGCC} != "no"
 
 SHLIB_MAJOR=	0
-SHLIB_MINOR=	0
+SHLIB_MINOR=	1
 
 LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
 LDADD+=		-L${LIBIBERTYDIR} -liberty



CVS commit: src/external/gpl3/gcc/lib/liblto_plugin

2017-11-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Nov  4 16:03:12 UTC 2017

Modified Files:
src/external/gpl3/gcc/lib/liblto_plugin: Makefile

Log Message:
Link liblto_plugin with -liberty (gcc)

GCC passes liblto_plugin.so in the linker invocation (part of "gcc -v file.c"):

ld -plugin /usr/libexec/liblto_plugin.so -plugin-opt=/usr/libexec/lto-wrapper \
-plugin-opt=-fresolution=/var/tmp//ccxda9Ar.res \
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc \
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s \
-plugin-opt=-pass-through=-lgcc --eh-frame-hdr -dc -dp -e _start \
-dynamic-linker /usr/libexec/ld.elf_so /usr/lib/crt0.o /usr/lib/crti.o \
/usr/lib/crtbegin.o /var/tmp//cc7A7mOK.o --as-needed -lgcc_s --no-as-needed \
-lgcc -lc --as-needed -lgcc_s --no-as-needed -lgcc /usr/lib/crtend.o \
/usr/lib/crtn.o

When attempting to use GNU GOLD, liblto_plugin.so cannot be used because it \
has missing symbol xstrerror:

ld: error: /usr/libexec/liblto_plugin.so: could not load plugin library: \
/usr/libexec/liblto_plugin.so: Undefined PLT symbol "xstrerror" (symnum = 38)

>From Makefiles and sources inspection, liblto_plugin.so shall be linked with \
libiberty (-liberty), a utility GNU library for internal usage with helping \
functions.

PR 52674 by myself


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc/lib/liblto_plugin/Makefile

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/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.4 src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.5
--- src/external/gpl3/gcc/lib/liblto_plugin/Makefile:1.4	Wed Apr 20 17:18:52 2016
+++ src/external/gpl3/gcc/lib/liblto_plugin/Makefile	Sat Nov  4 16:03:12 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2016/04/20 17:18:52 christos Exp $
+#	$NetBSD: Makefile,v 1.5 2017/11/04 16:03:12 kamil Exp $
 
 .include 
 .include 
@@ -31,6 +31,10 @@ LIBDIR=		/usr/libexec
 SHLIB_MAJOR=	0
 SHLIB_MINOR=	0
 
+LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
+LDADD+=		-L${LIBIBERTYDIR} -liberty
+DPADD+=		${LIBIBERTYDIR}/libiberty.a
+
 # Yuck, we have to run configure to generate this one...
 CLEANFILES+=	config.h
 HOST_CFLAGS+= -I${.OBJDIR}



CVS commit: src/external/gpl3/gcc.old/lib/liblto_plugin

2017-11-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Nov  4 15:59:16 UTC 2017

Modified Files:
src/external/gpl3/gcc.old/lib/liblto_plugin: Makefile

Log Message:
Link liblto_plugin with -liberty (gcc.old)

GCC passes liblto_plugin.so in the linker invocation (part of "gcc -v file.c"):

ld -plugin /usr/libexec/liblto_plugin.so -plugin-opt=/usr/libexec/lto-wrapper \
-plugin-opt=-fresolution=/var/tmp//ccxda9Ar.res \
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc \
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s \
-plugin-opt=-pass-through=-lgcc --eh-frame-hdr -dc -dp -e _start \
-dynamic-linker /usr/libexec/ld.elf_so /usr/lib/crt0.o /usr/lib/crti.o \
/usr/lib/crtbegin.o /var/tmp//cc7A7mOK.o --as-needed -lgcc_s --no-as-needed \
-lgcc -lc --as-needed -lgcc_s --no-as-needed -lgcc /usr/lib/crtend.o \
/usr/lib/crtn.o

When attempting to use GNU GOLD, liblto_plugin.so cannot be used because it \
has missing symbol xstrerror:

ld: error: /usr/libexec/liblto_plugin.so: could not load plugin library: \
/usr/libexec/liblto_plugin.so: Undefined PLT symbol "xstrerror" (symnum = 38)

>From Makefiles and sources inspection, liblto_plugin.so shall be linked with \
libiberty (-liberty), a utility GNU library for internal usage with helping \
functions.

PR 52674 by myself


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile

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/lib/liblto_plugin/Makefile
diff -u src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.3 src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.4
--- src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile:1.3	Sun Jul 23 01:12:06 2017
+++ src/external/gpl3/gcc.old/lib/liblto_plugin/Makefile	Sat Nov  4 15:59:16 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.3 2017/07/23 01:12:06 mrg Exp $
+#	$NetBSD: Makefile,v 1.4 2017/11/04 15:59:16 kamil Exp $
 
 .include 
 .include 
@@ -31,6 +31,10 @@ LIBDIR=		/usr/libexec
 SHLIB_MAJOR=	0
 SHLIB_MINOR=	0
 
+LIBIBERTYDIR!=	cd ${.CURDIR}/../../lib/libiberty && ${PRINTOBJDIR}
+LDADD+=		-L${LIBIBERTYDIR} -liberty
+DPADD+=		${LIBIBERTYDIR}/libiberty.a
+
 # Yuck, we have to run configure to generate this one...
 CLEANFILES+=	config.h
 HOST_CFLAGS+= -I${.OBJDIR}



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 15:24:42 UTC 2017

Modified Files:
src/sys/arch/x86/pci: pciide_machdep.c
src/sys/arch/xen/conf: files.xen
Removed Files:
src/sys/arch/xen/xen: pci_intr_machdep.c pciide_machdep.c

Log Message:
Remove bitrotted xen specific versions of pci, pciide machdep related code.

Use the common x86/ code instead.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/pci/pciide_machdep.c
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.21 -r0 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.20 -r0 src/sys/arch/xen/xen/pciide_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/x86/pci/pciide_machdep.c
diff -u src/sys/arch/x86/pci/pciide_machdep.c:1.16 src/sys/arch/x86/pci/pciide_machdep.c:1.17
--- src/sys/arch/x86/pci/pciide_machdep.c:1.16	Sat Oct 15 16:46:14 2016
+++ src/sys/arch/x86/pci/pciide_machdep.c	Sat Nov  4 15:24:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pciide_machdep.c,v 1.16 2016/10/15 16:46:14 jdolecek Exp $	*/
+/*	$NetBSD: pciide_machdep.c,v 1.17 2017/11/04 15:24:42 cherry Exp $	*/
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciide_machdep.c,v 1.16 2016/10/15 16:46:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciide_machdep.c,v 1.17 2017/11/04 15:24:42 cherry Exp $");
 
 #include 
 #include 
@@ -61,6 +61,7 @@ __KERNEL_RCSID(0, "$NetBSD: pciide_machd
 #include 
 #endif
 
+#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
 void *
 pciide_machdep_compat_intr_establish(device_t dev,
 const struct pci_attach_args *pa, int chan, int (*func)(void *),
@@ -96,7 +97,9 @@ pciide_machdep_compat_intr_establish(dev
 	PCIIDE_CHANNEL_NAME(chan), irq);
 	return cookie;
 }
+#endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
 
+#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
 void
 pciide_machdep_compat_intr_disestablish(device_t dev, pci_chipset_tag_t pc,
 int chan, void *cookie)
@@ -104,3 +107,4 @@ pciide_machdep_compat_intr_disestablish(
 	isa_intr_disestablish(NULL, cookie);
 	return;
 }
+#endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH */

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.161 src/sys/arch/xen/conf/files.xen:1.162
--- src/sys/arch/xen/conf/files.xen:1.161	Sat Nov  4 14:56:48 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 15:24:42 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.161 2017/11/04 14:56:48 cherry Exp $
+#	$NetBSD: files.xen,v 1.162 2017/11/04 15:24:42 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -232,7 +232,7 @@ include	"dev/pckbport/files.pckbport"
 include "dev/i2o/files.i2o"
 include "dev/pci/files.pci"
 include "dev/pci/files.agp"
-file	arch/xen/xen/pciide_machdep.c	pciide_common
+file	arch/x86/pci/pciide_machdep.c	pciide_common
 
 device	pciback {unit = -1}
 attach	pciback at pci
@@ -382,7 +382,9 @@ defflag	opt_xen.h			DOM0OPS
 file	arch/xen/xen/privcmd.c		dom0ops
 file 	arch/xen/x86/xen_shm_machdep.c	dom0ops
 file	arch/x86/pci/pci_machdep.c	hypervisor & pci & dom0ops
-file	arch/xen/xen/pci_intr_machdep.c	hypervisor & pci
+file	arch/x86/pci/pci_intr_machdep.c	hypervisor & pci
+file	arch/x86/pci/pci_msi_machdep.c	hypervisor & pci
+file	arch/x86/pci/msipic.c		hypervisor & pci
 file	arch/x86/isa/isa_machdep.c	hypervisor & dom0ops
 file	arch/xen/xen/xenevt.c		xenevt & dom0ops
 file	arch/xen/xen/xennetback_xenbus.c xvif



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 14:56:48 UTC 2017

Modified Files:
src/sys/arch/x86/include: intr.h
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/x86/x86: intr.c ioapic.c
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: evtchn.h intr.h
src/sys/arch/xen/xen: pci_intr_machdep.c pciide_machdep.c
Removed Files:
src/sys/arch/xen/x86: intr.c

Log Message:
Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

   void *intr_establish_xname(...);
   void *intr_establish(...);
   void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

int event_set_handler(...);
int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/ioapic.c
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.33 -r0 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/xen/xen/pci_intr_machdep.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/xen/xen/pciide_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/x86/include/intr.h
diff -u src/sys/arch/x86/include/intr.h:1.51 src/sys/arch/x86/include/intr.h:1.52
--- src/sys/arch/x86/include/intr.h:1.51	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/x86/include/intr.h	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.51 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.52 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -117,6 +117,18 @@ struct intrsource {
  */
 
 struct intrhand {
+#if defined(XEN)
+	/*
+	 * Note: This is transitional and will go away.
+	 *
+	 * We ought to use a union here, but too much effort.
+	 * We use this field to tear down the cookie handed to us
+	 * via x86/intr.c:intr_disestablish();
+	 * Interestingly, the intr_establish_xname() function returns
+	 * a "void *" - so we abuse this for now.
+	 */
+	int	pic_type; /* Overloading wrt struct pintrhand */
+#endif
 	int	(*ih_fun)(void *);
 	void	*ih_arg;
 	int	ih_level;
@@ -124,10 +136,9 @@ struct intrhand {
 	void	*ih_realarg;
 	struct	intrhand *ih_next;
 	struct	intrhand **ih_prevp;
-#if !defined(XEN)
 	int	ih_pin;
 	int	ih_slot;
-#else
+#if defined(XEN)
 	struct	intrhand *ih_evt_next;
 #endif
 	struct cpu_info *ih_cpu;

Index: src/sys/arch/x86/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.36 src/sys/arch/x86/isa/isa_machdep.c:1.37
--- src/sys/arch/x86/isa/isa_machdep.c:1.36	Fri Jul 21 12:27:48 2017
+++ src/sys/arch/x86/isa/isa_machdep.c	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $");
 
 #include 
 #include 
@@ -245,7 +245,7 @@ isa_intr_establish_xname(isa_chipset_tag
 
 	mpih |= APIC_IRQ_LEGACY_IRQ(irq);
 
-	evtch = xen_intr_map((int *), type); /* XXX: legacy - xen just tosses irq back at us */
+	evtch = xen_pirq_alloc((intr_handle_t *), type); /* XXX: legacy - xen just tosses irq back at us */
 	if (evtch == -1)
 		return NULL;
 #if NIOAPIC > 0

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.105 src/sys/arch/x86/x86/intr.c:1.106
--- src/sys/arch/x86/x86/intr.c:1.105	Fri Oct 27 12:25:14 2017
+++ src/sys/arch/x86/x86/intr.c	Sat Nov  4 14:56:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $	*/
+/*	$NetBSD: intr.c,v 1.106 2017/11/04 14:56:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.106 

CVS commit: src/sys/arch/evbarm/rpi

2017-11-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov  4 14:47:06 UTC 2017

Modified Files:
src/sys/arch/evbarm/rpi: rpi_machdep.c

Log Message:
Firmware after May 8, 2017 places APs in WFE state at boot. Add a "sev"
after writing the start vector, otherwise secondary CPUs will not boot.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/evbarm/rpi/rpi_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/evbarm/rpi/rpi_machdep.c
diff -u src/sys/arch/evbarm/rpi/rpi_machdep.c:1.80 src/sys/arch/evbarm/rpi/rpi_machdep.c:1.81
--- src/sys/arch/evbarm/rpi/rpi_machdep.c:1.80	Wed Aug 16 20:54:19 2017
+++ src/sys/arch/evbarm/rpi/rpi_machdep.c	Sat Nov  4 14:47:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpi_machdep.c,v 1.80 2017/08/16 20:54:19 jmcneill Exp $	*/
+/*	$NetBSD: rpi_machdep.c,v 1.81 2017/11/04 14:47:06 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.80 2017/08/16 20:54:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.81 2017/11/04 14:47:06 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bcm283x.h"
@@ -660,6 +660,9 @@ rpi_bootstrap(void)
 		}
 	}
 
+	/* Wake up APs in case firmware has placed them in WFE state */
+	__asm __volatile("sev");
+
 	for (int loop = 0; loop < 16; loop++) {
 		if (arm_cpu_hatched == __BITS(arm_cpu_max - 1, 1))
 			break;



CVS commit: src/external/bsd/nvi/dist/common

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  4 14:20:13 UTC 2017

Modified Files:
src/external/bsd/nvi/dist/common: recover.c

Log Message:
Don't use popenve() for portability; forking an extra shell here is not an
issue.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/bsd/nvi/dist/common/recover.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/nvi/dist/common/recover.c
diff -u src/external/bsd/nvi/dist/common/recover.c:1.8 src/external/bsd/nvi/dist/common/recover.c:1.9
--- src/external/bsd/nvi/dist/common/recover.c:1.8	Sat Nov  4 02:15:56 2017
+++ src/external/bsd/nvi/dist/common/recover.c	Sat Nov  4 10:20:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: recover.c,v 1.8 2017/11/04 06:15:56 christos Exp $ */
+/*	$NetBSD: recover.c,v 1.9 2017/11/04 14:20:12 christos Exp $ */
 /*-
  * Copyright (c) 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: recover.c,v 10.31 2001/11/01 15:24:44 skimo Exp  (Berkeley) Date: 2001/11/01 15:24:44 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: recover.c,v 1.8 2017/11/04 06:15:56 christos Exp $");
+__RCSID("$NetBSD: recover.c,v 1.9 2017/11/04 14:20:12 christos Exp $");
 #endif
 
 #include 
@@ -871,8 +871,6 @@ rcv_mktemp(SCR *sp, char *path, const ch
 	return (fd);
 }
 
-extern char **environ;
-
 /*
  * rcv_email --
  *	Send email.
@@ -883,7 +881,6 @@ rcv_email(SCR *sp, const char *fname)
 	struct stat sb;
 	char buf[BUFSIZ];
 	FILE *fin, *fout;
-	const char *argv[4];
 	size_t l;
 
 	if (_PATH_SENDMAIL[0] != '/' || stat(_PATH_SENDMAIL, ) == -1) {
@@ -910,12 +907,7 @@ rcv_email(SCR *sp, const char *fname)
 		return;
 	}
 
-	argv[0] = _PATH_SENDMAIL;
-	argv[1] = "-t";
-	argv[2] = fname;
-	argv[3] = NULL;
-
-	fout = popenve(_PATH_SENDMAIL, __UNCONST(argv), environ, "w");
+	fout = popen(_PATH_SENDMAIL " -t", "w");
 	if (fout == NULL) {
 		msgq_str(sp, M_SYSERR,
 		_PATH_SENDMAIL, "326|cannot execute sendmail: %s");



CVS commit: src/sys/arch/x86/x86

2017-11-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov  4 12:53:00 UTC 2017

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
Fix stack overflow, found when testing a new feature.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/x86/x86/lapic.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/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.62 src/sys/arch/x86/x86/lapic.c:1.63
--- src/sys/arch/x86/x86/lapic.c:1.62	Tue Aug 15 09:08:39 2017
+++ src/sys/arch/x86/x86/lapic.c	Sat Nov  4 12:53:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: lapic.c,v 1.62 2017/08/15 09:08:39 maxv Exp $	*/
+/*	$NetBSD: lapic.c,v 1.63 2017/11/04 12:53:00 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.62 2017/08/15 09:08:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.63 2017/11/04 12:53:00 maxv Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -250,7 +250,7 @@ lapic_is_x2apic(void)
 static void
 lapic_setup_bsp(paddr_t lapic_base)
 {
-	u_int regs[4];
+	u_int regs[6];
 	const char *reason = NULL;
 	const char *hw_vendor;
 	bool bios_x2apic;



CVS commit: src/sys

2017-11-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Nov  4 12:14:41 UTC 2017

Modified Files:
src/sys/kern: subr_kobj.c
src/sys/sys: kobj.h

Log Message:
Make kobj_sym_lookup's result type an Elf_Addr.
Fixes the arm builds.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/kern/subr_kobj.c
cvs rdiff -u -r1.17 -r1.18 src/sys/sys/kobj.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/subr_kobj.c
diff -u src/sys/kern/subr_kobj.c:1.63 src/sys/kern/subr_kobj.c:1.64
--- src/sys/kern/subr_kobj.c:1.63	Fri Nov  3 09:59:07 2017
+++ src/sys/kern/subr_kobj.c	Sat Nov  4 12:14:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_kobj.c,v 1.63 2017/11/03 09:59:07 maxv Exp $	*/
+/*	$NetBSD: subr_kobj.c,v 1.64 2017/11/04 12:14:41 martin Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.63 2017/11/03 09:59:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.64 2017/11/04 12:14:41 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -874,7 +874,7 @@ kobj_jettison(kobj_t ko)
  *	is known (ie during relocation).
  */
 int
-kobj_sym_lookup(kobj_t ko, uintptr_t symidx, uintptr_t *val)
+kobj_sym_lookup(kobj_t ko, uintptr_t symidx, Elf_Addr *val)
 {
 	const Elf_Sym *sym;
 	const char *symbol;

Index: src/sys/sys/kobj.h
diff -u src/sys/sys/kobj.h:1.17 src/sys/sys/kobj.h:1.18
--- src/sys/sys/kobj.h:1.17	Fri Nov  3 09:59:07 2017
+++ src/sys/sys/kobj.h	Sat Nov  4 12:14:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kobj.h,v 1.17 2017/11/03 09:59:07 maxv Exp $	*/
+/*	$NetBSD: kobj.h,v 1.18 2017/11/04 12:14:41 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@ int		kobj_stat(kobj_t, vaddr_t *, size_t
 int		kobj_find_section(kobj_t, const char *, void **, size_t *);
 
 /* MI-MD interface. */
-int		kobj_sym_lookup(kobj_t, uintptr_t, uintptr_t *);
+int		kobj_sym_lookup(kobj_t, uintptr_t, Elf_Addr *);
 int		kobj_reloc(kobj_t, uintptr_t, const void *, bool, bool);
 int		kobj_machdep(kobj_t, void *, size_t, bool);
 



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 10:26:14 UTC 2017

Modified Files:
src/sys/arch/x86/include: pic.h
src/sys/arch/xen/xen: evtchn.c

Log Message:
Add a PIC_XEN abstraction to evtchn.c

This allows us to get XEN interrupt code closer to unification to x86/intr.c


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/include/pic.h
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/xen/xen/evtchn.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/x86/include/pic.h
diff -u src/sys/arch/x86/include/pic.h:1.8 src/sys/arch/x86/include/pic.h:1.9
--- src/sys/arch/x86/include/pic.h:1.8	Mon Apr 27 07:03:58 2015
+++ src/sys/arch/x86/include/pic.h	Sat Nov  4 10:26:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.h,v 1.8 2015/04/27 07:03:58 knakahara Exp $	*/
+/*	$NetBSD: pic.h,v 1.9 2017/11/04 10:26:14 cherry Exp $	*/
 
 #ifndef _X86_PIC_H
 #define _X86_PIC_H
@@ -34,8 +34,10 @@ struct pic {
 #define PIC_MSI		3
 #define PIC_MSIX	4
 #define PIC_SOFT	5
+#define PIC_XEN		6
 
 extern struct pic i8259_pic;
 extern struct pic local_pic;
 extern struct pic softintr_pic;
+extern struct pic xen_pic;
 #endif

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.73 src/sys/arch/xen/xen/evtchn.c:1.74
--- src/sys/arch/xen/xen/evtchn.c:1.73	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/xen/xen/evtchn.c	Sat Nov  4 10:26:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.73 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.74 2017/11/04 10:26:14 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.73 2017/07/16 14:02:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.74 2017/11/04 10:26:14 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -115,6 +115,81 @@ physdev_op_t physdev_op_notify = {
 };
 #endif
 
+static void xen_evtchn_mask(struct pic *, int);
+static void xen_evtchn_unmask(struct pic *, int);
+static void xen_evtchn_addroute(struct pic *, struct cpu_info *, int, int, int);
+static void xen_evtchn_delroute(struct pic *, struct cpu_info *, int, int, int);
+static bool xen_evtchn_trymask(struct pic *, int);
+
+
+struct pic xen_pic = {
+	.pic_name = "xenev0",
+	.pic_type = PIC_XEN,
+	.pic_vecbase = 0,
+	.pic_apicid = 0,
+	.pic_lock = __SIMPLELOCK_UNLOCKED,
+	.pic_hwmask = xen_evtchn_mask,
+	.pic_hwunmask = xen_evtchn_unmask,
+	.pic_addroute = xen_evtchn_addroute,
+	.pic_delroute = xen_evtchn_delroute,
+	.pic_trymask = xen_evtchn_trymask,
+	.pic_level_stubs = xenev_stubs,
+	.pic_edge_stubs = xenev_stubs,
+};
+	
+/*
+ * We try to stick to the traditional x86 PIC semantics wrt Xen
+ * events.
+ *
+ * PIC pins exist in a global namespace which may be hierarchical, and
+ * are mapped to a cpu bus concept called 'IRQ' numbers, which are
+ * also global, but linear. Thus a PIC, pin tuple will always map to
+ * an IRQ number. These tuples can alias to the same IRQ number, thus
+ * causing IRQ "sharing". IRQ numbers can be bound to specific CPUs,
+ * and to specific callback vector indices on the CPU called idt_vec,
+ * which are aliases to handlers meant to run on destination
+ * CPUs. This binding can also happen at interrupt time and resolved
+ * 'round-robin' between all CPUs, depending on the lapic setup. In
+ * this case, all CPUs need to have identical idt_vec->handler
+ * mappings.
+ *
+ * The job of pic_addroute() is to setup the 'wiring' between the
+ * source pin, and the destination CPU handler, ideally on a specific
+ * CPU in MP systems (or 'round-robin').
+ *
+ * On Xen, a global namespace of 'events' exist, which are initially
+ * bound to nothing. This is similar to the relationship between
+ * realworld realworld IRQ numbers wrt PIC pins, since before routing,
+ * IRQ numbers by themselves have no causal connection setup with the
+ * real world. (Except for the hardwired cases on the PC Architecture,
+ * which we ignore for the purpose of this description). However the
+ * really important routing is from pin to idt_vec. On PIC_XEN, all
+ * three (pic, irq, idt_vec) belong to the same namespace and are
+ * identical. Further, the mapping between idt_vec and the actual
+ * callback handler is setup via calls to the evtchn.h api - this
+ * last bit is analogous to x86/idt.c:idt_vec_set() on real h/w
+ *
+ * For now we handle two cases:
+ * - IPC style events - eg: timer, PV devices, etc.
+ * - dom0 physical irq bound events.
+ *
+ * In the case of IPC style events, we currently externalise the
+ * event binding by using evtchn.h functions. From the POV of
+ * PIC_XEN ,  'pin' , 'irq' and 'idt_vec' are all identical to the
+ * port number of the event.
+ *
+ * In the case of dom0 physical irq bound events, we currently
+ * event binding by exporting evtchn.h functions. From the POV of
+ * PIC_LAPIC/PIC_IOAPIC, the 'pin' is the hardware 

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

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 09:31:08 UTC 2017

Modified Files:
src/sys/arch/xen/include: i82093var.h

Log Message:
protect header against recursive include


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/xen/include/i82093var.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/xen/include/i82093var.h
diff -u src/sys/arch/xen/include/i82093var.h:1.4 src/sys/arch/xen/include/i82093var.h:1.5
--- src/sys/arch/xen/include/i82093var.h:1.4	Mon Mar 22 16:43:08 2010
+++ src/sys/arch/xen/include/i82093var.h	Sat Nov  4 09:31:08 2017
@@ -1,4 +1,7 @@
-/*	 $NetBSD: i82093var.h,v 1.4 2010/03/22 16:43:08 cegger Exp $ */
+/*	 $NetBSD: i82093var.h,v 1.5 2017/11/04 09:31:08 cherry Exp $ */
+
+#ifndef _XEN_I82093VAR_H_
+#define _XEN_I82093VAR_H_
 
 #include "opt_xen.h"
 #define _IOAPIC_CUSTOM_RW
@@ -36,3 +39,5 @@ ioapic_write_ul(struct ioapic_softc *sc,
 	if (ret)
 		printf("PHYSDEVOP_APIC_WRITE ret %d\n", ret);
 }
+
+#endif /* !_XEN_I82093VAR_H_ */



CVS commit: src/sys/arch/xen

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 09:22:16 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: intr.c
Added Files:
src/sys/arch/xen/x86: pintr.c

Log Message:
On XEN dom0, the function xen/x86/intr.c:xen_intr_map() is used to map
hardware interrupts to XEN callbacks called 'events'. This function
combines both the allocation and the binding.

This change is the first part of breaking up that combination into
xen_pirq_alloc() and the binding will happen as part of the
pic_addroute() callback of a new pseudo PIC_XEN

This code will be added later on.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/x86/pintr.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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.159 src/sys/arch/xen/conf/files.xen:1.160
--- src/sys/arch/xen/conf/files.xen:1.159	Sat Nov  4 08:55:50 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 09:22:16 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.159 2017/11/04 08:55:50 cherry Exp $
+#	$NetBSD: files.xen,v 1.160 2017/11/04 09:22:16 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -138,6 +138,7 @@ file	arch/xen/x86/xen_bus_dma.c	machdep
 file	arch/x86/x86/bus_space.c	machdep
 file	arch/xen/x86/consinit.c		machdep
 file	arch/x86/x86/identcpu.c		machdep
+file	arch/xen/x86/pintr.c		machdep & dom0ops
 file	arch/xen/x86/intr.c		machdep
 file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/idt.c		machdep

Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.42 src/sys/arch/xen/include/intr.h:1.43
--- src/sys/arch/xen/include/intr.h:1.42	Sun Jul 16 14:02:48 2017
+++ src/sys/arch/xen/include/intr.h	Sat Nov  4 09:22:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.42 2017/07/16 14:02:48 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.43 2017/11/04 09:22:16 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -61,7 +61,9 @@ struct evtsource {
 };
 
 extern struct intrstub xenev_stubs[];
-
+extern int irq2vect[256];
+extern int vect2irq[256];
+extern int irq2port[NR_EVENT_CHANNELS];
 
 #ifdef MULTIPROCESSOR
 int xen_intr_biglock_wrapper(void *);
@@ -70,6 +72,9 @@ int xen_intr_biglock_wrapper(void *);
 int xen_intr_map(int *, int);
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
+#if defined(DOM0OPS) || NPCI > 0
+int xen_pirq_alloc(intr_handle_t *, int);
+#endif /* defined(DOM0OPS) || NPCI > 0 */
 
 #ifdef MULTIPROCESSOR
 void xen_ipi_init(void);

Index: src/sys/arch/xen/x86/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.32 src/sys/arch/xen/x86/intr.c:1.33
--- src/sys/arch/xen/x86/intr.c:1.32	Sun Jul 16 06:14:24 2017
+++ src/sys/arch/xen/x86/intr.c	Sat Nov  4 09:22:16 2017
@@ -103,7 +103,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.32 2017/07/16 06:14:24 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.33 2017/11/04 09:22:16 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -130,18 +130,9 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.3
 #include "acpica.h"
 #include "ioapic.h"
 #include "opt_mpbios.h"
-/* for x86/i8259.c */
-struct intrstub i8259_stubs[NUM_LEGACY_IRQS] = {{0,0}};
-#if NIOAPIC > 0
-/* for x86/ioapic.c */
-struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
-struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
 
+#if NIOAPIC > 0
 #include 
-int irq2vect[256] = {0};
-int vect2irq[256] = {0};
 #endif /* NIOAPIC */
 #if NACPICA > 0
 #include 

Added files:

Index: src/sys/arch/xen/x86/pintr.c
diff -u /dev/null src/sys/arch/xen/x86/pintr.c:1.1
--- /dev/null	Sat Nov  4 09:22:17 2017
+++ src/sys/arch/xen/x86/pintr.c	Sat Nov  4 09:22:16 2017
@@ -0,0 +1,213 @@
+/*	NetBSD: intr.c,v 1.15 2004/04/10 14:49:55 kochi Exp 	*/
+
+/*
+ * Copyright 2002 (c) Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * 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 

CVS commit: src/sys/arch/x86/x86

2017-11-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov  4 08:58:30 UTC 2017

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Add support for xsaveopt. It is basically an instruction that optimizes
context switch performance by not saving to memory FPU registers that are
known to be in their initial state or known not to have changed since the
last time they were saved to memory.

Our code is now compatible with the internal state tracking engine:
 - We don't modify the in-memory FPU state after doing an XSAVE/XSAVEOPT.
   That is to say, we always call XRSTOR first.
 - During a fork, the whole in-memory FPU state area is memcopied in the
   new PCB, and CR0_TS is set. Next time the forked thread uses the FPU it
   will fault, we migrate the area, call XRSTOR and clear CR0_TS. During
   this XRSTOR XSTATE_BV still contains the initial values, and it forces
   a reload of XINUSE.
 - Whenever software wants to change the in-memory FPU state, it manually
   sets XSTATE_BV[i]=1, which forces XINUSE[i]=1.
 - The address of the state passed to xrstor is always the same for a
   given LWP.

fpu_save_area_clear is changed not to force a reload of CW if fx_cw is
the standard FPU value. This way we have XINUSE[i]=0 for x87, and xsaveopt
will optimize this state.

Small benchmark:
switch lwp to cpu2
do float operation
switch lwp to cpu3
do float operation
Doing this 10^6 times in a loop, my cpu goes on average from 28,2 seconds
to 20,8 seconds.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/x86/x86/fpu.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/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.23 src/sys/arch/x86/x86/fpu.c:1.24
--- src/sys/arch/x86/x86/fpu.c:1.23	Sat Nov  4 07:38:42 2017
+++ src/sys/arch/x86/x86/fpu.c	Sat Nov  4 08:58:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.23 2017/11/04 07:38:42 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.24 2017/11/04 08:58:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.23 2017/11/04 07:38:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.24 2017/11/04 08:58:30 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -471,9 +471,12 @@ fpusave_cpu(bool save)
 break;
 
 			case FPU_SAVE_XSAVE:
-			case FPU_SAVE_XSAVEOPT:
 xsave(>pcb_savefpu, x86_xsave_features);
 break;
+
+			case FPU_SAVE_XSAVEOPT:
+xsaveopt(>pcb_savefpu, x86_xsave_features);
+break;
 		}
 	}
 
@@ -559,8 +562,9 @@ fpu_save_area_clear(struct lwp *l, unsig
 		fpu_save->sv_xmm.fx_cw = x87_cw;
 
 		/* Force a reload of CW */
-		if (x86_fpu_save == FPU_SAVE_XSAVE ||
-		x86_fpu_save == FPU_SAVE_XSAVEOPT) {
+		if ((x87_cw != __INITIAL_NPXCW__) &&
+		(x86_fpu_save == FPU_SAVE_XSAVE ||
+		x86_fpu_save == FPU_SAVE_XSAVEOPT)) {
 			fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
 			XCR0_X87;
 		}



CVS commit: src/sys/arch/xen/conf

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 08:55:50 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
On XEN PV, the ISA 8259A PIC is only used on dom0


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.158 src/sys/arch/xen/conf/files.xen:1.159
--- src/sys/arch/xen/conf/files.xen:1.158	Sat Nov  4 08:50:47 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 08:55:50 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.158 2017/11/04 08:50:47 cherry Exp $
+#	$NetBSD: files.xen,v 1.159 2017/11/04 08:55:50 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -256,7 +256,7 @@ include "dev/apm/files.apm"
 include "dev/acpi/files.acpi"
 file	arch/xen/xen/xen_acpi_machdep.c	acpi
 file	arch/x86/x86/mpacpi.c		acpi
-file	arch/x86/x86/i8259.c
+file	arch/x86/x86/i8259.c		dom0ops
 
 # Stubs for x86 routines not included in the system
 file	arch/x86/x86/x86_stub.c



CVS commit: src/lib/libc/stdio

2017-11-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Nov  4 08:53:24 UTC 2017

Modified Files:
src/lib/libc/stdio: fopen.3

Log Message:
Be more consistent with how we refer to fopen() - pointed out by wiz@


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdio/fopen.3

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/stdio/fopen.3
diff -u src/lib/libc/stdio/fopen.3:1.34 src/lib/libc/stdio/fopen.3:1.35
--- src/lib/libc/stdio/fopen.3:1.34	Sat Nov  4 08:04:40 2017
+++ src/lib/libc/stdio/fopen.3	Sat Nov  4 08:53:23 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fopen.3,v 1.34 2017/11/04 08:04:40 kre Exp $
+.\"	$NetBSD: fopen.3,v 1.35 2017/11/04 08:53:23 kre Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -139,7 +139,7 @@ The letter
 in the mode turns on exclusive open mode to the file
 .Pq Dv O_EXCL
 which means that the file will not be created if it already exists.
-In that case, the
+In that case
 .Fn fopen
 will fail.
 .El



CVS commit: src/sys/arch

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 08:50:48 UTC 2017

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/amd64/include: segments.h
src/sys/arch/i386/i386: machdep.c
src/sys/arch/i386/include: segments.h
src/sys/arch/x86/x86: idt.c
src/sys/arch/xen/conf: files.xen

Log Message:
In XEN PV, the idt vector table is not required to be altered at
runtime, since only entries for exceptions/traps are registered with
the hypervisor and interrupts are managed via a completely different
mechanism.

This change uses the idt_vec_reserve() mechanism nevertheless,
modifying it slightly to only do namespace management in XEN, while on
native it will continue to do idt entry init as before.

Rationale: Consistent API usage and potential future merging of
XEN/non-XEN code.

There are no functional changes in this commit.


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/include/segments.h
cvs rdiff -u -r1.797 -r1.798 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/i386/include/segments.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/idt.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/xen/conf/files.xen

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/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.274 src/sys/arch/amd64/amd64/machdep.c:1.275
--- src/sys/arch/amd64/amd64/machdep.c:1.274	Sun Oct 29 10:25:28 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.274 2017/10/29 10:25:28 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1747,6 +1747,7 @@ init_x86_64(paddr_t first_avail)
 		GSEL(GCODE_SEL, SEL_KPL));
 #else /* XEN */
 		pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1776,6 +1777,7 @@ init_x86_64(paddr_t first_avail)
 	setgate([128], (osyscall), 0, SDT_SYS386IGT, SEL_UPL,
 	GSEL(GCODE_SEL, SEL_KPL));
 #else
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_KPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/amd64/include/segments.h
diff -u src/sys/arch/amd64/include/segments.h:1.32 src/sys/arch/amd64/include/segments.h:1.33
--- src/sys/arch/amd64/include/segments.h:1.32	Wed Nov  1 07:14:29 2017
+++ src/sys/arch/amd64/include/segments.h	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.32 2017/11/01 07:14:29 maxv Exp $	*/
+/*	$NetBSD: segments.h,v 1.33 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -245,12 +245,12 @@ void set_mem_segment(struct mem_segment_
 void cpu_init_idt(void);
 void update_descriptor(void *, void *);
 
-#if !defined(XEN)
+
 void idt_vec_reserve(int);
 int idt_vec_alloc(int, int);
 void idt_vec_set(int, void (*)(void));
 void idt_vec_free(int);
-#endif
+
 
 struct lwp;
 void cpu_segregs64_zero(struct lwp *);

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.797 src/sys/arch/i386/i386/machdep.c:1.798
--- src/sys/arch/i386/i386/machdep.c:1.797	Sun Oct 29 10:01:21 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Nov  4 08:50:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.797 2017/10/29 10:01:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -1355,6 +1355,7 @@ init386(paddr_t first_avail)
 	xen_idt_idx = 0;
 	for (x = 0; x < 32; x++) {
 		KASSERT(xen_idt_idx < MAX_XEN_IDT);
+		idt_vec_reserve(x);
 		xen_idt[xen_idt_idx].vector = x;
 
 		switch (x) {
@@ -1377,6 +1378,7 @@ init386(paddr_t first_avail)
 		xen_idt_idx++;
 	}
 	KASSERT(xen_idt_idx < MAX_XEN_IDT);
+	idt_vec_reserve(128);
 	xen_idt[xen_idt_idx].vector = 128;
 	xen_idt[xen_idt_idx].flags = SEL_UPL;
 	xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);

Index: src/sys/arch/i386/include/segments.h
diff -u src/sys/arch/i386/include/segments.h:1.62 src/sys/arch/i386/include/segments.h:1.63
--- src/sys/arch/i386/include/segments.h:1.62	Sun Sep 17 09:41:35 2017
+++ 

CVS commit: src/sys/dev/wsfont

2017-11-04 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Nov  4 08:33:28 UTC 2017

Modified Files:
src/sys/dev/wsfont: wsfont.c

Log Message:
Don't test for failure of malloc(...,M_WAITOK), it cannot fail


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/wsfont/wsfont.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/wsfont/wsfont.c
diff -u src/sys/dev/wsfont/wsfont.c:1.61 src/sys/dev/wsfont/wsfont.c:1.62
--- src/sys/dev/wsfont/wsfont.c:1.61	Sun Nov 20 15:55:31 2016
+++ src/sys/dev/wsfont/wsfont.c	Sat Nov  4 08:33:28 2017
@@ -1,4 +1,4 @@
-/* 	$NetBSD: wsfont.c,v 1.61 2016/11/20 15:55:31 macallan Exp $	*/
+/* 	$NetBSD: wsfont.c,v 1.62 2017/11/04 08:33:28 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1.61 2016/11/20 15:55:31 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1.62 2017/11/04 08:33:28 maya Exp $");
 
 #include "opt_wsfont.h"
 
@@ -367,8 +367,6 @@ wsfont_rotate_cw_internal(struct wsdispl
 
 	/* Duplicate the existing font... */
 	newfont = malloc(sizeof(*font), M_DEVBUF, M_WAITOK);
-	if (newfont == NULL)
-		return (NULL);
 
 	*newfont = *font;
 
@@ -382,10 +380,6 @@ wsfont_rotate_cw_internal(struct wsdispl
 	newstride = (font->fontheight + 7) / 8;
 	newbits = malloc(newstride * font->fontwidth * font->numchars,
 	M_DEVBUF, M_WAITOK|M_ZERO);
-	if (newbits == NULL) {
-		free(newfont, M_DEVBUF);
-		return (NULL);
-	}
 
 	/* Rotate the font a bit at a time. */
 	for (n = 0; n < font->numchars; n++) {
@@ -438,8 +432,6 @@ wsfont_rotate_ccw_internal(struct wsdisp
 
 	/* Duplicate the existing font... */
 	newfont = malloc(sizeof(*font), M_DEVBUF, M_WAITOK);
-	if (newfont == NULL)
-		return (NULL);
 
 	*newfont = *font;
 
@@ -453,10 +445,6 @@ wsfont_rotate_ccw_internal(struct wsdisp
 	newstride = (font->fontheight + 7) / 8;
 	newbits = malloc(newstride * font->fontwidth * font->numchars,
 	M_DEVBUF, M_WAITOK|M_ZERO);
-	if (newbits == NULL) {
-		free(newfont, M_DEVBUF);
-		return (NULL);
-	}
 
 	/* Rotate the font a bit at a time. */
 	for (n = 0; n < font->numchars; n++) {



CVS commit: src/lib/libc/stdio

2017-11-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Nov  4 08:04:40 UTC 2017

Modified Files:
src/lib/libc/stdio: fopen.3

Log Message:
Some (mostly minor) wording improvements (IMO)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdio/fopen.3

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/stdio/fopen.3
diff -u src/lib/libc/stdio/fopen.3:1.33 src/lib/libc/stdio/fopen.3:1.34
--- src/lib/libc/stdio/fopen.3:1.33	Sat Nov  4 07:59:17 2017
+++ src/lib/libc/stdio/fopen.3	Sat Nov  4 08:04:40 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fopen.3,v 1.33 2017/11/04 07:59:17 wiz Exp $
+.\"	$NetBSD: fopen.3,v 1.34 2017/11/04 08:04:40 kre Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -62,29 +62,30 @@ and associates a stream with it.
 The argument
 .Fa mode
 points to a string beginning with one of the following
-sequences (Additional characters may follow these sequences.):
+sequences, which may be followed by additional modifiers
+as indicated below:
 .Bl -tag -width 4n
 .It Dq Li a
-Append; open for writing.
+Append; open an existing or new file for writing in append mode.
 The file is created if it does not exist.
 .It Dq Li a+
-Append; open for reading and writing.
+Open for reading and writing in append mode.
 The file is created if it does not exist.
 .It Dq Li r
-Open for reading.
+Read; open an existing file for reading.
 .It Dq Li r+
-Open for reading and writing.
+Open an existing file for reading and writing.
 .It Dq Li w
-Open for writing.
-Truncate file to zero length or create file.
+Write; open an empty file for writing.
+Truncate an existing file to zero length or create a new file.
 .It Dq Li w+
-Open for reading and writing.
+Open an empty file for reading and writing.
 Truncate file to zero length or create file.
 .El
 .Pp
-Additionally, the
+After one of those, the
 .Fa mode
-string can also include one of the following letters:
+string can also include one or more of the following modifier letters:
 .Bl -tag -width 4n
 .It Sq b
 The letter
@@ -92,8 +93,11 @@ The letter
 may appear either as a last character or as a character between the
 characters in any of the two-character strings described above.
 This is strictly for compatibility with
-.St -ansiC
-and has no effect; the
+.St -ansiC ,
+where it means open in
+.Dq binary
+mode which is identical to text mode here,
+so has no effect; the
 .Sq b
 is ignored.
 .It Sq e
@@ -115,7 +119,7 @@ in the mode string restricts
 .Fn fopen
 to regular files; if the file opened is not a regular file,
 .Fn fopen
-will fail.
+will close it, and fail.
 This is a non
 .St -ansiC
 extension.
@@ -135,6 +139,9 @@ The letter
 in the mode turns on exclusive open mode to the file
 .Pq Dv O_EXCL
 which means that the file will not be created if it already exists.
+In that case, the
+.Fn fopen
+will fail.
 .El
 .Pp
 Any created files will have mode



CVS commit: src/lib/libc/stdio

2017-11-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Nov  4 07:59:17 UTC 2017

Modified Files:
src/lib/libc/stdio: fopen.3

Log Message:
Fix xref. Remove Tn.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/fopen.3

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/stdio/fopen.3
diff -u src/lib/libc/stdio/fopen.3:1.32 src/lib/libc/stdio/fopen.3:1.33
--- src/lib/libc/stdio/fopen.3:1.32	Sat Nov  4 02:49:55 2017
+++ src/lib/libc/stdio/fopen.3	Sat Nov  4 07:59:17 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fopen.3,v 1.32 2017/11/04 02:49:55 christos Exp $
+.\"	$NetBSD: fopen.3,v 1.33 2017/11/04 07:59:17 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -99,11 +99,11 @@ is ignored.
 .It Sq e
 The letter
 .Sq e
-in the mode string sets the close-on-exec 
+in the mode string sets the close-on-exec
 .Pq Dv O_CLOEXEC
 flag of the file descriptor, which means that it will not be available
 after an
-.Xr exec 2
+.Xr exec 3
 system call.
 This is a non
 .St -ansiC
@@ -221,9 +221,7 @@ Upon successful completion
 .Fn fdopen
 and
 .Fn freopen
-return a
-.Tn FILE
-pointer.
+return a FILE pointer.
 Otherwise,
 .Dv NULL
 is returned and the global variable



CVS commit: src/sys/arch/x86/x86

2017-11-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov  4 07:38:42 UTC 2017

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Always set XCR0_X87, to force a reload of CW. That's needed for compat
options where fx_cw is not the standard fpu value.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/x86/x86/fpu.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/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.22 src/sys/arch/x86/x86/fpu.c:1.23
--- src/sys/arch/x86/x86/fpu.c:1.22	Sat Nov  4 07:35:00 2017
+++ src/sys/arch/x86/x86/fpu.c	Sat Nov  4 07:38:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.22 2017/11/04 07:35:00 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.23 2017/11/04 07:38:42 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.22 2017/11/04 07:35:00 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.23 2017/11/04 07:38:42 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -557,6 +557,13 @@ fpu_save_area_clear(struct lwp *l, unsig
 		fpu_save->sv_xmm.fx_mxcsr = __INITIAL_MXCSR__;
 		fpu_save->sv_xmm.fx_mxcsr_mask = x86_fpu_mxcsr_mask;
 		fpu_save->sv_xmm.fx_cw = x87_cw;
+
+		/* Force a reload of CW */
+		if (x86_fpu_save == FPU_SAVE_XSAVE ||
+		x86_fpu_save == FPU_SAVE_XSAVEOPT) {
+			fpu_save->sv_xsave_hdr.xsh_xstate_bv |=
+			XCR0_X87;
+		}
 	} else {
 		memset(_save->sv_87, 0, x86_fpu_save_size);
 		fpu_save->sv_87.s87_tw = 0x;



CVS commit: src/sys/arch/x86/x86

2017-11-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov  4 07:35:00 UTC 2017

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Fix xen. Not tested, but seems fine enough.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/fpu.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/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.21 src/sys/arch/x86/x86/fpu.c:1.22
--- src/sys/arch/x86/x86/fpu.c:1.21	Fri Nov  3 07:14:24 2017
+++ src/sys/arch/x86/x86/fpu.c	Sat Nov  4 07:35:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.21 2017/11/03 07:14:24 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.22 2017/11/04 07:35:00 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.21 2017/11/03 07:14:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.22 2017/11/04 07:35:00 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -233,6 +233,7 @@ fpuinit(struct cpu_info *ci)
 void
 fpuinit_mxcsr_mask(void)
 {
+#ifndef XEN
 	union savefpu fpusave __aligned(16);
 	u_long cr0, psl;
 
@@ -256,6 +257,12 @@ fpuinit_mxcsr_mask(void)
 	} else {
 		x86_fpu_mxcsr_mask = fpusave.sv_xmm.fx_mxcsr_mask;
 	}
+#else
+	/*
+	 * XXX: Does the detection above work on Xen?
+	 */
+	x86_fpu_mxcsr_mask = __INITIAL_MXCSR_MASK__;
+#endif
 }
 
 /*



CVS commit: src/lib/libc/stdio

2017-11-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Nov  4 07:26:35 UTC 2017

Modified Files:
src/lib/libc/stdio: fopen.c

Log Message:
Avoid losing a fd (ie: close it) in the (ever so likely) case that the
fd exceeds the limits of what can be stored in a FILE (65535).


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fopen.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/libc/stdio/fopen.c
diff -u src/lib/libc/stdio/fopen.c:1.15 src/lib/libc/stdio/fopen.c:1.16
--- src/lib/libc/stdio/fopen.c:1.15	Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/fopen.c	Sat Nov  4 07:26:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $	*/
+/*	$NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)fopen.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -88,6 +88,7 @@ fopen(const char *file, const char *mode
 	 * open. (We treat the short as unsigned, and special-case -1).
 	 */
 	if (f >= USHRT_MAX) {
+		(void)close(f);
 		errno = EMFILE;
 		goto release;
 	}



CVS commit: src/external/bsd/nvi/usr.bin/recover

2017-11-04 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Nov  4 07:04:01 UTC 2017

Modified Files:
src/external/bsd/nvi/usr.bin/recover: virecover

Log Message:
Put back the tests for "no files matched" (in a different way than they
were written previously - but that's just style.)   This is not csh...

Use the correct test operator to test for an empty file (rather than
testing for an empty file name...)

Write test ('[') commands in a way that is defined to work, rather than
just happens to - we can afford the (negligible) performance hit here.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/nvi/usr.bin/recover/virecover

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/nvi/usr.bin/recover/virecover
diff -u src/external/bsd/nvi/usr.bin/recover/virecover:1.2 src/external/bsd/nvi/usr.bin/recover/virecover:1.3
--- src/external/bsd/nvi/usr.bin/recover/virecover:1.2	Sat Nov  4 05:43:18 2017
+++ src/external/bsd/nvi/usr.bin/recover/virecover	Sat Nov  4 07:04:01 2017
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#	$NetBSD: virecover,v 1.2 2017/11/04 05:43:18 christos Exp $
+#	$NetBSD: virecover,v 1.3 2017/11/04 07:04:01 kre Exp $
 #
 #	@(#)recover.in	8.8 (Berkeley) 10/10/96
 #
@@ -11,14 +11,19 @@ SENDMAIL="/usr/sbin/sendmail"
 
 # Check editor backup files.
 for i in $RECDIR/vi.*; do
+
+	case "$i" in
+	$RECDIR/vi.\*) continue;;
+	esac
+
 	# Only test files that are readable.
-	if [ \( ! -f "$i" \) -o \( ! -r "$i" \) ]; then
+	if ! [ -f "$i" ] || ! [ -r "$i" ]; then
 		continue
 	fi
 
 	# Unmodified nvi editor backup files either have the
 	# execute bit set or are zero length.  Delete them.
-	if [ \( -x "$i" \) -o \( -z "$i" \) ]; then
+	if [ -x "$i" ] || ! [ -s "$i" ]; then
 		rm -f "$i"
 	fi
 done
@@ -26,8 +31,13 @@ done
 # It is possible to get incomplete recovery files, if the editor crashes
 # at the right time.
 for i in $RECDIR/recover.*; do
+
+	case "$i" in
+	$RECDIR/recover.\*) continue;;
+	esac
+
 	# Only test files that are readable.
-	if [ ! -r "$i" ]; then
+	if ! [ -r "$i" ]; then
 		continue
 	fi
 
@@ -35,7 +45,7 @@ for i in $RECDIR/recover.*; do
 	# or that have no corresponding backup file.  Else send mail
 	# to the user.
 	recfile=$(awk '/^X-vi-recover-path:/{print $2}' < "$i")
-	if [ \( -n "$recfile" \) -a \( -s "$recfile" \); then
+	if [ -n "$recfile" ] && [ -s "$recfile" ]; then
 		$SENDMAIL -t < "$i"
 	else
 		rm -f "$i"



CVS commit: src/sys/arch/xen/conf

2017-11-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Nov  4 07:01:45 UTC 2017

Modified Files:
src/sys/arch/xen/conf: files.xen

Log Message:
opt_intrdebug.h - this unbreaks the i386 DOMU build under some conditions


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/xen/conf/files.xen

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/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.156 src/sys/arch/xen/conf/files.xen:1.157
--- src/sys/arch/xen/conf/files.xen:1.156	Tue Aug 15 08:51:38 2017
+++ src/sys/arch/xen/conf/files.xen	Sat Nov  4 07:01:45 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.156 2017/08/15 08:51:38 maxv Exp $
+#	$NetBSD: files.xen,v 1.157 2017/11/04 07:01:45 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -15,6 +15,9 @@ defparam opt_kernbase.h	KERNBASE
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
 
+# Interrupt debug
+defflag opt_intrdebug.h	INTRDEBUG
+
 # delay before cpu_reset() for reboot.
 defparam		CPURESET_DELAY
 



CVS commit: src/external/bsd/nvi/dist/common

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  4 06:15:56 UTC 2017

Modified Files:
src/external/bsd/nvi/dist/common: recover.c

Log Message:
oops, accidendally committed an earlier non-working version; fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/bsd/nvi/dist/common/recover.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/nvi/dist/common/recover.c
diff -u src/external/bsd/nvi/dist/common/recover.c:1.7 src/external/bsd/nvi/dist/common/recover.c:1.8
--- src/external/bsd/nvi/dist/common/recover.c:1.7	Sat Nov  4 02:12:26 2017
+++ src/external/bsd/nvi/dist/common/recover.c	Sat Nov  4 02:15:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: recover.c,v 1.7 2017/11/04 06:12:26 christos Exp $ */
+/*	$NetBSD: recover.c,v 1.8 2017/11/04 06:15:56 christos Exp $ */
 /*-
  * Copyright (c) 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: recover.c,v 10.31 2001/11/01 15:24:44 skimo Exp  (Berkeley) Date: 2001/11/01 15:24:44 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: recover.c,v 1.7 2017/11/04 06:12:26 christos Exp $");
+__RCSID("$NetBSD: recover.c,v 1.8 2017/11/04 06:15:56 christos Exp $");
 #endif
 
 #include 
@@ -901,11 +901,11 @@ rcv_email(SCR *sp, const char *fname)
 	 */
 	if ((fin = fopen(fname, "refl")) == NULL) {
 		msgq_str(sp, M_SYSERR,
-		fname, "071|cannot open: %s");
+		fname, "325|cannot open: %s");
 		return;
 	}
 
-	if (!checkok(fname)) {
+	if (!checkok(fileno(fin))) {
 		(void)fclose(fin);
 		return;
 	}
@@ -915,16 +915,16 @@ rcv_email(SCR *sp, const char *fname)
 	argv[2] = fname;
 	argv[3] = NULL;
 
-	fout = popenve(_PATH_SENDMAIL, argv, environ, "w");
+	fout = popenve(_PATH_SENDMAIL, __UNCONST(argv), environ, "w");
 	if (fout == NULL) {
 		msgq_str(sp, M_SYSERR,
-		_PATH_SENDMAIL, "071|cannot execute sendmail: %s");
+		_PATH_SENDMAIL, "326|cannot execute sendmail: %s");
 		fclose(fin);
 		return;
 	}
 
-	while ((x = fread(fin, 1, sizeof(buf), buf)) != 0)
-		(void)fwrite(fout, 1, x, buf);
+	while ((l = fread(buf, 1, sizeof(buf), fin)) != 0)
+		(void)fwrite(buf, 1, l, fout);
 
 	(void)fclose(fin);
 	(void)pclose(fout);



CVS commit: src/external/bsd/nvi/dist/common

2017-11-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  4 06:12:26 UTC 2017

Modified Files:
src/external/bsd/nvi/dist/common: recover.c

Log Message:
Deal safely with recovery mail files.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/bsd/nvi/dist/common/recover.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/nvi/dist/common/recover.c
diff -u src/external/bsd/nvi/dist/common/recover.c:1.6 src/external/bsd/nvi/dist/common/recover.c:1.7
--- src/external/bsd/nvi/dist/common/recover.c:1.6	Fri Nov  3 23:26:41 2017
+++ src/external/bsd/nvi/dist/common/recover.c	Sat Nov  4 02:12:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: recover.c,v 1.6 2017/11/04 03:26:41 christos Exp $ */
+/*	$NetBSD: recover.c,v 1.7 2017/11/04 06:12:26 christos Exp $ */
 /*-
  * Copyright (c) 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -16,7 +16,7 @@
 static const char sccsid[] = "Id: recover.c,v 10.31 2001/11/01 15:24:44 skimo Exp  (Berkeley) Date: 2001/11/01 15:24:44 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: recover.c,v 1.6 2017/11/04 03:26:41 christos Exp $");
+__RCSID("$NetBSD: recover.c,v 1.7 2017/11/04 06:12:26 christos Exp $");
 #endif
 
 #include 
@@ -115,17 +115,17 @@ __RCSID("$NetBSD: recover.c,v 1.6 2017/1
 #define	VI_FHEADER	"X-vi-recover-file: "
 #define	VI_PHEADER	"X-vi-recover-path: "
 
-static int	 rcv_copy __P((SCR *, int, char *));
-static void	 rcv_email __P((SCR *, char *));
-static char	*rcv_gets __P((char *, size_t, int));
-static int	 rcv_mailfile __P((SCR *, int, char *));
-static int	 rcv_mktemp __P((SCR *, char *, const char *, int));
+static int	 rcv_copy(SCR *, int, char *);
+static void	 rcv_email(SCR *, const char *);
+static char	*rcv_gets(char *, size_t, int);
+static int	 rcv_mailfile(SCR *, int, char *);
+static int	 rcv_mktemp(SCR *, char *, const char *, int);
 
 /*
  * rcv_tmp --
  *	Build a file name that will be used as the recovery file.
  *
- * PUBLIC: int rcv_tmp __P((SCR *, EXF *, char *));
+ * PUBLIC: int rcv_tmp(SCR *, EXF *, char *);
  */
 int
 rcv_tmp(SCR *sp, EXF *ep, char *name)
@@ -186,7 +186,7 @@ err:		msgq(sp, M_ERR,
  * rcv_init --
  *	Force the file to be snapshotted for recovery.
  *
- * PUBLIC: int rcv_init __P((SCR *));
+ * PUBLIC: int rcv_init(SCR *);
  */
 int
 rcv_init(SCR *sp)
@@ -248,7 +248,7 @@ err:	msgq(sp, M_ERR,
  *		sending email to the user if the file was modified
  *		ending the file session
  *
- * PUBLIC: int rcv_sync __P((SCR *, u_int));
+ * PUBLIC: int rcv_sync(SCR *, u_int);
  */
 int
 rcv_sync(SCR *sp, u_int flags)
@@ -505,7 +505,7 @@ checkok(int fd)
  * rcv_list --
  *	List the files that can be recovered by this user.
  *
- * PUBLIC: int rcv_list __P((SCR *));
+ * PUBLIC: int rcv_list(SCR *);
  */
 int
 rcv_list(SCR *sp)
@@ -614,7 +614,7 @@ next:		(void)fclose(fp);
  * rcv_read --
  *	Start a recovered file as the file to edit.
  *
- * PUBLIC: int rcv_read __P((SCR *, FREF *));
+ * PUBLIC: int rcv_read(SCR *, FREF *);
  */
 int
 rcv_read(SCR *sp, FREF *frp)
@@ -871,29 +871,61 @@ rcv_mktemp(SCR *sp, char *path, const ch
 	return (fd);
 }
 
+extern char **environ;
+
 /*
  * rcv_email --
  *	Send email.
  */
 static void
-rcv_email(SCR *sp, char *fname)
+rcv_email(SCR *sp, const char *fname)
 {
 	struct stat sb;
-	char buf[MAXPATHLEN * 2 + 20];
+	char buf[BUFSIZ];
+	FILE *fin, *fout;
+	const char *argv[4];
+	size_t l;
 
-	if (_PATH_SENDMAIL[0] != '/' || stat(_PATH_SENDMAIL, ))
+	if (_PATH_SENDMAIL[0] != '/' || stat(_PATH_SENDMAIL, ) == -1) {
 		msgq_str(sp, M_SYSERR,
 		_PATH_SENDMAIL, "071|not sending email: %s");
-	else {
-		/*
-		 * !!!
-		 * If you need to port this to a system that doesn't have
-		 * sendmail, the -t flag causes sendmail to read the message
-		 * for the recipients instead of specifying them some other
-		 * way.
-		 */
-		(void)snprintf(buf, sizeof(buf),
-		"%s -t < %s", _PATH_SENDMAIL, fname);
-		(void)system(buf);
+		return;
+	}
+
+	/*
+	 * !!!
+	 * If you need to port this to a system that doesn't have
+	 * sendmail, the -t flag causes sendmail to read the message
+	 * for the recipients instead of specifying them some other
+	 * way.
+	 */
+	if ((fin = fopen(fname, "refl")) == NULL) {
+		msgq_str(sp, M_SYSERR,
+		fname, "071|cannot open: %s");
+		return;
 	}
+
+	if (!checkok(fname)) {
+		(void)fclose(fin);
+		return;
+	}
+
+	argv[0] = _PATH_SENDMAIL;
+	argv[1] = "-t";
+	argv[2] = fname;
+	argv[3] = NULL;
+
+	fout = popenve(_PATH_SENDMAIL, argv, environ, "w");
+	if (fout == NULL) {
+		msgq_str(sp, M_SYSERR,
+		_PATH_SENDMAIL, "071|cannot execute sendmail: %s");
+		fclose(fin);
+		return;
+	}
+
+	while ((x = fread(fin, 1, sizeof(buf), buf)) != 0)
+		(void)fwrite(fout, 1, x, buf);
+
+	(void)fclose(fin);
+	(void)pclose(fout);
 }