{"action":"created","issue":{"url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/11","labels_url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/11/comments","events_url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/11/events","html_url":"https://github.com/HSAFoundation/HSA-Runtime-Reference-Source/issues/11","id":126190326,"number":11,"title":"Segfault in hsa_init on non-HSA platforms","user":{"login":"r-potter","id":6206191,"avatar_url":"https://avatars.githubusercontent.com/u/6206191?v=3","gravatar_id":"","url":"https://api.github.com/users/r-potter","html_url":"https://github.com/r-potter","followers_url":"https://api.github.com/users/r-potter/followers","following_url":"https://api.github.com/users/r-potter/following{/other_user}","gists_url":"https://api.github.com/users/r-potter/gists{/gist_id}","starred_url":"https://api.github.com/users/r-potter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r-potter/subscriptions","organizations_url":"https://api.github.com/users/r-potter/orgs","repos_url":"https://api.github.com/users/r-potter/repos","events_url":"https://api.github.com/users/r-potter/events{/privacy}","received_events_url":"https://api.github.com/users/r-potter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-12T14:25:54Z","updated_at":"2016-01-26T10:06:32Z","closed_at":null,"body":"Prior to 1.0.3, calling hsa_init() on a non-HSA platform (such as an Intel CPU) was well behaved. I believe the behaviour was that hsa_init() succeeded, but that the runtime would report no agents or regions to the hsa_iterate_*.\r\n\r\nWith the 1.0.3 release, hsa_init segfaults. This is due to this line:\r\n\r\n   // Setup system region allocator.\r\n   if (reinterpret_cast<amd::MemoryRegion*>(\r\n           core::MemoryRegion::Convert(system_region_))->fine_grain()) {\r\n\r\nOn non-HSA platforms, system_region_.handle == 0, so the call to fine_grain() dereferences a null pointer.\r\n\r\nHaving hsa_init() fail cleanly, or restoring the previous behaviour, where hsa_init() succeeds, but no agents and regions are reported would be preferable to a segfault. \r\n\r\nIt appears that simply adding a check for a null system_region_ restores this behaviour.\r\n\r\n[runtime.patch.txt](https://github.com/HSAFoundation/HSA-Runtime-Reference-Source/files/87418/runtime.patch.txt)\r\n"},"comment":{"url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/comments/174939875","html_url":"https://github.com/HSAFoundation/HSA-Runtime-Reference-Source/issues/11#issuecomment-174939875","issue_url":"https://api.github.com/repos/HSAFoundation/HSA-Runtime-Reference-Source/issues/11","id":174939875,"user":{"login":"tschwinge","id":21753,"avatar_url":"https://avatars.githubusercontent.com/u/21753?v=3","gravatar_id":"","url":"https://api.github.com/users/tschwinge","html_url":"https://github.com/tschwinge","followers_url":"https://api.github.com/users/tschwinge/followers","following_url":"https://api.github.com/users/tschwinge/following{/other_user}","gists_url":"https://api.github.com/users/tschwinge/gists{/gist_id}","starred_url":"https://api.github.com/users/tschwinge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschwinge/subscriptions","organizations_url":"https://api.github.com/users/tschwinge/orgs","repos_url":"https://api.github.com/users/tschwinge/repos","events_url":"https://api.github.com/users/tschwinge/events{/privacy}","received_events_url":"https://api.github.com/users/tschwinge/received_events","type":"User","site_admin":false},"created_at":"2016-01-26T10:06:32Z","updated_at":"2016-01-26T10:06:32Z","body":"Confirming the problem (`master` branch: commit 576359e18ac998a3fbe45ba0569db6f4103f5949 \"HSA 1.0.3 Source\"):\r\n\r\n    [...]\r\n    Program received signal SIGSEGV, Segmentation fault.\r\n    0x00007ffff564e579 in core::Runtime::Load() () from [...]/libhsa-runtime64.so.1\r\n    (gdb) bt\r\n    #0  0x00007ffff564e579 in core::Runtime::Load() () from [...]/libhsa-runtime64.so.1\r\n    #1  0x00007ffff564d0ee in core::Runtime::Acquire() () from [...]/libhsa-runtime64.so.1\r\n    #2  0x00007ffff563910a in HSA::hsa_init() () from [...]/libhsa-runtime64.so.1\r\n    #3  0x00007ffff565e074 in hsa_init () from [...]/libhsa-runtime64.so.1\r\n    [...]\r\n\r\n..., and that the [patch](https://github.com/HSAFoundation/HSA-Runtime-Reference-Source/files/87418/runtime.patch.txt) posted by @r-potter, resolves this.\r\n"}}