From owner-svn-src-stable@freebsd.org Fri Jul 28 10:31:00 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8351CDC28F6; Fri, 28 Jul 2017 10:31:00 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5F41B7FDD4; Fri, 28 Jul 2017 10:31:00 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6SAUx86009432; Fri, 28 Jul 2017 10:30:59 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6SAUx01009431; Fri, 28 Jul 2017 10:30:59 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201707281030.v6SAUx01009431@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 28 Jul 2017 10:30:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r321650 - stable/11/lib/libc/x86/sys X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/lib/libc/x86/sys X-SVN-Commit-Revision: 321650 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jul 2017 10:31:00 -0000 Author: kib Date: Fri Jul 28 10:30:59 2017 New Revision: 321650 URL: https://svnweb.freebsd.org/changeset/base/321650 Log: MFC r314319 (by oshogbo): Don't try to open devices in the gettc() function which will always fail in the Capability mode. Instead silently fallback to the syscall method, which is done for example in the gettimeofday(2) function. MFC r314320 (by oshogbo): Remove unneeded variable initialization from r314319. MFC r321461: Fix indent. Modified: stable/11/lib/libc/x86/sys/__vdso_gettc.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/x86/sys/__vdso_gettc.c ============================================================================== --- stable/11/lib/libc/x86/sys/__vdso_gettc.c Fri Jul 28 04:41:57 2017 (r321649) +++ stable/11/lib/libc/x86/sys/__vdso_gettc.c Fri Jul 28 10:30:59 2017 (r321650) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include "namespace.h" +#include #include #include #include @@ -124,6 +125,7 @@ __vdso_init_hpet(uint32_t u) static const char devprefix[] = "/dev/hpet"; char devname[64], *c, *c1, t; volatile char *new_map, *old_map; + unsigned int mode; uint32_t u1; int fd; @@ -144,18 +146,25 @@ __vdso_init_hpet(uint32_t u) if (old_map != NULL) return; + if (cap_getmode(&mode) == 0 && mode != 0) + goto fail; + fd = _open(devname, O_RDONLY); - if (fd == -1) { - atomic_cmpset_rel_ptr((volatile uintptr_t *)&hpet_dev_map[u], - (uintptr_t)old_map, (uintptr_t)MAP_FAILED); - return; - } + if (fd == -1) + goto fail; + new_map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0); _close(fd); if (atomic_cmpset_rel_ptr((volatile uintptr_t *)&hpet_dev_map[u], (uintptr_t)old_map, (uintptr_t)new_map) == 0 && new_map != MAP_FAILED) munmap((void *)new_map, PAGE_SIZE); + + return; +fail: + /* Prevent the caller from re-entering. */ + atomic_cmpset_rel_ptr((volatile uintptr_t *)&hpet_dev_map[u], + (uintptr_t)old_map, (uintptr_t)MAP_FAILED); } #ifdef WANT_HYPERV @@ -174,16 +183,22 @@ static void __vdso_init_hyperv_tsc(void) { int fd; + unsigned int mode; + if (cap_getmode(&mode) == 0 && mode != 0) + goto fail; + fd = _open(HYPERV_REFTSC_DEVPATH, O_RDONLY); - if (fd < 0) { - /* Prevent the caller from re-entering. */ - hyperv_ref_tsc = MAP_FAILED; - return; - } + if (fd < 0) + goto fail; hyperv_ref_tsc = mmap(NULL, sizeof(*hyperv_ref_tsc), PROT_READ, MAP_SHARED, fd, 0); _close(fd); + + return; +fail: + /* Prevent the caller from re-entering. */ + hyperv_ref_tsc = MAP_FAILED; } static int