mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:27:45 +00:00
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
This commit is contained in:
parent
e279b45aed
commit
19d3f8cab7
48 changed files with 591 additions and 506 deletions
|
@ -179,12 +179,12 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, Virtual
|
|||
{
|
||||
REQUIRE_PROMISE(video);
|
||||
if (!shared)
|
||||
return KResult(-ENODEV);
|
||||
return ENODEV;
|
||||
ASSERT(offset == 0);
|
||||
ASSERT(size == framebuffer_size_in_bytes());
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
|
||||
if (!vmobject)
|
||||
return KResult(-ENOMEM);
|
||||
return ENOMEM;
|
||||
return process.allocate_region_with_vmobject(
|
||||
preferred_vaddr,
|
||||
framebuffer_size_in_bytes(),
|
||||
|
|
|
@ -50,7 +50,7 @@ KResultOr<size_t> FullDevice::read(FileDescription&, size_t, UserOrKernelBuffer&
|
|||
{
|
||||
ssize_t count = min(static_cast<size_t>(PAGE_SIZE), size);
|
||||
if (!buffer.memset(0, count))
|
||||
return KResult(-EFAULT);
|
||||
return EFAULT;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ KResultOr<size_t> FullDevice::write(FileDescription&, size_t, const UserOrKernel
|
|||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
return KResult(-ENOSPC);
|
||||
return ENOSPC;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -386,7 +386,7 @@ KResultOr<size_t> KeyboardDevice::read(FileDescription&, size_t, UserOrKernelBuf
|
|||
return (ssize_t)data_bytes;
|
||||
});
|
||||
if (n < 0)
|
||||
return KResult(n);
|
||||
return KResult((ErrnoCode)-n);
|
||||
ASSERT((size_t)n == sizeof(Event));
|
||||
nread += sizeof(Event);
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ KResultOr<Region*> MBVGADevice::mmap(Process& process, FileDescription&, Virtual
|
|||
{
|
||||
REQUIRE_PROMISE(video);
|
||||
if (!shared)
|
||||
return KResult(-ENODEV);
|
||||
return ENODEV;
|
||||
ASSERT(offset == 0);
|
||||
ASSERT(size == framebuffer_size_in_bytes());
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
|
||||
if (!vmobject)
|
||||
return KResult(-ENOMEM);
|
||||
return ENOMEM;
|
||||
return process.allocate_region_with_vmobject(
|
||||
preferred_vaddr,
|
||||
framebuffer_size_in_bytes(),
|
||||
|
|
|
@ -288,7 +288,7 @@ KResultOr<size_t> PS2MouseDevice::read(FileDescription&, size_t, UserOrKernelBuf
|
|||
#endif
|
||||
size_t bytes_read_from_packet = min(remaining_space_in_buffer, sizeof(MousePacket));
|
||||
if (!buffer.write(&packet, nread, bytes_read_from_packet))
|
||||
return KResult(-EFAULT);
|
||||
return EFAULT;
|
||||
nread += bytes_read_from_packet;
|
||||
remaining_space_in_buffer -= bytes_read_from_packet;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ KResultOr<size_t> RandomDevice::read(FileDescription&, size_t, UserOrKernelBuffe
|
|||
return (ssize_t)data_size;
|
||||
});
|
||||
if (!success)
|
||||
return KResult(-EFAULT);
|
||||
return EFAULT;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -236,11 +236,11 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer
|
|||
if (!m_dma_region) {
|
||||
auto page = MM.allocate_supervisor_physical_page();
|
||||
if (!page)
|
||||
return KResult(-ENOMEM);
|
||||
return ENOMEM;
|
||||
auto vmobject = AnonymousVMObject::create_with_physical_page(*page);
|
||||
m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Region::Access::Write);
|
||||
if (!m_dma_region)
|
||||
return KResult(-ENOMEM);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
#ifdef SB16_DEBUG
|
||||
|
@ -249,7 +249,7 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer
|
|||
ASSERT(length <= PAGE_SIZE);
|
||||
const int BLOCK_SIZE = 32 * 1024;
|
||||
if (length > BLOCK_SIZE) {
|
||||
return KResult(-ENOSPC);
|
||||
return ENOSPC;
|
||||
}
|
||||
|
||||
u8 mode = (u8)SampleFormat::Signed | (u8)SampleFormat::Stereo;
|
||||
|
@ -257,7 +257,7 @@ KResultOr<size_t> SB16::write(FileDescription&, size_t, const UserOrKernelBuffer
|
|||
const int sample_rate = 44100;
|
||||
set_sample_rate(sample_rate);
|
||||
if (!data.read(m_dma_region->vaddr().as_ptr(), length))
|
||||
return KResult(-EFAULT);
|
||||
return EFAULT;
|
||||
dma_start(length);
|
||||
|
||||
// 16-bit single-cycle output.
|
||||
|
|
|
@ -59,7 +59,7 @@ KResultOr<size_t> SerialDevice::read(FileDescription&, size_t, UserOrKernelBuffe
|
|||
return (ssize_t)data_size;
|
||||
});
|
||||
if (nwritten < 0)
|
||||
return KResult(nwritten);
|
||||
return KResult((ErrnoCode)-nwritten);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ KResultOr<size_t> SerialDevice::write(FileDescription&, size_t, const UserOrKern
|
|||
return (ssize_t)data_size;
|
||||
});
|
||||
if (nread < 0)
|
||||
return KResult(nread);
|
||||
return KResult((ErrnoCode)-nread);
|
||||
return (size_t)nread;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ KResultOr<size_t> ZeroDevice::read(FileDescription&, size_t, UserOrKernelBuffer&
|
|||
{
|
||||
ssize_t count = min(static_cast<size_t>(PAGE_SIZE), size);
|
||||
if (!buffer.memset(0, count))
|
||||
return KResult(-EFAULT);
|
||||
return EFAULT;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue