libnx  v4.2.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 Frees up resources used by a transfer memory object, unmapping and closing handles, etc.
77  * @param t Transfer memory information structure.
78  * @return Result code.
79  */
tmemCreateFromMemory
Result tmemCreateFromMemory(TransferMemory *t, void *buf, size_t size, Permission perm)
Creates a transfer memory object from existing memory.
TransferMemory::handle
Handle handle
Kernel object handle.
Definition: tmem.h:14
TransferMemory::perm
Permission perm
Permissions of the transfer memory object.
Definition: tmem.h:16
tmemLoadRemote
void tmemLoadRemote(TransferMemory *t, Handle handle, size_t size, Permission perm)
Loads a transfer memory object coming from a remote process.
TransferMemory::size
size_t size
Size of the transfer memory object.
Definition: tmem.h:15
tmemGetAddr
static void * tmemGetAddr(TransferMemory *t)
Retrieves the mapped address of a transfer memory object.
Definition: tmem.h:71
TransferMemory::map_addr
void * map_addr
Address to which the transfer memory object is mapped.
Definition: tmem.h:18
TransferMemory
Transfer memory information structure.
Definition: tmem.h:13
tmemCreate
Result tmemCreate(TransferMemory *t, size_t size, Permission perm)
Creates a transfer memory object.
Permission
Permission
Memory permission bitmasks.
Definition: svc.h:77
tmemUnmap
Result tmemUnmap(TransferMemory *t)
Unmaps a transfer memory object.
Result
u32 Result
Function error code result type.
Definition: types.h:44
TransferMemory::src_addr
void * src_addr
Address of the source backing memory.
Definition: tmem.h:17
tmemMap
Result tmemMap(TransferMemory *t)
Maps a transfer memory object.
Handle
u32 Handle
Kernel object handle.
Definition: types.h:43
tmemClose
Result tmemClose(TransferMemory *t)
Frees up resources used by a transfer memory object, unmapping and closing handles,...