system-calls

How to retrieve the user name from the user ID

拈花ヽ惹草 提交于 2019-11-27 19:29: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

How to implement system call in ARM64?

六月ゝ 毕业季﹏ 提交于 2019-11-27 18:14:15
问题 I am working with arm64 assembly coding and I want to implement system calls using svc instruction . I can't find any working arm64 system call implementation online.Also, I can't find the system call list for arm64. Also explain the implementation . 回答1: You can pass six arguments in x0 to x5 , return value is saved in x0 . To give an assembler snippet, this is write syscall from Android Bionic's libc implementation. write 's three arguments would already be in x0-x2 . Syscall number is

Spurious readiness notification for Select System call

点点圈 提交于 2019-11-27 18:06:05
问题 On http://linux.die.net/man/2/select, under BUGS section it is mentioned that the select system call may sometimes spuriously set the FD ready and the subsequent read call will return 0. The text describes one such example (wrong checksum) but I am assuming there would be other reasons too (otherwise they would have fixed this). Any ideas what could the other causes for Select to return a FD ready spuriously. and does this apply to other OS'es also. I am currently asking about Linux. Relevant

System call vs Function call

我们两清 提交于 2019-11-27 17:51:36
What is the difference between a system call and a function call? Is fopen() a system call or a function call? A system call is a call into kernel code, typically performed by executing an interrupt. The interrupt causes the kernel to take over and perform the requested action, then hands control back to the application. This mode switching is the reason that system calls are slower to execute than an equivalent application-level function. fopen is a function from the C library that, internally, performs one or more system calls. Generally, as a C programmer, you rarely need to use system

How to control which core a process runs on?

爷,独闯天下 提交于 2019-11-27 17:23:13
I can understand how one can write a program that uses multiple processes or threads: fork() a new process and use IPC, or create multiple threads and use those sorts of communication mechanisms. I also understand context switching. That is, with only once CPU, the operating system schedules time for each process (and there are tons of scheduling algorithms out there) and thereby we achieve running multiple processes simultaneously. And now that we have multi-core processors (or multi-processor computers), we could have two processes running simultaneously on two separate cores. My question is

gdb break when program opens specific file

北城以北 提交于 2019-11-27 17:22:46
问题 Back story: While running a program under strace I notice that '/dev/urandom' is being open 'ed. I would like to know where this call is coming from (it is not part of the program itself, it is part of the system). So, using gdb, I am trying to break (using catch syscall open ) program execution when the open call is issued, so I can see a backtrace. The problem is that open is being called alot , like several hundred times so I can't narrow down the specific call that is opening /dev/urandom

dup2 / dup - why would I need to duplicate a file descriptor?

南笙酒味 提交于 2019-11-27 17:06:06
I'm trying to understand the use of dup2 and dup . From the man page : DESCRIPTION dup and dup2 create a copy of the file descriptor oldfd. After successful return of dup or dup2, the old and new descriptors may be used interchangeably. They share locks, file position pointers and flags; for example, if the file position is modified by using lseek on one of the descriptors, the position is also changed for the other. The two descriptors do not share the close-on-exec flag, however. dup uses the lowest-numbered unused descriptor for the new descriptor. dup2 makes newfd be the copy of oldfd,

how does open works for normal file and device drivers

▼魔方 西西 提交于 2019-11-27 16:45:27
问题 Currently, I am learning Linux device drivers. And got stuck over how opening a device file works ? What I got until now... Consider the a simple code that opens a normal file.. #incldue<stdio.h> int main() { FILE fp; char buffer[20]; fp = fopen(/home/yoggi/foo.txt, "r"); fread(buffer, 5, 1, fp); } In above program, The fopen(), c-library function, is a wrapper function to the system call open() , which intern calls sys_open() or file_open() in VFS layer function. As linux supports a number

64-bit syscall documentation for MacOS assembly

孤街醉人 提交于 2019-11-27 16:21:09
I'm having trouble finding the good documentation for writing 64-bit assembly on MacOS. The 64-bit SysV ABI says the following in section A.2.1 and this SO post quotes it: A system-call is done via the syscall instruction. The kernel destroys registers %rcx and %r11. Returning from the syscall, register %rax contains the result of the system-call. A value in the range between -4095 and -1 indicates an error, it is -errno. Those two sentences are ok on Linux but are wrong on macOS Sierra with the following code: global _start extern _exit section .text _start: ; Align stack to 16 bytes for libc

System calls Implementation

爱⌒轻易说出口 提交于 2019-11-27 15:22:31
问题 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 ? 回答1: 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