arch/x86/kernel/ioport.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/ioport.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/ioport.c- Extension
.c- Size
- 5608 bytes
- Lines
- 221
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/capability.hlinux/security.hlinux/syscalls.hlinux/bitmap.hlinux/ioport.hlinux/sched.hlinux/slab.hasm/io_bitmap.hasm/desc.hasm/syscalls.h
Detected Declarations
syscall iopermsyscall ioplsyscall iopermsyscall ioplfunction io_bitmap_sharefunction task_update_io_bitmapfunction io_bitmap_exitfunction ksys_iopermfunction ksys_ioperm
Annotated Snippet
SYSCALL_DEFINE3(ioperm, unsigned long, from, unsigned long, num, int, turn_on)
{
return ksys_ioperm(from, num, turn_on);
}
/*
* The sys_iopl functionality depends on the level argument, which if
* granted for the task is used to enable access to all 65536 I/O ports.
*
* This does not use the IOPL mechanism provided by the CPU as that would
* also allow the user space task to use the CLI/STI instructions.
*
* Disabling interrupts in a user space task is dangerous as it might lock
* up the machine and the semantics vs. syscalls and exceptions is
* undefined.
*
* Setting IOPL to level 0-2 is disabling I/O permissions. Level 3
* 3 enables them.
*
* IOPL is strictly per thread and inherited on fork.
*/
SYSCALL_DEFINE1(iopl, unsigned int, level)
{
struct thread_struct *t = ¤t->thread;
unsigned int old;
if (level > 3)
return -EINVAL;
old = t->iopl_emul;
/* No point in going further if nothing changes */
if (level == old)
return 0;
/* Trying to gain more privileges? */
if (level > old) {
if (!capable(CAP_SYS_RAWIO) ||
security_locked_down(LOCKDOWN_IOPORT))
return -EPERM;
}
t->iopl_emul = level;
task_update_io_bitmap();
return 0;
}
#else /* CONFIG_X86_IOPL_IOPERM */
long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
return -ENOSYS;
}
SYSCALL_DEFINE3(ioperm, unsigned long, from, unsigned long, num, int, turn_on)
{
return -ENOSYS;
}
SYSCALL_DEFINE1(iopl, unsigned int, level)
{
return -ENOSYS;
}
#endif
Annotation
- Immediate include surface: `linux/capability.h`, `linux/security.h`, `linux/syscalls.h`, `linux/bitmap.h`, `linux/ioport.h`, `linux/sched.h`, `linux/slab.h`, `asm/io_bitmap.h`.
- Detected declarations: `syscall ioperm`, `syscall iopl`, `syscall ioperm`, `syscall iopl`, `function io_bitmap_share`, `function task_update_io_bitmap`, `function io_bitmap_exit`, `function ksys_ioperm`, `function ksys_ioperm`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: core implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.