[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core
From: |
Richard Henderson |
Subject: |
[PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core_dump |
Date: |
Tue, 27 Feb 2024 08:48:24 -1000 |
On the off-chance that one of the cleanup functions changes
errno, latch the errno that we want to return beforehand.
Flush errno to 0 upon success, rather than at the beginning.
No need to avoid negation of 0.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 98b82b1a49..39d9ef9acc 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4634,8 +4634,7 @@ static int elf_core_dump(int signr, const CPUArchState
*env)
off_t offset = 0, data_offset = 0;
int segs = 0;
int fd = -1;
-
- errno = 0;
+ int ret;
if (prctl(PR_GET_DUMPABLE) == 0) {
return 0;
@@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchState
*env)
goto out;
}
}
+ errno = 0;
out:
+ ret = -errno;
free_note_info(&info);
vma_delete(&mm);
- (void) close(fd);
-
- if (errno != 0)
- return (-errno);
- return (0);
+ close(fd);
+ return ret;
}
#endif /* USE_ELF_CORE_DUMP */
--
2.34.1
- [PATCH 00/14] linux-user: Rewrite core dump, Richard Henderson, 2024/02/27
- [PATCH 01/14] linux-user/elfload: Disable core dump if getrlimit fails, Richard Henderson, 2024/02/27
- [PATCH 02/14] linux-user/elfload: Merge init_note_info and fill_note_info, Richard Henderson, 2024/02/27
- [PATCH 03/14] linux-user/elfload: Tidy fill_note_info and struct elf_note_info, Richard Henderson, 2024/02/27
- [PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core_dump,
Richard Henderson <=
- [PATCH 04/14] linux-user/elfload: Stack allocate struct mm_struct, Richard Henderson, 2024/02/27
- [PATCH 06/14] linux-user/elfload: Open core file after vma_init, Richard Henderson, 2024/02/27
- [PATCH 07/14] linux-user/elfload: Truncate core file on open, Richard Henderson, 2024/02/27
- [PATCH 08/14] linux-user/elfload: Lock cpu list and mmap during elf_core_dump, Richard Henderson, 2024/02/27
- [PATCH 09/14] linux-user/elfload: Size corefile before opening, Richard Henderson, 2024/02/27
- [PATCH 10/14] linux-user/elfload: Write corefile elf header in one block, Richard Henderson, 2024/02/27
- [PATCH 11/14] linux-user/elfload: Write process memory to core file in larger chunks, Richard Henderson, 2024/02/27
- [PATCH 12/14] linux-user/elfload: Simplify vma_dump_size, Richard Henderson, 2024/02/27
- [PATCH 13/14] linux-user/elfload: Rely on walk_memory_regions for vmas, Richard Henderson, 2024/02/27