{"id":1084,"date":"2021-02-17T15:40:06","date_gmt":"2021-02-17T07:40:06","guid":{"rendered":"http:\/\/www.mrtblog.cn\/?p=1084"},"modified":"2023-03-12T16:04:24","modified_gmt":"2023-03-12T08:04:24","slug":"%e8%99%9a%e6%8b%9f%e5%86%85%e5%ad%98%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"http:\/\/www.mrtblog.cn\/?p=1084","title":{"rendered":"\u865a\u62df\u5185\u5b58\u7a7a\u95f4"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,349<\/span><span class='epvc-label'> Views<\/span><\/div><p>\u89c2\u5bdf\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801<\/p>\n<pre class=\"highlight\"><code class=\"language-cpp line-numbers\">size_t all_size = 4000000000;\nint *arr = (int*)malloc(all_size);\n\/\/memset(arr, 0, all_size);<\/code><\/pre>\n<p>\u76ee\u524d\u4e3a\u6b62\u7a0b\u5e8f\u662f\u53ef\u4ee5\u7f16\u8bd1\u548c\u8fd0\u884c\u7684<br \/>\n\u4f46\u662f\u5f53\u6211\u4eec\u53d6\u6d88\u6389\u6ce8\u91ca<\/p>\n<pre class=\"highlight\"><code class=\"language-cpp line-numbers\">memset(arr, 0, all_size)<\/code><\/pre>\n<p>\u73b0\u5728\u7684\u7a0b\u5e8f\u51fa\u73b0\u4e86<br \/>\nSegmentation fault (core dumped)<br \/>\n\u539f\u56e0\u5728\u4e8e\u8fdb\u7a0b\u5f00\u59cb\u7533\u8bf7\u5185\u5b58\u65f6\uff0c\u5e76\u4e0d\u4f1a\u7acb\u523b\u83b7\u5f97\u5b9e\u9645\u7684\u7269\u7406\u5185\u5b58\uff0c\u800c\u662f\u5f97\u5230\u4e86\u4e00\u4efd\u865a\u62df\u5185\u5b58\uff0c\u865a\u62df\u5185\u5b58\u53ea\u4f1a\u4fdd\u7559\u90e8\u5206\u6709\u7528\u7684\u4fe1\u606f\uff0c\u800c\u53ea\u6709\u5728\u8be5\u5185\u5b58\u88ab\u4f7f\u7528\u5230\u7684\u65f6\u5019(\u4f8b\u5982\u521d\u59cb\u5316\u6216\u8005\u8bfb\u5199\u64cd\u4f5c)\u624d\u4f1a\u771f\u6b63\u7684\u5728\u7269\u7406\u5185\u5b58\u4e2d\u7533\u8bf7\u5e76\u5360\u7528<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u76f4\u63a5\u7533\u8bf7\u7269\u7406\u5185\u5b58\uff1f<\/h3>\n<ol>\n<li>\u5982\u679c\u6240\u6709\u7684\u5185\u5b58\u5728\u58f0\u660e\u65f6\u5c31\u76f4\u63a5\u4ece\u7269\u7406\u5185\u5b58\u4e2d\u7533\u8bf7\u5360\u7528\u4e86\uff0c\u5373\u4f7f\u4e00\u4e9b\u6682\u65f6\u53ef\u80fd\u4e0d\u9700\u8981\u7684\u5185\u5b58\u4e5f\u88ab\u4e00\u6b21\u6027\u5360\u7528\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5185\u5b58\u4e2d\u5927\u90e8\u5206\u65f6\u95f4\u5b58\u653e\u7684\u51e0\u4e4e\u90fd\u662f\u672a\u88ab\u4f7f\u7528\u5230\u7684\u6570\u636e\uff0c\u5927\u5927\u964d\u4f4e\u4e86\u5185\u5b58\u7684\u53ef\u7528\u6027<\/li>\n<li>\u76f4\u63a5\u9488\u5bf9\u7269\u7406\u5185\u5b58\u64cd\u4f5c\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u5230\u5176\u4ed6\u4e0d\u76f8\u5e72\u7684\u7a0b\u5e8f\uff0c\u964d\u4f4e\u7a0b\u5e8f\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u4f8b\u5982\u8fdb\u7a0bA\u7684\u4e00\u6b21\u6808\u6ea2\u51fa(\u4f8b\u5982\u6570\u7ec4\u8d8a\u754c)\u4ea7\u751f\u7684\u810f\u6570\u636e\u5199\u574f\u4e86\u53e6\u4e00\u4e2a\u8fdb\u7a0bB\u7684\u5185\u5b58\uff0c\u5bfc\u81f4\u8fdb\u7a0bB\u83ab\u540d\u5176\u5999\u4ea7\u751f\u4e86\u7a0b\u5e8f\u5f02\u5e38\u3002<\/li>\n<li>\u8fdb\u7a0b\u7684\u90e8\u5206\u516c\u6709\u7684\u5c5e\u6027\uff08\u5982\u5e93\u51fd\u6570\u7b49\uff09\u5e94\u5f53\u4ee5\u5171\u4eab\u7684\u65b9\u5f0f\u5b58\u653e\u5728\u5185\u5b58\u4e2d(\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u628a\u76f8\u540c\u7684\u4ee3\u7801\u5355\u72ec\u4fdd\u5b58\u5230\u81ea\u5df1\u7ba1\u7406\u7684\u5185\u5b58\u4e2d\u662f\u975e\u5e38\u6d6a\u8d39\u7684)\uff0c\u76f4\u63a5\u4f7f\u7528\u7269\u7406\u5185\u5b58\u96be\u4ee5\u8868\u8fbe\u548c\u533a\u5206\u516c\u6709\u5185\u5b58\u548c\u79c1\u6709\u5185\u5b58<\/li>\n<\/ol>\n<h2>\u4ec0\u4e48\u662f\u865a\u62df\u5185\u5b58<\/h2>\n<p>\u865a\u62df\u5185\u5b58\u5176\u5b9e\u662f\u78c1\u76d8\u4e2d\u7684\u4e00\u90e8\u5206\u7a7a\u95f4\uff0c\u5b83\u7ba1\u7406\u81ea\u5df1\u72ec\u7acb\u7684\u5185\u5b58\u5730\u5740\uff0c\u5e76\u4fdd\u5b58\u865a\u62df\u5185\u5b58\u5730\u5740\u5230\u7269\u7406\u5185\u5b58\u5730\u5740\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u8fd9\u4e2a\u5730\u5740\u7684\u5bfb\u5740\u8303\u56f4\u53d6\u51b3\u4e8e\u673a\u5668\u7684\u4f4d\u6570(\u598232\u4f4d\u673a\u5668\u662f4GB\uff0c64\u4f4d\u673a\u5668\u662f256TB)\u3002\u56e0\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u7a7a\u95f4\u662f\u5b8c\u5168\u72ec\u7acb\u7684\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u53ef\u4ee5\u4f7f\u7528 0x0000000000000000 \u5230 0x00007FFFFFFFFFFFF \u4ee3\u8868\u4ed6\u4eec\u6240\u5360\u7528\u7684\u5168\u90e8\u5185\u5b58\uff0c\u91cd\u590d\u4e5f\u4e0d\u4f1a\u76f8\u4e92\u5f71\u54cd<\/p>\n<h2>\u9875\u8868<\/h2>\n<p>\u865a\u62df\u5185\u5b58\u7684\u7ef4\u62a4\u662f\u57fa\u4e8e\u540d\u4e3a\u9875\u8868\u7684\u529f\u80fd\u6765\u5b8c\u6210\u7684\u3002<\/p>\n<ol>\n<li>\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u542f\u52a8\u65f6\u4f1a\u751f\u6210\u4e00\u4e2a\u521d\u59cb\u7684\u9875\u8868(PTE\u6709\u6548\u4f4d\u5168\u4e3a0)<\/li>\n<li>\u6267\u884c\u5230\u8bf8\u5982malloc\u7b49\u529f\u80fd\u7684\u51fd\u6570\uff0c\u76f4\u63a5\u5c06\u9875\u8868\u5bf9\u5e94\u7684PTE\u7f6e\u4e3a1\uff0c\u540c\u65f6\u5bf9\u5e94\u5730\u5740\u586b\u5199\u4e3a\u865a\u62df\u5185\u5b58\u5730\u5740<\/li>\n<li>\u6267\u884c\u5230\u8bbf\u95ee\u5185\u5b58\u7684\u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u8be5\u5185\u5b58\u6307\u5411\u5730\u5740\u662f\u865a\u62df\u5185\u5b58\u5730\u5740\uff0c\u5219\u4f1a\u89e6\u53d1\u4e00\u4e2a\u7f3a\u9875\u4e2d\u65ad\uff0c\u4f7f\u7528\u9875\u9762\u7f6e\u6362\u7b97\u6cd5\u4ece\u7269\u7406\u5185\u5b58\u4e2d\u53d6\u51fa\u4e00\u5757\u533a\u57df\u62f7\u8d1d\u865a\u62df\u5185\u5b58\u5bf9\u5e94\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u5bf9\u5e94\u5730\u5740\u4fee\u6539\u4e3a\u5b9e\u9645\u7684\u7269\u7406\u5185\u5b58\u5730\u5740<a href=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b581.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1085\" src=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b581.png\" alt=\"\" width=\"764\" height=\"586\" srcset=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b581.png 764w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b581-300x230.png 300w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/a><\/li>\n<\/ol>\n<h2>\u6743\u9650\u7ba1\u7406<\/h2>\n<p>\u9875\u8868\u4e2d\u5b9e\u9645\u8fd8\u5305\u542b\u4e86\u4e00\u4e9b\u6807\u5fd7\u4f4d\u7528\u6765\u505a\u6743\u9650\u7684\u5212\u5206<a href=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1086\" src=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582.png\" alt=\"\" width=\"1139\" height=\"558\" srcset=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582.png 1139w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582-300x147.png 300w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582-768x376.png 768w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b582-1024x502.png 1024w\" sizes=\"auto, (max-width: 1139px) 100vw, 1139px\" \/><\/a><br \/>\nSUP\u8868\u793a\u662f\u5426\u5141\u8bb8\u975e\u5185\u6838\u6001(\u7528\u6237\u6a21\u5f0f)\u8bbf\u95ee<br \/>\nREAD\u8868\u793a\u662f\u5426\u5141\u8bb8\u8bfb\u5185\u5b58<br \/>\nWRITE\u8868\u793a\u662f\u5426\u5141\u8bb8\u5199\u5185\u5b58<br \/>\n\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u60f3\u8981\u4f7f\u4e24\u4e2a\u7a0b\u5e8f\u5171\u4eab\u7269\u7406\u5185\u5b58\uff0c\u53ea\u9700\u8981\u5c06\u4ed6\u4eec\u9875\u8868\u4e2d\u7684\u67d0\u4e00\u9879\u5730\u5740\u6307\u5411\u540c\u4e00\u4e2a\u7269\u7406\u5185\u5b58\u5730\u5740\uff08\u5982PP6\uff09\uff0c\u518d\u901a\u8fc7WRITE\u548cREAD\u89c4\u5b9a\u8c01\u662f\u8be5\u5185\u5b58\u7684\u53ef\u6539\u5199\u8005\u3002<br \/>\n\u5982\u679c\u7a0b\u5e8f\u7684\u67d0\u4e00\u6b21\u64cd\u4f5c\u8fdd\u80cc\u4e86\u6743\u9650\uff0c\u4f8b\u5982\u8bbf\u95ee\u4e00\u4e2a\u4e0d\u53ef\u4ee5READ\u7684\u5185\u5b58\u6216\u8005\u5199\u4e00\u4e2a\u4e0d\u53ef\u4ee5WRITE\u7684\u5185\u5b58(\u6700\u5e38\u89c1\u7684\u539f\u56e0\u662f\u7a0b\u5e8f\u7684\u903b\u8f91\u9519\u8bef\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\u6216\u6ea2\u51fa)\uff0clinux\u7cfb\u7edf\u4f1a\u4ea7\u751f\u4e00\u4e2a\u6bb5\u9519\u8bef(segmention fault)<\/p>\n<h2>Linux\u865a\u62df\u5185\u5b58<\/h2>\n<p>\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u5206\u522b\u662f\u5185\u6838\u7ea7\u865a\u62df\u5185\u5b58\u548c\u8fdb\u7a0b\u7ea7\u865a\u62df\u5185\u5b58<br \/>\n<a href=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b583.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1087\" src=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b583.png\" alt=\"\" width=\"604\" height=\"817\" srcset=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b583.png 604w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b583-222x300.png 222w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><br \/>\n\u6700\u9876\u90e8\u76840-0x40000000\u9ed8\u8ba4\u4e0d\u4f7f\u7528<br \/>\nbss\u3001text\u3001data\u4e5f\u5c31\u662f\u5404\u9762\u7ecf\u5e38\u63d0\u7684\u5e38\u91cf\u533a\u4e86\uff0c\u5305\u542b\u9759\u6001\u53d8\u91cf\u3001\u5e38\u91cf\u3001\u4ee3\u7801\u6bb5\u7b49<br \/>\n\u4ece\u6307\u9488brk\u5f00\u59cb\u5411\u4e0a\u7684\u4e00\u90e8\u5206\u533a\u57df(\u4f4e\u5730\u5740-&gt;\u9ad8\u5730\u5740)\u4e3a\u5806\u533a<br \/>\n\u6307\u9488rsp\u5411\u4e0b\u7684\u4e00\u90e8\u5206\u533a\u57df(\u9ad8\u5730\u5740-&gt;\u4f4e\u5730\u5740)\u4e3a\u6808\u533a<br \/>\n\u5171\u4eab\u5e93\u7684\u5185\u5b58\u6620\u5c04\u533a\u57df\uff0c\u672c\u8d28\u4e0a\u548c\u5176\u4ed6\u79c1\u6709\u533a\u57df\u4e00\u6837\uff0c\u4f46\u662f\u5728\u6982\u5ff5\u4e0a\u53ea\u5141\u8bb8\u5fc5\u987b\u88ab\u9700\u8981\u591a\u4e2a\u8fdb\u7a0b\u95f4\u5171\u4eab\u7684\u5185\u5bb9\u4f7f\u7528\uff0c\u4f8b\u5982\u516c\u5171\u5e93<\/p>\n<h2>\u5b88\u62a4\u8fdb\u7a0b<\/h2>\n<p>\u4e3a\u4e86\u540e\u9762\u4ee3\u7801\u7684\u8c03\u8bd5\u65b9\u4fbf\uff0c\u9700\u8981\u6d89\u53ca\u5230\u5b88\u62a4\u8fdb\u7a0b\u7684\u6982\u5ff5\u3002\u5b88\u62a4\u8fdb\u7a0b\u6307\u7684\u662f\u7cfb\u7edf\u4e2d\u4e0d\u5728\u524d\u53f0\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u4ed6\u4eec\u5728shell\u547d\u4ee4\u7ed3\u675f\u540e\u4f9d\u7136\u53ef\u4ee5\u957f\u671f\u5728\u540e\u53f0\u8fd0\u884c\u3002<br \/>\nC++\u4e2d\u4e00\u79cd\u6700\u7b80\u6613\u7684\u5b88\u62a4\u8fdb\u7a0b\u5b9e\u73b0\u65b9\u6cd5\u4e3a\u7236\u8fdb\u7a0bfork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u540e\u9000\u51fa\uff0c\u63a5\u4e0b\u6765\u7684\u5de5\u4f5c\u4ea4\u7531\u5b50\u8fdb\u7a0b\u7ee7\u7eed\u5904\u7406<\/p>\n<pre class=\"highlight\"><code class=\"language-cpp line-numbers\">pid_t fpid;\nfpid = fork();\nif (fpid &lt; 0)\n{\n    cout &lt;&lt; &quot;fork err &quot;&lt;&lt; fpid &lt;&lt; endl;\n    return 0;\n}\nif (fpid &gt; 0)\n{\n    cout &lt;&lt; &quot;i am father &quot; &lt;&lt; getpid() &lt;&lt; &quot;, son is &quot; &lt;&lt; fpid  &lt;&lt; endl;\n    return 0;\n}\n\/\/now this is son progress<\/code><\/pre>\n<h2>Linux\u8fdb\u7a0b\u5730\u5740\u5206\u6790<\/h2>\n<p>\u5728Linux\u7cfb\u7edf\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u542f\u52a8C++\u7a0b\u5e8f\u4f1a\u5f97\u5230\u5bf9\u5e94\u8fdb\u7a0b\u7684pid\u3002\u5728\u76ee\u5f55\/proc\/pid\u4e0b\u4f1a\u4fdd\u5b58\u8fdb\u7a0b\u7684\u8fd0\u884c\u4fe1\u606f\uff0c\u5176\u4e2dmaps\u6587\u4ef6\u8868\u793a\u8be5\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u5730\u5740\u3002<br \/>\n\u57fa\u4e8e\u4e4b\u524d\u7684\u5b88\u62a4\u8fdb\u7a0b\u4ee3\u7801\uff0c\u6211\u4eec\u5728\u5b50\u8fdb\u7a0b\u4e2d\u6dfb\u52a0\u6808\u53d8\u91cf\u548c\u5806\u53d8\u91cf\u6253\u5370\uff0c\u5e76\u5728\u6700\u540e\u6dfb\u52a0while\u5faa\u73af\u4fdd\u8bc1\u5b50\u8fdb\u7a0b\u5e38\u9a7b\u540e\u53f0<\/p>\n<pre class=\"highlight\"><code class=\"language-cpp line-numbers\">int *malloc_brk_address = NULL;\nint *malloc_mmap_address = NULL;\nint stack_arr_address[10] = {};\n\nmalloc_brk_address = (int*)malloc(1024 * 128 - 1);\nmalloc_mmap_address = (int*)malloc(1024 * 128 + 1);\n\nvector&lt;int&gt; my_vector;\nmy_vector.push_back(1);\n\ncout &lt;&lt; &quot;stack_arr_address   &quot; &lt;&lt; stack_arr_address &lt;&lt; endl;\ncout &lt;&lt; &quot;stack_arr[end]      &quot; &lt;&lt; &amp;stack_arr_address[9] &lt;&lt; endl;\ncout &lt;&lt; &quot;malloc_brk_address  &quot; &lt;&lt; malloc_brk_address &lt;&lt; endl;\ncout &lt;&lt; &quot;malloc_brk          &quot; &lt;&lt; &amp;malloc_brk_address &lt;&lt; endl;\ncout &lt;&lt; &quot;malloc_mmap_address &quot; &lt;&lt; malloc_mmap_address &lt;&lt; endl;\ncout &lt;&lt; &quot;malloc_mmap         &quot; &lt;&lt; &amp;malloc_mmap_address &lt;&lt; endl;\ncout &lt;&lt; &quot;vector_address      &quot; &lt;&lt; &amp;my_vector &lt;&lt; endl;\ncout &lt;&lt; &quot;vector[0]           &quot; &lt;&lt; &amp;my_vector[0] &lt;&lt; endl;\n\/\/cout &lt;&lt; &quot;i am son&quot; &lt;&lt; getpid() &lt;&lt; endl;\nwhile(1)\n{\n    \/\/keep running son progress\n    sleep(10);\n}<\/code><\/pre>\n<p>\u6839\u636e\u83b7\u5f97\u7684\u5b50\u8fdb\u7a0bpid(\u8fd9\u91cc\u6211\u7684pid\u662f29301)\uff0c\u4f7f\u7528\u547d\u4ee4<\/p>\n<pre class=\"highlight\"><code class=\"language-shell line-numbers\">cat \/proc\/29031\/maps<\/code><\/pre>\n<p>\u7ed3\u5408\u4ee3\u7801\u4e2d\u6253\u5370\u7684\u53d8\u91cf\u5730\u5740\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u7684\u5206\u5e03\u8868\uff0c\u5404\u53d8\u91cf\u4f4d\u4e8e\u7684\u865a\u62df\u5185\u5b58\u533a\u57df\u5df2\u7ecf\u7528\u4e0d\u540c\u989c\u8272\u5bf9\u5e94\u6807\u6ce8\u51fa\u6765<br \/>\n<a href=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584.png\" alt=\"\" width=\"1331\" height=\"761\" class=\"alignnone size-full wp-image-1091\" srcset=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584.png 1331w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584-300x172.png 300w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584-768x439.png 768w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b584-1024x585.png 1024w\" sizes=\"auto, (max-width: 1331px) 100vw, 1331px\" \/><\/a><\/p>\n<h3>\u533f\u540d\u6620\u5c04<\/h3>\n<p>\u53ef\u4ee5\u53d1\u73b0\u5728\u5806[heap]\u548c\u6808[stack]\u4e2d\u5206\u914d\u7684\u90e8\u5206\uff0c\u4ed6\u4eec\u7684inode\u548c\u8bbe\u5907\u53f7\u5747\u4e3a0\uff0c\u8fd9\u662f\u56e0\u4e3alinux\u5185\u5b58\u6620\u5c04\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u4e86\u533f\u540d\u6620\u5c04\u7684\u65b9\u6cd5\u3002\u533f\u540d\u6587\u4ef6\u4e0d\u662f\u78c1\u76d8\u4e2d\u5b9e\u9645\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u5b83\u662f\u7531\u5185\u6838\u521b\u5efa\u7684\uff0c\u5305\u542b\u7684\u5168\u90e8\u662f\u4e8c\u8fdb\u5236\u96f6\u3002<\/p>\n<h3>\u6743\u9650\u5c5e\u6027<\/h3>\n<p>\/lib\/x86_64-linux-gnu\/ld-2.23.so\u6587\u4ef6\u5728\u865a\u62df\u5185\u5b58\u7a7a\u95f4\u4e2d\u51fa\u73b0\u4e86\u4e09\u6b21\uff0c\u4ed6\u4eec\u552f\u4e00\u7684\u4e0d\u540c\u5728\u4e8e\u6743\u9650\uff0c\u4ece\u4e0a\u81f3\u4e0b\u6743\u9650\u5206\u522b\u4e3a<br \/>\nr-xp(\u53ef\u5199 \u53ef\u6267\u884c \u79c1\u6709)<br \/>\nr&#8211;p(\u53ef\u5199 \u79c1\u6709)<br \/>\nrw-p(\u53ef\u5199 \u53ef\u8bfb \u79c1\u6709)<br \/>\n\u5171\u4eab\u5185\u5b58\u548c\u79c1\u6709\u5185\u5b58\u7684\u533a\u522b\u5728\u4e8e\u6743\u9650\u7684\u6700\u540e\u4e00\u4f4d\u662fp(\u79c1\u6709)\u8fd8\u662fs(\u5171\u4eab)<\/p>\n<h3>\u5185\u5b58\u7533\u8bf7<\/h3>\n<p>\u6808\u5730\u5740\u4e3a7fffcdf57000-7fffcdf78000\uff0c\u4ee3\u7801\u4e2d\u7533\u8bf7\u7684\u4e34\u65f6\u53d8\u91cf\u5982malloc\u5934\u6307\u9488\u3001vector\u6307\u9488\u90fd\u5904\u4e8e\u6808\u7a7a\u95f4\u5185\uff0cvector\u4e2d\u5177\u4f53\u7684\u5143\u7d20\u548cmalloc\u7533\u8bf7\u7684\u7a7a\u95f4\u90fd\u5b58\u653e\u5728\u5806\u4e2d<br \/>\n\u4e3a\u4e86\u4fdd\u8bc1\u53ef\u4ee5\u4f7f\u7528++\u8fed\u4ee3\u5668\u8bbf\u95ee\u6570\u7ec4\u7b49\u5185\u5b58\u8fde\u7eed\u6570\u636e\uff0c\u6570\u7ec4\u7684\u5934\u90e8\u5143\u7d20\u5206\u914d\u5728\u6808\u4e2d\u7684\u4f4e\u5730\u5740\uff0c\u800c\u5c3e\u90e8\u5143\u7d20\u5728\u9ad8\u5730\u5740(\u53c2\u8003stack_arr[end]\u548cstack_arr_address)<\/p>\n<h2>Malloc\u548cFree\u51fd\u6570<\/h2>\n<p>\u4ece\u8868\u4e2d\u53ef\u4ee5\u770b\u51famalloc\u4f1a\u6839\u636e\u7533\u8bf7\u7684\u7a7a\u95f4\u5927\u5c0f\u81ea\u52a8\u8c03\u7528\u4e0d\u540c\u7684\u5206\u914d\u51fd\u6570\uff0c\u5f53\u7533\u8bf7\u7a7a\u95f4\u5c0f\u4e8e128k\u65f6\u8c03\u7528brk\uff0c\u5426\u5219\u8c03\u7528mmap(\u53c2\u8003malloc_brk_addres\u548cmalloc_mmap_addres\u5730\u5740\u5b58\u5728\u660e\u663e\u7684\u5dee\u5f02)<br \/>\nbrk\u4f1a\u4ece\u5806\u9876\u7a7a\u95f4\u533a\u57df\u7533\u8bf7\u548c\u91ca\u653e\u5185\u5b58\uff0c\u800cmmap\u4f1a\u4ece\u5806\u548c\u6808\u4e4b\u95f4\u7684\u8fd9\u90e8\u5206\u533a\u57df\u5bfb\u627e\u7a7a\u95f2\u533a\u5e76\u5206\u914d\u3002\u7533\u8bf7\u5185\u5b58\u65f6\u9075\u5faa\u5185\u5b58\u5bf9\u9f50\u539f\u5219\u3002<br \/>\n\u7533\u8bf7\u548c\u91ca\u653e\u5185\u5b58\u7684\u8fc7\u7a0b\u5982\u4e0b\u56fe<br \/>\n<a href=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b585.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1089\" src=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b585.png\" alt=\"\" width=\"525\" height=\"777\" srcset=\"http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b585.png 525w, http:\/\/www.mrtblog.cn\/wp-content\/uploads\/2021\/02\/linux\u865a\u62df\u5185\u5b585-203x300.png 203w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><br \/>\n\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u4f7f\u7528mmap\u7533\u8bf7\u7684\u5185\u5b58\u5728free\u65f6\u4f1a\u4f7f\u7528mummap\u91ca\u653e\uff0c\u4f46\u662fbrk\u7533\u8bf7\u7684\u5185\u5b58\u5e76\u6ca1\u6709\u771f\u6b63\u7684\u91ca\u653e\uff0c\u800c\u662f\u4ec5\u4ec5\u6e05\u9664\u4e86\u6570\u636e\uff0c\u6b64\u65f6brk\u6307\u9488\u4f9d\u7136\u6307\u5411\u5806\u7684\u9876\u7aef<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,349 Views\u89c2\u5bdf\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801 size_t all_size = 4000000000; int * [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112,102],"tags":[],"class_list":["post-1084","post","type-post","status-publish","format-standard","hentry","category-112","category-102"],"_links":{"self":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/1084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1084"}],"version-history":[{"count":4,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/1084\/revisions"}],"predecessor-version":[{"id":1120,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/1084\/revisions\/1120"}],"wp:attachment":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1084"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}