1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +00:00

Lots of hacking to make a very simple "ls" utility.

I added a dead-simple malloc that only allows allocations < 4096 bytes.
It just forwards the request to mmap() every time.

I also added simplified versions of opendir() and readdir().
This commit is contained in:
Andreas Kling 2018-10-24 12:43:52 +02:00
parent 0c5bbac86e
commit bca4b71bfa
19 changed files with 277 additions and 67 deletions

View file

@ -21,17 +21,18 @@ bool ProcFileSystem::initialize()
InterruptDisabler disabler;
auto tasks = Task::allTasks();
char* buffer;
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 128, buffer);
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
ptr += ksprintf(ptr, "PID OWNER STATE NSCHED NAME\n");
ptr += ksprintf(ptr, "PID OWNER STATE NSCHED FDS NAME\n");
for (auto* task : tasks) {
ptr += ksprintf(ptr, "%w %w:%w %b %w %s\n",
ptr += ksprintf(ptr, "%w %w:%w %b %w %w %s\n",
task->pid(),
task->uid(),
task->gid(),
task->state(),
task->timesScheduled(),
task->fileHandleCount(),
task->name().characters());
}
ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);

View file

@ -66,6 +66,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
break;
case Syscall::Spawn:
return current->sys$spawn((const char*)arg1);
case Syscall::GetDirEntries:
return current->sys$get_dir_entries((int)arg1, (void*)arg2, (size_t)arg3);
case Syscall::PosixOpen:
//kprintf("syscall: open('%s', %u)\n", arg1, arg2);
return current->sys$open((const char*)arg1, (size_t)arg2);

View file

@ -26,6 +26,7 @@ enum Function {
PosixWaitpid = 0x1994,
PosixMmap = 0x1995,
PosixMunmap = 0x1996,
GetDirEntries = 0x1997,
};
void initialize();

View file

@ -230,6 +230,10 @@ Task::Task(String&& name, uid_t uid, gid_t gid)
, m_state(Runnable)
, m_ring(Ring3)
{
m_fileHandles.append(nullptr);
m_fileHandles.append(nullptr);
m_fileHandles.append(nullptr);
m_nextRegion = LinearAddress(0x600000);
memset(&m_tss, 0, sizeof(m_tss));
@ -280,6 +284,10 @@ Task::Task(void (*e)(), const char* n, IPC::Handle h, RingLevel ring)
, m_state(Runnable)
, m_ring(ring)
{
m_fileHandles.append(nullptr);
m_fileHandles.append(nullptr);
m_fileHandles.append(nullptr);
m_nextRegion = LinearAddress(0x600000);
Region* codeRegion = nullptr;
@ -643,6 +651,14 @@ FileHandle* Task::fileHandleIfExists(int fd)
return nullptr;
}
ssize_t Task::sys$get_dir_entries(int fd, void* buffer, size_t size)
{
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -1;
return handle->get_dir_entries((byte*)buffer, size);
}
int Task::sys$seek(int fd, int offset)
{
auto* handle = fileHandleIfExists(fd);

View file

@ -101,6 +101,7 @@ public:
pid_t sys$waitpid(pid_t);
void* sys$mmap(void*, size_t size);
int sys$munmap(void*, size_t size);
int sys$get_dir_entries(int fd, void*, size_t);
struct
{
@ -122,6 +123,8 @@ public:
pid_t waitee() const { return m_waitee; }
size_t fileHandleCount() const { return m_fileHandles.size(); }
private:
friend class MemoryManager;

Binary file not shown.