mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
inline_asm: add missing "memory" constraints
This commit is contained in:
@@ -31,7 +31,11 @@ void __attribute__ ((noinline)) busy_loop(
|
|||||||
|
|
||||||
void* thread_main(void *arg) {
|
void* thread_main(void *arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
__asm__ __volatile__ ("ldxr x0, [%0]" : : "r" (&ldxr_var) : "x0");
|
__asm__ __volatile__ (
|
||||||
|
"ldxr x0, [%0]"
|
||||||
|
:
|
||||||
|
: "r" (&ldxr_var) : "x0", "memory"
|
||||||
|
);
|
||||||
ldxr_done = 1;
|
ldxr_done = 1;
|
||||||
lkmc_futex(&futex1, FUTEX_WAIT, futex1, NULL, NULL, 0);
|
lkmc_futex(&futex1, FUTEX_WAIT, futex1, NULL, NULL, 0);
|
||||||
lkmc_futex(&futex2, FUTEX_WAIT, futex2, NULL, NULL, 0);
|
lkmc_futex(&futex2, FUTEX_WAIT, futex2, NULL, NULL, 0);
|
||||||
@@ -45,7 +49,11 @@ int main(void) {
|
|||||||
/* Wait for thread1 to sleep on futex1. */
|
/* Wait for thread1 to sleep on futex1. */
|
||||||
busy_loop(1000, 1);
|
busy_loop(1000, 1);
|
||||||
/* Wrongly wake up the thread with a SEV. */
|
/* Wrongly wake up the thread with a SEV. */
|
||||||
__asm__ __volatile__ ("mov x0, 1;ldxr x0, [%0]; stxr w1, x0, [%0]" : : "r" (&ldxr_var) : "x0", "x1");
|
__asm__ __volatile__ (
|
||||||
|
"mov x0, 1;ldxr x0, [%0]; stxr w1, x0, [%0]"
|
||||||
|
:
|
||||||
|
: "r" (&ldxr_var) : "x0", "x1", "memory"
|
||||||
|
);
|
||||||
/* Wait for thread1 to sleep on futex2. */
|
/* Wait for thread1 to sleep on futex2. */
|
||||||
busy_loop(1000, 1);
|
busy_loop(1000, 1);
|
||||||
/* Wrongly wake thread from futex1 again. */
|
/* Wrongly wake thread from futex1 again. */
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ std::atomic_ulong done;
|
|||||||
int futex = 1;
|
int futex = 1;
|
||||||
|
|
||||||
void myfunc() {
|
void myfunc() {
|
||||||
__asm__ __volatile__ ("sevl;wfe;ldxr x0, [%0];wfe" : : "r" (&futex) : "x0");
|
__asm__ __volatile__ (
|
||||||
|
"sevl;wfe;ldxr x0, [%0];wfe"
|
||||||
|
:
|
||||||
|
: "r" (&futex)
|
||||||
|
: "x0", "memory"
|
||||||
|
);
|
||||||
done.store(futex);
|
done.store(futex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +32,12 @@ int main(int argc, char **argv) {
|
|||||||
thread = std::thread(myfunc);
|
thread = std::thread(myfunc);
|
||||||
while (!done.load()) {
|
while (!done.load()) {
|
||||||
if (do_sev) {
|
if (do_sev) {
|
||||||
__asm__ __volatile__ ("mov x0, 1;str x0, [%0]" : : "r" (&futex) : "x0");
|
__asm__ __volatile__ (
|
||||||
|
"mov x0, 1;str x0, [%0]"
|
||||||
|
:
|
||||||
|
: "r" (&futex)
|
||||||
|
: "x0", "memory"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ std::atomic_ulong done;
|
|||||||
int futex = 1;
|
int futex = 1;
|
||||||
|
|
||||||
void myfunc() {
|
void myfunc() {
|
||||||
__asm__ __volatile__ ("sevl;wfe;ldxr x0, [%0];wfe" : : "r" (&futex) : "x0");
|
__asm__ __volatile__ (
|
||||||
|
"sevl;wfe;ldxr x0, [%0];wfe"
|
||||||
|
:
|
||||||
|
: "r" (&futex) : "x0", "memory"
|
||||||
|
);
|
||||||
done.store(futex);
|
done.store(futex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +30,12 @@ int main(int argc, char **argv) {
|
|||||||
thread = std::thread(myfunc);
|
thread = std::thread(myfunc);
|
||||||
while (!done.load()) {
|
while (!done.load()) {
|
||||||
if (do_sev) {
|
if (do_sev) {
|
||||||
__asm__ __volatile__ ("ldxr x0, [%0];mov x0, 1;stxr w1, x0, [%0]" : : "r" (&futex) : "x0", "x1");
|
__asm__ __volatile__ (
|
||||||
|
"ldxr x0, [%0];mov x0, 1;stxr w1, x0, [%0]"
|
||||||
|
:
|
||||||
|
: "r" (&futex)
|
||||||
|
: "x0", "x1", "memory"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|||||||
Reference in New Issue
Block a user