system-calls

syscall wrapper asm C

人走茶凉 提交于 2021-02-04 16:31:37
问题 Can someone explain this code snippet to me? Also please give me some link/URL where i can know more about this? This code is used as a wrapper to override the "extern int errno" in our library. Can someone explain me this function, and tell why is wrapper needed in some syscalls? Which are also called WeakSYSCALLS? #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1) #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2) #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3) #define LOADREGS_5(a1, a2, a3, a4, a5) \ register int

pread and lseek not working on socket file descriptor

给你一囗甜甜゛ 提交于 2021-01-29 08:17:18
问题 This question is on system calls pread and lseek . I have a file descriptor of socket type . Data is added to it whenever packet is read from the network layer . I would like to know whats the amount of data present in the file descriptor at regular intervals . I tried using the systems calls pread and lseek , so that I know only the amount of data rather than reading data itself . But , both the calls fails giving Illegal seek error. Are there any other systems calls on the socket type file

Unreadable content of 'pathname' parameter in 'mkdir()' system call after inline hooking

蓝咒 提交于 2021-01-29 06:13:57
问题 I'm trying inline hooking system calls. The hook function is like this: asmlinkage long hooked_mkdir(const char __user *pathname, umode_t mode) { static char *msg = "hooked sys_mkdir(), mkdir name: "; printk("%s%s", msg, pathname); //print hex content to check bug. int i; for (i = 0; pathname[i] != '\0'; i++) { printk("\\x%x", pathname[i]); } return old_mkdir(pathname, mode); } Now I mkdir 3 directories named 111 , 222 and 333 . The syscalls were made successfully. However, the pathname is

How to fork a Linux process in a Stopped state?

拈花ヽ惹草 提交于 2021-01-28 14:41:37
问题 I am starting a new task using a clone(2) call. There used to be CLONE_STOPPED flag, but it is no longer present in current kernel. Is there any trick to start a task in a Stopped state (waiting for SIGCONT to actually run)? 回答1: You can't, there's no way to do that in recent kernels, not unless you write a kernel module to do that. You can see how kernel v2.6.32 used to do it in kernel/fork.c (L1449): if (unlikely(clone_flags & CLONE_STOPPED)) { /* * We'll start up with an immediate SIGSTOP.

How to add the two variations of the open syscall in OS161?

℡╲_俬逩灬. 提交于 2021-01-28 07:52:23
问题 From the man pages of OS161 : Synopsis #include <unistd.h> #include <fcntl.h> int open(const char *filename, int flags); int open(const char *filename, int flags, mode_t mode); How the standard c library function open is defined: int open(const char *filename, int flags, ...); The declaration: /* * Definition for each syscall. * All we do is load the syscall number into v0, the register the * kernel expects to find it in, and jump to the shared syscall code. * (Note that the addiu instruction

Writing a putchar in Assembly for x86_64 with 64 bit Linux?

旧城冷巷雨未停 提交于 2021-01-28 06:10:27
问题 I am trying to use the write syscall in order to reproduce the putchar function behavior which prints a single character. My code is as follows, asm_putchar: push rbp mov rbp, rsp mov r8, rdi call: mov rax, 1 mov rdi, 1 mov rsi, r8 mov rdx, 1 syscall return: mov rsp, rbp pop rbp ret 回答1: From man 2 write , you can see the signature of write is, ssize_t write(int fd, const void *buf, size_t count); It takes a pointer ( const void *buf ) to a buffer in memory. You can't pass it a char by value,

dtrace: doesn't catch any write sys call

狂风中的少年 提交于 2021-01-28 04:12:26
问题 I'm new to dtrace and trying to write some a basic dtrace scripting. I found a example to catch read(2) and write(2) syscall on seperate terminal as following, syscall::read:entry, syscall::write:entry /pid==4217/ { } The specified pid number is from the other terminal's pid id. When I saw the example, it supposed to show some read and write syscall if I run this script with dtrace. But I only observed read syscall but not write syscall. So if I understand correctly, on the terminal I observe

Where are the OSX (XNU) syscalls actually documented?

ぃ、小莉子 提交于 2021-01-28 02:06:37
问题 I'm looking through the syscalls.master file here but it isn't at all documented. Does documentation for the syscalls exist? If not, why not? By documentation I mean an actual explanation of what each syscall does and the meanings of the arguments it takes. 回答1: Apple's position is that the system libraries are the API and stable ABI, syscalls are not. They discourage their direct use, as they can change from release to release of the OS. So, the best documentation you'll see is the man pages

How do I print an address in x86 NASM assembly language? [duplicate]

拜拜、爱过 提交于 2021-01-27 18:53:17
问题 This question already has answers here : How to convert a binary integer number to a hex string? (2 answers) Closed 1 year ago . I am trying to print address of variable in NASM x86 assembly. When I assemble this code it assembles fine, however when I run this code it prints two characters instead of the address. section .bss Address: RESB 4 section .data variable db 1 section .text global _start _start: mov eax , variable ; variable Address is stored in eax register mov [Address] , dword eax

Where is located syscall_table in kernel x86_64?

烈酒焚心 提交于 2021-01-27 15:16:47
问题 I'm trying to add new System Call to Linux Kernel(x86_64). Based on this article which explained how to add System Call to Kernel(x86). The article says I need to define my System Call name in a file called syscall_table_32.S which is located in src/arch/x86/syscall_table_32.S . But in my case, there is no file named syscall_table_32.S or syscall_table_64.S in the kernel source! There isn't even a directory for x64 System Call table in src/arch/ . So, where is syscall_table_64.S defined in