system-calls

How to make a system call and read the stdout, in D?

左心房为你撑大大i 提交于 2020-01-03 08:36:09
问题 I thought to try using D for some system administration scripts which require high performance (for comparing performance with python/perl etc). I can't find an example in the tutorials I looked through so far (dsource.org etc.) on how to make a system call (i.e. calling another software) and receiving it's output from stdout, though? If I missed it, could someone point me to the right docs/tutorial, or provide with the answer right away? 回答1: Well, then I of course found it: http://www

Initializing a member of a struct to a function pointer without knowing the returned type

≯℡__Kan透↙ 提交于 2020-01-03 02:55:53
问题 I have this struct: typedef struct xyz_data { void *myfa; <------- correct void *myfb; <------- incorrect } and this function definition: asmlinkage ssize_t (*real_sys_read)(unsigned int fd, char __user *buf, size_t count); asmlinkage ssize_t hooked_sys_read(unsigned int fd, char __user *buf, size_t count); (as you might be guessing, this will point to the kernel's __NR_read ). Saving hooked_sys_read to *myfa; is as simple as xyz_data_something->myfa = hooked_sys_read , but what about myfb ?

system call hardware performance counters ubuntu

断了今生、忘了曾经 提交于 2020-01-02 20:19:07
问题 I am working on a project and I would like to obtain the performance counters(cache, TLB, etc) values of a system call(eg: read()) before and after the execution of a file. I tried doing this using perf on Ubuntu but was not able to get any results. Is there a way to do it using perf or maybe some other tool ? Thanks for the help. 3.329057 task-clock (msec) # 0.714 CPUs utilized 16 context-switches # 0.005 M/sec 0 cpu-migrations # 0.000 K/sec 257 page-faults # 0.077 M/sec 1,983,212 cycles # 0

epoll_wait fails due to EINTR, how to remedy this?

Deadly 提交于 2020-01-02 08:48:18
问题 My epoll_wait fails due to EINTR. My gdb trace shows this: enter code here 221 in ../nptl/sysdeps/pthread/createthread.c (gdb) 224 in ../nptl/sysdeps/pthread/createthread.c (gdb) [New Thread 0x40988490 (LWP 3589)] 227 in ../nptl/sysdeps/pthread/createthread.c (gdb) epoll_wait error in start timer: Measurement will befor entire duration of execution epoll_wait: Interrupted system call [Thread 0x40988490 (LWP 3589) exited] This string "epoll_wait error in start timer: Measurement will befor

Why would a simple C program need syscalls?

两盒软妹~` 提交于 2020-01-02 06:15:03
问题 Related to this other question. I am trying to run this simple C program in gem5: int main() { int a=1, b=2; int c=a+b; return c; } And it fails because gem5 doesn't have some syscalls implemented. My question is, why would a simple program like this require syscalls? This should run bare-metal without trouble. Is there a way to compile this to avoid syscalls? I am using arm-linux-gnueabi-gcc -static -DUNIX to compile it. 回答1: Without syscalls the program cannot exit. The way it works is

Why would a simple C program need syscalls?

雨燕双飞 提交于 2020-01-02 06:14:05
问题 Related to this other question. I am trying to run this simple C program in gem5: int main() { int a=1, b=2; int c=a+b; return c; } And it fails because gem5 doesn't have some syscalls implemented. My question is, why would a simple program like this require syscalls? This should run bare-metal without trouble. Is there a way to compile this to avoid syscalls? I am using arm-linux-gnueabi-gcc -static -DUNIX to compile it. 回答1: Without syscalls the program cannot exit. The way it works is

How do I trace a system call in Linux?

馋奶兔 提交于 2020-01-02 02:40:20
问题 How would I follow a system call from a trap to the kernel, to how arguments are passed, to how the system call in located in the kernel, to the actual processing of the system call in the kernel, to the return back to the user and how state is restored? 回答1: SystemTap This is the most powerful method I've found so far. It can even show the call arguments: Does ftrace allow capture of system call arguments to the Linux kernel, or only function names? Usage: sudo apt-get install systemtap sudo

linux assembly: how to call syscall?

我怕爱的太早我们不能终老 提交于 2020-01-01 14:37:45
问题 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

Implementation of system calls / traps within Linux kernel source

落花浮王杯 提交于 2020-01-01 04:16:45
问题 I'm currently learning about operating systems the use of traps to facilitate system calls within the Linux kernel. I've located the table of the traps in traps.c and the implementation of many of the traps within entry.S. However, I'm instructed to find an implementation of two system calls in the Linux kernel which utilize traps to implement a system call. Although I can find the definition of the traps themselves, I'm not sure what a "call" to one of these traps within the kernel would

Calling setns from Go returns EINVAL for mnt namespace

会有一股神秘感。 提交于 2019-12-31 13:55:11
问题 The C code works fine and correctly enters the namespace, but the Go code always seems to return EINVAL from the setns call to enter the mnt namespace. I've tried a number of permutations (including embedded C code with cgo and external .so ) on Go 1.2 , 1.3 and the current tip. Stepping through the code in gdb shows that both sequences are calling setns in libc the exact same way (or so it appears to me). I have boiled what seems to be the issue down to the code below. What am I doing wrong?