In LinuxKernel? Why? YstemCall

Source: Internet
Author: User
In LinuxKernel? Why? YstemCall-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: gpmoney
Use system call to call the system? But what should I do ?? Output 1 ?? What about your own system call ??? Which of the following are available ??? Step ?, If you want to call the system call, can you skip? (1) (2) directly to the third ??? False? Yourself? Familiar with kernel compile and how to use the new compile kernel again ?? C


(1 )? Set include? N? Magpie syscall function

First, find/usr/inlcude/asm/unistd. h ???? N case, in? One row


# Define _ NR_getdents64 220.
# Define _ NR_fcntl64 221.


Plus:

# Definely _ NR_myfunc 222


Then find/usr/include/bits/syscall. h ???? N case, plus one line:


# Define SYS_myfunc _ NR_myfunc


Find/usr/src/linux/arch/i386/kernel/entry. S ???? N case is added at the end? K modify? Why ?? T-colored? Two rows


. Long SYMBOL_NAME (sys_getdents64)/* 220 */
. Long SYMBOL_NAME (sys_fcntl64)
. Long SYMBOL_NAME (sys_myfunc) --> Add? One row
# Ifdef CONFIG_TUX
. Long SYMBOL_NAME (_ sys_tux)
# Else
# Ifdef CONFIG_TUX_MODULE
. Long SYMBOL_NAME (sys_tux)
# Endif
# Endif

/*
* NOTE !! This doesn't have to be exact-we just have
* To make sure we have _ enough _ of the "sys_ni_syscall"
* Entries. Don't panic if you notice that this hasn't
* Been shrunk every time we add a new system call.
*/
. Rept NR_syscalls-222 ----> change to NR_syscalls-223
. Long SYMBOL_NAME (sys_ni_syscall)
. Endr


(2) create ?? Syscall? Routine


False? In/usr/src/linux, find/usr/src/linux/kernel/sys. c.

Add the above ?? Zi:


Asmlinkageintsys_myfunc (int input ){
Printk ("<1> Input value is: % d \ n", input );
Return input * 10;
}


After the change, you can re-compile kernel? K and re ?? C.

(3) create ?? User space Applet


Use_syscall.c
# Include
# Include
# Include

Static inline _ syscall1 (int, myfunc, int,)

Int main (void ){
Printf ("Return Value: % d \ n", myfunc (10 ));
}


??? What is the hidden burial ground? The keys are exhausted @?? Program? Outbound 100

If you? Yes? Fun, you can use tail-f/var/log/message ?? When F? Like? Is your program available? Printed by printk? Face


Sep 3 22:02:02 private kernel: Input value is: 10


_ Syscall1 is a question ?? Macro command, what ?? The above is the _ syscallN command. N represents the system? Which of the following calls are required ?????

_ SyscallN (arg1, arg2, arg3, arg4 ):

Arg1: What does it mean? Zookeeper
Arg2: indicates the syscall name to be called.
Arg3: What does it mean? Charm ?? Male? B
Arg4: What does it mean? Charm ?? File? Q


System ?? Total set? 6 ?? _ SyscallN ,? _ Syscall0 to _ syscall5. Why? Limit @ is the limit for calling int 0x80. Do you think ?? One thing ,??? Just? F helps you call int 0x80 ??? System? Medium? Zhen? Jian? Bribe ^ linux? Hip ?? The package is good.


(4 )?? Program

# Gcc-O2 use_syscall.c use_syscall
#./Use_syscall

Return Value: 100

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.