diff mbox series

[RISU,1/5] risu: Use alternate stack

Message ID 20220917074317.1410274-2-gaosong@loongson.cn (mailing list archive)
State New, archived
Headers show
Series Add LoongArch architectures support | expand

Commit Message

Song Gao Sept. 17, 2022, 7:43 a.m. UTC
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(-)

Comments

Richard Henderson Oct. 10, 2022, 2:20 p.m. UTC | #1
On 9/17/22 00:43, Song Gao wrote:
> 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(-)

Good idea.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Peter Maydell Oct. 10, 2022, 2:43 p.m. UTC | #2
On Mon, 10 Oct 2022 at 15:20, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 9/17/22 00:43, Song Gao wrote:
> > 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(-)
>
> Good idea.

Depending on the architecture there might still need to be
restrictions on use of the stack pointer, eg aarch64's
alignment requirements, but this at least means you can
in theory write some risu rules that use SP.

-- PMM
Song Gao Oct. 11, 2022, 6:56 a.m. UTC | #3
在 2022/10/10 22:43, Peter Maydell 写道:
> On Mon, 10 Oct 2022 at 15:20, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>> On 9/17/22 00:43, Song Gao wrote:
>>> 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(-)
>> Good idea.
> Depending on the architecture there might still need to be
> restrictions on use of the stack pointer, eg aarch64's
> alignment requirements, but this at least means you can
> in theory write some risu rules that use SP.
I really want use alternate stack, this way can reduce risu rules.
what about use this only on LoongArch architecture ?

Thanks.
Song Gao
Peter Maydell Oct. 11, 2022, 9:27 a.m. UTC | #4
On Tue, 11 Oct 2022 at 07:57, gaosong <gaosong@loongson.cn> wrote:
>
>
> 在 2022/10/10 22:43, Peter Maydell 写道:
> > On Mon, 10 Oct 2022 at 15:20, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >> On 9/17/22 00:43, Song Gao wrote:
> >>> 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(-)
> >> Good idea.
> > Depending on the architecture there might still need to be
> > restrictions on use of the stack pointer, eg aarch64's
> > alignment requirements, but this at least means you can
> > in theory write some risu rules that use SP.
> I really want use alternate stack, this way can reduce risu rules.
> what about use this only on LoongArch architecture ?

I just mean that although this patch is fine it might
still mean that depending on the architecture some care
and/or special casing of sp in the target risu rules
might be needed. I don't know if that applies to
loongarch or not.

-- PMM
diff mbox series

Patch

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