FreeNOS
VMShare.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/System.h>
19#include <FreeNOS/ProcessEvent.h>
20#include <FreeNOS/ProcessManager.h>
21#include <MemoryBlock.h>
22#include "VMShare.h"
23#include "ProcessID.h"
24
26 const API::Operation op,
28{
30 Process *proc = ZERO;
32
33 DEBUG("");
34
35 // Find the given process
36 if (procID == SELF)
37 {
38 if (op != API::Read)
40 else
41 proc = procs->current();
42 }
43 else if (op != API::Delete && !(proc = procs->get(procID)))
44 {
45 return API::NotFound;
46 }
47
48 switch (op)
49 {
50 case API::Create:
51 {
52 switch (procs->current()->getShares().createShare(proc->getShares(), share))
53 {
57 default: return API::IOError;
58 }
59 break;
60 }
61
62 case API::Read:
63 if (procs->current()->getShares().readShare(share) != ProcessShares::Success)
64 {
65 ret = API::IOError;
66 }
67 break;
68
69 case API::Delete:
70 if (procs->current()->getShares().removeShares(procID) != ProcessShares::Success)
71 ret = API::IOError;
72 break;
73
74 default:
76 }
77
78 // Done
79 return ret;
80}
Result
Enumeration of generic kernel API result codes.
Definition API.h:69
@ NotFound
Definition API.h:73
@ IOError
Definition API.h:76
@ AlreadyExists
Definition API.h:77
@ Success
Definition API.h:70
@ InvalidArgument
Definition API.h:74
@ TemporaryUnavailable
Definition API.h:78
Operation
Various actions which may be performed inside an APIHandler.
Definition API.h:92
@ Read
Definition API.h:98
@ Create
Definition API.h:93
@ Delete
Definition API.h:94
ProcessManager * getProcessManager()
Get process manager.
Definition Kernel.cpp:143
Represents a process which may run on the host.
Process * get(const ProcessID id)
Retrieve a Process by it's ID.
Process * current()
Current process running.
Result readShare(MemoryShare *share)
Read memory share by Process, Core and Tag IDs.
Result createShare(ProcessShares &instance, MemoryShare *share)
Result removeShares(ProcessID pid)
Remove all shares for the given ProcessID.
Represents a process which may run on the host.
Definition Process.h:45
ProcessShares & getShares()
Get process shares.
Definition Process.cpp:85
static Kernel * instance()
Retrieve the instance.
Definition Singleton.h:86
API::Result VMShareHandler(const ProcessID procID, const API::Operation op, ProcessShares::MemoryShare *share)
Kernel handler prototype.
Definition VMShare.cpp:25
#define SELF
Definition ProcessID.h:35
u32 ProcessID
Process Identification Number.
Definition Types.h:140
#define ZERO
Zero value.
Definition Macros.h:43
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89