system-calls

Assembly segmentation fault after making a system call, at the end of my code

試著忘記壹切 提交于 2019-12-17 03:44:13
问题 I was experimenting and have the following assembly code, which works very well, except that I get a "Segmentation fault (core dumped)" message right before my program ends: GLOBAL _start %define ___STDIN 0 %define ___STDOUT 1 %define ___SYSCALL_WRITE 0x04 segment .data segment .rodata L1 db "hello World", 10, 0 segment .bss segment .text _start: mov eax, ___SYSCALL_WRITE mov ebx, ___STDOUT mov ecx, L1 mov edx, 13 int 0x80 It doesn't matter whether or not I have ret at the end; I still get

How does ptrace work with 2 different processes?

谁说胖子不能爱 提交于 2019-12-14 04:00:50
问题 I was reading about ptrace on the net and found that a process can request to trace another process by using PTRACE_ATTACH but apparently all the examples available involve the use of fork(). What I want is to have 2 programs - prg1.c and prg2.c where prg2.c should trace prg1.c. I tried using PTRACE_ATTACH in prg2.c but it seems that the call failed - prg2.c couldn't trace prg1.c . How does ptrace work ? Can anybody explain ? Code for prg1.c : #include <stdio.h> #include <sys/ptrace.h>

how to determine if two file are identical in c using system call

ⅰ亾dé卋堺 提交于 2019-12-14 03:31:25
问题 i need to see if 2 files are identical so i used struct stat fdin = open(argv[0],O_RDONLY); statos= fstat(fdin, &stat); close(fdin); fdin = open(argv[1],O_RDONLY); statos1= fstat(fdin, &stat1); close(fdin); printf("file 1 is in size: %lu\n",stat1.st_ino); printf("file 2 is in size: %lu\n",stat.st_ino); the result file 1 is in size: 9569486 file 2 is in size: 9569479 why is the st.ino aren't identical for the same file with the same path?? and how can i do so if two different file are

ptrace %edx for sys_open inconsistent

岁酱吖の 提交于 2019-12-13 19:07:59
问题 I am trying to get the filename from the sys_open system call using ptrace. I get the filepath pointer, and I am able to get the correct data from that address, however, I need a way to know how much data to get, ie the length of the filename. I thought this value was supposed to be in edx, but that doesn't seem to be the case here. Any thoughts? orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL); if(orig_eax == __NR_open){ ptrace(PTRACE_GETREGS, child, NULL, &regs); if(regs.eax >

Why does printf show negative values for unsigned int? [duplicate]

南笙酒味 提交于 2019-12-13 18:26:06
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Unsigned long with negative value I have written one kernel module which interrupts any system call, prints its current user_id and input parameters passed to the system call function. Among them, one is sys_ioctl() as below: asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd,unsigned long arg); which means all input parameters are unsigned int numbers. But when I print input parameters, I get the

Calling times() in kernel space

╄→гoц情女王★ 提交于 2019-12-13 16:08:46
问题 I am developing a kernel module, and I need to get an approximate value of the CPU time consumed by some process (iterating the processes is not an issue). Specifically, I want the same behavior provided by the libc clock or the times syscall. I tried calling do_sys_times but seems it's not exported (undefined symbol when compiled). Is there a way to call times inside a kernel module? Are there any other alternatives? 回答1: If you want precisely measure times between some events in kernel

C Programming - Stat system call - Error

喜夏-厌秋 提交于 2019-12-13 13:28:34
问题 I'm new to C but trying some system calls. I'm writing program that iterates through all files in a directory and prints the current file name and size. I can get the program to print the file name but it errors when I preform the stat system call. Here is some of the code: while (dptr = readdir(dirp)) { if (stat(dptr->d_name, &buf) != 0) { //Always does this and it does print the file name printf("Error on when getting size of %s \n", dptr->d_name); } else { //Never gets here printf("%u",

Which system calls can return EINTR or EAGAIN error codes? [closed]

若如初见. 提交于 2019-12-13 11:29:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Which of the following system calls can return EINTR or EAGAIN/EWOULDBLOCK? getsockname() chdir() bind() fcntl() listen() setsid() setsockopt() socket() stat() unlink() access() accept() open() usleep() dup2() fork() waitpid() wait() read() write() Some of these system calls

how to use write system call

て烟熏妆下的殇ゞ 提交于 2019-12-13 09:47:19
问题 My problem is system call write. arc file contains multiple file contains. I know each file size. and i want create different output files and I want write these contains into the these output files. I can create files but I can not write into the these file. I marked "PROBLEM HERE" below code. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #define BUFSIZE 4096 struct stat st; struct inputfiles{

C - syscall - 64-bit - pointer

耗尽温柔 提交于 2019-12-13 08:59:58
问题 I am on 64-bit Linux x86. I need to execute mmap syscall using syscall function. mmap syscall number is 9: printf("mmap-1: %lli\n", syscall(9, 0, 10, 3, 2 | 32, -1, 0)); printf("mmap-2: %lli\n", mmap( 0, 10, 3, 2 | 32, -1, 0)); However, when I run it, the syscall function gives wrong results. mmap-1: 2236940288 mmap-2: 140503502090240 mmap-1: 3425849344 mmap-2: 140612065181696 mmap-1: 249544704 mmap-2: 139625341366272 mmap works just fine, but the "addresses" returned syscall result in