arch/x86/kernel/vm86_32.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/vm86_32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/vm86_32.c- Extension
.c- Size
- 22471 bytes
- Lines
- 832
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/errno.hlinux/interrupt.hlinux/syscalls.hlinux/sched.hlinux/sched/task_stack.hlinux/kernel.hlinux/signal.hlinux/string.hlinux/mm.hlinux/smp.hlinux/highmem.hlinux/ptrace.hlinux/audit.hlinux/stddef.hlinux/slab.hlinux/security.hlinux/uaccess.hasm/io.hasm/tlbflush.hasm/irq.hasm/traps.hasm/vm86.hasm/switch_to.h
Detected Declarations
syscall vm86oldsyscall vm86function Copyrightfunction SYSCALL_DEFINE2function do_sys_vm86function set_IFfunction clear_IFfunction clear_TFfunction clear_ACfunction set_IFfunction set_vflags_shortfunction get_vflagsfunction is_revectoredfunction do_intfunction handle_vm86_trapfunction handle_vm86_faultfunction irq_handlerfunction free_vm86_irqfunction release_vm86_irqsfunction get_and_reset_irqfunction do_vm86_irq_handling
Annotated Snippet
SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, user_vm86)
{
return do_sys_vm86((struct vm86plus_struct __user *) user_vm86, false);
}
SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
{
switch (cmd) {
case VM86_REQUEST_IRQ:
case VM86_FREE_IRQ:
case VM86_GET_IRQ_BITS:
case VM86_GET_AND_RESET_IRQ:
return do_vm86_irq_handling(cmd, (int)arg);
case VM86_PLUS_INSTALL_CHECK:
/*
* NOTE: on old vm86 stuff this will return the error
* from access_ok(), because the subfunction is
* interpreted as (invalid) address to vm86_struct.
* So the installation check works.
*/
return 0;
}
/* we come here only for functions VM86_ENTER, VM86_ENTER_NO_BYPASS */
return do_sys_vm86((struct vm86plus_struct __user *) arg, true);
}
static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus)
{
struct task_struct *tsk = current;
struct vm86 *vm86 = tsk->thread.vm86;
struct kernel_vm86_regs vm86regs;
struct pt_regs *regs = current_pt_regs();
unsigned long err = 0;
struct vm86_struct v;
err = security_mmap_addr(0);
if (err) {
/*
* vm86 cannot virtualize the address space, so vm86 users
* need to manage the low 1MB themselves using mmap. Given
* that BIOS places important data in the first page, vm86
* is essentially useless if mmap_min_addr != 0. DOSEMU,
* for example, won't even bother trying to use vm86 if it
* can't map a page at virtual address 0.
*
* To reduce the available kernel attack surface, simply
* disallow vm86(old) for users who cannot mmap at va 0.
*
* The implementation of security_mmap_addr will allow
* suitably privileged users to map va 0 even if
* vm.mmap_min_addr is set above 0, and we want this
* behavior for vm86 as well, as it ensures that legacy
* tools like vbetool will not fail just because of
* vm.mmap_min_addr.
*/
pr_info_once("Denied a call to vm86(old) from %s[%d] (uid: %d). Set the vm.mmap_min_addr sysctl to 0 and/or adjust LSM mmap_min_addr policy to enable vm86 if you are using a vm86-based DOS emulator.\n",
current->comm, task_pid_nr(current),
from_kuid_munged(&init_user_ns, current_uid()));
return -EPERM;
}
if (!vm86) {
if (!(vm86 = kzalloc_obj(*vm86)))
return -ENOMEM;
tsk->thread.vm86 = vm86;
}
if (vm86->saved_sp0)
return -EPERM;
if (copy_from_user(&v, user_vm86,
offsetof(struct vm86_struct, int_revectored)))
return -EFAULT;
/* VM86_SCREEN_BITMAP had numerous bugs and appears to have no users. */
if (v.flags & VM86_SCREEN_BITMAP) {
pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n",
current->comm);
return -EINVAL;
}
memset(&vm86regs, 0, sizeof(vm86regs));
vm86regs.pt.bx = v.regs.ebx;
vm86regs.pt.cx = v.regs.ecx;
vm86regs.pt.dx = v.regs.edx;
vm86regs.pt.si = v.regs.esi;
Annotation
- Immediate include surface: `linux/capability.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/syscalls.h`, `linux/sched.h`, `linux/sched/task_stack.h`, `linux/kernel.h`, `linux/signal.h`.
- Detected declarations: `syscall vm86old`, `syscall vm86`, `function Copyright`, `function SYSCALL_DEFINE2`, `function do_sys_vm86`, `function set_IF`, `function clear_IF`, `function clear_TF`, `function clear_AC`, `function set_IF`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.