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/process/Scheduler.h"
22 #include "pedigree/kernel/processor/Processor.h"
23 #include "pedigree/kernel/processor/SyscallManager.h"
24 #include "pedigree/kernel/processor/state.h"
25 
26 #include "PedigreeCSyscallManager.h"
27 #include "pedigreecSyscallNumbers.h"
28 
29 #define PEDIGREEC_WITHIN_KERNEL
30 #include "pedigree-syscalls.h"
31 
33 {
34 }
35 
37 {
38 }
39 
40 void PedigreeCSyscallManager::initialise()
41 {
43  pedigree_config_init();
44 }
45 
47  uintptr_t function, uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4,
48  uintptr_t p5)
49 {
50  if (function >= serviceEnd)
51  {
52  ERROR(
53  "PedigreeCSyscallManager: invalid function called: "
54  << Dec << static_cast<int>(function));
55  return 0;
56  }
58  posix, function, p1, p2, p3, p4, p5);
59 }
60 
61 uintptr_t PedigreeCSyscallManager::syscall(SyscallState &state)
62 {
63  uintptr_t p1 = state.getSyscallParameter(0);
64  uintptr_t p2 = state.getSyscallParameter(1);
65  uintptr_t p3 = state.getSyscallParameter(2);
66  uintptr_t p4 = state.getSyscallParameter(3);
67  uintptr_t p5 = state.getSyscallParameter(4);
68 
69  // We're interruptible.
71 
72  switch (state.getSyscallNumber())
73  {
74  // Pedigree system calls, called from POSIX applications
75  case PEDIGREE_LOGIN:
76  return pedigree_login(
77  static_cast<int>(p1), reinterpret_cast<const char *>(p2));
78  case PEDIGREE_LOAD_KEYMAP:
79  return pedigree_load_keymap(reinterpret_cast<uint32_t *>(p1), p2);
80  case PEDIGREE_GET_MOUNT:
81  return pedigree_get_mount(
82  reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2), p3);
83  case PEDIGREE_REBOOT:
84  pedigree_reboot();
85  return 0;
86  case PEDIGREE_CONFIG_GETCOLNAME:
87  pedigree_config_getcolname(
88  p1, p2, reinterpret_cast<char *>(p3), p4);
89  return 0;
90  case PEDIGREE_CONFIG_GETSTR_N:
91  pedigree_config_getstr(
92  p1, p2, p3, reinterpret_cast<char *>(p4), p5);
93  return 0;
94  case PEDIGREE_CONFIG_GETSTR_S:
95  pedigree_config_getstr(
96  p1, p2, reinterpret_cast<const char *>(p3),
97  reinterpret_cast<char *>(p4), p5);
98  return 0;
99  case PEDIGREE_CONFIG_GETNUM_N:
100  return pedigree_config_getnum(p1, p2, p3);
101  case PEDIGREE_CONFIG_GETNUM_S:
102  return pedigree_config_getnum(
103  p1, p2, reinterpret_cast<const char *>(p3));
104  case PEDIGREE_CONFIG_GETBOOL_N:
105  return pedigree_config_getbool(p1, p2, p3);
106  case PEDIGREE_CONFIG_GETBOOL_S:
107  return pedigree_config_getbool(
108  p1, p2, reinterpret_cast<const char *>(p3));
109  case PEDIGREE_CONFIG_QUERY:
110  return pedigree_config_query(reinterpret_cast<const char *>(p1));
111  case PEDIGREE_CONFIG_FREERESULT:
112  pedigree_config_freeresult(p1);
113  return 0;
114  case PEDIGREE_CONFIG_NUMCOLS:
115  return pedigree_config_numcols(p1);
116  case PEDIGREE_CONFIG_NUMROWS:
117  return pedigree_config_numrows(p1);
118  case PEDIGREE_CONFIG_WAS_SUCCESSFUL:
119  return pedigree_config_was_successful(p1);
120  case PEDIGREE_CONFIG_GET_ERROR_MESSAGE:
121  pedigree_config_get_error_message(
122  p1, reinterpret_cast<char *>(p2), p3);
123  return 0;
124  case PEDIGREE_MODULE_LOAD:
125  pedigree_module_load(reinterpret_cast<char *>(p1));
126  return 0;
127  case PEDIGREE_MODULE_UNLOAD:
128  pedigree_module_unload(reinterpret_cast<char *>(p1));
129  return 0;
130  case PEDIGREE_MODULE_IS_LOADED:
131  return pedigree_module_is_loaded(reinterpret_cast<char *>(p1));
132  case PEDIGREE_MODULE_GET_DEPENDING:
133  return pedigree_module_get_depending(
134  reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2), p3);
135  case PEDIGREE_GFX_GET_PROVIDER:
136  return pedigree_gfx_get_provider(reinterpret_cast<void *>(p1));
137  case PEDIGREE_GFX_GET_CURR_MODE:
138  return pedigree_gfx_get_curr_mode(
139  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
140  case PEDIGREE_GFX_GET_RAW_BUFFER:
141  return pedigree_gfx_get_raw_buffer(reinterpret_cast<void *>(p1));
142  case PEDIGREE_GFX_CREATE_BUFFER:
143  return pedigree_gfx_create_buffer(
144  reinterpret_cast<void *>(p1), reinterpret_cast<void **>(p2),
145  reinterpret_cast<void *>(p3));
146  case PEDIGREE_GFX_DESTROY_BUFFER:
147  return pedigree_gfx_destroy_buffer(
148  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
149  case PEDIGREE_GFX_REDRAW:
150  pedigree_gfx_redraw(
151  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
152  return 0;
153  case PEDIGREE_GFX_BLIT:
154  pedigree_gfx_blit(
155  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
156  return 0;
157  case PEDIGREE_GFX_SET_PIXEL:
158  pedigree_gfx_set_pixel(
159  reinterpret_cast<void *>(p1), p2, p3, p4, p5);
160  return 0;
161  case PEDIGREE_GFX_RECT:
162  pedigree_gfx_rect(
163  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
164  return 0;
165  case PEDIGREE_GFX_COPY:
166  pedigree_gfx_copy(
167  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
168  return 0;
169  case PEDIGREE_GFX_LINE:
170  pedigree_gfx_line(
171  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
172  return 0;
173  case PEDIGREE_GFX_DRAW:
174  pedigree_gfx_draw(
175  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
176  return 0;
177  case PEDIGREE_GFX_CREATE_FBUFFER:
178  return pedigree_gfx_create_fbuffer(
179  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
180  case PEDIGREE_GFX_DELETE_FBUFFER:
181  pedigree_gfx_delete_fbuffer(reinterpret_cast<void *>(p1));
182  return 0;
183  case PEDIGREE_GFX_FBINFO:
184  pedigree_gfx_fbinfo(
185  reinterpret_cast<void *>(p1), reinterpret_cast<size_t *>(p2),
186  reinterpret_cast<size_t *>(p3),
187  reinterpret_cast<uint32_t *>(p4),
188  reinterpret_cast<size_t *>(p5));
189  return 0;
190  case PEDIGREE_GFX_SETPALETTE:
191  pedigree_gfx_setpalette(
192  reinterpret_cast<void *>(p1), reinterpret_cast<uint32_t *>(p2),
193  p3);
194  return 0;
195  case PEDIGREE_INPUT_INSTALL_CALLBACK:
196  pedigree_input_install_callback(
197  reinterpret_cast<void *>(p1), p2, p3);
198  return 0;
199  case PEDIGREE_INPUT_REMOVE_CALLBACK:
200  pedigree_input_remove_callback(reinterpret_cast<void *>(p1));
201  return 0;
202  case PEDIGREE_INPUT_INHIBIT_EVENTS:
203  pedigree_input_inhibit_events(p1);
204  return 0;
205  case PEDIGREE_EVENT_RETURN:
206  pedigree_event_return();
207  case PEDIGREE_SYS_REQUEST_MEM:
208  return reinterpret_cast<uintptr_t>(pedigree_sys_request_mem(p1));
209  case PEDIGREE_HALTFS:
210  pedigree_haltfs();
211  return 0;
212  default:
213  ERROR(
214  "PedigreeCSyscallManager: invalid syscall received: "
215  << Dec << state.getSyscallNumber());
216  return 0;
217  }
218 }
static EXPORTED_PUBLIC SyscallManager & instance()
virtual uintptr_t syscall(SyscallState &state)
static void setInterrupts(bool bEnable)
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)
#define ERROR(text)
Definition: Log.h:82
Definition: Log.h:138
virtual bool registerSyscallHandler(Service_t Service, SyscallHandler *pHandler)=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