system-calls

Why do we need to call poll_wait in poll?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 22:24:46
问题 In LDD3, i saw such codes static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); poll_wait(filp, &dev->inq, wait); poll_wait(filp, &dev->outq, wait); if (dev->rp != dev->wp) mask |= POLLIN | POLLRDNORM; /* readable */ if (spacefree(dev)) mask |= POLLOUT | POLLWRNORM; /*

system call hardware performance counters ubuntu

痞子三分冷 提交于 2019-12-06 21:55:38
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.596 GHz 1,352,902 stalled-cycles-frontend # 68.22% frontend cycles idle 1,080,180 stalled-cycles

Intercepting syscalls in Android kernel — device reboots when module is removed

瘦欲@ 提交于 2019-12-06 19:14:27
I have been trying to intercept the read syscall in Android kernel (3.0.72 for maguro). I am using kernel module for such purpose. An example is as follows: #include <linux/module.h> #include <linux/unistd.h> MODULE_LICENSE ("Dual BSD/GPL"); asmlinkage long (*orig_call_open) (const char __user * filename, int flags, int mode); asmlinkage long (*orig_call_read) (unsigned int fd, char __user * buf, size_t count); #define SYS_CALL_TABLE_ADDR 0xc0058828 void **sys_call_table; asmlinkage long new_sys_open (const char __user * filename, int flags, int mode) { printk ("Calling my open\n"); return

“short read” from filesystem, when can it happen?

白昼怎懂夜的黑 提交于 2019-12-06 18:29:25
问题 It is obvious that in general the read(2) system call can return less bytes than what was asked to be read. However, quite a few programs assume that when working with a local files, read(2) never returns less than what was asked (unless the file is shorter, of course). So, my question is: on Linux, in which cases can read(2) return less than what was requested if reading from an open file and EOF is not encountered and the amount being read is a few kilobytes at maximum? Some guesses: Can

Understanding `read, write` system calls in Unix

ぐ巨炮叔叔 提交于 2019-12-06 17:20:27
问题 My Systems Programming project has us implementing a compression/decompression program to crunch down ASCII text files by removing the zero top bit and writing the output to a separate file, depending on whether the compression or decompression routine is working. To do this, the professor has required us to use the binary files and Unix system calls, which include open, close, read, write , etc. From my understanding of read and write, it reads the binary data by defined byte chunks. However

List of and documentation for system calls for XNU kernel in OSX

大兔子大兔子 提交于 2019-12-06 17:13:59
问题 I'm trying to figure out how to get a list of and documentation for the system calls available in the XNU kernel in OSX. I've googled around quite a bit, but haven't been able to find anything of use. As I understand the calling conventions match BSD, is that correct? Thanks 回答1: The "official" list is at Darwin page at Apple. Specifically, see the file syscalls.master in the XNU distribution. (If something you expect is missing, try a newer XNU version.) The BSD part of the system calls

How Can I Count malloc in linux kernel with kprobe

爱⌒轻易说出口 提交于 2019-12-06 16:31:59
I want to count the malloc system call with Kprobe in fedora. I know that malloc is not a system call and is implemented in user space, but I want to count malloc with kprobe if its possible. What is the name of system call that I must give to Kprobe? For example for do_work: kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("do_fork"); This is not possible with kprobes because, as you said, malloc is not a system call. You can, however, use USDTs to trace userspace processes. The bcc tools contain an example with uobjnew . It traces object allocations in the given process: $ ./uobjnew -h

Why system call hooking produces different result everytime in Linux/Android 2.6.29?

北城以北 提交于 2019-12-06 15:32:37
I have implemented system call hooking for Android 2.6.29 kernel through a LKM module . I am tracing down one Android app for system calls. But interestingly, it returns different results every time I get a list of system calls. I am not able to make bold text in the code section, so I have put ** to show where the difference starts. For example, first run: our_sys_gettid ---> uid = 10028 our_sys_open ---> uid = 10028 with filename= /dev/cpuctl//tasks, flags= 131073, mode=0 our_sys_write ---> uid = 10028 with fd= 30, buf = 230 and count=3 our_sys_close ---> uid = 10028 with fd= 30 our_sys

Problem of understanding clock_gettime

筅森魡賤 提交于 2019-12-06 14:50:11
问题 I am having difficulties with the different clocks which can be accessed by clock_gettime . Especially I am interested in: CLOCK_REALTIME CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_COUTIME_ID I read the manpage, but it didn't help me very much. I use clock_gettime in order to generate timestamps for my profiler when it sends the gathered data via socket. I have noticed the following differences: CLOCK_REALTIME The events I receive from my profiler with this clocks are sometimes, in a wrong order.

how can i know whether a linux syscall is thread safe?

假如想象 提交于 2019-12-06 14:19:58
问题 some functions in linux mark "thread safe" by _r (e.g. gmtime_r ) but most of the syscalls are not be marked and also not mentioned in manpages. So my question is : How can i konw whether a linux syscall is thread safe? Thank you! 回答1: I think you mean "library functions"; syscalls should, by virtue of operating on the thread's kernel-side data, be thread-safe. And the answer is: check the manual pages for the functions in question. The "_r" variants are provided specifically for functions