libnx  v4.8.0
shmem.h
Go to the documentation of this file.
1 /**
2  * @file shmem.h
3  * @brief Shared memory object handling
4  * @author plutoo
5  * @copyright libnx Authors
6  * @remark Shared memory differs from transfer memory in the fact that the kernel (as opposed to the user process) allocates and owns its backing memory.
7  */
8 #pragma once
9 #include "../types.h"
10 
11 /// Shared memory information structure.
12 typedef struct {
13  Handle handle; ///< Kernel object handle.
14  size_t size; ///< Size of the shared memory object.
15  Permission perm; ///< Permissions.
16  void* map_addr; ///< Address to which the shared memory object is mapped.
17 } SharedMemory;
18 
19 /**
20  * @brief Creates a shared memory object.
21  * @param s Shared memory information structure which will be filled in.
22  * @param size Size of the shared memory object to create.
23  * @param local_perm Permissions with which the shared memory object will be mapped in the local process.
24  * @param remote_perm Permissions with which the shared memory object will be mapped in the remote process (can be Perm_DontCare).
25  * @return Result code.
26  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
27  */
28 Result shmemCreate(SharedMemory* s, size_t size, Permission local_perm, Permission remote_perm);
29 
30 /**
31  * @brief Loads a shared memory object coming from a remote process.
32  * @param s Shared memory information structure which will be filled in.
33  * @param handle Handle of the shared memory object.
34  * @param size Size of the shared memory object that is being loaded.
35  * @param perm Permissions with which the shared memory object will be mapped in the local process.
36  */
37 void shmemLoadRemote(SharedMemory* s, Handle handle, size_t size, Permission perm);
38 
39 /**
40  * @brief Maps a shared memory object.
41  * @param s Shared memory information structure.
42  * @return Result code.
43  */
45 
46 /**
47  * @brief Unmaps a shared memory object.
48  * @param s Shared memory information structure.
49  * @return Result code.
50  */
52 
53 /**
54  * @brief Retrieves the mapped address of a shared memory object.
55  * @param s Shared memory information structure.
56  * @return Mapped address of the shared memory object.
57  */
58 static inline void* shmemGetAddr(SharedMemory* s) {
59  return s->map_addr;
60 }
61 
62 /**
63  * @brief Frees up resources used by a shared memory object, unmapping and closing handles, etc.
64  * @param s Shared memory information structure.
65  * @return Result code.
66  */
Result shmemUnmap(SharedMemory *s)
Unmaps a shared memory object.
void shmemLoadRemote(SharedMemory *s, Handle handle, size_t size, Permission perm)
Loads a shared memory object coming from a remote process.
Result shmemMap(SharedMemory *s)
Maps a shared memory object.
Result shmemCreate(SharedMemory *s, size_t size, Permission local_perm, Permission remote_perm)
Creates a shared memory object.
Result shmemClose(SharedMemory *s)
Frees up resources used by a shared memory object, unmapping and closing handles, etc.
static void * shmemGetAddr(SharedMemory *s)
Retrieves the mapped address of a shared memory object.
Definition: shmem.h:58
Shared memory information structure.
Definition: shmem.h:12
size_t size
Size of the shared memory object.
Definition: shmem.h:14
Permission perm
Permissions.
Definition: shmem.h:15
Handle handle
Kernel object handle.
Definition: shmem.h:13
void * map_addr
Address to which the shared memory object is mapped.
Definition: shmem.h:16
Permission
Memory permission bitmasks.
Definition: svc.h:80
u32 Handle
Kernel object handle.
Definition: types.h:43
u32 Result
Function error code result type.
Definition: types.h:44