mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Implement sys$getcwd properly.
Also fixed broken strcpy that didn't copy the null terminator.
This commit is contained in:
parent
8e640539ef
commit
0f20be05a6
Notes:
sideshowbarker
2024-07-19 18:36:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0f20be05a6f
5 changed files with 18 additions and 27 deletions
|
@ -13,8 +13,7 @@ void memcpy(void *dest, const void *src, DWORD n)
|
|||
|
||||
void strcpy(char* dest, const char *src)
|
||||
{
|
||||
while (*src)
|
||||
*(dest++) = *(src++);
|
||||
while ((*dest++ = *src++) != '\0');
|
||||
}
|
||||
|
||||
void* memset(void* dest, BYTE c, DWORD n)
|
||||
|
|
|
@ -233,6 +233,8 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren
|
|||
InterruptDisabler disabler;
|
||||
if (auto* parentTask = Task::fromPID(parentPID))
|
||||
cwd = parentTask->m_cwd.copyRef();
|
||||
if (!cwd)
|
||||
cwd = VirtualFileSystem::the().root();
|
||||
}
|
||||
|
||||
auto handle = VirtualFileSystem::the().open(path, error, 0, cwd ? cwd->inode : InodeIdentifier());
|
||||
|
@ -260,7 +262,7 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren
|
|||
}
|
||||
|
||||
InterruptDisabler disabler; // FIXME: Get rid of this, jesus christ. This "critical" section is HUGE.
|
||||
Task* t = new Task(parts.takeLast(), uid, gid, parentPID, Ring3, handle->vnode());
|
||||
Task* t = new Task(parts.takeLast(), uid, gid, parentPID, Ring3, move(cwd), handle->vnode());
|
||||
|
||||
t->m_arguments = move(taskArguments);
|
||||
|
||||
|
@ -361,13 +363,14 @@ Task* Task::createKernelTask(void (*e)(), String&& name)
|
|||
return task;
|
||||
}
|
||||
|
||||
Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring, RetainPtr<VirtualFileSystem::Node>&& executable)
|
||||
Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring, RetainPtr<VirtualFileSystem::Node>&& cwd, RetainPtr<VirtualFileSystem::Node>&& executable)
|
||||
: m_name(move(name))
|
||||
, m_pid(next_pid++)
|
||||
, m_uid(uid)
|
||||
, m_gid(gid)
|
||||
, m_state(Runnable)
|
||||
, m_ring(ring)
|
||||
, m_cwd(move(cwd))
|
||||
, m_executable(move(executable))
|
||||
, m_parentPID(parentPID)
|
||||
{
|
||||
|
@ -375,12 +378,6 @@ Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring,
|
|||
m_fileHandles.append(nullptr); // stdout
|
||||
m_fileHandles.append(nullptr); // stderr
|
||||
|
||||
auto* parentTask = Task::fromPID(parentPID);
|
||||
if (parentTask)
|
||||
m_cwd = parentTask->m_cwd.copyRef();
|
||||
else
|
||||
m_cwd = nullptr;
|
||||
|
||||
m_nextRegion = LinearAddress(0x600000);
|
||||
|
||||
memset(&m_tss, 0, sizeof(m_tss));
|
||||
|
@ -833,8 +830,13 @@ int Task::sys$chdir(const char* path)
|
|||
|
||||
int Task::sys$getcwd(char* buffer, size_t size)
|
||||
{
|
||||
// FIXME: Implement!
|
||||
VALIDATE_USER_BUFFER(buffer, size);
|
||||
auto path = VirtualFileSystem::the().absolutePath(cwdInode());
|
||||
if (path.isNull())
|
||||
return -EINVAL;
|
||||
if (size < path.length() + 1)
|
||||
return -ERANGE;
|
||||
strcpy(buffer, path.characters());
|
||||
return -ENOTIMPL;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ private:
|
|||
friend class MemoryManager;
|
||||
friend bool scheduleNewTask();
|
||||
|
||||
Task(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel, RetainPtr<VirtualFileSystem::Node>&& = nullptr);
|
||||
Task(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr);
|
||||
|
||||
void allocateLDT();
|
||||
|
||||
|
|
|
@ -164,7 +164,11 @@ int main(int, char**)
|
|||
printf("failed to open /dev/keyboard :(\n");
|
||||
return 1;
|
||||
}
|
||||
g->cwd = "/";
|
||||
{
|
||||
char cwdbuf[1024];
|
||||
getcwd(cwdbuf, sizeof(cwdbuf));
|
||||
g->cwd = cwdbuf;
|
||||
}
|
||||
prompt();
|
||||
for (;;) {
|
||||
char keybuf[16];
|
||||
|
@ -173,12 +177,6 @@ int main(int, char**)
|
|||
printf("failed to read :(\n");
|
||||
return 2;
|
||||
}
|
||||
if (nread > 2)
|
||||
printf("read %u bytes\n", nread);
|
||||
if (nread > (ssize_t)sizeof(keybuf)) {
|
||||
printf("read() overran the buffer i gave it!\n");
|
||||
return 3;
|
||||
}
|
||||
for (ssize_t i = 0; i < nread; ++i) {
|
||||
putchar(keybuf[i]);
|
||||
if (keybuf[i] != '\n') {
|
||||
|
|
|
@ -50,8 +50,6 @@ int FileHandle::stat(Unix::stat* buffer)
|
|||
|
||||
Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
||||
{
|
||||
LOCKER(VirtualFileSystem::lock());
|
||||
|
||||
if (!m_vnode)
|
||||
return -EBADF;
|
||||
|
||||
|
@ -94,8 +92,6 @@ Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
|||
|
||||
Unix::ssize_t FileHandle::read(byte* buffer, Unix::size_t count)
|
||||
{
|
||||
LOCKER(VirtualFileSystem::lock());
|
||||
|
||||
if (m_vnode->isCharacterDevice()) {
|
||||
// FIXME: What should happen to m_currentOffset?
|
||||
return m_vnode->characterDevice()->read(buffer, count);
|
||||
|
@ -114,8 +110,6 @@ bool FileHandle::hasDataAvailableForRead()
|
|||
|
||||
ByteBuffer FileHandle::readEntireFile()
|
||||
{
|
||||
LOCKER(VirtualFileSystem::lock());
|
||||
|
||||
if (m_vnode->isCharacterDevice()) {
|
||||
auto buffer = ByteBuffer::createUninitialized(1024);
|
||||
Unix::ssize_t nread = m_vnode->characterDevice()->read(buffer.pointer(), buffer.size());
|
||||
|
@ -133,8 +127,6 @@ bool FileHandle::isDirectory() const
|
|||
|
||||
ssize_t FileHandle::get_dir_entries(byte* buffer, Unix::size_t size)
|
||||
{
|
||||
LOCKER(VirtualFileSystem::lock());
|
||||
|
||||
auto metadata = m_vnode->metadata();
|
||||
if (!metadata.isValid())
|
||||
return -EIO;
|
||||
|
|
Loading…
Reference in a new issue