diff options
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/MemoryManager.cpp | 3 | ||||
-rw-r--r-- | Kernel/Syscall.cpp | 8 | ||||
-rw-r--r-- | Kernel/Syscall.h | 3 | ||||
-rw-r--r-- | Kernel/Task.cpp | 41 | ||||
-rw-r--r-- | Kernel/Task.h | 4 | ||||
-rwxr-xr-x | Kernel/sync-local.sh | 7 | ||||
-rwxr-xr-x | Kernel/sync-sh | 1 |
7 files changed, 55 insertions, 12 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index c22e8b3e0e..9a23f9da56 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -41,7 +41,6 @@ void MemoryManager::initializePaging() identityMap(LinearAddress(4096), 4 * MB); - // Put pages between 4MB and 8MB in the page freelist. for (size_t i = (4 * MB) + PAGE_SIZE; i < (8 * MB); i += PAGE_SIZE) { m_freePages.append(PhysicalAddress(i)); } @@ -170,7 +169,7 @@ RetainPtr<Zone> MemoryManager::createZone(size_t size) InterruptDisabler disabler; auto pages = allocatePhysicalPages(ceilDiv(size, PAGE_SIZE)); if (pages.isEmpty()) { - kprintf("[MM] createZone: no physical pages for size %u", size); + kprintf("[MM] createZone: no physical pages for size %u\n", size); return nullptr; } return adopt(*new Zone(move(pages))); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 67b0ff992c..d84c1642aa 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -77,10 +77,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3) case Syscall::PosixRead: //kprintf("syscall: read(%d, %p, %u)\n", arg1, arg2, arg3); return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3); - case Syscall::PosixSeek: - // FIXME: This has the wrong signature, should be like lseek() - kprintf("syscall: seek(%d, %d)\n", arg1, arg2); - return current->sys$seek((int)arg1, (int)arg2); + case Syscall::PosixLseek: + return current->sys$lseek((int)arg1, (off_t)arg2, (int)arg3); case Syscall::PosixKill: return current->sys$kill((pid_t)arg1, (int)arg2); case Syscall::PosixGetuid: @@ -104,6 +102,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3) return 0; case Syscall::GetArguments: return current->sys$get_arguments((int*)arg1, (char***)arg2); + case Syscall::GetEnvironment: + return current->sys$get_environment((char***)arg1); case Syscall::PosixChdir: return current->sys$chdir((const char*)arg1); case Syscall::PosixUname: diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 9f0d8de243..1e952d8598 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -17,7 +17,7 @@ enum Function { PosixOpen = 0x1985, PosixClose = 0x1986, PosixRead = 0x1987, - PosixSeek = 0x1988, + PosixLseek = 0x1988, PosixKill = 0x1989, PosixGetuid = 0x1990, PosixExit = 0x1991, @@ -39,6 +39,7 @@ enum Function { PosixWrite = 0x2007, PosixTtynameR = 0x2008, PosixStat = 0x2009, + GetEnvironment = 0x2010, }; void initialize(); diff --git a/Kernel/Task.cpp b/Kernel/Task.cpp index 07f9f8cc77..8d26e9c02c 100644 --- a/Kernel/Task.cpp +++ b/Kernel/Task.cpp @@ -182,6 +182,7 @@ int Task::sys$set_mmap_name(void* addr, size_t size, const char* name) void* Task::sys$mmap(void* addr, size_t size) { + InterruptDisabler disabler; // FIXME: Implement mapping at a client-preferred address. ASSERT(addr == nullptr); auto* region = allocateRegion(size, "mmap"); @@ -193,6 +194,7 @@ void* Task::sys$mmap(void* addr, size_t size) int Task::sys$munmap(void* addr, size_t size) { + InterruptDisabler disabler; auto* region = regionFromRange(LinearAddress((dword)addr), size); if (!region) return -1; @@ -213,6 +215,12 @@ int Task::sys$gethostname(char* buffer, size_t size) int Task::sys$spawn(const char* path, const char** args) { + if (args) { + for (size_t i = 0; args[i]; ++i) { + VALIDATE_USER_BUFFER(args[i], strlen(args[i])); + } + } + int error = 0; auto* child = Task::createUserTask(path, m_uid, m_gid, m_pid, error, args, m_tty); if (child) @@ -261,10 +269,17 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren taskArguments.append(parts.last()); } + Vector<String> taskEnvironment; + taskEnvironment.append("PATH=/bin"); + taskEnvironment.append("SHELL=/bin/sh"); + taskEnvironment.append("TERM=console"); + taskEnvironment.append("HOME=/"); + InterruptDisabler disabler; // FIXME: Get rid of this, jesus christ. This "critical" section is HUGE. Task* t = new Task(parts.takeLast(), uid, gid, parentPID, Ring3, move(cwd), handle->vnode(), tty); t->m_arguments = move(taskArguments); + t->m_initialEnvironment = move(taskEnvironment); ExecSpace space; Region* region = nullptr; @@ -322,11 +337,29 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren #ifdef TASK_DEBUG kprintf("Task %u (%s) spawned @ %p\n", t->pid(), t->name().characters(), t->m_tss.eip); #endif - error = 0; return t; } +int Task::sys$get_environment(char*** environ) +{ + auto* region = allocateRegion(4096, "environ"); + if (!region) + return -ENOMEM; + MM.mapRegion(*this, *region); + char* envpage = (char*)region->linearAddress.get(); + *environ = (char**)envpage; + char* bufptr = envpage + (sizeof(char*) * (m_initialEnvironment.size() + 1)); + for (size_t i = 0; i < m_initialEnvironment.size(); ++i) { + (*environ)[i] = bufptr; + memcpy(bufptr, m_initialEnvironment[i].characters(), m_initialEnvironment[i].length()); + bufptr += m_initialEnvironment[i].length(); + *(bufptr++) = '\0'; + } + (*environ)[m_initialEnvironment.size()] = nullptr; + return 0; +} + int Task::sys$get_arguments(int* argc, char*** argv) { auto* region = allocateRegion(4096, "argv"); @@ -763,12 +796,12 @@ ssize_t Task::sys$get_dir_entries(int fd, void* buffer, size_t size) return handle->get_dir_entries((byte*)buffer, size); } -int Task::sys$seek(int fd, int offset) +int Task::sys$lseek(int fd, off_t offset, int whence) { auto* handle = fileHandleIfExists(fd); if (!handle) - return -1; - return handle->seek(offset, SEEK_SET); + return -EBADF; + return handle->seek(offset, whence); } int Task::sys$ttyname_r(int fd, char* buffer, size_t size) diff --git a/Kernel/Task.h b/Kernel/Task.h index c86b501792..8f7e77716c 100644 --- a/Kernel/Task.h +++ b/Kernel/Task.h @@ -94,7 +94,7 @@ public: ssize_t sys$write(int fd, const void*, size_t); int sys$lstat(const char*, Unix::stat*); int sys$stat(const char*, Unix::stat*); - int sys$seek(int fd, int offset); + int sys$lseek(int fd, off_t, int whence); int sys$kill(pid_t pid, int sig); int sys$geterror() { return m_error; } void sys$exit(int status); @@ -110,6 +110,7 @@ public: int sys$gettimeofday(timeval*); int sys$gethostname(char* name, size_t length); int sys$get_arguments(int* argc, char*** argv); + int sys$get_environment(char*** environ); int sys$uname(utsname*); int sys$readlink(const char*, char*, size_t); int sys$ttyname_r(int fd, char*, size_t); @@ -220,6 +221,7 @@ private: void murder(); Vector<String> m_arguments; + Vector<String> m_initialEnvironment; }; extern void task_init(); diff --git a/Kernel/sync-local.sh b/Kernel/sync-local.sh new file mode 100755 index 0000000000..ee67768785 --- /dev/null +++ b/Kernel/sync-local.sh @@ -0,0 +1,7 @@ +cp ../../figlet-2.2.5/figlet mnt/bin/ +mkdir -p mnt/usr/local/share/figlet +FIGLET_FONTDIR=/ +cp ../../figlet-2.2.5/fonts/standard.flf mnt/$FIGLET_FONTDIR +cp ../../figlet-2.2.5/fonts/big.flf mnt/$FIGLET_FONTDIR +cp ../../figlet-2.2.5/fonts/slant.flf mnt/$FIGLET_FONTDIR +cp ../../figlet-2.2.5/fonts/lean.flf mnt/$FIGLET_FONTDIR diff --git a/Kernel/sync-sh b/Kernel/sync-sh index d455f52f31..99855924a2 100755 --- a/Kernel/sync-sh +++ b/Kernel/sync-sh @@ -17,6 +17,7 @@ cp ../Userland/clear mnt/bin/clear cp ../Userland/tst mnt/bin/tst cp ../Userland/mm mnt/bin/mm cp ../Userland/kill mnt/bin/kill +sh sync-local.sh cp kernel.map mnt/ umount mnt sync |