system-calls

execve() argv in GAS AT&T assembler

故事扮演 提交于 2021-01-27 14:40:43
问题 My code: .section .data name: .string "/bin/sh" args: .string "-c" .string "ls" .section .text .globl _start _start: pushq $0 pushq name movq $59, %rax movq %rsp, %rdi pushq $0 pushq args movq %rsp, %rsi movq $0, %rdx syscall I know that the second argument of execve is array of chars. How to do this in assembly avoiding this: execve("./payload", ["./payload"], 0x7ffc291fd160 /* 40 vars */) = 0 execve("/bin/sh", [0x736c00632d], NULL) = -1 EFAULT (Bad address) --- SIGSEGV {si_signo=SIGSEGV, si

What is causing my program to hang and not exit properly? (pipe, read system call, while loop)

こ雲淡風輕ζ 提交于 2021-01-27 11:22:49
问题 I have a program where I write from several child processes to a pipe, and then attempt to read all the messages written to each process, from each pipe, and print them to the screen. With the following code (specifically, the while loop using the read system call to store the messages into buffer buf ), my program will hang and not exit, nor print all of the messages sent to the different processes. for (i = 0; i < MAXP; i++) { if(id == i) { while(read(pfds[i][0], buf, sizeof(buf)) > 0)

What is causing my program to hang and not exit properly? (pipe, read system call, while loop)

ぃ、小莉子 提交于 2021-01-27 11:22:48
问题 I have a program where I write from several child processes to a pipe, and then attempt to read all the messages written to each process, from each pipe, and print them to the screen. With the following code (specifically, the while loop using the read system call to store the messages into buffer buf ), my program will hang and not exit, nor print all of the messages sent to the different processes. for (i = 0; i < MAXP; i++) { if(id == i) { while(read(pfds[i][0], buf, sizeof(buf)) > 0)

golang no such device in syscall.Mount

安稳与你 提交于 2021-01-27 05:32:13
问题 I'm trying to use the syscall.Mount function to mount a usb pendrive and autodetect the filesystem to some folder. I fetch the device path from the kernel's netlink socket and try to mount it to /tmp/+devicename , in my instance /dev/sdd1 should be mounted to /tmp/sdd1 I have the following lines of code in a go program if err := syscall.Mount(src, target, "auto", 0, "ro"); err != nil { log.Printf("Mount(\"%s\", \"%s\", \"auto\", 0, \"ro\")\n",src,target) log.Fatal(err) } Output: main.go:47:

Linux API Calls to implement rm, mv, and cp [closed]

丶灬走出姿态 提交于 2021-01-20 12:00:53
问题 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 . Improve this question I'm writing my own little shell in C, or at least I'm going to start today. I want to implement three functions. remove file1 What system calls would I need for this? Just open file and delete its contents or is there a system call to delete a file besides

What is the written-out word for O_EXCL

霸气de小男生 提交于 2021-01-05 09:20:06
问题 I was writing a safe enum class for the different file flags listed in open(3) , when I noticed that I couldn't find the written-out word for O_EXCL . enum class Flags { readOnly, // O_RDONLY truncate, // O_TRUNC ? // O_EXCL }; Two possible meanings come into my mind: OPEN_EXCLUSIVE OPEN_EXISTS_CLOSE But I can't find any resources on the intended meaning. 回答1: Exclusive would be a correct word here, since the flag is exclusive to the O_CREAT flag and makes the function fail if the file exists

X86 read from stdin and write to stdout without referring the standard library

六月ゝ 毕业季﹏ 提交于 2020-12-30 03:56:06
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

X86 read from stdin and write to stdout without referring the standard library

做~自己de王妃 提交于 2020-12-30 03:55:50
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

X86 read from stdin and write to stdout without referring the standard library

廉价感情. 提交于 2020-12-30 03:55:33
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

Adding new System Call to Linux Kernel 3.13 on 64 bit system

陌路散爱 提交于 2020-12-29 05:45:48
问题 I'm trying to add a simple helloworld System Call to kernel 3.13.0-37-generic on 64 bit system. I'll try to show what I did so far step by step : 1- I've downloaded kernel source by : sudo apt-get source linux-image-3.13.0-37-generic After that, kernel source files extracted to /usr/src/ 2- Define a new system call sys_hello() : I've created a directory with hello name in the kernel source directory in /usr/src/linux-3.13/ And I created a hello.c file in hello directory with below content :