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)
39  return API::InvalidArgument;
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:
75  return API::InvalidArgument;
76  }
77 
78  // Done
79  return ret;
80 }
ProcessManager
Represents a process which may run on the host.
Definition: ProcessManager.h:44
ProcessShares::MemoryShare
Definition: ProcessShares.h:48
API::Result
Result
Enumeration of generic kernel API result codes.
Definition: API.h:68
API::Operation
Operation
Various actions which may be performed inside an APIHandler.
Definition: API.h:91
Process
Represents a process which may run on the host.
Definition: Process.h:44
API::InvalidArgument
@ InvalidArgument
Definition: API.h:74
VMShareHandler
API::Result VMShareHandler(const ProcessID procID, const API::Operation op, ProcessShares::MemoryShare *share)
Kernel handler prototype.
Definition: VMShare.cpp:25
ProcessID.h
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
MemoryBlock.h
Kernel::getProcessManager
ProcessManager * getProcessManager()
Get process manager.
Definition: Kernel.cpp:143
Process::getShares
ProcessShares & getShares()
Get process shares.
Definition: Process.cpp:85
API::Read
@ Read
Definition: API.h:98
API::IOError
@ IOError
Definition: API.h:76
SELF
#define SELF
Definition: ProcessID.h:35
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
WeakSingleton< Kernel >::instance
static Kernel * instance()
Retrieve the instance.
Definition: Singleton.h:86
ProcessManager::get
Process * get(const ProcessID id)
Retrieve a Process by it's ID.
Definition: ProcessManager.cpp:95
VMShare.h
ProcessShares::readShare
Result readShare(MemoryShare *share)
Read memory share by Process, Core and Tag IDs.
Definition: ProcessShares.cpp:358
ProcessShares::createShare
Result createShare(ProcessShares &instance, MemoryShare *share)
Definition: ProcessShares.cpp:142
API::AlreadyExists
@ AlreadyExists
Definition: API.h:77
API::NotFound
@ NotFound
Definition: API.h:73
API::Delete
@ Delete
Definition: API.h:94
API::TemporaryUnavailable
@ TemporaryUnavailable
Definition: API.h:78
API::Success
@ Success
Definition: API.h:70
ProcessManager::current
Process * current()
Current process running.
Definition: ProcessManager.cpp:203
ProcessShares::removeShares
Result removeShares(ProcessID pid)
Remove all shares for the given ProcessID.
Definition: ProcessShares.cpp:254
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
ProcessShares::DetachInProgress
@ DetachInProgress
Definition: ProcessShares.h:73
API::Create
@ Create
Definition: API.h:93
ProcessShares::AlreadyExists
@ AlreadyExists
Definition: ProcessShares.h:72
ProcessShares::Success
@ Success
Definition: ProcessShares.h:68