mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 18:00:17 +02:00
This is an interesting vdso implementation because it only exists in x86-64 with kernel v6.11. For Arm64 the implementation is likely to land in a couple kernel versions from now. Some differences with vdso_getrandom versus the regular getrandom syscall - Has two additional arguments, opaque_state and opaque_len - Expects the userspace to mmap/munmap this opaque state structure - Lets userspace query information about this structure upfront - If the opaque data structure isn't provided then it falls back to regular SYS_getrandom With the "glibc" implementation, we can tell the interface to allocate a single page that gets unused (otherwise glibc ends up not using the interface), and fallback to the regular SYS_getrandom. In the case of the vdso interface, currently the arguments just get passed through. Keeping this as a WIP until the ARM64 kernel patches land and I can actually test the things. Running the "glibc" path works today with the selftest, but the vdso path is currently completely untested.
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
|
|
/*
|
|
$info$
|
|
tags: thunklibs|VDSO
|
|
desc: Linux VDSO thunking
|
|
$end_info$
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <cstring>
|
|
|
|
#include <sched.h>
|
|
#include <sys/time.h>
|
|
#include <time.h>
|
|
|
|
#include "Types.h"
|
|
#include "common/Guest.h"
|
|
|
|
#include "thunkgen_guest_libVDSO.inl"
|
|
|
|
extern "C" {
|
|
time_t __vdso_time(time_t* tloc) __attribute__((alias("fexfn_pack_time")));
|
|
int __vdso_gettimeofday(struct timeval* tv, struct timezone* tz) __attribute__((alias("fexfn_pack_gettimeofday")));
|
|
int __vdso_clock_gettime(clockid_t, struct timespec*) __attribute__((alias("fexfn_pack_clock_gettime")));
|
|
int __vdso_clock_getres(clockid_t, struct timespec*) __attribute__((alias("fexfn_pack_clock_getres")));
|
|
int __vdso_getcpu(uint32_t*, uint32_t*) __attribute__((alias("fexfn_pack_getcpu")));
|
|
|
|
#if __SIZEOF_POINTER__ == 4
|
|
int __vdso_clock_gettime64(clockid_t, struct timespec64*) __attribute__((alias("fexfn_pack_clock_gettime64")));
|
|
|
|
__attribute__((naked)) int __kernel_vsyscall() {
|
|
asm volatile(R"(
|
|
.intel_syntax noprefix
|
|
int 0x80;
|
|
ret;
|
|
.att_syntax prefix
|
|
)" ::
|
|
: "memory");
|
|
}
|
|
|
|
__attribute__((naked)) void __kernel_sigreturn() {
|
|
asm volatile(R"(
|
|
.intel_syntax noprefix
|
|
pop eax;
|
|
mov eax, 0x77;
|
|
int 0x80;
|
|
nop;
|
|
.att_syntax prefix
|
|
)" ::
|
|
: "memory");
|
|
}
|
|
__attribute__((naked)) void __kernel_rt_sigreturn() {
|
|
asm volatile(R"(
|
|
.intel_syntax noprefix
|
|
mov eax, 0xad;
|
|
int 0x80;
|
|
.att_syntax prefix
|
|
)" ::
|
|
: "memory");
|
|
}
|
|
#else
|
|
ssize_t __vdso_getrandom(void*, size_t, uint32_t, void*, size_t) __attribute__((alias("fexfn_pack_getrandom")));
|
|
#endif
|
|
}
|