system-calls

Is there a way to have a bit bucket pointer? (C/C++)

半腔热情 提交于 2019-12-12 14:29:51
问题 Is there a way to have a bit bucket pointer? A lot of IO (specifically input related) system calls return data to a buffer of a specific size. Is there a trick or way to make a sorta bit bucket pointer, so I can accept any amount of data that will be thrown away. Doing something like "char tmp[INT_MAX]" is crazy. The behavior I am looking for is something like /dev/null, only in a pointer world. Not to hopeful on this.... just curious. Thanks, Chenz UPDATE: Perhaps mmap-ing /dev/null. Forgot

Using ptrace to write a program supervisor in userspace

99封情书 提交于 2019-12-12 13:27:39
问题 I'll looking for advice/resources to write a program that can intercept system calls from a programm to supervise it's filesystem, network, etc access. The aim of this is to write an online judge, so that untrusted code can be run safely on a server. This is on linux, and I would prefer to write C++ or a scripting langauge (ruby, python, etc), and a library would be great! Thanks. 回答1: This looks like a good place to start. http://www.linuxjournal.com/article/6100 回答2: You can't safely use

Passing custom flags to “open” in a device driver

末鹿安然 提交于 2019-12-12 12:14:05
问题 I need to pass some custom flags to the open() call of my device driver. I found this example in LDD3: int dev_open(struct inode *inode, struct file *filp) { if ((filp->f_flags & O_ACCMODE) == O_WRONLY) { ... } } My question is: is it possibile to define other flags (like O_ACCMODE and O_WRONLY ) without conflicts with any others? 回答1: Yes, it's possible. Take a look at include/uapi/asm-generic/fcntl.h. Pay attention to next comment: /* * When introducing new O_* bits, please check its

Should I declare system call functions in C?

我的梦境 提交于 2019-12-12 12:06:58
问题 I read this answer: Must declare function prototype in C? My question is more specific: In a program that uses system calls like access() , open() , creat() , write() , read() ... Must I declare every system call function? Is that how C works? Because I'm getting the following: hw1.c: In function ‘main’: hw1.c:50:9: warning: implicit declaration of function ‘access’ [-Wimplicit-function-declaration] hw1.c:131:9: warning: implicit declaration of function ‘lseek’ [-Wimplicit-function

efficiency of fwrite for massive numbers of small writes

偶尔善良 提交于 2019-12-12 10:38:16
问题 I have a program that saves many large files >1GB using fwrite It works fine, but unfortunately due to the nature of the data each call to fwrite only writes 1-4bytes. with the result that the write can take over an hour, with most of this time seemingly due to the syscall overhead (or at least in the library function of fwrite). I have a similar problem with fread . Does anyone know of any existing / library functions that will buffer these writes and reads with an inline function, or is

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

血红的双手。 提交于 2019-12-12 10:18:57
问题 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 --->

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

送分小仙女□ 提交于 2019-12-12 10:16:15
问题 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

Difference in ABI between x86_64 Linux functions and syscalls

痞子三分冷 提交于 2019-12-12 09:35:25
问题 The x86_64 SysV ABI's function calling convention defines integer argument #4 to be passed in the rcx register. The Linux kernel syscall ABI, on the other hand, uses r10 for that same purpose. All other arguments are passed in the same registers for both functions and syscalls. This leads to some strange things. Check out, for example, the implementation of mmap in glibc for the x32 platform (for which the same discrepancy exists): 00432ce0 <__mmap>: 432ce0: 49 89 ca mov %rcx,%r10 432ce3: b8

compile errors using signal.h in Linux [duplicate]

痴心易碎 提交于 2019-12-12 09:31:26
问题 This question already has answers here : struct sigaction incomplete error (2 answers) Closed 5 years ago . I'm writing a shell program that must handle signals. My relevant signal handling related code is as follows: #include <signal.h> ... #include <sys/types.h> ... void installSigactions( int, struct sigaction* ); void handler_function( int signal_id ); ... /*define signal table*/ struct sigaction signal_action; /*insert handler function*/ signal_action.sa_handler = handler_function; /

How to call c++ functionality from java

江枫思渺然 提交于 2019-12-12 08:08:24
问题 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