system-calls

A simple new system call in FreeBSD-11.0-RELEASE-amd64

旧街凉风 提交于 2019-12-11 06:43:15
问题 I am a newbie in FreeBSD. I installed FreeBSD-11.0-RELEASE-amd64 on VMware. I want to add first new system call. I find this link. I Did: cd /usr/src/sys/kern ee mykern.c #include <sys/sysproto.h> #include <sys/proc.h> #include <sys/types.h> #include <sys/systm.h> #ifndef _SYS_SYSPROTO_H_ struct myargs { int k; }; #endif int func(struct thread *p, struct myargs *uap) { printf("Hello"); return (0); } I added my system call to the end /kern/syscalls.master 550 AUE_NULL STD { int func(int k);}

How to invoke a system call via sysenter in inline assembly?

和自甴很熟 提交于 2019-12-11 06:24:28
问题 How can we implement the system call using sysenter/syscall directly in x86 Linux? Can anybody provide help? It would be even better if you can also show the code for amd64 platform. I know in x86, we can use __asm__( " movl $1, %eax \n" " movl $0, %ebx \n" " call *%gs:0x10 \n" ); to route to sysenter indirectly. But how can we code using sysenter/syscall directly to issue a system call? I find some material http://damocles.blogbus.com/tag/sysenter/ . But still find it difficult to figure out

C - Lstat on /proc/pid/exe

三世轮回 提交于 2019-12-11 05:28:07
问题 I'm trying to get the size in bytes of a /proc/pid/exe file with lstat. Here's my code: int main(int argc, char *argv[]) { struct stat sb; char *linkname; ssize_t r; if (argc != 2) { fprintf(stderr, "Usage: %s <pathname>\n", argv[0]); exit(EXIT_FAILURE); } if (lstat(argv[1], &sb) == -1) { perror("lstat"); exit(EXIT_FAILURE); } printf("sb.st_size %d\n", sb.st_size); exit(EXIT_SUCCESS); } It seems like sb.st_size is ALWAYS equal to 0, and I don't understand why. Plus, this sample is extracted

shellcode calls different syscall while runing alone as individiual code and while running with C++ code

烂漫一生 提交于 2019-12-11 04:48:07
问题 I've such a code that run's shell: BITS 64 global _start _start: mov rax, 59 jmp short file c1: pop rdi jmp short argv c2: pop rsi mov rdx, 0 syscall file: call c1 db '/bin/sh',0 argv: call c2 dq arg, 0 arg: db 'sh',0 It works when it's built in this way: nasm -f elf64 shcode.asm ld shcode.o -o shcode Althougt, when I bring it into binary form with: nasm -f bin shcode.asm paste it into following C++ code: int main(void) { char kod[]="\xB8\x3B\x00\x00\x00\xEB\x0B\x5F\xEB\x15\x5E\xBA\x00\x00

What is the difference between system calls and instruction set

妖精的绣舞 提交于 2019-12-11 04:43:40
问题 Iam confused whether system calls and instruction set are synonymous? Do the instructions like MOV, LOAD, CALL, IN, OUT , ADD, SUB etc fall in the category of system calls? System call instructions like open(), close(), read(), write(). If not then what is the relationship between them. Can someone please explain and clear the confusion. 回答1: Several books are needed to explain the difference. I recommend notably Operating Systems : Three Easy Pieces and some book on computer architecture, or

How can a process inquire, when it was started?

房东的猫 提交于 2019-12-11 04:34:37
问题 Is there a call, that can be used to ask the OS, when the current process started? Of course, one could simply call gettimeofday() at start-up and refer to that once-recorded value through the life of the process, but is there another option? Obviously, the OS keeps the record for each process (one can see it in the output of ps , for example). Can it be queried by the process itself (using C)? An ideal solution would, of course, be cross-platform, but something (Free)BSD-specific is fine too

Context switching when a thread invokes a system call

可紊 提交于 2019-12-11 04:02:54
问题 I have a process with multiple threads. If one of my threads invokes a system call like gettimeofday() , does the kernel only switch that thread out of context to service the system call, or does it switch the entire process (and all other threads) out of context? 回答1: Most system calls may involve a context switch (if other tasks are runnable) and switch the processor's state to kernel mode. But gettimeofday (and e.g. getpid() ) are unusual. with recent kernels they use VDSO to avoid it (and

Print floats in nasm without binding to C functions

心不动则不痛 提交于 2019-12-11 02:43:48
问题 I'm wondering, how to print float numbers in nasm using only syscalls in linux. I have the following code, but it prints only @ section .data num dq 2.0 len equ $ - num section .text global _start _start: mov edx, len mov ecx, num mov ebx, 1 mov eax, 4 int 80h mov eax, 1 int 80h Who to make it right? 回答1: You can use the FPU to convert a float into a writeable string. The following example takes PI (a number with quite a few digits) and separates the float into an integral and a fractional

Why does gdb backtrace show only one frame when catching syscall?

做~自己de王妃 提交于 2019-12-11 02:31:13
问题 I'm trying to find all the places in the source of a running program where certain syscalls are used. I set breakpoints like: catch syscall socketcall ...Which is working fine. However, when one of the breakpoints is actually hit, the backtrace always looks the same: (gdb) bt #0 __cp_end () at src/thread/i386/syscall_cp.s:25 And that's all she wrote! Why can't GCC walk the stack and show a full stacktrace going all the way up to main ? 回答1: Why can't GCC walk the stack and show a full