wut  v1.5.0
Wii U Toolchain
dynload.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 #include "thread.h"
4 #include "time.h"
5 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
18 typedef void *OSDynLoad_Module;
19 
23 
24 typedef enum OSDynLoad_Error
25 {
38 
39 typedef OSDynLoad_Error (*OSDynLoadAllocFn)(int32_t size, int32_t align, void **outAddr);
40 typedef void (*OSDynLoadFreeFn)(void *addr);
41 
42 typedef enum OSDynLoad_ExportType {
46 
48 {
52 
54 {
55  char *name;
56 
57  uint32_t textAddr;
58  uint32_t textOffset;
59  uint32_t textSize;
60 
61  uint32_t dataAddr;
62  uint32_t dataOffset;
63  uint32_t dataSize;
64 
65  uint32_t readAddr;
66  uint32_t readOffset;
67  uint32_t readSize;
68 };
69 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x00, name);
70 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x04, textAddr);
71 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x08, textOffset);
72 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x0C, textSize);
73 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x10, dataAddr);
74 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x14, dataOffset);
75 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x18, dataSize);
76 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x1C, readAddr);
77 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x20, readOffset);
78 WUT_CHECK_OFFSET(OSDynLoad_NotifyData, 0x24, readSize);
79 WUT_CHECK_SIZE(OSDynLoad_NotifyData, 0x28);
80 
82 {
83  uint32_t codeHeapUsed;
84  uint32_t unk_0x04;
85  uint32_t codeHeapFree;
87  uint32_t dataHeapUsed;
88  uint32_t unk_0x14;
89 };
90 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x00, codeHeapUsed);
91 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x04, unk_0x04);
92 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x08, codeHeapFree);
93 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x0C, codeHeapLargestFree);
94 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x10, dataHeapUsed);
95 WUT_CHECK_OFFSET(OSDynLoad_LoaderHeapStatistics, 0x14, unk_0x14);
96 WUT_CHECK_SIZE(OSDynLoad_LoaderHeapStatistics, 0x18);
97 
99 {
100  uint32_t size;
101  uint32_t magic;
103  char *pathString;
104  uint32_t fileInfoFlags;
105  int16_t tlsModuleIndex;
106  int16_t tlsAlignShift;
108  uint32_t tlsSectionSize;
109  uint32_t shstrndx;
110  uint32_t titleLocation;
111  WUT_UNKNOWN_BYTES(0x60 - 0x28);
112 };
113 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x00, size);
114 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x04, magic);
115 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x08, pathStringLength);
116 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x0C, pathString);
117 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x10, fileInfoFlags);
118 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x14, tlsModuleIndex);
119 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x16, tlsAlignShift);
120 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x18, tlsAddressStart);
121 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x1C, tlsSectionSize);
122 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x20, shstrndx);
123 WUT_CHECK_OFFSET(OSDynLoad_LoaderUserFileInfo, 0x24, titleLocation);
124 WUT_CHECK_SIZE(OSDynLoad_LoaderUserFileInfo, 0x60);
125 
126 
128 {
129  uint32_t type;
130  uint32_t flags;
131  void *address;
132 
133  union {
135  uint32_t size;
136 
138  uint32_t name;
139  };
140 };
141 WUT_CHECK_OFFSET(OSDynLoad_LoaderSectionInfo, 0x00, type);
142 WUT_CHECK_OFFSET(OSDynLoad_LoaderSectionInfo, 0x04, flags);
143 WUT_CHECK_OFFSET(OSDynLoad_LoaderSectionInfo, 0x08, address);
144 WUT_CHECK_OFFSET(OSDynLoad_LoaderSectionInfo, 0x0C, size);
145 WUT_CHECK_OFFSET(OSDynLoad_LoaderSectionInfo, 0x0C, name);
146 WUT_CHECK_SIZE(OSDynLoad_LoaderSectionInfo, 0x10);
147 
148 
150 {
151  uint32_t handle;
153  char *moduleName;
154  uint32_t moduleNameLen;
162  void *entryPoint;
163  uint32_t dataSectionSize;
164  void *dataSection;
165  uint32_t loadSectionSize;
166  void *loadSection;
168  void *codeExports;
169  uint32_t numCodeExports;
170  void *dataExports;
171  uint32_t numDataExports;
173  WUT_UNKNOWN_BYTES(0x94 - 0x58);
174 };
175 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x00, handle);
176 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x04, loaderHandle);
177 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x08, moduleName);
178 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x0C, moduleNameLen);
179 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x10, sectionInfoCount);
180 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x14, sectionInfo);
181 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x18, importModules);
182 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x1C, importModuleCount);
183 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x20, userFileInfoSize);
184 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x24, userFileInfo);
185 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x28, notifyData);
186 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x2C, entryPoint);
187 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x30, dataSectionSize);
188 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x34, dataSection);
189 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x38, loadSectionSize);
190 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x3C, loadSection);
191 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x40, dynLoadFreeFn);
192 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x44, codeExports);
193 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x48, numCodeExports);
194 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x4C, dataExports);
195 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x50, numDataExports);
196 WUT_CHECK_OFFSET(OSDynLoad_InternalData, 0x54, next);
197 WUT_CHECK_SIZE(OSDynLoad_InternalData, 0x94);
198 
200 {
204 
205 typedef void (*OSDynLoadNotifyFunc)(OSDynLoad_Module module,
206  void *userContext,
207  OSDynLoad_NotifyReason notifyReason,
208  OSDynLoad_NotifyData *infos);
209 
217 OSDynLoad_Acquire(char const *name,
218  OSDynLoad_Module *outModule);
219 
220 
228  OSDynLoad_ExportType exportType,
229  char const *name,
230  void **outAddr);
231 
232 
239 void
241 
242 
248  OSDynLoadFreeFn freeFn);
249 
250 
256  OSDynLoadFreeFn *outFreeFn);
257 
258 
264  OSDynLoadFreeFn freeFn);
265 
266 
272  OSDynLoadFreeFn *outFreeFn);
273 
274 
280 
281 
288  char *nameBuf,
289  int32_t *nameBufSize);
290 
291 
298 int32_t
300 
301 
313 BOOL
314 OSDynLoad_GetRPLInfo(uint32_t first,
315  uint32_t count,
316  OSDynLoad_NotifyData *outInfos);
317 
324 OSDynLoad_IsModuleLoaded(char const *name,
325  OSDynLoad_Module *outModule);
326 
332  void *userContext);
333 
339  void *userContext);
340 
346 int
348  OSDynLoad_EntryReason reason);
349 
350 #ifdef __cplusplus
351 }
352 #endif
353 
OSDynLoad_LoaderUserFileInfo * userFileInfo
Definition: dynload.h:160
uint32_t readAddr
Definition: dynload.h:65
uint32_t textOffset
Definition: dynload.h:58
uint32_t textSize
Definition: dynload.h:59
uint32_t numCodeExports
Definition: dynload.h:169
uint32_t moduleNameLen
Definition: dynload.h:154
uint32_t userFileInfoSize
Definition: dynload.h:159
OSDynLoad_InternalData * next
Definition: dynload.h:172
uint32_t numDataExports
Definition: dynload.h:171
OSDynLoad_LoaderSectionInfo * sectionInfo
Definition: dynload.h:156
uint32_t readSize
Definition: dynload.h:67
uint32_t sectionInfoCount
Definition: dynload.h:155
OSDynLoad_InternalData ** importModules
Definition: dynload.h:157
uint32_t importModuleCount
Definition: dynload.h:158
OSDynLoadFreeFn dynLoadFreeFn
Definition: dynload.h:167
OSDynLoad_NotifyData * notifyData
Definition: dynload.h:161
uint32_t loadSectionSize
Definition: dynload.h:165
uint32_t readOffset
Definition: dynload.h:66
uint32_t dataSize
Definition: dynload.h:63
uint32_t dataSectionSize
Definition: dynload.h:163
uint32_t textAddr
Definition: dynload.h:57
uint32_t dataAddr
Definition: dynload.h:61
uint32_t dataOffset
Definition: dynload.h:62
void(* OSDynLoadFreeFn)(void *addr)
Definition: dynload.h:40
OSDynLoad_Error OSDynLoad_FindExport(OSDynLoad_Module module, OSDynLoad_ExportType exportType, char const *name, void **outAddr)
Retrieve the address of a function or data export from a module.
void * OSDynLoad_Module
Definition: dynload.h:18
BOOL OSDynLoad_GetRPLInfo(uint32_t first, uint32_t count, OSDynLoad_NotifyData *outInfos)
Get information about the currently loaded RPLs.
OSDynLoad_Error OSDynLoad_GetLoaderHeapStatistics(OSDynLoad_LoaderHeapStatistics *outLoaderHeapStatistics)
Get loader heap statistics.
OSDynLoad_Error OSDynLoad_AddNotifyCallback(OSDynLoadNotifyFunc notifyFn, void *userContext)
Registers a callback that's called whenever a new .rpl is loaded or unloaded.
OSDynLoad_Error OSDynLoad_GetAllocator(OSDynLoadAllocFn *outAllocFn, OSDynLoadFreeFn *outFreeFn)
Get the allocator functions used for dynamic loading.
OSDynLoad_EntryReason
Definition: dynload.h:48
OSDynLoad_Error
Definition: dynload.h:25
OSDynLoad_NotifyReason
Definition: dynload.h:200
OSDynLoad_Error OSDynLoad_SetTLSAllocator(OSDynLoadAllocFn allocFn, OSDynLoadFreeFn freeFn)
Set the allocator functions to use for thread local storage.
OSDynLoad_Error OSDynLoad_DelNotifyCallback(OSDynLoadNotifyFunc notifyFn, void *userContext)
Removes a previously added a callback.
int rpl_entry(OSDynLoad_Module module, OSDynLoad_EntryReason reason)
The prototype for an RPL entry point.
OSDynLoad_ExportType
Definition: dynload.h:42
OSDynLoad_Error OSDynLoad_Acquire(char const *name, OSDynLoad_Module *outModule)
Load a module.
OSDynLoad_Error OSDynLoad_GetModuleName(OSDynLoad_Module module, char *nameBuf, int32_t *nameBufSize)
Gets the name for a given module handle.
void(* OSDynLoadNotifyFunc)(OSDynLoad_Module module, void *userContext, OSDynLoad_NotifyReason notifyReason, OSDynLoad_NotifyData *infos)
Definition: dynload.h:205
int32_t OSDynLoad_GetNumberOfRPLs()
Gets the number of currently loaded RPLs.
OSDynLoad_Error OSDynLoad_GetTLSAllocator(OSDynLoadAllocFn *outAllocFn, OSDynLoadFreeFn *outFreeFn)
Get the allocator functions used for thread local storage.
OSDynLoad_Error OSDynLoad_SetAllocator(OSDynLoadAllocFn allocFn, OSDynLoadFreeFn freeFn)
Set the allocator functions to use for dynamic loading.
OSDynLoad_Error(* OSDynLoadAllocFn)(int32_t size, int32_t align, void **outAddr)
Definition: dynload.h:39
void OSDynLoad_Release(OSDynLoad_Module module)
Free a module handle returned from OSDynLoad_Acquire.
OSDynLoad_Error OSDynLoad_IsModuleLoaded(char const *name, OSDynLoad_Module *outModule)
Checks if a module is already loaded.
@ OS_DYNLOAD_LOADED
Definition: dynload.h:49
@ OS_DYNLOAD_UNLOADED
Definition: dynload.h:50
@ OS_DYNLOAD_INVALID_MODULE_NAME
Definition: dynload.h:30
@ OS_DYNLOAD_INVALID_ACQUIRE_PTR
Definition: dynload.h:31
@ OS_DYNLOAD_INVALID_MODULE_NAME_PTR
Definition: dynload.h:29
@ OS_DYNLOAD_EMPTY_MODULE_NAME
Definition: dynload.h:32
@ OS_DYNLOAD_OUT_OF_MEMORY
Definition: dynload.h:27
@ OS_DYNLOAD_OK
Definition: dynload.h:26
@ OS_DYNLOAD_TLS_ALLOCATOR_LOCKED
Definition: dynload.h:35
@ OS_DYNLOAD_INVALID_NOTIFY_PTR
Definition: dynload.h:28
@ OS_DYNLOAD_MODULE_NOT_FOUND
Definition: dynload.h:36
@ OS_DYNLOAD_INVALID_ALLOCATOR_PTR
Definition: dynload.h:33
@ OS_DYNLOAD_OUT_OF_SYSTEM_MEMORY
Definition: dynload.h:34
@ OS_DYNLOAD_NOTIFY_UNLOADED
Definition: dynload.h:201
@ OS_DYNLOAD_NOTIFY_LOADED
Definition: dynload.h:202
@ OS_DYNLOAD_EXPORT_FUNC
Definition: dynload.h:43
@ OS_DYNLOAD_EXPORT_DATA
Definition: dynload.h:44
int32_t BOOL
Definition: wut_types.h:7