Merge "[Native][25/11/2013][Add]Adding BigInteger class" into tizen
[platform/framework/native/appfw.git] / inc / FBaseRtMemoryManager.h
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.h
19  * @brief       This is the header file for the %MemoryManager class.
20  *
21  * This header file contains the declarations of the %MemoryManager class.
22  */
23
24 #ifndef _FBASE_RT_MEMORY_MANAGER_H_
25 #define _FBASE_RT_MEMORY_MANAGER_H_
26
27 #include <FBase.h>
28 #include <FBaseObject.h>
29
30 namespace Tizen { namespace Base { namespace Runtime {
31
32 /**
33  * @enum         MemoryProtectionMode
34  *
35  * Defines the memory protection modes.
36  *
37  * @since 2.0
38  */
39 enum MemoryProtectionMode
40 {
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 */
45 };
46
47 /**
48  *  @class              MemoryManager
49  *      @brief  This class represents a memory manager for runtime.
50  *
51  *      @since 2.0
52  *
53  *  The %MemoryManager class represents a memory manager for runtime.
54  *
55  *  The following example demonstrates how to use the %MemoryManager class.
56  *
57  *  @code
58  *  #include <FBase.h>
59  *
60  *  using namespace Tizen::Base::Runtime;
61  *
62  *  result
63  *  MyApp::Execute(void)
64  *  {
65  *              result r = E_SUCCESS;
66  *              int size = 1024;
67  *              void* pMemory = (void*)malloc(4096);
68  *
69  *              // Sets to an aligned page
70  *              pMemory = (void*)(((int)pMemory + size) & ~(size - 1));
71  *
72  *              // Prepares for execution
73  *              r = MemoryManager::ProtectMemory(pMemory, size, MEMORY_PROTECTION_MODE_EXEC);
74  *              if (IsFailed(r))
75  *              {
76  *                              // Failed to change memory protection
77  *              }
78  *
79  *              // Executes code in the memory
80  *
81  *  }
82  *
83  *  @endcode
84  */
85 class _OSP_EXPORT_ MemoryManager
86 {
87 public:
88         /**
89          * Changes protection on a memory region.
90          *
91          * @since 2.0
92          *
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.
102          */
103         static result ProtectMemory(const void* pAddress, long long length, unsigned long protection);
104
105 private:
106         /**
107          * This is the default constructor for this class.
108          *
109          * @since 2.0
110          */
111         MemoryManager(void);
112
113         /**
114          * This is the destructor for this class.
115          *
116          * @since 2.0
117          */
118         ~MemoryManager(void);
119
120 }; // MemoryManager
121
122 } } } // Tizen::Base::Runtime
123
124 #endif // _FBASE_RT_MEMORY_MANAGER_H_