2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FBaseRtMemoryManager.h
19 * @brief This is the header file for the %MemoryManager class.
21 * This header file contains the declarations of the %MemoryManager class.
24 #ifndef _FBASE_RT_MEMORY_MANAGER_H_
25 #define _FBASE_RT_MEMORY_MANAGER_H_
28 #include <FBaseObject.h>
30 namespace Tizen { namespace Base { namespace Runtime {
33 * @enum MemoryProtectionMode
35 * Defines the memory protection modes.
39 enum MemoryProtectionMode
41 MEMORY_PROTECTION_MODE_NONE = 0x0, /**< The memory cannot be accessed */
42 MEMORY_PROTECTION_MODE_READ = 0x1, /**< The memory can be read */
43 MEMORY_PROTECTION_MODE_WRITE = 0x2, /**< The memory can be modified */
44 MEMORY_PROTECTION_MODE_EXEC = 0x4, /**< The memory can be executed */
48 * @class MemoryManager
49 * @brief This class represents a memory manager for runtime.
53 * The %MemoryManager class represents a memory manager for runtime.
55 * The following example demonstrates how to use the %MemoryManager class.
60 * using namespace Tizen::Base::Runtime;
63 * MyApp::Execute(void)
65 * result r = E_SUCCESS;
67 * void* pMemory = (void*)malloc(4096);
69 * // Sets to an aligned page
70 * pMemory = (void*)(((int)pMemory + size) & ~(size - 1));
72 * // Prepares for execution
73 * r = MemoryManager::ProtectMemory(pMemory, size, MEMORY_PROTECTION_MODE_EXEC);
76 * // Failed to change memory protection
79 * // Executes code in the memory
85 class _OSP_EXPORT_ MemoryManager
89 * Changes protection on a memory region.
93 * @return An error code
94 * @param[in] pAddress The start address of the memory region aligned on a page boundary.
95 * @param[in] length The length of the memory region in bytes
96 * @param[in] protection The memory protection @n
97 * It is either Tizen::Base::Runtime::MEMORY_PROTECTION_MODE_NONE or a bitwise OR of the
98 * other values in Tizen::Base::Runtime::MemoryProtectionMode.
99 * @exception E_SUCCESS The method is successful.
100 * @exception E_SYSTEM A system error has occurred due to an invalid address.
101 * @exception E_INVALID_ARG The memory address is not valid, or the length is not a multiple of system page size.
103 static result ProtectMemory(const void* pAddress, long long length, unsigned long protection);
107 * This is the default constructor for this class.
114 * This is the destructor for this class.
118 ~MemoryManager(void);
122 } } } // Tizen::Base::Runtime
124 #endif // _FBASE_RT_MEMORY_MANAGER_H_