tools/testing/selftests/x86/ioperm.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/ioperm.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/x86/ioperm.c- Extension
.c- Size
- 3584 bytes
- Lines
- 165
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
err.hstdio.hstdint.hsignal.hsetjmp.hstdlib.hstring.herrno.hunistd.hsys/types.hsys/wait.hstdbool.hsched.hsys/io.hhelpers.h
Detected Declarations
function sigsegvfunction try_outbfunction expect_okfunction expect_gpfunction main
Annotated Snippet
if (ioperm(0x81, 1, 1) != 0) {
printf("[FAIL]\tioperm(0x81, 1, 1) failed (%d)", errno);
return 1;
}
printf("[RUN]\tchild: Drop permissions to 0x80\n");
if (ioperm(0x80, 1, 0) != 0) {
printf("[FAIL]\tioperm(0x80, 1, 0) failed (%d)", errno);
return 1;
}
expect_gp(0x80);
return 0;
} else {
int status;
if (waitpid(child, &status, 0) != child ||
!WIFEXITED(status)) {
printf("[FAIL]\tChild died\n");
nerrs++;
} else if (WEXITSTATUS(status) != 0) {
printf("[FAIL]\tChild failed\n");
nerrs++;
} else {
printf("[OK]\tChild succeeded\n");
}
}
/* Verify that the child dropping 0x80 did not affect the parent */
printf("\tVerify that unsharing the bitmap worked\n");
expect_ok(0x80);
/* Test the capability checks. */
printf("\tDrop privileges\n");
if (setresuid(1, 1, 1) != 0) {
printf("[WARN]\tDropping privileges failed\n");
return 0;
}
printf("[RUN]\tdisable 0x80\n");
if (ioperm(0x80, 1, 0) != 0) {
printf("[FAIL]\tioperm(0x80, 1, 0) failed (%d)", errno);
return 1;
}
printf("[OK]\tit worked\n");
printf("[RUN]\tenable 0x80 again\n");
if (ioperm(0x80, 1, 1) == 0) {
printf("[FAIL]\tit succeeded but should have failed.\n");
return 1;
}
printf("[OK]\tit failed\n");
return 0;
}
Annotation
- Immediate include surface: `err.h`, `stdio.h`, `stdint.h`, `signal.h`, `setjmp.h`, `stdlib.h`, `string.h`, `errno.h`.
- Detected declarations: `function sigsegv`, `function try_outb`, `function expect_ok`, `function expect_gp`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.