mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-29 13:04:27 +01:00
gcc hacks: busy_loop and prevent_reorder
This commit is contained in:
29
userland/gcc/busy_loop.c
Normal file
29
userland/gcc/busy_loop.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#compilers */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void __attribute__ ((noinline)) busy_loop(
|
||||
unsigned long long max,
|
||||
unsigned long long max2
|
||||
) {
|
||||
for (unsigned i = 0; i < max; i++) {
|
||||
for (unsigned j = 0; j < max2; j++) {
|
||||
__asm__ __volatile__ ("" : "+g" (j), "+g" (j) : :);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned long long max, max2;
|
||||
if (argc > 1) {
|
||||
max = strtoll(argv[1], NULL, 0);
|
||||
} else {
|
||||
max = 1;
|
||||
}
|
||||
if (argc > 2) {
|
||||
max2 = strtoll(argv[2], NULL, 0);
|
||||
} else {
|
||||
max2 = 1;
|
||||
}
|
||||
busy_loop(max, max2);
|
||||
}
|
||||
Reference in New Issue
Block a user