mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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:
@@ -249,13 +249,13 @@ build_frame_blocks(const util::counted<bootproto::mem_entry> &kmap)
|
||||
unsigned i = 0;
|
||||
|
||||
uint64_t b1 = (page_count + 4095) / 4096;
|
||||
blk->map1 = (1 << b1) - 1;
|
||||
blk->map1 = (1ull << b1) - 1;
|
||||
|
||||
uint64_t b2 = (page_count + 63) / 64;
|
||||
uint64_t b2q = b2 / 64;
|
||||
uint64_t b2r = b2 % 64;
|
||||
g_alloc.memset(blk->map2, b2q, 0xff);
|
||||
blk->map2[b2q] = (1 << b2r) - 1;
|
||||
blk->map2[b2q] = (1ull << b2r) - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ build_frame_blocks(const util::counted<bootproto::mem_entry> &kmap)
|
||||
size_t b = blk.count / 64;
|
||||
size_t r = blk.count % 64;
|
||||
g_alloc.memset(blk.bitmap, b*8, 0xff);
|
||||
blk.bitmap[b] = (1 << r) - 1;
|
||||
blk.bitmap[b] = (1ull << r) - 1;
|
||||
|
||||
bitmap += bitmap_size(blk.count);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
m_nodes(nullptr)
|
||||
{
|
||||
if (capacity)
|
||||
set_capacity(1 << log2(capacity));
|
||||
set_capacity(1ull << log2(capacity));
|
||||
}
|
||||
|
||||
virtual ~base_map() {
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
m_nodes {nullptr}
|
||||
{
|
||||
if (capacity) {
|
||||
m_capacity = 1 << log2(capacity);
|
||||
m_capacity = 1ull << log2(capacity);
|
||||
m_nodes = reinterpret_cast<node_type*>(
|
||||
alloc::allocate(m_capacity * sizeof(node_type)));
|
||||
for (size_t i = 0; i < m_capacity; ++i)
|
||||
|
||||
@@ -265,7 +265,7 @@ public:
|
||||
void ensure_capacity(count_t size)
|
||||
{
|
||||
if (capacity() >= size) return;
|
||||
count_t capacity = (1 << log2(size));
|
||||
count_t capacity = (1ull << log2(size));
|
||||
if (capacity < min_capacity)
|
||||
capacity = min_capacity;
|
||||
set_capacity(capacity);
|
||||
|
||||
Reference in New Issue
Block a user