* FixedWidthPointer: - operators ==/!=: Change second operand type from void* to const Type*. Also add non-const version to resolve ambiguity warning when comparing with non-const pointer. - Add Pointer() getter. - Remove templatized cast operators. They are nice for casting the pointer directly to another pointer type, but result in ambiguity. * Make preloaded_image::debug_string_table non-const. Avoids clashes of the const and non-coast FixedWidthPointer comparison operators. A cleaner (but more verbose) solution would be to spezialize FixedWidthPointer for const types. --- headers/private/kernel/boot/elf.h | 2 +- headers/private/kernel/util/FixedWidthPointer.h | 42 ++++++++++++++++------- src/system/boot/loader/menu.cpp | 8 +++-- src/system/boot/platform/bios_ia32/smp.cpp | 2 +- src/system/boot/platform/bios_ia32/start.cpp | 2 +- src/system/kernel/arch/x86/timers/x86_hpet.cpp | 2 +- src/system/kernel/debug/debug.cpp | 6 ++- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/headers/private/kernel/boot/elf.h b/headers/private/kernel/boot/elf.h index 6c07ebc..88514d9 100644 --- a/headers/private/kernel/boot/elf.h +++ b/headers/private/kernel/boot/elf.h @@ -32,7 +32,7 @@ struct preloaded_image { uint8 elf_class; addr_range dynamic_section; - FixedWidthPointer<const char> debug_string_table; + FixedWidthPointer<char> debug_string_table; uint32 num_debug_symbols; uint32 debug_string_table_size; diff --git a/headers/private/kernel/util/FixedWidthPointer.h b/headers/private/kernel/util/FixedWidthPointer.h index 7024b65..0329532 100644 --- a/headers/private/kernel/util/FixedWidthPointer.h +++ b/headers/private/kernel/util/FixedWidthPointer.h @@ -20,30 +20,29 @@ template<typename Type> class FixedWidthPointer { public: - operator Type*() const + Type * Pointer() const { return (Type*)(addr_t)fValue; } - template<typename OtherType> - operator OtherType*() const + operator Type*() const { - return static_cast<OtherType*>((Type*)(addr_t)fValue); + return Pointer(); } Type& operator*() const { - return *((Type*)(addr_t)fValue); + return *Pointer(); } Type* operator->() const { - return (Type*)(addr_t)fValue; + return Pointer(); } Type& operator[](size_t i) const { - return ((Type*)(addr_t)fValue)[i]; + return Pointer()[i]; } FixedWidthPointer& operator=(const FixedWidthPointer& p) @@ -85,15 +84,14 @@ private: template<> class FixedWidthPointer<void> { public: - operator void*() const + void * Pointer() const { return (void*)(addr_t)fValue; } - template<typename OtherType> - operator OtherType*() const + operator void*() const { - return (OtherType*)(addr_t)fValue; + return Pointer(); } FixedWidthPointer& operator=(const FixedWidthPointer& p) @@ -122,16 +120,34 @@ private: uint64 fValue; } _PACKED; + template<typename Type> inline bool -operator==(const FixedWidthPointer<Type>& a, void* b) +operator==(const FixedWidthPointer<Type>& a, const Type* b) { return a.Get() == (addr_t)b; } + +template<typename Type> +inline bool +operator!=(const FixedWidthPointer<Type>& a, const Type* b) +{ + return a.Get() != (addr_t)b; +} + + +template<typename Type> +inline bool +operator==(const FixedWidthPointer<Type>& a, Type* b) +{ + return a.Get() == (addr_t)b; +} + + template<typename Type> inline bool -operator!=(const FixedWidthPointer<Type>& a, void* b) +operator!=(const FixedWidthPointer<Type>& a, Type* b) { return a.Get() != (addr_t)b; } diff --git a/src/system/boot/loader/menu.cpp b/src/system/boot/loader/menu.cpp index 0397237..fbb90d5 100644 --- a/src/system/boot/loader/menu.cpp +++ b/src/system/boot/loader/menu.cpp @@ -534,7 +534,7 @@ debug_menu_display_current_log(Menu* menu, MenuItem* item) static bool debug_menu_display_previous_syslog(Menu* menu, MenuItem* item) { - ring_buffer* buffer = (ring_buffer*)gKernelArgs.debug_output; + ring_buffer* buffer = (ring_buffer*)gKernelArgs.debug_output.Pointer(); if (buffer == NULL) return true; @@ -595,7 +595,8 @@ save_previous_syslog_to_volume(Directory* directory) return fd; } - ring_buffer* syslogBuffer = (ring_buffer*)gKernelArgs.debug_output; + ring_buffer* syslogBuffer + = (ring_buffer*)gKernelArgs.debug_output.Pointer(); iovec vecs[2]; int32 vecCount = ring_buffer_get_vecs(syslogBuffer, vecs); if (vecCount > 0) { @@ -899,7 +900,8 @@ add_debug_menu() "Displays the debug info the boot loader has logged."); } - ring_buffer* syslogBuffer = (ring_buffer*)gKernelArgs.debug_output; + ring_buffer* syslogBuffer + = (ring_buffer*)gKernelArgs.debug_output.Pointer(); if (syslogBuffer != NULL && ring_buffer_readable(syslogBuffer) > 0) { if (!currentLogItemVisible) menu->AddSeparatorItem(); diff --git a/src/system/boot/platform/bios_ia32/smp.cpp b/src/system/boot/platform/bios_ia32/smp.cpp index d4364f7..4bc2402 100644 --- a/src/system/boot/platform/bios_ia32/smp.cpp +++ b/src/system/boot/platform/bios_ia32/smp.cpp @@ -357,7 +357,7 @@ smp_cpu_ready(void) //TRACE(("smp_cpu_ready: entry cpu %ld\n", curr_cpu)); preloaded_elf32_image *image = static_cast<preloaded_elf32_image *>( - gKernelArgs.kernel_image); + gKernelArgs.kernel_image.Pointer()); // Important. Make sure supervisor threads can fault on read only pages... asm("movl %%eax, %%cr0" : : "a" ((1 << 31) | (1 << 16) | (1 << 5) | 1)); diff --git a/src/system/boot/platform/bios_ia32/start.cpp b/src/system/boot/platform/bios_ia32/start.cpp index 41284f6..b15d539 100644 --- a/src/system/boot/platform/bios_ia32/start.cpp +++ b/src/system/boot/platform/bios_ia32/start.cpp @@ -83,7 +83,7 @@ platform_start_kernel(void) = gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size; preloaded_elf32_image *image = static_cast<preloaded_elf32_image *>( - gKernelArgs.kernel_image); + gKernelArgs.kernel_image.Pointer()); smp_init_other_cpus(); debug_cleanup(); diff --git a/src/system/kernel/arch/x86/timers/x86_hpet.cpp b/src/system/kernel/arch/x86/timers/x86_hpet.cpp index d5dfa48..e25785c 100644 --- a/src/system/kernel/arch/x86/timers/x86_hpet.cpp +++ b/src/system/kernel/arch/x86/timers/x86_hpet.cpp @@ -221,7 +221,7 @@ hpet_init(struct kernel_args *args) return B_ERROR; if (sHPETRegs == NULL) { - sHPETRegs = (struct hpet_regs *)args->arch_args.hpet; + sHPETRegs = (struct hpet_regs *)args->arch_args.hpet.Pointer(); if (vm_map_physical_memory(B_SYSTEM_TEAM, "hpet", (void **)&sHPETRegs, B_EXACT_ADDRESS, B_PAGE_SIZE, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index 791c827..1b5d12d 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -1401,8 +1401,10 @@ syslog_init_post_vm(struct kernel_args* args) sSyslogMessage->ident[0] = '\0'; //strcpy(sSyslogMessage->ident, "KERNEL"); - if (args->debug_output != NULL) - syslog_write((const char*)args->debug_output, args->debug_size, false); + if (args->debug_output != NULL) { + syslog_write((const char*)args->debug_output.Pointer(), + args->debug_size, false); + } char revisionBuffer[64]; length = snprintf(revisionBuffer, sizeof(revisionBuffer), -- 1.7.3.4 --========GMX35901340490678389899--