2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseRtMemoryManager.h
20 * @brief This is the header file for the %MemoryManager class.
22 * This header file contains the declarations of the %MemoryManager class.
25 #ifndef _FBASE_RT_MEMORY_MANAGER_H_
26 #define _FBASE_RT_MEMORY_MANAGER_H_
29 #include <FBaseObject.h>
31 namespace Tizen { namespace Base { namespace Runtime {
34 * @enum MemoryProtectionMode
36 * Defines the memory protection modes.
40 enum MemoryProtectionMode
42 MEMORY_PROTECTION_MODE_NONE = 0x0, /**< The memory cannot be accessed */
43 MEMORY_PROTECTION_MODE_READ = 0x1, /**< The memory can be read */
44 MEMORY_PROTECTION_MODE_WRITE = 0x2, /**< The memory can be modified */
45 MEMORY_PROTECTION_MODE_EXEC = 0x4, /**< The memory can be executed */
49 * @class MemoryManager
50 * @brief This class represents a memory manager for runtime.
54 * The %MemoryManager class represents a memory manager for runtime.
56 * The following example demonstrates how to use the %MemoryManager class.
61 * using namespace Tizen::Base::Runtime;
64 * MyApp::Execute(void)
66 * result r = E_SUCCESS;
68 * void* pMemory = (void*)malloc(4096);
70 * // Sets to an aligned page
71 * pMemory = (void*)(((int)pMemory + size) & ~(size - 1));
73 * // Prepares for execution
74 * r = MemoryManager::ProtectMemory(pMemory, size, MEMORY_PROTECTION_MODE_EXEC);
77 * // Failed to change memory protection
80 * // Executes code in the memory
86 class _OSP_EXPORT_ MemoryManager
90 * Changes protection on a memory region.
94 * @return An error code
95 * @param[in] pAddress The start address of the memory region aligned on a page boundary.
96 * @param[in] length The length of the memory region in bytes
97 * @param[in] protection The memory protection @n
98 * It is either Tizen::Base::Runtime::MEMORY_PROTECTION_MODE_NONE or a bitwise OR of the
99 * other values in Tizen::Base::Runtime::MemoryProtectionMode.
100 * @exception E_SUCCESS The method is successful.
101 * @exception E_SYSTEM A system error has occurred due to an invalid address.
102 * @exception E_INVALID_ARG The memory address is not valid, or the length is not a multiple of system page size.
104 static result ProtectMemory(const void* pAddress, long long length, unsigned long protection);
108 * This is the default constructor for this class.
115 * This is the destructor for this class.
119 ~MemoryManager(void);
123 } } } // Tizen::Base::Runtime
125 #endif // _FBASE_RT_MEMORY_MANAGER_H_