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

Support for go 1.6 (cgo argument has Go pointer to Go pointer) + stack corruption #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bendikro
Copy link

This PR adds two commits. One to fix the dreaded panic: runtime error: cgo argument has Go pointer to Go pointer, and one that fixes a bug in asm_amd64.S causing stack corruption.

The PR also includes the commit from tiborvass' PR

tiborvass and others added 3 commits February 10, 2016 01:49
In Go 1.6, arguments passed to C cannot be a Go pointer to memory
containing Go pointers.
When they do the following panic occurs:
panic: runtime error: cgo argument has Go pointer to Go pointer

Fix by converting argument to uintptr instead of unsafe.Pointer
Calling sum8 in TestStackArguments fails due to a bug in asm_amd64.S

The function sum8 passes 8 arguments, where two of them are pushed on the
stack before the function in the shared library is called.
After the call instruction in asm_amd64.S returns, the stack must be restored
to the previous state before the CPU registers are restored. Since the stack
is not restored, invalid values are restored to the CPU registers, leading
the incorrect results.

Fix by restoring the stack pointer when arguments are passed on the stack.
@bendikro bendikro mentioned this pull request Apr 10, 2019
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