From 1b312d7f0a9c6d0bacf21895109fccced5363278 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Sat, 23 Feb 2019 15:42:04 +0100 Subject: [PATCH] kernel/elf: use BytePointer Change-Id: I3a40921854540d78dec025b2a349e3a153f91d55 Reviewed-on: https://review.haiku-os.org/c/1083 Reviewed-by: Adrien Destugues --- src/system/kernel/elf.cpp | 47 +++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/system/kernel/elf.cpp b/src/system/kernel/elf.cpp index 92957ab9d6..0883e523e3 100644 --- a/src/system/kernel/elf.cpp +++ b/src/system/kernel/elf.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -829,7 +830,7 @@ assert_defined_image_version(elf_image_info* dependentImage, } // iterate through the defined versions to find the given one - elf_verdef* definition = image->version_definitions; + BytePointer definition(image->version_definitions); for (uint32 i = 0; i < image->num_version_definitions; i++) { uint32 versionIndex = VER_NDX(definition->vd_ndx); elf_version_info& info = image->versions[versionIndex]; @@ -839,8 +840,7 @@ assert_defined_image_version(elf_image_info* dependentImage, return B_OK; } - definition = (elf_verdef*) - ((uint8*)definition + definition->vd_next); + definition += definition->vd_next; } // version not found -- fail, if not weak @@ -863,7 +863,7 @@ init_image_version_infos(elf_image_info* image) uint32 maxIndex = 0; if (image->version_definitions != NULL) { - elf_verdef* definition = image->version_definitions; + BytePointer definition(image->version_definitions); for (uint32 i = 0; i < image->num_version_definitions; i++) { if (definition->vd_version != 1) { dprintf("Unsupported version definition revision: %u\n", @@ -875,13 +875,12 @@ init_image_version_infos(elf_image_info* image) if (versionIndex > maxIndex) maxIndex = versionIndex; - definition = (elf_verdef*) - ((uint8*)definition + definition->vd_next); + definition += definition->vd_next; } } if (image->needed_versions != NULL) { - elf_verneed* needed = image->needed_versions; + BytePointer needed(image->needed_versions); for (uint32 i = 0; i < image->num_needed_versions; i++) { if (needed->vn_version != 1) { dprintf("Unsupported version needed revision: %u\n", @@ -889,17 +888,16 @@ init_image_version_infos(elf_image_info* image) return B_BAD_VALUE; } - elf_vernaux* vernaux - = (elf_vernaux*)((uint8*)needed + needed->vn_aux); + BytePointer vernaux(needed + needed->vn_aux); for (uint32 k = 0; k < needed->vn_cnt; k++) { uint32 versionIndex = VER_NDX(vernaux->vna_other); if (versionIndex > maxIndex) maxIndex = versionIndex; - vernaux = (elf_vernaux*)((uint8*)vernaux + vernaux->vna_next); + vernaux += vernaux->vna_next; } - needed = (elf_verneed*)((uint8*)needed + needed->vn_next); + needed += needed->vn_next; } } @@ -919,12 +917,12 @@ init_image_version_infos(elf_image_info* image) // version definitions if (image->version_definitions != NULL) { - elf_verdef* definition = image->version_definitions; + BytePointer definition(image->version_definitions); for (uint32 i = 0; i < image->num_version_definitions; i++) { if (definition->vd_cnt > 0 && (definition->vd_flags & VER_FLG_BASE) == 0) { - elf_verdaux* verdaux - = (elf_verdaux*)((uint8*)definition + definition->vd_aux); + BytePointer verdaux(definition + + definition->vd_aux); uint32 versionIndex = VER_NDX(definition->vd_ndx); elf_version_info& info = image->versions[versionIndex]; @@ -933,19 +931,17 @@ init_image_version_infos(elf_image_info* image) info.file_name = NULL; } - definition = (elf_verdef*) - ((uint8*)definition + definition->vd_next); + definition += definition->vd_next; } } // needed versions if (image->needed_versions != NULL) { - elf_verneed* needed = image->needed_versions; + BytePointer needed(image->needed_versions); for (uint32 i = 0; i < image->num_needed_versions; i++) { const char* fileName = STRING(image, needed->vn_file); - elf_vernaux* vernaux - = (elf_vernaux*)((uint8*)needed + needed->vn_aux); + BytePointer vernaux(needed + needed->vn_aux); for (uint32 k = 0; k < needed->vn_cnt; k++) { uint32 versionIndex = VER_NDX(vernaux->vna_other); elf_version_info& info = image->versions[versionIndex]; @@ -953,10 +949,10 @@ init_image_version_infos(elf_image_info* image) info.name = STRING(image, vernaux->vna_name); info.file_name = fileName; - vernaux = (elf_vernaux*)((uint8*)vernaux + vernaux->vna_next); + vernaux += vernaux->vna_next; } - needed = (elf_verneed*)((uint8*)needed + needed->vn_next); + needed += needed->vn_next; } } @@ -970,12 +966,11 @@ check_needed_image_versions(elf_image_info* image) if (image->needed_versions == NULL) return B_OK; - elf_verneed* needed = image->needed_versions; + BytePointer needed(image->needed_versions); for (uint32 i = 0; i < image->num_needed_versions; i++) { elf_image_info* dependency = sKernelImage; - elf_vernaux* vernaux - = (elf_vernaux*)((uint8*)needed + needed->vn_aux); + BytePointer vernaux(needed + needed->vn_aux); for (uint32 k = 0; k < needed->vn_cnt; k++) { uint32 versionIndex = VER_NDX(vernaux->vna_other); elf_version_info& info = image->versions[versionIndex]; @@ -985,10 +980,10 @@ check_needed_image_versions(elf_image_info* image) if (error != B_OK) return error; - vernaux = (elf_vernaux*)((uint8*)vernaux + vernaux->vna_next); + vernaux += vernaux->vna_next; } - needed = (elf_verneed*)((uint8*)needed + needed->vn_next); + needed += needed->vn_next; } return B_OK;