{"action":"created","issue":{"url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/155","repository_url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK","labels_url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/155/comments","events_url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/155/events","html_url":"https://github.com/espressif/ESP8266_NONOS_SDK/issues/155","id":346248212,"node_id":"MDU6SXNzdWUzNDYyNDgyMTI=","number":155,"title":"calloc (pvPortCallocIram) fails when it fills IRAM ","user":{"login":"gilpinheiro","id":5205260,"node_id":"MDQ6VXNlcjUyMDUyNjA=","avatar_url":"https://avatars0.githubusercontent.com/u/5205260?v=4","gravatar_id":"","url":"https://api.github.com/users/gilpinheiro","html_url":"https://github.com/gilpinheiro","followers_url":"https://api.github.com/users/gilpinheiro/followers","following_url":"https://api.github.com/users/gilpinheiro/following{/other_user}","gists_url":"https://api.github.com/users/gilpinheiro/gists{/gist_id}","starred_url":"https://api.github.com/users/gilpinheiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gilpinheiro/subscriptions","organizations_url":"https://api.github.com/users/gilpinheiro/orgs","repos_url":"https://api.github.com/users/gilpinheiro/repos","events_url":"https://api.github.com/users/gilpinheiro/events{/privacy}","received_events_url":"https://api.github.com/users/gilpinheiro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-31T15:47:56Z","updated_at":"2018-08-09T23:31:40Z","closed_at":null,"author_association":"NONE","body":"I have been having crashes in the mbedtls connection routines, on the current MASTER branch and spent some time to diagnose what was going on.\r\n\r\nIt looks like calloc is failing - the calloc request asks for more space than is available in what remains of the 0x4010xxxx-0x40108000 IRAM block - it is supposed to realize that, and return another buffer of the requested size in the 0x3fffxxxx (DRAM) range instead.\r\n\r\nWhat it does: returns the 0x4010xxxx ptr (with insufficient space available), and writes to that buffer are  truncated at 0x40108000. Subsequent callocs work fine. \r\n\r\n```c\r\n    #define COUNT 20\r\n    #define BUFSIZE 1024\r\n    void *buffers[COUNT];\r\n\r\n    os_printf(\"create buffers...\\n\");\r\n    int i=0;\r\n    for (i=0; i<COUNT; i++) {\r\n        //        buffers[i] = os_malloc(BUFSIZE); // This works\r\n        buffers[i] = pvPortCallocIram(BUFSIZE, 1, \"\", __LINE__);\r\n        os_printf(\"building buffer %d (0x%p)\\n\", i, buffers[i]);\r\n        if (buffers[i] == NULL) {\r\n            error(\"failed to alloc\");\r\n        } else {\r\n            os_printf(\".. buffer is 0x%p\\n\", buffers[i]);\r\n            // fill buffer with value that we can verify to make sure it hasn't been\r\n            // overwritten by another alloc'd buffer\r\n            os_memset(buffers[i], i, BUFSIZE);\r\n        }\r\n\r\n        // do a quick check to make sure memset has worked\r\n        uint8_t *d = buffers[i];\r\n        for (int j=0; j<BUFSIZE; j++) {\r\n            uint8_t v = *d++;\r\n            if (v != i) {\r\n                os_printf(\"failed write verify %d : [%d] = (%d)\\n\", i, j, v);\r\n                print_bytes(buffers[i], BUFSIZE);\r\n                goto FAIL_WRITE_VERIFY;\r\n            }\r\n        }\r\n        os_printf(\".. write verify passed\\n\");\r\n        FAIL_WRITE_VERIFY:\r\n        continue;\r\n    }\r\n```\r\n\r\n```\r\ncreate buffers...\r\nbuilding buffer 0 (0x40106c50)\r\n.. buffer is 0x40106c50\r\n.. write verify passed\r\nbuilding buffer 1 (0x40107060)\r\n.. buffer is 0x40107060\r\n.. write verify passed\r\nbuilding buffer 2 (0x40107470)\r\n.. buffer is 0x40107470\r\n.. write verify passed\r\nbuilding buffer 3 (0x40107880)\r\n.. buffer is 0x40107880\r\n.. write verify passed\r\nbuilding buffer 4 (0x40107c90)\r\n.. buffer is 0x40107c90\r\nfailed write verify 4 : [880] = (0)\r\n....\r\n0x40107fe0:   04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04       ................\r\n0x40107ff0:   04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04       ................\r\n0x40108000:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00       ................\r\n0x40108010:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00       ................\r\n...\r\n\r\nbuilding buffer 5 (0x3fff22a8)\r\n.. buffer is 0x3fff22a8\r\n.. write verify passed\r\nbuilding buffer 6 (0x3fff26b8)\r\n.. buffer is 0x3fff26b8\r\n.. write verify passed\r\nbuilding buffer 7 (0x3fff2ac8)\r\n.. buffer is 0x3fff2ac8\r\n.. write verify passed\r\nbuilding buffer 8 (0x3fff2ed8)\r\n.. buffer is 0x3fff2ed8\r\n.. write verify passed\r\nbuilding buffer 9 (0x3fff32e8)\r\n.. buffer is 0x3fff32e8\r\n.. write verify passed\r\nbuilding buffer 10 (0x3fff36f8)\r\n.. buffer is 0x3fff36f8\r\n.. write verify passed\r\nbuilding buffer 11 (0x3fff3b08)\r\n.. buffer is 0x3fff3b08\r\n.. write verify passed\r\nbuilding buffer 12 (0x3fff3f18)\r\n.. buffer is 0x3fff3f18\r\n.. write verify passed\r\nbuilding buffer 13 (0x3fff4328)\r\n.. buffer is 0x3fff4328\r\n.. write verify passed\r\nbuilding buffer 14 (0x3fff4738)\r\n.. buffer is 0x3fff4738\r\n.. write verify passed\r\nbuilding buffer 15 (0x3fff4b48)\r\n.. buffer is 0x3fff4b48\r\n.. write verify passed\r\nbuilding buffer 16 (0x3fff4f58)\r\n.. buffer is 0x3fff4f58\r\n.. write verify passed\r\nbuilding buffer 17 (0x3fff5368)\r\n.. buffer is 0x3fff5368\r\n.. write verify passed\r\nbuilding buffer 18 (0x3fff5778)\r\n.. buffer is 0x3fff5778\r\n.. write verify passed\r\nbuilding buffer 19 (0x3fff5b88)\r\n.. buffer is 0x3fff5b88\r\n.. write verify passed\r\n```"},"comment":{"url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/comments/411930001","html_url":"https://github.com/espressif/ESP8266_NONOS_SDK/issues/155#issuecomment-411930001","issue_url":"https://api.github.com/repos/espressif/ESP8266_NONOS_SDK/issues/155","id":411930001,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTkzMDAwMQ==","user":{"login":"gilpinheiro","id":5205260,"node_id":"MDQ6VXNlcjUyMDUyNjA=","avatar_url":"https://avatars0.githubusercontent.com/u/5205260?v=4","gravatar_id":"","url":"https://api.github.com/users/gilpinheiro","html_url":"https://github.com/gilpinheiro","followers_url":"https://api.github.com/users/gilpinheiro/followers","following_url":"https://api.github.com/users/gilpinheiro/following{/other_user}","gists_url":"https://api.github.com/users/gilpinheiro/gists{/gist_id}","starred_url":"https://api.github.com/users/gilpinheiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gilpinheiro/subscriptions","organizations_url":"https://api.github.com/users/gilpinheiro/orgs","repos_url":"https://api.github.com/users/gilpinheiro/repos","events_url":"https://api.github.com/users/gilpinheiro/events{/privacy}","received_events_url":"https://api.github.com/users/gilpinheiro/received_events","type":"User","site_admin":false},"created_at":"2018-08-09T23:31:40Z","updated_at":"2018-08-09T23:31:40Z","author_association":"NONE","body":"Hi @xcguang \r\n\r\nI've updated to latest build @6dcfc86e186b6e37e1b5c22aaf19086fbc659e7c\r\n\r\npvPortCallocIram() is exhibiting different bad behaviour now.\r\n\r\nI get failures just doing:\r\n\r\n```\r\n#define COUNT 50\r\n#define BUFSIZE 4096\r\n    void *buffers[COUNT];\r\n\r\n    os_printf(\"create buffers...\\n\");\r\n    int i=0;\r\n    for (i=0; i<COUNT; i++) {\r\n        buffers[i] = pvPortCallocIram(BUFSIZE, 1, \"\", __LINE__);\r\n        if (buffers[i] == NULL) {\r\n            os_printf(\"failed to alloc\");\r\n        } else {\r\n            os_printf(\".. buffer is 0x%p\\n\", buffers[i]);\r\n        }\r\n    }\r\n    os_printf(\"done\\n\");\r\n```\r\nresult:\r\n\r\n```\r\ncreate buffers...\r\n.. buffer is 0x0x40107a30\r\n.. buffer is 0x0x3ffeff78\r\n.. buffer is 0x0x3fff0f88\r\n.. buffer is 0x0x3fff1f98\r\n.. buffer is 0x0x3fff2fa8\r\n.. buffer is 0x0x3fff3fb8\r\n.. buffer is 0x0x3fff4fc8\r\n.. buffer is 0x0x3fff5fd8\r\n.. buffer is 0x0x3fff6fe8\r\n.. buffer is 0x0x3fff7ff8\r\n.. buffer is 0x0x3fff9008\r\n.. buffer is 0x0x3fffa018\r\n.. buffer is 0x0x3fffb028\r\n.. buffer is 0x\r\n ets Jan  8 2013,rst cause:4, boot mode:(3,6)\r\n\r\nwdt reset\r\n```\r\n\r\ndevice sits at that last 0x for a long time before watchdog triggers. I'm not sure what the cause could be -- it seems like an odd place to get stuck - I thought it could be something unrelated in the print function, but removing all print statements still results in a watchdog failure (we never reach the end of the containing function).\r\n\r\nDoesn't matter whether or not user_iram_memory_is_enabled() is true or false.\r\n"}}
{"actor":{"display_login":"gilpinheiro"}}