{"id":1193,"date":"2022-03-06T20:24:23","date_gmt":"2022-03-06T12:24:23","guid":{"rendered":"https:\/\/www.xianwaizhiyin.net\/?p=1193"},"modified":"2022-06-11T02:29:02","modified_gmt":"2022-06-10T18:29:02","slug":"st%e6%ba%90%e7%a0%81%e5%88%86%e6%9e%90-st_thread_create","status":"publish","type":"post","link":"https:\/\/www.xianwaizhiyin.net\/?p=1193","title":{"rendered":"ST\u6e90\u7801\u5206\u6790-st_thread_create"},"content":{"rendered":"\n<p>\u672c\u6587 \u4e3b\u8981\u5206\u6790 <code class=\"prettyprint\" >st_thread_create()<\/code> \u51fd\u6570\u7684\u5185\u90e8\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p><code class=\"prettyprint\" >st_thread_create<\/code> \u6d41\u7a0b\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"460\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png\" alt=\"\" class=\"wp-image-1196\"\/><\/figure>\n\n\n\n<p>\u73b0\u5728\u5f00\u59cb\u4e00\u884c\u4e00\u884c\u4ee3\u7801\u5206\u6790 <code class=\"prettyprint\" >st_thread_create<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >  _st_thread_t *thread;\n  _st_stack_t *stack;\n  void **ptds;\n  char *sp;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u4ee3\u7801\u58f0\u660e\u4e86 4 \u4e2a\u53d8\u91cf \uff0c\u53d8\u91cf <code class=\"prettyprint\" >ptds<\/code> \u7684\u5168\u79f0\u5e94\u8be5\u662f pthread_data_register\uff08\u7ebf\u7a0b\u7684\u5bc4\u5b58\u5668\u7f13\u5b58\uff09\uff0csp \u7684\u5168\u79f0 \u662f stack point\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Adjust stack size *\/\nif (stk_size == 0)\n  stk_size = ST_DEFAULT_STACK_SIZE;\nstk_size = ((stk_size + _ST_PAGE_SIZE - 1) \/ _ST_PAGE_SIZE) * _ST_PAGE_SIZE;\nstack = _st_stack_new(stk_size);\nif (!stack)\n  return NULL;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u5f00\u59cb\u7533\u8bf7 \u6808\u5185\u5b58\uff0c<code class=\"prettyprint\" >ST_DEFAULT_STACK_SIZE<\/code> \u662f (64*1024) \uff0c\u4e5f\u5c31\u662f 64Kb \u9ed8\u8ba4\u5185\u5b58\u3002\u8fd8\u6709\u4e00\u4e2a \u5b8f\u5b9a\u4e49 <code>_ST_PAGE_SIZE<\/code>\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define _ST_PAGE_SIZE                   (_st_this_vp.pagesize)<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >_st_this_vp.pagesize<\/code> \u662f\u7528 <code>getpagesize()<\/code> \u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u5b58\u9875\u5927\u5c0f\u3002\u6240\u4ee5\u4e0b\u9762\u7684\u8fd9\u884c\u4ee3\u7801\uff0c\u53c8\u4e58\uff0c\u53c8\u9664\uff0c\u5b9e\u9645\u4e0a\u662f\u4e3a\u4e86\u5f97\u51fa \u64cd\u4f5c\u7cfb\u7edf\u5185\u5b58\u9875\u5927\u5c0f \u7684\u500d\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >stk_size = ((stk_size + _ST_PAGE_SIZE - 1) \/ _ST_PAGE_SIZE) * _ST_PAGE_SIZE;<\/code><\/pre>\n\n\n\n<p>\u4e3a\u4ec0\u4e48 stk_size \u8981\u662f \u64cd\u4f5c\u7cfb\u7edf \u5185\u5b58\u9875\u5927\u5c0f\u7684 <strong>\u500d\u6570<\/strong> \uff0c\u8fd9\u4e2a\u6d89\u53ca\u5230\u5185\u5b58\u5bf9\u9f50\uff0c\u865a\u62df\u5185\u5b58\u8ddf\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\u539f\u7406\uff0c\u901a\u4fd7\u6765\u8bf4\uff0c\u662f\u4e3a\u4e86\u8ba9\u5185\u5b58\u4f7f\u7528\u66f4\u52a0\u9ad8\u6548\uff0c\u63a8\u8350\u9605\u8bfb<\/p>\n\n\n\n<p>\u300a<a href=\"https:\/\/www.cnblogs.com\/myseries\/p\/12487211.html\">\u64cd\u4f5c\u7cfb\u7edf \u865a\u62df\u5185\u5b58 \u3001\u5206\u6bb5\u3001\u5206\u9875\u7684\u7406\u89e3<\/a>\u300b<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>google_ads_content<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u7136\u540e \u5c31\u8c03 <code class=\"prettyprint\" >_st_stack_new()<\/code> \u51fd\u6570 \u6765\u7533\u8bf7\u5185\u5b58\u3002\u5728 \u8bb2 <code>_st_stack_new<\/code> \u51fd\u6570\u7684\u5185\u90e8\u903b\u8f91 \u4e4b\u524d\uff0c\u5148\u666e\u53ca\u4e00\u4e0b <code>mmap<\/code> \u8ddf <code>calloc<\/code> \u7684\u533a\u522b\u3002<\/p>\n\n\n\n<p><code class=\"prettyprint\" >mmap<\/code> \u7684\u4e00\u4e2a\u5e38\u89c1\u7684\u7528\u6cd5\uff0c\u662f\u628a\u6587\u4ef6\u6620\u5c04\u5230\u5185\u5b58\uff0c\u4f8b\u5982\u628a 2G \u7684\u5927\u6587\u4ef6\u6620\u5c04\u5230\u5185\u5b58\uff0c\u7136\u540e\u5199\u5185\u5b58\u5c31\u76f8\u5f53\u4e8e\u5199\u6587\u4ef6\uff0c\u4f46\u662f\u5e76\u4e0d\u4f1a\u5360\u7528 2G \u7684\u7269\u7406\u5185\u5b58\u3002mmap \u4ed6\u8fd9\u4e2a\u6620\u5c04\u662f\u865a\u62df\u7684\uff0c\u5982\u679c\u4e0d\u4f7f\u7528\u6587\u4ef6\u6620\u5c04\uff0c\u53ef\u4ee5\u628a fd \u8bbe\u7f6e\u4e3a -1 \u5c31\u662f <strong>\u533f\u540d\u6620\u5c04<\/strong>\u3002\u800c calloc \u51fd\u6570\u7533\u8bf7\u7684\u662f\u5b9e\u5b9e\u5728\u5728\u7684\u7269\u7406\u5185\u5b58\uff0c\u7269\u7406\u5185\u5b58\u7684\u4f7f\u7528\u91cf\u4f1a\u589e\u52a0\u3002<\/p>\n\n\n\n<p>mmap \u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#include &lt;unistd.h&gt;\n#include &lt;sys\/mman.h&gt;\n\u200b\nint main() {\n    void* vaddr = mmap(NULL, 1024 * 1024 * 1024 * 1, PROT_READ | PROT_WRITE, 34, -1, 0);\n    sleep(600);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>calloc \u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#include &lt;unistd.h&gt;\n#include &lt;stdlib.h&gt;\n\u200b\nint main() {\n    void* vaddr = calloc(1, 1024 * 1024 * 1024 * 1);\n    sleep(600);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u547d\u4ee4\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >gcc -o calloc calloc.c<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u7528 <code class=\"prettyprint\" >top -p 100054<\/code> \u67e5\u770b\u6307\u5b9a\u8fdb\u7a0b\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"183\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-1.png\" alt=\"\" class=\"wp-image-1197\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u56de\u5230 <code class=\"prettyprint\" >_st_stack_new()<\/code> \u51fd\u6570\u7684\u5206\u6790\uff0c\u6d41\u7a0b\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"548\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-1-1.png\" alt=\"\" class=\"wp-image-1198\"\/><\/figure>\n\n\n\n<p>\u4ece\u6d41\u7a0b\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c<code class=\"prettyprint\" >_st_stack_new<\/code> \u51fd\u6570\u4e3b\u8981\u6709\u4e24\u4e2a\u91cd\u70b9\uff1a<\/p>\n\n\n\n<p>1\uff0c\u7528 calloc \u6765\u7533\u8bf7\u4e00\u5757\u5185\u5b58\uff0c<code class=\"prettyprint\" >_st_stack_t<\/code> \u8fd9\u4e2a\u7ed3\u6784\u4f53\u662f 56 \u5b57\u8282\uff0c\u56e0\u4e3a calloc \u4f1a\u521d\u59cb\u5316\u4e3a 0\uff0c\u4f1a\u5bfc\u81f4 commit\u3002\u6240\u4ee5\u7269\u7406\u5185\u5b58\u7684\u4f7f\u7528\u662f\u5b9e\u5b9e\u5728\u5728\u589e\u52a0\u4e86 56 \u5b57\u8282\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL)\n    return NULL;<\/code><\/pre>\n\n\n\n<p>2\uff0c\u7528 <code class=\"prettyprint\" >_st_new_stk_segment<\/code> \u6765\u7533\u8bf7\u6808\u7684\u5b9e\u9645\u5185\u5b58\uff0c<code>_st_new_stk_segment<\/code> \u51fd\u6570\u6bd4\u8f83\u7b80\u5355\uff0c\u5c31\u662f\u5bf9 <code>mmap<\/code> \u5c01\u88c5\u4e00\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ REDZONE \u7b49\u4e8e\u4e00\u4e2a\u5185\u5b58\u9875\u5927\u5c0f\nts-&gt;vaddr_size = stack_size + 2*REDZONE + extra;\nts-&gt;vaddr = _st_new_stk_segment(ts-&gt;vaddr_size);<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >st_thread_create()<\/code> \u51fd\u6570\u4f20\u7ed9 <code>_st_stack_new()<\/code> \u51fd\u6570\u7684 <code>stack_size<\/code> \u53c2\u6570\u662f 65536 \uff0c\u4e5f\u5c31\u662f 64 \u5b57\u8282\uff0c\u4f46\u662f\u4e0d\u4f1a\u7acb\u9a6c\u4f7f\u7528 64 kb \u7684\u7269\u7406\u5185\u5b58\uff0c\u56e0\u4e3a\u7528\u7684\u662f mmap\u3002\u4e0d\u662f calloc\u3002\u6ce8\u610f\uff0c\u5b9e\u9645\u4e0a \u4ed6\u8fd8\u52a0\u4e86 <strong>2*REDZONE<\/strong>\uff0c\u591a\u4e86\u4e24\u4e2a\u5185\u5b58\u9875\u5927\u5c0f\u3002\u4e3a\u4ec0\u4e48\u8981\u5197\u4f59\u4e24\u4e2a\u5185\u5b58\u9875\u5927\u5c0f\uff0c\u8bf7\u770b\u6587\u7ae0<a href=\"https:\/\/www.xianwaizhiyin.net\/?p=1356\">\u300aST\u6e90\u7801\u5206\u6790-\u5185\u5b58\u4fdd\u62a4\u300b<\/a>\u3002<\/p>\n\n\n\n<p><code class=\"prettyprint\" >_st_free_stack<\/code> \u7684\u903b\u8f91\u672c\u6587\u4e0d\u4f1a\u8bb2\u89e3\u592a\u591a\uff0c\u56e0\u4e3a\u8fd9\u662f\u5165\u95e8\u6559\u7a0b\uff0c\u7b2c\u4e00\u6b21\u8c03 <code>_st_stack_new()<\/code> \u662f\u4e0d\u4f1a\u8dd1\u8fdb\u53bb <code>_st_free_stack<\/code> \u6761\u4ef6\u7684\uff0c\u4e0d\u4f1a\u8dd1\u8fdb\u53bb\u7684\u903b\u8f91\u672c\u6587\u4e0d\u4f1a\u8bb2\u89e3\u592a\u591a\uff0c\u529b\u6c42\u7b80\u5355\u3002<\/p>\n\n\n\n<p>_st_stack_new \u8fd0\u884c\u540e\u4e4b\u540e\uff0c\u6574\u4e2a\u6808\u5185\u5b58\u7684\u7ed3\u6784\u662f\u8fd9\u6837\u7684...<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"272\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-1-v2.png\" alt=\"\" class=\"wp-image-1349\" srcset=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-1-v2.png 335w, https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-1-v2-300x244.png 300w\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u8c03\u7528<code class=\"prettyprint\" >_st_stack_new()<\/code> \u62ff\u5230\u8fd9\u4e48\u4e00\u4e2a \u6808\u7ed3\u6784\u4e4b\u540e\uff0c\u56de\u5230 <code>st_thread_create()<\/code> \u7684\u903b\u8f91\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#if defined (MD_STACK_GROWS_DOWN)\n  sp = stack-&gt;stk_top;\n#ifdef<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u6211\u7684\u73af\u5883 \u6808\u662f\u5411\u4e0b\u538b\u7684\uff0c\u6240\u4ee5 MD_STACK_GROWS_DOWN \u5b9a\u4e49\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sp = sp - (ST_KEYS_MAX * sizeof(void *));\nptds = (void **) sp;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\uff0cST_KEYS_MAX \u7b49\u4e8e 16\uff0c(void *) \u5728 32\u4f4d\u5360 4\u5b57\u8282\uff0c\u5728 64 \u4f4d\u5360 8\u5b57\u8282\u3002\u6240\u4ee5\u4e0a\u9762\u7684\u4ee3\u7801\u903b\u8f91\u662f \u4ece\u4e4b\u524d\u7533\u8bf7\u7684\u5185\u5b58\u91cc\u9762\u62ff\u51fa 16 * 8 \u4e2a\u5b57\u8282\u7684\u5185\u5b58 \u5b58\u50a8\u534f\u7a0b\u7684\u79c1\u6709\u6570\u636e\uff0c\u8fd9\u5757\u5185\u5b58\u5728 ST \u4ee3\u7801\u91cc\u6ca1\u6709\u4f7f\u7528\uff0c\u662f\u7559\u7ed9\u4f7f\u7528\u8005\u81ea\u7531\u53d1\u6325\u7684\u3002\u60f3\u5b58\u4ec0\u4e48\u5c31\u5b58\u4ec0\u4e48\u53d8\u91cf <code class=\"prettyprint\" >ptds<\/code> \u7684\u5168\u79f0\u662f <code>private_data<\/code>\uff0c<code>ptds<\/code> \u6307\u5411\u6570\u636e\u7684\u5f00\u59cb\u5730\u5740\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sp = sp - sizeof(_st_thread_t);\nthread = (_st_thread_t *) sp;<\/code><\/pre>\n\n\n\n<p>\u518d \u4ece \u4e4b\u524d\u7533\u8bf7\u7684\u5185\u5b58\u91cc\u9762\u62ff\u51fa <code class=\"prettyprint\" >sizeof(_st_thread_t)<\/code> \u5927\u5c0f\u7684\u5185\u5b58\u6765\u5b58\u50a8 <code>_st_thread_t<\/code> \u534f\u7a0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Make stack 64-byte aligned *\/\nif ((unsigned long)sp &amp; 0x3f)\n  sp = sp - ((unsigned long)sp &amp; 0x3f);\nstack-&gt;sp = sp - _ST_STACK_PAD_SIZE;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c31\u662f\u628a <code class=\"prettyprint\" >sp<\/code> \u505a 64\u4f4d\u5bf9\u9f50\uff0c\u6700\u540e \u518d\u62ff\u8d70 <code>_ST_STACK_PAD_SIZE<\/code> \u5927\u5c0f\u7684\u5185\u5b58\uff0c<code>_ST_STACK_PAD_SIZE<\/code> \u7b49\u4e8e 128 \u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u5168\u90e8\u4ee3\u7801\u6267\u884c\u5b8c\u4e4b\u540e\uff0c\u6808\u7684\u5185\u5b58\u5e03\u5c40\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"539\" height=\"440\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4.png\" alt=\"\" class=\"wp-image-1375\" srcset=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4.png 539w, https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4-300x245.png 300w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><\/figure>\n\n\n\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c<code class=\"prettyprint\" >stack-&gt;stk_bottom<\/code> ~ <code>stack-&gt;stk_sp<\/code> \u4e2d\u95f4\u7684\u7a7a\u767d\u533a\u57df\uff0c\u8fd9\u5757\u533a\u57df \u662f \u534f\u7a0b\u51fd\u6570\u5c40\u90e8\u53d8\u91cf\u7528\u7684\u3002\u8bf7\u770b\u6587\u7ae0<strong><a href=\"https:\/\/www.xianwaizhiyin.net\/?p=1363\">\u300aST\u6e90\u7801\u5206\u6790-\u534f\u7a0b\u5c40\u90e8\u53d8\u91cf\u300b<\/a><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u7ee7\u7eed \u5206\u6790 <code class=\"prettyprint\" >st_thread_create()<\/code> \u7684\u540e\u7eed\u4ee3\u7801\u903b\u8f91\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >memset(thread, 0, sizeof(_st_thread_t));\nmemset(ptds, 0, ST_KEYS_MAX * sizeof(void *));\n\u200b\n\/* Initialize thread *\/\nthread-&gt;private_data = ptds;\nthread-&gt;stack = stack;\nthread-&gt;start = start;\nthread-&gt;arg = arg;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u8fd9\u4e9b\u90fd\u662f \u53d8\u91cf\u64cd\u4f5c\uff0c\u521d\u59cb\u5316\u903b\u8f91\uff0c\u8df3\u8fc7\uff0c\u7ee7\u7eed\u770b\u4e0b\u9762\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >_ST_INIT_CONTEXT(thread, stack-&gt;sp, _st_thread_main);<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >_ST_INIT_CONTEXT<\/code> \u5b9e\u9645\u4e0a\u5c31\u662f <code>MD_INIT_CONTEXT<\/code>\uff0c\u6211\u7684\u73af\u5883\u662f <code>Linux<\/code> + <code>x86_64<\/code>\uff0c\u6240\u4ee5<code>MD_INIT_CONTEXT<\/code> \u5b8f\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define MD_INIT_CONTEXT(_thread, _sp, _main) \\\n  ST_BEGIN_MACRO                             \\\n  if (MD_SETJMP((_thread)-&gt;context))         \\\n    _main();                                 \\\n  MD_GET_SP(_thread) = (long) (_sp);         \\\n  ST_END_MACRO<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >MD_SETJMP<\/code> \u5b8f\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define MD_SETJMP(env) _st_md_cxt_save(env)<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >_st_md_cxt_save<\/code> \u51fd\u6570\u7684\u6c47\u7f16\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >.globl _st_md_cxt_save\n        .type _st_md_cxt_save, @function\n        .align 16\n_st_md_cxt_save:\n        \/*\n         * Save registers.\n         *\/\n        movq %rbx, (JB_RBX*8)(%rdi)\n        movq %rbp, (JB_RBP*8)(%rdi)\n        movq %r12, (JB_R12*8)(%rdi)\n        movq %r13, (JB_R13*8)(%rdi)\n        movq %r14, (JB_R14*8)(%rdi)\n        movq %r15, (JB_R15*8)(%rdi)\n        \/* Save SP *\/\n        leaq 8(%rsp), %rdx\n        movq %rdx, (JB_RSP*8)(%rdi)\n        \/* Save PC we are returning to *\/\n        movq (%rsp), %rax\n        movq %rax, (JB_PC*8)(%rdi)\n        xorq %rax, %rax\n        ret\n        .size _st_md_cxt_save, .-_st_md_cxt_save<\/code><\/pre>\n\n\n\n<p>\u56de\u5230 <code class=\"prettyprint\" >MD_SETJMP((_thread)-&gt;context)<\/code> \u8fd9\u91cc\u7684 context \u662f\u4e00\u4e2a <code>jmp_buf<\/code> \u7684\u7ed3\u6784\uff0c <code>jmp_buf<\/code> \u662f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\uff0c\u63a8\u8350\u9605\u8bfb\u300a<a href=\"https:\/\/www.xianwaizhiyin.net\/?p=1163\">ST\u6e90\u7801\u5206\u6790-setjmp<\/a>\u300b\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u7406\u6e05\u695a <code class=\"prettyprint\" >MD_SETJMP((_thread)-&gt;context)<\/code> \u8fd9\u53e5\u4ee3\u7801\u5e72\u4e86\u4ec0\u4e48\u4e8b\u60c5\uff0c\u9700\u8981\u4e00\u6b65\u4e00\u6b65\u5206\u6790\u3002<\/p>\n\n\n\n<p><code class=\"prettyprint\" >MD_SETJMP((_thread)-&gt;context)<\/code> \u7b49\u4e8e <code>_st_md_cxt_save(env)<\/code>\uff0c<code>_st_md_cxt_save<\/code> \u662f\u4e00\u4e2a\u6c47\u7f16\u51fd\u6570\uff0c\u4e4b\u524d\u6ca1\u6709\u8bb2\u8fc7 \u6c47\u7f16\u51fd\u6570\uff0c\u5982\u679c\u4f20\u53c2\uff0c\u8fd9\u4e2a\u53c2\u6570\u662f\u600e\u4e48\u538b\u8fdb\u53bb\u5806\u6808\uff0c\u5bc4\u5b58\u5668\u53c8\u662f\u5982\u4f55\u53d8\u6362\uff0c\u73b0\u5728\u5c31\u7528 gdb \u6f14\u793a\u4e00\u6b21\u3002\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >gdb .\/obj\/lookupdns\n# \u8bbe\u7f6e\u53c2\u6570\nset args xianwaizhiyin.net www.baidu.com\n# \u65ad\u70b9 1\nb *st_thread_create\n# \u65ad\u70b9 2\nb sched.c:588\n# \u67e5\u770b \u5bc4\u5b58\u5668\nlayout regs\n# \u67e5\u770b C \u6e90\u7801\nlayout src\n# \u67e5\u770b \u6c47\u7f16 \u6e90\u7801\nlayout asm\n# \u6253\u5370\u5730\u5740\nprint &amp;(thread-&gt;context)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"923\" height=\"662\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-3.png\" alt=\"\" class=\"wp-image-1201\"\/><\/figure>\n\n\n\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u5728\u8c03 <code class=\"prettyprint\" >callq<\/code> \u4e4b\u524d \uff0c<code>rax<\/code> \u8ddf <code>rdi<\/code> \u7684\u503c \u5c31\u662f <code>thread-&gt;context<\/code> \u7684\u5185\u5b58\u5730\u5740\u3002\u6240\u4ee5\u53c2\u6570 <code>env<\/code> \u662f\u901a\u8fc7 <code>rdi<\/code> \u5bc4\u5b58\u5668\u4f20\u8fdb\u53bb\u7ed9 <code>_st_md_cxt_save<\/code> \u51fd\u6570\u7528\u7684\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7ee7\u7eed \u5206\u6790 <code class=\"prettyprint\" >_st_md_cxt_save<\/code> \u51fd\u6570\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >_st_md_cxt_save:\n        \/*\n         * Save registers.\n         *\/\n        movq %rbx, (JB_RBX*8)(%rdi)\n        movq %rbp, (JB_RBP*8)(%rdi)\n        movq %r12, (JB_R12*8)(%rdi)\n        movq %r13, (JB_R13*8)(%rdi)\n        movq %r14, (JB_R14*8)(%rdi)\n        movq %r15, (JB_R15*8)(%rdi)<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4ece\u903b\u8f91\u662f\u770b\uff0c\u5c31\u662f\u4fdd\u5b58 6 \u4e2a\u5bc4\u5b58\u5668 \u7684\u503c\u5230 <code class=\"prettyprint\" >pthread-&gt;context<\/code> \uff08jmp_buf\uff09\u91cc\u9762\u3002<\/p>\n\n\n\n<p>\u4ed6\u8fd9\u4e2a\u662f\u76f4\u63a5\u641e\u6e05\u695a\u4e86 jmp_buf \u7684\u5185\u5b58\u5e03\u5c40\uff0c\u7136\u540e\u6309\u5b57\u6bb5\u6765\u586b\u6570\u636e\u3002\u6ca1\u6709\u76f4\u63a5\u7528 C\u8bed\u8a00\u7684\u51fd\u6570 <code class=\"prettyprint\" >setjmp()<\/code> \u8ddf <code>longjmp()<\/code> \u6765\u64cd\u4f5c <code>jmp_buf<\/code>\uff0c\u800c\u662f\u81ea\u5df1\u5199\u6c47\u7f16\u6765\u64cd\u4f5c <code>jmp_buf<\/code>\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c55\u793a\u4e00\u4e0b <code class=\"prettyprint\" >jmp_buf<\/code> \u7684\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Calling environment, plus possibly a saved signal mask.  *\/\nstruct __jmp_buf_tag\n  {\n    \/* NOTE: The machine-dependent definitions of `__sigsetjmp&#039;\n       assume that a `jmp_buf&#039; begins with a `__jmp_buf&#039; and that\n       `__mask_was_saved&#039; follows it.  Do not move these members\n       or add others before it.  *\/\n    __jmp_buf __jmpbuf;     \/* Calling environment.  *\/\n    int __mask_was_saved;   \/* Saved the signal mask?  *\/\n    __sigset_t __saved_mask;    \/* Saved signal mask.  *\/\n  };\n\u200b\n\u200b\ntypedef struct __jmp_buf_tag jmp_buf&#091;1];<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684 jmp_buf[1] \u5b9e\u9645\u4e0a\u5c31\u662f \u5b9a\u4e49\u4e00\u4e2a\u6570\u636e\uff0c<code class=\"prettyprint\" >jmp_buf<\/code> \u5c31\u7b49\u4e8e <code>__jmp_buf_tag[1]<\/code> \u3002<code>struct __jmp_buf_tag = {0}<\/code> \u8ddf <code>struct __jmp_buf_tag[1] = {0}<\/code> \u662f\u4e0d\u4e00\u6837\u7684\uff0c\u540e\u9762\u7684\u662f <code>__jmp_buf_tag*<\/code> \u662f\u6307\u9488\u3002<\/p>\n\n\n\n<p><code class=\"prettyprint\" >__jmp_buf<\/code> \u7684\u5b9a\u4e49\u5982\u4e0b\uff0c\u662f\u4e00\u4e2a 8 \u5143\u7d20\u7684\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >typedef long int __jmp_buf&#091;8];<\/code><\/pre>\n\n\n\n<p>\u63a5\u7740\u770b\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Save SP *\/\nleaq 8(%rsp), %rdx\nmovq %rdx, (JB_RSP*8)(%rdi)\n\/* Save PC we are returning to *\/\nmovq (%rsp), %rax\nmovq %rax, (JB_PC*8)(%rdi)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7528\u7684\u662f <code class=\"prettyprint\" >lea<\/code> \u6307\u4ee4\uff0c<code>lea<\/code> \u4f1a\u628a <code>8(%rsp)<\/code> \u8fd9\u4e2a\u5185\u5b58\u5730\u5740 <code>\u8d4b\u503c\u7ed9<\/code> <code>rdx<\/code> \u5bc4\u5b58\u5668 \uff0c\u800c\u4e0d\u662f\u628a \u5185\u5b58\u5730\u5740\u7684<strong>\u6570\u636e<\/strong>\u8d4b\u503c\u7ed9 <code>rdx<\/code> \u5bc4\u5b58\u5668\uff0c\u8fd9\u4e2a\u8ddf <code>mov<\/code> \u6709\u5dee\u5f02 \uff0c \u63a8\u8350\u9605\u8bfb<a href=\"https:\/\/www.zhihu.com\/question\/40720890\">\u300a\u6c47\u7f16\u8bed\u8a00\u4e2dmov\u548clea\u7684\u533a\u522b\u6709\u54ea\u4e9b\uff1f\u300b<\/a><\/p>\n\n\n\n<p>\u4e0a\u9762\u7684 <code class=\"prettyprint\" >Save SP<\/code> \u5c31\u662f\u628a <code>rsp+8<\/code> \u7136\u540e\u4fdd\u5b58\u8fdb\u53bb <code>jmf_buf<\/code> \u91cc\u9762\uff0c\u4e3a\u4ec0\u4e48\u8981\u52a0 8 \uff1f<code>rsp + 8<\/code> \u5c31\u662f\u6ca1 call <code>_st_md_cxt_save<\/code> \u51fd\u6570\u4e4b\u524d\u7684 <code>rsp<\/code> \u7684\u503c\uff0c\u56e0\u4e3a call \u4f1a\u628a rsp \u51cf 8 \u5b57\u8282\u3002\u8fd9\u91cc \u4fdd\u5b58 <code>rsp+8<\/code> \u7684\u503c\uff0c\u5e94\u8be5\u662f\u591a\u4f59\u7684\uff0c\u56e0\u4e3a\u4f1a\u88ab\u540e\u9762\u7684 <code>MD_GET_SP(thread) = (long) (stack-&gt;sp);<\/code> \u8986\u76d6\u6389\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u518d\u628a <code class=\"prettyprint\" >rsp<\/code> \u7684\u503c \u4fdd\u5b58\u5230 <code>jmf_buf<\/code> \u3002PC \u662f Program Counter \u7684\u7f29\u5199\uff0c\u7528\u4e8e\u6307\u793a\u5f53\u524d\u5c06\u8981\u6267\u884c\u7684\u4e0b\u4e00\u6761\u673a\u5668\u6307\u4ee4\u7684\u5185\u5b58\u5730\u5740 \uff0c\u4e5f\u5c31\u662f EIP \u5bc4\u5b58\u5668\u3002<\/p>\n\n\n\n<p>\u6b64\u65f6\u6b64\u523b <code class=\"prettyprint\" >rsp<\/code> ~ <code>rsp +8<\/code> \u8fd9 8 \u5b57\u8282\u5185\u5b58\uff0c\u5b58\u7684\u662f\u4ec0\u4e48\u5462\uff1f\u5b58\u7684\u662f \u8c03 call \u7684\u4e0a\u5c42\u51fd\u6570\u7684\u4e0b\u4e00\u6761\u6307\u4ee4\u7684\u4f4d\u7f6e\uff0c\u5728 C\u4ee3\u7801\u91cc\u9762\u5c31\u662f \u4e0b\u9762\u7684 if \u5224\u65ad \u8fd4\u56de\u503c\uff0c<\/p>\n\n\n\n<p><code class=\"prettyprint\" >if (MD_SETJMP((_thread)-&gt;context))<\/code> \u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a \u6267\u884c\u5b8c call \u4e4b\u540e\u8981\u8df3\u56de\u8c03\u4e0a\u5c42\u8c03\u7528\u4e0b\u4e00\u884c\u6307\u4ee4\u7684\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u4f4d\u7f6e \u5c31\u5b58\u5728 <code class=\"prettyprint\" >rsp<\/code> ~ <code>rsp +8<\/code> \u8fd9 8 \u5b57\u8282\u5185\u5b58 \u91cc\u9762\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"622\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-4.png\" alt=\"\" class=\"wp-image-1202\"\/><\/figure>\n\n\n\n<p>\u4e0a\u56fe\uff0c\u662f\u521a\u521a\u7528 <code class=\"prettyprint\" >si<\/code> \u8df3\u8fdb\u53bb <code>call<\/code> \u91cc\u9762\uff0c<code>call<\/code> \u6307\u4ee4\u5df2\u7ecf\u6267\u884c\u4e86\uff0c\u4f46\u662f\u91cc\u9762\u7684\u6307\u4ee4\u8fd8\u6ca1\u6267\u884c\uff0c\u6b64\u65f6\u6b64\u523b 0x7fffffffde88 ~ 0x7fffffffde90 \u5b58\u7684\u5c31\u662f <code>st_thread_create<\/code> \u51fd\u6570\u7684\u4e0b\u4e00\u6761\u6307\u4ee4\u3002<\/p>\n\n\n\n<p>\u4fdd\u5b58\u597d\u8fd9\u4e9b\u4e1c\u897f \u8fdb\u53bb <code class=\"prettyprint\" >jmp_buf<\/code> \u4e4b\u540e\uff0c\u5c31\u4f1a\u64cd\u4f5c <code>rax<\/code> \u641e\u8fd4\u56de\u503c \uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >xorq %rax, %rax<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u8fd9\u53e5\u4ee3\u7801\u662f\u5f02\u6216\u64cd\u4f5c\uff0c\u53ea\u662f\u628a <code class=\"prettyprint\" >rax<\/code> \u641e\u6210 0 \uff0c\u5e76\u6ca1\u6709\u4ec0\u4e48\u7279\u522b\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>google_ads_content<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><code class=\"prettyprint\" >_st_md_cxt_save<\/code> \u6267\u884c\u5b8c\u4e86\uff0c\u56de\u8c03\u4e4b\u524d\u7684 \u5b8f\u51fd\u6570 \u3002\u7531\u4e8e MD_SETJMP \u628a <code>rax<\/code> \u641e\u6210 0 \uff0c\u6240\u4ee5\u4e0b\u9762\u7684 <code>_main()<\/code> \u5e76\u4e0d\u4f1a\u6267\u884c\u3002\u90a3 <code>_main()<\/code> \u4ec0\u4e48\u65f6\u5019\u6267\u884c\u5462\uff1f\u8fd9\u91cc\u5148\u7b80\u5355\u5267\u900f\u4e00\u4e0b\uff0c\u5728 <code>_st_md_cxt_restore()<\/code> \u51fd\u6570\u91cc\u9762\u4f1a\u628a <code>rax<\/code> \u8bbe\u7f6e \u4e3a 1 \uff0c\u518d\u8df3\u56de\u5230\u8fd9\u4e2a <code>if<\/code> \u5224\u65ad\u3002\u56e0\u4e3a <code>MD_SETJMP<\/code> \u5df2\u7ecf\u628a <code>if<\/code> \u4ee3\u7801\u7684\u6307\u4ee4\u5730\u5740 \u5b58\u8fdb\u53bb jmp_buf\u91cc\u9762\u4e86\uff0c\u6240\u4ee5\u53ef\u4ee5\u8df3\u56de\u6765\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define MD_INIT_CONTEXT(_thread, _sp, _main) \\\n  ST_BEGIN_MACRO                             \\\n  if (MD_SETJMP((_thread)-&gt;context))         \\\n    _main();                                 \\\n  MD_GET_SP(_thread) = (long) (_sp);         \\\n  ST_END_MACRO<\/code><\/pre>\n\n\n\n<p>\u6240\u4ee5\u4e0a\u9762\u7684\u4ee3\u7801\uff0c <code class=\"prettyprint\" >if<\/code> \u6267\u884c\u4e4b\u540e\uff0c\u53ea\u4f1a\u6267\u884c \u4e0b\u9762\u8fd9\u53e5\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >MD_GET_SP(_thread) = (long) (_sp);<\/code><\/pre>\n\n\n\n<p><code class=\"prettyprint\" >MD_GET_SP<\/code> \u5b8f\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define MD_GET_SP(_t) (_t)-&gt;context&#091;0].__jmpbuf&#091;JB_RSP]<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e \u53c2\u6570 <code class=\"prettyprint\" >_sp<\/code> \u662f <code>stack-&gt;sp<\/code>\uff0c\u6240\u4ee5\u662f\u628a <code>stack-&gt;sp<\/code> \u5b58\u50a8\u5728<code>__jmpbuf[JB_RSP]<\/code> \u7684\u4f4d\u7f6e\uff0c\u4f46\u4e4b\u524d\u5728 <code>_st_md_cxt_save<\/code> \u91cc\u9762\uff0c<code>__jmpbuf[JB_RSP]<\/code> \u5df2\u7ecf\u88ab\u7528\u4e86\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Save SP *\/\nleaq 8(%rsp), %rdx\nmovq %rdx, (JB_RSP*8)(%rdi)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u53c8\u4f1a\u88ab\u8986\u76d6\uff0c\u4e3a\u4ec0\u4e48\u8981\u8986\u76d6\uff0c\u8fd9\u91cc\u4f30\u8ba1\u662f\u4f5c\u8005\u5199\u591a\u4e86\u3002\u6211\u628a\u4ed6\u8fd9\u53e5 <code class=\"prettyprint\" >movq %rdx, (JB_RSP*8)(%rdi)<\/code> \u6ce8\u91ca\u6389\u4e5f\u6ca1\u95ee\u9898\uff0c\u8865\u5145\uff1a\u8fd9\u91cc\u53ef\u80fd\u662f\u5176\u4ed6\u5e73\u53f0\u4f1a\u7528\u5230\u8fd9\u53e5 <code>movq<\/code>\u3002\u8986\u76d6\u4e4b\u540e\u7684\u60c5\u51b5\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"754\" height=\"298\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-7.png\" alt=\"\" class=\"wp-image-1195\"\/><\/figure>\n\n\n\n<p><strong><code class=\"prettyprint\" >MD_GET_SP<\/code> \u662f\u91cd\u91cf\u7ea7\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u628a \u521a\u521a\u7533\u8bf7\u7684\u5185\u5b58\u7684\u90a3\u6bb5\u8fd8\u672a\u4f7f\u7528\u7684\u7a7a\u767d\u5185\u5b58\uff0c\u4f5c\u4e3a\u534f\u7a0b\u51fd\u6570\u7684\u6808\u5185\u5b58\u3002<\/strong> \u4ec0\u4e48\u662f\u534f\u7a0b\u51fd\u6570\u7684\u6808\u5185\u5b58\uff0c\u9996\u5148\uff0c\u534f\u7a0b\u51fd\u6570\u91cc\u9762\u5982\u679c\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\uff0c\u662f\u4e0d\u662f\u8981\u538b\u6808\uff1f\u5c31\u4f1a\u628a <code>RSP<\/code> \u51cf\u5c11\uff0c\u628a\u5c40\u90e8\u53d8\u91cf\u5199\u8fdb\u53bb RSP \u5bc4\u5b58\u5668\u6307\u5411\u7684\u5185\u5b58\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u4e0a\u9762 \u628a <code class=\"prettyprint\" >(_t)-&gt;context[0].__jmpbuf[JB_RSP]<\/code> \u4fee\u6539\u4e3a <code>stack-&gt;sp<\/code> \u5c31\u662f\u4e3a\u4e86\u5206\u914d \u534f\u7a0b\u51fd\u6570\u7684 \u6808\u5185\u5b58\u3002\u56e0\u4e3a\u5728 <code>_st_md_cxt_restore()<\/code> \u7684\u65f6\u5019\uff0c\u4f1a\u628a \u8fd9\u4e2a <code>__jmpbuf[JB_RSP]<\/code> \u6062\u590d\u5230 RSP \u5bc4\u5b58\u5668\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"539\" height=\"440\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4.png\" alt=\"\" class=\"wp-image-1375\" srcset=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4.png 539w, https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-2-2-v4-300x245.png 300w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><\/figure>\n\n\n\n<p>\u81f3\u6b64 <code class=\"prettyprint\" >_ST_INIT_CONTEXT()<\/code> \u51fd\u6570\u5206\u6790\u5b8c\u6bd5\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u73b0\u5728 <code class=\"prettyprint\" >st_thread_create()<\/code> \u51fd\u6570\u8fd8\u6709\u4ee5\u4e0b\u4ee3\u7801\u6ca1\u6709\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Make thread runnable *\/\n  thread-&gt;state = _ST_ST_RUNNABLE;\n  _st_active_count++;\n  _ST_ADD_RUNQ(thread);\n\u200b\n  return thread;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u53ea\u6709 <code class=\"prettyprint\" >_ST_ADD_RUNQ<\/code> \u662f\u91cd\u70b9\uff0c\u4ed4\u7ec6\u5206\u6790\u4e00\u4e0b\u8fd9\u4e2a\u51fd\u6570\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define _ST_ADD_RUNQ(_thr)  ST_APPEND_LINK(&amp;(_thr)-&gt;links, &amp;_ST_RUNQ)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Append an element &quot;_e&quot; to the end of the list &quot;_l&quot; *\/\n#define ST_APPEND_LINK(_e,_l) ST_INSERT_BEFORE(_e,_l)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/* Insert element &quot;_e&quot; into the list, before &quot;_l&quot; *\/\n#define ST_INSERT_BEFORE(_e,_l)     \\\n    ST_BEGIN_MACRO     \\\n   (_e)-&gt;next = (_l);  \\\n   (_e)-&gt;prev = (_l)-&gt;prev; \\\n   (_l)-&gt;prev-&gt;next = (_e); \\\n   (_l)-&gt;prev = (_e);  \\\n    ST_END_MACRO<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u6709\u70b9\u7ed5\uff0c\u4f46\u5b9e\u9645\u4e0a\u5c31\u662f\u628a \u534f\u7a0b \u7684 <code class=\"prettyprint\" >links<\/code> \u63d2\u8fdb\u53bb \u5168\u5c40\u7ba1\u7406\u5668 <code>_st_this_vp.run_q<\/code> \uff0c\u4ed6\u4eec\u90fd\u662f <code>_st_clist<\/code> \u7ed3\u6784\u3002 <code>_st_clist<\/code> \u7ed3\u6784 \u5728\u5f88\u591a\u5730\u65b9\u90fd\u6709\u7528\u5230\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a _st_clist \u7684\u8bbe\u8ba1\u6bd4\u8f83\u7cbe\u5de7\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >typedef struct _st_clist {\n  struct _st_clist *next;\n  struct _st_clist *prev;\n} _st_clist_t;<\/code><\/pre>\n\n\n\n<p>\u6ca1\u9519\uff0c\u53ea\u6709\u4e00\u524d\u4e00\u540e \u4e24\u4e2a\u5b57\u6bb5\u3002\u5b9e\u9645\u4e0a <code class=\"prettyprint\" >next<\/code> \u5b58\u7684\u662f \u67d0\u4e2a\u534f\u7a0b\u7684 <code>links<\/code> \u5b57\u6bb5\u7684\u5185\u5b58\u5730\u5740\u3002\u56e0\u4e3a _st_thread \u5185\u90e8\u7684\u5b57\u6bb5\u7684\u5185\u5b58\u5730\u5740\u90fd\u662f\u8fde\u7eed\u7684\uff0c\u6240\u4ee5\u6839\u636e <code>links<\/code> \u5b57\u6bb5\u7684\u5185\u5b58\u5730\u5740 \u505a offset \u5c31\u80fd\u5b9a\u4f4d\u5230 _st_thread \u7684\u5934\u90e8\u7684\u5730\u5740\u3002\u6709\u4e00\u4e2a\u5c01\u88c5\u597d\u7684\u5b8f\u51fd\u6570 <code>_ST_THREAD_PTR()<\/code> \uff0c\u6839\u636e links \u7684\u5185\u5b58\u5730\u5740\u627e\u5230 \u534f\u7a0b\u3002\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#define _ST_THREAD_PTR(_qp)         \\\n    ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, links)))<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><strong>\u91cd\u65b0\u770b \u56de\u53bb st_init() \uff0cst_thread_create \u51fd\u6570\u5b9e\u9645\u4e0a\u5c31\u662f\u521b\u5efa\u4e86\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf <code class=\"prettyprint\" >_st_thread_t pthread<\/code>\uff0c\u8fd9\u4e2a\u7ed3\u6784\u4f53\u91cc\u9762\u4fdd\u5b58\u4e86\uff0cpthread-&gt;start \u51fd\u6570\u672a\u6267\u884c\u4e4b\u524d\u7684\u5bc4\u5b58\u5668\u4fe1\u606f\u3002<\/strong><\/p>\n\n\n\n<p>st_thread_create \u51fd\u6570\u5206\u6790\u5b8c\u6bd5\u3002<\/p>\n\n\n\n<p><strong>\u603b\u7ed3\uff1a<\/strong><\/p>\n\n\n\n<p>1\uff0c\u7533\u8bf7\u5185\u5b58\uff0c\u62ff\u51fa 336 \u5b57\u8282 \u521d\u59cb\u4e3a <code class=\"prettyprint\" >_st_thread_t<\/code> \u7ed3\u6784\uff0c\u540e\u7eed\u8fd9\u5757\u5185\u5b58\u7684\u7ba1\u7406\u901a\u8fc7 <code>_st_thread_t<\/code> \u7ed3\u6784\u8fdb\u884c\u7ba1\u7406\uff0c\u4f8b\u5982 \uff1a<code>thread-&gt;private_data<\/code>\uff0c<code>thread-&gt;stack<\/code>\u3002<\/p>\n\n\n\n<p>2\uff0c\u7136\u540e\u7528\u6c47\u7f16 \u628a\u5bc4\u5b58\u5668\u4fe1\u606f\u4fdd\u5b58\u8fdb\u53bb <code class=\"prettyprint\" >thread-&gt;context<\/code> \uff08jmp_buf\uff09 \u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u5176\u5b9e\u5206\u6790\u5230\u8fd9\u91cc\uff0c\u5927\u5bb6\u4f1a\u53d1\u73b0\uff0cst_thread_create() \u867d\u7136\u521b\u5efa\u4e86\u534f\u7a0b\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5f00\u59cb\u8fd0\u884c\u534f\u7a0b\u3002\u4ece <code class=\"prettyprint\" >lookupdns<\/code> \u7a0b\u5e8f\u770b\u6765\u3002\u521b\u5efa\u4e86\u4e24\u4e2a\u534f\u7a0b\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>1\uff0c<code class=\"prettyprint\" >st_thread_create(_st_idle_thread_start,...)<\/code><\/p>\n\n\n\n<p>2\uff0c<code class=\"prettyprint\" >st_thread_create(do_resolve,...)<\/code><\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u4e24\u4e2a\u51fd\u6570 <code class=\"prettyprint\" >_st_idle_thread_start()<\/code> \uff0c\u8ddf <code>do_resolve()<\/code> \u5e76\u6ca1\u6709\u5f00\u59cb\u8fd0\u884c\u3002\u90a3\u662f\u4ec0\u4e48\u65f6\u5019\u5f00\u59cb\u8fd0\u884c \u5462\uff1f\u5728 <code>st_thread_exit()<\/code> \u91cc\u9762\u3002<\/p>\n\n\n\n<p>\u8bf7\u770b \u4e0b\u4e00\u7bc7\u6587\u7ae0\u300aST\u6e90\u7801\u5206\u6790-st_thread_exit\u300b\u3002<\/p>\n\n\n\n<p><strong>\u6269\u5c55\u77e5\u8bc6\uff1a<\/strong><\/p>\n\n\n\n<p>1\uff0cGCC \u7f16\u8bd1\u7684\u65f6\u5019\u52a0\u4e0a<code class=\"prettyprint\" >-gdwarf-2<\/code> \u548c <code>-g3<\/code> \u7f16\u8bd1\u9009\u9879\u53ef\u4ee5\u6253\u5370\u5b8f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u76f8\u5173\u9605\u8bfb\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/ossrs\/state-threads\/issues\/15\">\u300a\u6768\u6210\u7acbstate-threads\u4ee3\u7801\u5206\u6790\u300b<\/a><\/li><li><a href=\"https:\/\/www.zhihu.com\/question\/40720890\">\u300a\u6c47\u7f16\u8bed\u8a00\u4e2dmov\u548clea\u7684\u533a\u522b\u6709\u54ea\u4e9b\uff1f\u300b<\/a><\/li><li><a href=\"https:\/\/blog.csdn.net\/qq_15762939\/article\/details\/104062307\">\u300aLinux\u4e2dmprotect()\u51fd\u6570\u8be6\u89e3\u300b<\/a><\/li><\/ol>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u7531\u4e8e\u7b14\u8005\u7684\u6c34\u5e73\u6709\u9650\uff0c \u52a0\u4e4b\u7f16\u5199\u7684\u540c\u65f6\u8fd8\u8981\u53c2\u4e0e\u5f00\u53d1\u5de5\u4f5c\uff0c\u6587\u4e2d\u96be\u514d\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u6216\u8005\u4e0d\u51c6\u786e\u7684\u5730\u65b9\uff0c\u6073\u8bf7\u8bfb\u8005\u6279\u8bc4\u6307\u6b63\u3002\u5982\u679c\u8bfb\u8005\u6709\u4efb\u4f55\u5b9d\u8d35\u610f\u89c1\uff0c\u53ef\u4ee5\u52a0\u6211\u5fae\u4fe1 Loken1\u3002QQ\uff1a2338195090\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587 \u4e3b\u8981\u5206\u6790 st_thread_create() \u51fd\u6570\u7684\u5185\u90e8\u5b9e\u73b0\u3002 st_thread_create \u6d41\u7a0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-1193","post","type-post","status-publish","format-standard","hentry","category-state-thread-analysis"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3<\/title>\n<meta name=\"description\" content=\"ST\u6e90\u7801\u5206\u6790-st_thread_create\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.xianwaizhiyin.net\/?p=1193\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3\" \/>\n<meta property=\"og:description\" content=\"ST\u6e90\u7801\u5206\u6790-st_thread_create\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.xianwaizhiyin.net\/?p=1193\" \/>\n<meta property=\"og:site_name\" content=\"\u5f26\u5916\u4e4b\u97f3\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-06T12:24:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-10T18:29:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"loken\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#website\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/\",\"name\":\"\u5f26\u5916\u4e4b\u97f3\",\"description\":\"FFmpeg\u3001WebRTC\uff0cSRS \u97f3\u89c6\u9891\u3001\u6d41\u5a92\u4f53\u6280\u672f\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.xianwaizhiyin.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193#primaryimage\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png\",\"contentUrl\":\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png\",\"width\":972,\"height\":460},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193#webpage\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193\",\"name\":\"ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3\",\"isPartOf\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193#primaryimage\"},\"datePublished\":\"2022-03-06T12:24:23+00:00\",\"dateModified\":\"2022-06-10T18:29:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3\"},\"description\":\"ST\u6e90\u7801\u5206\u6790-st_thread_create\",\"breadcrumb\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.xianwaizhiyin.net\/?p=1193\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1193#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.xianwaizhiyin.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ST\u6e90\u7801\u5206\u6790-st_thread_create\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3\",\"name\":\"loken\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g\",\"caption\":\"loken\"},\"sameAs\":[\"https:\/\/www.xianwaizhiyin.net\/\"],\"url\":\"https:\/\/www.xianwaizhiyin.net\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3","description":"ST\u6e90\u7801\u5206\u6790-st_thread_create","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.xianwaizhiyin.net\/?p=1193","og_locale":"zh_CN","og_type":"article","og_title":"ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3","og_description":"ST\u6e90\u7801\u5206\u6790-st_thread_create","og_url":"https:\/\/www.xianwaizhiyin.net\/?p=1193","og_site_name":"\u5f26\u5916\u4e4b\u97f3","article_published_time":"2022-03-06T12:24:23+00:00","article_modified_time":"2022-06-10T18:29:02+00:00","og_image":[{"url":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png"}],"twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"loken","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.xianwaizhiyin.net\/#website","url":"https:\/\/www.xianwaizhiyin.net\/","name":"\u5f26\u5916\u4e4b\u97f3","description":"FFmpeg\u3001WebRTC\uff0cSRS \u97f3\u89c6\u9891\u3001\u6d41\u5a92\u4f53\u6280\u672f","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.xianwaizhiyin.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"ImageObject","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1193#primaryimage","inLanguage":"zh-Hans","url":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png","contentUrl":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/st-7-0-0.png","width":972,"height":460},{"@type":"WebPage","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1193#webpage","url":"https:\/\/www.xianwaizhiyin.net\/?p=1193","name":"ST\u6e90\u7801\u5206\u6790-st_thread_create - \u5f26\u5916\u4e4b\u97f3","isPartOf":{"@id":"https:\/\/www.xianwaizhiyin.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.xianwaizhiyin.net\/?p=1193#primaryimage"},"datePublished":"2022-03-06T12:24:23+00:00","dateModified":"2022-06-10T18:29:02+00:00","author":{"@id":"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3"},"description":"ST\u6e90\u7801\u5206\u6790-st_thread_create","breadcrumb":{"@id":"https:\/\/www.xianwaizhiyin.net\/?p=1193#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.xianwaizhiyin.net\/?p=1193"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1193#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.xianwaizhiyin.net\/"},{"@type":"ListItem","position":2,"name":"ST\u6e90\u7801\u5206\u6790-st_thread_create"}]},{"@type":"Person","@id":"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3","name":"loken","image":{"@type":"ImageObject","@id":"https:\/\/www.xianwaizhiyin.net\/#personlogo","inLanguage":"zh-Hans","url":"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g","caption":"loken"},"sameAs":["https:\/\/www.xianwaizhiyin.net\/"],"url":"https:\/\/www.xianwaizhiyin.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1193"}],"version-history":[{"count":24,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1193\/revisions"}],"predecessor-version":[{"id":2622,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1193\/revisions\/2622"}],"wp:attachment":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}