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