system-calls

How to use ptrace(2) to change behaviour of syscalls?

半腔热情 提交于 2019-12-03 20:52:52
Are there any guides or examples (especially ARM ones) or libraries of using ptrace to affect execution of other process? For example, to make it believe that some data is appeared on file descriptor (i.e. release select/poll with some result and "answer" the following read syscall before the kernel). Expecting something involving PTRACE_SYSEMU. Can it be done in portable way? I want something like libc-overriding LD_PRELOAD trick, but which can be attached at runtime. Can it be done with some gdb commands? Ideal variant would be if there is some library where I can easily and portably hook

Perl: After a successful system call, “or die” command still ends script

跟風遠走 提交于 2019-12-03 18:01:47
问题 I am using the following line to make a simple system call which works: system ("mkdir -p Purged") or die "Failed to mkdir." ; Executing the script does make the system call and I can find a directory called Purged, but the error message is still printed and the script dies. What is wrong with my syntax? 回答1: That would be a little confusing, wouldn't? - Leonardo Herrera on Ikegami's answer Yes, it is confusing that the system command inverts true and false in Perl, and creates fun logic like

Syscall or sysenter on 32 bits Linux?

╄→гoц情女王★ 提交于 2019-12-03 13:47:38
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: global _start _start: mov eax, 4 ; 4 is write mov ebx, 1 ; 1 is stdout mov ecx, message ; address of

OS system calls from bash script

笑着哭i 提交于 2019-12-03 13:45:53
Is it possible to call os system calls like open, close etc from a shell script? I tried googling but it takes me in the wrong direction of using "system()" command. Can some one help on this? Many syscalls are accessible, but only via the native shell mechanisms, rather than being able to directly specify exact parameters. For instance: exec 4>outfile calls: open("outfile", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3 dup2(3, 4) (with 3 being replaced by the next available descriptor), and exec 4<&- calls: close(4) Some shells, such as bash, allow additional builtins to be added through loadable

How to call c++ functionality from java

最后都变了- 提交于 2019-12-03 13:30:29
I have a Java program that is mostly GUI and it shows data that is written to an xml file from a c++ command line tool. Now I want to add a button to the java program to refresh the data. This means that my program has to call the c++ functionality. Is the best way to just call the program from java through a system call? The c++ program will be compiled for mac os and windows and should always be in the same directory as the java program. I would like to generate an executable can the c program be stored inside the jar and called from my program? Assuming no better communication method is

Difference between nice and setpriority in unix

帅比萌擦擦* 提交于 2019-12-03 12:59:19
I'm trying to implement a different flavor of the 'nice' command of unix in C. I have seen the definitions of nice() system call and setpriority() call. The nice() call only increments/decrements the priority of the process. If I want to set the priority of a process to a particular value, can't I use the nice() call? Basically, other than how the priority is modified, is there any difference between nice() and setpriority() ? It's historical. nice() was introduced long before setpriority() . For backwards compatibility, the nice function was retained. nice sets your own priority (the niceness

How to take advantage of the VDSO object with your own programming language?

こ雲淡風輕ζ 提交于 2019-12-03 12:58:01
问题 Recent Linux kernels (at least on amd64) provide a magic object file called linux-vdso.so.1 that abstracts away the syscall interface to the kernel, allowing the kernel to choose the optimal calling convention. If you write code in C, the glibc automatically uses this object. Now, if I want to write a program without using the glibc, how can I use this object? Is the interface it provides documented somewhere? What about the calling convention? 回答1: It depends if your implementation is using

What determines the order directory entries are returned by getdents?

倖福魔咒の 提交于 2019-12-03 12:53:34
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 Niklas B. 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 can use LD_PRELOAD to hook the call to opendir and readdir and replace it with your own, sorting

select()-able timers

陌路散爱 提交于 2019-12-03 12:13:56
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. 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. Use the timeout parameter - keep your timer events in a priority queue, check the top item and set the timeout accordingly - if the

intercepting file system system calls

孤人 提交于 2019-12-03 11:58:29
I am writing an application for which I need to intercept some filesystem system calls eg. unlink. I would like to save some file say abc. If user deletes the file then I need to copy it to some other place. So I need unlink to call my code before deleting abc so that I could save it. I have gone through threads related to intercepting system calls but methods like LD_PRELOAD it wont work in my case because I want this to be secure and implemented in kernel so this method wont be useful. inotify notifies after the event so I could not be able to save it. Could you suggest any such method. I