mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +00:00
Rage hacking to get bash to run. It finally runs. So cool! :^)
This commit is contained in:
parent
9b70808ab5
commit
d5d45d1088
31 changed files with 567 additions and 61 deletions
|
@ -289,7 +289,9 @@ bool MemoryManager::page_in_from_vnode(PageDirectory& page_directory, Region& re
|
|||
}
|
||||
remap_region_page(&page_directory, region, page_index_in_region, true);
|
||||
byte* dest_ptr = region.linearAddress.offset(page_index_in_region * PAGE_SIZE).asPtr();
|
||||
#ifdef MM_DEBUG
|
||||
dbgprintf("MM: page_in_from_vnode ready to read from vnode, will write to L%x!\n", dest_ptr);
|
||||
#endif
|
||||
sti(); // Oh god here we go...
|
||||
auto nread = vnode.fileSystem()->readInodeBytes(vnode.inode, vmo.vnode_offset() + ((region.first_page_index() + page_index_in_region) * PAGE_SIZE), PAGE_SIZE, dest_ptr, nullptr);
|
||||
if (nread < 0) {
|
||||
|
@ -444,7 +446,9 @@ void MemoryManager::map_region_at_address(PageDirectory* page_directory, Region&
|
|||
{
|
||||
InterruptDisabler disabler;
|
||||
auto& vmo = region.vmo();
|
||||
#ifdef MM_DEBUG
|
||||
dbgprintf("MM: map_region_at_address will map VMO pages %u - %u (VMO page count: %u)\n", region.first_page_index(), region.last_page_index(), vmo.page_count());
|
||||
#endif
|
||||
for (size_t i = region.first_page_index(); i <= region.last_page_index(); ++i) {
|
||||
auto page_laddr = laddr.offset(i * PAGE_SIZE);
|
||||
auto pte = ensurePTE(page_directory, page_laddr);
|
||||
|
|
|
@ -431,11 +431,13 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
|
|||
{
|
||||
VALIDATE_USER_READ(filename, strlen(filename));
|
||||
if (argv) {
|
||||
VALIDATE_USER_READ(argv, sizeof(const char**));
|
||||
for (size_t i = 0; argv[i]; ++i) {
|
||||
VALIDATE_USER_READ(argv[i], strlen(argv[i]));
|
||||
}
|
||||
}
|
||||
if (envp) {
|
||||
VALIDATE_USER_READ(envp, sizeof(const char**));
|
||||
for (size_t i = 0; envp[i]; ++i) {
|
||||
VALIDATE_USER_READ(envp[i], strlen(envp[i]));
|
||||
}
|
||||
|
@ -455,9 +457,8 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
|
|||
|
||||
Vector<String> environment;
|
||||
if (envp) {
|
||||
for (size_t i = 0; envp[i]; ++i) {
|
||||
for (size_t i = 0; envp[i]; ++i)
|
||||
environment.append(envp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int rc = exec(path, move(arguments), move(environment));
|
||||
|
@ -976,12 +977,9 @@ ssize_t Process::sys$write(int fd, const void* data, size_t size)
|
|||
{
|
||||
VALIDATE_USER_READ(data, size);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: called(%d, %p, %u)\n", fd, data, size);
|
||||
dbgprintf("%s(%u): sys$write(%d, %p, %u)\n", name().characters(), pid(), fd, data, size);
|
||||
#endif
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: handle=%p\n", descriptor);
|
||||
#endif
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
auto nwritten = descriptor->write((const byte*)data, size);
|
||||
|
@ -992,7 +990,7 @@ ssize_t Process::sys$write(int fd, const void* data, size_t size)
|
|||
return -EINTR;
|
||||
}
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: nwritten=%u\n", nwritten);
|
||||
dbgprintf("%s(%u) sys$write: nwritten=%u\n", name().characters(), pid(), nwritten);
|
||||
#endif
|
||||
return nwritten;
|
||||
}
|
||||
|
@ -1001,12 +999,9 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
|
|||
{
|
||||
VALIDATE_USER_WRITE(outbuf, nread);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: called(%d, %p, %u)\n", fd, outbuf, nread);
|
||||
dbgprintf("%s(%u) sys$read(%d, %p, %u)\n", name().characters(), pid(), fd, outbuf, nread);
|
||||
#endif
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: handle=%p\n", descriptor);
|
||||
#endif
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (descriptor->isBlocking()) {
|
||||
|
@ -1020,7 +1015,7 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
|
|||
}
|
||||
nread = descriptor->read((byte*)outbuf, nread);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: nread=%u\n", nread);
|
||||
dbgprintf("%s(%u) Process::sys$read: nread=%u\n", name().characters(), pid(), nread);
|
||||
#endif
|
||||
return nread;
|
||||
}
|
||||
|
@ -1042,14 +1037,27 @@ int Process::sys$access(const char* pathname, int mode)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
int Process::sys$fcntl(int fd, int cmd, dword extra_arg)
|
||||
int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||
{
|
||||
(void) cmd;
|
||||
(void) extra_arg;
|
||||
(void) arg;
|
||||
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
ASSERT_NOT_REACHED();
|
||||
switch (cmd) {
|
||||
case F_GETFD:
|
||||
return descriptor->fd_flags();
|
||||
case F_SETFD:
|
||||
return descriptor->set_fd_flags(arg);
|
||||
case F_GETFL:
|
||||
return descriptor->file_flags();
|
||||
case F_SETFL:
|
||||
return descriptor->set_file_flags(arg);
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::sys$fstat(int fd, Unix::stat* statbuf)
|
||||
|
@ -1129,7 +1137,7 @@ int Process::sys$getcwd(char* buffer, size_t size)
|
|||
if (size < path.length() + 1)
|
||||
return -ERANGE;
|
||||
strcpy(buffer, path.characters());
|
||||
return -ENOTIMPL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t Process::number_of_open_file_descriptors() const
|
||||
|
@ -1145,7 +1153,7 @@ size_t Process::number_of_open_file_descriptors() const
|
|||
int Process::sys$open(const char* path, int options)
|
||||
{
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$open(): PID=%u, path=%s {%u}\n", m_pid, path, pathLength);
|
||||
dbgprintf("%s(%u) sys$open(\"%s\")\n", name().characters(), pid(), path);
|
||||
#endif
|
||||
VALIDATE_USER_READ(path, strlen(path));
|
||||
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
|
||||
|
@ -1307,6 +1315,7 @@ void Process::reap(Process& process)
|
|||
|
||||
pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
||||
{
|
||||
//kprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
|
||||
// FIXME: Respect options
|
||||
(void) options;
|
||||
if (wstatus)
|
||||
|
@ -1314,7 +1323,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
|||
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (!Process::from_pid(waitee))
|
||||
if (waitee != -1 && !Process::from_pid(waitee))
|
||||
return -ECHILD;
|
||||
}
|
||||
m_waitee = waitee;
|
||||
|
@ -1326,7 +1335,9 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
|||
Process* waitee_process;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
waitee_process = Process::from_pid(waitee);
|
||||
|
||||
// NOTE: If waitee was -1, m_waitee will have been filled in by the scheduler.
|
||||
waitee_process = Process::from_pid(m_waitee);
|
||||
}
|
||||
ASSERT(waitee_process);
|
||||
reap(*waitee_process);
|
||||
|
@ -1471,7 +1482,12 @@ int Process::sys$tcgetattr(int fd, Unix::termios* tp)
|
|||
return -EBADF;
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
ASSERT_NOT_REACHED();
|
||||
auto& tty = *descriptor->tty();
|
||||
#ifdef TERMIOS_DEBUG
|
||||
kprintf("sys$tcgetattr(fd=%d, tp=%p)\n", fd, tp);
|
||||
#endif
|
||||
memcpy(tp, &tty.termios(), sizeof(Unix::termios));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::sys$tcsetattr(int fd, int optional_actions, const Unix::termios* tp)
|
||||
|
@ -1483,7 +1499,12 @@ int Process::sys$tcsetattr(int fd, int optional_actions, const Unix::termios* tp
|
|||
return -EBADF;
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
ASSERT_NOT_REACHED();
|
||||
#ifdef TERMIOS_DEBUG
|
||||
kprintf("sys$tcsetattr(fd=%d, tp=%p)\n", fd, tp);
|
||||
#endif
|
||||
auto& tty = *descriptor->tty();
|
||||
memcpy(&tty.termios(), tp, sizeof(Unix::termios));
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t Process::sys$tcgetpgrp(int fd)
|
||||
|
@ -1560,20 +1581,25 @@ Unix::sighandler_t Process::sys$signal(int signum, Unix::sighandler_t handler)
|
|||
|
||||
int Process::sys$sigprocmask(int how, const Unix::sigset_t* set, Unix::sigset_t* old_set)
|
||||
{
|
||||
VALIDATE_USER_READ(set, sizeof(Unix::sigset_t));
|
||||
if (old_set)
|
||||
if (old_set) {
|
||||
VALIDATE_USER_READ(old_set, sizeof(Unix::sigset_t));
|
||||
*old_set = m_signal_mask;
|
||||
switch (how) {
|
||||
case SIG_BLOCK:
|
||||
m_signal_mask &= ~(*set);
|
||||
break;
|
||||
case SIG_UNBLOCK:
|
||||
m_signal_mask |= *set;
|
||||
break;
|
||||
case SIG_SETMASK:
|
||||
m_signal_mask = *set;
|
||||
break;
|
||||
*old_set = m_signal_mask;
|
||||
}
|
||||
if (set) {
|
||||
VALIDATE_USER_READ(set, sizeof(Unix::sigset_t));
|
||||
switch (how) {
|
||||
case SIG_BLOCK:
|
||||
m_signal_mask &= ~(*set);
|
||||
break;
|
||||
case SIG_UNBLOCK:
|
||||
m_signal_mask |= *set;
|
||||
break;
|
||||
case SIG_SETMASK:
|
||||
m_signal_mask = *set;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ public:
|
|||
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
|
||||
template<typename Callback> static void for_each_in_state(State, Callback);
|
||||
template<typename Callback> static void for_each_not_in_state(State, Callback);
|
||||
template<typename Callback> void for_each_child(Callback);
|
||||
|
||||
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
||||
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
||||
|
@ -360,6 +361,21 @@ inline void Process::for_each(Callback callback)
|
|||
}
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
inline void Process::for_each_child(Callback callback)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
pid_t my_pid = pid();
|
||||
for (auto* process = g_processes->head(); process;) {
|
||||
auto* next_process = process->next();
|
||||
if (process->ppid() == my_pid) {
|
||||
if (!callback(*process))
|
||||
break;
|
||||
}
|
||||
process = next_process;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
inline void Process::for_each_in_pgrp(pid_t pgid, Callback callback)
|
||||
{
|
||||
|
|
|
@ -35,15 +35,17 @@ bool Scheduler::pick_next()
|
|||
}
|
||||
|
||||
if (process.state() == Process::BlockedWait) {
|
||||
auto* waitee = Process::from_pid(process.waitee());
|
||||
if (!waitee) {
|
||||
kprintf("waitee %u of %s(%u) reaped before I could wait?\n", process.waitee(), process.name().characters(), process.pid());
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
if (waitee->state() == Process::Dead) {
|
||||
process.m_waitee_status = (waitee->m_termination_status << 8) | waitee->m_termination_signal;
|
||||
process.unblock();
|
||||
}
|
||||
process.for_each_child([&process] (Process& child) {
|
||||
if (child.state() != Process::Dead)
|
||||
return true;
|
||||
if (process.waitee() == -1 || process.waitee() == child.pid()) {
|
||||
process.m_waitee_status = (child.m_termination_status << 8) | child.m_termination_signal;
|
||||
process.m_waitee = child.pid();
|
||||
process.unblock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
TTY::TTY(unsigned major, unsigned minor)
|
||||
: CharacterDevice(major, minor)
|
||||
{
|
||||
memset(&m_termios, 0, sizeof(m_termios));
|
||||
m_termios.c_lflag |= ISIG | ECHO;
|
||||
}
|
||||
|
||||
TTY::~TTY()
|
||||
|
@ -42,6 +44,8 @@ void TTY::emit(byte ch)
|
|||
|
||||
void TTY::interrupt()
|
||||
{
|
||||
if (!should_generate_signals())
|
||||
return;
|
||||
dbgprintf("%s: Interrupt ^C pressed!\n", ttyName().characters());
|
||||
if (pgid()) {
|
||||
dbgprintf("%s: Send SIGINT to everyone in pgrp %d\n", ttyName().characters(), pgid());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <VirtualFileSystem/CharacterDevice.h>
|
||||
#include <VirtualFileSystem/UnixTypes.h>
|
||||
|
||||
class TTY : public CharacterDevice {
|
||||
public:
|
||||
|
@ -15,6 +16,10 @@ public:
|
|||
void set_pgid(pid_t pgid) { m_pgid = pgid; }
|
||||
pid_t pgid() const { return m_pgid; }
|
||||
|
||||
Unix::termios& termios() { return m_termios; }
|
||||
bool should_generate_signals() const { return m_termios.c_lflag & ISIG; }
|
||||
bool should_echo_input() const { return m_termios.c_lflag & ECHO; }
|
||||
|
||||
protected:
|
||||
virtual bool isTTY() const final override { return true; }
|
||||
|
||||
|
@ -28,5 +33,6 @@ protected:
|
|||
private:
|
||||
Vector<byte> m_buffer;
|
||||
pid_t m_pgid { 0 };
|
||||
Unix::termios m_termios;
|
||||
};
|
||||
|
||||
|
|
|
@ -261,6 +261,17 @@ void VirtualConsole::escape$H(const Vector<unsigned>& params)
|
|||
set_cursor(row - 1, col - 1);
|
||||
}
|
||||
|
||||
void VirtualConsole::escape$A(const Vector<unsigned>& params)
|
||||
{
|
||||
int num = 1;
|
||||
if (params.size() >= 1)
|
||||
num = params[0];
|
||||
int new_row = (int)m_cursor_row - num;
|
||||
if (new_row < 0)
|
||||
new_row = 0;
|
||||
set_cursor(new_row, m_cursor_column);
|
||||
}
|
||||
|
||||
void VirtualConsole::escape$J(const Vector<unsigned>& params)
|
||||
{
|
||||
int mode = 0;
|
||||
|
|
|
@ -40,6 +40,7 @@ private:
|
|||
void set_cursor(unsigned row, unsigned column);
|
||||
void put_character_at(unsigned row, unsigned column, byte ch);
|
||||
|
||||
void escape$A(const Vector<unsigned>&);
|
||||
void escape$H(const Vector<unsigned>&);
|
||||
void escape$J(const Vector<unsigned>&);
|
||||
void escape$m(const Vector<unsigned>&);
|
||||
|
|
|
@ -239,8 +239,11 @@ static void init_stage2()
|
|||
}
|
||||
#endif
|
||||
|
||||
Vector<String> environment;
|
||||
environment.append("TERM=ansi");
|
||||
|
||||
int error;
|
||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, Vector<String>(), Vector<String>(), tty0);
|
||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, Vector<String>(), move(environment), tty0);
|
||||
#ifdef SPAWN_MULTIPLE_SHELLS
|
||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, Vector<String>(), Vector<String>(), tty1);
|
||||
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, Vector<String>(), Vector<String>(), tty2);
|
||||
|
|
|
@ -5,3 +5,6 @@ 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
|
||||
|
||||
cp ../../bash-1.14.7/bash2 mnt/bin/bash
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue