Compare commits
No commits in common. "19d16620a64f12f5d7f797d951d8ed959d7798d1" and "e8bcebfb8e92933ee175d1e09bd7f9d8f26868bf" have entirely different histories.
19d16620a6
...
e8bcebfb8e
|
@ -13,20 +13,8 @@ namespace Kernel
|
||||||
|
|
||||||
if (offset < 0 || offset % PAGE_SIZE || size == 0)
|
if (offset < 0 || offset % PAGE_SIZE || size == 0)
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
switch (type)
|
if (size > (size_t)inode->size() || (size_t)offset > (size_t)inode->size() - size)
|
||||||
{
|
return BAN::Error::from_errno(EOVERFLOW);
|
||||||
case Type::PRIVATE:
|
|
||||||
if (offset >= inode->size())
|
|
||||||
return BAN::Error::from_errno(EOVERFLOW);
|
|
||||||
break;
|
|
||||||
case Type::SHARED:
|
|
||||||
if ((size > (size_t)inode->size() || (size_t)offset > (size_t)inode->size() - size))
|
|
||||||
return BAN::Error::from_errno(EOVERFLOW);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* region_ptr = new FileBackedRegion(inode, page_table, offset, size, type, flags);
|
auto* region_ptr = new FileBackedRegion(inode, page_table, offset, size, type, flags);
|
||||||
if (region_ptr == nullptr)
|
if (region_ptr == nullptr)
|
||||||
|
@ -124,7 +112,7 @@ namespace Kernel
|
||||||
ASSERT(contains(address));
|
ASSERT(contains(address));
|
||||||
|
|
||||||
// Check if address is already mapped
|
// Check if address is already mapped
|
||||||
const vaddr_t vaddr = address & PAGE_ADDR_MASK;
|
vaddr_t vaddr = address & PAGE_ADDR_MASK;
|
||||||
if (m_page_table.physical_address_of(vaddr) != 0)
|
if (m_page_table.physical_address_of(vaddr) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -138,30 +126,25 @@ namespace Kernel
|
||||||
// Temporarily force mapping to be writable so kernel can write to it
|
// Temporarily force mapping to be writable so kernel can write to it
|
||||||
m_page_table.map_page_at(paddr, vaddr, m_flags | PageTable::Flags::ReadWrite);
|
m_page_table.map_page_at(paddr, vaddr, m_flags | PageTable::Flags::ReadWrite);
|
||||||
|
|
||||||
|
size_t file_offset = m_offset + (vaddr - m_vaddr);
|
||||||
|
size_t bytes = BAN::Math::min<size_t>(m_size - file_offset, PAGE_SIZE);
|
||||||
|
|
||||||
ASSERT(&PageTable::current() == &m_page_table);
|
ASSERT(&PageTable::current() == &m_page_table);
|
||||||
memset(reinterpret_cast<void*>(vaddr), 0x00, PAGE_SIZE);
|
auto read_ret = m_inode->read(file_offset, BAN::ByteSpan((uint8_t*)vaddr, bytes));
|
||||||
|
|
||||||
const size_t file_offset = m_offset + (vaddr - m_vaddr);
|
if (read_ret.is_error())
|
||||||
|
|
||||||
if (file_offset < static_cast<size_t>(m_inode->size()))
|
|
||||||
{
|
{
|
||||||
const size_t bytes = BAN::Math::min<size_t>(BAN::Math::min<size_t>(m_offset + m_size, m_inode->size()) - file_offset, PAGE_SIZE);
|
Heap::get().release_page(paddr);
|
||||||
auto read_ret = m_inode->read(file_offset, BAN::ByteSpan((uint8_t*)vaddr, bytes));
|
m_page_table.unmap_page(vaddr);
|
||||||
|
return read_ret.release_error();
|
||||||
|
}
|
||||||
|
|
||||||
if (read_ret.is_error())
|
if (read_ret.value() < bytes)
|
||||||
{
|
{
|
||||||
Heap::get().release_page(paddr);
|
dwarnln("Only {}/{} bytes read", read_ret.value(), bytes);
|
||||||
m_page_table.unmap_page(vaddr);
|
Heap::get().release_page(paddr);
|
||||||
return read_ret.release_error();
|
m_page_table.unmap_page(vaddr);
|
||||||
}
|
return BAN::Error::from_errno(EIO);
|
||||||
|
|
||||||
if (read_ret.value() < bytes)
|
|
||||||
{
|
|
||||||
dwarnln("Only {}/{} bytes read", read_ret.value(), bytes);
|
|
||||||
Heap::get().release_page(paddr);
|
|
||||||
m_page_table.unmap_page(vaddr);
|
|
||||||
return BAN::Error::from_errno(EIO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable writable if not wanted
|
// Disable writable if not wanted
|
||||||
|
@ -189,8 +172,7 @@ namespace Kernel
|
||||||
TRY(m_inode->read(offset, BAN::ByteSpan(m_shared_data->page_buffer, bytes)));
|
TRY(m_inode->read(offset, BAN::ByteSpan(m_shared_data->page_buffer, bytes)));
|
||||||
|
|
||||||
PageTable::with_fast_page(pages[page_index], [&] {
|
PageTable::with_fast_page(pages[page_index], [&] {
|
||||||
memcpy(PageTable::fast_page_as_ptr(), m_shared_data->page_buffer, bytes);
|
memcpy(PageTable::fast_page_as_ptr(), m_shared_data->page_buffer, PAGE_SIZE);
|
||||||
memset(PageTable::fast_page_as_ptr(bytes), 0x00, PAGE_SIZE - bytes);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,6 @@ if [ ! -f "$BANAN_SYSROOT/usr/lib/libc.a" ]; then
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$BANAN_ARCH" = "i686" ]; then
|
|
||||||
export LDFLAGS="-shared-libgcc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
clean() {
|
clean() {
|
||||||
find . -mindepth 1 -maxdepth 1 -not -name 'patches' -not -name 'build.sh' -exec rm -rf {} +
|
find . -mindepth 1 -maxdepth 1 -not -name 'patches' -not -name 'build.sh' -exec rm -rf {} +
|
||||||
}
|
}
|
||||||
|
|
|
@ -622,7 +622,7 @@ static void load_program_header(const ElfNativeProgramHeader& program_header, in
|
||||||
return result;
|
return result;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if ((program_header.p_vaddr & 0xFFF) || (program_header.p_offset & 0xFFF) || program_header.p_filesz == 0)
|
if ((program_header.p_vaddr & 0xFFF) || (program_header.p_offset & 0xFFF))
|
||||||
{
|
{
|
||||||
const uintptr_t aligned_addr = program_header.p_vaddr & ~(uintptr_t)0xFFF;
|
const uintptr_t aligned_addr = program_header.p_vaddr & ~(uintptr_t)0xFFF;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue