[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RISU PATCH 1/5] risu: Use alternate stack
From: |
Song Gao |
Subject: |
[RISU PATCH 1/5] risu: Use alternate stack |
Date: |
Sat, 17 Sep 2022 15:43:13 +0800 |
We can use alternate stack, so that we can use sp register as intput/ouput
register.
I had tested aarch64/LoongArch architecture.
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
risu.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/risu.c b/risu.c
index 1c096a8..714074e 100644
--- a/risu.c
+++ b/risu.c
@@ -329,7 +329,7 @@ static void set_sigill_handler(void (*fn) (int, siginfo_t
*, void *))
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = fn;
- sa.sa_flags = SA_SIGINFO;
+ sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGILL, &sa, 0) != 0) {
perror("sigaction");
@@ -550,6 +550,7 @@ int main(int argc, char **argv)
char *trace_fn = NULL;
struct option *longopts;
char *shortopts;
+ stack_t ss;
longopts = setup_options(&shortopts);
@@ -617,6 +618,19 @@ int main(int argc, char **argv)
load_image(imgfile);
+ /* create alternate stack */
+ ss.ss_sp = malloc(SIGSTKSZ);
+ if (ss.ss_sp == NULL) {
+ perror("malloc");
+ exit(EXIT_FAILURE);
+ }
+ ss.ss_size = SIGSTKSZ;
+ ss.ss_flags = 0;
+ if (sigaltstack(&ss, NULL) == -1) {
+ perror("sigaltstac");
+ exit(EXIT_FAILURE);
+ }
+
/* E.g. select requested SVE vector length. */
arch_init();
--
2.31.1