summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/arch/aarch64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/aarch64/gen/usertc.c21
-rw-r--r--lib/libc/arch/alpha/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/alpha/gen/usertc.c21
-rw-r--r--lib/libc/arch/amd64/gen/Makefile.inc5
-rw-r--r--lib/libc/arch/amd64/gen/usertc.c41
-rw-r--r--lib/libc/arch/arm/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/arm/gen/usertc.c21
-rw-r--r--lib/libc/arch/hppa/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/hppa/gen/usertc.c21
-rw-r--r--lib/libc/arch/i386/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/i386/gen/usertc.c21
-rw-r--r--lib/libc/arch/m88k/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/m88k/gen/usertc.c21
-rw-r--r--lib/libc/arch/mips64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/mips64/gen/usertc.c21
-rw-r--r--lib/libc/arch/powerpc/gen/Makefile.inc2
-rw-r--r--lib/libc/arch/powerpc/gen/usertc.c21
-rw-r--r--lib/libc/arch/sh/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/sh/gen/usertc.c21
-rw-r--r--lib/libc/arch/sparc64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/sparc64/gen/usertc.c21
-rw-r--r--lib/libc/asr/asr.c8
-rw-r--r--lib/libc/crypt/bcrypt.c6
-rw-r--r--lib/libc/dlfcn/init.c14
-rw-r--r--lib/libc/gen/auth_subr.c6
-rw-r--r--lib/libc/gen/time.c4
-rw-r--r--lib/libc/gen/times.c4
-rw-r--r--lib/libc/gen/timespec_get.c4
-rw-r--r--lib/libc/hidden/sys/time.h4
-rw-r--r--lib/libc/hidden/sys/timetc.h38
-rw-r--r--lib/libc/hidden/time.h4
-rw-r--r--lib/libc/net/res_random.c6
-rw-r--r--lib/libc/rpc/auth_unix.c6
-rw-r--r--lib/libc/rpc/clnt_tcp.c6
-rw-r--r--lib/libc/rpc/clnt_udp.c6
-rw-r--r--lib/libc/rpc/svc_tcp.c6
-rw-r--r--lib/libc/sys/Makefile.inc12
-rw-r--r--lib/libc/sys/microtime.c138
-rw-r--r--lib/libc/sys/w_clock_gettime.c51
-rw-r--r--lib/libc/sys/w_gettimeofday.c40
-rw-r--r--lib/libc/thread/synch.h4
-rw-r--r--regress/lib/libc/timekeep/Makefile5
-rw-r--r--regress/lib/libc/timekeep/test_clock_gettime.c43
-rw-r--r--regress/lib/libc/timekeep/test_gettimeofday.c37
-rw-r--r--regress/lib/libc/timekeep/test_time_skew.c55
-rw-r--r--sys/arch/alpha/alpha/clock.c4
-rw-r--r--sys/arch/alpha/include/timetc.h23
-rw-r--r--sys/arch/amd64/amd64/tsc.c11
-rw-r--r--sys/arch/amd64/include/timetc.h24
-rw-r--r--sys/arch/amd64/isa/clock.c4
-rw-r--r--sys/arch/arm/cortex/amptimer.c4
-rw-r--r--sys/arch/arm/include/timetc.h23
-rw-r--r--sys/arch/arm64/dev/agtimer.c4
-rw-r--r--sys/arch/arm64/include/timetc.h23
-rw-r--r--sys/arch/armv7/include/timetc.h23
-rw-r--r--sys/arch/armv7/omap/gptimer.c4
-rw-r--r--sys/arch/armv7/sunxi/sxitimer.c4
-rw-r--r--sys/arch/hppa/dev/clock.c4
-rw-r--r--sys/arch/hppa/include/timetc.h23
-rw-r--r--sys/arch/i386/include/timetc.h23
-rw-r--r--sys/arch/i386/isa/clock.c4
-rw-r--r--sys/arch/i386/pci/geodesc.c6
-rw-r--r--sys/arch/i386/pci/gscpm.c6
-rw-r--r--sys/arch/i386/pci/ichpcib.c6
-rw-r--r--sys/arch/landisk/include/timetc.h23
-rw-r--r--sys/arch/loongson/include/timetc.h23
-rw-r--r--sys/arch/loongson/loongson/generic3a_machdep.c6
-rw-r--r--sys/arch/luna88k/include/timetc.h23
-rw-r--r--sys/arch/luna88k/luna88k/clock.c6
-rw-r--r--sys/arch/m88k/include/timetc.h23
-rw-r--r--sys/arch/macppc/include/timetc.h23
-rw-r--r--sys/arch/macppc/macppc/clock.c4
-rw-r--r--sys/arch/mips64/include/timetc.h23
-rw-r--r--sys/arch/mips64/mips64/mips64_machdep.c6
-rw-r--r--sys/arch/octeon/include/timetc.h23
-rw-r--r--sys/arch/octeon/octeon/machdep.c5
-rw-r--r--sys/arch/powerpc/include/timetc.h23
-rw-r--r--sys/arch/powerpc64/include/timetc.h23
-rw-r--r--sys/arch/sgi/include/timetc.h23
-rw-r--r--sys/arch/sgi/sgi/ip27_machdep.c6
-rw-r--r--sys/arch/sgi/xbow/xheart.c6
-rw-r--r--sys/arch/sh/include/timetc.h23
-rw-r--r--sys/arch/sparc64/dev/psycho.c4
-rw-r--r--sys/arch/sparc64/include/timetc.h23
-rw-r--r--sys/arch/sparc64/sparc64/clock.c6
-rw-r--r--sys/dev/acpi/acpihpet.c6
-rw-r--r--sys/dev/acpi/acpitimer.c6
-rw-r--r--sys/dev/pci/amdpm.c6
-rw-r--r--sys/dev/pci/viapm.c6
-rw-r--r--sys/dev/pv/hyperv.c2
-rw-r--r--sys/dev/pv/pvclock.c4
-rw-r--r--sys/kern/exec_elf.c8
-rw-r--r--sys/kern/kern_exec.c54
-rw-r--r--sys/kern/kern_tc.c34
-rw-r--r--sys/sys/exec_elf.h5
-rw-r--r--sys/sys/proc.h3
-rw-r--r--sys/sys/time.h10
-rw-r--r--sys/sys/timetc.h28
-rw-r--r--sys/uvm/uvm_unix.c5
100 files changed, 1393 insertions, 133 deletions
diff --git a/lib/libc/arch/aarch64/gen/Makefile.inc b/lib/libc/arch/aarch64/gen/Makefile.inc
index a7b1b73f3ef..c52c3400e45 100644
--- a/lib/libc/arch/aarch64/gen/Makefile.inc
+++ b/lib/libc/arch/aarch64/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.1 2017/01/11 18:09:24 patrick Exp $
+# $OpenBSD: Makefile.inc,v 1.2 2020/07/06 13:33:05 pirofti Exp $
# $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $
SRCS+= byte_swap_2.S byte_swap_4.S fabs.c flt_rounds.c infinity.c
@@ -9,4 +9,4 @@ SRCS+= fpgetmask.c fpgetround.c fpgetsticky.c
SRCS+= fpsetmask.c fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c
SRCS+= isfinitel.c isinfl.c isnanl.c isnormall.c
-SRCS+= signbitl.c
+SRCS+= signbitl.c usertc.c
diff --git a/lib/libc/arch/aarch64/gen/usertc.c b/lib/libc/arch/aarch64/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/aarch64/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/alpha/gen/Makefile.inc b/lib/libc/arch/alpha/gen/Makefile.inc
index a44599d2cab..aa851a7bf9c 100644
--- a/lib/libc/arch/alpha/gen/Makefile.inc
+++ b/lib/libc/arch/alpha/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.13 2012/04/12 16:14:09 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.14 2020/07/06 13:33:05 pirofti Exp $
# $NetBSD: Makefile.inc,v 1.3 1995/04/29 05:09:14 cgd Exp $
SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c setjmp.S
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
- fpsetround.c fpsetsticky.c
+ fpsetround.c fpsetsticky.c usertc.c
SRCS+= sigsetjmp.S
diff --git a/lib/libc/arch/alpha/gen/usertc.c b/lib/libc/arch/alpha/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/alpha/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/amd64/gen/Makefile.inc b/lib/libc/arch/amd64/gen/Makefile.inc
index e995309ed71..7dcd8bd9f79 100644
--- a/lib/libc/arch/amd64/gen/Makefile.inc
+++ b/lib/libc/arch/amd64/gen/Makefile.inc
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.12 2012/04/19 19:14:55 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.13 2020/07/06 13:33:05 pirofti Exp $
SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.S nan.c setjmp.S \
sigsetjmp.S
-SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
+SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c \
+ usertc.c
SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \
fpsetround.S fpsetsticky.S
diff --git a/lib/libc/arch/amd64/gen/usertc.c b/lib/libc/arch/amd64/gen/usertc.c
new file mode 100644
index 00000000000..ea920481841
--- /dev/null
+++ b/lib/libc/arch/amd64/gen/usertc.c
@@ -0,0 +1,41 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+static inline u_int
+rdtsc(void)
+{
+ uint32_t hi, lo;
+ asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
+ return ((uint64_t)lo)|(((uint64_t)hi)<<32);
+}
+
+int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ int tk_user = tk->tk_user;
+
+ if (tk_user < 1 || tk_user >= TC_LAST)
+ return -1;
+
+ *tc = rdtsc();
+ return 0;
+}
+int (*const _tc_get_timecount)(struct timekeep *tk, u_int *tc)
+ = tc_get_timecount;
diff --git a/lib/libc/arch/arm/gen/Makefile.inc b/lib/libc/arch/arm/gen/Makefile.inc
index 1b4ab2f3ae7..ae135f5885e 100644
--- a/lib/libc/arch/arm/gen/Makefile.inc
+++ b/lib/libc/arch/arm/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.15 2012/04/19 19:14:56 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.16 2020/07/06 13:33:05 pirofti Exp $
# $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $
SRCS+= byte_swap_2.S byte_swap_4.S divsi3.S fabs.c flt_rounds.c infinity.c
-SRCS+= ldexp.c modf.c nan.c
+SRCS+= ldexp.c modf.c nan.c usertc.c
SRCS+= setjmp.S _setjmp.S sigsetjmp.S
diff --git a/lib/libc/arch/arm/gen/usertc.c b/lib/libc/arch/arm/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/arm/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/hppa/gen/Makefile.inc b/lib/libc/arch/hppa/gen/Makefile.inc
index e0c864242fe..c7bb4182f89 100644
--- a/lib/libc/arch/hppa/gen/Makefile.inc
+++ b/lib/libc/arch/hppa/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.15 2016/04/28 19:53:20 kettenis Exp $
+# $OpenBSD: Makefile.inc,v 1.16 2020/07/06 13:33:05 pirofti Exp $
SRCS+= setjmp.S
SRCS+= fabs.c
-SRCS+= infinity.c ldexp.c modf.c nan.c
+SRCS+= infinity.c ldexp.c modf.c nan.c usertc.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
diff --git a/lib/libc/arch/hppa/gen/usertc.c b/lib/libc/arch/hppa/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/hppa/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/i386/gen/Makefile.inc b/lib/libc/arch/i386/gen/Makefile.inc
index 4c18e059581..30b5f8726c5 100644
--- a/lib/libc/arch/i386/gen/Makefile.inc
+++ b/lib/libc/arch/i386/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.14 2012/04/19 19:14:56 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.15 2020/07/06 13:33:05 pirofti Exp $
-SRCS+= _setjmp.S fabs.S infinity.c ldexp.c \
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c usertc.c \
modf.S nan.c setjmp.S sigsetjmp.S
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \
diff --git a/lib/libc/arch/i386/gen/usertc.c b/lib/libc/arch/i386/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/i386/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/m88k/gen/Makefile.inc b/lib/libc/arch/m88k/gen/Makefile.inc
index cff75b8d425..8ad1f858abd 100644
--- a/lib/libc/arch/m88k/gen/Makefile.inc
+++ b/lib/libc/arch/m88k/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.16 2013/06/05 22:06:30 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.17 2020/07/06 13:33:05 pirofti Exp $
# $NetBSD: Makefile.inc,v 1.3 1995/04/10 21:09:06 jtc Exp $
-SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c usertc.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= setjmp.S sigsetjmp.S
diff --git a/lib/libc/arch/m88k/gen/usertc.c b/lib/libc/arch/m88k/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/m88k/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/mips64/gen/Makefile.inc b/lib/libc/arch/mips64/gen/Makefile.inc
index 8cf1fc2d28a..f3f88957860 100644
--- a/lib/libc/arch/mips64/gen/Makefile.inc
+++ b/lib/libc/arch/mips64/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.12 2012/04/12 16:14:09 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.13 2020/07/06 13:33:05 pirofti Exp $
-SRCS+= _setjmp.S fabs.S infinity.c ldexp.S modf.S nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.S modf.S nan.c usertc.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/mips64/gen/usertc.c b/lib/libc/arch/mips64/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/mips64/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/powerpc/gen/Makefile.inc b/lib/libc/arch/powerpc/gen/Makefile.inc
index 6b2e4613ee8..d4d7b00bff7 100644
--- a/lib/libc/arch/powerpc/gen/Makefile.inc
+++ b/lib/libc/arch/powerpc/gen/Makefile.inc
@@ -1,5 +1,5 @@
SRCS+= infinity.c setjmp.S sigsetjmp.S flt_rounds.c ldexp.c modf.c nan.c
-SRCS+= fabs.c
+SRCS+= fabs.c usertc.c
SRCS+= fpgetmask.c fpsetmask.c
SRCS+= fpgetround.c fpsetround.c
SRCS+= fpgetsticky.c fpsetsticky.c
diff --git a/lib/libc/arch/powerpc/gen/usertc.c b/lib/libc/arch/powerpc/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/powerpc/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/sh/gen/Makefile.inc b/lib/libc/arch/sh/gen/Makefile.inc
index 55de1973b30..341480b4678 100644
--- a/lib/libc/arch/sh/gen/Makefile.inc
+++ b/lib/libc/arch/sh/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 22:28:33 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.11 2020/07/06 13:33:05 pirofti Exp $
SRCS+= flt_rounds.c infinity.c ldexp.c modf.c nan.c setjmp.S _setjmp.S
SRCS+= sigsetjmp.S
SRCS+= fabs.c fpgetmask.c fpgetround.c fpgetsticky.c \
- fpsetmask.c fpsetround.c fpsetsticky.c
+ fpsetmask.c fpsetround.c fpsetsticky.c usertc.c
diff --git a/lib/libc/arch/sh/gen/usertc.c b/lib/libc/arch/sh/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/sh/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/arch/sparc64/gen/Makefile.inc b/lib/libc/arch/sparc64/gen/Makefile.inc
index 58259cedef6..cbad435a89c 100644
--- a/lib/libc/arch/sparc64/gen/Makefile.inc
+++ b/lib/libc/arch/sparc64/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.14 2017/10/28 21:37:28 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.15 2020/07/06 13:33:05 pirofti Exp $
SRCS+= _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpclassifyl.c \
fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c infinity.c isfinitel.c \
- isinfl.c isnanl.c isnormall.c ldexp.c modf.S \
+ isinfl.c isnanl.c isnormall.c ldexp.c usertc.c modf.S \
mul.S nan.c setjmp.S signbitl.c sigsetjmp.S umul.S
diff --git a/lib/libc/arch/sparc64/gen/usertc.c b/lib/libc/arch/sparc64/gen/usertc.c
new file mode 100644
index 00000000000..f73831f742e
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/usertc.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/timetc.h>
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c
index 131da4b2190..8bc25fd82bd 100644
--- a/lib/libc/asr/asr.c
+++ b/lib/libc/asr/asr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.c,v 1.63 2020/06/07 16:16:01 deraadt Exp $ */
+/* $OpenBSD: asr.c,v 1.64 2020/07/06 13:33:05 pirofti Exp $ */
/*
* Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org>
*
@@ -198,11 +198,11 @@ poll_intrsafe(struct pollfd *fds, nfds_t nfds, int timeout)
struct timespec pollstart, pollend, elapsed;
int r;
- if (clock_gettime(CLOCK_MONOTONIC, &pollstart))
+ if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &pollstart))
return -1;
while ((r = poll(fds, 1, timeout)) == -1 && errno == EINTR) {
- if (clock_gettime(CLOCK_MONOTONIC, &pollend))
+ if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &pollend))
return -1;
timespecsub(&pollend, &pollstart, &elapsed);
timeout -= elapsed.tv_sec * 1000 + elapsed.tv_nsec / 1000000;
@@ -420,7 +420,7 @@ asr_check_reload(struct asr *asr)
asr->a_rtime = 0;
}
- if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
+ if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts) == -1)
return;
if ((ts.tv_sec - asr->a_rtime) < RELOAD_DELAY && asr->a_rtime != 0)
diff --git a/lib/libc/crypt/bcrypt.c b/lib/libc/crypt/bcrypt.c
index 82de8fa33b7..ba45b104eda 100644
--- a/lib/libc/crypt/bcrypt.c
+++ b/lib/libc/crypt/bcrypt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcrypt.c,v 1.57 2016/08/26 08:25:02 guenther Exp $ */
+/* $OpenBSD: bcrypt.c,v 1.58 2020/07/06 13:33:05 pirofti Exp $ */
/*
* Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
@@ -248,9 +248,9 @@ _bcrypt_autorounds(void)
char buf[_PASSWORD_LEN];
int duration;
- clock_gettime(CLOCK_THREAD_CPUTIME_ID, &before);
+ WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &before);
bcrypt_newhash("testpassword", r, buf, sizeof(buf));
- clock_gettime(CLOCK_THREAD_CPUTIME_ID, &after);
+ WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &after);
duration = after.tv_sec - before.tv_sec;
duration *= 1000000;
diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c
index 270f54aada5..3df61076dff 100644
--- a/lib/libc/dlfcn/init.c
+++ b/lib/libc/dlfcn/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.7 2019/06/02 01:03:01 guenther Exp $ */
+/* $OpenBSD: init.c,v 1.8 2020/07/06 13:33:05 pirofti Exp $ */
/*
* Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
*
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/syscall.h>
+#include <sys/timetc.h> /* timekeep */
#ifndef PIC
#include <sys/mman.h>
@@ -45,8 +46,9 @@
/* XXX should be in an include file shared with csu */
char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void));
-/* provide definition for this */
+/* provide definitions for these */
int _pagesize = 0;
+struct timekeep *_timekeep;
/*
* In dynamicly linked binaries environ and __progname are overriden by
@@ -105,6 +107,14 @@ _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb)
phnum = aux->au_v;
break;
#endif /* !PIC */
+ case AUX_openbsd_timekeep:
+ if (_tc_get_timecount) {
+ _timekeep = (void *)aux->au_v;
+ if (_timekeep &&
+ _timekeep->tk_version != TK_VERSION)
+ _timekeep = NULL;
+ }
+ break;
}
}
diff --git a/lib/libc/gen/auth_subr.c b/lib/libc/gen/auth_subr.c
index 1286a96fe40..11c6416a274 100644
--- a/lib/libc/gen/auth_subr.c
+++ b/lib/libc/gen/auth_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth_subr.c,v 1.54 2019/12/04 06:25:45 deraadt Exp $ */
+/* $OpenBSD: auth_subr.c,v 1.55 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2000-2002,2004 Todd C. Miller <millert@openbsd.org>
@@ -752,7 +752,7 @@ auth_check_expire(auth_session_t *as)
if (as->pwd && (quad_t)as->pwd->pw_expire != 0) {
if (as->now.tv_sec == 0)
- gettimeofday(&as->now, NULL);
+ WRAP(gettimeofday)(&as->now, NULL);
if ((quad_t)as->now.tv_sec >= (quad_t)as->pwd->pw_expire) {
as->state &= ~AUTH_ALLOW;
as->state |= AUTH_EXPIRED;
@@ -779,7 +779,7 @@ auth_check_change(auth_session_t *as)
if (as->pwd && (quad_t)as->pwd->pw_change) {
if (as->now.tv_sec == 0)
- gettimeofday(&as->now, NULL);
+ WRAP(gettimeofday)(&as->now, NULL);
if (as->now.tv_sec >= (quad_t)as->pwd->pw_change) {
as->state &= ~AUTH_ALLOW;
as->state |= AUTH_PWEXPIRED;
diff --git a/lib/libc/gen/time.c b/lib/libc/gen/time.c
index 3bbd0d733d1..7e24d60f6cb 100644
--- a/lib/libc/gen/time.c
+++ b/lib/libc/gen/time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.c,v 1.8 2019/06/28 13:32:41 deraadt Exp $ */
+/* $OpenBSD: time.c,v 1.9 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,7 +36,7 @@ time(time_t *t)
{
struct timeval tt;
- if (gettimeofday(&tt, NULL) == -1)
+ if (WRAP(gettimeofday)(&tt, NULL) == -1)
return (-1);
if (t)
*t = (time_t)tt.tv_sec;
diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c
index 02e4dd44b5c..012fc5274fc 100644
--- a/lib/libc/gen/times.c
+++ b/lib/libc/gen/times.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: times.c,v 1.9 2019/06/28 13:32:41 deraadt Exp $ */
+/* $OpenBSD: times.c,v 1.10 2020/07/06 13:33:06 pirofti Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -52,7 +52,7 @@ times(struct tms *tp)
return ((clock_t)-1);
tp->tms_cutime = CONVTCK(ru.ru_utime);
tp->tms_cstime = CONVTCK(ru.ru_stime);
- if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
+ if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts) == -1)
return ((clock_t)-1);
return (ts.tv_sec * CLK_TCK + ts.tv_nsec / (1000000000 / CLK_TCK));
}
diff --git a/lib/libc/gen/timespec_get.c b/lib/libc/gen/timespec_get.c
index 520a5954025..273e709e75f 100644
--- a/lib/libc/gen/timespec_get.c
+++ b/lib/libc/gen/timespec_get.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timespec_get.c,v 1.1 2018/10/30 16:28:42 guenther Exp $ */
+/* $OpenBSD: timespec_get.c,v 1.2 2020/07/06 13:33:06 pirofti Exp $ */
/* $NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $ */
/*-
@@ -37,7 +37,7 @@ timespec_get(struct timespec *ts, int base)
{
switch (base) {
case TIME_UTC:
- if (clock_gettime(CLOCK_REALTIME, ts) == -1)
+ if (WRAP(clock_gettime)(CLOCK_REALTIME, ts) == -1)
return 0;
break;
default:
diff --git a/lib/libc/hidden/sys/time.h b/lib/libc/hidden/sys/time.h
index ed112320fa2..66d3a6388be 100644
--- a/lib/libc/hidden/sys/time.h
+++ b/lib/libc/hidden/sys/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.1 2015/09/11 15:38:33 guenther Exp $ */
+/* $OpenBSD: time.h,v 1.2 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -24,7 +24,7 @@ PROTO_NORMAL(adjfreq);
PROTO_NORMAL(adjtime);
PROTO_NORMAL(futimes);
PROTO_NORMAL(getitimer);
-PROTO_NORMAL(gettimeofday);
+PROTO_WRAP(gettimeofday);
PROTO_NORMAL(setitimer);
PROTO_NORMAL(settimeofday);
PROTO_NORMAL(utimes);
diff --git a/lib/libc/hidden/sys/timetc.h b/lib/libc/hidden/sys/timetc.h
new file mode 100644
index 00000000000..1431002ea7f
--- /dev/null
+++ b/lib/libc/hidden/sys/timetc.h
@@ -0,0 +1,38 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LIBC_SYS_TIMETC_H_
+#define _LIBC_SYS_TIMETC_H_
+
+#define _LIBC
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include_next <sys/timetc.h>
+
+__BEGIN_HIDDEN_DECLS
+extern struct timekeep *_timekeep;
+
+extern int (*const _tc_get_timecount)(struct timekeep *, u_int *);
+
+int _microtime(struct timeval *, struct timekeep *);
+int _nanotime(struct timespec *, struct timekeep *);
+int _nanoruntime(struct timespec *, struct timekeep *);
+int _nanouptime(struct timespec *, struct timekeep *);
+__END_HIDDEN_DECLS
+
+#endif /* !_LIBC_SYS_TIMETC_H_ */
diff --git a/lib/libc/hidden/time.h b/lib/libc/hidden/time.h
index 18c49f8fcb9..facd898d932 100644
--- a/lib/libc/hidden/time.h
+++ b/lib/libc/hidden/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.6 2018/10/30 16:28:42 guenther Exp $ */
+/* $OpenBSD: time.h,v 1.7 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -29,7 +29,7 @@ PROTO_NORMAL(asctime_r);
PROTO_STD_DEPRECATED(clock);
PROTO_DEPRECATED(clock_getcpuclockid);
PROTO_NORMAL(clock_getres);
-PROTO_NORMAL(clock_gettime);
+PROTO_WRAP(clock_gettime);
PROTO_NORMAL(clock_settime);
PROTO_STD_DEPRECATED(ctime);
PROTO_DEPRECATED(ctime_r);
diff --git a/lib/libc/net/res_random.c b/lib/libc/net/res_random.c
index 763e420bb88..b7036815c9d 100644
--- a/lib/libc/net/res_random.c
+++ b/lib/libc/net/res_random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_random.c,v 1.24 2016/04/05 04:29:21 guenther Exp $ */
+/* $OpenBSD: res_random.c,v 1.25 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@@ -219,7 +219,7 @@ res_initid(void)
if (ru_prf != NULL)
arc4random_buf(ru_prf, sizeof(*ru_prf));
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts);
ru_reseed = ts.tv_sec + RU_OUT;
ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
}
@@ -232,7 +232,7 @@ __res_randomid(void)
u_int r;
static void *randomid_mutex;
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts);
pid = getpid();
_MUTEX_LOCK(&randomid_mutex);
diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c
index 402d98cede4..de2c14d246e 100644
--- a/lib/libc/rpc/auth_unix.c
+++ b/lib/libc/rpc/auth_unix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth_unix.c,v 1.27 2019/06/28 13:32:42 deraadt Exp $ */
+/* $OpenBSD: auth_unix.c,v 1.28 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -121,7 +121,7 @@ authunix_create(char *machname, int uid, int gid, int len, int *aup_gids)
/*
* fill in param struct from the given params
*/
- (void)gettimeofday(&now, NULL);
+ (void)WRAP(gettimeofday)(&now, NULL);
aup.aup_time = now.tv_sec;
aup.aup_machname = machname;
aup.aup_uid = uid;
@@ -274,7 +274,7 @@ authunix_refresh(AUTH *auth)
goto done;
/* update the time and serialize in place */
- (void)gettimeofday(&now, NULL);
+ (void)WRAP(gettimeofday)(&now, NULL);
aup.aup_time = now.tv_sec;
xdrs.x_op = XDR_ENCODE;
XDR_SETPOS(&xdrs, 0);
diff --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c
index 8e6ef515b0e..b9c3191f514 100644
--- a/lib/libc/rpc/clnt_tcp.c
+++ b/lib/libc/rpc/clnt_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clnt_tcp.c,v 1.33 2019/06/28 13:32:42 deraadt Exp $ */
+/* $OpenBSD: clnt_tcp.c,v 1.34 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -393,12 +393,12 @@ readtcp(struct ct_data *ct, caddr_t buf, int len)
pfd[0].events = POLLIN;
TIMEVAL_TO_TIMESPEC(&ct->ct_wait, &wait);
delta = wait;
- clock_gettime(CLOCK_MONOTONIC, &start);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &start);
for (;;) {
r = ppoll(pfd, 1, &delta, NULL);
save_errno = errno;
- clock_gettime(CLOCK_MONOTONIC, &after);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &after);
timespecsub(&start, &after, &duration);
timespecsub(&wait, &duration, &delta);
if (delta.tv_sec < 0 || !timespecisset(&delta))
diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c
index 68d01674410..196583423e7 100644
--- a/lib/libc/rpc/clnt_udp.c
+++ b/lib/libc/rpc/clnt_udp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clnt_udp.c,v 1.36 2019/06/28 13:32:42 deraadt Exp $ */
+/* $OpenBSD: clnt_udp.c,v 1.37 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -265,7 +265,7 @@ send_again:
reply_msg.acpted_rply.ar_results.where = resultsp;
reply_msg.acpted_rply.ar_results.proc = xresults;
- clock_gettime(CLOCK_MONOTONIC, &start);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &start);
for (;;) {
switch (ppoll(pfd, 1, &wait, NULL)) {
case 0:
@@ -283,7 +283,7 @@ send_again:
/* FALLTHROUGH */
case -1:
if (errno == EINTR) {
- clock_gettime(CLOCK_MONOTONIC, &after);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &after);
timespecsub(&after, &start, &duration);
timespecadd(&time_waited, &duration, &time_waited);
if (timespeccmp(&time_waited, &timeout, <))
diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c
index f9d7a70938f..d1501770e14 100644
--- a/lib/libc/rpc/svc_tcp.c
+++ b/lib/libc/rpc/svc_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svc_tcp.c,v 1.40 2019/06/28 13:32:42 deraadt Exp $ */
+/* $OpenBSD: svc_tcp.c,v 1.41 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -342,7 +342,7 @@ readtcp(SVCXPRT *xprt, caddr_t buf, int len)
* A timeout is fatal for the connection.
*/
delta = wait_per_try;
- clock_gettime(CLOCK_MONOTONIC, &start);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &start);
pfd[0].fd = sock;
pfd[0].events = POLLIN;
do {
@@ -351,7 +351,7 @@ readtcp(SVCXPRT *xprt, caddr_t buf, int len)
case -1:
if (errno != EINTR)
goto fatal_err;
- clock_gettime(CLOCK_MONOTONIC, &after);
+ WRAP(clock_gettime)(CLOCK_MONOTONIC, &after);
timespecsub(&after, &start, &duration);
timespecsub(&wait_per_try, &duration, &delta);
if (delta.tv_sec < 0 || !timespecisset(&delta))
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 34769576ced..44fce1a7981 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.158 2019/11/27 19:45:24 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.159 2020/07/06 13:33:06 pirofti Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@@ -12,7 +12,8 @@ SRCS+= Ovfork.S brk.S ${CERROR} \
# glue to offer userland wrappers for some syscalls
SRCS+= posix_madvise.c pthread_sigmask.c \
- w_fork.c w_sigaction.c w_sigprocmask.c w_sigsuspend.c w_vfork.c
+ w_fork.c w_sigaction.c w_sigprocmask.c w_sigsuspend.c w_vfork.c \
+ w_clock_gettime.c w_gettimeofday.c microtime.c
# glue for compat with old syscall interfaces.
SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \
@@ -43,7 +44,7 @@ SRCS+= ${CANCEL:%=w_%.c} w_pread.c w_preadv.c w_pwrite.c w_pwritev.c
ASM= __semctl.o __syscall.o __thrsigdivert.o \
access.o acct.o adjfreq.o adjtime.o \
bind.o chdir.o chflags.o chflagsat.o chmod.o chown.o chroot.o \
- clock_getres.o clock_gettime.o clock_settime.o \
+ clock_getres.o clock_settime.o \
dup.o dup2.o dup3.o \
execve.o \
faccessat.o fchdir.o fchflags.o fchmod.o fchmodat.o fchown.o \
@@ -54,7 +55,7 @@ ASM= __semctl.o __syscall.o __thrsigdivert.o \
getgroups.o getitimer.o getpeername.o getpgid.o \
getpriority.o getresgid.o getresuid.o \
getrlimit.o getrusage.o getsid.o getsockname.o \
- getsockopt.o gettimeofday.o ioctl.o \
+ getsockopt.o ioctl.o \
kevent.o kill.o kqueue.o ktrace.o lchown.o \
link.o linkat.o listen.o lstat.o madvise.o \
minherit.o mkdir.o mkdirat.o mkfifo.o mkfifoat.o \
@@ -109,7 +110,8 @@ PPSEUDO_NOERR=${PSEUDO_NOERR:.o=.po}
SPSEUDO_NOERR=${PSEUDO_NOERR:.o=.so}
DPSEUDO_NOERR=${PSEUDO_NOERR:.o=.do}
-HIDDEN= ___realpath.o ___getcwd.o fork.o sigaction.o _ptrace.o ${CANCEL:=.o}
+HIDDEN= ___realpath.o ___getcwd.o fork.o sigaction.o _ptrace.o ${CANCEL:=.o} \
+ clock_gettime.o gettimeofday.o
PHIDDEN=${HIDDEN:.o=.po}
SHIDDEN=${HIDDEN:.o=.so}
DHIDDEN=${HIDDEN:.o=.do}
diff --git a/lib/libc/sys/microtime.c b/lib/libc/sys/microtime.c
new file mode 100644
index 00000000000..e85a86a78de
--- /dev/null
+++ b/lib/libc/sys/microtime.c
@@ -0,0 +1,138 @@
+/* $OpenBSD: microtime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/atomic.h>
+#include <sys/timetc.h>
+
+#include <time.h>
+
+/*
+ * Return the difference between the timehands' counter value now and what
+ * was when we copied it to the timehands' offset_count.
+ */
+static inline int
+tc_delta(struct timekeep *tk, u_int *delta)
+{
+ u_int tc;
+
+ if (_tc_get_timecount(tk, &tc))
+ return -1;
+ *delta = (tc - tk->tk_offset_count) & tk->tk_counter_mask;
+ return 0;
+}
+
+static int
+binuptime(struct bintime *bt, struct timekeep *tk)
+{
+ u_int gen, delta;
+
+ do {
+ gen = tk->tk_generation;
+ membar_consumer();
+ *bt = tk->tk_offset;
+ if (tc_delta(tk, &delta))
+ return -1;
+ bintimeaddfrac(bt, tk->tk_scale * delta, bt);
+ membar_consumer();
+ } while (gen == 0 || gen != tk->tk_generation);
+
+ return 0;
+}
+
+static int
+binruntime(struct bintime *bt, struct timekeep *tk)
+{
+ u_int gen, delta;
+
+ do {
+ gen = tk->tk_generation;
+ membar_consumer();
+ if (tc_delta(tk, &delta))
+ return -1;
+ bintimeaddfrac(&tk->tk_offset, tk->tk_scale * delta, bt);
+ bintimesub(bt, &tk->tk_naptime, bt);
+ membar_consumer();
+ } while (gen == 0 || gen != tk->tk_generation);
+
+ return 0;
+}
+
+static int
+bintime(struct bintime *bt, struct timekeep *tk)
+{
+ u_int gen, delta;
+
+ do {
+ gen = tk->tk_generation;
+ membar_consumer();
+ *bt = tk->tk_offset;
+ if (tc_delta(tk, &delta))
+ return -1;
+ bintimeaddfrac(bt, tk->tk_scale * delta, bt);
+ bintimeadd(bt, &tk->tk_boottime, bt);
+ membar_consumer();
+ } while (gen == 0 || gen != tk->tk_generation);
+
+ return 0;
+}
+
+int
+_microtime(struct timeval *tvp, struct timekeep *tk)
+{
+ struct bintime bt;
+
+ if (bintime(&bt, tk))
+ return -1;
+ BINTIME_TO_TIMEVAL(&bt, tvp);
+ return 0;
+}
+
+int
+_nanotime(struct timespec *tsp, struct timekeep *tk)
+{
+ struct bintime bt;
+
+ if (bintime(&bt, tk))
+ return -1;
+ BINTIME_TO_TIMESPEC(&bt, tsp);
+ return 0;
+}
+
+int
+_nanoruntime(struct timespec *ts, struct timekeep *tk)
+{
+ struct bintime bt;
+
+ if (binruntime(&bt, tk))
+ return -1;
+ BINTIME_TO_TIMESPEC(&bt, ts);
+ return 0;
+}
+
+
+int
+_nanouptime(struct timespec *tsp, struct timekeep *tk)
+{
+ struct bintime bt;
+
+ if (binuptime(&bt, tk))
+ return -1;
+ BINTIME_TO_TIMESPEC(&bt, tsp);
+ return 0;
+}
diff --git a/lib/libc/sys/w_clock_gettime.c b/lib/libc/sys/w_clock_gettime.c
new file mode 100644
index 00000000000..ac21de31bf3
--- /dev/null
+++ b/lib/libc/sys/w_clock_gettime.c
@@ -0,0 +1,51 @@
+/* $OpenBSD: w_clock_gettime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/timetc.h>
+
+#include <time.h>
+
+int
+WRAP(clock_gettime)(clockid_t clock_id, struct timespec *tp)
+{
+ int rc = 0;
+ struct timekeep *timekeep = _timekeep;
+
+ if (timekeep == NULL || timekeep->tk_user == 0)
+ return clock_gettime(clock_id, tp);
+
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ rc = _nanotime(tp, timekeep);
+ break;
+ case CLOCK_UPTIME:
+ rc = _nanoruntime(tp, timekeep);
+ break;
+ case CLOCK_MONOTONIC:
+ case CLOCK_BOOTTIME:
+ rc = _nanouptime(tp, timekeep);
+ break;
+ default:
+ return clock_gettime(clock_id, tp);
+ }
+
+ if (rc)
+ return clock_gettime(clock_id, tp);
+
+ return 0;
+}
+DEF_WRAP(clock_gettime);
diff --git a/lib/libc/sys/w_gettimeofday.c b/lib/libc/sys/w_gettimeofday.c
new file mode 100644
index 00000000000..541a8f3cde8
--- /dev/null
+++ b/lib/libc/sys/w_gettimeofday.c
@@ -0,0 +1,40 @@
+/* $OpenBSD: w_gettimeofday.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Robert Nagy <robert@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/timetc.h>
+
+int
+WRAP(gettimeofday)(struct timeval *tp, struct timezone *tzp)
+{
+ int rc = 0;
+ struct timekeep *timekeep = _timekeep;
+ static struct timezone zerotz = { 0, 0 };
+
+ if (timekeep == NULL || timekeep->tk_user == 0)
+ return gettimeofday(tp, tzp);
+
+ if (tp)
+ rc = _microtime(tp, timekeep);
+ if (rc)
+ return gettimeofday(tp, tzp);
+
+ if (tzp)
+ *tzp = zerotz;
+
+ return 0;
+}
+DEF_WRAP(gettimeofday);
diff --git a/lib/libc/thread/synch.h b/lib/libc/thread/synch.h
index 788890add89..aaeb965956a 100644
--- a/lib/libc/thread/synch.h
+++ b/lib/libc/thread/synch.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: synch.h,v 1.4 2019/10/21 10:04:19 mpi Exp $ */
+/* $OpenBSD: synch.h,v 1.5 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot
*
@@ -33,7 +33,7 @@ _twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec *
if (abs == NULL)
return futex(p, FUTEX_WAIT_PRIVATE, val, NULL, NULL);
- if (abs->tv_nsec >= 1000000000 || clock_gettime(clockid, &rel))
+ if (abs->tv_nsec >= 1000000000 || WRAP(clock_gettime)(clockid, &rel))
return (EINVAL);
rel.tv_sec = abs->tv_sec - rel.tv_sec;
diff --git a/regress/lib/libc/timekeep/Makefile b/regress/lib/libc/timekeep/Makefile
new file mode 100644
index 00000000000..ed7dc60379d
--- /dev/null
+++ b/regress/lib/libc/timekeep/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2020/07/06 13:33:06 pirofti Exp $
+
+PROGS= test_clock_gettime test_time_skew test_gettimeofday
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/timekeep/test_clock_gettime.c b/regress/lib/libc/timekeep/test_clock_gettime.c
new file mode 100644
index 00000000000..cc1d8e36e39
--- /dev/null
+++ b/regress/lib/libc/timekeep/test_clock_gettime.c
@@ -0,0 +1,43 @@
+/* $OpenBSD: test_clock_gettime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <time.h>
+
+#define ASSERT_EQ(a, b) assert((a) == (b))
+
+void
+check()
+{
+ struct timespec tp = {0};
+
+ ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &tp));
+ ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp));
+ ASSERT_EQ(0, clock_gettime(CLOCK_BOOTTIME, &tp));
+ ASSERT_EQ(0, clock_gettime(CLOCK_UPTIME, &tp));
+
+
+ ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp));
+ ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp));
+
+}
+
+int main()
+{
+ check();
+ return 0;
+}
diff --git a/regress/lib/libc/timekeep/test_gettimeofday.c b/regress/lib/libc/timekeep/test_gettimeofday.c
new file mode 100644
index 00000000000..914058505dd
--- /dev/null
+++ b/regress/lib/libc/timekeep/test_gettimeofday.c
@@ -0,0 +1,37 @@
+/* $OpenBSD: test_gettimeofday.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <sys/time.h>
+
+#define ASSERT_EQ(a, b) assert((a) == (b))
+
+void
+check()
+{
+ struct timeval tv = {0};
+ struct timezone tzp;
+
+ ASSERT_EQ(0, gettimeofday(&tv, NULL));
+ ASSERT_EQ(0, gettimeofday(&tv, &tzp));
+}
+
+int main()
+{
+ check();
+ return 0;
+}
diff --git a/regress/lib/libc/timekeep/test_time_skew.c b/regress/lib/libc/timekeep/test_time_skew.c
new file mode 100644
index 00000000000..7871795f06b
--- /dev/null
+++ b/regress/lib/libc/timekeep/test_time_skew.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: test_time_skew.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/time.h>
+
+#include <assert.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define ASSERT_EQ(a, b) assert((a) == (b))
+#define ASSERT_NE(a, b) assert((a) != (b))
+
+void
+check()
+{
+ struct timespec tp1, tp2, tout;
+
+ tout.tv_sec = 0;
+ tout.tv_nsec = 100000;
+
+ ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp1));
+
+ nanosleep(&tout, NULL);
+
+ ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp2));
+
+ /* tp1 should never be larger than tp2 */
+ ASSERT_NE(1, timespeccmp(&tp1, &tp2, >));
+}
+
+int
+main(void)
+{
+ int i;
+
+ for (i = 0; i < 1000; i++)
+ check();
+
+ return 0;
+}
diff --git a/sys/arch/alpha/alpha/clock.c b/sys/arch/alpha/alpha/clock.c
index 3f5f2c5b42b..78caeef059f 100644
--- a/sys/arch/alpha/alpha/clock.c
+++ b/sys/arch/alpha/alpha/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.23 2020/05/11 19:42:53 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.24 2020/07/06 13:33:06 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.29 2000/06/05 21:47:10 thorpej Exp $ */
/*
@@ -64,7 +64,7 @@ int clk_irq = 0;
u_int rpcc_get_timecount(struct timecounter *);
struct timecounter rpcc_timecounter = {
- rpcc_get_timecount, NULL, ~0u, 0, "rpcc", 0, NULL
+ rpcc_get_timecount, NULL, ~0u, 0, "rpcc", 0, NULL, 0
};
extern todr_chip_handle_t todr_handle;
diff --git a/sys/arch/alpha/include/timetc.h b/sys/arch/alpha/include/timetc.h
new file mode 100644
index 00000000000..62eca133a80
--- /dev/null
+++ b/sys/arch/alpha/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/amd64/amd64/tsc.c b/sys/arch/amd64/amd64/tsc.c
index e16c1ddbeb3..e7c4b539daa 100644
--- a/sys/arch/amd64/amd64/tsc.c
+++ b/sys/arch/amd64/amd64/tsc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tsc.c,v 1.18 2020/07/03 17:54:27 kettenis Exp $ */
+/* $OpenBSD: tsc.c,v 1.19 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* Copyright (c) 2016,2017 Reyk Floeter <reyk@openbsd.org>
@@ -37,6 +37,7 @@ uint64_t tsc_frequency;
int tsc_is_invariant;
#define TSC_DRIFT_MAX 250
+#define TSC_SKEW_MAX 100
int64_t tsc_drift_observed;
volatile int64_t tsc_sync_val;
@@ -50,7 +51,7 @@ extern u_int32_t lapic_per_second;
#endif
struct timecounter tsc_timecounter = {
- tsc_get_timecount, NULL, ~0u, 0, "tsc", -1000, NULL
+ tsc_get_timecount, NULL, ~0u, 0, "tsc", -1000, NULL, TC_TSC
};
uint64_t
@@ -220,6 +221,11 @@ tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
printf("%s: TSC skew=%lld observed drift=%lld\n", ci->ci_dev->dv_xname,
(long long)ci->ci_tsc_skew, (long long)tsc_drift_observed);
#endif
+ if (ci->ci_tsc_skew < -TSC_SKEW_MAX || ci->ci_tsc_skew > TSC_SKEW_MAX) {
+ printf("%s: disabling user TSC (skew=%lld)\n",
+ ci->ci_dev->dv_xname, (long long)ci->ci_tsc_skew);
+ tsc_timecounter.tc_user = 0;
+ }
if (!(ci->ci_flags & CPUF_PRIMARY) ||
!(ci->ci_flags & CPUF_CONST_TSC) ||
@@ -244,6 +250,7 @@ tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
printf("ERROR: %lld cycle TSC drift observed\n",
(long long)tsc_drift_observed);
tsc_timecounter.tc_quality = -1000;
+ tsc_timecounter.tc_user = 0;
tsc_is_invariant = 0;
}
diff --git a/sys/arch/amd64/include/timetc.h b/sys/arch/amd64/include/timetc.h
new file mode 100644
index 00000000000..273e809116a
--- /dev/null
+++ b/sys/arch/amd64/include/timetc.h
@@ -0,0 +1,24 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_TSC 1
+#define TC_LAST 2
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/amd64/isa/clock.c b/sys/arch/amd64/isa/clock.c
index 613f7ee0e0f..cc0b38b69c1 100644
--- a/sys/arch/amd64/isa/clock.c
+++ b/sys/arch/amd64/isa/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.33 2020/05/02 10:44:48 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.34 2020/07/06 13:33:06 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.1 2003/04/26 18:39:50 fvdl Exp $ */
/*-
@@ -116,7 +116,7 @@ u_int i8254_get_timecount(struct timecounter *tc);
u_int i8254_simple_get_timecount(struct timecounter *tc);
static struct timecounter i8254_timecounter = {
- i8254_get_timecount, NULL, ~0u, TIMER_FREQ, "i8254", 0, NULL
+ i8254_get_timecount, NULL, ~0u, TIMER_FREQ, "i8254", 0, NULL, 0
};
int clockintr(void *);
diff --git a/sys/arch/arm/cortex/amptimer.c b/sys/arch/arm/cortex/amptimer.c
index b4825d59da9..2f013d1c3e0 100644
--- a/sys/arch/arm/cortex/amptimer.c
+++ b/sys/arch/arm/cortex/amptimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: amptimer.c,v 1.6 2018/07/09 09:51:43 patrick Exp $ */
+/* $OpenBSD: amptimer.c,v 1.7 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
*
@@ -67,7 +67,7 @@ int32_t amptimer_frequency = TIMER_FREQUENCY;
u_int amptimer_get_timecount(struct timecounter *);
static struct timecounter amptimer_timecounter = {
- amptimer_get_timecount, NULL, 0x7fffffff, 0, "amptimer", 0, NULL
+ amptimer_get_timecount, NULL, 0x7fffffff, 0, "amptimer", 0, NULL, 0
};
#define MAX_ARM_CPUS 8
diff --git a/sys/arch/arm/include/timetc.h b/sys/arch/arm/include/timetc.h
new file mode 100644
index 00000000000..62eca133a80
--- /dev/null
+++ b/sys/arch/arm/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c
index 11196b5c60d..fe9606a3733 100644
--- a/sys/arch/arm64/dev/agtimer.c
+++ b/sys/arch/arm64/dev/agtimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: agtimer.c,v 1.12 2020/06/05 22:14:25 kettenis Exp $ */
+/* $OpenBSD: agtimer.c,v 1.13 2020/07/06 13:33:06 pirofti Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
@@ -43,7 +43,7 @@ int32_t agtimer_frequency = TIMER_FREQUENCY;
u_int agtimer_get_timecount(struct timecounter *);
static struct timecounter agtimer_timecounter = {
- agtimer_get_timecount, NULL, 0x7fffffff, 0, "agtimer", 0, NULL
+ agtimer_get_timecount, NULL, 0x7fffffff, 0, "agtimer", 0, NULL, 0
};
struct agtimer_pcpu_softc {
diff --git a/sys/arch/arm64/include/timetc.h b/sys/arch/arm64/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/arm64/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/armv7/include/timetc.h b/sys/arch/armv7/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/armv7/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/armv7/omap/gptimer.c b/sys/arch/armv7/omap/gptimer.c
index 7605845d5e2..97f9dc0ba0b 100644
--- a/sys/arch/armv7/omap/gptimer.c
+++ b/sys/arch/armv7/omap/gptimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gptimer.c,v 1.7 2019/05/06 03:45:58 mlarkin Exp $ */
+/* $OpenBSD: gptimer.c,v 1.8 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
*
@@ -117,7 +117,7 @@ int gptimer_irq = 0;
u_int gptimer_get_timecount(struct timecounter *);
static struct timecounter gptimer_timecounter = {
- gptimer_get_timecount, NULL, 0x7fffffff, 0, "gptimer", 0, NULL
+ gptimer_get_timecount, NULL, 0x7fffffff, 0, "gptimer", 0, NULL, 0
};
volatile u_int32_t nexttickevent;
diff --git a/sys/arch/armv7/sunxi/sxitimer.c b/sys/arch/armv7/sunxi/sxitimer.c
index 14a243c78d0..24c6b551a7c 100644
--- a/sys/arch/armv7/sunxi/sxitimer.c
+++ b/sys/arch/armv7/sunxi/sxitimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sxitimer.c,v 1.13 2019/05/06 03:49:53 mlarkin Exp $ */
+/* $OpenBSD: sxitimer.c,v 1.14 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2013 Raphael Graf <r@undefined.ch>
@@ -89,7 +89,7 @@ void sxitimer_delay(u_int);
u_int sxitimer_get_timecount(struct timecounter *);
static struct timecounter sxitimer_timecounter = {
- sxitimer_get_timecount, NULL, 0xffffffff, 0, "sxitimer", 0, NULL
+ sxitimer_get_timecount, NULL, 0xffffffff, 0, "sxitimer", 0, NULL, 0
};
bus_space_tag_t sxitimer_iot;
diff --git a/sys/arch/hppa/dev/clock.c b/sys/arch/hppa/dev/clock.c
index 4c594ab5ec7..ac99711224e 100644
--- a/sys/arch/hppa/dev/clock.c
+++ b/sys/arch/hppa/dev/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.30 2020/05/01 19:56:11 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.31 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 1998-2003 Michael Shalayeff
@@ -47,7 +47,7 @@ int cpu_hardclock(void *);
u_int itmr_get_timecount(struct timecounter *);
struct timecounter itmr_timecounter = {
- itmr_get_timecount, NULL, 0xffffffff, 0, "itmr", 0, NULL
+ itmr_get_timecount, NULL, 0xffffffff, 0, "itmr", 0, NULL, 0
};
extern todr_chip_handle_t todr_handle;
diff --git a/sys/arch/hppa/include/timetc.h b/sys/arch/hppa/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/hppa/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/i386/include/timetc.h b/sys/arch/i386/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/i386/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/i386/isa/clock.c b/sys/arch/i386/isa/clock.c
index 09a6db983f2..3ff97aace48 100644
--- a/sys/arch/i386/isa/clock.c
+++ b/sys/arch/i386/isa/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.58 2020/05/02 10:44:49 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.59 2020/07/06 13:33:07 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.39 1996/05/12 23:11:54 mycroft Exp $ */
/*-
@@ -129,7 +129,7 @@ u_int i8254_get_timecount(struct timecounter *tc);
u_int i8254_simple_get_timecount(struct timecounter *tc);
static struct timecounter i8254_timecounter = {
- i8254_get_timecount, NULL, ~0u, TIMER_FREQ, "i8254", 0, NULL
+ i8254_get_timecount, NULL, ~0u, TIMER_FREQ, "i8254", 0, NULL, 0
};
struct mutex timer_mutex = MUTEX_INITIALIZER(IPL_HIGH);
u_long rtclock_tval;
diff --git a/sys/arch/i386/pci/geodesc.c b/sys/arch/i386/pci/geodesc.c
index 9d9f061eef9..3e804e05a93 100644
--- a/sys/arch/i386/pci/geodesc.c
+++ b/sys/arch/i386/pci/geodesc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: geodesc.c,v 1.14 2020/01/05 01:07:58 jsg Exp $ */
+/* $OpenBSD: geodesc.c,v 1.15 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
@@ -65,7 +65,9 @@ struct timecounter geodesc_timecounter = {
0xffffffff, /* counter_mask */
27000000, /* frequency */
"GEOTSC", /* name */
- 2000 /* quality */
+ 2000, /* quality */
+ NULL, /* private bits */
+ 0 /* expose to user */
};
int
diff --git a/sys/arch/i386/pci/gscpm.c b/sys/arch/i386/pci/gscpm.c
index 8b8aa4ac430..84c67c64764 100644
--- a/sys/arch/i386/pci/gscpm.c
+++ b/sys/arch/i386/pci/gscpm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gscpm.c,v 1.9 2012/08/16 18:42:04 tedu Exp $ */
+/* $OpenBSD: gscpm.c,v 1.10 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
*
@@ -55,7 +55,9 @@ struct timecounter gscpm_timecounter = {
0xffffff, /* counter_mask */
3579545, /* frequency */
"GSCPM", /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0 /* expose to user */
};
struct cfattach gscpm_ca = {
diff --git a/sys/arch/i386/pci/ichpcib.c b/sys/arch/i386/pci/ichpcib.c
index 6abf1627de2..3ece43ecc56 100644
--- a/sys/arch/i386/pci/ichpcib.c
+++ b/sys/arch/i386/pci/ichpcib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ichpcib.c,v 1.28 2014/09/14 14:17:23 jsg Exp $ */
+/* $OpenBSD: ichpcib.c,v 1.29 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
*
@@ -63,7 +63,9 @@ struct timecounter ichpcib_timecounter = {
0xffffff, /* counter_mask */
3579545, /* frequency */
"ICHPM", /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0 /* expose to user */
};
struct cfattach ichpcib_ca = {
diff --git a/sys/arch/landisk/include/timetc.h b/sys/arch/landisk/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/landisk/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/loongson/include/timetc.h b/sys/arch/loongson/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/loongson/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/loongson/loongson/generic3a_machdep.c b/sys/arch/loongson/loongson/generic3a_machdep.c
index ac3f1db6ccd..ae9f7d1b79e 100644
--- a/sys/arch/loongson/loongson/generic3a_machdep.c
+++ b/sys/arch/loongson/loongson/generic3a_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: generic3a_machdep.c,v 1.8 2017/05/21 13:00:53 visa Exp $ */
+/* $OpenBSD: generic3a_machdep.c,v 1.9 2020/07/06 13:33:07 pirofti Exp $ */
/*
* Copyright (c) 2009, 2010, 2012 Miodrag Vallat.
@@ -98,7 +98,9 @@ struct timecounter rs780e_timecounter = {
.tc_counter_mask = 0xffffffffu, /* truncated to 32 bits */
.tc_frequency = HPET_FREQ,
.tc_name = "hpet",
- .tc_quality = 100
+ .tc_quality = 100,
+ .tc_priv = NULL,
+ .tc_user = 0,
};
/* Firmware entry points */
diff --git a/sys/arch/luna88k/include/timetc.h b/sys/arch/luna88k/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/luna88k/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/luna88k/luna88k/clock.c b/sys/arch/luna88k/luna88k/clock.c
index a04120987e0..97138a03097 100644
--- a/sys/arch/luna88k/luna88k/clock.c
+++ b/sys/arch/luna88k/luna88k/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.14 2020/05/12 15:13:18 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.15 2020/07/06 13:33:07 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.2 2000/01/11 10:29:35 nisimura Exp $ */
/*
@@ -112,7 +112,9 @@ struct timecounter clock_tc = {
.tc_counter_mask = 0xffffffff,
.tc_frequency = 0, /* will be filled in */
.tc_name = "clock",
- .tc_quality = 0
+ .tc_quality = 0,
+ .tc_priv = NULL,
+ .tc_user = 0,
};
/*
diff --git a/sys/arch/m88k/include/timetc.h b/sys/arch/m88k/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/m88k/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/macppc/include/timetc.h b/sys/arch/macppc/include/timetc.h
new file mode 100644
index 00000000000..be5be950d4d
--- /dev/null
+++ b/sys/arch/macppc/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/macppc/macppc/clock.c b/sys/arch/macppc/macppc/clock.c
index 4a44a92cfc0..33b12f29eda 100644
--- a/sys/arch/macppc/macppc/clock.c
+++ b/sys/arch/macppc/macppc/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.43 2020/05/01 20:00:26 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.44 2020/07/06 13:33:08 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.1 1996/09/30 16:34:40 ws Exp $ */
/*
@@ -57,7 +57,7 @@ u_int32_t ns_per_tick = 320;
static int32_t ticks_per_intr;
static struct timecounter tb_timecounter = {
- tb_get_timecount, NULL, 0x7fffffff, 0, "tb", 0, NULL
+ tb_get_timecount, NULL, 0x7fffffff, 0, "tb", 0, NULL, 0
};
/* calibrate the timecounter frequency for the listed models */
diff --git a/sys/arch/mips64/include/timetc.h b/sys/arch/mips64/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/mips64/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/mips64/mips64/mips64_machdep.c b/sys/arch/mips64/mips64/mips64_machdep.c
index 2657f9e8ae1..8509c3331e2 100644
--- a/sys/arch/mips64/mips64/mips64_machdep.c
+++ b/sys/arch/mips64/mips64/mips64_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mips64_machdep.c,v 1.31 2020/06/30 14:56:10 visa Exp $ */
+/* $OpenBSD: mips64_machdep.c,v 1.32 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2009, 2010, 2012 Miodrag Vallat.
@@ -273,7 +273,9 @@ struct timecounter cp0_timecounter = {
0xffffffff, /* counter_mask */
0, /* frequency */
"CP0", /* name */
- 0 /* quality */
+ 0, /* quality */
+ NULL, /* private bits */
+ 0, /* expose to user */
};
u_int
diff --git a/sys/arch/octeon/include/timetc.h b/sys/arch/octeon/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/octeon/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/octeon/octeon/machdep.c b/sys/arch/octeon/octeon/machdep.c
index 902e462d53f..d1ce2fbf84b 100644
--- a/sys/arch/octeon/octeon/machdep.c
+++ b/sys/arch/octeon/octeon/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.124 2020/06/05 13:35:21 visa Exp $ */
+/* $OpenBSD: machdep.c,v 1.125 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2009, 2010 Miodrag Vallat.
@@ -151,8 +151,9 @@ struct timecounter ioclock_timecounter = {
.tc_name = "ioclock",
.tc_quality = 0, /* ioclock can be overridden
* by cp0 counter */
- .tc_priv = 0 /* clock register,
+ .tc_priv = 0, /* clock register,
* determined at runtime */
+ .tc_user = 0, /* expose to user */
};
static int
diff --git a/sys/arch/powerpc/include/timetc.h b/sys/arch/powerpc/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/powerpc/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/powerpc64/include/timetc.h b/sys/arch/powerpc64/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/powerpc64/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/sgi/include/timetc.h b/sys/arch/sgi/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/sgi/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/sgi/sgi/ip27_machdep.c b/sys/arch/sgi/sgi/ip27_machdep.c
index ba7fa558b96..93997886918 100644
--- a/sys/arch/sgi/sgi/ip27_machdep.c
+++ b/sys/arch/sgi/sgi/ip27_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip27_machdep.c,v 1.80 2019/12/20 13:29:23 visa Exp $ */
+/* $OpenBSD: ip27_machdep.c,v 1.81 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2008, 2009 Miodrag Vallat.
@@ -111,7 +111,9 @@ struct timecounter ip27_hub_timecounter = {
.tc_counter_mask = 0xffffffff, /* truncated to 32 bits. */
.tc_frequency = 1250000,
.tc_name = "hubrt",
- .tc_quality = 100
+ .tc_quality = 100,
+ .tc_priv = 0,
+ .tc_user = 0,
};
volatile uint64_t ip27_spinup_a0;
diff --git a/sys/arch/sgi/xbow/xheart.c b/sys/arch/sgi/xbow/xheart.c
index 56b29915c70..be5a244a5ae 100644
--- a/sys/arch/sgi/xbow/xheart.c
+++ b/sys/arch/sgi/xbow/xheart.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xheart.c,v 1.32 2018/02/24 11:42:31 visa Exp $ */
+/* $OpenBSD: xheart.c,v 1.33 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2008 Miodrag Vallat.
@@ -83,7 +83,9 @@ struct timecounter xheart_timecounter = {
.tc_counter_mask = 0xffffffff, /* truncate 52-bit counter to 32-bit */
.tc_frequency = 12500000,
.tc_name = "heart",
- .tc_quality = 100
+ .tc_quality = 100,
+ .tc_priv = NULL,
+ .tc_user = 0,
};
extern uint32_t ip30_lights_frob(uint32_t, struct trapframe *);
diff --git a/sys/arch/sh/include/timetc.h b/sys/arch/sh/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/sh/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/sparc64/dev/psycho.c b/sys/arch/sparc64/dev/psycho.c
index e24f804dff6..ce8d9a7bb9f 100644
--- a/sys/arch/sparc64/dev/psycho.c
+++ b/sys/arch/sparc64/dev/psycho.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: psycho.c,v 1.76 2019/06/25 22:30:56 dlg Exp $ */
+/* $OpenBSD: psycho.c,v 1.77 2020/07/06 13:33:08 pirofti Exp $ */
/* $NetBSD: psycho.c,v 1.39 2001/10/07 20:30:41 eeh Exp $ */
/*
@@ -127,7 +127,7 @@ extern struct sparc_pci_chipset _sparc_pci_chipset;
u_int stick_get_timecount(struct timecounter *);
struct timecounter stick_timecounter = {
- stick_get_timecount, NULL, ~0u, 0, "stick", 1000, NULL
+ stick_get_timecount, NULL, ~0u, 0, "stick", 1000, NULL, 0
};
/*
diff --git a/sys/arch/sparc64/include/timetc.h b/sys/arch/sparc64/include/timetc.h
new file mode 100644
index 00000000000..ec63af16d18
--- /dev/null
+++ b/sys/arch/sparc64/include/timetc.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */
+/*
+ * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TIMETC_H_
+#define _MACHINE_TIMETC_H_
+
+#define TC_LAST 0
+
+#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/sparc64/sparc64/clock.c b/sys/arch/sparc64/sparc64/clock.c
index fd5e8a9c15b..fa3ff46718c 100644
--- a/sys/arch/sparc64/sparc64/clock.c
+++ b/sys/arch/sparc64/sparc64/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.61 2020/05/17 08:48:15 visa Exp $ */
+/* $OpenBSD: clock.c,v 1.62 2020/07/06 13:33:08 pirofti Exp $ */
/* $NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp $ */
/*
@@ -109,13 +109,13 @@ struct cfdriver clock_cd = {
u_int tick_get_timecount(struct timecounter *);
struct timecounter tick_timecounter = {
- tick_get_timecount, NULL, ~0u, 0, "tick", 0, NULL
+ tick_get_timecount, NULL, ~0u, 0, "tick", 0, NULL, 0
};
u_int sys_tick_get_timecount(struct timecounter *);
struct timecounter sys_tick_timecounter = {
- sys_tick_get_timecount, NULL, ~0u, 0, "sys_tick", 1000, NULL
+ sys_tick_get_timecount, NULL, ~0u, 0, "sys_tick", 1000, NULL, 0
};
/*
diff --git a/sys/dev/acpi/acpihpet.c b/sys/dev/acpi/acpihpet.c
index d0ee72cec9b..9dc4908eaaf 100644
--- a/sys/dev/acpi/acpihpet.c
+++ b/sys/dev/acpi/acpihpet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpihpet.c,v 1.23 2018/06/29 17:39:18 kettenis Exp $ */
+/* $OpenBSD: acpihpet.c,v 1.24 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
*
@@ -45,7 +45,9 @@ static struct timecounter hpet_timecounter = {
0xffffffff, /* counter_mask (32 bits) */
0, /* frequency */
0, /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0, /* expose to user */
};
#define HPET_TIMERS 3
diff --git a/sys/dev/acpi/acpitimer.c b/sys/dev/acpi/acpitimer.c
index cdc8c99a17a..8885ab43a71 100644
--- a/sys/dev/acpi/acpitimer.c
+++ b/sys/dev/acpi/acpitimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpitimer.c,v 1.12 2017/10/06 13:33:53 mikeb Exp $ */
+/* $OpenBSD: acpitimer.c,v 1.13 2020/07/06 13:33:08 pirofti Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
*
@@ -36,7 +36,9 @@ static struct timecounter acpi_timecounter = {
0x00ffffff, /* counter_mask (24 bits) */
ACPI_FREQUENCY, /* frequency */
0, /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0, /* expose to user */
};
struct acpitimer_softc {
diff --git a/sys/dev/pci/amdpm.c b/sys/dev/pci/amdpm.c
index 6df82858016..73659d477d4 100644
--- a/sys/dev/pci/amdpm.c
+++ b/sys/dev/pci/amdpm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: amdpm.c,v 1.35 2020/05/29 04:42:25 deraadt Exp $ */
+/* $OpenBSD: amdpm.c,v 1.36 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
@@ -82,7 +82,9 @@ static struct timecounter amdpm_timecounter = {
0xffffff, /* counter_mask */
AMDPM_FREQUENCY, /* frequency */
"AMDPM", /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0, /* expose to user */
};
#define AMDPM_CONFREG 0x40
diff --git a/sys/dev/pci/viapm.c b/sys/dev/pci/viapm.c
index db806eedf80..ee7e93f9f05 100644
--- a/sys/dev/pci/viapm.c
+++ b/sys/dev/pci/viapm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: viapm.c,v 1.18 2020/01/09 14:35:19 mpi Exp $ */
+/* $OpenBSD: viapm.c,v 1.19 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 2005 Mark Kettenis <kettenis@openbsd.org>
@@ -177,7 +177,9 @@ static struct timecounter viapm_timecounter = {
0xffffff, /* counter_mask */
VIAPM_FREQUENCY, /* frequency */
"VIAPM", /* name */
- 1000 /* quality */
+ 1000, /* quality */
+ NULL, /* private bits */
+ 0, /* expose to user */
};
struct timeout viapm_timeout;
diff --git a/sys/dev/pv/hyperv.c b/sys/dev/pv/hyperv.c
index b32facdacb1..b9ee2feec4c 100644
--- a/sys/dev/pv/hyperv.c
+++ b/sys/dev/pv/hyperv.c
@@ -141,7 +141,7 @@ struct {
};
struct timecounter hv_timecounter = {
- hv_gettime, 0, 0xffffffff, 10000000, "hyperv", 9001
+ hv_gettime, 0, 0xffffffff, 10000000, "hyperv", 9001, NULL, 0
};
struct cfdriver hyperv_cd = {
diff --git a/sys/dev/pv/pvclock.c b/sys/dev/pv/pvclock.c
index 6b242f7448d..cf72aecedcc 100644
--- a/sys/dev/pv/pvclock.c
+++ b/sys/dev/pv/pvclock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pvclock.c,v 1.5 2019/12/13 06:43:46 pd Exp $ */
+/* $OpenBSD: pvclock.c,v 1.6 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 2018 Reyk Floeter <reyk@openbsd.org>
@@ -74,7 +74,7 @@ struct cfdriver pvclock_cd = {
};
struct timecounter pvclock_timecounter = {
- pvclock_get_timecount, NULL, ~0u, 0, NULL, -2000, NULL
+ pvclock_get_timecount, NULL, ~0u, 0, NULL, -2000, NULL, 0
};
int
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index 9b5b8eb3acf..5e455208663 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.c,v 1.154 2020/01/25 01:28:38 deraadt Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.155 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
@@ -124,7 +124,7 @@ extern char *syscallnames[];
/*
* How many entries are in the AuxInfo array we pass to the process?
*/
-#define ELF_AUX_ENTRIES 8
+#define ELF_AUX_ENTRIES 9
/*
* This is the OpenBSD ELF emul
@@ -860,6 +860,10 @@ exec_elf_fixup(struct proc *p, struct exec_package *epp)
a->au_v = ap->arg_entry;
a++;
+ a->au_id = AUX_openbsd_timekeep;
+ a->au_v = p->p_p->ps_timekeep;
+ a++;
+
a->au_id = AUX_null;
a->au_v = 0;
a++;
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 20480c2fc28..863686de932 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.213 2020/02/15 09:35:48 anton Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.214 2020/07/06 13:33:09 pirofti Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -64,6 +64,11 @@
#include <uvm/uvm_extern.h>
#include <machine/tcb.h>
+#include <sys/timetc.h>
+
+struct uvm_object *timekeep_object;
+struct timekeep* timekeep;
+
void unveil_destroy(struct process *ps);
const struct kmem_va_mode kv_exec = {
@@ -77,6 +82,11 @@ const struct kmem_va_mode kv_exec = {
int exec_sigcode_map(struct process *, struct emul *);
/*
+ * Map the shared timekeep page.
+ */
+int exec_timekeep_map(struct process *);
+
+/*
* If non-zero, stackgap_random specifies the upper limit of the random gap size
* added to the fixed stack position. Must be n^2.
*/
@@ -670,6 +680,10 @@ sys_execve(struct proc *p, void *v, register_t *retval)
*/
KNOTE(&pr->ps_klist, NOTE_EXEC);
+ /* map the process's timekeep page, needs to be before e_fixup */
+ if (exec_timekeep_map(pr))
+ goto free_pack_abort;
+
/* setup new registers and do misc. setup. */
if (pack.ep_emul->e_fixup != NULL) {
if ((*pack.ep_emul->e_fixup)(p, &pack) != 0)
@@ -863,3 +877,41 @@ exec_sigcode_map(struct process *pr, struct emul *e)
return (0);
}
+
+int
+exec_timekeep_map(struct process *pr)
+{
+ size_t timekeep_sz = sizeof(struct timekeep);
+
+ /*
+ * Similar to the sigcode object, except that there is a single
+ * timekeep object, and not one per emulation.
+ */
+ if (timekeep_object == NULL) {
+ vaddr_t va = 0;
+
+ timekeep_object = uao_create(timekeep_sz, 0);
+ uao_reference(timekeep_object);
+
+ if (uvm_map(kernel_map, &va, round_page(timekeep_sz), timekeep_object,
+ 0, 0, UVM_MAPFLAG(PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
+ MAP_INHERIT_SHARE, MADV_RANDOM, 0))) {
+ uao_detach(timekeep_object);
+ return (ENOMEM);
+ }
+
+ timekeep = (struct timekeep *)va;
+ timekeep->tk_version = TK_VERSION;
+ }
+
+ pr->ps_timekeep = 0; /* no hint */
+ uao_reference(timekeep_object);
+ if (uvm_map(&pr->ps_vmspace->vm_map, &pr->ps_timekeep, round_page(timekeep_sz),
+ timekeep_object, 0, 0, UVM_MAPFLAG(PROT_READ, PROT_READ,
+ MAP_INHERIT_COPY, MADV_RANDOM, 0))) {
+ uao_detach(timekeep_object);
+ return (ENOMEM);
+ }
+
+ return (0);
+}
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index c3c0ee07fbb..a46502c9784 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_tc.c,v 1.61 2020/07/04 08:06:07 anton Exp $ */
+/* $OpenBSD: kern_tc.c,v 1.62 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@@ -63,7 +63,7 @@ dummy_get_timecount(struct timecounter *tc)
}
static struct timecounter dummy_timecounter = {
- dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000
+ dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000, NULL, 0
};
/*
@@ -527,6 +527,34 @@ tc_setclock(const struct timespec *ts)
#endif
}
+void
+tc_update_timekeep(void)
+{
+ static struct timecounter *last_tc = NULL;
+ struct timehands *th;
+
+ if (timekeep == NULL)
+ return;
+
+ th = timehands;
+ timekeep->tk_generation = 0;
+ membar_producer();
+ timekeep->tk_scale = th->th_scale;
+ timekeep->tk_offset_count = th->th_offset_count;
+ timekeep->tk_offset = th->th_offset;
+ timekeep->tk_naptime = th->th_naptime;
+ timekeep->tk_boottime = th->th_boottime;
+ if (last_tc != th->th_counter) {
+ timekeep->tk_counter_mask = th->th_counter->tc_counter_mask;
+ timekeep->tk_user = th->th_counter->tc_user;
+ last_tc = th->th_counter;
+ }
+ membar_producer();
+ timekeep->tk_generation = th->th_generation;
+
+ return;
+}
+
/*
* Initialize the next struct timehands in the ring and make
* it the active timehands. Along the way we might switch to a different
@@ -679,6 +707,8 @@ tc_windup(struct bintime *new_boottime, struct bintime *new_offset,
time_uptime = th->th_offset.sec;
membar_producer();
timehands = th;
+
+ tc_update_timekeep();
}
/* Report or change the active timecounter hardware. */
diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h
index a40e0510273..9a1dec64cbd 100644
--- a/sys/sys/exec_elf.h
+++ b/sys/sys/exec_elf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.h,v 1.87 2019/12/01 13:10:51 jsg Exp $ */
+/* $OpenBSD: exec_elf.h,v 1.88 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 1995, 1996 Erik Theisen. All rights reserved.
*
@@ -691,7 +691,8 @@ enum AuxID {
AUX_sun_uid = 2000, /* euid */
AUX_sun_ruid = 2001, /* ruid */
AUX_sun_gid = 2002, /* egid */
- AUX_sun_rgid = 2003 /* rgid */
+ AUX_sun_rgid = 2003, /* rgid */
+ AUX_openbsd_timekeep = 4000, /* userland clock_gettime */
};
struct elf_args {
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index c146332a6e0..835cd614440 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.296 2020/07/04 08:06:08 anton Exp $ */
+/* $OpenBSD: proc.h,v 1.297 2020/07/06 13:33:09 pirofti Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -242,6 +242,7 @@ struct process {
char ps_comm[MAXCOMLEN+1];
vaddr_t ps_strings; /* User pointers to argv/env */
+ vaddr_t ps_timekeep; /* User pointer to timekeep */
vaddr_t ps_sigcode; /* User pointer to the signal code */
vaddr_t ps_sigcoderet; /* User pointer to sigreturn retPC */
u_long ps_sigcookie;
diff --git a/sys/sys/time.h b/sys/sys/time.h
index 32d3dd10364..69e58e9c4c9 100644
--- a/sys/sys/time.h
+++ b/sys/sys/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.54 2020/06/26 18:48:31 cheloha Exp $ */
+/* $OpenBSD: time.h,v 1.55 2020/07/06 13:33:09 pirofti Exp $ */
/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
/*
@@ -163,7 +163,7 @@ struct clockinfo {
};
#endif /* __BSD_VISIBLE */
-#if defined(_KERNEL) || defined(_STANDALONE)
+#if defined(_KERNEL) || defined(_STANDALONE) || defined (_LIBC)
#include <sys/_time.h>
/* Time expressed as seconds and fractions of a second + operations on it. */
@@ -171,6 +171,9 @@ struct bintime {
time_t sec;
uint64_t frac;
};
+#endif
+
+#if defined(_KERNEL) || defined(_STANDALONE) || defined (_LIBC)
#define bintimecmp(btp, ctp, cmp) \
((btp)->sec == (ctp)->sec ? \
@@ -249,6 +252,9 @@ TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt)
/* 18446744073709 = int(2^64 / 1000000) */
bt->frac = (uint64_t)tv->tv_usec * (uint64_t)18446744073709ULL;
}
+#endif
+
+#if defined(_KERNEL) || defined(_STANDALONE)
/*
* Functions for looking at our clocks: [get]{bin,nano,micro}[boot|up]time()
diff --git a/sys/sys/timetc.h b/sys/sys/timetc.h
index 82796616c65..dccee1364bd 100644
--- a/sys/sys/timetc.h
+++ b/sys/sys/timetc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timetc.h,v 1.11 2020/07/04 08:06:08 anton Exp $ */
+/* $OpenBSD: timetc.h,v 1.12 2020/07/06 13:33:09 pirofti Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@@ -24,10 +24,11 @@
#ifndef _SYS_TIMETC_H_
#define _SYS_TIMETC_H_
-#ifndef _KERNEL
+#if !defined(_KERNEL) && !defined(_LIBC)
#error "no user-serviceable parts inside"
#endif
+#include <machine/timetc.h>
#include <sys/queue.h>
/*-
@@ -80,6 +81,8 @@ struct timecounter {
*/
void *tc_priv; /* [I] */
/* Pointer to the timecounter's private parts. */
+ int tc_user; /* [I] */
+ /* Expose this timecounter to userland. */
SLIST_ENTRY(timecounter) tc_next; /* [I] */
/* Pointer to the next timecounter. */
int64_t tc_freq_adj; /* [T,W] */
@@ -88,11 +91,32 @@ struct timecounter {
/* Precision of the counter. Computed in tc_init(). */
};
+struct timekeep {
+ /* set at initialization */
+ uint32_t tk_version; /* version number */
+
+ /* timehands members */
+ uint64_t tk_scale;
+ u_int tk_offset_count;
+ struct bintime tk_offset;
+ struct bintime tk_naptime;
+ struct bintime tk_boottime;
+ volatile u_int tk_generation;
+
+ /* timecounter members */
+ int tk_user;
+ u_int tk_counter_mask;
+};
+#define TK_VERSION 0
+
struct rwlock;
extern struct rwlock tc_lock;
extern struct timecounter *timecounter;
+extern struct uvm_object *timekeep_object;
+extern struct timekeep *timekeep;
+
u_int64_t tc_getfrequency(void);
u_int64_t tc_getprecision(void);
void tc_init(struct timecounter *tc);
diff --git a/sys/uvm/uvm_unix.c b/sys/uvm/uvm_unix.c
index 88bfaf8be69..fb77142e2b9 100644
--- a/sys/uvm/uvm_unix.c
+++ b/sys/uvm/uvm_unix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_unix.c,v 1.67 2019/11/05 08:18:47 mpi Exp $ */
+/* $OpenBSD: uvm_unix.c,v 1.68 2020/07/06 13:33:09 pirofti Exp $ */
/* $NetBSD: uvm_unix.c,v 1.18 2000/09/13 15:00:25 thorpej Exp $ */
/*
@@ -214,7 +214,8 @@ uvm_should_coredump(struct proc *p, struct vm_map_entry *entry)
{
if (!(entry->protection & PROT_WRITE) &&
entry->aref.ar_amap == NULL &&
- entry->start != p->p_p->ps_sigcode)
+ entry->start != p->p_p->ps_sigcode &&
+ entry->start != p->p_p->ps_timekeep)
return 0;
/*