kernel/elf: use BytePointer

Change-Id: I3a40921854540d78dec025b2a349e3a153f91d55
Reviewed-on: https://review.haiku-os.org/c/1083
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
PulkoMandy 2019-02-23 15:42:04 +01:00 committed by waddlesplash
parent eea7ceb31d
commit 1b312d7f0a

View File

@ -24,6 +24,7 @@
#include <algorithm> #include <algorithm>
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <BytePointer.h>
#include <commpage.h> #include <commpage.h>
#include <driver_settings.h> #include <driver_settings.h>
#include <boot/kernel_args.h> #include <boot/kernel_args.h>
@ -829,7 +830,7 @@ assert_defined_image_version(elf_image_info* dependentImage,
} }
// iterate through the defined versions to find the given one // iterate through the defined versions to find the given one
elf_verdef* definition = image->version_definitions; BytePointer<elf_verdef> definition(image->version_definitions);
for (uint32 i = 0; i < image->num_version_definitions; i++) { for (uint32 i = 0; i < image->num_version_definitions; i++) {
uint32 versionIndex = VER_NDX(definition->vd_ndx); uint32 versionIndex = VER_NDX(definition->vd_ndx);
elf_version_info& info = image->versions[versionIndex]; elf_version_info& info = image->versions[versionIndex];
@ -839,8 +840,7 @@ assert_defined_image_version(elf_image_info* dependentImage,
return B_OK; return B_OK;
} }
definition = (elf_verdef*) definition += definition->vd_next;
((uint8*)definition + definition->vd_next);
} }
// version not found -- fail, if not weak // version not found -- fail, if not weak
@ -863,7 +863,7 @@ init_image_version_infos(elf_image_info* image)
uint32 maxIndex = 0; uint32 maxIndex = 0;
if (image->version_definitions != NULL) { if (image->version_definitions != NULL) {
elf_verdef* definition = image->version_definitions; BytePointer<elf_verdef> definition(image->version_definitions);
for (uint32 i = 0; i < image->num_version_definitions; i++) { for (uint32 i = 0; i < image->num_version_definitions; i++) {
if (definition->vd_version != 1) { if (definition->vd_version != 1) {
dprintf("Unsupported version definition revision: %u\n", dprintf("Unsupported version definition revision: %u\n",
@ -875,13 +875,12 @@ init_image_version_infos(elf_image_info* image)
if (versionIndex > maxIndex) if (versionIndex > maxIndex)
maxIndex = versionIndex; maxIndex = versionIndex;
definition = (elf_verdef*) definition += definition->vd_next;
((uint8*)definition + definition->vd_next);
} }
} }
if (image->needed_versions != NULL) { if (image->needed_versions != NULL) {
elf_verneed* needed = image->needed_versions; BytePointer<elf_verneed> needed(image->needed_versions);
for (uint32 i = 0; i < image->num_needed_versions; i++) { for (uint32 i = 0; i < image->num_needed_versions; i++) {
if (needed->vn_version != 1) { if (needed->vn_version != 1) {
dprintf("Unsupported version needed revision: %u\n", dprintf("Unsupported version needed revision: %u\n",
@ -889,17 +888,16 @@ init_image_version_infos(elf_image_info* image)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
elf_vernaux* vernaux BytePointer<elf_vernaux> vernaux(needed + needed->vn_aux);
= (elf_vernaux*)((uint8*)needed + needed->vn_aux);
for (uint32 k = 0; k < needed->vn_cnt; k++) { for (uint32 k = 0; k < needed->vn_cnt; k++) {
uint32 versionIndex = VER_NDX(vernaux->vna_other); uint32 versionIndex = VER_NDX(vernaux->vna_other);
if (versionIndex > maxIndex) if (versionIndex > maxIndex)
maxIndex = versionIndex; 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 // version definitions
if (image->version_definitions != NULL) { if (image->version_definitions != NULL) {
elf_verdef* definition = image->version_definitions; BytePointer<elf_verdef> definition(image->version_definitions);
for (uint32 i = 0; i < image->num_version_definitions; i++) { for (uint32 i = 0; i < image->num_version_definitions; i++) {
if (definition->vd_cnt > 0 if (definition->vd_cnt > 0
&& (definition->vd_flags & VER_FLG_BASE) == 0) { && (definition->vd_flags & VER_FLG_BASE) == 0) {
elf_verdaux* verdaux BytePointer<elf_verdaux> verdaux(definition
= (elf_verdaux*)((uint8*)definition + definition->vd_aux); + definition->vd_aux);
uint32 versionIndex = VER_NDX(definition->vd_ndx); uint32 versionIndex = VER_NDX(definition->vd_ndx);
elf_version_info& info = image->versions[versionIndex]; elf_version_info& info = image->versions[versionIndex];
@ -933,19 +931,17 @@ init_image_version_infos(elf_image_info* image)
info.file_name = NULL; info.file_name = NULL;
} }
definition = (elf_verdef*) definition += definition->vd_next;
((uint8*)definition + definition->vd_next);
} }
} }
// needed versions // needed versions
if (image->needed_versions != NULL) { if (image->needed_versions != NULL) {
elf_verneed* needed = image->needed_versions; BytePointer<elf_verneed> needed(image->needed_versions);
for (uint32 i = 0; i < image->num_needed_versions; i++) { for (uint32 i = 0; i < image->num_needed_versions; i++) {
const char* fileName = STRING(image, needed->vn_file); const char* fileName = STRING(image, needed->vn_file);
elf_vernaux* vernaux BytePointer<elf_vernaux> vernaux(needed + needed->vn_aux);
= (elf_vernaux*)((uint8*)needed + needed->vn_aux);
for (uint32 k = 0; k < needed->vn_cnt; k++) { for (uint32 k = 0; k < needed->vn_cnt; k++) {
uint32 versionIndex = VER_NDX(vernaux->vna_other); uint32 versionIndex = VER_NDX(vernaux->vna_other);
elf_version_info& info = image->versions[versionIndex]; 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.name = STRING(image, vernaux->vna_name);
info.file_name = fileName; 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) if (image->needed_versions == NULL)
return B_OK; return B_OK;
elf_verneed* needed = image->needed_versions; BytePointer<elf_verneed> needed(image->needed_versions);
for (uint32 i = 0; i < image->num_needed_versions; i++) { for (uint32 i = 0; i < image->num_needed_versions; i++) {
elf_image_info* dependency = sKernelImage; elf_image_info* dependency = sKernelImage;
elf_vernaux* vernaux BytePointer<elf_vernaux> vernaux(needed + needed->vn_aux);
= (elf_vernaux*)((uint8*)needed + needed->vn_aux);
for (uint32 k = 0; k < needed->vn_cnt; k++) { for (uint32 k = 0; k < needed->vn_cnt; k++) {
uint32 versionIndex = VER_NDX(vernaux->vna_other); uint32 versionIndex = VER_NDX(vernaux->vna_other);
elf_version_info& info = image->versions[versionIndex]; elf_version_info& info = image->versions[versionIndex];
@ -985,10 +980,10 @@ check_needed_image_versions(elf_image_info* image)
if (error != B_OK) if (error != B_OK)
return error; 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; return B_OK;