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

ucontext_t fpregs ABI incompatibility #2555

Closed
alexrp opened this issue Oct 10, 2017 · 5 comments
Closed

ucontext_t fpregs ABI incompatibility #2555

alexrp opened this issue Oct 10, 2017 · 5 comments
Labels

Comments

@alexrp
Copy link

alexrp commented Oct 10, 2017

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.15063]

  • What you're doing and what's happening: (Copy&paste specific commands and their output, or include screen shots)

Given a ucontext_t *ctx pointer, I'm trying to access ctx->uc_mcontext.fpregs->_xmm[0].

  • What's wrong / what should be happening instead:

The ctx->uc_mcontext.fpregs field contains a NULL pointer. On a normal Linux system, the ctx->uc_mcontext.fpregs field is always a non-NULL pointer, presumably pointing to ctx->__fpregs_mem. Indeed, if I dig into ctx->__fpregs_mem, all the data is there as expected. So it seems WSL is simply not setting the ctx->uc_mcontext.fpregs field as it should.

@benhillis
Copy link
Member

@alexrp - Thanks for posting, could you share an strace so I can narrow down what's happening?

@therealkenc
Copy link
Collaborator

therealkenc commented Oct 11, 2017

@benhillis - I don't know if a strace will show much, because there won't be a syscall fail.

Richard's tight repro from unrelated #1692 (message) demonstrates the problem. Besides his gregs ask, fpregs are all nada. On Real Linux it's populated, natch.

[...blah blah gdb startup]
(gdb) break 16
Breakpoint 1 at 0x40071d: file ucontext.c, line 16.
(gdb) run
Starting program: /home/ken/Devel/ucontext/ucontext

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400812 in main () at ucontext.c:41
41              *x = 3;
(gdb) cont
Continuing.

Breakpoint 1, segv (sig=11, info=0x7ffffffddd40, context=0x7ffffffdd730) at ucontext.c:16
16              printf("SIGSEGV at 0x%lx, fixing up\n", (unsigned long)fault_addr);
(gdb) list
11              ucontext_t *c = context;
12              mcontext_t m = c->uc_mcontext;
13              void *fault_addr = (void *)m.gregs[REG_CR2];
14              void *addr;
15
16              printf("SIGSEGV at 0x%lx, fixing up\n", (unsigned long)fault_addr);
17
18              addr = mmap(fault_addr, 4096, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
19              if (addr == MAP_FAILED) {
20                      printf("map failed!\n");
(gdb) print m
$1 = {gregs = {0, 255, 8, 8, 4195776, 140737488215856, 0, 0, 11, 140737488215104, 140737488215632, 0, 0, 3735928559,
    8, 140737488215616, 4196370, 66118, 356485103667, 0, 0, 0, 0}, fpregs = 0x0, __reserved1 = {0, 0, 0, 0, 0, 0, 0,
    0}}
(gdb)

@alexrp
Copy link
Author

alexrp commented Oct 13, 2017

To be clear, the ucontext_t is obtained as the third argument from a signal handler that was installed via sigaction with SA_SIGINFO.

@therealkenc
Copy link
Collaborator

To be clear, the ucontext_t is obtained as the third argument from a signal handler that was installed via sigaction with SA_SIGINFO.

Yep. In the test case I cited it is:

static void segv(int sig, siginfo_t *info, void *context)
{
	ucontext_t *c = context;
	mcontext_t m = c->uc_mcontext;
[...]

They were trapping SIGSEGV, but any signal will do. I assume you are trapping SIGFPE. I hope gregs is addressed also because that is valuable on its own merits, as is fpregs. I haven't tested it personally, but I am pretty sure libsigsegv is broken on WSL.

@benhillis benhillis added the wsl1 label May 5, 2021
trungnt2910 added a commit to trungnt2910/darling that referenced this issue Aug 29, 2022
On WSL1, this value is always NULL. See
microsoft/WSL#2555
for more details.
Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

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

No branches or pull requests

3 participants