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:
Andreas Kling 2021-01-20 23:11:17 +01:00
parent e279b45aed
commit 19d3f8cab7
Notes: sideshowbarker 2024-07-18 23:01:53 +09:00
48 changed files with 591 additions and 506 deletions

View file

@ -52,7 +52,7 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, size_t offset, U
evaluate_block_conditions();
}
if (nread < 0)
return KResult(nread);
return KResult((ErrnoCode)-nread);
return nread;
}
@ -65,7 +65,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset,
evaluate_block_conditions();
}
if (nwritten < 0)
return KResult(nwritten);
return KResult((ErrnoCode)-nwritten);
return nwritten;
}
@ -78,7 +78,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptio
else
vmobject = PrivateInodeVMObject::create_with_inode(inode());
if (!vmobject)
return KResult(-ENOMEM);
return ENOMEM;
return process.allocate_region_with_vmobject(preferred_vaddr, size, *vmobject, offset, description.absolute_path(), prot, shared);
}
@ -95,8 +95,8 @@ KResult InodeFile::truncate(u64 size)
if (truncate_result.is_error())
return truncate_result;
int mtime_result = m_inode->set_mtime(kgettimeofday().tv_sec);
if (mtime_result != 0)
return KResult(mtime_result);
if (mtime_result < 0)
return KResult((ErrnoCode)-mtime_result);
return KSuccess;
}