system-calls

Can more than seven arguments be passed to system call in arm linux?

一世执手 提交于 2019-12-11 16:55:38
问题 In arm linux(EABI), system call number is passed in r7 and the arguments can be passed in r0-r6 registers Below table from (syscall(2)) shows the registers used to pass the system call arguments. arch/ABI arg1 arg2 arg3 arg4 arg5 arg6 arg7 Notes ────────────────────────────────────────────────────────────── alpha a0 a1 a2 a3 a4 a5 - arc r0 r1 r2 r3 r4 r5 - arm/OABI a1 a2 a3 a4 v1 v2 v3 arm/EABI r0 r1 r2 r3 r4 r5 r6 I am just curious whether seven is the maximum number of arguments that can be

why we can mmap to a file but exceed the file size?

一世执手 提交于 2019-12-11 16:26:43
问题 For example. fd = ::open ("/test.txt", O_RDONLY, 0); struct stat buf; fstat(fd, &buf); char* addr = (char*)::mmap(NULL, buf.st_size + 10, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); Notice that I mapped + 10 here. But it still works? Why system does NOT apply any check? Is it dangerous? Thanks 回答1: Signature of mmap is: void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); To quote Michael Kerrisk: The length argument specifies the size of the mapping in bytes.

Pass struct to xv6 system call

╄→гoц情女王★ 提交于 2019-12-11 15:55:16
问题 I'm aware which we are not able to pass parameters to xv6 system call directly and we are forced to use it's built in methods. But all examples and questions in this site is about how to send integer to system call. Which it's answer is using argint() method. But my question is, is there anyway to pass "struct" to a xv6 system call? Are there any bulit-in methods for this purpose too? If there is, could you please say a simple example? 回答1: Passing a struct through system call is possible.

Correct usage of fork, wait, exit, etc

不羁的心 提交于 2019-12-11 15:50:17
问题 I have this problem to solve that I have no idea how to do it because there's only a few system calls we can use to solve it and I don't see how they are helpful for the situation. The Exercise: I have matrix with size [10][1000000] with integers and for each line I create a new process with fork(). The idea of each process is to go through all the numbers for that specific line and find a specific number then print a message about it. This was the first step of the problem and it's done. The

Generating random numbers using a syscall

╄→尐↘猪︶ㄣ 提交于 2019-12-11 15:35:38
问题 I'm trying to generate a random integer from 0-99 (inclusive) but I'm having some difficulty finding where it stores the value to when using the 42 syscall. So far I have: li $a1, 100 li $v0, 42 syscall I'm not sure where the value generated is stored so I can use it though. 回答1: From a syscall help page: $a0 is the pseudorandom number generator id, $a1 is the upper bound, and the returned random number will also be contained in $a0 . 来源: https://stackoverflow.com/questions/8394537/generating

How to implement something similar to “truncateat”?

て烟熏妆下的殇ゞ 提交于 2019-12-11 14:39:19
问题 While researching this question I came across the fact that in POSIX (and Linux) there simply is not a truncateat system call. Certain system calls like for instance unlink have an equivalent alternative method with an added at suffix at the end of their names, i.e. unlinkat . The difference between those methods is that the variations with the at suffix accept an additional argument, a file descriptor pointing to a directory. Therefore, a relative path passed into unlinkat is not relative to

Wait for keypress Assembly NASM, Linux

社会主义新天地 提交于 2019-12-11 13:58:09
问题 I'm working on a Hello World in Assembly for x86-64. I have managed to create one that finishes when Enter key is pressed, but I have to finish it when ANY key is pressed. This is the code for waiting the ENTER Key: mov rax, 0 mov rdi, 0 mov rdx, 1 syscall I can't use any int xh or something like that. Only syscalls. Thanks! 回答1: I've answered a similar question before, and gave C code that would work directly with system calls to do what you wanted. Here's a translation of that code to nasm,

linux pipe data from file descriptor into a fifo

人走茶凉 提交于 2019-12-11 13:38:02
问题 Lets say I know that a file descriptor fd is open for reading in my process. I would like to pipe data from this fd into a fifo that is available for reading outside my of process, in a way that avoids calling poll or select on fd and manually reading/forwarding data. Can this be done? 回答1: You mean ask the OS to do that behind the scenes on an ongoing basis from now on? Like an I/O redirection? No, you can't do that. You could spawn a thread that does nothing but read the file fd and write

Go package syscall conn.Read() is non-blocking and cause high CPU usage

老子叫甜甜 提交于 2019-12-11 12:48:45
问题 Strangely, in my case Read() is non-blocking and caused high CPU usage. My code: In function main : l, err := net.Listen("tcp", ":13798") if err != nil { log.Fatal(err) } for { // Wait for a connection. conn, err := l.Accept() if err != nil { log.Fatal(err) } // Handle the connection in a new goroutine. // The loop then returns to accepting, so that // multiple connections may be served concurrently. go reqHandler.TCPHandler(conn) runtime.Gosched() } Function TCPHandler : func TCPHandler(conn

Why isn't usleep working?

拈花ヽ惹草 提交于 2019-12-11 12:38:19
问题 I have a function that is being run on a separate queue/thread. In this function I am trying to call usleep . Regardless of the value passed in, usleep doesn't seem to work. The same goes for sleep() . To diagnose the error, I printed out errno . errno prints as: "Interrupted system call" What exactly does this mean, and how could I go about diagnosing it? The man pages describe the error as: [EINTR] A signal was delivered to the process and its action was to invoke a signal-catching function