libnx
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 Loads a transfer memory object coming from a remote process.
32  * @param t Transfer memory information structure which will be filled in.
33  * @param handle Handle of the transfer memory object.
34  * @param size Size of the transfer memory object that is being loaded.
35  * @param perm Permissions which the transfer memory is expected to have in the process that owns the memory.
36  * @warning This is a privileged operation; in normal circumstances applications shouldn't use this function.
37  */
38 void tmemLoadRemote(TransferMemory* t, Handle handle, size_t size, Permission perm);
39 
40 /**
41  * @brief Maps a transfer memory object.
42  * @param t Transfer memory information structure.
43  * @return Result code.
44  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
45  */
47 
48 /**
49  * @brief Unmaps a transfer memory object.
50  * @param t Transfer memory information structure.
51  * @return Result code.
52  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
53  */
55 
56 /**
57  * @brief Retrieves the mapped address of a transfer memory object.
58  * @param t Transfer memory information structure.
59  * @return Mapped address of the transfer memory object.
60  */
61 static inline void* tmemGetAddr(TransferMemory* t){
62  return t->map_addr;
63 }
64 
65 /**
66  * @brief Frees up resources used by a transfer memory object, unmapping and closing handles, etc.
67  * @param t Transfer memory information structure.
68  * @return Result code.
69  */
Result tmemClose(TransferMemory *t)
Frees up resources used by a transfer memory object, unmapping and closing handles, etc.
Permission
Memory permission bitmasks.
Definition: svc.h:73
Transfer memory information structure.
Definition: tmem.h:13
u32 Handle
Kernel object handle.
Definition: types.h:45
Result tmemUnmap(TransferMemory *t)
Unmaps a transfer memory object.
u32 Result
Function error code result type.
Definition: types.h:46
void * map_addr
Address to which the transfer memory object is mapped.
Definition: tmem.h:18
Permission perm
Permissions of the transfer memory object.
Definition: tmem.h:16
void tmemLoadRemote(TransferMemory *t, Handle handle, size_t size, Permission perm)
Loads a transfer memory object coming from a remote process.
void * src_addr
Address of the source backing memory.
Definition: tmem.h:17
static void * tmemGetAddr(TransferMemory *t)
Retrieves the mapped address of a transfer memory object.
Definition: tmem.h:61
Result tmemMap(TransferMemory *t)
Maps a transfer memory object.
size_t size
Size of the transfer memory object.
Definition: tmem.h:15
Handle handle
Kernel object handle.
Definition: tmem.h:14
Result tmemCreate(TransferMemory *t, size_t size, Permission perm)
Creates a transfer memory object.