-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
SigAction isn't missing a field on amd64? #23700
Comments
Make a pull request? 🤔 |
Correction of nim-lang#23700
Yeah sure ! I was hesitant out of fear that something might explode or I don't know what, I have never contributed before 🙂 |
For
We can tell two points from it:
Edit: I later found in the code below the definition, the getter and setter is defined as templates. Footnotes
|
Could you please refer to the I've had a look at Debain's, and there's union in Different linux distributions may have different definitions.... which requires further inspect and discussion... |
Further steps:
|
FreeBSD's 1 is defined as follows: struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
int sa_flags; /* see signal options below */
sigset_t sa_mask; /* signal mask to apply */
}; in which case a field is indeed missing. So may we add a new What's more, OpenBSD's is the same as what's defined in posix_linux_amd64.nim, Footnotes
|
Wow, that a very detailed research you did. Awesome. I had put more info in the PR request, but the PR request is wrong indeed as you noticed well. I will rewrite the information i found there below Here it is for my fedora : /* 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);
}; If I'm not wrong, this is the standard: https://github.com/lattera/glibc/blob/895ef79e04a953cac1493863bcae29ad85657ee1/bits/sigaction.h#L32-L55 But there is something strange, on my machine, there is |
@Alogani /* These definitions match those used by the 4.4 BSD kernel.
If the operating system has a `sigaction' system call that correctly
implements the POSIX.1 behavior, there should be a system-dependent
version of this file that defines `struct sigaction' and the `SA_*'
constants appropriately. */ And I think rather check the main repos and not an old mirror to be safe, but it doesn't look like it has changed at all. |
glibc's definition really seems to contain no sa_restorer field.... Maybe many linux distributions do not use glibc's definition directly. |
So instead of using basing on linux specific architecture, we should put all defs in posix common architecture and use compile switch for each distro -> https://nim-lang.org/docs/distros.html There is also the problem of how to represent it (dicussion on the PR): Because some systems uses a union inside a an object, naive implementation will have a wrong |
Isn't each function pointer in C the same size?1 (as function pointer is still pointer). So as far as I'm concerned, despite araq's worry, a union of two pointer is still of one pointer length. Therefore the Footnotes
|
I wasn't sure of what you said, so I verified, and you are indeed right: #include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
struct sigaction action; // #Sigaction
printf("%ld", sizeof(action));
return 0;
} Output = 152 type
Sigaction2* {.importc: "struct sigaction",
header: "<signal.h>", final, pure.} = object ## struct sigaction
sa_sigaction*: proc (x: cint, y: pointer, z: pointer) {.noconv.}
sa_handler*: proc (x: cint) {.noconv.}
## 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.
var a = Sigaction2()
echo sizeof(a) Output = 152 Because there can be multiple different variations by distribution and only one topic is a bit messy to check that, I propose you make an issue for each different distribution here: https://github.com/Alogani/Nim/issues Then, we could either:
|
Ops, I meant either using a union inside object or defining only one function pointer field keeps the struct layout valid. But defining two field together like above breaks the validaity of such a struct, as in your system, the two function pointers is only one pointer length. Also, I later realized that |
Oups, true. I don't see how to do it, except by using just a pointer, but we would lose some information. |
omg, have a look at code here It's not missing! |
So, it turns out the origin problem is not a problem. But there are some other raised when inspecting it: The 1st
I've found the relavant pr: #12137 The 2ndAs we've found glibc didn't define the sa_restorer field, then what such a thing will affect? in which Linux distribution? |
@litlighilit this is very nice work. The workaround using a template is a nice one! So the only problem is to make openbsd field in good order and that's all ? |
In that pr, @euantorano mentioned:
So it means the definitions of these structs may not be generated from header files. Therefore, it's more likely the |
I think it would quite easy to make std/distro work at compile time. But certainly not very efficient... The template might still be the most polyvalent solution |
Use the same definition as posix_linux_amd64.nim did, where we can still define templates/procs as getter and setter, and replace the last field definition with |
I'll make it done. |
Also, I'd like to add some comments that such a field repersents a union. |
Here is about the 2nd problem:
according to Linux's man.7:
Also, POSIX manual indices this. a POSIX may doesn't define a sa_restorer, ... I also found there is not sa_restorer in MacOSX's manual |
It may be worth trying to get the |
Thanks for your reply! I currently rely on online doc https://man.openbsd.org/sigaction.2 For current issue, |
Sure, I’ll check the header file on my machine tonight when I’m back at home. |
Nice work @litlighilit 👍 |
Description
Hello,
I see the SigAction struct of posix miss the field
sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
for amd64Nim/lib/posix/posix_linux_amd64.nim
Lines 304 to 313 in 767a901
However, I have tested in c, it seems we can define use this field succesfully on my amd64 machine
Nim Version
v2.0.4 Fedora, on amd64
Current Output
No response
Expected Output
No response
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: