Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRtMemoryManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FBaseRtMemoryManager.cpp
19  * @brief       This is the implementation file for the MemoryManager class.
20  *
21  */
22
23 #include <sys/mman.h>
24 #include <errno.h>
25
26 #include <FBaseRtMemoryManager.h>
27
28 #include <FBaseSysLog.h>
29
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33
34 namespace Tizen { namespace Base { namespace Runtime {
35
36 MemoryManager::MemoryManager()
37 {
38
39 }
40 MemoryManager::~MemoryManager()
41 {
42
43 }
44
45 result
46 MemoryManager::ProtectMemory(const void* pAddress, long long length, unsigned long protection)
47 {
48         result r = E_SUCCESS;
49         int prot = PROT_NONE;
50         int ret = -1;
51
52         if (protection & MEMORY_PROTECTION_MODE_READ)
53         {
54                 prot |= PROT_READ;
55         }
56
57         if (protection & MEMORY_PROTECTION_MODE_WRITE)
58         {
59                 prot |= PROT_WRITE;
60         }
61
62         if (protection & MEMORY_PROTECTION_MODE_EXEC)
63         {
64                 prot |= PROT_EXEC;
65         }
66
67         ret = mprotect((void*)pAddress, length, prot);
68         if (ret == -1)
69         {
70                 if (errno == EINVAL)
71                 {
72                         r = E_INVALID_ARG;
73                         SysLogException(NID_BASE_RT, r, "[E_INVALID_ARG] pAddress(0x%x) is not a valid address or length is not a multiple of the system page size.");
74                 }
75                 else
76                 {
77                         r = E_SYSTEM;
78                         SysLogException(NID_BASE_RT, r, "[E_SYSTEM] pAddress(0x%x) is not a valid address or length is not a multiple of the system page size.");
79                 }
80         }
81
82         return r;
83 }
84
85 } } }