[many] Fix many cases of 1 << n exceeding the size of int

Yet again burned by the fack that integer literals are assumed to be of
type int, so `1 << n` is 0 for any n >= 32. This burned me in the frame
allocator, but I also grepped for all instances of `1 <<` and fixed
those too.
This commit is contained in:
Justin C. Miller
2023-02-18 19:53:04 -08:00
parent 42db1e8899
commit 55c88dd943
7 changed files with 20 additions and 19 deletions

View File

@@ -385,7 +385,7 @@ device_manager::dispatch_irq(unsigned irq)
if (!binding.target || binding.target == ignore_event)
return binding.target == ignore_event;
binding.target->signal(1 << binding.signal);
binding.target->signal(1ull << binding.signal);
return true;
}

View File

@@ -101,9 +101,9 @@ frame_allocator::free(uintptr_t address, size_t count)
unsigned o3 = frame & 0x3f;
while (count--) {
block.map1 |= (1 << o1);
block.map2[o1] |= (1 << o2);
block.bitmap[o2] |= (1 << o3);
block.map1 |= (1ull << o1);
block.map2[o1] |= (1ull << o2);
block.bitmap[o2] |= (1ull << o3);
if (++o3 == 64) {
o3 = 0;
if (++o2 == 64) {
@@ -139,12 +139,12 @@ frame_allocator::used(uintptr_t address, size_t count)
unsigned o3 = frame & 0x3f;
while (count--) {
block.bitmap[o2] &= ~(1 << o3);
block.bitmap[o2] &= ~(1ull << o3);
if (!block.bitmap[o2]) {
block.map2[o1] &= ~(1 << o2);
block.map2[o1] &= ~(1ull << o2);
if (!block.map2[o1]) {
block.map1 &= ~(1 << o1);
block.map1 &= ~(1ull << o1);
}
}

View File

@@ -27,7 +27,7 @@ struct heap_allocator::free_header
inline free_header * buddy() const {
return reinterpret_cast<free_header *>(
reinterpret_cast<uintptr_t>(this) ^ (1 << order));
reinterpret_cast<uintptr_t>(this) ^ (1ull << order));
}
inline bool eldest() const { return this < buddy(); }
@@ -67,7 +67,7 @@ heap_allocator::allocate(size_t length)
util::scoped_lock lock {m_lock};
m_allocated_size += (1 << order);
m_allocated_size += (1ull << order);
free_header *block = pop_free(order);
if (!block && !split_off(order, block)) {
@@ -95,7 +95,8 @@ heap_allocator::free(void *p)
kassert(info, "Attempt to free pointer not known to the heap");
if (!info) return;
m_allocated_size -= (1 << info->order);
size_t size = (1ull << info->order);
m_allocated_size -= size;
block->clear(info->order);
block = merge_block(block);
@@ -118,7 +119,7 @@ heap_allocator::reallocate(void *p, size_t old_length, size_t new_length)
if (!info)
return nullptr;
if (new_length <= (1 << info->order))
if (new_length <= (1ull << info->order))
return p;
lock.release();
@@ -180,12 +181,12 @@ heap_allocator::new_block(unsigned order)
unsigned current = address_order(m_end);
while (current < order) {
register_free_block(reinterpret_cast<free_header*>(m_end), current);
m_end += 1 << current;
m_end += 1ull << current;
current = address_order(m_end);
}
void *block = reinterpret_cast<void*>(m_end);
m_end += 1 << order;
m_end += 1ull << order;
m_map[map_key(block)].order = order;
return block;
}