system-calls

System calls Implementation

烂漫一生 提交于 2019-11-29 00:33:35
If a user application makes a system call , a software interrupt/exception is triggered. How can I see the source code for generating a software interrupt ? Basile Starynkevitch It is explained in Linux Assembly Howto . And you should read wikipedia syscall page (and also about VDSO ), and also intro(2) & syscalls(2) man pages. See also this answer and this one. Look also inside Gnu Libc & musl-libc source code. Learn also to use strace to find out which syscalls are made by a given command or process. See also the calling conventions and Application Binary Interface specification relevant to

What is the difference between the functions of the exec family of system calls like exec and execve?

拟墨画扇 提交于 2019-11-28 20:22:57
I have been following a system programming course recently and I came through the system calls exec() and execve() . So far I cannot find any difference between these two, Even the Wikipedia does not give a clear explanation, so is there a difference between exec() and execve() . And someone please could give brief descriptions about exec family system calls such as execl() , execv() , execle() , execvp() . Use man exec and read: The execv(), execvp(), and execvpe() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program.

Is “asmlinkage” required for a c function to be called from assembly?

穿精又带淫゛_ 提交于 2019-11-28 18:50:51
I am writing a C function that will be invoked from assembly code. (Specifically, I want to do some checking job in the path of system call handling in linux kernel, so I will call the c function before a system call is dispatched in entry_32.S) I am confused with the "asmlinkage" modifier when defining my c function. I know asmlinkage is to tell the compiler that the parameters will be passed through stack. #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) Questions: (1) Is asmlinkage required when defining such a function that will be invoked from assembly code? (2) what is the

system call and context switch

安稳与你 提交于 2019-11-28 15:44:04
I am sorry to ask this question when it has already been asked but I couldn't get a clarity from them. So I am asking the following related questions to get the difference between system call (mode-switch) and context switch Why is it said that the system call doesn't require context switch when the context of the process making the call has to be saved and then reloaded. Is it just because according to the definition of context switch a switch has to be made to another process. What does it mean that when a system call is made the kernel executes in "user context". According to the wikipedia

Magic numbers of the Linux reboot() system call

主宰稳场 提交于 2019-11-28 15:05:05
问题 The Linux Programming Interface has an exercise in Chapter 3 that goes like this: When using the Linux-specific reboot() system call to reboot the system, the second argument, magic2, must be specified as one of a set of magic numbers (e.g., LINUX_REBOOT_MAGIC2). What is the significance of these numbers? (Converting them to hexadecimal provides a clue.) The man page tells us magic2 can be one of LINUX_REBOOT_MAGIC2 (672274793), LINUX_REBOOT_MAGIC2A (85072278), LINUX_REBOOT_MAGIC2B (369367448

Why does returning from _start segfault?

ぐ巨炮叔叔 提交于 2019-11-28 14:47:28
I tried to put code not in the main function, but directly into _start : segment .text global _start _start: push rbp mov rbp, rsp ; ... program logic ... leave ret Compile: yasm -f elf64 main.s ld -o main main.o Run: ./main Segmentation fault(core dumped) I read, leave is mov esp,ebp pop ebp But why is it that such an epilogue to the pop stack frame and the set base frame pointer to a previous frame's base results in a segmentation fault? Indeed, making an exit system call exits gracefully. As per ABI 1 the stack at the entry on _start is There is no "return address". The only way to exit a

How do sites like codepad.org and ideone.com sandbox your program?

我怕爱的太早我们不能终老 提交于 2019-11-28 14:11:26
问题 I need to compile and run user-submitted scripts on my site, similar to what codepad and ideone do. How can I sandbox these programs so that malicious users don't take down my server? Specifically, I want to lock them inside an empty directory and prevent them from reading or writing anywhere outside of that, from consuming too much memory or CPU, or from doing anything else malicious. I will need to communicate with these programs via pipes (over stdin/stdout) from outside the sandbox. 回答1:

How to retrieve the user name from the user ID

纵然是瞬间 提交于 2019-11-28 13:35:32
I am implementing the (ls) command on Unix while learning from a book. During the coding part of my implementation of the (ls) command with the (-l) flag , I see that I have to prompt the user and group names of the file. So far I have the user and group IDs from the following lines: struct stat statBuf; statBuf.st_uid; //For the user id. statBuf.st_gid; //For the group id. In the default (ls) command on Unix, the information of the file is printed in such a way that the user name is shown instead of the user id. Can anyone help me to find the correct methodology to retrieve the user and group

Can we call system call in kernel space?

二次信任 提交于 2019-11-28 12:12:04
Sometimes, when we have to call system call in kernel system, we invoke it's helper or related kernel functions, instead do 'syscall'. I am still wondering can we call system call in kernel space? If not, what stops us doing that. My question is a little bit weird. Technologeeks Actually, contrary to popular belief (and some answers here), the answer is, yes, you can, but depending on which OS: In Linux, you can call almost all system calls if you can find their kernel export (do cat /proc/kallsysms | grep sys_ for an example). There is a minor "trick" to get around a protection in most

Why can the execve system call run “/bin/sh” without any argv arguments, but not “/bin/ls”?

微笑、不失礼 提交于 2019-11-28 12:06:46
I am confused with the syscall of __NR_execve . When I learn linux system call. The correct way that I know to use execve is like this: char *sc[2]; sc[0]="/bin/sh"; sc[1]= NULL; execve(sc[0],sc,NULL); Then the function execve will call syscall() to get into system kernel with putting the arguments on Registers EAX , EBX , ECX and EDX . However, It still succeed if I use execve("/bin/sh",NULL,NULL); But if I replace "/bin/sh" with "/bin/ls" ,it fail with: A NULL argv[0] was passed through an exec system call. I wonder why "/bin/sh" can be executed successfully without enough parameters while "