system-calls

What is better “int 0x80” or “syscall”?

孤街浪徒 提交于 2019-11-26 19:42:25
I study the Linux Kernel and found out that for x86_64 architecture the interrupt int 0x80 doesn't work as calling for system call. The question is: in case of x86 architecture what is more preferable syscall or int 0x80 and why? EDIT : I use the kernel 3.4 syscall is default way of entering kernel mode on x86-64 . This instruction is not available in 32 bit modes of operation on Intel processors . sysenter is an instruction most frequently used to invoke system calls in 32 bit modes of operation. It is similar to syscall , a bit more difficult to use though, but that is kernel's concern. int

Call to operating system to open url?

混江龙づ霸主 提交于 2019-11-26 19:40:28
问题 What can I use to call the OS to open a URL in whatever browser the user has as default? Not worried about cross-OS compatibility; if it works in linux thats enough for me! 回答1: Here is how to open the user's default browser with a given url: import webbrowser webbrowser.open(url[, new=0[, autoraise=True]]) Here is the documentation about this functionality. It's part of Python's stdlibs: http://docs.python.org/library/webbrowser.html I have tested this successfully on Linux, Ubuntu 10.10.

Why do x86-64 Linux system calls modify RCX, and what does the value mean?

社会主义新天地 提交于 2019-11-26 19:12:15
I'm trying to allocate some memory in linux with sys_brk syscall. Here is what I tried: BYTES_TO_ALLOCATE equ 0x08 section .text global _start _start: mov rax, 12 mov rdi, BYTES_TO_ALLOCATE syscall mov rax, 60 syscall The thing is as per linux calling convention I expected the return value to be in rax register (pointer to the allocated memory). I ran this in gdb and after making sys_brk syscall I noticed the following register contents Before syscall rax 0xc 12 rbx 0x0 0 rcx 0x0 0 rdx 0x0 0 rsi 0x0 0 rdi 0x8 8 After syscall rax 0x401000 4198400 rbx 0x0 0 rcx 0x40008c 4194444 ; <---- What does

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

感情迁移 提交于 2019-11-26 18:50:13
问题 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

Assembly segmentation fault after making a system call, at the end of my code

假如想象 提交于 2019-11-26 18:02:02
I was experimenting and have the following assembly code, which works very well, except that I get a "Segmentation fault (core dumped)" message right before my program ends: GLOBAL _start %define ___STDIN 0 %define ___STDOUT 1 %define ___SYSCALL_WRITE 0x04 segment .data segment .rodata L1 db "hello World", 10, 0 segment .bss segment .text _start: mov eax, ___SYSCALL_WRITE mov ebx, ___STDOUT mov ecx, L1 mov edx, 13 int 0x80 It doesn't matter whether or not I have ret at the end; I still get the message. What's the problem? I'm using x86 and nasm. As n.m. said in the comments, the issue is that

Syscall implementation of exit()

柔情痞子 提交于 2019-11-26 17:14:51
问题 I wrote a simple C program which just calls the exit() function, however strace says that the binary is actually calling exit_group, is exit() a exit_group() wrapper? Are these two functions equivalent? If so why would the compiler choose exit_group() over exit()? 回答1: The Linux and glibc man pages document all of this (See especially the "C library/kernel differences" in the NOTES section). _exit(2): In glibc 2.3 and later, this wrapper function actually calls the Linux sys_exit_group system

How to invoke a system call via sysenter in inline assembly?

拟墨画扇 提交于 2019-11-26 16:17:37
How can we implement the system call using sysenter/syscall directly in x86 Linux? Can anybody provide help? It would be even better if you can also show the code for amd64 platform. I know in x86, we can use __asm__( " movl $1, %eax \n" " movl $0, %ebx \n" " call *%gs:0x10 \n" ); to route to sysenter indirectly. But how can we code using sysenter/syscall directly to issue a system call? I find some material http://damocles.blogbus.com/tag/sysenter/ . But still find it difficult to figure out. I'm going to show you how to execute system calls by writing a program that writes Hello World! to

How to access the system call from user-space?

牧云@^-^@ 提交于 2019-11-26 16:10:55
I read some paragraphs in LKD 1 and I just cannot understand the contents below: Accessing the System Call from User-Space Generally, the C library provides support for system calls. User applications can pull in function prototypes from the standard headers and link with the C library to use your system call (or the library routine that, in turn, uses your syscall call). If you just wrote the system call, however, it is doubtful that glibc already supports it! Thankfully, Linux provides a set of macros for wrapping access to system calls. It sets up the register contents and issues the trap

What are the return values of system calls in Assembly?

心已入冬 提交于 2019-11-26 14:54:16
问题 When I try to research about return values of system calls of the kernel, I find tables that describe them and what do I need to put in the different registers to let them work. However, I don't find any documentation where it states what is that return value I get from the system call. I'm just finding in different places that what I receive will be in the EAX register. TutorialsPoint: The result is usually returned in the EAX register. Assembly Language Step-By-Step: Programming with Linux

What is the difference between `read` and `sysread`?

六眼飞鱼酱① 提交于 2019-11-26 14:13:58
问题 read and sysread have very similar documentation. What are the differences between the two? 回答1: About read: read supports PerlIO layers. read works with any Perl file handle [1] . read buffers. read obtains data from the system in fixed sized blocks of 8 KiB [2] . read may block if less data than requested is available [3] . About sysread: sysread doesn't support PerlIO layers (meaning it requires a raw a.k.a. binary handle). sysread only works with Perl file handles that map to a system