svn commit: r237087 - in user/alc/superpages: lib/libc/gen libexec/rtld-elf sys/amd64/amd64 sys/arm/include sys/dev/usb sys/dev/usb/quirk sys/geom/part sys/kern sys/sys

Alan Cox alc at FreeBSD.org
Thu Jun 14 17:54:53 UTC 2012


Author: alc
Date: Thu Jun 14 17:54:52 2012
New Revision: 237087
URL: http://svn.freebsd.org/changeset/base/237087

Log:
  MFC r237086
    Loop back fixes to comments and a KASSERT().

Added:
  user/alc/superpages/sys/arm/include/atags.h
     - copied unchanged from r237086, head/sys/arm/include/atags.h
Modified:
  user/alc/superpages/lib/libc/gen/fstab.c
  user/alc/superpages/libexec/rtld-elf/map_object.c
  user/alc/superpages/sys/amd64/amd64/pmap.c
  user/alc/superpages/sys/dev/usb/quirk/usb_quirk.c
  user/alc/superpages/sys/dev/usb/usbdevs
  user/alc/superpages/sys/geom/part/g_part_gpt.c
  user/alc/superpages/sys/kern/kern_descrip.c
  user/alc/superpages/sys/kern/kern_event.c
  user/alc/superpages/sys/sys/filedesc.h
Directory Properties:
  user/alc/superpages/   (props changed)
  user/alc/superpages/lib/libc/   (props changed)
  user/alc/superpages/sys/   (props changed)

Modified: user/alc/superpages/lib/libc/gen/fstab.c
==============================================================================
--- user/alc/superpages/lib/libc/gen/fstab.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/lib/libc/gen/fstab.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <fstab.h>
 #include <paths.h>
 #include <stdio.h>
@@ -246,6 +247,8 @@ getfsfile(name)
 int 
 setfsent()
 {
+	int fd;
+
 	if (_fs_fp) {
 		rewind(_fs_fp);
 		LineNo = 0;
@@ -257,11 +260,18 @@ setfsent()
 		else
 			setfstab(getenv("PATH_FSTAB"));
 	}
-	if ((_fs_fp = fopen(path_fstab, "r")) != NULL) {
+	fd = _open(path_fstab, O_RDONLY | O_CLOEXEC);
+	if (fd == -1) {
+		error(errno);
+		return (0);
+	}
+	_fs_fp = fdopen(fd, "r");
+	if (_fs_fp  != NULL) {
 		LineNo = 0;
 		return(1);
 	}
 	error(errno);
+	_close(fd);
 	return(0);
 }
 

Modified: user/alc/superpages/libexec/rtld-elf/map_object.c
==============================================================================
--- user/alc/superpages/libexec/rtld-elf/map_object.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/libexec/rtld-elf/map_object.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -38,7 +38,7 @@
 #include "debug.h"
 #include "rtld.h"
 
-static Elf_Ehdr *get_elf_header (int, const char *);
+static Elf_Ehdr *get_elf_header(int, const char *);
 static int convert_prot(int);	/* Elf flags -> mmap protection */
 static int convert_flags(int); /* Elf flags -> mmap flags */
 
@@ -121,7 +121,7 @@ map_object(int fd, const char *path, con
     	    if ((segs[nsegs]->p_align & (PAGE_SIZE - 1)) != 0) {
 		_rtld_error("%s: PT_LOAD segment %d not page-aligned",
 		    path, nsegs);
-		return NULL;
+		goto error;
 	    }
 	    break;
 
@@ -161,12 +161,12 @@ map_object(int fd, const char *path, con
     }
     if (phdyn == NULL) {
 	_rtld_error("%s: object is not dynamically-linked", path);
-	return NULL;
+	goto error;
     }
 
     if (nsegs < 0) {
 	_rtld_error("%s: too few PT_LOAD segments", path);
-	return NULL;
+	goto error;
     }
 
     /*
@@ -183,13 +183,12 @@ map_object(int fd, const char *path, con
     if (mapbase == (caddr_t) -1) {
 	_rtld_error("%s: mmap of entire address space failed: %s",
 	  path, rtld_strerror(errno));
-	return NULL;
+	goto error;
     }
     if (base_addr != NULL && mapbase != base_addr) {
 	_rtld_error("%s: mmap returned wrong address: wanted %p, got %p",
 	  path, base_addr, mapbase);
-	munmap(mapbase, mapsize);
-	return NULL;
+	goto error1;
     }
 
     for (i = 0; i <= nsegs; i++) {
@@ -201,10 +200,10 @@ map_object(int fd, const char *path, con
 	data_prot = convert_prot(segs[i]->p_flags);
 	data_flags = convert_flags(segs[i]->p_flags) | MAP_FIXED;
 	if (mmap(data_addr, data_vlimit - data_vaddr, data_prot,
-	  data_flags, fd, data_offset) == (caddr_t) -1) {
+	  data_flags | MAP_PREFAULT_READ, fd, data_offset) == (caddr_t) -1) {
 	    _rtld_error("%s: mmap of data failed: %s", path,
 		rtld_strerror(errno));
-	    return NULL;
+	    goto error1;
 	}
 
 	/* Do BSS setup */
@@ -221,7 +220,7 @@ map_object(int fd, const char *path, con
 		     mprotect(clear_page, PAGE_SIZE, data_prot|PROT_WRITE)) {
 			_rtld_error("%s: mprotect failed: %s", path,
 			    rtld_strerror(errno));
-			return NULL;
+			goto error1;
 		}
 
 		memset(clear_addr, 0, nclear);
@@ -240,7 +239,7 @@ map_object(int fd, const char *path, con
 		    data_flags | MAP_ANON, -1, 0) == (caddr_t)-1) {
 		    _rtld_error("%s: mmap of bss failed: %s", path,
 			rtld_strerror(errno));
-		    return NULL;
+		    goto error1;
 		}
 	    }
 	}
