The Pedigree Project 0.1
PedigreeCSyscallManager.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/processor/Processor.h"
22#include "pedigree/kernel/processor/SyscallManager.h"
23#include "pedigree/kernel/processor/state.h"
24#include "pedigree/kernel/syscallError.h"
25#include "pedigree/kernel/utilities/String.h"
26
27#include "PedigreeCSyscallManager.h"
28#include "pedigree-syscalls.h"
29#include "pedigreecSyscallNumbers.h"
30
32
34
35bool PedigreeCSyscallManager::initialise() {
36 if (!SyscallManager::instance().registerSyscallHandler(pedigree_c, this, m_Registration)) {
37 return false;
38 }
39 return true;
40}
41
42bool PedigreeCSyscallManager::shutdown() {
43 return m_Registration.reset();
44}
45
46uintptr_t PedigreeCSyscallManager::call(uintptr_t function, uintptr_t p1, uintptr_t p2,
47 uintptr_t p3, uintptr_t p4, uintptr_t p5) {
48 if (function >= serviceEnd) {
49 ERROR("PedigreeCSyscallManager: invalid function called: " << Dec
50 << static_cast<int>(function));
51 return 0;
52 }
53 return SyscallManager::instance().syscall(posix, function, p1, p2, p3, p4, p5);
54}
55
56uintptr_t PedigreeCSyscallManager::syscall(SyscallState& state) {
57 uintptr_t p1 = state.getSyscallParameter(0);
58 uintptr_t p2 = state.getSyscallParameter(1);
59 uintptr_t p3 = state.getSyscallParameter(2);
60
61 // We're interruptible.
63
64 switch (state.getSyscallNumber()) {
65 // Pedigree system calls, called from POSIX applications
66 case PEDIGREE_LOGIN:
67 return pedigree_login(static_cast<int>(p1));
68 case PEDIGREE_LOAD_KEYMAP:
69 return pedigree_load_keymap(reinterpret_cast<uint32_t*>(p1), p2);
70 case PEDIGREE_GET_MOUNT:
71 return pedigree_get_mount(reinterpret_cast<char*>(p1), reinterpret_cast<char*>(p2), p3);
72 case PEDIGREE_REBOOT:
73 pedigree_reboot();
74 return 0;
75 case PEDIGREE_MODULE_LOAD:
76 pedigree_module_load(reinterpret_cast<char*>(p1));
77 return 0;
78 case PEDIGREE_MODULE_UNLOAD: {
79 if (!p1) {
80 SYSCALL_ERROR(InvalidArgument);
81 return -1;
82 }
83
84 // KernelElf must not invoke this module's exit routine while its
85 // syscall handler is still pinned on the current stack.
86 String moduleName(reinterpret_cast<const char*>(p1));
87 if (moduleName.compare("pedigree-c")) {
88 SYSCALL_ERROR(DeviceBusy);
89 return -1;
90 }
91
92 if (!pedigree_module_unload(const_cast<char*>(moduleName.cstr()))) {
93 SYSCALL_ERROR(DeviceBusy);
94 return -1;
95 }
96 return 0;
97 }
98 case PEDIGREE_MODULE_IS_LOADED:
99 return pedigree_module_is_loaded(reinterpret_cast<char*>(p1));
100 case PEDIGREE_MODULE_GET_DEPENDING:
101 return pedigree_module_get_depending(reinterpret_cast<char*>(p1), reinterpret_cast<char*>(p2),
102 p3);
103 case PEDIGREE_INPUT_INHIBIT_EVENTS:
104 pedigree_input_inhibit_events(p1);
105 return 0;
106 case PEDIGREE_EVENT_RETURN:
107 return pedigree_event_return();
108 case PEDIGREE_SYS_REQUEST_MEM:
109 return reinterpret_cast<uintptr_t>(pedigree_sys_request_mem(p1));
110 case PEDIGREE_HALTFS:
111 pedigree_haltfs();
112 return 0;
113 default:
114 ERROR("PedigreeCSyscallManager: invalid syscall received: " << Dec
115 << state.getSyscallNumber());
116 return 0;
117 }
118}
virtual uintptr_t syscall(SyscallState &state)
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)
static void setInterrupts(bool bEnable)
bool compare(const char *s, size_t len) const
Definition String.cc:202
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
static EXPORTED_PUBLIC SyscallManager & instance()
@ Dec
Definition Log.h:126