Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction Sigaction struct on amd64 #1 #23705

Closed
wants to merge 2 commits into from
Closed

Conversation

Alogani
Copy link

@Alogani Alogani commented Jun 10, 2024

Correction of #23700, sa_sigaction field of struct Sigaction is missing actually but does exists on amd64.

https://github.com/lattera/glibc/blob/895ef79e04a953cac1493863bcae29ad85657ee1/bits/sigaction.h#L32-L55

Also on my machine (Linux fedora 6.8.11-300.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 27 14:53:33 UTC 2024 x86_64 GNU/Linux) :

/* Structure describing the action to be taken when a signal arrives.  */
struct sigaction
  {
    /* Signal handler.  */
#if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
    union
      {
	/* Used if SA_SIGINFO is not set.  */
	__sighandler_t sa_handler;
	/* Used if SA_SIGINFO is set.  */
	void (*sa_sigaction) (int, siginfo_t *, void *);
      }
    __sigaction_handler;
# define sa_handler	__sigaction_handler.sa_handler
# define sa_sigaction	__sigaction_handler.sa_sigaction
#else
    __sighandler_t sa_handler;
#endif

    /* Additional set of signals to be blocked.  */
    __sigset_t sa_mask;

    /* Special flags.  */
    int sa_flags;

    /* Restore handler.  */
    void (*sa_restorer) (void);
  };

(However I don't know why field sa_restorer doesn't appear in online source)

@Araq
Copy link
Member

Araq commented Jun 10, 2024

But it is inside a union so I think now the sizeof()s are not correct anymore.

@Alogani
Copy link
Author

Alogani commented Jun 10, 2024

Like all other lib/posix/posix_* files

I havn't used importc a lot, so not sure how to express those kinds of unions with it.

@beef331
Copy link
Collaborator

beef331 commented Jun 11, 2024

You'll want to use https://nim-lang.org/docs/manual.html#foreign-function-interface-union-pragma and do something like

type MyUnion {.union.} = object
  typeAName: TypeA
  typeBName: TypeB

@Alogani
Copy link
Author

Alogani commented Jun 11, 2024

@beef331 not sure if that works if this is nested inside an union:

type
  Sigaction_internal {.union.} = object
    sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
                                            ## function or one of the macros
                                            ## SIG_IGN or SIG_DFL.
  Sigaction* {.importc: "struct sigaction",
                header: "<signal.h>", final, pure.} = object ## struct sigaction
    sigaction_union: Sigaction_internal
    sa_mask*: Sigset ## Set of signals to be blocked during execution of
                      ## the signal handling function.
    sa_flags*: cint   ## Special flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants