system-calls

select()-able timers

一曲冷凌霜 提交于 2019-12-04 20:11:54
问题 select() is a great system call. You can pack any number of file descriptors, socket descriptors, pipes, etc. and get notified in a synchronous fashion when input becomes available. Is there a way to create an interval/oneshot timer and use it with select()? That would save me from having multiple threads for IO and timing. 回答1: timerfd_create does exactly this. It's a fairly recent addition to the linux kernel and might not be available on all distros yet though. 回答2: Use the timeout

What determines the order directory entries are returned by getdents?

你离开我真会死。 提交于 2019-12-04 20:09:29
问题 Background is I have an existing application which lists directory entries; strace reveals it just calls getdents and lists them in the order returned. I would like them displayed in the same order as a call to ls with no arguments. Is it possible to update the directory data in some way to achieve this? FS is ext4, if that makes any difference. Thanks 回答1: If you really are determined to change this program's behaviour (of which I assume that you don't have the source code available), you

Syscall or sysenter on 32 bits Linux?

本秂侑毒 提交于 2019-12-04 19:36:49
问题 Since MS‑DOS, I know system invocation using interrupts. In old papers, I saw reference to int 80h to invoke system functions on Linux. Since a rather long time now, I know int 80h is deprecated in favour of the syscall instruction. But I can't get it working on my 32 bits machine. The question Is the syscall instruction to be used on 64 bits platform only? Doesn't 32 bits Linux makes use of syscall ? A sample test On my 32 bits Linux (Ubuntu Precise), this program terminates with a core dump

How does a syscall actually happen on linux?

若如初见. 提交于 2019-12-04 19:29:05
问题 Inspired by this question How can I force GDB to disassemble? and related to this one What is INT 21h? How does an actually system call happen under linux? what happens when the call is performed, until the actual kernel routine is invoked ? 回答1: Assuming we're talking about x86: The ID of the system call is deposited into the EAX register Any arguments required by the system call are deposited into the locations dictated by the system call. For example, some system calls expect their

In linux, how to do system calls through GNU ARM assembly

烈酒焚心 提交于 2019-12-04 17:44:55
Till now, I only know how to exit a program by gnu arm assembly. #exit(0) mov r0, #0 # return code mov r7, #1 # supervisor service number svc # call supervisor service But there are still many other syscalls like read, write, fork... I suppose that each of them will require different service number, different numbers of registers as arguments and different rules on how to use registers. My question is where I can get information on writing assembly for each of them. I searched google but the information is less on this topic. You can take an approach like Android's Bionic and generate sys call

What means “atomic” system call?

不羁的心 提交于 2019-12-04 16:53:38
I know that atomic is usually used in the context of race condition and means something like consistency and determinism of the result according to multithreading/multiprocessing environment . That's ok. But recently I read about atomic system calls in Linux and didn't understand what does atomic actually mean here, i.e. how this atomicity is implemented . Does it mean that this system calls simply use locks on the resources (e.g. open() on the target file inode) or there is anything more, may be some kernel guarantees? I think about disabling interrupts but not all interrupts can be disabled.

New syscall not found (linux kernel 3.0.0) where should I start looking?

ⅰ亾dé卋堺 提交于 2019-12-04 15:49:43
问题 I created two new syscalls, but when I try to test them I get the following error: matt@ubuntu:~/test$ gcc test.c test.c: In function ‘newcall’: test.c:6:17: error: ‘sys_get_slob_amnt_free’ undeclared (first use in this function) test.c:6:17: note: each undeclared identifier is reported only once for each function it appears in matt@ubuntu:~/test$ I also tried this with syscall(sys_get_slob_amnt_free) with the same result. Here is the test code: #include <unistd.h> #include <stdio.h> unsigned

Using ioprio_set in c++

流过昼夜 提交于 2019-12-04 15:02:57
I am trying to use ioprio_set to give a calling thread a higher priority for the IO scheduler. This is done within a c++ program. I want the call to look like this: ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_BE,0)); The man page says ioprio_set does not have Glibc wrapper, so they should be called using syscall. I tried the following: syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_BE,0)); The problem is that the macros IOPRIO_WHO_PROCESS, IOPRIO_PRIO_VALUE and IO_PRIO_CLASS_BE cannot be found, and I don't know how to replace them by int

Trying to single step through program with trap-flag and trap-signal-handler, crash on vsyscall

谁说我不能喝 提交于 2019-12-04 12:46:47
I'd like to create a complete instruction trace of the execution of a program, to collect some stats etc. I first tried using linux' ptrace functionality to step through a program (using the tutorial here ). This creates two processes, the traced one and the debugger, and they communicate via signals. I only got around 16K instructions per second (on 1.6GHz Atom), so this is too slow for anything non-trivial. I thought the interprocess communication via signals is too slow, so I tried setting up the debugging in the same process as the execution: Set the trap flag, and create a signal handler.

linux assembly: how to call syscall?

爱⌒轻易说出口 提交于 2019-12-04 12:46:13
I want to call a syscall in assembly. The problem is I can't mov ecx,rsp . rsp is 64-bit register, ecx is a 32-bit register. I want to pass the buffer addr as a parameter of this syscall. What can I do? Thanks. section .data s0: db "Largest basic function number supported:%s\n",0 s0len: equ $-s0 section .text global main extern write main: sub rsp, 16 xor eax, eax cpuid mov [rsp], ebx mov [rsp+4], edx mov [rsp+8], ecx mov [rsp+12], word 0x0 mov eax, 4 mov ebx, 1 mov ecx, rsp mov edx, 4 int 80h mov eax, 4 mov ebx, 1 mov ecx, s0 mov edx, s0len int 80h mov eax, 1 int 80h To make a system call in