system-calls

Converting a pointer to a byte slice

随声附和 提交于 2019-12-06 12:44:47
The Mmap() syscall in the x/sys/unix package in Golang returns a []byte type, while the underlying syscall actually returns a pointer. How does it do this? More specifically, in this package by a Golang developer, the VirtualAlloc function simply returns a pointer. How can this be converted to a byte slice, the same way as it's done in the Unix package? Using the unsafe package you can do the same thing golang.org/x/sys/unix does in the Mmap method of its unexported mmapper type: // Slice memory layout var sl = struct { addr uintptr len int cap int }{addr, length, length} // Use unsafe to turn

Extending the Rasbian Kernel (Linux Kernel 3.10.28) for Arm / Raspberry PI - How to correctly add own system calls?

三世轮回 提交于 2019-12-06 12:03:15
I need to add an own system call to the Raspbian Linux Kernel. Now I am stuck after searching for about 2 days to find a solution. To add a system call, I am basically following the general outline ( http://elinux.org/RPi_Kernel_Compilation ) using the kernel sources from the following git repo: git://github.com/raspberrypi/tools.git I have installed a cross-compile environment using crosstool-ng ( http://www.kitware.com/blog/home/post/426 ). All these above works. I am able to compile and deploy a new kernel. I am furthermore able to cross-compile for the Raspbian. I am trying to add a 'hello

In linux, how to do system calls through GNU ARM assembly

匆匆过客 提交于 2019-12-06 11:01:08
问题 Till now, I only know how to exit a program by gnu arm assembly. #exit(0) mov r0, #0 # return code mov r7, #1 # supervisor service number svc # call supervisor service But there are still many other syscalls like read, write, fork... I suppose that each of them will require different service number, different numbers of registers as arguments and different rules on how to use registers. My question is where I can get information on writing assembly for each of them. I searched google but the

C synchronize processes using signal

冷暖自知 提交于 2019-12-06 09:16:47
Okay so I am trying to teach myself on how to do signalling, and I came across a hiccup and I can't figure out what I'm doing wrong. What is going on right now is: it is executing the parent then goes to child and then back to parent.. It's not doing what I want it to do which is execute the parent (which the user defines the amount of time it runs) then kills it then go to child and run itself at the same amount of time. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> // for wait #include <sys/wait.h> // for wait void action(int); void

Using Ptrace to track the location of files being opened

放肆的年华 提交于 2019-12-06 08:52:54
I was using the following code which actually gets me the contents in the registers (eax, ebx, ecx) whenever a open system call is called. Now after a lot of struggle I understood what the values signify from this Question . ebx contains the pointer to filename. But when I try to access it I was getting a segmentation fault. Where am I going wrong? The code can be accessed from the here Every process has its own address space. An address obtained from another process will not be valid in yours. One way to read memory in the other process would be to use PTRACE_PEEKDATA . On Linux, another way

when is the system call set_tid_address used?

泄露秘密 提交于 2019-12-06 07:54:44
i have been trying to undertand the system calls, and want to understand how set_tid_address works. bascially from what i have read is that it returns the pid of the program or process which is executed. I have tested this with ls, however with some commands like uptime, top etc i dont see set_tid_address being used. Why is that? The clone() syscall can take a CLONE_CHILD_CLEARTID flag, that the value at child_tidptr (another clone() argument) gets cleared and an associated futex signal a wake-up when the child thread exits. This is used to implement pthread_join() (the parent thread waits on

How do I write the value in RAX to STDOUT in assembly?

最后都变了- 提交于 2019-12-06 07:18:30
问题 I can use syscall for write to print some data in memory to STDOUT: ssize_t write(int fd, const void *buf, size_t count); That is: movq $1, %rax movq $1, %rdi move address_of_variable %rsi movq $5, %rdx syscall But how can I print register values? UPDATE .text call start start: movq $100, %rdi movq $10, %rsi call print_number ret buffer: .skip 64 bufferend: # rdi = number # rsi = base print_number: leaq bufferend, %rcx movq %rdi, %rax 1: xorq %rdx, %rdx divq %rsi add $'0', %dl cmp $'9', %dl

Use in memory certificate for client authentication

大城市里の小女人 提交于 2019-12-06 06:42:12
问题 I have a non-exportable certificate in my windows box which works fine with IE and Chrome when I try to access websites. I would like to be able to use this certificate from a Go CLI application to access a HTTPS URI that requires client certificate authentication but also a non standard CA cert which I suppose I need to add to the request if its not already there. Some code example would be appreciated since documentation I found concerning calls do not have any. I suppose that I would use

To sleep in C, should I use while with a clock, or a system call?

空扰寡人 提交于 2019-12-06 05:35:23
I was checking out clock() on cplusplus.com . Their example involves making the process wait for a second and then output a line, in a loop until 10 seconds have ellapsed. I need to do something similar in the homework assignment I'm working on. What I was wondering was this: if I just send my program into a loop, isn't that using system resources to just spin me around? In this case, wouldn't a system call be better? Thanks for your help! Yes, using a system call or library function like sleep() is much better. That clock() example is just meant to just show how to correctly call the function

Modifying integer value from another process using process_vm_readv

给你一囗甜甜゛ 提交于 2019-12-06 04:40:19
I am using Ubuntu Linux to write two programs. I am attempting to change the value of an integer from another process. My first process (A) is a simple program that loops forever and displays the value to the screen. This program works as intended and simply displays the value -1430532899 (0xAABBCCDD) to the screen. #include <stdio.h> int main() { //The needle that I am looking for to change from another process int x = 0xAABBCCDD; //Loop forever printing out the value of x int counter = 0; while(1==1) { while(counter<100000000) { counter++; } counter = 0; printf("%d",x); fflush(stdout); }