What are some user space examples of using
inw to access kernel space in Linux?
outb and friends aren't meant for kernel ↔ userspace communication, they are used to read from and write to platform-specific IO ports.
Typical usage for these features would be direct interactions with the serial or parallel ports (and thus devices attached), without going all the way and creating specific kernel device drivers.
X servers can also use these for low-level communication with the video (or possibly input device) hardware.
To use these calls from userspace, two things are required:
- The calling process must have CAP_SYS_RAWIO capability (this usually means it needs to be run as root).
- The calling process must request permission to use the ports it wants, with the
Linux I/O port programming mini-HOWTO will walk you through the essentials, and there's a simple example program at the end*.
Do note that programs that use this communicate directly with whatever hardware (or firmware) is behind those ports. The kernel doesn't validate or otherwise interfere with these calls. So mis-using them could cause serious problems. Handle with care.
*You'll need to
#include <stdlib.h> and replace
<sys/io.h> to get it to compile.