mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:57:35 +00:00
Enough compatibility work to make figlet build and run!
I ran out of steam writing library routines and imported two BSD-licensed libc routines: sscanf() and getopt(). I will most likely rewrite them sooner or later. For now I just wanted to see figlet running.
This commit is contained in:
parent
69c7a59e6f
commit
819ce91395
22 changed files with 714 additions and 36 deletions
|
@ -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)));
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
7
Kernel/sync-local.sh
Executable file
7
Kernel/sync-local.sh
Executable file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue