tools/testing/selftests/proc/proc-self-syscall.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-self-syscall.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/proc-self-syscall.c- Extension
.c- Size
- 1634 bytes
- Lines
- 59
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
Dependency Surface
unistd.hsys/syscall.hsys/types.hsys/stat.hfcntl.herrno.hstring.hstdio.h
Detected Declarations
function sys_readfunction main
Annotated Snippet
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
static inline ssize_t sys_read(int fd, void *buf, size_t len)
{
return syscall(SYS_read, fd, buf, len);
}
int main(void)
{
char buf1[64];
char buf2[64];
int fd;
ssize_t rv;
fd = open("/proc/self/syscall", O_RDONLY);
if (fd == -1) {
if (errno == ENOENT)
return 4;
return 1;
}
/* Do direct system call as libc can wrap anything. */
snprintf(buf1, sizeof(buf1), "%ld 0x%lx 0x%lx 0x%lx",
(long)SYS_read, (long)fd, (long)buf2, (long)sizeof(buf2));
memset(buf2, 0, sizeof(buf2));
rv = sys_read(fd, buf2, sizeof(buf2));
if (rv < 0)
return 1;
if (rv < strlen(buf1))
return 1;
if (strncmp(buf1, buf2, strlen(buf1)) != 0)
return 1;
return 0;
}
Annotation
- Immediate include surface: `unistd.h`, `sys/syscall.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `errno.h`, `string.h`, `stdio.h`.
- Detected declarations: `function sys_read`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.