@@ -273,7 +272,7 @@ map_object(int fd, const char *path, con
 	if (obj->phdr == NULL) {
 	    obj_free(obj);
 	    _rtld_error("%s: cannot allocate program header", path);
-	     return NULL;
+	    goto error1;
 	}
 	memcpy((char *)obj->phdr, (char *)hdr + hdr->e_phoff, phsize);
 	obj->phdr_alloc = true;
@@ -293,63 +292,72 @@ map_object(int fd, const char *path, con
     obj->relro_page = obj->relocbase + trunc_page(relro_page);
     obj->relro_size = round_page(relro_size);
 
-    return obj;
+    munmap(hdr, PAGE_SIZE);
+    return (obj);
+
+error1:
+    munmap(mapbase, mapsize);
+error:
+    munmap(hdr, PAGE_SIZE);
+    return (NULL);
 }
 
 static Elf_Ehdr *
-get_elf_header (int fd, const char *path)
+get_elf_header(int fd, const char *path)
 {
-    static union {
-	Elf_Ehdr hdr;
-	char buf[PAGE_SIZE];
-    } u;
-    ssize_t nbytes;
-
-    if ((nbytes = pread(fd, u.buf, PAGE_SIZE, 0)) == -1) {
-	_rtld_error("%s: read error: %s", path, rtld_strerror(errno));
-	return NULL;
-    }
-
-    /* Make sure the file is valid */
-    if (nbytes < (ssize_t)sizeof(Elf_Ehdr) || !IS_ELF(u.hdr)) {
-	_rtld_error("%s: invalid file format", path);
-	return NULL;
-    }
-    if (u.hdr.e_ident[EI_CLASS] != ELF_TARG_CLASS
-      || u.hdr.e_ident[EI_DATA] != ELF_TARG_DATA) {
-	_rtld_error("%s: unsupported file layout", path);
-	return NULL;
-    }
-    if (u.hdr.e_ident[EI_VERSION] != EV_CURRENT
-      || u.hdr.e_version != EV_CURRENT) {
-	_rtld_error("%s: unsupported file version", path);
-	return NULL;
-    }
-    if (u.hdr.e_type != ET_EXEC && u.hdr.e_type != ET_DYN) {
-	_rtld_error("%s: unsupported file type", path);
-	return NULL;
-    }
-    if (u.hdr.e_machine != ELF_TARG_MACH) {
-	_rtld_error("%s: unsupported machine", path);
-	return NULL;
-    }
+	Elf_Ehdr *hdr;
 
-    /*
-     * We rely on the program header being in the first page.  This is
-     * not strictly required by the ABI specification, but it seems to
-     * always true in practice.  And, it simplifies things considerably.
-     */
-    if (u.hdr.e_phentsize != sizeof(Elf_Phdr)) {
-	_rtld_error(
-	  "%s: invalid shared object: e_phentsize != sizeof(Elf_Phdr)", path);
-	return NULL;
-    }
-    if (u.hdr.e_phoff + u.hdr.e_phnum * sizeof(Elf_Phdr) > (size_t)nbytes) {
-	_rtld_error("%s: program header too large", path);
-	return NULL;
-    }
+	hdr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_PREFAULT_READ,
+	    fd, 0);
+	if (hdr == (Elf_Ehdr *)MAP_FAILED) {
+		_rtld_error("%s: read error: %s", path, rtld_strerror(errno));
+		return (NULL);
+	}
+
+	/* Make sure the file is valid */
+	if (!IS_ELF(*hdr)) {
+		_rtld_error("%s: invalid file format", path);
+		goto error;
+	}
+	if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS ||
+	    hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
+		_rtld_error("%s: unsupported file layout", path);
+		goto error;
+	}
+	if (hdr->e_ident[EI_VERSION] != EV_CURRENT ||
+	    hdr->e_version != EV_CURRENT) {
+		_rtld_error("%s: unsupported file version", path);
+		goto error;
+	}
+	if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
+		_rtld_error("%s: unsupported file type", path);
+		goto error;
+	}
+	if (hdr->e_machine != ELF_TARG_MACH) {
+		_rtld_error("%s: unsupported machine", path);
+		goto error;
+	}
 
-    return (&u.hdr);
+	/*
+	 * We rely on the program header being in the first page.  This is
+	 * not strictly required by the ABI specification, but it seems to
+	 * always true in practice.  And, it simplifies things considerably.
+	 */
+	if (hdr->e_phentsize != sizeof(Elf_Phdr)) {
+		_rtld_error(
+	    "%s: invalid shared object: e_phentsize != sizeof(Elf_Phdr)", path);
+		goto error;
+	}
+	if (hdr->e_phoff + hdr->e_phnum * sizeof(Elf_Phdr) >
+	    (size_t)PAGE_SIZE) {
+		_rtld_error("%s: program header too large", path);
+		goto error;
+	}
+	return (hdr);
+
+error:
+	munmap(hdr, PAGE_SIZE);
+	return (NULL);
 }
 
 void

