Last active
October 22, 2023 10:05
-
-
Save oToToT/9ebdaf9be836891eff0a5e1372edd4f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
void main_() { | |
// implement your solution here | |
} | |
void run_with_stack_size(size_t sz, void (*f)(void)) { | |
assert(sz % 16 == 0); | |
char *s = (char *)malloc(sz), *e = s + sz; | |
__asm__("mov x19, sp\n" | |
"mov sp, %1\n" | |
"sub sp, sp, #32\n" | |
"stp %0, x19, [sp]\n" | |
"str x29, [sp, 24]\n" | |
"mov x29, sp\n" | |
"blr %2\n" | |
"ldr x29, [sp, 24]\n" | |
"ldp %0, x19, [sp]\n" | |
"mov sp, x19\n" | |
:"+r"(s):"r"(e),"r"(f):"x19"); | |
free(s); | |
} | |
int main() { | |
run_with_stack_size(1024 * 1024 * 1024, main_); // run with a 1 GiB stack | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment