Path: blob/main/sys/amd64/linux32/linux32_vdso_gtod.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Dmitry Chagin <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <sys/elf.h>28#include <sys/errno.h>29#include <sys/proc.h>30#include <sys/stdarg.h>31#include <sys/stddef.h>32#define _KERNEL33#include <sys/vdso.h>34#undef _KERNEL35#include <stdbool.h>3637#include <i386/include/atomic.h>38#include <i386/include/cpufunc.h>3940#include <amd64/linux32/linux.h>41#include <amd64/linux32/linux32_syscall.h>42#include <compat/linux/linux_errno.h>43#include <compat/linux/linux_time.h>4445/* The kernel fixup this at vDSO install */46uintptr_t *kern_timekeep_base = NULL;47uint32_t kern_tsc_selector = 0;48uint32_t kern_cpu_selector = 0;4950#include <x86/linux/linux_vdso_gettc_x86.inc>51#include <x86/linux/linux_vdso_getcpu_x86.inc>5253static int54write(int fd, const void *buf, size_t size)55{56int res;5758__asm__ __volatile__59(60"int $0x80"61: "=a"(res)62: "a"(LINUX32_SYS_linux_write), "b"(fd), "c"(buf), "d"(size)63: "cc", "memory"64);65return (res);66}6768static int69__vdso_clock_gettime_fallback(clockid_t clock_id, struct l_timespec *ts)70{71int res;7273__asm__ __volatile__74(75"int $0x80"76: "=a"(res)77: "a"(LINUX32_SYS_linux_clock_gettime), "b"(clock_id), "c"(ts)78: "cc", "memory"79);80return (res);81}8283static int84__vdso_clock_gettime64_fallback(clockid_t clock_id, struct l_timespec64 *ts)85{86int res;8788__asm__ __volatile__89(90"int $0x80"91: "=a"(res)92: "a"(LINUX32_SYS_linux_clock_gettime64), "b"(clock_id), "c"(ts)93: "cc", "memory"94);95return (res);96}9798static int99__vdso_gettimeofday_fallback(l_timeval *tv, struct timezone *tz)100{101int res;102103__asm__ __volatile__104(105"int $0x80"106: "=a"(res)107: "a"(LINUX32_SYS_linux_gettimeofday), "b"(tv), "c"(tz)108: "cc", "memory"109);110return (res);111}112113static int114__vdso_clock_getres_fallback(clockid_t clock_id, struct l_timespec *ts)115{116int res;117118__asm__ __volatile__119(120"int $0x80"121: "=a"(res)122: "a"(LINUX32_SYS_linux_clock_getres), "b"(clock_id), "c"(ts)123: "cc", "memory"124);125return (res);126}127128static int129__vdso_getcpu_fallback(uint32_t *cpu, uint32_t *node, void *cache)130{131int res;132133__asm__ __volatile__134(135"int $0x80"136: "=a"(res)137: "a"(LINUX32_SYS_linux_getcpu), "D"(cpu), "S"(node), "d"(cache)138: "cc", "memory"139);140return (res);141}142143static int144__vdso_time_fallback(long *tm)145{146int res;147148__asm__ __volatile__149(150"int $0x80"151: "=a"(res)152: "a"(LINUX32_SYS_linux_time), "b"(tm)153: "cc", "memory"154);155return (res);156}157158#include <compat/linux/linux_vdso_gtod.inc>159160161