What are some user space examples of using inb, inl, and inw to access kernel space in Linux?


1 Answer 1


inb, 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 ioperm or iopl system calls.

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 <asm/io.h> with <sys/io.h> to get it to compile.

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.