system-calls

x86_64 Assembly Linux System Call Confusion

≯℡__Kan透↙ 提交于 2019-11-27 02:16:36
问题 I am currently learning Assembly language on Linux. I have been using the book 'Programming From the Ground Up' and all the examples are 32-bit. My OS is 64-bit and I have been trying to do all the examples in 64-bit. I am having trouble however: .section .data .section .text .global _start _start: movq $60, %rax movq $2, %rbx int $0x80 This merely just calls the Linux exit System call or it should. Instead it causes a SEG FAULT and when I instead do this .section .data .section .text .global

How are sbrk/brk implemented in Linux?

守給你的承諾、 提交于 2019-11-27 00:37:51
问题 I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? 回答1: In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" ( struct vm_area_struct ). There is also a structure which represents (again in a very high level

How to know if a Linux system call is restartable or not?

半腔热情 提交于 2019-11-26 22:58:28
问题 Some system calls can be restarted transparently by the Kernel if the SA_RESTART flag is used when installing the signal handler, according to man signal(7): If a blocked call to one of the following interfaces is interrupted by a signal handler, then the call will be automatically restarted after the signal handler returns if the SA_RESTART flag was used ; otherwise the call will fail with the error EINTR: Then it mentions some system calls that can (and can not) be restarted, but does not

What is the interface for ARM system calls and where is it defined in the Linux kernel?

萝らか妹 提交于 2019-11-26 22:52:58
问题 I have read about system calls in Linux, and everywhere description is given regarding x86 architecture (ox80 interrupt and SYSENTER). But I am not able to track down the files and process for a system call in ARM achitecture. Can anyone please help. Few relevant files which I got to know are: \arch\arm\kernel\calls.S \arch\arm\kernel\entry-common.S (explanation needed) 回答1: In ARM world, you do a software interrupt (mechanism to signal the kernel) by supervisor call / svc (previously called

System call vs Function call

守給你的承諾、 提交于 2019-11-26 22:37:26
问题 What is the difference between a system call and a function call? Is fopen() a system call or a function call? 回答1: 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,

User input and output doesn't work in my assembly code

自作多情 提交于 2019-11-26 22:26:28
问题 The following program compiles without errors, but when run it doesn't prompt for any input and nothing prints. What's the problem, and how can I fix it? I use these commands to assemble and link: /usr/local/bin/nasm -f macho32 $1 ld -macosx_version_min 10.9.0 -lSystem -o run $filename.o -e _start -lc My code is: section .data ;New line string NEWLINE: db 0xa, 0xd LENGTH: equ $-NEWLINE section .bss INPT: resd 1 section .text global _start _start: ;Read character mov eax, 0x3 mov ebx, 0x1 mov

how could I intercept linux sys calls?

耗尽温柔 提交于 2019-11-26 22:04:46
Besides the LD_PRELOAD trick , and Linux Kernel Modules that replace a certain syscall with one provided by you , is there any possibility to intercept a syscall ( open for example ) , so that it first goes through your function , before it reaches the actual open ? if you really need a solution you might be interested in the DR rootkit that accomplishes just this, http://www.immunityinc.com/downloads/linux_rootkit_source.tbz2 the article about it is here http://www.theregister.co.uk/2008/09/04/linux_rootkit_released/ DJ Capelis Why can't you / don't want to use the LD_PRELOAD trick ? Example

How does execve call dynamic linker/loader (ld-linux.so.2)

一个人想着一个人 提交于 2019-11-26 21:39:30
问题 I used gcc to compile and link the most basic C program, test.c: int main() { } As expected, the output is a dynamically linked executable: $ file test test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x0f806c099f74132a158d98aebde4639ae0998971, not stripped Running strace gives the following output: $ strace -f ./test execve("./test", ["./test"], [/* 31 vars */]) = 0 brk(0) = 0x248d000 access("/etc/ld.so

How do I get a thread ID from an arbitrary pthread_t?

给你一囗甜甜゛ 提交于 2019-11-26 20:16:38
I have a pthread_t, and I'd like to change its CPU affinity. The problem is that I'm using glibc 2.3.2, which doesn't have pthread_setaffinity_np() . That's OK, though, because pthread_setaffinity_np() is itself a wrapper of sched_setaffinity() , which can be called by passing a thread ID instead of a process ID to set the affinity for an arbitrary thread. BUT ... The thread id that sched_setaffinity can work with is an OS thread id, the kind that you can get from the gettid() system call. This is different from the opaque type pthread_t , and gettid() will only return the thread-id of the

how do i add a system call / utility in xv6

筅森魡賤 提交于 2019-11-26 19:46:41
问题 Can any one tell me/ point me any references to how to add a system call / utility in XV6 exhaustive search on google was futile and hacking the hard way also was not productive so far . the reference book also did not have any hello world example to start with any help greatly appreciated 回答1: Read this: http://zoo.cs.yale.edu/classes/cs422/2010/xv6-book/trap.pdf It explains it quite well 回答2: To add a system call that can be called in xv6's shell, you should so something with the five files