Files
linux-kernel-module-cheat/userland/arch/aarch64/inline_asm/wfe_ldxr_str.cpp
Ciro Santilli 六四事件 法轮功 09cbc26819 wfe ldxr minor improvements
2020-06-25 03:00:02 +00:00

35 lines
747 B
C++

// https://cirosantilli.com/linux-kernel-module-cheat#arm-wfe-global-monitor-events
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <atomic>
#include <iostream>
#include <thread>
#include <lkmc/futex.h>
std::atomic_ulong done;
int futex = 1;
void myfunc() {
__asm__ __volatile__ ("sevl;wfe;ldxr x0, [%0];wfe" : : "r" (&futex) : "x0");
done.store(futex);
}
int main(int argc, char **argv) {
bool do_sev = true;
if (argc > 1) {
do_sev = (argv[1][0] != '0');
}
done.store(0);
std::thread thread;
thread = std::thread(myfunc);
while (!done.load()) {
if (do_sev) {
__asm__ __volatile__ ("mov x0, 1;str x0, [%0]" : : "r" (&futex) : "x0");
}
}
thread.join();
}