aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libc/x86/sys/__vdso_gettc.c
diff options
context:
space:
mode:
authorMariusz Zaborski <oshogbo@FreeBSD.org>2017-02-26 22:07:26 +0000
committerMariusz Zaborski <oshogbo@FreeBSD.org>2017-02-26 22:07:26 +0000
commitba1b6636562e9c3fc6183aab6f7a4e95d9aa7f92 (patch)
tree504f4017bc4618a56cba72cdd4abe7aab0e964f2 /lib/libc/x86/sys/__vdso_gettc.c
parent43ad57d358f110d1f4752744a39dfc06fad010a9 (diff)
downloadsrc-ba1b6636562e9c3fc6183aab6f7a4e95d9aa7f92.tar.gz
src-ba1b6636562e9c3fc6183aab6f7a4e95d9aa7f92.zip
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. Reviewed by: kib
Notes
Notes: svn path=/head/; revision=314319
Diffstat (limited to 'lib/libc/x86/sys/__vdso_gettc.c')
-rw-r--r--lib/libc/x86/sys/__vdso_gettc.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/lib/libc/x86/sys/__vdso_gettc.c b/lib/libc/x86/sys/__vdso_gettc.c
index bf46a10e48b7..4977d153da20 100644
--- a/lib/libc/x86/sys/__vdso_gettc.c
+++ b/lib/libc/x86/sys/__vdso_gettc.c
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include "namespace.h"
+#include <sys/capsicum.h>
#include <sys/elf.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
@@ -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,26 @@ __vdso_init_hpet(uint32_t u)
if (old_map != NULL)
return;
+ mode = 0;
+ 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);
+ 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 +184,23 @@ static void
__vdso_init_hyperv_tsc(void)
{
int fd;
+ unsigned int mode;
+
+ mode = 0;
+ 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