{"action":"created","issue":{"url":"https://api.github.com/repos/go-gl/gl/issues/71","repository_url":"https://api.github.com/repos/go-gl/gl","labels_url":"https://api.github.com/repos/go-gl/gl/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/go-gl/gl/issues/71/comments","events_url":"https://api.github.com/repos/go-gl/gl/issues/71/events","html_url":"https://github.com/go-gl/gl/issues/71","id":227229974,"node_id":"MDU6SXNzdWUyMjcyMjk5NzQ=","number":71,"title":"gl.FenceSync returns invalid unsafe.Pointer, causing crash","user":{"login":"dominikh","id":39825,"node_id":"MDQ6VXNlcjM5ODI1","avatar_url":"https://avatars0.githubusercontent.com/u/39825?v=4","gravatar_id":"","url":"https://api.github.com/users/dominikh","html_url":"https://github.com/dominikh","followers_url":"https://api.github.com/users/dominikh/followers","following_url":"https://api.github.com/users/dominikh/following{/other_user}","gists_url":"https://api.github.com/users/dominikh/gists{/gist_id}","starred_url":"https://api.github.com/users/dominikh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominikh/subscriptions","organizations_url":"https://api.github.com/users/dominikh/orgs","repos_url":"https://api.github.com/users/dominikh/repos","events_url":"https://api.github.com/users/dominikh/events{/privacy}","received_events_url":"https://api.github.com/users/dominikh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":24,"created_at":"2017-05-09T02:32:17Z","updated_at":"2018-10-21T15:56:51Z","closed_at":null,"author_association":"NONE","body":"gl.FenceSync returns the created fence as an unsafe.Pointer. However, values returned by glFenceSync aren't necessarily valid pointers to memory owned by the driver.\r\n\r\nOn my system (nvidia 378.13 on Linux), for example, glFenceSync returns increasing numbers, starting at 1. The issue with that is that the Go runtime expects pointers in unsafe.Pointer to be valid, either pointing to memory owned by the Go memory allocator, or valid, non-Go memory. Pointers such as \"1\" are neither, which causes runtime.writebarrierptr to abort the program with a \"bad pointer in write barrier\" error. Similarly, the driver might return a value that looks like a valid pointer to Go memory, preventing said Go memory from being garbage collected as long as the unsafe.Pointer is alive.\r\n\r\nTo simulate the issue, compile https://play.golang.org/p/614oIx_Y1D and run it with GOGC=0 (to force frequent GCs, triggering the problem faster.). You should see the following:\r\n\r\n```\r\n$ GOGC=0 ./foo\r\nruntime: writebarrierptr *0x4fa230 = 0x1\r\nfatal error: bad pointer in write barrier\r\n\r\nruntime stack:\r\nruntime.throw(0x4a81ca, 0x1c)\r\n\t/usr/lib/go/src/runtime/panic.go:596 +0x95\r\nruntime.writebarrierptr.func1()\r\n\t/usr/lib/go/src/runtime/mbarrier.go:208 +0xbd\r\nruntime.systemstack(0x4fab00)\r\n\t/usr/lib/go/src/runtime/asm_amd64.s:327 +0x79\r\nruntime.mstart()\r\n\t/usr/lib/go/src/runtime/proc.go:1132\r\n\r\ngoroutine 1 [running]:\r\nruntime.systemstack_switch()\r\n\t/usr/lib/go/src/runtime/asm_amd64.s:281 fp=0xc420048f00 sp=0xc420048ef8\r\nruntime.writebarrierptr(0x4fa230, 0x1)\r\n\t/usr/lib/go/src/runtime/mbarrier.go:209 +0x96 fp=0xc420048f38 sp=0xc420048f00\r\nmain.main()\r\n\t/tmp/foo.go:15 +0x9b fp=0xc420048f88 sp=0xc420048f38\r\nruntime.main()\r\n\t/usr/lib/go/src/runtime/proc.go:185 +0x20a fp=0xc420048fe0 sp=0xc420048f88\r\nruntime.goexit()\r\n\t/usr/lib/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420048fe8 sp=0xc420048fe0\r\n```\r\n\r\nI would recommend returning a uintptr instead (and, similarly, accepting a uintptr in gl.ClientWaitSync and gl.WaitSync)."},"comment":{"url":"https://api.github.com/repos/go-gl/gl/issues/comments/431680477","html_url":"https://github.com/go-gl/gl/issues/71#issuecomment-431680477","issue_url":"https://api.github.com/repos/go-gl/gl/issues/71","id":431680477,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTY4MDQ3Nw==","user":{"login":"dmitshur","id":1924134,"node_id":"MDQ6VXNlcjE5MjQxMzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/1924134?v=4","gravatar_id":"","url":"https://api.github.com/users/dmitshur","html_url":"https://github.com/dmitshur","followers_url":"https://api.github.com/users/dmitshur/followers","following_url":"https://api.github.com/users/dmitshur/following{/other_user}","gists_url":"https://api.github.com/users/dmitshur/gists{/gist_id}","starred_url":"https://api.github.com/users/dmitshur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmitshur/subscriptions","organizations_url":"https://api.github.com/users/dmitshur/orgs","repos_url":"https://api.github.com/users/dmitshur/repos","events_url":"https://api.github.com/users/dmitshur/events{/privacy}","received_events_url":"https://api.github.com/users/dmitshur/received_events","type":"User","site_admin":false},"created_at":"2018-10-21T15:56:51Z","updated_at":"2018-10-21T15:56:51Z","author_association":"MEMBER","body":"Friendly ping @dominikh. You said [on February 15](https://github.com/go-gl/gl/issues/71#issuecomment-366133553):\r\n\r\n> I've finally gotten around to testing the change. It compiles, doesn't cause runtime panics, and I've successfully used a fence.\r\n\r\nIf that's still the case, I think we can close this issue as resolved (via PR https://github.com/go-gl/glow/pull/85 PR to glow, and PR https://github.com/go-gl/gl/pull/93 to regenerate gl)."}}
{"actor":{"display_login":"dmitshur"}}