{"id":4094,"date":"2015-10-02T09:46:34","date_gmt":"2015-10-02T09:46:34","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=4094"},"modified":"2015-10-06T08:02:15","modified_gmt":"2015-10-06T08:02:15","slug":"syscall-system-call-in-freebsd-and-linux","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=4094","title":{"rendered":"Syscall \/ System Call \/ vDSO in FreeBSD and Linux"},"content":{"rendered":"<h3>vsyscall \/ vDSO<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/VDSO\">vDSOs (virtual dynamically linked shared objects)<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/19938324\/what-are-vdso-and-vsyscall\">What are vdso and vsyscall?<\/a><br \/>\n<a href=\"http:\/\/www.linuxjournal.com\/content\/creating-vdso-colonels-other-chicken?page=0,0\">Creating a vDSO: the Colonel&#8217;s Other Chicken<\/a><br \/>\n<a href=\"http:\/\/lwn.net\/Articles\/446528\/\">On vsyscalls and the vDSO<\/a><br \/>\n<a href=\"http:\/\/davisdoesdownunder.blogspot.ie\/2011\/02\/linux-syscall-vsyscall-and-vdso-oh-my.html\">Linux syscall, vsyscall, and vDSO&#8230; Oh My!<\/a><br \/>\n<a href=\"http:\/\/www.trilithium.com\/johan\/2005\/08\/linux-gate\/\">What is linux-gate.so.1?<\/a><\/p>\n<p><a href=\"http:\/\/articles.manugarg.com\/systemcallinlinux2_6.html\">Sysenter Based System Call Mechanism in Linux 2.6<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/9506353\/how-to-invoke-a-system-call-via-sysenter-in-inline-assembly-x86-amd64-linux\">How to invoke a system call via sysenter in inline assembly (x86\/amd64 linux)?<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/15168822\/intel-x86-vs-x64-system-call\">Intel x86 vs x64 system call<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Call_gate\">Call gate<\/a><br \/>\n<a href=\"http:\/\/wiki.osdev.org\/System_Calls\">System Calls<\/a><br \/>\n<a href=\"http:\/\/wiki.osdev.org\/Sysenter\">Sysenter<\/a><br \/>\n<a href=\"http:\/\/x86asm.net\/articles\/debugging-in-amd64-64-bit-mode-in-theory\/\">Debugging in AMD64 64-bit Mode in Theory<\/a><\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Comparison_of_command_shells\">Comparison of command shells<\/a><\/p>\n<h3>Linux<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Linux_kernel_interfaces\">Linux kernel interfaces<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Linux_Programming_Interface\">The Linux Programming Interface<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/System_call\">System call<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Wait_%28system_call%29\">wait (system call)<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Read_%28system_call%29\">read (system call)<\/a><\/p>\n<p><a href=\"http:\/\/cs.lmu.edu\/~ray\/notes\/linuxsyscalls\/\">Linux System Calls Overview<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/17652555\/where-is-the-system-call-table-in-linux-kernel-v3-9\">Where is the system call table in linux kernel v3.9?<\/a><br \/>\n<a href=\"http:\/\/comments.gmane.org\/gmane.linux.kernel.kernelnewbies\/44938\">Where is the system call table in linux kernel v3.9?<\/a><br \/>\n<a href=\"http:\/\/heartinpiece.blogspot.ch\/2014\/01\/adding-system-call-for-linux-310-x8664.html\">Adding a System call for Linux 3.10 x86_64<\/a><br \/>\n<a href=\"https:\/\/www.kernel.org\/doc\/Documentation\/arm\/kernel_user_helpers.txt\">ARM Kernel-provided User Helpers<\/a><br \/>\n<a href=\"https:\/\/kerneltweaks.wordpress.com\/2014\/11\/26\/add-system-call-to-linux-kernel\/\">Add new system call to linux kernel\u2026<\/a><br \/>\n<a href=\"http:\/\/syscalls.kernelgrok.com\/\">Linux Syscall Reference for Kernel 2.6<\/a><br \/>\n<a href=\"http:\/\/asm.sourceforge.net\/syscall.html\">List of Linux\/i386 system calls for Kernel 2.6<\/a><br \/>\n<a href=\"http:\/\/man7.org\/linux\/man-pages\/man2\/syscalls.2.html\">man syscalls &#8211; Linux system calls<\/a><\/p>\n<h3>FreeBSD<\/h3>\n<p><a href=\"https:\/\/wiki.freebsd.org\/AddingSyscalls\">Adding Syscalls To FreeBSD<\/a><br \/>\n<a href=\"https:\/\/github.com\/golang\/go\/issues\/9627\">runtime: reconsider using SYSCALL instruction on FreeBSD<\/a><br \/>\n<a href=\"https:\/\/int80.wordpress.com\/2009\/03\/13\/reading-the-freebsd-kernel\/\">Reading the FreeBSD Kernel<\/a><br \/>\n<a href=\"http:\/\/www.int80h.org\/\">int80h.org<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ngrep -r sysenter .\r\ngrep -r sysexit .\r\ngrep -r db_inst_0f0x .\r\ngrep -r db_inst_0f .\r\ngrep -r &quot;int 0x80&quot; .\r\ngrep -r &quot;syscall&quot; .\r\ngrep -r &quot;sys\/syscall.h&quot; .\r\ngrep -r &quot;sy_call&quot; .\r\ngrep -r sigtramp.S .\r\ngrep -r &quot;NON_GPROF_ENTRY(sigcode)&quot; .\r\ngrep -r &quot;sigcode&quot; .\r\ngrep -r SYS_sigreturn .\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#include &lt;sys\/syscall.h&gt;\r\n\r\n.\/powerpc\/booke\/vm_machdep.c\r\n.\/powerpc\/booke\/trap.c:\r\n\r\n.\/i386\/i386\/trap.c\r\n.\/i386\/i386\/elf_machdep.c\r\n.\/i386\/i386\/locore.s\r\n.\/i386\/xen\/locore.s\r\n\r\n.\/arm\/arm\/sys_machdep.c\r\n.\/arm\/arm\/vm_machdep.c\r\n.\/arm\/arm\/trap.c\r\n.\/arm\/arm\/locore.S\r\n.\/arm\/arm\/elf_machdep.c\r\n\r\n.\/amd64\/amd64\/trap.c\r\n.\/amd64\/amd64\/elf_machdep.c\r\n.\/amd64\/ia32\/ia32_signal.c\r\n.\/amd64\/ia32\/ia32_sigtramp.S\r\n.\/amd64\/ia32\/ia32_reg.c\r\n.\/amd64\/ia32\/ia32_syscall.c\r\n\r\nSYS_syscall \r\n \r\ncpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)\r\n\r\n\/*\r\n * System call handler for native binaries.  The trap frame is already\r\n * set up by the assembler trampoline and a pointer to it is saved in\r\n * td_frame.\r\n *\/\r\nvoid\r\namd64_syscall(struct thread *td, int traced)\r\n{\r\n    &#x5B;...]\r\n}\r\n\r\n.\/kern\/subr_syscall.c:syscallenter(struct thread *td, struct syscall_args *sa)\r\n\r\nstatic inline int\r\nsyscallenter(struct thread *td, struct syscall_args *sa)\r\n{\r\n        struct proc *p;\r\n        int error, traced;\r\n\r\n        PCPU_INC(cnt.v_syscall);\r\n        p = td-&gt;td_proc;\r\n        \r\n        error = (p-&gt;p_sysent-&gt;sv_fetch_syscall_args)(td, sa);\r\n\r\n\r\n                error = syscall_thread_enter(td, sa-&gt;callp);\r\n\r\n                AUDIT_SYSCALL_ENTER(sa-&gt;code, td);\r\n                error = (sa-&gt;callp-&gt;sy_call)(td, sa-&gt;args);\r\n                AUDIT_SYSCALL_EXIT(error, td);\r\n\r\n                syscall_thread_exit(td, sa-&gt;callp);\r\n}\r\n\r\n.\/amd64\/amd64\/db_trace.c:       sy_call_t *f;\r\n.\/amd64\/amd64\/db_trace.c:               f = p-&gt;p_sysent-&gt;sv_table&#x5B;number].sy_call;\r\n\r\n<\/pre>\n<h4>ARM<\/h4>\n<p><a href=\"http:\/\/comments.gmane.org\/gmane.os.freebsd.devel.arm\/7684\">The arguments of sys_sigreturn<\/a><br \/>\n<a href=\"https:\/\/lists.freebsd.org\/pipermail\/svn-src-head\/2013-January\/044066.html\">svn commit: r245414 &#8211; head\/sys\/arm\/arm\/locore.S<\/a><\/p>\n<p>==================================================<\/p>\n<h3>i386<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/INT_%28x86_instruction%29\">Wikipedia: INT (x86 instruction)<\/a><\/p>\n<h3>ARM<\/h3>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_ARM_microarchitectures\">List of ARM microarchitectures<\/a><\/p>\n<ul>\n<li>ARM9E (ARMv5TEJ => ARM926EJ-S)<\/li>\n<li>ARM10E (ARMv5TEJ => ARM1026EJ-S)<\/li>\n<li>ARM11 (ARMv6Z => ARM1176JZ(F)-S)<\/li>\n<li>Cortex-M (ARMv7E-M => Cortex-M4)<\/li>\n<li>Cortex-A 32-bit (ARMv7-A => Cortex-A17)<\/li>\n<li>Cortex-A 64-bit (ARMv8-A => Cortex-A57)<\/li>\n<\/ul>\n<p><a href=\"http:\/\/infocenter.arm.com\/help\/index.jsp?topic=\/com.arm.doc.dui0068b\/BABFCEEG.html\">Thumb software interrupt and breakpoint instructions > Software interrupt (SWI)<\/a><br \/>\n<a href=\"http:\/\/infocenter.arm.com\/help\/index.jsp?topic=\/com.arm.doc.dai0179b\/ar01s02s07.html\">Developing software for Cortex-M3 > Supervisor Calls (SVC)<\/a> => formerly SWI<br \/>\n<a href=\"http:\/\/infocenter.arm.com\/help\/index.jsp?topic=\/com.arm.doc.dui0473l\/dom1387466087086.html\"> ARM and Thumb Instructions > Hypervisor Call (HVC)<\/a> (Virtualization Extensions)<br \/>\n<a href=\"http:\/\/www.heyrick.co.uk\/assembler\/swi.html\">SWI : SoftWare Interrupt<\/a><br \/>\n<a href=\"http:\/\/www.keil.com\/support\/man\/docs\/rlarm\/rlarm_ar_swi_func.htm\">Keil: SWI Functions<\/a>, run in Supervisor Mode of ARM7 and ARM9, interrupt protected<br \/>\n<a href=\"http:\/\/www.keil.com\/support\/man\/docs\/rlarm\/rlarm_ar_svc_func.htm\">Keil: SVC Functions<\/a>, run in Privileged Handler Mode of the Cortex-M core<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/8459279\/are-arm-instructuons-swi-and-svc-exactly-same-thing\">Are ARM instructuons SWI and SVC exactly same thing?<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/22474840\/how-to-use-the-swi-in-arm-cortex-a9-for-enabling-the-irq-interrupt\">How to use the SWI in ARM Cortex A9 for enabling the IRQ interrupt?<\/a><br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/2752151\/which-cortex-m3-interrupts-can-i-use-for-general-purpose-work\">Which Cortex-M3 interrupts can I use for general purpose work?<\/a><br \/>\n<a href=\"http:\/\/coactionos.com\/embedded%20design%20tips\/2013\/10\/12\/Tips-Effective-Use-of-ARM-Cortex-M3-SVCall\/\">Effective Use of ARM Cortex-M3 SVCall<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>vsyscall \/ vDSO vDSOs (virtual dynamically linked shared objects) What are vdso and vsyscall? Creating a vDSO: the Colonel&#8217;s Other Chicken On vsyscalls and the vDSO Linux syscall, vsyscall, and vDSO&#8230; Oh My! What is linux-gate.so.1? Sysenter Based System Call Mechanism in Linux 2.6 How to invoke a system call via sysenter in inline assembly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4094","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4094"}],"version-history":[{"count":14,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4094\/revisions"}],"predecessor-version":[{"id":4151,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/4094\/revisions\/4151"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}