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

runtime: refactor assembly for C calls in signal handlers #18352

Open
bcmills opened this Issue Dec 16, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@bcmills
Member

bcmills commented Dec 16, 2016

On change 34501, @minux notes:

It seems the complexity of runtime.sigtramp has got out of control. (sigtramp used to be only called by kernel, now with signal forwarding, it can also be called by foreign C code)

Perhaps we need to separate the concern of saving callee saved register to another function, possbily reusing the existing runtime/cgo crosscall function?

@ianlancetaylor replies:

Signal forwarding applied as soon as we started thinking about combining Go and C code together in the same program. We're just continuing to grapple with it.

Unifying C ABI register saving sounds like a good idea if we can figure out how to do it.

@bcmills

This comment has been minimized.

Member

bcmills commented Dec 16, 2016

One possibility for the "C call into Go" direction would be to split crosscall2 into two functions. One would save callee-saved registers, call a function (passed in via a stack slot or a non-callee-save non-argument register such as r11) with the non-stack-pointer registers remaining as-is, and then restore the callee-saved registers. The other would copy argument registers into stack slots, invoke a Go function, and then copy return-parameter slots into return-registers.

The register-saving function does not depend on the particulars of the C call, so it could be reused for calls with other signatures (such as signal handlers). The arguments-to-slots function necessarily does depend on the function signature (because that determines which registers need to be copied and what size slots they need to be copied into), so that would need specific variants for crosscall2, sigtramp, and any other function with a distinct signature.

@bcmills

This comment has been minimized.

Member

bcmills commented Dec 16, 2016

For the "Go call into C" direction (such as sigfwd; see #17641), we could probably factor out a function which aligns the stack pointer, invokes a function (again passed in a stack slot or non-argument register), and then restores the stack. It would still be up to the individual callers to load the appropriate argument registers, but that would at least cut down on some of the duplication (e.g. between sigfwd and callCgoSigaction).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment