tools/testing/selftests/proc/proc-self-map-files-002.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-self-map-files-002.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/proc-self-map-files-002.c- Extension
.c- Size
- 2792 bytes
- Lines
- 95
- 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
errno.hsys/types.hsys/stat.hfcntl.hstdio.hunistd.hsys/mman.hstdlib.h
Detected Declarations
function passfunction failfunction main
Annotated Snippet
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
static void pass(const char *fmt, unsigned long a, unsigned long b)
{
char name[64];
char buf[64];
snprintf(name, sizeof(name), fmt, a, b);
if (readlink(name, buf, sizeof(buf)) == -1)
exit(1);
}
static void fail(const char *fmt, unsigned long a, unsigned long b)
{
char name[64];
char buf[64];
snprintf(name, sizeof(name), fmt, a, b);
if (readlink(name, buf, sizeof(buf)) == -1 && errno == ENOENT)
return;
exit(1);
}
int main(void)
{
const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
/*
* va_max must be enough bigger than vm.mmap_min_addr, which is
* 64KB/32KB by default. (depends on CONFIG_LSM_MMAP_MIN_ADDR)
*/
const unsigned long va_max = 1UL << 20;
unsigned long va;
void *p;
int fd;
unsigned long a, b;
fd = open("/dev/zero", O_RDONLY);
if (fd == -1)
return 1;
for (va = 0; va < va_max; va += PAGE_SIZE) {
p = mmap((void *)va, PAGE_SIZE, PROT_NONE, MAP_PRIVATE|MAP_FILE|MAP_FIXED, fd, 0);
if (p == (void *)va)
break;
}
if (va == va_max) {
fprintf(stderr, "error: mmap doesn't like you\n");
return 1;
}
a = (unsigned long)p;
b = (unsigned long)p + PAGE_SIZE;
pass("/proc/self/map_files/%lx-%lx", a, b);
fail("/proc/self/map_files/ %lx-%lx", a, b);
fail("/proc/self/map_files/%lx -%lx", a, b);
fail("/proc/self/map_files/%lx- %lx", a, b);
fail("/proc/self/map_files/%lx-%lx ", a, b);
fail("/proc/self/map_files/0%lx-%lx", a, b);
fail("/proc/self/map_files/%lx-0%lx", a, b);
if (sizeof(long) == 4) {
fail("/proc/self/map_files/100000000%lx-%lx", a, b);
fail("/proc/self/map_files/%lx-100000000%lx", a, b);
} else if (sizeof(long) == 8) {
fail("/proc/self/map_files/10000000000000000%lx-%lx", a, b);
fail("/proc/self/map_files/%lx-10000000000000000%lx", a, b);
} else
return 1;
return 0;
}
Annotation
- Immediate include surface: `errno.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `stdio.h`, `unistd.h`, `sys/mman.h`, `stdlib.h`.
- Detected declarations: `function pass`, `function fail`, `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.