Compare commits
No commits in common. "71633e264fc5ccbe38bbddeb7b7689ede42255cb" and "7afbff08b60632e68c4c26faf35f1d1f808c3549" have entirely different histories.
71633e264f
...
7afbff08b6
@ -103,7 +103,6 @@ struct Task
|
|||||||
|
|
||||||
bool is_still_blocking();
|
bool is_still_blocking();
|
||||||
|
|
||||||
Descriptor* open_descriptor_from_fd(int fd, int& error);
|
|
||||||
Descriptor* descriptor_from_fd(int fd, int& error);
|
Descriptor* descriptor_from_fd(int fd, int& error);
|
||||||
|
|
||||||
bool is_superuser();
|
bool is_superuser();
|
||||||
|
@ -16,7 +16,7 @@ VFS::Node* SerialDevice::create_new(const char* devname)
|
|||||||
dev->type = VFS_DEVICE;
|
dev->type = VFS_DEVICE;
|
||||||
dev->flags = 0;
|
dev->flags = 0;
|
||||||
dev->uid = dev->gid = 0;
|
dev->uid = dev->gid = 0;
|
||||||
dev->mode = 0222;
|
dev->mode = 0200;
|
||||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||||
strncpy(dev->name, devname, sizeof(dev->name));
|
strncpy(dev->name, devname, sizeof(dev->name));
|
||||||
return dev;
|
return dev;
|
||||||
|
@ -32,8 +32,12 @@ static int mman_flags_from_prot(int prot)
|
|||||||
prot &= 0b111;
|
prot &= 0b111;
|
||||||
int flags = MAP_USER | MAP_AS_OWNED_BY_TASK;
|
int flags = MAP_USER | MAP_AS_OWNED_BY_TASK;
|
||||||
if (prot == PROT_NONE) return MAP_AS_OWNED_BY_TASK;
|
if (prot == PROT_NONE) return MAP_AS_OWNED_BY_TASK;
|
||||||
if ((prot & PROT_WRITE) > 0) { flags |= MAP_READ_WRITE; }
|
if ((prot & PROT_WRITE) > 0) {
|
||||||
if ((prot & PROT_EXEC) > 0) { flags |= MAP_EXEC; }
|
flags |= MAP_READ_WRITE;
|
||||||
|
}
|
||||||
|
if ((prot & PROT_EXEC) > 0) {
|
||||||
|
flags |= MAP_EXEC;
|
||||||
|
}
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,11 +72,11 @@ void sys_mmap(Context* context, void* address, size_t size, int prot, int fd, of
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint64_t addr_offset = (uint64_t)address % PAGE_SIZE;
|
uint64_t addr_offset = (uint64_t)address % PAGE_SIZE;
|
||||||
if (fd >= 0)
|
if(fd >= 0)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if(!file)
|
||||||
{
|
{
|
||||||
context->rax = MAP_FAIL(err);
|
context->rax = MAP_FAIL(err);
|
||||||
return;
|
return;
|
||||||
@ -95,8 +99,7 @@ void sys_mmap(Context* context, void* address, size_t size, int prot, int fd, of
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kdbgln("mmap(): %ld pages at any address, %s, fd %d", Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
kdbgln("mmap(): %ld pages at any address, %s, fd %d", Utilities::get_blocks_from_size(PAGE_SIZE, size), format_prot(prot), fd);
|
||||||
format_prot(prot), fd);
|
|
||||||
uint64_t ptr =
|
uint64_t ptr =
|
||||||
Scheduler::current_task()->allocator.request_virtual_pages(Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
Scheduler::current_task()->allocator.request_virtual_pages(Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
@ -105,11 +108,11 @@ void sys_mmap(Context* context, void* address, size_t size, int prot, int fd, of
|
|||||||
context->rax = MAP_FAIL(ENOMEM);
|
context->rax = MAP_FAIL(ENOMEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fd >= 0)
|
if(fd >= 0)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if(!file)
|
||||||
{
|
{
|
||||||
context->rax = MAP_FAIL(err);
|
context->rax = MAP_FAIL(err);
|
||||||
return;
|
return;
|
||||||
@ -169,12 +172,10 @@ void sys_munmap(Context* context, void* address, size_t size)
|
|||||||
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
||||||
Scheduler::current_task()->allocator.free_virtual_pages(((uint64_t)address - offset),
|
Scheduler::current_task()->allocator.free_virtual_pages(((uint64_t)address - offset),
|
||||||
Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
||||||
if (flags & MAP_AS_OWNED_BY_TASK)
|
if(flags & MAP_AS_OWNED_BY_TASK)
|
||||||
MemoryManager::release_pages((void*)((uint64_t)address - offset),
|
MemoryManager::release_pages((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
||||||
Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
|
||||||
else
|
else
|
||||||
MemoryManager::release_unaligned_mappings((void*)((uint64_t)address - offset),
|
MemoryManager::release_unaligned_mappings((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
||||||
Utilities::get_blocks_from_size(PAGE_SIZE, size));
|
|
||||||
kdbgln("munmap() succeeded");
|
kdbgln("munmap() succeeded");
|
||||||
context->rax = 0;
|
context->rax = 0;
|
||||||
return;
|
return;
|
||||||
@ -218,8 +219,7 @@ void sys_mprotect(Context* context, void* address, size_t size, int prot)
|
|||||||
|
|
||||||
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
uint64_t offset = (uint64_t)address % PAGE_SIZE;
|
||||||
MemoryManager::protect((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
MemoryManager::protect((void*)((uint64_t)address - offset), Utilities::get_blocks_from_size(PAGE_SIZE, size),
|
||||||
flags & MAP_AS_OWNED_BY_TASK ? mman_flags_from_prot(prot)
|
flags & MAP_AS_OWNED_BY_TASK ? mman_flags_from_prot(prot) : mman_flags_from_prot(prot) & ~(MAP_AS_OWNED_BY_TASK));
|
||||||
: mman_flags_from_prot(prot) & ~(MAP_AS_OWNED_BY_TASK));
|
|
||||||
kdbgln("mprotect() succeeded");
|
kdbgln("mprotect() succeeded");
|
||||||
context->rax = 0;
|
context->rax = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@ void sys_fcntl(Context* context, int fd, int command, uintptr_t arg)
|
|||||||
{
|
{
|
||||||
Task* current_task = Scheduler::current_task();
|
Task* current_task = Scheduler::current_task();
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = current_task->open_descriptor_from_fd(fd, err);
|
Descriptor* file = current_task->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
@ -102,7 +102,7 @@ void sys_seek(Context* context, int fd, long offset, int whence)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
@ -144,7 +144,7 @@ void sys_write(Context* context, int fd, size_t size, const char* addr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
@ -155,8 +155,7 @@ void sys_write(Context* context, int fd, size_t size, const char* addr)
|
|||||||
context->rax = -EBADF;
|
context->rax = -EBADF;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ssize_t result = file->write(
|
ssize_t result = file->write(size, (const char*)VMM::get_physical((uint64_t)addr));
|
||||||
size, (const char*)VMM::get_physical((uint64_t)addr)); // FIXME: Handle big buffers and invalid addresses.
|
|
||||||
context->rax = (size_t)result;
|
context->rax = (size_t)result;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -275,13 +274,13 @@ void sys_read(Context* context, int fd, size_t size, char* buffer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file->can_read())
|
if (!file->is_open() || !file->can_read())
|
||||||
{
|
{
|
||||||
context->rax = -EBADF;
|
context->rax = -EBADF;
|
||||||
return;
|
return;
|
||||||
@ -311,7 +310,7 @@ void sys_read(Context* context, int fd, size_t size, char* buffer)
|
|||||||
void sys_close(Context* context, int fd)
|
void sys_close(Context* context, int fd)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
@ -353,13 +352,13 @@ void sys_access(Context* context, const char* path, int) // FIXME: Use the amode
|
|||||||
void sys_dup2(Context* context, int fd, int fd2)
|
void sys_dup2(Context* context, int fd, int fd2)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file1 = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file1 = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file1)
|
if (!file1)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Descriptor* file2 = Scheduler::current_task()->descriptor_from_fd(fd2, err);
|
Descriptor* file2 = Scheduler::current_task()->descriptor_from_fd(fd2, err); // FIXME: This will return EBADF if fd2 is not open, but we want to replace it with fd1 if it is not open.
|
||||||
if (!file2)
|
if (!file2)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
@ -381,7 +380,7 @@ void sys_umask(Context* context, mode_t cmask)
|
|||||||
void sys_ioctl(Context* context, int fd, int cmd, uintptr_t arg)
|
void sys_ioctl(Context* context, int fd, int cmd, uintptr_t arg)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
Descriptor* file = Scheduler::current_task()->open_descriptor_from_fd(fd, err);
|
Descriptor* file = Scheduler::current_task()->descriptor_from_fd(fd, err);
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
context->rax = -err;
|
context->rax = -err;
|
||||||
|
@ -112,21 +112,14 @@ bool Task::is_still_blocking()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Descriptor* Task::open_descriptor_from_fd(int fd, int& error)
|
Descriptor* Task::descriptor_from_fd(int fd, int& error)
|
||||||
{
|
{
|
||||||
Descriptor* file = descriptor_from_fd(fd, error);
|
if (fd < 0 || fd >= TASK_MAX_FDS)
|
||||||
if (!file) return nullptr;
|
|
||||||
if (!file->is_open())
|
|
||||||
{
|
{
|
||||||
error = EBADF;
|
error = EBADF;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return file;
|
if (!files[fd].is_open())
|
||||||
}
|
|
||||||
|
|
||||||
Descriptor* Task::descriptor_from_fd(int fd, int& error)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd >= TASK_MAX_FDS)
|
|
||||||
{
|
{
|
||||||
error = EBADF;
|
error = EBADF;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -163,8 +163,7 @@ extern "C"
|
|||||||
* of the last error encountered during a call to a system or library function. */
|
* of the last error encountered during a call to a system or library function. */
|
||||||
void perror(const char* str);
|
void perror(const char* str);
|
||||||
|
|
||||||
int remove(const char* pathname); // Not implemented.
|
int remove(const char* pathname); // Not implemented.
|
||||||
int rename(const char* oldpath, const char* newpath); // Not implemented.
|
|
||||||
|
|
||||||
FILE* tmpfile(void); // Not implemented.
|
FILE* tmpfile(void); // Not implemented.
|
||||||
|
|
||||||
|
@ -185,7 +185,6 @@ static int internal_printf(const char* format, PutString put_string_callback, ss
|
|||||||
preserve_format = true;
|
preserve_format = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'i':
|
|
||||||
case 'd': {
|
case 'd': {
|
||||||
char result[32];
|
char result[32];
|
||||||
if (is_unsigned_long)
|
if (is_unsigned_long)
|
||||||
|
@ -64,11 +64,6 @@ extern "C"
|
|||||||
NOT_IMPLEMENTED("fscanf");
|
NOT_IMPLEMENTED("fscanf");
|
||||||
}
|
}
|
||||||
|
|
||||||
int rename(const char*, const char*)
|
|
||||||
{
|
|
||||||
NOT_IMPLEMENTED("rename");
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* tmpfile()
|
FILE* tmpfile()
|
||||||
{
|
{
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
|
@ -37,5 +37,6 @@ port_install()
|
|||||||
|
|
||||||
port_uninstall() # nasm's Makefile does not provide an uninstall target.
|
port_uninstall() # nasm's Makefile does not provide an uninstall target.
|
||||||
{
|
{
|
||||||
rm -f $DESTDIR/bin/{nasm,ndisasm}
|
rm -f $DESTDIR/bin/nasm
|
||||||
|
rm -f $DESTDIR/bin/ndisasm
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user