summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-05 19:01:22 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-05 19:01:59 +0100
commit9f2b9c82bf0424bb8d0bbc832a0fa6366c3def9a (patch)
tree953c9032c530310a9e230801e6d8f0aa46aa9bcd /Kernel
parent82f84bab114e8fb1651041ed1ccff4c30d267f19 (diff)
downloadserenity-9f2b9c82bf0424bb8d0bbc832a0fa6366c3def9a.zip
More work towards getting bash to build.
Implemented some syscalls: dup(), dup2(), getdtablesize(). FileHandle is now a retainable, since that's needed for dup()'ed fd's. I didn't really test any of this beyond a basic smoke check.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp33
-rw-r--r--Kernel/Process.h5
-rw-r--r--Kernel/Syscall.cpp6
-rw-r--r--Kernel/Syscall.h3
4 files changed, 45 insertions, 2 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index fa44563a1c..52f3870172 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -1158,7 +1158,6 @@ int Process::sys$open(const char* path, int options)
if (!m_file_descriptors[fd])
break;
}
- handle->setFD(fd);
m_file_descriptors[fd] = move(handle);
return fd;
}
@@ -1435,3 +1434,35 @@ int Process::sys$tcsetpgrp(int fd, pid_t pgid)
tty.set_pgid(pgid);
return 0;
}
+
+int Process::sys$getdtablesize()
+{
+ return m_max_open_file_descriptors;
+}
+
+int Process::sys$dup(int old_fd)
+{
+ auto* handle = fileHandleIfExists(old_fd);
+ if (!handle)
+ return -EBADF;
+ if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
+ return -EMFILE;
+ int new_fd = 0;
+ for (; new_fd < m_max_open_file_descriptors; ++new_fd) {
+ if (!m_file_descriptors[new_fd])
+ break;
+ }
+ m_file_descriptors[new_fd] = handle;
+ return new_fd;
+}
+
+int Process::sys$dup2(int old_fd, int new_fd)
+{
+ auto* handle = fileHandleIfExists(old_fd);
+ if (!handle)
+ return -EBADF;
+ if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
+ return -EMFILE;
+ m_file_descriptors[new_fd] = handle;
+ return new_fd;
+}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 84ef0a2de3..5c6365d9dd 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -126,6 +126,9 @@ public:
int sys$execve(const char* filename, const char** argv, const char** envp);
Unix::sighandler_t sys$signal(int signum, Unix::sighandler_t);
int sys$isatty(int fd);
+ int sys$getdtablesize();
+ int sys$dup(int oldfd);
+ int sys$dup2(int oldfd, int newfd);
static void initialize();
@@ -193,7 +196,7 @@ private:
State m_state { Invalid };
DWORD m_wakeupTime { 0 };
TSS32 m_tss;
- Vector<OwnPtr<FileHandle>> m_file_descriptors;
+ Vector<RetainPtr<FileHandle>> m_file_descriptors;
RingLevel m_ring { Ring0 };
int m_error { 0 };
void* m_kernelStack { nullptr };
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index cef16f864c..c4e5fd704a 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -140,6 +140,12 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
return (dword)current->sys$signal((int)arg1, (Unix::sighandler_t)arg2);
case Syscall::PosixIsatty:
return current->sys$isatty((int)arg1);
+ case Syscall::Getdtablesize:
+ return current->sys$getdtablesize();
+ case Syscall::Dup:
+ return current->sys$dup((int)arg1);
+ case Syscall::Dup2:
+ return current->sys$dup2((int)arg1, (int)arg2);
default:
kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
break;
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index 1582b45dcf..c5a210d099 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -53,6 +53,9 @@ enum Function {
PosixGetegid = 0x2021,
PosixSignal = 0x2022,
PosixIsatty = 0x2023,
+ Getdtablesize = 0x2024,
+ Dup = 0x2025,
+ Dup2 = 0x2026,
};
void initialize();