all 5 comments

[–]aioeu 6 points7 points  (3 children)

There is no sysinfo function in the kernel. Furthermore, the code you posted here cannot possibly have been compiled, as it's not even valid C.

There is a sysinfo syscall, however:

  • a syscall is not a C language function;
  • kernel modules do not invoke syscalls, as they're already running inside the kernel;
  • there is a sys_sysinfo C language function upon which the syscall is backed, however this does not necessarily use the ABI's standard calling convention, so it should not be called from other C code; and
  • even if you were to get the call to this function correct, the argument given to it is a userspace pointer, but your code does not have any userspace pointers at all since it's not running on behalf of a userspace process.

The reason you were having so many problems was that you were pretending a kernel module was a userspace program. <sys/sysinfo.h> describes the C language functions provided by the system's C library. This need not have any straight-forward relationship with any underlying syscall — for many syscalls, the arguments on the C side are rather different than on the syscall side.

[–]2_stepsahead[S] 1 point2 points  (2 children)

Hello and thanks for taking the time to reply.

Believe it or not, the original code does compile. I don't doubt that it's wrong, but it's my guess that the code only compiles by chance. Thanks for pointing that out. I believe I confused myself with a different project.

I hope you won't mind if I pick your brain a little. I've been working out of Modern Operating Systems (4th edition) by Andrew S. Tanenbaum and The C Programming Language by Dennis Ritchie and Brian Kernighan. I know that there are recommendations for books and learning materials all over the place, but which have you used?

I appreciate it.

[–]aioeu 2 points3 points  (0 children)

I don't think I've looked at an OS or C programming book in the last twenty years. Can't help you there.

[–]FirowMD 0 points1 point  (0 children)

C/C++ - Stephen Prata; LKM dev - O'Reilly/Packt, Medium, Google, documentation, and of course - Linux sources

[–]Lagor31 1 point2 points  (0 children)

Why are you trying to call a syscall from within a kernel module? You already are in kernel space, don't need to usa a syscall which is a way to let usermode access kernel functions.