system-calls

segfault with clone() and printf

a 夏天 提交于 2019-12-01 09:08:43
问题 I'm trying to experiment with how clone() is implemented for threads in Linux 3.10.0-327.3.1.el7.x86_64 I'm running this piece of code and having occasional segfaults. I know if I use CLONE_THREAD then there's no way to check if the thread finished, but why does printf cause problems? How does the Pthread library handle this issue? Without the printf s there's no segfault. #define STACK_SIZE (1ULL<<22) //4MB int tmp = 10; int threadfunc(void *ptr) { printf("i'm here\n"); tmp++; return 0; }

writing a glibc api for a system call [duplicate]

爱⌒轻易说出口 提交于 2019-12-01 09:06:31
Possible Duplicate: Need help with glibc source I understand how to implement our own system calls in linux kernel. I know we can call this with syscall() or with _asm() in a c program. But I want to understand how to write glibc api for this new system call?. How the open() and read() glibc function calls mapping into system call in kernel?. char message[ ] = "Hello!\n"; int main( void ) { write( 1, message, 7 ); exit( 0 ); } When I convert the above program into assembly it is giving main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $20, %esp

Details of Syscall.RawSyscall() & Syscall.Syscall() in Go?

北城以北 提交于 2019-12-01 08:55:55
I'm reading source code in package syscall now, and met some problems: Since I'm totally a noob of syscall and assembly , so don't hesitate to share anything you know about it :) First about func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) : what does its parameter trap, a1, a2, a3 & return value r1 r2 means? I've searched documents and site but seems lack of description about this. Second, since I'm using darwin/amd64 I searched source code and find it here: http://golang.org/src/pkg/syscall/asm_darwin_amd64.s?h=RawSyscall Seems it's written by assemble(which I can't

In what library on Linux are the system calls and how is this library linked to the executable object file that contains the system calls?

纵然是瞬间 提交于 2019-12-01 08:54:07
I know that the system calls are not in the C standard Library. Is there any library (some sort of a system library) where the system calls are? If there is such a library how is this library linked to the executable program? A system call can work in a few different ways, depending on the target architecture, but in any case, it is not a library call. It is a way for a running user-space program to call some functionality in the kernel. In very old systems, this typically meant to jump directly to some address where this kernel function starts. Later, kernels introduced "jump tables" adding a

In what library on Linux are the system calls and how is this library linked to the executable object file that contains the system calls?

痞子三分冷 提交于 2019-12-01 06:43:25
问题 I know that the system calls are not in the C standard Library. Is there any library (some sort of a system library) where the system calls are? If there is such a library how is this library linked to the executable program? 回答1: A system call can work in a few different ways, depending on the target architecture, but in any case, it is not a library call. It is a way for a running user-space program to call some functionality in the kernel. In very old systems, this typically meant to jump

writing a glibc api for a system call [duplicate]

人盡茶涼 提交于 2019-12-01 06:32:21
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Need help with glibc source I understand how to implement our own system calls in linux kernel. I know we can call this with syscall() or with _asm() in a c program. But I want to understand how to write glibc api for this new system call?. How the open() and read() glibc function calls mapping into system call in kernel?. char message[ ] = "Hello!\n"; int main( void ) { write( 1, message, 7 ); exit( 0 ); } When

significance of (void*) -1 [duplicate]

房东的猫 提交于 2019-12-01 06:28:05
This question already has an answer here: Is ((void *) -1) a valid address? 3 answers I was looking at the documentation of sbrk system call and found this : On success, sbrk() returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error, (void *) -1 is returned, and errno is set to ENOMEM . Now, What's the significance of (void *) -1 ? What is the exact memory address it points to? (if it does at all) How is it guaranteed that (void *) -1 is not a valid address that can be returned by sbrk() on success?

Details of Syscall.RawSyscall() & Syscall.Syscall() in Go?

 ̄綄美尐妖づ 提交于 2019-12-01 06:25:33
问题 I'm reading source code in package syscall now, and met some problems: Since I'm totally a noob of syscall and assembly , so don't hesitate to share anything you know about it :) First about func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) : what does its parameter trap, a1, a2, a3 & return value r1 r2 means? I've searched documents and site but seems lack of description about this. Second, since I'm using darwin/amd64 I searched source code and find it here: http:/

xv6 add a system call that counts system calls

假装没事ソ 提交于 2019-12-01 06:20:56
EDIT: GOT IT here is what I did: in syscall.c: extern int numSysCalls; in sysproc.c: int numSysCalls = -1; Okay, so I'm working on implementing an easy system call that returns the number of times a system call has been made. Seems easy, but I'm getting an error I don't understand... Basically, here is what I did: in syscall.c there is a function called syscall() that checks whether it is a syscall or not. I have basically declared a variable and am incrementing it every time this function is called. Var Declaration in syscall.c: 18: int16_t numSysCalls = -1; //global Syscall() function: 115:

So malloc doesn't invoke any syscall?

一笑奈何 提交于 2019-12-01 05:18:02
Related code: write(-1, "test", sizeof("test")); void * p = malloc(1024); void * p2 = malloc(510); write(-1, "hi", sizeof("hi")); Related strace output: write(4294967295, "test\0", 5) = -1 EBADF (Bad file descriptor) brk(0) = 0x601000 brk(0x622000) = 0x622000 write(4294967295, "hi\0", 3) = -1 EBADF (Bad file descriptor) I'm surprised such low level operation doesn't involve syscall? Not every call to malloc invokes a syscall. On my linux desktop malloc allocates a space in 128KB blocks and then distributes the space. So I will see a syscall every 100-200 malloc calls. On freebsd malloc