* max_size specifies a limit on the bytes read. If max_size is SIZE_MAX, the full file is read. If
* the full file is too large to read, an error is returned. For other values of max_size, *partial
* contents* may be returned. (Though the read is still done using one syscall.) Returns 0 on
- * partial success, 1 if untruncated contents were read. */
+ * partial success, 1 if untruncated contents were read.
+ *
+ * Rule: for kernfs files using "seq_file" → use regular read_full_file_at()
+ * for kernfs files using "raw" → use read_virtual_file_at()
+ */
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
assert(max_size <= READ_VIRTUAL_BYTES_MAX || max_size == SIZE_MAX);
(void) iovw_put_string_field_free(iovw, "COREDUMP_OPEN_FDS=", t);
p = procfs_file_alloca(pid, "status");
- if (read_full_virtual_file(p, &t, NULL) >= 0)
+ if (read_full_file(p, &t, /* ret_size= */ NULL) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_STATUS=", t);
p = procfs_file_alloca(pid, "maps");
- if (read_full_virtual_file(p, &t, NULL) >= 0)
+ if (read_full_file(p, &t, /* ret_size= */ NULL) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_MAPS=", t);
- p = procfs_file_alloca(pid, "limits");
- if (read_full_virtual_file(p, &t, NULL) >= 0)
+ p = procfs_file_alloca(pid, "limits"); /* this uses 'seq_file' in kernel, use read_full_file_at() */
+ if (read_full_file(p, &t, /* ret_size= */ NULL) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_LIMITS=", t);
p = procfs_file_alloca(pid, "cgroup");
- if (read_full_virtual_file(p, &t, NULL) >= 0)
+ if (read_full_file(p, &t, /* ret_size= */ NULL) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_CGROUP=", t);
p = procfs_file_alloca(pid, "mountinfo");
- if (read_full_virtual_file(p, &t, NULL) >= 0)
+ if (read_full_file(p, &t, /* ret_size= */ NULL) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_MOUNTINFO=", t);
/* We attach /proc/auxv here. ELF coredumps also contain a note for this (NT_AUXV), see elf(5). */
p = procfs_file_alloca(pid, "auxv");
- if (read_full_virtual_file(p, &t, &size) >= 0) {
+ if (read_full_file(p, &t, &size) >= 0) {
char *buf = malloc(strlen("COREDUMP_PROC_AUXV=") + size + 1);
if (buf) {
/* Add a dummy terminator to make context_parse_iovw() happy. */