Modified: user/alc/superpages/sys/amd64/amd64/pmap.c
==============================================================================
--- user/alc/superpages/sys/amd64/amd64/pmap.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/amd64/amd64/pmap.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -2587,7 +2587,7 @@ pmap_demote_pde(pmap_t pmap, pd_entry_t 
 	/*
 	 * Demote the pv entry.  This depends on the earlier demotion
 	 * of the mapping.  Specifically, the (re)creation of a per-
-	 * page pv entry might trigger the execution of pmap_collect(),
+	 * page pv entry might trigger the execution of pmap_pv_reclaim(),
 	 * which might reclaim a newly (re)created per-page pv entry
 	 * and destroy the associated mapping.  In order to destroy
 	 * the mapping, the PDE must have already changed from mapping
@@ -4450,8 +4450,9 @@ small_mappings:
 		pmap = PV_PMAP(pv);
 		PMAP_LOCK(pmap);
 		pde = pmap_pde(pmap, pv->pv_va);
-		KASSERT((*pde & PG_PS) == 0, ("pmap_clear_write: found"
-		    " a 2mpage in page %p's pv list", m));
+		KASSERT((*pde & PG_PS) == 0,
+		    ("pmap_remove_write: found a 2mpage in page %p's pv list",
+		    m));
 		pte = pmap_pde_to_pte(pde, pv->pv_va);
 retry:
 		oldpte = *pte;

Copied: user/alc/superpages/sys/arm/include/atags.h (from r237086, head/sys/arm/include/atags.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/alc/superpages/sys/arm/include/atags.h	Thu Jun 14 17:54:52 2012	(r237087, copy of r237086, head/sys/arm/include/atags.h)
@@ -0,0 +1,129 @@
+/*-
+ * Copyright (c) 2012 M. Warner Losh.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	__MACHINE_ATAGS_H__
+#define __MACHINE_ATAGS_H__
+
+/*
+ * Linux boot ABI compatable ATAG definitions.  All these structures
+ * assume tight packing, but since they are all uint32_t's, I've not
+ * bothered to do the usual alignment dance.
+ */
+
+#define	LBABI_MAX_COMMAND_LINE  1024
+
+struct arm_lbabi_header
+{
+	uint32_t	size;		/* Size of this node, including header */
+	uint32_t	tag;		/* Node type */
+};
+
+#define	ATAG_NONE       0x00000000	/* End of atags list */
+#define	ATAG_CORE	0x54410001	/* List must start with ATAG_CORE */
+#define	ATAG_MEM	0x54410002	/* Multiple ATAG_MEM nodes possible */
+#define	ATAG_VIDEOTEXT	0x54410003	/* Video parameters */
+#define	ATAG_RAMDISK	0x54410004	/* Describes the ramdisk parameters */
+#define	ATAG_INITRD	0x54410005	/* Deprecated ramdisk -- used va not pa */
+#define	ATAG_INITRD2	0x54420005	/* compressed ramdisk image */
+#define	ATAG_SERIAL	0x54410006	/* 64-bits of serial number */
+#define	ATAG_REVISION	0x54410007	/* Board revision */
+#define	ATAG_VIDEOLFB	0x54410008	/* vesafb framebuffer */
+#define	ATAG_CMDLINE	0x54410009	/* Command line */
+
+/*
+ * ATAG_CORE data
+ */
+struct arm_lbabi_core
+{
+	uint32_t flags;			/* bit 0 == read-only */
+	uint32_t pagesize;
+	uint32_t rootdev;
+};
+		
+/*
+ * ATAG_MEM data -- Can be more than one to describe different
+ * banks.
+ */
+struct arm_lbabi_mem32
+{
+	uint32_t size;
+	uint32_t start;			/* start of physical memory */
+};
+
+/* 
+ * ATAG_INITRD2 - Compressed ramdisk image details
+ */
+struct arm_lbabi_initrd
+{
+	uint32_t start;			/* pa of start */
+	uint32_t size;			/* How big the ram disk is */
+};
+
+/*
+ * ATAG_SERIAL - serial number
+ */
+struct arm_lbabi_serial_number
+{
+	uint32_t low;
+	uint32_t high;
+};
+	
+/*
+ * ATAG_REVISION - board revision
+ */
+struct arm_lbabi_revision
+{
+	uint32_t rev;
+};
+	
+/*
+ * ATAG_CMDLINE - Command line from uboot
+ */
+struct arm_lbabi_command_line
+{
+	char command[1];		/* Minimum command length */
+};
+
+struct arm_lbabi_tag 
+{
+	struct arm_lbabi_header tag_hdr;
+	union {
+		struct arm_lbabi_core tag_core;
+		struct arm_lbabi_mem32 tag_mem;
+		struct arm_lbabi_initrd tag_initrd;
+		struct arm_lbabi_serial_number tag_sn;
+		struct arm_lbabi_revision tag_rev;
+		struct arm_lbabi_command_line tag_cmd;
+	} u;
+};
+
+#define	ATAG_TAG(a)  (a)->tag_hdr.tag
+#define ATAG_SIZE(a) (a)->tag_hdr.size
+#define ATAG_NEXT(a) (struct arm_lbabi_tag *)((char *)(a) + ATAG_SIZE(a))
+
+#endif /* __MACHINE_ATAGS_H__ */

Modified: user/alc/superpages/sys/dev/usb/quirk/usb_quirk.c
==============================================================================
--- user/alc/superpages/sys/dev/usb/quirk/usb_quirk.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/dev/usb/quirk/usb_quirk.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -454,7 +454,13 @@ static struct usb_quirk_entry usb_quirks
 	USB_QUIRK(ROLAND, SD20, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
 	USB_QUIRK(ROLAND, SD80, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
 	USB_QUIRK(ROLAND, UA700, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
+	USB_QUIRK(EGO, M4U, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
+	USB_QUIRK(LOGILINK, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
 	USB_QUIRK(MEDELI, DD305, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI, UQ_MATCH_VENDOR_ONLY),
+	USB_QUIRK(REDOCTANE, GHMIDI, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
+	USB_QUIRK(TEXTECH, U2M_1, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
+	USB_QUIRK(TEXTECH, U2M_2, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
+	USB_QUIRK(WCH2, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
 
 	/*
 	 * Quirks for manufacturers which USB devices does not respond

Modified: user/alc/superpages/sys/dev/usb/usbdevs
==============================================================================
--- user/alc/superpages/sys/dev/usb/usbdevs	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/dev/usb/usbdevs	Thu Jun 14 17:54:52 2012	(r237087)
@@ -487,6 +487,7 @@ vendor BROADCOM		0x0a5c	Broadcom
 vendor GREENHOUSE	0x0a6b	GREENHOUSE
 vendor MEDELI		0x0a67	Medeli
 vendor GEOCAST		0x0a79	Geocast Network Systems
+vendor EGO		0x0a92	EGO systems
 vendor IDQUANTIQUE	0x0aba	id Quantique
 vendor ZYDAS		0x0ace	Zydas Technology Corporation
 vendor NEODIO		0x0aec	Neodio
@@ -611,6 +612,7 @@ vendor INITIO		0x13fd	Initio Corporation
 vendor EMTEC		0x13fe	Emtec
 vendor NOVATEL		0x1410	Novatel Wireless
 vendor MERLIN		0x1416	Merlin
+vendor REDOCTANE	0x1430	RedOctane
 vendor WISTRONNEWEB	0x1435	Wistron NeWeb
 vendor RADIOSHACK	0x1453	Radio Shack
 vendor HUAWEI3COM	0x1472	Huawei-3Com
@@ -633,6 +635,7 @@ vendor FIBERLINE	0x1582	Fiberline
 vendor SPARKLAN		0x15a9	SparkLAN
 vendor SOUNDGRAPH 	0x15c2	Soundgraph, Inc.
 vendor AMIT2		0x15c5	AMIT
+vendor TEXTECH		0x15ca	Textech International Ltd.
 vendor SOHOWARE		0x15e8	SOHOware
 vendor UMAX		0x1606	UMAX Data Systems
 vendor INSIDEOUT	0x1608	Inside Out Networks
@@ -723,6 +726,7 @@ vendor MARVELL		0x9e88	Marvell Technolog
 vendor 3COM3		0xa727	3Com
 vendor DATAAPEX		0xdaae	DataApex
 vendor HP2		0xf003	Hewlett Packard
+vendor LOGILINK		0xfc08	LogiLink
 vendor USRP		0xfffe	GNU Radio USRP
 
 /*
@@ -1472,6 +1476,10 @@ product EGALAX TPANEL		0x0001	Touch Pane
 product EGALAX TPANEL2		0x0002	Touch Panel
 product EGALAX2 TPANEL		0x0001	Touch Panel
 
+/* EGO Products */
+product EGO DUMMY		0x0000	Dummy Product
+product EGO M4U			0x1020	ESI M4U
+
 /* Eicon Networks */
 product EICON DIVA852		0x4905	Diva 852 ISDN TA
 
@@ -2090,6 +2098,10 @@ product LINKSYS4 WUSB54GCV3	0x0077	WUSB5
 product LINKSYS4 RT3070		0x0078	RT3070
 product LINKSYS4 WUSB600NV2	0x0079	WUSB600N v2
 
+/* Logilink products */
+product LOGILINK DUMMY		0x0000	Dummy product
+product LOGILINK U2M		0x0101	LogiLink USB MIDI Cable
+
 /* Logitech products */
 product LOGITECH M2452		0x0203	M2452 keyboard
 product LOGITECH M4848		0x0301	M4848 mouse
@@ -2813,6 +2825,10 @@ product REALTEK RTL8187B_0	0x8189	RTL818
 product REALTEK RTL8187B_1	0x8197	RTL8187B Wireless Adapter
 product REALTEK RTL8187B_2	0x8198	RTL8187B Wireless Adapter
 
+/* RedOctane products */
+product REDOCTANE DUMMY		0x0000	Dummy product
+product REDOCTANE GHMIDI	0x474b	GH MIDI INTERFACE
+
 /* Renesas products */
 product RENESAS RX610		0x0053	RX610 RX-Stick
 
@@ -3249,6 +3265,11 @@ product	SYNTECH CYPHERLAB100	0x1000	Ciph
 /* Teclast products */
 product TECLAST TLC300		0x3203	USB Media Player
 
+/* TexTech products */
+product TEXTECH DUMMY		0x0000	Dummy product
+product TEXTECH U2M_1		0x0101	Textech USB MIDI cable
+product TEXTECH U2M_2		0x1806	Textech USB MIDI cable
+
 /* Supra products */
 product DIAMOND2 SUPRAEXPRESS56K 0x07da	Supra Express 56K modem
 product DIAMOND2 SUPRA2890	0x0b4a	SupraMax 2890 56K Modem
@@ -3421,7 +3442,9 @@ product WAVESENSE JAZZ		0xaaaa	Jazz bloo
 
 /* WCH products */
 product WCH CH341SER		0x5523	CH341/CH340 USB-Serial Bridge
+product WCH2 DUMMY		0x0000	Dummy product
 product WCH2 CH341SER		0x7523	CH341/CH340 USB-Serial Bridge
+product WCH2 U2M		0X752d	CH345 USB2.0-MIDI
 
 /* Western Digital products */
 product WESTERN COMBO		0x0200	Firewire USB Combo

Modified: user/alc/superpages/sys/geom/part/g_part_gpt.c
==============================================================================
--- user/alc/superpages/sys/geom/part/g_part_gpt.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/geom/part/g_part_gpt.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -341,9 +341,6 @@ gpt_update_bootcamp(struct g_part_table 
 
  disable:
 	table->bootcamp = 0;
-	bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
-	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1ull,
-	    MIN(table->lba[GPT_ELT_SECHDR], UINT32_MAX));
 }
 
 static struct gpt_hdr *
@@ -589,10 +586,6 @@ g_part_gpt_bootcode(struct g_part_table 
 	codesz = MIN(codesz, gpp->gpp_codesize);
 	if (codesz > 0)
 		bcopy(gpp->gpp_codeptr, table->mbr, codesz);
-
-	/* Mark the PMBR active since some BIOS require it. */
-	if (!table->bootcamp)
-		table->mbr[DOSPARTOFF] = 0x80;		/* status */
 	return (0);
 }
 
@@ -601,7 +594,6 @@ g_part_gpt_create(struct g_part_table *b
 {
 	struct g_provider *pp;
 	struct g_part_gpt_table *table;
-	quad_t last;
 	size_t tblsz;
 
 	/* We don't nest, which means that our depth should be 0. */
@@ -617,11 +609,6 @@ g_part_gpt_create(struct g_part_table *b
 	    pp->sectorsize)
 		return (ENOSPC);
 
-	last = (pp->mediasize / pp->sectorsize) - 1;
-
-	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
-	gpt_write_mbr_entry(table->mbr, 0, 0xee, 1, MIN(last, UINT32_MAX));
-
 	/* Allocate space for the header */
 	table->hdr = g_malloc(sizeof(struct gpt_hdr), M_WAITOK | M_ZERO);
 
@@ -1047,6 +1034,16 @@ g_part_gpt_write(struct g_part_table *ba
 	if (table->bootcamp)
 		gpt_update_bootcamp(basetable);
 
+	/* Update partition entries in the PMBR if Boot Camp disabled. */
+	if (!table->bootcamp) {
+		bzero(table->mbr + DOSPARTOFF, DOSPARTSIZE * NDOSPART);
+		gpt_write_mbr_entry(table->mbr, 0, 0xee, 1,
+		    MIN(pp->mediasize / pp->sectorsize - 1, UINT32_MAX));
+		/* Mark the PMBR active since some BIOS require it. */
+		table->mbr[DOSPARTOFF] = 0x80;
+	}
+	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
+
 	/* Write the PMBR */
 	buf = g_malloc(pp->sectorsize, M_WAITOK | M_ZERO);
 	bcopy(table->mbr, buf, MBRSIZE);

Modified: user/alc/superpages/sys/kern/kern_descrip.c
==============================================================================
--- user/alc/superpages/sys/kern/kern_descrip.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/kern/kern_descrip.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -102,7 +102,7 @@ __FBSDID("$FreeBSD$");
 
 static MALLOC_DEFINE(M_FILEDESC, "filedesc", "Open file descriptor table");
 static MALLOC_DEFINE(M_FILEDESC_TO_LEADER, "filedesc_to_leader",
-		     "file desc to leader structures");
+    "file desc to leader structures");
 static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures");
 
 MALLOC_DECLARE(M_FADVISE);
@@ -114,22 +114,21 @@ static uma_zone_t file_zone;
 #define DUP_FIXED	0x1	/* Force fixed allocation */
 #define DUP_FCNTL	0x2	/* fcntl()-style errors */
 
-static int	closefp(struct filedesc *fdp, int fd, struct file *fp,
-    struct thread *td);
-static int	do_dup(struct thread *td, int flags, int old, int new,
+static int closefp(struct filedesc *fdp, int fd, struct file *fp,
+    struct thread *td, int holdleaders);
+static int do_dup(struct thread *td, int flags, int old, int new,
     register_t *retval);
-static int	fd_first_free(struct filedesc *, int, int);
-static int	fd_last_used(struct filedesc *, int);
-static void	fdgrowtable(struct filedesc *, int);
-static void	fdunused(struct filedesc *fdp, int fd);
-static void	fdused(struct filedesc *fdp, int fd);
-static int	fill_vnode_info(struct vnode *vp, struct kinfo_file *kif);
-static int	fill_socket_info(struct socket *so, struct kinfo_file *kif);
-static int	fill_pts_info(struct tty *tp, struct kinfo_file *kif);
-static int	fill_pipe_info(struct pipe *pi, struct kinfo_file *kif);
-static int	fill_procdesc_info(struct procdesc *pdp,
-    struct kinfo_file *kif);
-static int	fill_shm_info(struct file *fp, struct kinfo_file *kif);
+static int fd_first_free(struct filedesc *fdp, int low, int size);
+static int fd_last_used(struct filedesc *fdp, int size);
+static void fdgrowtable(struct filedesc *fdp, int nfd);
+static void fdunused(struct filedesc *fdp, int fd);
+static void fdused(struct filedesc *fdp, int fd);
+static int fill_pipe_info(struct pipe *pi, struct kinfo_file *kif);
+static int fill_procdesc_info(struct procdesc *pdp, struct kinfo_file *kif);
+static int fill_pts_info(struct tty *tp, struct kinfo_file *kif);
+static int fill_shm_info(struct file *fp, struct kinfo_file *kif);
+static int fill_socket_info(struct socket *so, struct kinfo_file *kif);
+static int fill_vnode_info(struct vnode *vp, struct kinfo_file *kif);
 
 /*
  * A process is initially started out with NDFILE descriptors stored within
@@ -183,10 +182,10 @@ struct filedesc0 {
  */
 volatile int openfiles;			/* actual number of open files */
 struct mtx sigio_lock;		/* mtx to protect pointers to sigio */
-void	(*mq_fdclose)(struct thread *td, int fd, struct file *fp);
+void (*mq_fdclose)(struct thread *td, int fd, struct file *fp);
 
 /* A mutex to protect the association between a proc and filedesc. */
-static struct mtx	fdesc_mtx;
+static struct mtx fdesc_mtx;
 
 /*
  * If low >= size, just return low. Otherwise find the first zero bit in the
@@ -243,8 +242,12 @@ fd_last_used(struct filedesc *fdp, int s
 static int
 fdisused(struct filedesc *fdp, int fd)
 {
-        KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
-            ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
+
+	FILEDESC_LOCK_ASSERT(fdp);
+
+	KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
+	    ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
+
 	return ((fdp->fd_map[NDSLOT(fd)] & NDBIT(fd)) != 0);
 }
 
@@ -256,8 +259,8 @@ fdused(struct filedesc *fdp, int fd)
 {
 
 	FILEDESC_XLOCK_ASSERT(fdp);
-	KASSERT(!fdisused(fdp, fd),
-	    ("fd already used"));
+
+	KASSERT(!fdisused(fdp, fd), ("fd=%d is already used", fd));
 
 	fdp->fd_map[NDSLOT(fd)] |= NDBIT(fd);
 	if (fd > fdp->fd_lastfile)
@@ -274,10 +277,9 @@ fdunused(struct filedesc *fdp, int fd)
 {
 
 	FILEDESC_XLOCK_ASSERT(fdp);
-	KASSERT(fdisused(fdp, fd),
-	    ("fd is already unused"));
-	KASSERT(fdp->fd_ofiles[fd] == NULL,
-	    ("fd is still in use"));
+
+	KASSERT(fdisused(fdp, fd), ("fd=%d is already unused", fd));
+	KASSERT(fdp->fd_ofiles[fd] == NULL, ("fd=%d is still in use", fd));
 
 	fdp->fd_map[NDSLOT(fd)] &= ~NDBIT(fd);
 	if (fd < fdp->fd_freefile)
@@ -427,23 +429,13 @@ sys_fcntl(struct thread *td, struct fcnt
 	return (error);
 }
 
-static inline struct file *
-fdtofp(int fd, struct filedesc *fdp)
-{
-
-	FILEDESC_LOCK_ASSERT(fdp);
-
-	if (fd < 0 || fd >= fdp->fd_nfiles)
-		return (NULL);
-
-	return (fdp->fd_ofiles[fd]);
-}
-
 static inline int
 fdunwrap(int fd, cap_rights_t rights, struct filedesc *fdp, struct file **fpp)
 {
 
-	*fpp = fdtofp(fd, fdp);
+	FILEDESC_LOCK_ASSERT(fdp);
+
+	*fpp = fget_locked(fdp, fd);
 	if (*fpp == NULL)
 		return (EBADF);
 
@@ -492,7 +484,7 @@ kern_fcntl(struct thread *td, int fd, in
 
 	case F_GETFD:
 		FILEDESC_SLOCK(fdp);
-		if ((fp = fdtofp(fd, fdp)) == NULL) {
+		if ((fp = fget_locked(fdp, fd)) == NULL) {
 			FILEDESC_SUNLOCK(fdp);
 			error = EBADF;
 			break;
@@ -504,7 +496,7 @@ kern_fcntl(struct thread *td, int fd, in
 
 	case F_SETFD:
 		FILEDESC_XLOCK(fdp);
-		if ((fp = fdtofp(fd, fdp)) == NULL) {
+		if ((fp = fget_locked(fdp, fd)) == NULL) {
 			FILEDESC_XUNLOCK(fdp);
 			error = EBADF;
 			break;
@@ -677,8 +669,7 @@ kern_fcntl(struct thread *td, int fd, in
 		vfslocked = 0;
 		/* Check for race with close */
 		FILEDESC_SLOCK(fdp);
-		if (fd < 0 || fd >= fdp->fd_nfiles ||
-		    fp != fdp->fd_ofiles[fd]) {
+		if (fget_locked(fdp, fd) != fp) {
 			FILEDESC_SUNLOCK(fdp);
 			flp->l_whence = SEEK_SET;
 			flp->l_start = 0;
@@ -686,7 +677,7 @@ kern_fcntl(struct thread *td, int fd, in
 			flp->l_type = F_UNLCK;
 			vfslocked = VFS_LOCK_GIANT(vp->v_mount);
 			(void) VOP_ADVLOCK(vp, (caddr_t)p->p_leader,
-					   F_UNLCK, flp, F_POSIX);
+			    F_UNLCK, flp, F_POSIX);
 			VFS_UNLOCK_GIANT(vfslocked);
 			vfslocked = 0;
 		} else
@@ -743,7 +734,7 @@ kern_fcntl(struct thread *td, int fd, in
 		/* FALLTHROUGH */
 	case F_READAHEAD:
 		FILEDESC_SLOCK(fdp);
-		if ((fp = fdtofp(fd, fdp)) == NULL) {
+		if ((fp = fget_locked(fdp, fd)) == NULL) {
 			FILEDESC_SUNLOCK(fdp);
 			error = EBADF;
 			break;
@@ -820,7 +811,7 @@ do_dup(struct thread *td, int flags, int
 		return (flags & DUP_FCNTL ? EINVAL : EBADF);
 
 	FILEDESC_XLOCK(fdp);
-	if (old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) {
+	if (fget_locked(fdp, old) == NULL) {
 		FILEDESC_XUNLOCK(fdp);
 		return (EBADF);
 	}
@@ -885,7 +876,7 @@ do_dup(struct thread *td, int flags, int
 	*retval = new;
 
 	if (delfp != NULL) {
-		(void) closefp(fdp, new, delfp, td);
+		(void) closefp(fdp, new, delfp, td, 1);
 		/* closefp() drops the FILEDESC lock for us. */
 	} else {
 		FILEDESC_XUNLOCK(fdp);
@@ -1117,22 +1108,24 @@ fgetown(sigiop)
  * Function drops the filedesc lock on return.
  */
 static int
-closefp(struct filedesc *fdp, int fd, struct file *fp, struct thread *td)
+closefp(struct filedesc *fdp, int fd, struct file *fp, struct thread *td,
+    int holdleaders)
 {
 	struct file *fp_object;
-	int error, holdleaders;
+	int error;
 
 	FILEDESC_XLOCK_ASSERT(fdp);
 
-	if (td->td_proc->p_fdtol != NULL) {
-		/*
-		 * Ask fdfree() to sleep to ensure that all relevant
-		 * process leaders can be traversed in closef().
-		 */
-		fdp->fd_holdleaderscount++;
-		holdleaders = 1;
-	} else {
-		holdleaders = 0;
+	if (holdleaders) {
+		if (td->td_proc->p_fdtol != NULL) {
+			/*
+			 * Ask fdfree() to sleep to ensure that all relevant
+			 * process leaders can be traversed in closef().
+			 */
+			fdp->fd_holdleaderscount++;
+		} else {
+			holdleaders = 0;
+		}
 	}
 
 	/*
@@ -1197,8 +1190,7 @@ kern_close(td, fd)
 	AUDIT_SYSCLOSE(td, fd);
 
 	FILEDESC_XLOCK(fdp);
-	if (fd < 0 || fd >= fdp->fd_nfiles ||
-	    (fp = fdp->fd_ofiles[fd]) == NULL) {
+	if ((fp = fget_locked(fdp, fd)) == NULL) {
 		FILEDESC_XUNLOCK(fdp);
 		return (EBADF);
 	}
@@ -1207,7 +1199,7 @@ kern_close(td, fd)
 	fdunused(fdp, fd);
 
 	/* closefp() drops the FILEDESC lock for us. */
-	return (closefp(fdp, fd, fp, td));
+	return (closefp(fdp, fd, fp, td, 1));
 }
 
 /*
@@ -1370,6 +1362,7 @@ sys_fpathconf(struct thread *td, struct 
 	vp = fp->f_vnode;
 	if (vp != NULL) {
 		int vfslocked;
+
 		vfslocked = VFS_LOCK_GIANT(vp->v_mount);
 		vn_lock(vp, LK_SHARED | LK_RETRY);
 		error = VOP_PATHCONF(vp, uap->name, td->td_retval);
@@ -1380,7 +1373,7 @@ sys_fpathconf(struct thread *td, struct 
 			error = EINVAL;
 		} else {
 			td->td_retval[0] = PIPE_BUF;
-		error = 0;
+			error = 0;
 		}
 	} else {
 		error = EOPNOTSUPP;
@@ -1834,11 +1827,8 @@ fdfree(struct thread *td)
 				vp = fp->f_vnode;
 				locked = VFS_LOCK_GIANT(vp->v_mount);
 				(void) VOP_ADVLOCK(vp,
-						   (caddr_t)td->td_proc->
-						   p_leader,
-						   F_UNLCK,
-						   &lf,
-						   F_POSIX);
+				    (caddr_t)td->td_proc->p_leader, F_UNLCK,
+				    &lf, F_POSIX);
 				VFS_UNLOCK_GIANT(locked);
 				FILEDESC_XLOCK(fdp);
 				fdrop(fp, td);
@@ -2027,6 +2017,7 @@ void
 fdcloseexec(struct thread *td)
 {
 	struct filedesc *fdp;
+	struct file *fp;
 	int i;
 
 	/* Certain daemons might not have file descriptors. */
@@ -2034,31 +2025,20 @@ fdcloseexec(struct thread *td)
 	if (fdp == NULL)
 		return;
 
-	FILEDESC_XLOCK(fdp);
-
 	/*
 	 * We cannot cache fd_ofiles or fd_ofileflags since operations
 	 * may block and rip them out from under us.
 	 */
+	FILEDESC_XLOCK(fdp);
 	for (i = 0; i <= fdp->fd_lastfile; i++) {
-		if (fdp->fd_ofiles[i] != NULL &&
-		    (fdp->fd_ofiles[i]->f_type == DTYPE_MQUEUE ||
+		fp = fdp->fd_ofiles[i];
+		if (fp != NULL && (fp->f_type == DTYPE_MQUEUE ||
 		    (fdp->fd_ofileflags[i] & UF_EXCLOSE))) {
-			struct file *fp;
-
-			knote_fdclose(td, i);
-			/*
-			 * NULL-out descriptor prior to close to avoid
-			 * a race while close blocks.
-			 */
-			fp = fdp->fd_ofiles[i];
 			fdp->fd_ofiles[i] = NULL;
 			fdp->fd_ofileflags[i] = 0;
 			fdunused(fdp, i);
-			if (fp->f_type == DTYPE_MQUEUE)
-				mq_fdclose(td, i, fp);
-			FILEDESC_XUNLOCK(fdp);
-			(void) closef(fp, td);
+			(void) closefp(fdp, i, fp, td, 0);
+			/* closefp() drops the FILEDESC lock. */
 			FILEDESC_XLOCK(fdp);
 		}
 	}
@@ -2123,6 +2103,9 @@ closef(struct file *fp, struct thread *t
 	struct filedesc *fdp;
 	struct file *fp_object;
 
+	fdp = td->td_proc->p_fd;
+	FILEDESC_UNLOCK_ASSERT(fdp);
+
 	/*
 	 * POSIX record locking dictates that any close releases ALL
 	 * locks owned by this process.  This is handled by setting
@@ -2139,7 +2122,7 @@ closef(struct file *fp, struct thread *t
 	 * node, not the capability itself.
 	 */
 	(void)cap_funwrap(fp, 0, &fp_object);
-	if ((fp_object->f_type == DTYPE_VNODE) && (td != NULL)) {
+	if (fp_object->f_type == DTYPE_VNODE && td != NULL) {
 		int vfslocked;
 
 		vp = fp_object->f_vnode;
@@ -2150,7 +2133,7 @@ closef(struct file *fp, struct thread *t
 			lf.l_len = 0;
 			lf.l_type = F_UNLCK;
 			(void) VOP_ADVLOCK(vp, (caddr_t)td->td_proc->p_leader,
-					   F_UNLCK, &lf, F_POSIX);
+			    F_UNLCK, &lf, F_POSIX);
 		}
 		fdtol = td->td_proc->p_fdtol;
 		if (fdtol != NULL) {
@@ -2158,7 +2141,6 @@ closef(struct file *fp, struct thread *t
 			 * Handle special case where file descriptor table is
 			 * shared between multiple process leaders.
 			 */
-			fdp = td->td_proc->p_fd;
 			FILEDESC_XLOCK(fdp);
 			for (fdtol = fdtol->fdl_next;
 			     fdtol != td->td_proc->p_fdtol;
@@ -2174,8 +2156,8 @@ closef(struct file *fp, struct thread *t
 				lf.l_type = F_UNLCK;
 				vp = fp_object->f_vnode;
 				(void) VOP_ADVLOCK(vp,
-						   (caddr_t)fdtol->fdl_leader,
-						   F_UNLCK, &lf, F_POSIX);
+				    (caddr_t)fdtol->fdl_leader, F_UNLCK, &lf,
+				    F_POSIX);
 				FILEDESC_XLOCK(fdp);
 				fdtol->fdl_holdcount--;
 				if (fdtol->fdl_holdcount == 0 &&
@@ -2602,8 +2584,7 @@ dupfdopen(struct thread *td, struct file
 	 * closed, then reject.
 	 */
 	FILEDESC_XLOCK(fdp);
-	if (dfd < 0 || dfd >= fdp->fd_nfiles ||
-	    (fp = fdp->fd_ofiles[dfd]) == NULL) {
+	if ((fp = fget_locked(fdp, dfd)) == NULL) {
 		FILEDESC_XUNLOCK(fdp);
 		return (EBADF);
 	}

Modified: user/alc/superpages/sys/kern/kern_event.c
==============================================================================
--- user/alc/superpages/sys/kern/kern_event.c	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/kern/kern_event.c	Thu Jun 14 17:54:52 2012	(r237087)
@@ -692,7 +692,7 @@ sys_kqueue(struct thread *td, struct kqu
 	if (error)
 		goto done2;
 
-	/* An extra reference on `nfp' has been held for us by falloc(). */
+	/* An extra reference on `fp' has been held for us by falloc(). */
 	kq = malloc(sizeof *kq, M_KQUEUE, M_WAITOK | M_ZERO);
 	mtx_init(&kq->kq_lock, "kqueue", NULL, MTX_DEF|MTX_DUPOK);
 	TAILQ_INIT(&kq->kq_head);

Modified: user/alc/superpages/sys/sys/filedesc.h
==============================================================================
--- user/alc/superpages/sys/sys/filedesc.h	Thu Jun 14 17:47:54 2012	(r237086)
+++ user/alc/superpages/sys/sys/filedesc.h	Thu Jun 14 17:54:52 2012	(r237087)
@@ -105,6 +105,7 @@ struct filedesc_to_leader {
 					    SX_NOTRECURSED)
 #define	FILEDESC_XLOCK_ASSERT(fdp)	sx_assert(&(fdp)->fd_sx, SX_XLOCKED | \
 					    SX_NOTRECURSED)
+#define	FILEDESC_UNLOCK_ASSERT(fdp)	sx_assert(&(fdp)->fd_sx, SX_UNLOCKED)
 
 struct thread;
 
@@ -141,7 +142,12 @@ static __inline struct file *
 fget_locked(struct filedesc *fdp, int fd)
 {
 
-	return ((unsigned int)fd >= fdp->fd_nfiles ? NULL : fdp->fd_ofiles[fd]);
+	FILEDESC_LOCK_ASSERT(fdp);
+
+	if (fd < 0 || fd >= fdp->fd_nfiles)
+		return (NULL);
+
+	return (fdp->fd_ofiles[fd]);
 }
 
 #endif /* _KERNEL */


More information about the svn-src-user mailing list