The Pedigree Project 0.1
pedigree-syscalls.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/linker/KernelElf.h"
22#include "pedigree/kernel/machine/KeymapManager.h"
23#include "pedigree/kernel/process/Process.h"
24#include "pedigree/kernel/process/TerminationDeferral.h"
25#include "pedigree/kernel/process/Thread.h"
26#include "pedigree/kernel/process/eventNumbers.h"
27#include "pedigree/kernel/processor/Processor.h"
28#include "pedigree/kernel/processor/SyscallManager.h"
29#include "pedigree/kernel/syscallError.h"
30
31#include "modules/system/vfs/File.h"
33#include "modules/system/vfs/MountView.h"
34#include "modules/system/vfs/VFS.h"
35#include "pedigree-syscalls.h"
36
37// Module handling functions
38
39// Load a module
40void pedigree_module_load(char* _file) {
41 TerminationDeferral lifetime;
42 Process* process = Processor::information().getCurrentThread()->getParent();
43 auto context = process->acquireFilesystemContext();
44 auto* view = VFS::instance().mountView();
45 FilesystemPathRef selected;
47 if (!view || !context ||
48 !view->resolve(context, FilesystemPathRef(), String(_file), options, selected)) {
49 SYSCALL_ERROR(DoesNotExist);
50 return;
51 }
52 File* file = selected->node();
53
54 if (file->isDirectory()) {
55 // Error - is directory.
56 SYSCALL_ERROR(IsADirectory);
57 return;
58 }
59
60 // Map the module in the memory
61 uintptr_t buffer = 0;
62 MemoryMappedObject* pMmFile =
63 MemoryMapManager::instance().mapFile(file, buffer, file->getSize(), MemoryMappedObject::Read);
64 KernelElf::instance().loadModule(reinterpret_cast<uint8_t*>(buffer), file->getSize(), true);
66}
67
68// Unload a module
69int pedigree_module_unload(char* name) {
70 return KernelElf::instance().unloadModule(name, true) ? 1 : 0;
71}
72
73// Check if a module is loaded
74int pedigree_module_is_loaded(char* name) {
75 return (KernelElf::instance().moduleIsLoaded(name) ? 1 : 0);
76}
77
78// Get the first module that depends on the specified module
79int pedigree_module_get_depending(char* name, char* buf, size_t bufsz) {
80 char* dep = KernelElf::instance().getDependingModule(name);
81 if (dep)
82 StringCopyN(buf, dep, bufsz);
83 else
84 return 0;
85 return 1;
86}
87
88void pedigree_input_inhibit_events(int inhibit) {
89 Thread* pThread = Processor::information().getCurrentThread();
90 pThread->inhibitEvent(EventNumbers::InputEvent, inhibit == 1);
91}
92
93int pedigree_load_keymap(uint32_t* buf, size_t len) {
95 if (!KeymapManager::instance().useCompiledKeymap(buf, len)) {
96 return -1;
97 } else {
98 return 0;
99 }
100}
101
102int pedigree_event_return() {
103 if (!SyscallManager::instance().requestEventReturn()) {
104 SYSCALL_ERROR(InvalidArgument);
105 return -1;
106 }
107 return 0;
108}
109
110void* pedigree_sys_request_mem(size_t len) {
111 Process* pProcess = Processor::information().getCurrentThread()->getParent();
112 uintptr_t mapAddress = 0;
113 if (!pProcess->allocateUserRange(Process::UserRegion::Dynamic, len, mapAddress)) {
114 if (!pProcess->allocateUserRange(Process::UserRegion::Normal, len, mapAddress)) {
115 return 0;
116 }
117 }
118
119 return reinterpret_cast<void*>(mapAddress);
120}
121
122void pedigree_haltfs() {
123 // Synchronises all filesystems and disks and unloads them.
125 NOTICE("Stubbed: pedigree_haltfs");
126}
Memory-mapped file interface.
Definition File.h:75
virtual bool isDirectory()
Definition File.cc:804
char * getDependingModule(char *name)
bool unloadModule(const char *name, bool silent=false, bool progress=true)
Definition KernelElf.cc:929
static KernelElf & instance()
Definition KernelElf.h:135
Module * loadModule(uint8_t *pModule, size_t len, bool silent=false)
Definition KernelElf.cc:372
static KeymapManager & instance()
Singleton design.
void unmap(MemoryMappedObject *pObj)
static MemoryMapManager & instance()
MemoryMappedObject * mapFile(File *pFile, uintptr_t &address, size_t length, MemoryMappedObject::Permissions perms, size_t offset=0, bool bCopyOnWrite=true)
Process * getParent()
Definition Process.h:620
static ProcessorInformation & information()
static EXPORTED_PUBLIC SyscallManager & instance()
void inhibitEvent(size_t eventNumber, bool bInhibit)
Definition Thread.cc:1973
static VFS & instance()
Definition VFS.cc:311