FixedWidthPointer: Fix ==/!= operators, remove OtherType casts
* 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.
This commit is contained in:
committed by
Alex Smith
parent
ccadfaeeb5
commit
69a8b95491
@@ -32,7 +32,7 @@ struct preloaded_image {
|
|||||||
uint8 elf_class;
|
uint8 elf_class;
|
||||||
addr_range dynamic_section;
|
addr_range dynamic_section;
|
||||||
|
|
||||||
FixedWidthPointer<const char> debug_string_table;
|
FixedWidthPointer<char> debug_string_table;
|
||||||
uint32 num_debug_symbols;
|
uint32 num_debug_symbols;
|
||||||
uint32 debug_string_table_size;
|
uint32 debug_string_table_size;
|
||||||
|
|
||||||
|
|||||||
@@ -20,30 +20,29 @@
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
class FixedWidthPointer {
|
class FixedWidthPointer {
|
||||||
public:
|
public:
|
||||||
operator Type*() const
|
Type * Pointer() const
|
||||||
{
|
{
|
||||||
return (Type*)(addr_t)fValue;
|
return (Type*)(addr_t)fValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OtherType>
|
operator Type*() const
|
||||||
operator OtherType*() const
|
|
||||||
{
|
{
|
||||||
return static_cast<OtherType*>((Type*)(addr_t)fValue);
|
return Pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type& operator*() const
|
Type& operator*() const
|
||||||
{
|
{
|
||||||
return *((Type*)(addr_t)fValue);
|
return *Pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type* operator->() const
|
Type* operator->() const
|
||||||
{
|
{
|
||||||
return (Type*)(addr_t)fValue;
|
return Pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type& operator[](size_t i) const
|
Type& operator[](size_t i) const
|
||||||
{
|
{
|
||||||
return ((Type*)(addr_t)fValue)[i];
|
return Pointer()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
||||||
@@ -85,15 +84,14 @@ private:
|
|||||||
template<>
|
template<>
|
||||||
class FixedWidthPointer<void> {
|
class FixedWidthPointer<void> {
|
||||||
public:
|
public:
|
||||||
operator void*() const
|
void * Pointer() const
|
||||||
{
|
{
|
||||||
return (void*)(addr_t)fValue;
|
return (void*)(addr_t)fValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OtherType>
|
operator void*() const
|
||||||
operator OtherType*() const
|
|
||||||
{
|
{
|
||||||
return (OtherType*)(addr_t)fValue;
|
return Pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
||||||
@@ -122,16 +120,34 @@ private:
|
|||||||
uint64 fValue;
|
uint64 fValue;
|
||||||
} _PACKED;
|
} _PACKED;
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline bool
|
inline bool
|
||||||
operator==(const FixedWidthPointer<Type>& a, void* b)
|
operator==(const FixedWidthPointer<Type>& a, const Type* b)
|
||||||
{
|
{
|
||||||
return a.Get() == (addr_t)b;
|
return a.Get() == (addr_t)b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline bool
|
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, 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;
|
return a.Get() != (addr_t)b;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ debug_menu_display_current_log(Menu* menu, MenuItem* item)
|
|||||||
static bool
|
static bool
|
||||||
debug_menu_display_previous_syslog(Menu* menu, MenuItem* item)
|
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)
|
if (buffer == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -595,7 +595,8 @@ save_previous_syslog_to_volume(Directory* directory)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ring_buffer* syslogBuffer = (ring_buffer*)gKernelArgs.debug_output;
|
ring_buffer* syslogBuffer
|
||||||
|
= (ring_buffer*)gKernelArgs.debug_output.Pointer();
|
||||||
iovec vecs[2];
|
iovec vecs[2];
|
||||||
int32 vecCount = ring_buffer_get_vecs(syslogBuffer, vecs);
|
int32 vecCount = ring_buffer_get_vecs(syslogBuffer, vecs);
|
||||||
if (vecCount > 0) {
|
if (vecCount > 0) {
|
||||||
@@ -899,7 +900,8 @@ add_debug_menu()
|
|||||||
"Displays the debug info the boot loader has logged.");
|
"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 (syslogBuffer != NULL && ring_buffer_readable(syslogBuffer) > 0) {
|
||||||
if (!currentLogItemVisible)
|
if (!currentLogItemVisible)
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ smp_cpu_ready(void)
|
|||||||
//TRACE(("smp_cpu_ready: entry cpu %ld\n", curr_cpu));
|
//TRACE(("smp_cpu_ready: entry cpu %ld\n", curr_cpu));
|
||||||
|
|
||||||
preloaded_elf32_image *image = static_cast<preloaded_elf32_image *>(
|
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...
|
// Important. Make sure supervisor threads can fault on read only pages...
|
||||||
asm("movl %%eax, %%cr0" : : "a" ((1 << 31) | (1 << 16) | (1 << 5) | 1));
|
asm("movl %%eax, %%cr0" : : "a" ((1 << 31) | (1 << 16) | (1 << 5) | 1));
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ platform_start_kernel(void)
|
|||||||
= gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size;
|
= gKernelArgs.cpu_kstack[0].start + gKernelArgs.cpu_kstack[0].size;
|
||||||
|
|
||||||
preloaded_elf32_image *image = static_cast<preloaded_elf32_image *>(
|
preloaded_elf32_image *image = static_cast<preloaded_elf32_image *>(
|
||||||
gKernelArgs.kernel_image);
|
gKernelArgs.kernel_image.Pointer());
|
||||||
|
|
||||||
smp_init_other_cpus();
|
smp_init_other_cpus();
|
||||||
debug_cleanup();
|
debug_cleanup();
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ hpet_init(struct kernel_args *args)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (sHPETRegs == NULL) {
|
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",
|
if (vm_map_physical_memory(B_SYSTEM_TEAM, "hpet",
|
||||||
(void **)&sHPETRegs, B_EXACT_ADDRESS, B_PAGE_SIZE,
|
(void **)&sHPETRegs, B_EXACT_ADDRESS, B_PAGE_SIZE,
|
||||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
|
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
|
||||||
|
|||||||
@@ -1401,8 +1401,10 @@ syslog_init_post_vm(struct kernel_args* args)
|
|||||||
sSyslogMessage->ident[0] = '\0';
|
sSyslogMessage->ident[0] = '\0';
|
||||||
//strcpy(sSyslogMessage->ident, "KERNEL");
|
//strcpy(sSyslogMessage->ident, "KERNEL");
|
||||||
|
|
||||||
if (args->debug_output != NULL)
|
if (args->debug_output != NULL) {
|
||||||
syslog_write((const char*)args->debug_output, args->debug_size, false);
|
syslog_write((const char*)args->debug_output.Pointer(),
|
||||||
|
args->debug_size, false);
|
||||||
|
}
|
||||||
|
|
||||||
char revisionBuffer[64];
|
char revisionBuffer[64];
|
||||||
length = snprintf(revisionBuffer, sizeof(revisionBuffer),
|
length = snprintf(revisionBuffer, sizeof(revisionBuffer),
|
||||||
|
|||||||
Reference in New Issue
Block a user