system-calls

Why would a simple C program need syscalls?

百般思念 提交于 2019-12-05 15:10:15
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. Without syscalls the program cannot exit. The way it works is typically something like this: // Not how it's actually implemented... just a sketch. void _start() { char *

Simulate effect of select() and poll() in kernel socket programming

扶醉桌前 提交于 2019-12-05 14:29:49
问题 One of the Linux kernel drivers I am developing is using network communication in the kernel ( sock_create() , sock->ops->bind() , and so on). The problem is there will be multiple sockets to receive data from. So I need something that will simulate a select() or poll() in kernel space. Since these functions use file descriptors, I cannot use the system calls unless I use the system calls to create the sockets, but that seems unnecessary since I am working in the kernel. So I was thinking of

copy data from kernel space to user space

拜拜、爱过 提交于 2019-12-05 12:38:02
I'm trying to make a custom system call. my system call takes 2 parameters struct buffer **mybuffer & int size . it's imposed any change that happens to **mybuffer should reflect in the user-space, but it seems it doesn't work. so I've seen somewhere else that i can use copy_to_user(void *dest, void *src, int size) to copy data from kernel space to user space. in user-space i have a struct called buffer, also this struct appears the same in the system call. typedef struct buffer { int n; }buffer; int main(void) { buffer **buf = malloc(sizeof(buffer *)); int i = 0 for(;i<8;i++) buf[i] = malloc

Do other operating systems implement the Linux system call splice?

半城伤御伤魂 提交于 2019-12-05 12:10:56
In an application I am developing I use splice on Linux for socket-to-socket data transfer. Do other operating systems (specifically at least Windows, OS X and FreeBSD) implement splice or an equivalent solution? Is it possible to imitate socket-to-socket data splice ing on Windows with sendfile ¹ + memmap ¹? ¹ Both exist on Windows under different names which I do not remember. Update You can see the performance improvements of splice vs user space buffers on Linux. DF , DR , F , MF , MR are my application in its different tunneling modes, NX is NGINX web server -p+t uses the Linux system

Can't access the open /arch/x86/syscalls/syscall_32.tbl

本秂侑毒 提交于 2019-12-05 12:01:12
As i'm writing this command after i shift to the kernel. When i compile it, it wasn't showing any list.Is there any other command to open the list ? open /arch/x86/syscalls/syscall_32.tbl Bug Remove first / character from your file path (as it should be relative path). Check file Now, check that this file exists, using file tool: $ file arch/x86/syscalls/syscall_32.tbl Print file If file exists, you can print it using cat or less commands. E.g.: $ less arch/x86/syscalls/syscall_32.tbl You can also open this file in editor, e.g. using vi command. If file absent This file comes with Linux kernel

intercepting the openat() system call for GNU tar

為{幸葍}努か 提交于 2019-12-05 09:42:41
I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD . An example intercept-openat.c has this content: #define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <dlfcn.h> int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) __attribute__((constructor)); int openat(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) { _original_openat = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat"); }

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

有些话、适合烂在心里 提交于 2019-12-05 09:02:43
问题 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

call gettid witin glibc

。_饼干妹妹 提交于 2019-12-05 08:21:54
I am working in glibc and I need to get the id of the current thread. For this i use syscall(SYS_gettid); Issue is, i am forced to include bits/syscall.h instead of ideal case i.e sys/syscall.h . sys/syscall.h internally calls bits/syscall.h but that is wrapped with #ifndef _LIBC macro. i.e #ifndef _LIBC /* The Linux kernel header file defines macros `__NR_<name>', but some programs expect the traditional form `SYS_<name>'. So in building libc we scan the kernel's list and produce <bits/syscall.h> with macros for all the `SYS_' names. */ # include <bits/syscall.h> #endif also bits/syscall.h

I have a trouble with looking into the read() function code defined in <unistd.h>

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:14:44
问题 I am now trying to understand how read(2) function works by looking into the actual code implementation and first, I try to see how it is defined in #include header file. In that file, I found this : ssize_t read(int, void *, size_t) __DARWIN_ALIAS_C(read); And then, I googled to find the actual read() function declaration. And, https://github.com/lattera/glibc/blob/master/io/read.c I found this. In this code, /* Read NBYTES into BUF from FD. Return the number read or -1. */ ssize_t __libc

how to dump call stack in syscall(android kernel) ?

一曲冷凌霜 提交于 2019-12-05 05:21:50
问题 I want to know who called *sys_reboot* when the phone(android) reboot unexpectly. Is there a way to dump the call stack in syscall (android kernel)? 回答1: If all you want it a kernel call trace, you can get that via dump_stack(). panic() calls that, amongst other things. The BUG() / BUG_ON() wrappers give it a more descriptive message and an optional conditional test. A userland stacktrace , particularly a symbolic one, though, cannot reliably be obtained from within the kernel directly. It's