Skip to content

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
Signed-off-by: Tibor Vass <teabee89@gmail.com>
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