Deleted Added
full compact
3c3
< * Copyright (c) 2016 The FreeBSD Foundation
---
> * Copyright (c) 2016, 2017 The FreeBSD Foundation
32c32
< __FBSDID("$FreeBSD: stable/11/lib/libc/x86/sys/__vdso_gettc.c 311376 2017-01-05 07:42:08Z sephe $");
---
> __FBSDID("$FreeBSD: stable/11/lib/libc/x86/sys/__vdso_gettc.c 311927 2017-01-11 11:25:18Z kib $");
44a45
> #include <machine/atomic.h>
49d49
< #include <machine/atomic.h>
118,119c118,119
< static char *hpet_dev_map = NULL;
< static uint32_t hpet_idx = 0xffffffff;
---
> #define HPET_DEV_MAP_MAX 10
> static volatile char *hpet_dev_map[HPET_DEV_MAP_MAX];
125a126,127
> volatile char *new_map, *old_map;
> uint32_t u1;
129c131
< u = hpet_idx;
---
> u1 = u;
131,133c133,135
< *c++ = u % 10 + '0';
< u /= 10;
< } while (u != 0);
---
> *c++ = u1 % 10 + '0';
> u1 /= 10;
> } while (u1 != 0);
139a142,146
>
> old_map = hpet_dev_map[u];
> if (old_map != NULL)
> return;
>
142c149,150
< hpet_dev_map = MAP_FAILED;
---
> atomic_cmpset_rel_ptr((volatile uintptr_t *)&hpet_dev_map[u],
> (uintptr_t)old_map, (uintptr_t)MAP_FAILED);
145,147c153
< if (hpet_dev_map != NULL && hpet_dev_map != MAP_FAILED)
< munmap(hpet_dev_map, PAGE_SIZE);
< hpet_dev_map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
---
> new_map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
148a155,158
> 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);
216c226,227
< uint32_t tmp;
---
> volatile char *map;
> uint32_t idx;
224,227c235,243
< tmp = th->th_x86_hpet_idx;
< if (hpet_dev_map == NULL || tmp != hpet_idx) {
< hpet_idx = tmp;
< __vdso_init_hpet(hpet_idx);
---
> idx = th->th_x86_hpet_idx;
> if (idx >= HPET_DEV_MAP_MAX)
> return (ENOSYS);
> map = (volatile char *)atomic_load_acq_ptr(
> (volatile uintptr_t *)&hpet_dev_map[idx]);
> if (map == NULL) {
> __vdso_init_hpet(idx);
> map = (volatile char *)atomic_load_acq_ptr(
> (volatile uintptr_t *)&hpet_dev_map[idx]);
229c245
< if (hpet_dev_map == MAP_FAILED)
---
> if (map == MAP_FAILED)
231c247
< *tc = *(volatile uint32_t *)(hpet_dev_map + HPET_MAIN_COUNTER);
---
> *tc = *(volatile uint32_t *)(map + HPET_MAIN_COUNTER);