libnx  v4.6.0
tmem.h
Go to the documentation of this file.
1 /**
2  * @file tmem.h
3  * @brief Transfer memory handling
4  * @author plutoo
5  * @copyright libnx Authors
6  * @remark Transfer memory differs from shared memory in the fact that the user process (as opposed to the kernel) allocates and owns its backing memory.
7  */
8 #pragma once
9 #include "../types.h"
10 #include "../kernel/svc.h"
11 
12 /// Transfer memory information structure.
13 typedef struct {
14  Handle handle; ///< Kernel object handle.
15  size_t size; ///< Size of the transfer memory object.
16  Permission perm; ///< Permissions of the transfer memory object.
17  void* src_addr; ///< Address of the source backing memory.
18  void* map_addr; ///< Address to which the transfer memory object is mapped.
20 
21 /**
22  * @brief Creates a transfer memory object.
23  * @param t Transfer memory information structure that will be filled in.
24  * @param size Size of the transfer memory object to create.
25  * @param perm Permissions with which to protect the transfer memory in the local process.
26  * @return Result code.
27  */
28 Result tmemCreate(TransferMemory* t, size_t size, Permission perm);
29 
30 /**
31  * @brief Creates a transfer memory object from existing memory.
32  * @param t Transfer memory information structure that will be filled in.
33  * @param buf Pointer to a page-aligned buffer.
34  * @param size Size of the transfer memory object to create.
35  * @param perm Permissions with which to protect the transfer memory in the local process.
36  * @return Result code.
37  */
38 Result tmemCreateFromMemory(TransferMemory* t, void* buf, size_t size, Permission perm);
39 
40 /**
41  * @brief Loads a transfer memory object coming from a remote process.
42  * @param t Transfer memory information structure which will be filled in.
43  * @param handle Handle of the transfer memory object.
44  * @param size Size of the transfer memory object that is being loaded.
45  * @param perm Permissions which the transfer memory is expected to have in the process that owns the memory.
46  * @warning This is a privileged operation; in normal circumstances applications shouldn't use this function.
47  */
48 void tmemLoadRemote(TransferMemory* t, Handle handle, size_t size, Permission perm);
49 
50 /**
51  * @brief Maps a transfer memory object.
52  * @param t Transfer memory information structure.
53  * @return Result code.
54  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
55  */
57 
58 /**
59  * @brief Unmaps a transfer memory object.
60  * @param t Transfer memory information structure.
61  * @return Result code.
62  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
63  */
65 
66 /**
67  * @brief Retrieves the mapped address of a transfer memory object.
68  * @param t Transfer memory information structure.
69  * @return Mapped address of the transfer memory object.
70  */
71 static inline void* tmemGetAddr(TransferMemory* t){
72  return t->map_addr;
73 }
74 
75 /**
76  * @brief Closes handle of a transfer memory object.
77  * @param t Transfer memory information structure.
78  * @return Result code.
79  */
81 
82 /**
83  * @brief Waits until source backing memory permissions match perm.
84  * @param t Transfer memory information structure.
85  * @param perm Permissions which the source backing memory is expected to have before return.
86  * @return Result code.
87  */
89 
90 /**
91  * @brief Frees up resources used by a transfer memory object, unmapping and closing handles, etc.
92  * @param t Transfer memory information structure.
93  * @return Result code.
94  */
Transfer memory information structure.
Definition: tmem.h:13
Permission perm
Permissions of the transfer memory object.
Definition: tmem.h:16
Handle handle
Kernel object handle.
Definition: tmem.h:14
void * src_addr
Address of the source backing memory.
Definition: tmem.h:17
void * map_addr
Address to which the transfer memory object is mapped.
Definition: tmem.h:18
size_t size
Size of the transfer memory object.
Definition: tmem.h:15
Permission
Memory permission bitmasks.
Definition: svc.h:80
Result tmemUnmap(TransferMemory *t)
Unmaps a transfer memory object.
static void * tmemGetAddr(TransferMemory *t)
Retrieves the mapped address of a transfer memory object.
Definition: tmem.h:71
Result tmemMap(TransferMemory *t)
Maps a transfer memory object.
Result tmemCreate(TransferMemory *t, size_t size, Permission perm)
Creates a transfer memory object.
void tmemLoadRemote(TransferMemory *t, Handle handle, size_t size, Permission perm)
Loads a transfer memory object coming from a remote process.
Result tmemCreateFromMemory(TransferMemory *t, void *buf, size_t size, Permission perm)
Creates a transfer memory object from existing memory.
Result tmemCloseHandle(TransferMemory *t)
Closes handle of a transfer memory object.
Result tmemClose(TransferMemory *t)
Frees up resources used by a transfer memory object, unmapping and closing handles,...
Result tmemWaitForPermission(TransferMemory *t, Permission perm)
Waits until source backing memory permissions match perm.
u32 Handle
Kernel object handle.
Definition: types.h:43
u32 Result
Function error code result type.
Definition: types.h:44