{"action":"created","issue":{"url":"https://api.github.com/repos/graemedouglas/LittleD/issues/3","repository_url":"https://api.github.com/repos/graemedouglas/LittleD","labels_url":"https://api.github.com/repos/graemedouglas/LittleD/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/graemedouglas/LittleD/issues/3/comments","events_url":"https://api.github.com/repos/graemedouglas/LittleD/issues/3/events","html_url":"https://github.com/graemedouglas/LittleD/issues/3","id":116454035,"number":3,"title":"Misaligned memory accesses cause hard faults on 32 bit M0 platform","user":{"login":"bradjc","id":1467890,"avatar_url":"https://avatars.githubusercontent.com/u/1467890?v=3","gravatar_id":"","url":"https://api.github.com/users/bradjc","html_url":"https://github.com/bradjc","followers_url":"https://api.github.com/users/bradjc/followers","following_url":"https://api.github.com/users/bradjc/following{/other_user}","gists_url":"https://api.github.com/users/bradjc/gists{/gist_id}","starred_url":"https://api.github.com/users/bradjc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradjc/subscriptions","organizations_url":"https://api.github.com/users/bradjc/orgs","repos_url":"https://api.github.com/users/bradjc/repos","events_url":"https://api.github.com/users/bradjc/events{/privacy}","received_events_url":"https://api.github.com/users/bradjc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2015-11-12T00:41:10Z","updated_at":"2016-09-16T08:42:07Z","closed_at":null,"body":"This one took me a while to track down, but things stopped working when I moved code from Linux to the Cortex M0 nRF51822 BLE chip. I tracked this back to `db_qmm_falloc()` and `db_qmm_balloc()`. Basically, if something tries to allocate a buffer of a size not a multiple of 4, when the alloc() functions try to write the `size` to the beginning of the allocated area, it causes a misaligned memory access:\r\n\r\n    *((db_int*)(mmp->last_back)) = size;\r\n\r\nMy quick and dirty workaround is to convert size to the next biggest multiple of four:\r\n\r\n```c\r\ndb_int blob = size+sizeof(db_int);\r\nif (blob % 4 != 0) {\r\n    blob += (4 - (blob % 4));\r\n}\r\nsize = blob - sizeof(db_int);\r\n```\r\n\r\nand throw that near the beginning of the alloc() functions.\r\n\r\nI have no idea if that actually fixes anything or just masks issues temporarily. I've ran one `SELECT` statement that I got to work with that change in there, but haven't done any more than that (I wanted to get this posted so I didn't forget). It's entirely possible that this is the best solution and that all later accesses are safe."},"comment":{"url":"https://api.github.com/repos/graemedouglas/LittleD/issues/comments/247548807","html_url":"https://github.com/graemedouglas/LittleD/issues/3#issuecomment-247548807","issue_url":"https://api.github.com/repos/graemedouglas/LittleD/issues/3","id":247548807,"user":{"login":"kazetora","id":4298591,"avatar_url":"https://avatars.githubusercontent.com/u/4298591?v=3","gravatar_id":"","url":"https://api.github.com/users/kazetora","html_url":"https://github.com/kazetora","followers_url":"https://api.github.com/users/kazetora/followers","following_url":"https://api.github.com/users/kazetora/following{/other_user}","gists_url":"https://api.github.com/users/kazetora/gists{/gist_id}","starred_url":"https://api.github.com/users/kazetora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazetora/subscriptions","organizations_url":"https://api.github.com/users/kazetora/orgs","repos_url":"https://api.github.com/users/kazetora/repos","events_url":"https://api.github.com/users/kazetora/events{/privacy}","received_events_url":"https://api.github.com/users/kazetora/received_events","type":"User","site_admin":false},"created_at":"2016-09-16T08:42:07Z","updated_at":"2016-09-16T08:42:07Z","body":"@bradjc I tried to compile this using arm-gcc for cortex m0, and the size is too big (about 100KB). It seems you made it work with cortex m0, what sort of compiler and options are you using? "}}
{"actor":{"display_login":"kazetora"}}