2

I am trying to understand code for a C program that among other things, increments the NR_syscalls value of the Linux kernel. Does the NR_syscalls value store the number of system calls in the system calls table?

  • @Kusalananda this C code is dealing with the Linux system call table. – Paradox Sep 28 '17 at 16:28
  • Still unclear: Are you talking about a C program or a C function in the kernel ?  If it's a program, how is it manipulating kernel data?  In any case, can you tell overall what the code is doing?   (Can you tell us?) – G-Man Sep 28 '17 at 18:12
  • 1
    @G-Man Although unixes have traditionally a very strong separation between the user and kernel space, there are still some shared data structures, mainly to make their interactions more feasible. include/linux is nearly the same in the kernel and the glibc source. The list of the system calls is one of them - simply your app has to see the same id of sys_open, as the kernel api. _NR_syscalls is the upper index of the array of the linux system calls. – peterh Sep 28 '17 at 22:01
  • @peterh Very little of what you’re saying makes any sense to me, least of all the suggestion that a user mode program can modify kernel data without using a system call specifically designed for that purpose. – G-Man Sep 28 '17 at 23:07
  • @G-Man Of course no user program can modify kernel data (except very extraordinary things, like going to ring0 with sys_iopl, although it happens mainly for direct hw control and not for modifying kernel data structures), also _NR_syscalls is a static value (as I can remember, it isn't even a const, but a #define somewhere below /usr/include/linux). For example, strace uses it. Another example for shared data structures are, for example, the headers describing filesystems or network protocols. These are used mainly by kernel, but sometimes also by user space (for example, tcpdump – peterh Sep 28 '17 at 23:11
2

Yes, exactly this is what it does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.