system-calls

How to prohibit system calls, GNU/Linux

北城余情 提交于 2019-12-04 06:21:44
I'm currently working on the back-end of ACM-like public programming contest system. In such system, any user can submit a code source, which will be compiled and run automatically (which means, no human-eye pre-moderation is performed) in attempt to solve some computational problem. Back-end is a GNU/Linux dedicated machine, where a user will be created for each contestant, all such users being part of users group. Sources sent by any particular user will be stored at the user's home directory, then compiled and executed to be verified against various test cases. What I want is to prohibit

C printf %d incorrect value with leading zeros? [duplicate]

只愿长相守 提交于 2019-12-04 05:58:04
问题 This question already has an answer here : Strange behavior in C when calculating sum of digits with leading zeroes (1 answer) Closed 2 years ago . The C function printf seems to print different values depending on whether or not leading zeros are present. I was trying to determine the numerical values for the mode argument in the Linux 'open' system call. printf("mode:%d\n",S_IRWXU); printf("mode:%d\n",00700); both gave me 448, while printf("mode:%d\n",700); gives me 700, as I would expect

Duplicate stdout and stderr from fork process to files

烂漫一生 提交于 2019-12-04 05:44:50
问题 I need to duplicate stdout and stderr of a child proccess to multiple files. I understand that i can use tee() , but I haven't found examples for that. Now, it's only to print all to stdout and stderr. How to do it? pid_t childId = fork(); switch(childId){ case -1: perror("fork() error!\n"); return; case 0: mysignal(SIGTTOU, SIG_DFL); mysignal(SIGTTIN, SIG_DFL); mysignal(SIGCHLD, SIG_DFL); if(!background) tcsetpgrp(cterm, getpid()); setpgid(0, 0); if (isWriter) close(pipefd[0]); if (isReader!

How can I get the CPU time for a perl system call?

故事扮演 提交于 2019-12-04 04:44:18
问题 I have a perl script that calls external executables using system() . I would like to measure the CPU seconds taken by these external programs. Ideally, I would like to run them using the shell builtin time command (this is on a Linux system). Something like this: system("time /path/to/command") Now, time prints its output to stderr, but in order to do so, launches the command it is given in a separate subshell. This means that in order to capture time's output when running manually in the

How come _exit(0) (exiting by syscall) prevents me from receiving any stdout content?

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:31:55
问题 I have a Linux x86-32 GAS assembly program terminating like this: movl $1, %eax movl $0, %ebx # argument for _exit int $0x80 When I exit like this, the program functions like normally, but if I try to read the stdout output, I get nothing (using i.e. less or wc). I tried compiling a minimal C program and comparing the strace outputs. The only difference I found was, that GCC made the C program ( int main() { printf("donkey\n"); } ) implicitely exit with exit_group(0) in the strace output. I

Simulate effect of select() and poll() in kernel socket programming

寵の児 提交于 2019-12-04 00:31:43
One of the Linux kernel drivers I am developing is using network communication in the kernel ( sock_create() , sock->ops->bind() , and so on). The problem is there will be multiple sockets to receive data from. So I need something that will simulate a select() or poll() in kernel space. Since these functions use file descriptors, I cannot use the system calls unless I use the system calls to create the sockets, but that seems unnecessary since I am working in the kernel. So I was thinking of wrapping the default sock->sk_data_ready handler in my own handler ( custom_sk_data_ready() ), which

Writing a new system call

被刻印的时光 ゝ 提交于 2019-12-03 21:59:12
I have been trying to write a new system call(called sys_defclose) in the raspberry's kernel, but upon compiling i get this error: arch/arm/kernel/built-in.o: In function `__sys_trace_return': :(.text+0xd50): undefined reference to `sys_defclose' i have modified the following file: -include/linux/syscalls.h : where i put the prototype of my syscall -arch/arm/include/asm/unistd.h : where i put the new raw of the syscall table: #define __NR_sys_defclose (__NR_SYSCALL_BASE+380) -arch/arm/kernel/calls.S : where i put: CALL(sys_defclose) -i put the source of sys_defclose in arch/arm/kernel and i

I have a trouble with looking into the read() function code defined in <unistd.h>

僤鯓⒐⒋嵵緔 提交于 2019-12-03 21:24:45
I am now trying to understand how read(2) function works by looking into the actual code implementation and first, I try to see how it is defined in #include header file. In that file, I found this : ssize_t read(int, void *, size_t) __DARWIN_ALIAS_C(read); And then, I googled to find the actual read() function declaration. And, https://github.com/lattera/glibc/blob/master/io/read.c I found this. In this code, /* Read NBYTES into BUF from FD. Return the number read or -1. */ ssize_t __libc_read (int fd, void *buf, size_t nbytes) { if (nbytes == 0) return 0; if (fd < 0) { __set_errno (EBADF);

How to allocate a new TLS area with clone system call

耗尽温柔 提交于 2019-12-03 21:13:36
问题 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

how to dump call stack in syscall(android kernel) ?

旧城冷巷雨未停 提交于 2019-12-03 20:59:20
I want to know who called *sys_reboot* when the phone(android) reboot unexpectly. Is there a way to dump the call stack in syscall (android kernel)? FrankH. If all you want it a kernel call trace, you can get that via dump_stack() . panic() calls that, amongst other things. The BUG() / BUG_ON() wrappers give it a more descriptive message and an optional conditional test. A userland stacktrace , particularly a symbolic one, though, cannot reliably be obtained from within the kernel directly. It's possible to copy the stack memory into kernel space and log the contents, or even heuristically