Compare commits
No commits in common. "207d901de8fe180247c5478737424857e67b8793" and "d0ceec6952175ff3f11fd80e597bfbbb19ec4847" have entirely different histories.
207d901de8
...
d0ceec6952
@ -26,12 +26,11 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
|
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
setpgid(0, 0);
|
|
||||||
signal(SIGTTOU, SIG_IGN);
|
|
||||||
if (isatty(STDIN_FILENO)) tcsetpgrp(STDIN_FILENO, getpgid(0));
|
|
||||||
|
|
||||||
if (username.is_empty())
|
if (username.is_empty())
|
||||||
{
|
{
|
||||||
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
|
||||||
|
if (isatty(STDIN_FILENO)) tcsetpgrp(STDIN_FILENO, getpgid(0));
|
||||||
|
|
||||||
auto input = os::File::standard_input();
|
auto input = os::File::standard_input();
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ set(SOURCES
|
|||||||
src/sys/resource.cpp
|
src/sys/resource.cpp
|
||||||
src/sys/signal.cpp
|
src/sys/signal.cpp
|
||||||
src/sys/socket.cpp
|
src/sys/socket.cpp
|
||||||
src/sys/poll.cpp
|
|
||||||
src/fs/VFS.cpp
|
src/fs/VFS.cpp
|
||||||
src/fs/Pipe.cpp
|
src/fs/Pipe.cpp
|
||||||
src/fs/Mount.cpp
|
src/fs/Mount.cpp
|
||||||
|
@ -754,8 +754,8 @@ Result<u64> ATADevice::read(u8* buf, usize offset, usize size) const
|
|||||||
ScopedKMutexLock<100> lock(m_drive->channel()->lock());
|
ScopedKMutexLock<100> lock(m_drive->channel()->lock());
|
||||||
|
|
||||||
// FIXME: Don't always allocate this if we don't need it.
|
// FIXME: Don't always allocate this if we don't need it.
|
||||||
auto* temp = (u8*)TRY(malloc_impl(block_size));
|
auto* temp = TRY(make_array<u8>(block_size));
|
||||||
auto guard = make_scope_guard([temp] { free_impl(temp); });
|
auto guard = make_scope_guard([temp] { delete[] temp; });
|
||||||
|
|
||||||
if (offset % block_size)
|
if (offset % block_size)
|
||||||
{
|
{
|
||||||
|
@ -41,8 +41,8 @@ namespace GPT
|
|||||||
|
|
||||||
u32 partition_index = 1;
|
u32 partition_index = 1;
|
||||||
|
|
||||||
auto* table = (PartitionEntry*)TRY(calloc_impl(header.num_partitions, sizeof(PartitionEntry)));
|
auto* table = TRY(make_array<PartitionEntry>(header.num_partitions));
|
||||||
auto guard = make_scope_guard([table] { free_impl(table); });
|
auto guard = make_scope_guard([table] { delete[] table; });
|
||||||
|
|
||||||
nread = TRY(device->read((u8*)table, partition_table_start, sizeof(PartitionEntry) * header.num_partitions));
|
nread = TRY(device->read((u8*)table, partition_table_start, sizeof(PartitionEntry) * header.num_partitions));
|
||||||
check(nread == sizeof(PartitionEntry) * header.num_partitions);
|
check(nread == sizeof(PartitionEntry) * header.num_partitions);
|
||||||
|
@ -91,8 +91,8 @@ namespace Ext2
|
|||||||
const usize inode_size = m_metadata.size;
|
const usize inode_size = m_metadata.size;
|
||||||
const usize block_size = m_fs->m_block_size;
|
const usize block_size = m_fs->m_block_size;
|
||||||
|
|
||||||
u8* const buf = (u8*)TRY(calloc_impl(block_size, 1));
|
u8* const buf = TRY(make_array<u8>(block_size));
|
||||||
auto guard = make_scope_guard([buf] { free_impl(buf); });
|
auto guard = make_scope_guard([buf] { delete[] buf; });
|
||||||
|
|
||||||
m_entries.clear();
|
m_entries.clear();
|
||||||
|
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
#include "fs/VFS.h"
|
|
||||||
#include "memory/MemoryManager.h"
|
|
||||||
#include "sys/Syscall.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
#include <bits/poll.h>
|
|
||||||
|
|
||||||
Result<u64> sys_poll(Registers* regs, SyscallArgs args)
|
|
||||||
{
|
|
||||||
struct pollfd* fds = (struct pollfd*)args[0];
|
|
||||||
nfds_t nfds = (nfds_t)args[1];
|
|
||||||
int timeout = (int)args[2];
|
|
||||||
|
|
||||||
struct pollfd* kfds = (struct pollfd*)TRY(malloc_impl(nfds * sizeof(pollfd)));
|
|
||||||
auto guard = make_scope_guard([kfds] { free_impl(kfds); });
|
|
||||||
|
|
||||||
if (!MemoryManager::copy_from_user(fds, kfds, nfds * sizeof(pollfd))) return err(EFAULT);
|
|
||||||
|
|
||||||
Vector<SharedPtr<VFS::Inode>> inodes;
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
|
|
||||||
for (nfds_t i = 0; i < nfds; i++)
|
|
||||||
{
|
|
||||||
int fd = kfds[i].fd;
|
|
||||||
auto maybe_inode = current->resolve_fd(fd);
|
|
||||||
if (maybe_inode.has_error())
|
|
||||||
{
|
|
||||||
kfds[i].revents |= POLLNVAL;
|
|
||||||
TRY(inodes.try_append({}));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
TRY(inodes.try_append(maybe_inode.release_value()->description->inode));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool infinite = timeout < 0;
|
|
||||||
int fds_with_events;
|
|
||||||
|
|
||||||
do {
|
|
||||||
fds_with_events = 0;
|
|
||||||
for (nfds_t i = 0; i < nfds; i++)
|
|
||||||
{
|
|
||||||
auto& inode = inodes[i];
|
|
||||||
if (!inode) continue;
|
|
||||||
|
|
||||||
if (kfds[i].events & POLLIN && !inode->will_block_if_read())
|
|
||||||
{
|
|
||||||
fds_with_events++;
|
|
||||||
kfds[i].revents |= POLLIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fds_with_events && (timeout > 0 || infinite))
|
|
||||||
{
|
|
||||||
kernel_sleep(10);
|
|
||||||
timeout -= (int)current->sleep_ticks_left;
|
|
||||||
if (current->interrupted)
|
|
||||||
{
|
|
||||||
guard.deactivate();
|
|
||||||
free_impl(kfds);
|
|
||||||
if (current->will_invoke_signal_handler()) return err(EINTR);
|
|
||||||
current->process_pending_signals(regs);
|
|
||||||
return err(EINTR);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} while (false);
|
|
||||||
|
|
||||||
MemoryManager::copy_to_user(fds, kfds, nfds * sizeof(pollfd));
|
|
||||||
|
|
||||||
return fds_with_events;
|
|
||||||
}
|
|
@ -3,8 +3,7 @@
|
|||||||
#ifndef _BITS_FIXED_SIZE_TYPES_H
|
#ifndef _BITS_FIXED_SIZE_TYPES_H
|
||||||
#define _BITS_FIXED_SIZE_TYPES_H
|
#define _BITS_FIXED_SIZE_TYPES_H
|
||||||
|
|
||||||
#if !defined(_SYS_TYPES_H) && !defined(_BITS_SETJMP_TYPES_H) && !defined(_BITS_MAKEDEV_H) && \
|
#if !defined(_SYS_TYPES_H) && !defined(_BITS_SETJMP_TYPES_H) && !defined(_BITS_MAKEDEV_H) && !defined(_BITS_TERMIOS_H)
|
||||||
!defined(_BITS_TERMIOS_H) && !defined(_BITS_POLL_H)
|
|
||||||
#error "Never include bits/fixed-size-types.h, use the standard <stdint.h> header instead."
|
#error "Never include bits/fixed-size-types.h, use the standard <stdint.h> header instead."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/* bits/poll.h: The pollfd data structure. */
|
|
||||||
|
|
||||||
#ifndef _BITS_POLL_H
|
|
||||||
#define _BITS_POLL_H
|
|
||||||
|
|
||||||
#include <bits/fixed-size-types.h>
|
|
||||||
|
|
||||||
#define POLLIN 0
|
|
||||||
#define POLLERR 1
|
|
||||||
#define POLLNVAL 2
|
|
||||||
|
|
||||||
typedef __u64_t nfds_t;
|
|
||||||
|
|
||||||
struct pollfd
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
short events;
|
|
||||||
short revents;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -432,12 +432,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
u8 value;
|
u8 value;
|
||||||
ssize_t rc = read_from_buffer(stream, &value, 1);
|
ssize_t rc = read_from_buffer(stream, &value, 1);
|
||||||
if (rc < 0)
|
if (rc <= 0) return EOF;
|
||||||
{
|
|
||||||
stream->_err = 1;
|
|
||||||
return EOF;
|
|
||||||
}
|
|
||||||
else if (rc == 0) { return EOF; }
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,19 @@ template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
||||||
|
{
|
||||||
|
T* const result = (T*)TRY(calloc_impl(count, sizeof(T)));
|
||||||
|
new (result) T[count];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T> void destroy(T* item)
|
template <typename T> void destroy(T* item)
|
||||||
{
|
{
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> void destroy_array(T* item)
|
||||||
|
{
|
||||||
|
delete[] item;
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
||||||
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
||||||
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
||||||
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept) _e(poll)
|
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
@ -149,9 +149,9 @@ namespace os
|
|||||||
int current;
|
int current;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
current = TRY(getchar());
|
current = fgetc(m_file);
|
||||||
|
|
||||||
if (current == EOF) break;
|
if (current == -1) break;
|
||||||
|
|
||||||
TRY(data.try_append((char)current));
|
TRY(data.try_append((char)current));
|
||||||
|
|
||||||
@ -208,9 +208,7 @@ namespace os
|
|||||||
|
|
||||||
Result<int> File::getchar()
|
Result<int> File::getchar()
|
||||||
{
|
{
|
||||||
int rc = fgetc(m_file);
|
return fgetc(m_file);
|
||||||
if (rc == EOF && ferror(m_file)) return err(errno);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::set_close_on_exec()
|
void File::set_close_on_exec()
|
||||||
|
@ -82,11 +82,12 @@ namespace os::FileSystem
|
|||||||
TRY(stat(path, st, false));
|
TRY(stat(path, st, false));
|
||||||
if (!S_ISLNK(st.st_mode)) return String {};
|
if (!S_ISLNK(st.st_mode)) return String {};
|
||||||
|
|
||||||
char* buf = (char*)TRY(calloc_impl(st.st_size + 1, 1));
|
char* buf = TRY(make_array<char>(st.st_size + 1));
|
||||||
auto guard = make_scope_guard([buf] { free_impl(buf); });
|
auto guard = make_scope_guard([buf] { delete[] buf; });
|
||||||
usize nread = TRY(
|
usize nread = TRY(
|
||||||
Result<usize>::from_syscall(syscall(SYS_readlinkat, path.dirfd(), path.name().chars(), buf, st.st_size)));
|
Result<usize>::from_syscall(syscall(SYS_readlinkat, path.dirfd(), path.name().chars(), buf, st.st_size)));
|
||||||
|
|
||||||
|
buf[nread] = '\0';
|
||||||
guard.deactivate();
|
guard.deactivate();
|
||||||
|
|
||||||
return String { buf, nread };
|
return String { buf, nread };
|
||||||
|
Loading…
Reference in New Issue
Block a user