20 #include "pedigree/kernel/Log.h" 21 #include "pedigree/kernel/process/Scheduler.h" 22 #include "pedigree/kernel/processor/Processor.h" 23 #include "pedigree/kernel/processor/SyscallManager.h" 24 #include "pedigree/kernel/processor/state.h" 26 #include "pedigree/native/ipc/Ipc.h" 27 #include <native-ipc.h> 29 #include "NativeSyscallManager.h" 30 #include "pedigree/native/nativeSyscallNumbers.h" 36 syscall(uint64_t subid,
void *params,
size_t params_size);
47 void NativeSyscallManager::initialise()
53 uintptr_t
function, uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4,
56 if (
function >= serviceEnd)
59 "NativeSyscallManager: invalid function called: " 60 <<
Dec << static_cast<int>(
function));
65 native,
function, p1, p2, p3, p4, p5);
71 uintptr_t p1 = state.getSyscallParameter(0);
72 uintptr_t p2 = state.getSyscallParameter(1);
73 uintptr_t p3 = state.getSyscallParameter(2);
74 uintptr_t p4 = state.getSyscallParameter(3);
75 uintptr_t p5 = state.getSyscallParameter(4);
83 switch (state.getSyscallNumber())
85 case IPC_CREATE_STANDARD_MESSAGE:
86 return createStandardMessage(
87 reinterpret_cast<PedigreeIpc::IpcMessage *>(p1));
88 case IPC_CREATE_SHARED_MESSAGE:
89 return createSharedMessage(
90 reinterpret_cast<PedigreeIpc::IpcMessage *>(p1), p2, p3);
91 case IPC_GET_SHARED_REGION:
92 return reinterpret_cast<uintptr_t
>(getIpcSharedRegion(
93 reinterpret_cast<PedigreeIpc::IpcMessage *>(p1)));
94 case IPC_DESTROY_MESSAGE:
95 destroyMessage(reinterpret_cast<PedigreeIpc::IpcMessage *>(p1));
99 return static_cast<uintptr_t
>(sendIpc(
100 reinterpret_cast<PedigreeIpc::IpcEndpoint *>(p1),
101 reinterpret_cast<PedigreeIpc::IpcMessage *>(p2),
102 static_cast<bool>(p3)));
103 case IPC_RECV_PHASE1:
104 return reinterpret_cast<uintptr_t
>(recvIpcPhase1(
105 reinterpret_cast<PedigreeIpc::IpcEndpoint *>(p1),
106 static_cast<bool>(p2)));
107 case IPC_RECV_PHASE2:
108 return recvIpcPhase2(
109 reinterpret_cast<PedigreeIpc::IpcMessage *>(p1),
110 reinterpret_cast<void *>(p2));
112 case IPC_CREATE_ENDPOINT:
113 createEndpoint(reinterpret_cast<const char *>(p1));
115 case IPC_REMOVE_ENDPOINT:
116 removeEndpoint(reinterpret_cast<const char *>(p1));
118 case IPC_GET_ENDPOINT:
119 return reinterpret_cast<uintptr_t
>(
120 getEndpoint(reinterpret_cast<const char *>(p1)));
123 case NATIVE_REGISTER_OBJECT:
124 NOTICE(
"NativeSyscallManager: register object");
127 void *ptr =
reinterpret_cast<void *
>(p2);
132 m_NativeObjects.insert(ptr, kptr);
138 case NATIVE_UNREGISTER_OBJECT:
139 NOTICE(
"NativeSyscallManager: unregister object");
141 void *ptr =
reinterpret_cast<void *
>(p1);
142 NativeBase *kptr = m_NativeObjects.lookup(ptr);
146 m_NativeObjects.remove(ptr);
151 NOTICE(
"NativeSyscallManager: call");
153 void *ptr =
reinterpret_cast<void *
>(p1);
155 void *params =
reinterpret_cast<void *
>(p3);
156 size_t params_size = p4;
162 NativeBase *kptr = m_NativeObjects.lookup(ptr);
165 *adjustedState = kptr->
syscall(subid, params, params_size);
169 adjustedState->
success =
false;
170 adjustedState->
meta = META_ERROR_BADOBJECT;
177 "NativeSyscallManager: invalid syscall received: " 178 <<
Dec << state.getSyscallNumber());
187 NOTICE(
"NativeSyscallManager::factory(" << guid <<
")");
188 if (guid == 0xdeadbeef)
195 NOTICE(
"syscall subid=" << subid);
NativeBase * factory(uint64_t guid)
static EXPORTED_PUBLIC SyscallManager & instance()
uintptr_t call(uintptr_t function, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0, uintptr_t p5=0)
virtual uintptr_t syscall(SyscallState &state)
virtual ReturnState syscall(uint64_t subid, void *params, size_t params_size)
static void setInterrupts(bool bEnable)
virtual ~NativeSyscallManager()
virtual bool registerSyscallHandler(Service_t Service, SyscallHandler *pHandler)=0
virtual ReturnState syscall(uint64_t subid, void *params, size_t params_size)=0
virtual uintptr_t syscall(Service_t service, uintptr_t function, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0, uintptr_t p5=0)=0