{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/11089","labels_url":"https://api.github.com/repos/golang/go/issues/11089/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/11089/comments","events_url":"https://api.github.com/repos/golang/go/issues/11089/events","html_url":"https://github.com/golang/go/issues/11089","id":85634805,"number":11089,"title":"runtime: use separate stack for cgo callbacks","user":{"login":"randall77","id":6889504,"avatar_url":"https://avatars.githubusercontent.com/u/6889504?v=3","gravatar_id":"","url":"https://api.github.com/users/randall77","html_url":"https://github.com/randall77","followers_url":"https://api.github.com/users/randall77/followers","following_url":"https://api.github.com/users/randall77/following{/other_user}","gists_url":"https://api.github.com/users/randall77/gists{/gist_id}","starred_url":"https://api.github.com/users/randall77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randall77/subscriptions","organizations_url":"https://api.github.com/users/randall77/orgs","repos_url":"https://api.github.com/users/randall77/repos","events_url":"https://api.github.com/users/randall77/events{/privacy}","received_events_url":"https://api.github.com/users/randall77/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-05T21:16:56Z","updated_at":"2015-06-05T21:42:39Z","closed_at":null,"body":"Currently there is a problem combining cgo callbacks and stack copying.  Imagine we pass a pointer to a Go-stack-allocated object into cgo.  That in itself is fine, as the Go stack will not be grown (because no one is running on it) or shrunk (because we forbid it, just like syscalls) during the cgo call.  However, if cgo does a callback into Go, we resume running on the same Go stack.  Additional stack use might force us to grow the Go stack, which involves copying it.  After the callback returns, the pointers that the C code had are now bogus.\r\n\r\nThere are no easy solutions here.  I propose to fix this problem by allocating a new stack for the callback.  That way we can leave the previous Go stack frozen so pointers into it remain valid.  It will be somewhat expensive, but cgo callbacks are hopefully uncommon.  I have not seen any reports of this bug happening in the wild.\r\n\r\nAllocating a new stack for the callback will complicate stack tracebacks, panic, and the like.  There will now potentially be multiple stacks per G, which I'm sure will get tricky. (I've also considered using a whole new G for the callback, but that has its own issues).\r\n\r\nRelated to issue 10303."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/109447771","html_url":"https://github.com/golang/go/issues/11089#issuecomment-109447771","issue_url":"https://api.github.com/repos/golang/go/issues/11089","id":109447771,"user":{"login":"minux","id":135652,"avatar_url":"https://avatars.githubusercontent.com/u/135652?v=3","gravatar_id":"","url":"https://api.github.com/users/minux","html_url":"https://github.com/minux","followers_url":"https://api.github.com/users/minux/followers","following_url":"https://api.github.com/users/minux/following{/other_user}","gists_url":"https://api.github.com/users/minux/gists{/gist_id}","starred_url":"https://api.github.com/users/minux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minux/subscriptions","organizations_url":"https://api.github.com/users/minux/orgs","repos_url":"https://api.github.com/users/minux/repos","events_url":"https://api.github.com/users/minux/events{/privacy}","received_events_url":"https://api.github.com/users/minux/received_events","type":"User","site_admin":false},"created_at":"2015-06-05T21:42:39Z","updated_at":"2015-06-05T21:42:39Z","body":"It seems we removed segmented stack support too soon?\nIt's a perfect case to use a new segmented stack for growing\ncallback stacks.\n\nPlease don't assume cgo callbacks are rare.\n"}}