inline_asm: add missing "memory" constraints

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-06-25 09:00:08 +00:00
parent fef0b24025
commit 3eca3b8124
3 changed files with 33 additions and 6 deletions

View File

@@ -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. */

View File

@@ -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();

View File

@@ -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();