arch/um/os-Linux/mem.c
Source file repositories/reference/linux-study-clean/arch/um/os-Linux/mem.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/os-Linux/mem.c- Extension
.c- Size
- 5235 bytes
- Lines
- 247
- Domain
- Architecture Layer
- Bucket
- arch/um
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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 uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstddef.hstdlib.hunistd.herrno.hfcntl.hstring.hsys/stat.hsys/mman.hsys/vfs.hlinux/magic.hinit.hkern_util.hos.hinternal.h
Detected Declarations
function Copyrightfunction check_tmpfsfunction choose_tempdirfunction make_tempfilefunction create_tmp_filefunction create_mem_filefunction check_tmpexec
Annotated Snippet
if ((dir != NULL) && (*dir != '\0')) {
os_info("%s\n", dir);
if (check_tmpfs(dir) >= 0)
goto done;
else
goto warn;
}
}
os_info("none found\n");
for (i = 0; tmpfs_dirs[i]; i++) {
dir = tmpfs_dirs[i];
if (check_tmpfs(dir) >= 0)
goto done;
}
dir = fallback_dir;
warn:
os_warn("Warning: tempdir %s is not on tmpfs\n", dir);
done:
/* Make a copy since getenv results may not remain valid forever. */
return strdup(dir);
}
/*
* Create an unlinked tempfile in a suitable tempdir. template must be the
* basename part of the template with a leading '/'.
*/
static int __init make_tempfile(const char *template)
{
char *tempname;
int fd;
if (tempdir == NULL) {
tempdir = choose_tempdir();
if (tempdir == NULL) {
os_warn("Failed to choose tempdir: %s\n",
strerror(errno));
return -1;
}
}
#ifdef O_TMPFILE
fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700);
/*
* If the running system does not support O_TMPFILE flag then retry
* without it.
*/
if (fd != -1 || (errno != EINVAL && errno != EISDIR &&
errno != EOPNOTSUPP))
return fd;
#endif
tempname = malloc(strlen(tempdir) + strlen(template) + 1);
if (tempname == NULL)
return -1;
strcpy(tempname, tempdir);
strcat(tempname, template);
fd = mkstemp(tempname);
if (fd < 0) {
os_warn("open - cannot create %s: %s\n", tempname,
strerror(errno));
goto out;
}
if (unlink(tempname) < 0) {
perror("unlink");
goto close;
}
free(tempname);
return fd;
close:
close(fd);
out:
free(tempname);
return -1;
}
#define TEMPNAME_TEMPLATE "/vm_file-XXXXXX"
static int __init create_tmp_file(unsigned long long len)
{
int fd, err;
char zero;
fd = make_tempfile(TEMPNAME_TEMPLATE);
if (fd < 0)
exit(1);
/*
Annotation
- Immediate include surface: `stdio.h`, `stddef.h`, `stdlib.h`, `unistd.h`, `errno.h`, `fcntl.h`, `string.h`, `sys/stat.h`.
- Detected declarations: `function Copyright`, `function check_tmpfs`, `function choose_tempdir`, `function make_tempfile`, `function create_tmp_file`, `function create_mem_file`, `function check_tmpexec`.
- Atlas domain: Architecture Layer / arch/um.
- 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.