forked from Bananymous/banan-os
Kernel/LibC: Implement pwrite and make pread non-locking
This commit is contained in:
parent
5d80c880c8
commit
44b762f916
|
@ -112,6 +112,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2);
|
BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
|
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
|
||||||
|
BAN::ErrorOr<long> sys_pwrite(int fd, const void* buffer, size_t count, off_t offset);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_fchmodat(int fd, const char* path, mode_t mode, int flag);
|
BAN::ErrorOr<long> sys_fchmodat(int fd, const char* path, mode_t mode, int flag);
|
||||||
BAN::ErrorOr<long> sys_fchownat(int fd, const char* path, uid_t uid, gid_t gid, int flag);
|
BAN::ErrorOr<long> sys_fchownat(int fd, const char* path, uid_t uid, gid_t gid, int flag);
|
||||||
|
|
|
@ -1192,17 +1192,23 @@ namespace Kernel
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::sys_pread(int fd, void* buffer, size_t count, off_t offset)
|
BAN::ErrorOr<long> Process::sys_pread(int fd, void* buffer, size_t count, off_t offset)
|
||||||
{
|
{
|
||||||
LockGuard _(m_process_lock);
|
|
||||||
if (count == 0)
|
|
||||||
{
|
|
||||||
TRY(m_open_file_descriptors.inode_of(fd));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
TRY(validate_pointer_access(buffer, count, true));
|
|
||||||
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
|
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
|
||||||
return TRY(inode->read(offset, { (uint8_t*)buffer, count }));
|
|
||||||
|
auto* buffer_region = TRY(validate_and_pin_pointer_access(buffer, count, true));
|
||||||
|
BAN::ScopeGuard _([buffer_region]{ if (buffer_region) buffer_region->unpin(); });
|
||||||
|
|
||||||
|
return TRY(inode->read(offset, { reinterpret_cast<uint8_t*>(buffer), count }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<long> Process::sys_pwrite(int fd, const void* buffer, size_t count, off_t offset)
|
||||||
|
{
|
||||||
|
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
|
||||||
|
|
||||||
|
auto* buffer_region = TRY(validate_and_pin_pointer_access(buffer, count, false));
|
||||||
|
BAN::ScopeGuard _([buffer_region]{ if (buffer_region) buffer_region->unpin(); });
|
||||||
|
|
||||||
|
return TRY(inode->write(offset, { reinterpret_cast<const uint8_t*>(buffer), count })); }
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::sys_fchmodat(int fd, const char* path, mode_t mode, int flag)
|
BAN::ErrorOr<long> Process::sys_fchmodat(int fd, const char* path, mode_t mode, int flag)
|
||||||
{
|
{
|
||||||
if (mode & S_IFMASK)
|
if (mode & S_IFMASK)
|
||||||
|
|
|
@ -60,6 +60,7 @@ __BEGIN_DECLS
|
||||||
O(SYS_READLINKAT, readlinkat) \
|
O(SYS_READLINKAT, readlinkat) \
|
||||||
O(SYS_MSYNC, msync) \
|
O(SYS_MSYNC, msync) \
|
||||||
O(SYS_PREAD, pread) \
|
O(SYS_PREAD, pread) \
|
||||||
|
O(SYS_PWRITE, pwrite) \
|
||||||
O(SYS_FCHOWNAT, fchownat) \
|
O(SYS_FCHOWNAT, fchownat) \
|
||||||
O(SYS_LOAD_KEYMAP, load_keymap) \
|
O(SYS_LOAD_KEYMAP, load_keymap) \
|
||||||
O(SYS_SOCKET, socket) \
|
O(SYS_SOCKET, socket) \
|
||||||
|
|
|
@ -127,6 +127,11 @@ ssize_t pread(int fildes, void* buf, size_t nbyte, off_t offset)
|
||||||
return syscall(SYS_PREAD, fildes, buf, nbyte, offset);
|
return syscall(SYS_PREAD, fildes, buf, nbyte, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t pwrite(int fildes, const void* buf, size_t nbyte, off_t offset)
|
||||||
|
{
|
||||||
|
return syscall(SYS_PWRITE, fildes, buf, nbyte, offset);
|
||||||
|
}
|
||||||
|
|
||||||
off_t lseek(int fildes, off_t offset, int whence)
|
off_t lseek(int fildes, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
return syscall(SYS_SEEK, fildes, offset, whence);
|
return syscall(SYS_SEEK, fildes, offset, whence);
|
||||||
|
|
Loading…
Reference in New Issue