system-calls

How does System.currentTimeMillis() get its time

青春壹個敷衍的年華 提交于 2019-12-01 04:26:25
问题 Is the method System.currentTimeMillis() implemented to make a system call to the underlying operating system in order to receive the current time? I ask since as far as I know, the method runs pretty fast, and takes as little as 6 CPU clocks, but this doesn't make sense because system calls are known to be slow. What am I missing here? 回答1: System.currentTimeMillis() does not usually require switching to kernel mode. OS provides a mechanism that allows reading current time from user mode by

Constraining r10 register in gcc inline x86_64 assembly

痞子三分冷 提交于 2019-12-01 03:30:47
I'm having a go at writing a very light weight libc replacement library so that I can better understand the kernel - application interface. The first task is clearly getting some system call wrappers in place. I've successfully got 1 to 3 argument wrappers working but I'm struggling with a 4 argument varient. Here's my starting point: long _syscall4(long type, long a1, long a2, long a3, long a4) { long ret; asm ( "syscall" : "=a"(ret) : "a"(type), "D"(a1), "S"(a2), "d"(a3), "r10"(a4) : "c", "r11" ); return ret; } The compiler gives me the following error: error: matching constraint references

Constraining r10 register in gcc inline x86_64 assembly

末鹿安然 提交于 2019-12-01 00:51:53
问题 I'm having a go at writing a very light weight libc replacement library so that I can better understand the kernel - application interface. The first task is clearly getting some system call wrappers in place. I've successfully got 1 to 3 argument wrappers working but I'm struggling with a 4 argument varient. Here's my starting point: long _syscall4(long type, long a1, long a2, long a3, long a4) { long ret; asm ( "syscall" : "=a"(ret) : "a"(type), "D"(a1), "S"(a2), "d"(a3), "r10"(a4) : "c",

How to allocate a new TLS area with clone system call

 ̄綄美尐妖づ 提交于 2019-11-30 22:39:01
Short version of question: What parameter do I need to pass to the clone system call on x86_64 Linux system if I want to allocate a new TLS area for the thread that I am creating. Long version : I am working on a research project and for something I am experimenting with I want to create threads using the clone system call instead of using pthread_create . However, I also want to be able to use thread local storage. I don't plan on creating many threads right now, so it would be fine for me to create a new TLS area for each thread that I create with the clone system call. I was looking at the

Can eBPF modify the return value or parameters of a syscall?

╄→гoц情女王★ 提交于 2019-11-30 21:33:12
To simulate some behavior I would like to attach a probe to a syscall and modify the return value when certain parameters are passed. Alternatively, it would also be enough to modify the parameters of the function before they are processes. Is this possible with BPF? I believe that attaching eBPF to kprobes/kretprobes gives you read access to function arguments and return values, but that you cannot tamper with them. I am NOT 100% sure; good places to ask for confirmation would be the IO Visor project mailing list or IRC channel (#iovisor at irc.oftc.net). As an alternative solution, I know

On Linux, in C, how can I get all threads of a process?

牧云@^-^@ 提交于 2019-11-30 21:03:40
How to iterate through all tids of all threads of the current process? Is there some way that doesn't involve diving into /proc ? lvella The code I am using, based on reading /proc #include <sys/types.h> #include <dirent.h> #include <stdlib.h> #include <stdio.h> Then, from inside a funcion: DIR *proc_dir; { char dirname[100]; snprintf(dirname, sizeof dirname, "/proc/%d/task", getpid()); proc_dir = opendir(dirname); } if (proc_dir) { /* /proc available, iterate through tasks... */ struct dirent *entry; while ((entry = readdir(proc_dir)) != NULL) { if(entry->d_name[0] == '.') continue; int tid =

Can eBPF modify the return value or parameters of a syscall?

懵懂的女人 提交于 2019-11-30 17:13:15
问题 To simulate some behavior I would like to attach a probe to a syscall and modify the return value when certain parameters are passed. Alternatively, it would also be enough to modify the parameters of the function before they are processes. Is this possible with BPF? 回答1: I believe that attaching eBPF to kprobes/kretprobes gives you read access to function arguments and return values, but that you cannot tamper with them. I am NOT 100% sure; good places to ask for confirmation would be the IO

On Linux, in C, how can I get all threads of a process?

这一生的挚爱 提交于 2019-11-30 17:10:14
问题 How to iterate through all tids of all threads of the current process? Is there some way that doesn't involve diving into /proc ? 回答1: The code I am using, based on reading /proc #include <sys/types.h> #include <dirent.h> #include <stdlib.h> #include <stdio.h> Then, from inside a funcion: DIR *proc_dir; { char dirname[100]; snprintf(dirname, sizeof dirname, "/proc/%d/task", getpid()); proc_dir = opendir(dirname); } if (proc_dir) { /* /proc available, iterate through tasks... */ struct dirent

Huge memory leak in repeated os.path.isdir calls?

折月煮酒 提交于 2019-11-30 16:27:49
问题 I've been scripting something that has to do with scanning directories and noticed a severe memory leak when calling os.path.isdir, so I've tried the following snippet: def func(): if not os.path.isdir('D:\Downloads'): return False while True: func() Within a few seconds, the Python process reached 100MB RAM. I'm trying to figure out what's going on. It seems like the huge memory leak is in effect only when the path is indeed a valid directory path (meaning the 'return False' is not executed)

Why blocking system calls blocks entire procedure with user-level threads?

拥有回忆 提交于 2019-11-30 13:34:25
问题 I dont understand the following: User-level threads requires non-blocking systems call i.e., a multithreaded kernel. Otherwise, entire process will blocked in the kernel, even if there are runable threads left in the processes. How the kernel threads handle the blocking system calls? In the user-level threads when one thread is making a blocking system call (e.g. read) why cant other threads continue their work? 回答1: In the user-level threads when one thread is making a blocking system call