system-calls

Where can I find system call source code?

北城余情 提交于 2019-11-27 06:54:26
In linux where can I find the source code for all system calls given that I have the source tree? Also if I were to want to look up the source code and assembly for a particular system call is there something that I can type in terminal like -my_system_call? You'll need the Linux kernel sources in order to see the actual source of the system calls. Manual pages, if installed on your local system, only contain the documentation of the calls and not their source itself. Unfortunately for you, system calls aren't stored in just one particular location in the whole kernel tree. This is because

Can we call system call in kernel space?

梦想的初衷 提交于 2019-11-27 06:50:43
问题 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. 回答1: 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 |

Sleeping for milliseconds on Windows, Linux, Solaris, HP-UX, IBM AIX, Vxworks, Wind River Linux?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 06:49:53
问题 I have to write a C program which has to sleep for milliseconds, which has to run on various platforms like Windows, Linux, Solaris, HP-UX, IBM AIX, Vxworks, and Windriver Linux On Windows, the Sleep system call will work on milliseconds only. On Linux, sleep will work on seconds; usleep will perform on microseconds and it's available on Solaris also. In Vxworks, I hope I can implement using taskDelay and sysClkRateSet . How can I achieve this millisecond sleep on HP-UX, IBM AIX and Wind

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

醉酒当歌 提交于 2019-11-27 06:42:53
问题 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

How do I reimplement (or wrap) a syscall function on Linux?

孤者浪人 提交于 2019-11-27 06:34:09
Suppose I want to completely take over the open() system call, maybe to wrap the actual syscall and perform some logging. One way to do this is to use LD_PRELOAD to load a (user-made) shared object library that takes over the open() entry point. The user-made open() routine then obtains the pointer to the glibc function open() by dlsym() ing it, and calling it. The solution proposed above is a dynamic solution, however. Suppose I want to link my own open() wrapper statically. How would I do it? I guess the mechanism is the same, but I also guess there will be a symbol clash between the user

Using interrupt 0x80 on 64-bit Linux [duplicate]

不打扰是莪最后的温柔 提交于 2019-11-27 06:19:44
问题 This question already has an answer here : What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? (1 answer) Closed last year . I have a simple 64-bit assembly program which is intended to print an 'O' and 'K' followed by a newline. However, the 'K' is never printed. One of the goals of the programs is to print the value in the lower bits of the rax register as ASCII letter. The program is specifically for 64-bit Linux, written for educational purposes, so there is no need to

Accessing a system call directly from user program

断了今生、忘了曾经 提交于 2019-11-27 05:47:41
问题 On Ubuntu - kernel 2.6.32.2 How to call already existing system call from user code directly without help of any library? I read in books and on internet to solve this then written following code but still getting error. Please help Want to find out the process id of current process #include <stdio.h> #include<linux/unistd.h> // for __NR_getpid _syscall0(int, getpid) int main() { printf("Current Process ID : %d\n",getpid()); return 0; } Error While compilation : root@Omkant:~/os# gcc -Wall

Is it true that fork() calls clone() internally?

末鹿安然 提交于 2019-11-27 05:04:14
问题 I read here that clone() system call is used to create a thread in Linux. Now the syntax of clone() is such that a starting routine/function address is needed to be passed to it. But here on this page it is written that fork() calls clone() internally. So my question is how do child process created by fork() starts running the part of code which is after fork() call, i.e. how does it not require a function as starting point? If the links I provided have incorrect info, then please guide me to

Programmatically getting UID and GID from username in Unix?

你离开我真会死。 提交于 2019-11-27 03:53:21
问题 I'm trying to use setuid() and setgid() to set the respective id's of a program to drop privileges down from root, but to use them I need to know the uid and gid of the user I want to change to. Is there a system call to do this? I don't want to hardcode it or parse from /etc/passwd . Also I'd like to do this programmatically rather than using: id -u USERNAME Any help would be greatly appreciated 回答1: Have a look at the getpwnam() and getgrnam() functions. 回答2: You want to use the getpw*

System calls overhead

倾然丶 夕夏残阳落幕 提交于 2019-11-27 02:52:57
问题 I just started studying about system calls. I would like to know what causes overhead when a system call is made. For example, if we consider getpid(), when a system call is made to getpid() my guess is that if the control is currently in the child process then a context switching has to be made to enter the parent process to get the pid. Can that contribute to overhead? Also when getpid() is called, there will be some metadata transfer across the user-space boundary and enters and exits the