system-calls

Linux syscall, libc, VDSO and implementation dissection

狂风中的少年 提交于 2019-12-01 16:47:10
I dissects the syscall call in the last libc: git clone git://sourceware.org/git/glibc.git And I have this code in sysdeps/unix/sysv/linux/i386/sysdep.h: # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *%%gs:%P2" \ : "=a" (resultvar) \ : "a" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \ ASMARGS_##nr(args) : "memory", "cc") If I understand well this code, the LOADREGS_##nr(args) macro loads the argument in the registers ebx, ecx, edx, esi, edx and ebp. sysdeps/unix/sysv/linux/i386/sysdep.h # define LOADREGS_0() # define ASMARGS

system call to map memory to a file descriptor (inverse mmap)?

五迷三道 提交于 2019-12-01 16:19:33
问题 I want to be able to map memory to a file descriptor so I can use some existing functions that need a file descriptor. Here's essentially what I'm looking for: void do_operation1(int fd); char data[DATA_MAX] = { /* embedded binary data */ }; int fd = addr_to_fd(data, DATA_MAX); do_operation1(fd); /* ... operate on fd ... */ What system call, or calls, can I use to accomplish this? 回答1: You should Check out shm_open() . 回答2: Some implementations have fmemopen() . (Then of course you have to

Where is clone() method in sched.h on Mac OS X

萝らか妹 提交于 2019-12-01 15:59:29
问题 I can not find clone() in the sched.h header file. Where is it on Mac OS X? 回答1: man 2 clone says: The clone() and sys_clone calls are Linux-specific and should not be used in programs intended to be portable. 回答2: clone() is a Linux-specific call and doesn't exist in OSX. 来源: https://stackoverflow.com/questions/8320174/where-is-clone-method-in-sched-h-on-mac-os-x

Filter out broken pipe errors

戏子无情 提交于 2019-12-01 15:58:50
I'm getting an error returned from an io.Copy call, to which I've passed a socket ( TCPConn ) as the destination. It's expected that the remote host will simply drop the connection when they've had enough, and I'm not receiving anything from them. When the drop occurs, I get this error: write tcp 192.168.26.5:21277: broken pipe But all I have is an error interface. How can I differentiate broken pipe errors from other kinds of error? if err.Errno == EPIPE... The broken pipe error is defined in the syscall package. You can use the equality operator to compare the error to the one in syscall.

Linux syscall, libc, VDSO and implementation dissection

旧巷老猫 提交于 2019-12-01 15:27:49
问题 I dissects the syscall call in the last libc: git clone git://sourceware.org/git/glibc.git And I have this code in sysdeps/unix/sysv/linux/i386/sysdep.h: # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *%%gs:%P2" \ : "=a" (resultvar) \ : "a" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \ ASMARGS_##nr(args) : "memory", "cc") If I understand well this code, the LOADREGS_##nr(args) macro loads the argument in the registers ebx,

Filter out broken pipe errors

萝らか妹 提交于 2019-12-01 14:32:45
问题 I'm getting an error returned from an io.Copy call, to which I've passed a socket ( TCPConn ) as the destination. It's expected that the remote host will simply drop the connection when they've had enough, and I'm not receiving anything from them. When the drop occurs, I get this error: write tcp 192.168.26.5:21277: broken pipe But all I have is an error interface. How can I differentiate broken pipe errors from other kinds of error? if err.Errno == EPIPE... 回答1: The broken pipe error is

sys_call_table in linux kernel 2.6.18

旧城冷巷雨未停 提交于 2019-12-01 14:15:55
I am trying to set the sys exit call to a variable by extern void *sys_call_table[]; real_sys_exit = sys_call_table[__NR_exit] however, when I try to make, the console gives me the error error: ‘__NR_exit’ undeclared (first use in this function) Any tips would be appreciated :) Thank you Since you are in kernel 2.6.x , sys_call_table isnt exported any more. If you want to avoid the compilation error try this include #include<linux/unistd.h> however, It will not work. So the work around to "play" with the sys_call_table is to find the address of sys_call_table in SystemXXXX.map (located at

How to disassemble a system call

拥有回忆 提交于 2019-12-01 13:59:50
If I have the virtual address of system call, can I disassemble that system call? I want to do it on running kernel to find what all address are handled by the particular system call while running. I am running 32 bit 2.6.38 kernel (x86). I am not sure you question is very meaningful. Please read more about system calls , kernels , operating systems , linux , and the linux kernel Essentially, a system call is (from the application point of view) an atomic operation implemented by one machine instruction ( int 0x80 , syscall , etc.) with a few book-keeping instructions before (e.g. loading the

sys_call_table in linux kernel 2.6.18

荒凉一梦 提交于 2019-12-01 12:06:25
问题 I am trying to set the sys exit call to a variable by extern void *sys_call_table[]; real_sys_exit = sys_call_table[__NR_exit] however, when I try to make, the console gives me the error error: ‘__NR_exit’ undeclared (first use in this function) Any tips would be appreciated :) Thank you 回答1: Since you are in kernel 2.6.x , sys_call_table isnt exported any more. If you want to avoid the compilation error try this include #include<linux/unistd.h> however, It will not work. So the work around

How to know when a process created by Process.Start() was closed?

好久不见. 提交于 2019-12-01 11:38:58
问题 I'm using this: var proc2 = Process.Start(Path.GetFullPath(filename)); proc2.Exited += (_, __) => { MessageBox.Show("closed!"); }; But I close the window and don't get MessageBox.Show("closed!"); . How to fix this? 回答1: You need to set Process.EnableRaisingEvents to true . 回答2: You forgot to set the EnableRaisingEvents to true. Also, you may want to create a Process with the constructor, set the ProcessStartInfo and then call Start after you register to listen to the event. Otherwise you have