{"id":283279,"date":"2023-09-23T04:01:14","date_gmt":"2023-09-22T20:01:14","guid":{"rendered":"https:\/\/lrxjmw.cn\/ltxjgnhkjyyh.html"},"modified":"2023-09-23T04:01:14","modified_gmt":"2023-09-22T20:01:14","slug":"ltxjgnhkjyyh","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ltxjgnhkjyyh.html","title":{"rendered":"Linux\u4f53\u7cfb\u7ed3\u6784\u5185\u6838\u7a7a\u95f4\u4e0e\u7528\u6237\u7a7a\u95f4\u662f\u7a0b\u5e8f\u6267\u884c\u7684\u4e24\u79cd\u4e0d\u540c\u72b6\u6001"},"content":{"rendered":"

Linux<\/a>\u4f53\u7cfb\u7ed3\u6784<\/p>\n

\u5185\u6838\u7a7a\u95f4\u4e0e\u7528\u6237\u7a7a\u95f4\u662f\u7a0b\u5e8f\u6267\u884c\u7684\u4e24\u79cd\u4e0d\u540c\u72b6\u6001\uff0c\u901a\u8fc7\u7cfb\u7edf<\/a>\u8c03\u7528\u548c\u786c\u4ef6\u4e2d\u65ad\u624d\u80fd\u5b8c\u6210\u4ece\u7528\u6237\u7a7a\u95f4\u5230\u5185\u6838\u7a7a\u95f4\u7684\u8f6c\u79fb\u3002\u5982\u53f3\u56fe\u6240\u793a\uff1a<\/p>\n

linux\u5185\u6838\u8c03\u8bd5\u65b9\u6cd5\u603b\u7ed3_linux\u8c03\u7528\u7cfb\u7edf\u5185\u6838\u51fd\u6570_linux\u5185\u6838\u7cfb\u7edf\u8c03\u7528<\/p>\n

linux\u4f53\u7cfb\u7ed3\u5e03\u5149<\/p>\n

\u4ece\u4e0a\u56fe\u83b7\u77e5\uff0cLinux\u7531\u7528\u6237\u7a7a\u95f4\u548c\u5185\u6838\u7a7a\u95f4<\/p>\n

\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7528\u6237\u8fdb\u7a0b\u662f\u4e0d\u80fd\u8bbf\u95ee\u5185\u6838\u7684\u3002\u5b83\u65e2\u4e0d\u80fd\u8bbf\u95ee\u5185\u6838\u6240\u5728\u7684\u663e\u5b58\u7a7a\u95f4\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u5185\u6838\u4e2d\u7684\u51fd\u6570\u3002Linux\u5185\u6838\u4e2d\u8bbe\u7f6e\u4e86\u4e00\u7ec4\u7528\u4e8e\u5b9e\u73b0\u5404\u7c7b\u7cfb\u7edf\u529f\u80fd\u7684\u5b50\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u5979\u4eec\u8bbf\u95eelinux\u5185\u6838\u7684\u6570\u636e\u548c\u51fd\u6570\uff0c\u8fd9\u79cd\u7cfb\u7edf\u8c03\u7528\u63d2\u53e3\uff08SCI\uff09\u79f0\u4e3a\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n

\u7cfb\u7edf\u8c03\u7528\u548c\u666e\u901a\u51fd\u6570\u7684\u533a\u522b\uff1a<\/p>\n

\u7cfb\u7edf\u8c03\u7528\u548c\u666e\u901a\u7684\u51fd\u6570\u8c03\u7528\u5341\u5206\u76f8\u50cf\uff0c\u533a\u522b\u4ec5\u4ec5\u5728\u4e8e\uff0c\u7cfb\u7edf\u8c03\u7528\u7531\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5b9e\u73b0\uff0c\u8fd0\u884c\u4e8e\u5185\u6838\u6001\uff1b\u800c\u666e\u901a\u7684\u51fd\u6570\u8c03\u7528\u7531\u51fd\u6570\u5e93\u6216\u7528\u6237\u81ea\u5df1\u63d0\u4f9b\uff0c\u8fd0\u884c\u4e8e\u7528\u6237\u6001\u3002<\/p>\n

\u7cfb\u7edf\u8c03\u7528\u6570:<\/p>\n

\u57282.6.32\u7248\u5185\u6838\u4e2d\uff0c\u5171\u6709\u7cfb\u7edf\u8c03\u7528365\u4e2a\uff0c\u53ef\u5728arch\/arm\/include\/asm\/unistd.h\u4e2d\u627e\u5230\u5b83\u4eec\u3002<\/p>\n

\/*Thisfilecontainsthesystemcallnumbers*\/<\/p>\n

#define__NR_restart_syscall(__NR_SYSCALL_BASE+0)<\/p>\n

#define__NR_exit(__NR_SYSCALL_BASE+1)<\/p>\n

#define__NR_fork(__NR_SYSCALL_BASE+2)<\/p>\n

......<\/p>\n

#define__NR_preadv(__NR_SYSCALL_BASE+361)<\/p>\n

#define__NR_pwritev(__NR_SYSCALL_BASE+362)<\/p>\n

linux\u5185\u6838\u7cfb\u7edf\u8c03\u7528_linux\u8c03\u7528\u7cfb\u7edf\u5185\u6838\u51fd\u6570_linux\u5185\u6838\u8c03\u8bd5\u65b9\u6cd5\u603b\u7ed3<\/p>\n

#define__NR_rt_tgsigqueueinfo(__NR_SYSCALL_BASE+363)<\/p>\n

#define__NR_perf_event_open(__NR_SYSCALL_BASE+364)<\/p>\n

\u7cfb\u7edf\u8c03\u7528\u7684\u529f\u80fd\uff1a<\/p>\n

\u4e3b\u8981\u5206\u4e3a3\u5927\u7c7b\uff1a<\/p>\n

(1)\u8fdb\u7a0b\u63a7\u5236\u7c7b<\/p>\n

fork\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b<\/p>\n

clone\u6839\u636e\u6307\u5b9a\u6761\u4ef6\u521b\u5efa\u5b50\u8fdb\u7a0b<\/p>\n

execve\u8fd0\u884c\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

...<\/p>\n

(2)\u6587\u4ef6\u63a7\u5236\u64cd\u4f5c<\/p>\n

fcntl\u6587\u4ef6\u63a7\u5236<\/p>\n

open\u6253\u5f00\u6587\u4ef6<\/p>\n

read\u8bfb\u6587\u4ef6<\/p>\n

...<\/p>\n

(3)\u7cfb\u7edf\u63a7\u5236<\/p>\n

ioctlI\/O\u603b\u63a7\u5236\u51fd\u6570<\/p>\n

reboot\u91cd\u65b0\u542f\u52a8<\/p>\n

\u2014sysctl\u8bfb\u5199\u7cfb\u7edf\u53c2\u6570<\/p>\n

...<\/p>\n

\u4f7f\u7528\u7cfb\u7edf\u8c03\u7528\u51fd\u6570\u4e3e\u4f8b\uff1a<\/p>\n

\u4e0b\u8fb9\u901a\u8fc7time\u51fd\u6570\u7cfb\u7edf\u8c03\u7528\u5b9e\u73b0\u4ece\u683c\u6797\u5c3c\u6cbb\u65f6\u95f41970\u5e741\u67081\u65e50:00\u5f00\u59cb\u5230\u73b0\u4eca\u7684\u79d2\u6570\u3002<\/p>\n

#include<\/p>\n

main()<\/p>\n

time_tt_time;<\/p>\n

t_time=time((time_t*)0);\/*\u8c03\u7528time\u7cfb\u7edf\u8c03\u7528*\/<\/p>\n

printf(\"Thetimeis%ldn\",t_time);<\/p>\n

\u7cfb\u7edf\u8c03\u7528\u5de5\u4f5c\u539f\u7406\uff1a<\/p>\n

\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7528\u6237\u8fdb\u7a0b\u662f\u4e0d\u80fd\u8bbf\u95ee\u5185\u6838\u7684\u3002\u5b83\u65e2\u4e0d\u80fd\u8bbf\u95ee\u5185\u6838\u6240\u5728\u7684\u663e\u5b58\u7a7a\u95f4\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u5185\u6838\u4e2d\u7684\u51fd\u6570\u3002\u7cfb<\/p>\n

\u7edf\u8c03\u7528\u662f\u4e00\u4e2a\u4f8b\u5916\u3002\u5176\u539f\u7406\u662f(1)\u8fdb\u7a0b\u5148\u7528\u9002\u5f53\u7684\u503c\u586b\u5145\u5bc4\u5b58\u5668\uff0c(2)\u4e4b\u540e\u8c03\u7528\u4e00\u4e2a\u7279\u6b8a\u7684\u6307\u4ee4\uff0c(3)\u8fd9\u4e2a\u6307\u4ee4\u4f1a\u8ba9\u7528\u6237\u7a0b\u5e8f\u8df3\u8f6c\u5230\u4e00\u4e2a\u4e8b\u5148\u5b9a\u4e49\u597d\u7684\u5185\u6838\u4e2d\u7684\u4e00\u4e2a\u4f4d\u7f6e\u3002\uff084\uff09\u8fdb\u7a0b\u53ef\u4ee5\u8df3\u8f6c\u5230\u7684\u56fa\u5b9a\u7684\u5185\u6838\u4f4d\u7f6e\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u68c0\u6d4b\u7cfb\u7edf\u8c03\u7528\u53f7\uff0c\u8fd9\u4e2a\u53f7\u7801\u544a\u8bc9\u5185\u6838\u8fdb\u7a0b\u6073\u6c42\u54ea\u79cd\u670d\u52a1\u3002\u4e4b\u540e\uff0c\u5b83\u67e5\u770b\u7cfb\u7edf\u8c03\u7528\u8868(sys_call_table)\u627e\u5230\u6240\u8c03\u7528\u7684\u5185\u6838\u51fd\u6570\u5165\u53e3\u5730\u5740\u3002\u63a5\u7740\uff0c\u5c31\u8c03\u7528\u51fd\u6570\uff0c\u7b49\u8fd4\u56de\u540e\uff0c\u505a\u4e00\u4e9b\u7cfb\u7edf\u68c0\u6d4blinux\u5185\u6838\u7cfb\u7edf\u8c03\u7528<\/strong>\uff0c\u6700\u540e\u8fd4\u56de\u5230\u8fdb\u7a0b\u3002<\/p>\n

\u5de5\u4f5c\u539f\u7406\u6982\u8ff0\uff1a<\/p>\n

(1)\u9002\u5f53\u7684\u503c<\/p>\n

\u6240\u6709\u9002\u5f53\u7684\u503c\u6211\u4eec\u90fd\u53ef\u4ee5\u5728include\/asm\/unistd.h\u4e2d\u627e\u5230\uff0c\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u4e3a\u6bcf\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u89c4\u5b9a\u4e86\u60df\u4e00\u7684\u7f16\u53f7\uff0c\u79f0\u4f5c\u7cfb\u7edf\u8c03\u7528\u53f7\u3002<\/p>\n

#define__NR_utimensat(__NR_SYSCALL_BASE+348)<\/p>\n

#define__NR_signalfd(__NR_SYSCALL_BASE+349)<\/p>\n

#define__NR_timerfd_create(__NR_SYSCALL_BASE+350)<\/p>\n

#define__NR_eventfd(__NR_SYSCALL_BASE+351)<\/p>\n

#define__NR_fallocate(__NR_SYSCALL_BASE+352)<\/p>\n

\u8fd9\u513f\u9762\u6bcf\u4e00\u4e2a\u5b8f\u5c31\u662f\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u53f7<\/p>\n

(2)\u7279\u6b8a\u7684\u6307\u4ee4<\/p>\n

\u5728IntelCPU\u4e2dlinux\u5185\u6838\u7cfb\u7edf\u8c03\u7528<\/strong>linux makefile\uff0c\u8fd9\u4e2a\u6307\u4ee4\u7531\u4e2d\u65ad0x80\u5b9e\u73b0<\/p>\n

\u5728ARM\u4e2d\uff0c\u8fd9\u4e2a\u6307\u4ee4\u662fSWI\uff08softwhereinterrupt\uff1a\u8f6f\u4e2d\u65ad\u6307\u4ee4\uff09\uff0c\u73b0\u4eca\u91cd\u65b0\u547d\u540d\u4e3aSVC<\/p>\n

(3)\u56fa\u5b9a\u7684\u4f4d\u7f6e<\/p>\n

\u6bcf\u4f4dCPU\u56fa\u5b9a\u7684\u4f4d\u7f6e\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u5728ARM\u4f53\u7cfb\u4e2d\u8fd9\u4e2a\u56fa\u5b9a\u7684\u5185\u6838\u4f4d\u7f6e\u662fENTRY(vector_swi)\uff08\u5728archshkernelentry-common.S\uff09\uff0c\u4e5f\u5c31\u662fPC\u8868\u9488\u4f1a\u8df3\u8f6c\u5230\u8fd9\u4e2a\u4f4d\u7f6e<\/p>\n

(4)\u76f8\u5e94\u7684\u51fd\u6570<\/p>\n

\u5185\u6838\u4f9d\u7167\u5e94\u7528\u7a0b\u5e8f\u4f20\u9012\u6765\u7684\u7cfb\u7edf\u8c03\u7528\u53f7linux\u5b89\u88c5\uff0c\u4ece\u7cfb\u7edf\u8c03\u7528\u8868sys_call_table\u627e\u5230\u76f8\u5e94\u7684\u5185\u6838\u51fd\u6570<\/p>\n

CALL\uff08sys_restart_syscall\uff09<\/p>\n

CALL\uff08sys_exit\uff09<\/p>\n

CALL\uff08sys_fork_wrapper\uff09<\/p>\n

\u5b9e\u4f8b\uff1a<\/p>\n

\u5de5\u4f5c\u539f\u7406\uff08\u5e94\u7528\uff09\uff1a\u4e0b\u8fb9\u662f\u4e00\u4e2a\u4ece\u7528\u6237open\u8c03\u7528\u5230\u627e\u5230\u5185\u6838\u4e2d\u5177\u4f53\u7684\u7cfb\u7edf\u8c03\u7528\u51fd\u6570\u5165\u53e3\u5730\u5740\u7684\u5927\u4f53\u6d41\u7a0b<\/p>\n

#define__syscall(name)\"swit\"__NR_##name\"nt\u201c<\/p>\n

intopen(constchar*pathname,intflags)<\/p>\n

\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n

__syscall(open)\uff1b<\/p>\n

\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n

\u8f6c\u5316\u4e3a<\/p>\n

intopen(constchar*pathname,intflags)<\/p>\n

\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n

swit__NR_open\/\/#define__NR_open(__NR_SYSCALL_BASE+5)<\/p>\n

\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n

\/\/\u5185\u6838\u5165\u53e3<\/p>\n

\/*arch\/arm\/kernel\/entry-common.S*\/<\/p>\n

ENTRY(vector_swi)<\/p>\n

\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026<\/p>\n

adrtbl,sys_call_table@loadsyscalltablepointer<\/p>\n

\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026<\/p>\n

ldrccpc,[tbl,scno,lsl#2]@callsys_*routine<\/p>\n

\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026<\/p>\n

ENTRY(sys_call_table)<\/p>\n

#include\"calls.S\"<\/p>\n

\/*arch\/arm\/kernel\/calls.S*\/<\/p>\n

\/*0*\/CALL(sys_restart_syscall)<\/p>\n

CALL(sys_exit)<\/p>\n

CALL(sys_fork_wrapper)<\/p>\n

CALL(sys_read)<\/p>\n

CALL(sys_write)<\/p>\n

\/*5*\/CALL(sys_open)<\/p>\n

\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026<\/p>\n

CALL(sys_dup3)<\/p>\n

CALL(sys_pipe2)<\/p>\n

\/*360*\/CALL(sys_inotify_init1)<\/p>\n","protected":false},"excerpt":{"rendered":"

Linux\u5185\u6838\u4e2d\u8bbe\u7f6e\u4e86\u4e00\u7ec4\u7528\u4e8e\u5b9e\u73b0\u5404\u79cd\u7cfb\u7edf\u529f\u80fd\u7684\u5b50\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u4ed6\u4eec\u8bbf\u95eelinux\u5185\u6838\u7684\u6570\u636e\u548c\u51fd\u6570\uff0c\u8fd9\u4e9b\u7cfb\u7edf\u8c03\u7528\u63a5\u53e3\uff08SCI\uff09\u79f0\u4e3a\u7cfb\u7edf\u8c03\u7528\u3002\u7cfb\u7edf\u8c03\u7528\u548c\u666e\u901a\u7684\u51fd\u6570\u8c03\u7528\u975e\u5e38\u76f8\u4f3c\uff0c\u533a\u522b\u4ec5\u4ec5\u5728\u4e8e\uff0c\u7cfb\u7edf\u8c03\u7528\u7531\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u5b9e\u73b0\uff0c\u8fd0\u884c\u4e8e\u5185\u6838\u6001\uff1b\u800c\u666e\u901a\u7684\u51fd\u6570\u8c03\u7528\u7531\u51fd\u6570\u5e93\u6216\u7528\u6237\u81ea\u5df1\u63d0\u4f9b\uff0c\u8fd0\u884c\u4e8e\u7528\u6237\u6001\u3002\u5185\u6838\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u4f20\u9012\u6765\u7684\u7cfb\u7edf\u8c03\u7528\u53f7\uff0c\u4ece\u7cfb\u7edf\u8c03\u7528\u8868sys_call_table\u627e\u5230\u76f8\u5e94\u7684\u5185\u6838\u51fd\u6570<\/p>\n","protected":false},"author":1,"featured_media":283280,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-283279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/283279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=283279"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/283279\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/283280"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=283279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=283279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=283279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}