mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:47:41 +00:00
Remove age-old IPC stuff that wasn't working anyway.
I'll make a fresh start with IPC code when I get there.
This commit is contained in:
parent
ce126120d1
commit
de7c54545a
7 changed files with 6 additions and 242 deletions
|
@ -1,6 +1,5 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
#include "IPC.h"
|
|
||||||
#include "VGA.h"
|
#include "VGA.h"
|
||||||
#include "Disk.h"
|
#include "Disk.h"
|
||||||
#include "kmalloc.h"
|
#include "kmalloc.h"
|
||||||
|
|
104
Kernel/IPC.cpp
104
Kernel/IPC.cpp
|
@ -1,104 +0,0 @@
|
||||||
#include "IPC.h"
|
|
||||||
#include "Task.h"
|
|
||||||
#include "i386.h"
|
|
||||||
#include "StdLib.h"
|
|
||||||
#include "VGA.h"
|
|
||||||
#include "system.h"
|
|
||||||
|
|
||||||
namespace IPC {
|
|
||||||
|
|
||||||
Message receive(Handle src)
|
|
||||||
{
|
|
||||||
for (;;) {
|
|
||||||
current->ipc.src = src;
|
|
||||||
block(Task::BlockedReceive);
|
|
||||||
if (src == Handle::Any && current->ipc.notifies) {
|
|
||||||
for (BYTE i = 0; i < 32; ++i) {
|
|
||||||
if (current->ipc.notifies & (1 << i)) {
|
|
||||||
// FIXME: Source PID is `i' here. Do something with it?
|
|
||||||
current->ipc.notifies &= ~(1 << i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Message(MSG_NOTIFY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src == Handle::Any || src == current->ipc.msg.sender()) {
|
|
||||||
return move(current->ipc.msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Why are we here?
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(Handle dst, Message&& msg)
|
|
||||||
{
|
|
||||||
Task* task;
|
|
||||||
|
|
||||||
// TODO: Block waiting for `dst' to spawn.
|
|
||||||
for (;;) {
|
|
||||||
task = Task::fromIPCHandle(dst);
|
|
||||||
if (task)
|
|
||||||
break;
|
|
||||||
yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
// I'll fill this in myself thankyouverymuch.
|
|
||||||
msg.setSender(current->handle());
|
|
||||||
|
|
||||||
// Block until `dst' is ready to receive a message.
|
|
||||||
current->ipc.dst = dst;
|
|
||||||
block(Task::BlockedSend);
|
|
||||||
|
|
||||||
ASSERT(msg.isValid());
|
|
||||||
task->ipc.msg = move(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify(Handle dst)
|
|
||||||
{
|
|
||||||
Task* task = Task::fromIPCHandle(dst);
|
|
||||||
|
|
||||||
if (!task) {
|
|
||||||
// Can't really block here since we might be coming from
|
|
||||||
// an interrupt handler and that'd be devastating...
|
|
||||||
// XXX: Need to figure that one out.
|
|
||||||
kprintf("notify(): no such task %u\n", dst.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current->pid() >= 32) {
|
|
||||||
kprintf( "notify(): PID must be < 32\n" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
task->ipc.notifies |= 1 << current->pid();
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::Message(Message&& other)
|
|
||||||
: m_data(move(other.m_data))
|
|
||||||
, m_type(other.m_type)
|
|
||||||
, m_sender(other.m_sender)
|
|
||||||
, m_isValid(other.m_isValid)
|
|
||||||
{
|
|
||||||
other.m_type = 0;
|
|
||||||
other.m_sender = Handle();
|
|
||||||
other.m_isValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message& Message::operator=(Message&& other)
|
|
||||||
{
|
|
||||||
if (this == &other)
|
|
||||||
return *this;
|
|
||||||
m_data = move(other.m_data);
|
|
||||||
m_type = other.m_type;
|
|
||||||
m_sender = other.m_sender;
|
|
||||||
m_isValid = other.m_isValid;
|
|
||||||
other.m_type = 0;
|
|
||||||
other.m_sender = Handle();
|
|
||||||
other.m_isValid = false;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
82
Kernel/IPC.h
82
Kernel/IPC.h
|
@ -1,82 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "DataBuffer.h"
|
|
||||||
#include "RefPtr.h"
|
|
||||||
#include <AK/StdLib.h>
|
|
||||||
|
|
||||||
/* IPC message types. There will be moar. */
|
|
||||||
#define MSG_INTERRUPT 0x00000001
|
|
||||||
#define MSG_KILL 0x00000002
|
|
||||||
#define MSG_NOTIFY 0x00000003
|
|
||||||
|
|
||||||
#define DEV_READ 0x00000004
|
|
||||||
|
|
||||||
#define FS_OPEN 0x00000100
|
|
||||||
#define FS_CLOSE 0x00000101
|
|
||||||
#define FS_READ 0x00000102
|
|
||||||
|
|
||||||
#define SYS_KILL 0x00000666
|
|
||||||
|
|
||||||
namespace IPC {
|
|
||||||
|
|
||||||
class Handle {
|
|
||||||
public:
|
|
||||||
// If Handle::Any is passed as the `src' parameter of receive(),
|
|
||||||
// any process can send us a message.
|
|
||||||
enum AnyHandle { Any };
|
|
||||||
Handle(AnyHandle) : m_data(0xffffffff) { }
|
|
||||||
|
|
||||||
enum KernelTask {
|
|
||||||
DiskTask = 4002,
|
|
||||||
FileSystemTask = 4003,
|
|
||||||
MotdTask = 4004,
|
|
||||||
UserTask = 4005,
|
|
||||||
InitTask = 4006,
|
|
||||||
};
|
|
||||||
Handle(KernelTask task) : m_data((DWORD)task) { }
|
|
||||||
|
|
||||||
Handle() { }
|
|
||||||
explicit Handle(DWORD data) : m_data(data) { }
|
|
||||||
|
|
||||||
DWORD data() const { return m_data; }
|
|
||||||
bool operator==(const Handle& o) const { return m_data == o.m_data; }
|
|
||||||
bool operator!=(const Handle& o) const { return m_data != o.m_data; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
DWORD m_data { 0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
class Message {
|
|
||||||
public:
|
|
||||||
Message() { }
|
|
||||||
explicit Message(DWORD type) : m_type(type), m_isValid(true) { }
|
|
||||||
Message(DWORD type, RefPtr<DataBuffer>&& d) : m_data(move(d)), m_type(type), m_isValid(true) { }
|
|
||||||
Message(Message&&);
|
|
||||||
Message& operator=(Message&&);
|
|
||||||
|
|
||||||
size_t length() const { return m_data ? m_data->length() : 0; }
|
|
||||||
const BYTE* data() const { return m_data ? m_data->data() : nullptr; }
|
|
||||||
BYTE* data() { return m_data ? m_data->data() : nullptr; }
|
|
||||||
|
|
||||||
bool isValid() const { return m_isValid; }
|
|
||||||
|
|
||||||
DWORD type() const { return m_type; }
|
|
||||||
Handle sender() const { return m_sender; }
|
|
||||||
|
|
||||||
void setType(DWORD t) { m_type = t; }
|
|
||||||
void setSender(Handle s) { m_sender = s; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
RefPtr<DataBuffer> m_data;
|
|
||||||
DWORD m_type { 0 };
|
|
||||||
Handle m_sender;
|
|
||||||
bool m_isValid { false };
|
|
||||||
};
|
|
||||||
|
|
||||||
Message receive(Handle);
|
|
||||||
void send(Handle, Message&&);
|
|
||||||
void notify(Handle);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ KERNEL_OBJS = \
|
||||||
Task.o \
|
Task.o \
|
||||||
i8253.o \
|
i8253.o \
|
||||||
Keyboard.o \
|
Keyboard.o \
|
||||||
IPC.o \
|
|
||||||
CMOS.o \
|
CMOS.o \
|
||||||
IO.o \
|
IO.o \
|
||||||
PIC.o \
|
PIC.o \
|
||||||
|
|
|
@ -57,7 +57,7 @@ void Task::initialize()
|
||||||
next_pid = 0;
|
next_pid = 0;
|
||||||
s_tasks = new InlineLinkedList<Task>;
|
s_tasks = new InlineLinkedList<Task>;
|
||||||
s_deadTasks = new InlineLinkedList<Task>;
|
s_deadTasks = new InlineLinkedList<Task>;
|
||||||
s_kernelTask = new Task(0, "colonel", IPC::Handle::Any, Task::Ring0);
|
s_kernelTask = new Task(0, "colonel", Task::Ring0);
|
||||||
redoKernelTaskTSS();
|
redoKernelTaskTSS();
|
||||||
loadTaskRegister(s_kernelTask->selector());
|
loadTaskRegister(s_kernelTask->selector());
|
||||||
}
|
}
|
||||||
|
@ -285,11 +285,10 @@ Task::Task(String&& name, uid_t uid, gid_t gid, pid_t parentPID)
|
||||||
ASSERT(m_pid);
|
ASSERT(m_pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::Task(void (*e)(), const char* n, IPC::Handle h, RingLevel ring)
|
Task::Task(void (*e)(), const char* n, RingLevel ring)
|
||||||
: m_name(n)
|
: m_name(n)
|
||||||
, m_entry(e)
|
, m_entry(e)
|
||||||
, m_pid(next_pid++)
|
, m_pid(next_pid++)
|
||||||
, m_handle(h)
|
|
||||||
, m_state(Runnable)
|
, m_state(Runnable)
|
||||||
, m_ring(ring)
|
, m_ring(ring)
|
||||||
{
|
{
|
||||||
|
@ -518,19 +517,6 @@ bool scheduleNewTask()
|
||||||
|
|
||||||
// Check and unblock tasks whose wait conditions have been met.
|
// Check and unblock tasks whose wait conditions have been met.
|
||||||
for (auto* task = s_tasks->head(); task; task = task->next()) {
|
for (auto* task = s_tasks->head(); task; task = task->next()) {
|
||||||
if (task->state() == Task::BlockedReceive && (task->ipc.msg.isValid() || task->ipc.notifies)) {
|
|
||||||
task->unblock();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task->state() == Task::BlockedSend) {
|
|
||||||
Task* peer = Task::fromIPCHandle(task->ipc.dst);
|
|
||||||
if (peer && peer->state() == Task::BlockedReceive && peer->acceptsMessageFrom(*task)) {
|
|
||||||
task->unblock();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task->state() == Task::BlockedSleep) {
|
if (task->state() == Task::BlockedSleep) {
|
||||||
if (task->wakeupTime() <= system.uptime) {
|
if (task->wakeupTime() <= system.uptime) {
|
||||||
task->unblock();
|
task->unblock();
|
||||||
|
@ -647,15 +633,6 @@ Task* Task::fromPID(pid_t pid)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task* Task::fromIPCHandle(IPC::Handle handle)
|
|
||||||
{
|
|
||||||
for (auto* task = s_tasks->head(); task; task = task->next()) {
|
|
||||||
if (task->handle() == handle)
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileHandle* Task::fileHandleIfExists(int fd)
|
FileHandle* Task::fileHandleIfExists(int fd)
|
||||||
{
|
{
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -780,11 +757,6 @@ int Task::sys$kill(pid_t pid, int sig)
|
||||||
// errno = ESRCH;
|
// errno = ESRCH;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
send(peer->handle(), IPC::Message(SYS_KILL, DataBuffer::copy((BYTE*)&sig, sizeof(sig))));
|
|
||||||
IPC::Message response = receive(peer->handle());
|
|
||||||
return *(int*)response.data();
|
|
||||||
#endif
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,11 +786,6 @@ pid_t Task::sys$waitpid(pid_t waitee)
|
||||||
return m_waitee;
|
return m_waitee;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Task::acceptsMessageFrom(Task& peer)
|
|
||||||
{
|
|
||||||
return !ipc.msg.isValid() && (ipc.src == IPC::Handle::Any || ipc.src == peer.handle());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Task::unblock()
|
void Task::unblock()
|
||||||
{
|
{
|
||||||
ASSERT(m_state != Task::Runnable && m_state != Task::Running);
|
ASSERT(m_state != Task::Runnable && m_state != Task::Running);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "IPC.h"
|
|
||||||
#include "InlineLinkedList.h"
|
#include "InlineLinkedList.h"
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include "TSS.h"
|
#include "TSS.h"
|
||||||
|
@ -48,10 +47,9 @@ public:
|
||||||
bool isRing0() const { return m_ring == Ring0; }
|
bool isRing0() const { return m_ring == Ring0; }
|
||||||
|
|
||||||
static Task* fromPID(pid_t);
|
static Task* fromPID(pid_t);
|
||||||
static Task* fromIPCHandle(IPC::Handle);
|
|
||||||
static Task* kernelTask();
|
static Task* kernelTask();
|
||||||
|
|
||||||
Task(void (*entry)(), const char* name, IPC::Handle, RingLevel);
|
Task(void (*entry)(), const char* name, RingLevel);
|
||||||
~Task();
|
~Task();
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
|
@ -60,7 +58,6 @@ public:
|
||||||
WORD selector() const { return m_farPtr.selector; }
|
WORD selector() const { return m_farPtr.selector; }
|
||||||
TSS32& tss() { return m_tss; }
|
TSS32& tss() { return m_tss; }
|
||||||
State state() const { return m_state; }
|
State state() const { return m_state; }
|
||||||
IPC::Handle handle() const { return m_handle; }
|
|
||||||
uid_t uid() const { return m_uid; }
|
uid_t uid() const { return m_uid; }
|
||||||
uid_t gid() const { return m_gid; }
|
uid_t gid() const { return m_gid; }
|
||||||
|
|
||||||
|
@ -72,8 +69,6 @@ public:
|
||||||
|
|
||||||
static void doHouseKeeping();
|
static void doHouseKeeping();
|
||||||
|
|
||||||
bool acceptsMessageFrom(Task&);
|
|
||||||
|
|
||||||
void block(Task::State);
|
void block(Task::State);
|
||||||
void unblock();
|
void unblock();
|
||||||
|
|
||||||
|
@ -107,14 +102,6 @@ public:
|
||||||
int sys$get_dir_entries(int fd, void*, size_t);
|
int sys$get_dir_entries(int fd, void*, size_t);
|
||||||
int sys$getcwd(char*, size_t);
|
int sys$getcwd(char*, size_t);
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
IPC::Message msg;
|
|
||||||
IPC::Handle dst;
|
|
||||||
IPC::Handle src;
|
|
||||||
DWORD notifies { 0 };
|
|
||||||
} ipc;
|
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
void setError(int);
|
void setError(int);
|
||||||
|
|
||||||
|
@ -146,7 +133,6 @@ private:
|
||||||
gid_t m_gid { 0 };
|
gid_t m_gid { 0 };
|
||||||
DWORD m_ticks { 0 };
|
DWORD m_ticks { 0 };
|
||||||
DWORD m_ticksLeft { 0 };
|
DWORD m_ticksLeft { 0 };
|
||||||
IPC::Handle m_handle { 0 };
|
|
||||||
DWORD m_stackTop { 0 };
|
DWORD m_stackTop { 0 };
|
||||||
FarPtr m_farPtr;
|
FarPtr m_farPtr;
|
||||||
State m_state { Invalid };
|
State m_state { Invalid };
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "i8253.h"
|
#include "i8253.h"
|
||||||
#include "Keyboard.h"
|
#include "Keyboard.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
#include "IPC.h"
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "Disk.h"
|
#include "Disk.h"
|
||||||
#include "PIC.h"
|
#include "PIC.h"
|
||||||
|
@ -115,7 +114,7 @@ static void init_stage2()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TEST_CRASHY_USER_PROCESSES
|
#ifdef TEST_CRASHY_USER_PROCESSES
|
||||||
new Task(user_main, "user", IPC::Handle::UserTask, Task::Ring3);
|
new Task(user_main, "user", Task::Ring3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TEST_ELF_LOADER
|
#ifdef TEST_ELF_LOADER
|
||||||
|
@ -197,9 +196,9 @@ void init()
|
||||||
|
|
||||||
Task::initialize();
|
Task::initialize();
|
||||||
|
|
||||||
new Task(undertaker_main, "undertaker", IPC::Handle::UserTask, Task::Ring0);
|
new Task(undertaker_main, "undertaker", Task::Ring0);
|
||||||
|
|
||||||
auto* init2 = new Task(init_stage2, "init", IPC::Handle::InitTask, Task::Ring0);
|
auto* init2 = new Task(init_stage2, "init", Task::Ring0);
|
||||||
scheduleNewTask();
|
scheduleNewTask();
|
||||||
|
|
||||||
sti();
|
sti();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue