summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-01 17:01:26 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-03 16:15:04 +0200
commit1beaaeab2fde2ae4d1a948e661241ca11096167e (patch)
tree27277a8d34347e5e35d7a55006c0632eb2ac0105 /src
parentefi: fix mangle_stub_cmdline() for empty strings (diff)
downloadsystemd-1beaaeab2fde2ae4d1a948e661241ca11096167e.tar.xz
systemd-1beaaeab2fde2ae4d1a948e661241ca11096167e.zip
efi: drop "ret_" prefix from "ret_sections[]" parameter
While we write data to this parameter, it's not really a return parameter, we after all do not fully set it, we just fill in some fields. Hence it must be initialized beforehand. According to our coding style only parameters that are purely used for returning something should be named "ret_xyz", hence this one should not be. (We'll later rely on the current behaviour that it leaves array entries for which we find no sections untouched, hence leave behaviour as is, just rename the parameters to something more appropriate). (Since we are dropping the "ret_" prefix of "ret_sections", let's rename the old "section" parameter at the same time to "section_names", to make clearer what it is about).
Diffstat (limited to 'src')
-rw-r--r--src/boot/efi/pe.c42
-rw-r--r--src/boot/efi/pe.h8
2 files changed, 26 insertions, 24 deletions
diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c
index 587e3ef7b1..33aeaeab50 100644
--- a/src/boot/efi/pe.c
+++ b/src/boot/efi/pe.c
@@ -178,22 +178,22 @@ static bool pe_section_name_equal(const char *a, const char *b) {
static void pe_locate_sections(
const PeSectionHeader section_table[],
size_t n_section_table,
- const char * const sections[],
+ const char *const section_names[],
size_t validate_base,
- PeSectionVector *ret_sections) {
+ PeSectionVector sections[]) {
assert(section_table || n_section_table == 0);
+ assert(section_names);
assert(sections);
- assert(ret_sections);
/* Searches for the sections listed in 'sections[]' within the section table. Validates the resulted
* data. If 'validate_base' is non-zero also takes base offset when loaded into memory into account for
* qchecking for overflows. */
- for (size_t i = 0; sections[i]; i++)
+ for (size_t i = 0; section_names[i]; i++)
FOREACH_ARRAY(j, section_table, n_section_table) {
- if (!pe_section_name_equal((const char*) j->Name, sections[i]))
+ if (!pe_section_name_equal((const char*) j->Name, section_names[i]))
continue;
/* Overflow check: ignore sections that are impossibly large, relative to the file
@@ -220,7 +220,7 @@ static void pe_locate_sections(
}
/* At this time, the sizes and offsets have been validated. Store them away */
- ret_sections[i] = (PeSectionVector) {
+ sections[i] = (PeSectionVector) {
.size = j->VirtualSize,
.file_offset = j->PointerToRawData,
.memory_offset = j->VirtualAddress,
@@ -232,17 +232,19 @@ static void pe_locate_sections(
}
static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const PeFileHeader *pe) {
- static const char *sections[] = { ".compat", NULL };
- PeSectionVector vector = {};
-
/* The kernel may provide alternative PE entry points for different PE architectures. This allows
* booting a 64-bit kernel on 32-bit EFI that is otherwise running on a 64-bit CPU. The locations of any
* such compat entry points are located in a special PE section. */
+ assert(dos);
+ assert(pe);
+
+ static const char *const section_names[] = { ".compat", NULL };
+ PeSectionVector vector = {};
pe_locate_sections(
(const PeSectionHeader *) ((const uint8_t *) dos + section_table_offset(dos, pe)),
pe->FileHeader.NumberOfSections,
- sections,
+ section_names,
PTR_TO_SIZE(dos),
&vector);
@@ -308,16 +310,16 @@ EFI_STATUS pe_kernel_info(const void *base, uint32_t *ret_compat_address) {
EFI_STATUS pe_memory_locate_sections(
const void *base,
- const char* const sections[],
- PeSectionVector *ret_sections) {
+ const char *const section_names[],
+ PeSectionVector sections[]) {
const DosFileHeader *dos;
const PeFileHeader *pe;
size_t offset;
assert(base);
+ assert(section_names);
assert(sections);
- assert(ret_sections);
dos = (const DosFileHeader *) base;
if (!verify_dos(dos))
@@ -331,9 +333,9 @@ EFI_STATUS pe_memory_locate_sections(
pe_locate_sections(
(const PeSectionHeader *) ((const uint8_t *) base + offset),
pe->FileHeader.NumberOfSections,
- sections,
+ section_names,
PTR_TO_SIZE(base),
- ret_sections);
+ sections);
return EFI_SUCCESS;
}
@@ -341,8 +343,8 @@ EFI_STATUS pe_memory_locate_sections(
EFI_STATUS pe_file_locate_sections(
EFI_FILE *dir,
const char16_t *path,
- const char * const sections[],
- PeSectionVector *ret_sections) {
+ const char *const section_names[],
+ PeSectionVector sections[]) {
_cleanup_free_ PeSectionHeader *section_table = NULL;
_cleanup_(file_closep) EFI_FILE *handle = NULL;
DosFileHeader dos;
@@ -352,8 +354,8 @@ EFI_STATUS pe_file_locate_sections(
assert(dir);
assert(path);
+ assert(section_names);
assert(sections);
- assert(ret_sections);
err = dir->Open(dir, &handle, (char16_t *) path, EFI_FILE_MODE_READ, 0ULL);
if (err != EFI_SUCCESS)
@@ -402,9 +404,9 @@ EFI_STATUS pe_file_locate_sections(
pe_locate_sections(
section_table,
pe.FileHeader.NumberOfSections,
- sections,
+ section_names,
/* validate_base= */ 0, /* don't validate base */
- ret_sections);
+ sections);
return EFI_SUCCESS;
}
diff --git a/src/boot/efi/pe.h b/src/boot/efi/pe.h
index bc6d74beeb..e55ac5daa9 100644
--- a/src/boot/efi/pe.h
+++ b/src/boot/efi/pe.h
@@ -17,13 +17,13 @@ static inline bool PE_SECTION_VECTOR_IS_SET(const PeSectionVector *v) {
EFI_STATUS pe_memory_locate_sections(
const void *base,
- const char * const sections[],
- PeSectionVector *ret_sections);
+ const char *const section_names[],
+ PeSectionVector sections[]);
EFI_STATUS pe_file_locate_sections(
EFI_FILE *dir,
const char16_t *path,
- const char * const sections[],
- PeSectionVector *ret_sections);
+ const char *const section_names[],
+ PeSectionVector sections[]);
EFI_STATUS pe_kernel_info(const void *base, uint32_t *ret_compat_address);