Skip to content

SigAction isn't missing a field on amd64? #23700

@Alogani

Description

@Alogani

Description

Hello,

I see the SigAction struct of posix miss the field sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.} for amd64

Sigaction* {.importc: "struct sigaction",
header: "<signal.h>", final, pure.} = object ## struct sigaction
sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching
## function or one of the macros
## SIG_IGN or SIG_DFL.
sa_mask*: Sigset ## Set of signals to be blocked during execution of
## the signal handling function.
sa_flags*: cint ## Special flags.
sa_restorer: proc() {.noconv.} ## not intended for application use.

However, I have tested in c, it seems we can define use this field succesfully on my amd64 machine

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>

#define SEGV_STACK_SIZE (MINSIGSTKSZ + 4096)

void sigsegv_handler(int signum, siginfo_t *info, void *data) {
    void *addr = info->si_addr;
    printf("Segmentation fault from reading the address %p\n", addr);
    exit(1);
}

int main() {
    stack_t segv_stack; // #Stack
    segv_stack.ss_sp = posix_memalign(SEGV_STACK_SIZE); //#-> to import, included already in stdlib.h
    segv_stack.ss_flags = 0;
    segv_stack.ss_size = SEGV_STACK_SIZE;
    sigaltstack(&segv_stack, NULL); // #sigaltstack

    struct sigaction action; // #Sigaction
    action.sa_flags = SA_SIGINFO | SA_ONSTACK;
    action.sa_sigaction = &sigsegv_handler;
    sigaction(SIGSEGV, &action, NULL); // #sigaction

    printf("Installed signal handler for SIGSEGV.\n");
    
     int* ptr = NULL;
    *ptr = 42;

    return 0;
}

Nim Version

v2.0.4 Fedora, on amd64

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions