1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_TransferMemoryBlock.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 23761 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_OS_OS_TRANSFERMEMORYBLOCK_H_
17 #define NN_OS_OS_TRANSFERMEMORYBLOCK_H_
18 
19 #include <nn/config.h>
20 #if NN_PLATFORM_HAS_MMU
21 
22 #include <nn/os/os_MemoryBlockBase.h>
23 #include <nn/os/os_HandleObject.h>
24 
25 #ifdef __cplusplus
26 
27 namespace nn{ namespace os{
28 
29 
30 class TransferMemoryBlock : public MemoryBlockBase, public HandleObject
31 {
32 public:
33 
TransferMemoryBlock()34     TransferMemoryBlock() : m_SpaceAllocated(false) {}
~TransferMemoryBlock()35     ~TransferMemoryBlock() { Finalize(); }
36 
37     void Initialize(
38         void*   p,
39         size_t  size,
40         bit32   myPermission    = os::MEMORY_PERMISSION_NONE,
41         bit32   otherPermission = os::MEMORY_PERMISSION_READ_WRITE );
42 
43     Result TryInitialize(
44         void*   p,
45         size_t  size,
46         bit32   myPermission    = os::MEMORY_PERMISSION_NONE,
47         bit32   otherPermission = os::MEMORY_PERMISSION_READ_WRITE );
48 
49     void Finalize();
50 
51 
52 private:
53     friend class HandleManager;
54 
55     Result AttachAndMap(
56         Handle handle,
57         size_t  size,
58         bit32   otherPermission,
59         bit32   myPermission );
60 
61     Result Map(
62         size_t  size,
63         bit32   otherPermission,
64         bit32   myPermission );
65 
66     void Unmap(void);
67 
68 private:
69     bool    m_SpaceAllocated;
70     NN_PADDING3;
71     NN_PADDING4;
72 };
73 
74 }} // namespace nn::os
75 
76 #endif
77 
78 #endif  // if NN_PLATFORM_HAS_MMU
79 #endif /* NN_OS_OS_TRANSFERMEMORYBLOCK_H_ */
80