{"action":"created","comment":{"url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/comments/64435942","id":64435942,"diff_hunk":"@@ -0,0 +1,70 @@\n+\n+#include <stdint.h>\n+#include <stddef.h>\n+#include <stdio.h>\n+#include <reent.h>\n+\n+#include \"uvisor-lib/uvisor-lib.h\"\n+#include \"cmsis_os.h\"\n+\n+#define DPRINTF(...) {};\n+/* Use printf with caution inside malloc: printf may allocate memory itself,\n+   so using printf in malloc may lead to recursive calls! */\n+/* #define DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) */\n+\n+extern UvisorBoxIndex *const __uvisor_ps;\n+extern void uvisor_malloc_init(void);\n+\n+static int is_kernel_initialized() {\n+    static uint8_t kernel_running = 0;\n+    return (kernel_running || (kernel_running = osKernelRunning()));\n+}\n+\n+static int init_allocator()\n+{\n+    int ret = 0;\n+#if !(defined(UVISOR_PRESENT) && (UVISOR_PRESENT == 1))\n+    if (__uvisor_ps == NULL) uvisor_malloc_init();\n+#else\n+    if (__uvisor_ps == NULL) return -1;\n+#endif\n+\n+    if (__uvisor_ps->mutex_id == NULL && is_kernel_initialized()) {\n+        memset(__uvisor_ps->mutex_data, 0, sizeof(__uvisor_ps->mutex_data));\n+        /* point the mutex pointer to the data */\n+        __uvisor_ps->mutex = &(__uvisor_ps->mutex_data);\n+        /* create mutex if not already done */\n+        __uvisor_ps->mutex_id = osMutexCreate((osMutexDef_t *)&(__uvisor_ps->mutex));\n+        /* mutex failed to be created */\n+        if (__uvisor_ps->mutex_id == NULL) return -1;\n+    }\n+\n+    if (__uvisor_ps->active_heap == NULL) {\n+        /* we need to initialize the process heap */\n+        if (__uvisor_ps->process_heap != NULL) {\n+            /* lock the mutex during initialization */\n+            if (is_kernel_initialized()) osMutexWait(__uvisor_ps->mutex_id, osWaitForever);\n+            /* initialize the process heap */\n+            UvisorAllocator allocator = uvisor_allocator_create_with_pool(\n+                __uvisor_ps->process_heap,\n+                __uvisor_ps->process_heap_size);\n+            /* set the allocator */\n+            ret = allocator ? 0 : -1;\n+            __uvisor_ps->active_heap = allocator;\n+            /* release the mutex */\n+            if (is_kernel_initialized()) osMutexRelease(__uvisor_ps->mutex_id);\n+        }\n+        else {\n+            DPRINTF(\"uvisor_allocator: No process heap available!\\n\");\n+            ret = -1;\n+        }\n+    }\n+    return ret;\n+}\n+\n+/* public API */\n+UvisorAllocator uvisor_get_allocator(void)\n+{\n+    if (init_allocator()) return NULL;","path":"api/rtx/src/uvisor_malloc.c","position":69,"original_position":68,"commit_id":"d103351efb104e0e7060fcea39269297aeb4d827","original_commit_id":"399cbf6698134ed7a7403ce2951cd3d35eadf333","user":{"login":"AlessandroA","id":8617445,"avatar_url":"https://avatars.githubusercontent.com/u/8617445?v=3","gravatar_id":"","url":"https://api.github.com/users/AlessandroA","html_url":"https://github.com/AlessandroA","followers_url":"https://api.github.com/users/AlessandroA/followers","following_url":"https://api.github.com/users/AlessandroA/following{/other_user}","gists_url":"https://api.github.com/users/AlessandroA/gists{/gist_id}","starred_url":"https://api.github.com/users/AlessandroA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlessandroA/subscriptions","organizations_url":"https://api.github.com/users/AlessandroA/orgs","repos_url":"https://api.github.com/users/AlessandroA/repos","events_url":"https://api.github.com/users/AlessandroA/events{/privacy}","received_events_url":"https://api.github.com/users/AlessandroA/received_events","type":"User","site_admin":false},"body":"No 1-line if statements, always use braces.","created_at":"2016-05-24T17:19:19Z","updated_at":"2016-05-24T17:19:19Z","html_url":"https://github.com/ARMmbed/uvisor/pull/223#discussion_r64435942","pull_request_url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223","_links":{"self":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/comments/64435942"},"html":{"href":"https://github.com/ARMmbed/uvisor/pull/223#discussion_r64435942"},"pull_request":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223"}}},"pull_request":{"url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223","id":71251347,"html_url":"https://github.com/ARMmbed/uvisor/pull/223","diff_url":"https://github.com/ARMmbed/uvisor/pull/223.diff","patch_url":"https://github.com/ARMmbed/uvisor/pull/223.patch","issue_url":"https://api.github.com/repos/ARMmbed/uvisor/issues/223","number":223,"state":"open","locked":false,"title":"RFC: Export table allocator","user":{"login":"Patater","id":410816,"avatar_url":"https://avatars.githubusercontent.com/u/410816?v=3","gravatar_id":"","url":"https://api.github.com/users/Patater","html_url":"https://github.com/Patater","followers_url":"https://api.github.com/users/Patater/followers","following_url":"https://api.github.com/users/Patater/following{/other_user}","gists_url":"https://api.github.com/users/Patater/gists{/gist_id}","starred_url":"https://api.github.com/users/Patater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Patater/subscriptions","organizations_url":"https://api.github.com/users/Patater/orgs","repos_url":"https://api.github.com/users/Patater/repos","events_url":"https://api.github.com/users/Patater/events{/privacy}","received_events_url":"https://api.github.com/users/Patater/received_events","type":"User","site_admin":false},"body":"Not ready for mergin' yet. This PR includes both the supported and unsupported support for malloc. It also includes the export table additions for thread notifications.\r\n\r\n@AlessandroA @meriac @niklas-arm ","created_at":"2016-05-24T16:25:32Z","updated_at":"2016-05-24T17:19:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63cb8827d22b3792370c58120c4dbec8077d2d51","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223/commits","review_comments_url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223/comments","review_comment_url":"https://api.github.com/repos/ARMmbed/uvisor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ARMmbed/uvisor/issues/223/comments","statuses_url":"https://api.github.com/repos/ARMmbed/uvisor/statuses/d103351efb104e0e7060fcea39269297aeb4d827","head":{"label":"Patater:export-table-allocator","ref":"export-table-allocator","sha":"d103351efb104e0e7060fcea39269297aeb4d827","user":{"login":"Patater","id":410816,"avatar_url":"https://avatars.githubusercontent.com/u/410816?v=3","gravatar_id":"","url":"https://api.github.com/users/Patater","html_url":"https://github.com/Patater","followers_url":"https://api.github.com/users/Patater/followers","following_url":"https://api.github.com/users/Patater/following{/other_user}","gists_url":"https://api.github.com/users/Patater/gists{/gist_id}","starred_url":"https://api.github.com/users/Patater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Patater/subscriptions","organizations_url":"https://api.github.com/users/Patater/orgs","repos_url":"https://api.github.com/users/Patater/repos","events_url":"https://api.github.com/users/Patater/events{/privacy}","received_events_url":"https://api.github.com/users/Patater/received_events","type":"User","site_admin":false},"repo":{"id":46977092,"name":"uvisor","full_name":"Patater/uvisor","owner":{"login":"Patater","id":410816,"avatar_url":"https://avatars.githubusercontent.com/u/410816?v=3","gravatar_id":"","url":"https://api.github.com/users/Patater","html_url":"https://github.com/Patater","followers_url":"https://api.github.com/users/Patater/followers","following_url":"https://api.github.com/users/Patater/following{/other_user}","gists_url":"https://api.github.com/users/Patater/gists{/gist_id}","starred_url":"https://api.github.com/users/Patater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Patater/subscriptions","organizations_url":"https://api.github.com/users/Patater/orgs","repos_url":"https://api.github.com/users/Patater/repos","events_url":"https://api.github.com/users/Patater/events{/privacy}","received_events_url":"https://api.github.com/users/Patater/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Patater/uvisor","description":"mbed OS uVisor -- device security layer for ARMv7M microcontrollers","fork":true,"url":"https://api.github.com/repos/Patater/uvisor","forks_url":"https://api.github.com/repos/Patater/uvisor/forks","keys_url":"https://api.github.com/repos/Patater/uvisor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Patater/uvisor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Patater/uvisor/teams","hooks_url":"https://api.github.com/repos/Patater/uvisor/hooks","issue_events_url":"https://api.github.com/repos/Patater/uvisor/issues/events{/number}","events_url":"https://api.github.com/repos/Patater/uvisor/events","assignees_url":"https://api.github.com/repos/Patater/uvisor/assignees{/user}","branches_url":"https://api.github.com/repos/Patater/uvisor/branches{/branch}","tags_url":"https://api.github.com/repos/Patater/uvisor/tags","blobs_url":"https://api.github.com/repos/Patater/uvisor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Patater/uvisor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Patater/uvisor/git/refs{/sha}","trees_url":"https://api.github.com/repos/Patater/uvisor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Patater/uvisor/statuses/{sha}","languages_url":"https://api.github.com/repos/Patater/uvisor/languages","stargazers_url":"https://api.github.com/repos/Patater/uvisor/stargazers","contributors_url":"https://api.github.com/repos/Patater/uvisor/contributors","subscribers_url":"https://api.github.com/repos/Patater/uvisor/subscribers","subscription_url":"https://api.github.com/repos/Patater/uvisor/subscription","commits_url":"https://api.github.com/repos/Patater/uvisor/commits{/sha}","git_commits_url":"https://api.github.com/repos/Patater/uvisor/git/commits{/sha}","comments_url":"https://api.github.com/repos/Patater/uvisor/comments{/number}","issue_comment_url":"https://api.github.com/repos/Patater/uvisor/issues/comments{/number}","contents_url":"https://api.github.com/repos/Patater/uvisor/contents/{+path}","compare_url":"https://api.github.com/repos/Patater/uvisor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Patater/uvisor/merges","archive_url":"https://api.github.com/repos/Patater/uvisor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Patater/uvisor/downloads","issues_url":"https://api.github.com/repos/Patater/uvisor/issues{/number}","pulls_url":"https://api.github.com/repos/Patater/uvisor/pulls{/number}","milestones_url":"https://api.github.com/repos/Patater/uvisor/milestones{/number}","notifications_url":"https://api.github.com/repos/Patater/uvisor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Patater/uvisor/labels{/name}","releases_url":"https://api.github.com/repos/Patater/uvisor/releases{/id}","deployments_url":"https://api.github.com/repos/Patater/uvisor/deployments","created_at":"2015-11-27T11:36:21Z","updated_at":"2016-02-26T16:51:50Z","pushed_at":"2016-05-24T16:05:37Z","git_url":"git://github.com/Patater/uvisor.git","ssh_url":"git@github.com:Patater/uvisor.git","clone_url":"https://github.com/Patater/uvisor.git","svn_url":"https://github.com/Patater/uvisor","homepage":"","size":5145,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ARMmbed:master","ref":"master","sha":"85745f08857d518c5807d889a94598dbe1c45de0","user":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"repo":{"id":27869517,"name":"uvisor","full_name":"ARMmbed/uvisor","owner":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ARMmbed/uvisor","description":"mbed OS uVisor -- device security layer for ARMv7M microcontrollers","fork":false,"url":"https://api.github.com/repos/ARMmbed/uvisor","forks_url":"https://api.github.com/repos/ARMmbed/uvisor/forks","keys_url":"https://api.github.com/repos/ARMmbed/uvisor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ARMmbed/uvisor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ARMmbed/uvisor/teams","hooks_url":"https://api.github.com/repos/ARMmbed/uvisor/hooks","issue_events_url":"https://api.github.com/repos/ARMmbed/uvisor/issues/events{/number}","events_url":"https://api.github.com/repos/ARMmbed/uvisor/events","assignees_url":"https://api.github.com/repos/ARMmbed/uvisor/assignees{/user}","branches_url":"https://api.github.com/repos/ARMmbed/uvisor/branches{/branch}","tags_url":"https://api.github.com/repos/ARMmbed/uvisor/tags","blobs_url":"https://api.github.com/repos/ARMmbed/uvisor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ARMmbed/uvisor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ARMmbed/uvisor/git/refs{/sha}","trees_url":"https://api.github.com/repos/ARMmbed/uvisor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ARMmbed/uvisor/statuses/{sha}","languages_url":"https://api.github.com/repos/ARMmbed/uvisor/languages","stargazers_url":"https://api.github.com/repos/ARMmbed/uvisor/stargazers","contributors_url":"https://api.github.com/repos/ARMmbed/uvisor/contributors","subscribers_url":"https://api.github.com/repos/ARMmbed/uvisor/subscribers","subscription_url":"https://api.github.com/repos/ARMmbed/uvisor/subscription","commits_url":"https://api.github.com/repos/ARMmbed/uvisor/commits{/sha}","git_commits_url":"https://api.github.com/repos/ARMmbed/uvisor/git/commits{/sha}","comments_url":"https://api.github.com/repos/ARMmbed/uvisor/comments{/number}","issue_comment_url":"https://api.github.com/repos/ARMmbed/uvisor/issues/comments{/number}","contents_url":"https://api.github.com/repos/ARMmbed/uvisor/contents/{+path}","compare_url":"https://api.github.com/repos/ARMmbed/uvisor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ARMmbed/uvisor/merges","archive_url":"https://api.github.com/repos/ARMmbed/uvisor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ARMmbed/uvisor/downloads","issues_url":"https://api.github.com/repos/ARMmbed/uvisor/issues{/number}","pulls_url":"https://api.github.com/repos/ARMmbed/uvisor/pulls{/number}","milestones_url":"https://api.github.com/repos/ARMmbed/uvisor/milestones{/number}","notifications_url":"https://api.github.com/repos/ARMmbed/uvisor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ARMmbed/uvisor/labels{/name}","releases_url":"https://api.github.com/repos/ARMmbed/uvisor/releases{/id}","deployments_url":"https://api.github.com/repos/ARMmbed/uvisor/deployments","created_at":"2014-12-11T11:59:50Z","updated_at":"2016-05-24T03:12:47Z","pushed_at":"2016-05-24T16:25:33Z","git_url":"git://github.com/ARMmbed/uvisor.git","ssh_url":"git@github.com:ARMmbed/uvisor.git","clone_url":"https://github.com/ARMmbed/uvisor.git","svn_url":"https://github.com/ARMmbed/uvisor","homepage":"","size":6284,"stargazers_count":56,"watchers_count":56,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":33,"mirror_url":null,"open_issues_count":31,"forks":33,"open_issues":31,"watchers":56,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223"},"html":{"href":"https://github.com/ARMmbed/uvisor/pull/223"},"issue":{"href":"https://api.github.com/repos/ARMmbed/uvisor/issues/223"},"comments":{"href":"https://api.github.com/repos/ARMmbed/uvisor/issues/223/comments"},"review_comments":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223/comments"},"review_comment":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ARMmbed/uvisor/pulls/223/commits"},"statuses":{"href":"https://api.github.com/repos/ARMmbed/uvisor/statuses/d103351efb104e0e7060fcea39269297aeb4d827"}}}}
{"actor":{"display_login":"AlessandroA"}}