muteki
Loading...
Searching...
No Matches
loader.h
Go to the documentation of this file.
1/*
2 * Copyright 2021-present dogtopus
3 * SPDX-License-Identifier: MIT
4 */
5
11#ifndef __MUTEKI_LOADER_H__
12#define __MUTEKI_LOADER_H__
13
14#include <muteki/common.h>
15#include <muteki/file.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
31
47
56 unsigned int unk_0x0;
60 unsigned int unk_0x4;
68 unsigned int unk_0xc;
72 void *unk_0x10;
76 unsigned char unk_0x14;
80 unsigned char size_high_8;
84 unsigned char unk_0x16;
88 unsigned char unk_0x17;
92 unsigned int unk_0x18;
96 unsigned int unk_0x1c;
98
111 void *parent_fd; /* Created by retype action */
119 size_t size;
127 short unk_0x14; /* _OpenSubFile sets this to 1 */
131 short unk_0x16;
135 unsigned int unk_0x18;
139 unsigned int unk_0x1c;
141
147 size_t mapped_size;
148 size_t mapped_offset;
149 size_t data_size;
150 size_t data_offset;
153
159 size_t base;
160 size_t size;
162
167typedef struct loader_image_info_s {
168 size_t bestape_code_size;
169 size_t bestape_data_size;
170 size_t bestape_bss_size;
171 size_t bestape_total_raw_size; /* Size of headers and all raw section data */
172 size_t bestape_total_size;
173 size_t bestape_header_size;
174 unsigned int bestape_checksum;
175 unsigned int unk_0x1c;
176 unsigned char unk_0x20[24];
178
183typedef struct loader_impl_s {
184 void *load;
185 void *load_into;
186 void *unload;
187 void *exec;
188 void *probe;
189 unsigned char *(*dlopen)(char *);
190 void *unk_0x18;
191 void *dlsym;
192 void *unk_0x20;
193 void *unk_0x24;
194 loader_resource_descriptor_t * (*open_resource_descriptor)(loader_file_descriptor_t *);
195 void (*close_resource_descriptor)(loader_resource_descriptor_t *);
197 int (*collect_image_info)(loader_file_descriptor_t *, loader_image_info_t *);
199
263
267typedef struct loader_applet_info_s {
271 unsigned short rom_magic;
275 unsigned short unused_0x2;
279 unsigned short rom_type;
283 unsigned short unused_0x4;
288 unsigned int exe_checksum;
296 unsigned char unused_0x10[0x74];
298
319extern loader_file_descriptor_t *_OpenFile(const char *pathname, const char *mode_or_subfile);
320
329extern loader_file_descriptor_t *_OpenFileW(const UTF16 *pathname, const void *mode_or_subfile);
330
339
348extern size_t _ReadFile(loader_file_descriptor_t *ldrfd, void *buf, size_t size);
349
359extern int _FseekFile(loader_file_descriptor_t *ldrfd, size_t offset, int whence);
360
367extern ssize_t _FileSize(loader_file_descriptor_t *ldrfd);
368
380extern loader_file_descriptor_t *_OpenSubFile(loader_file_descriptor_t *parent, size_t base, size_t max_size);
381
388extern ssize_t _TellFile(loader_file_descriptor_t *ldrfd);
389
399extern int RunApplicationA(const char *pathname,int subroutine,void *applet_arg1,void *applet_arg2);
400
410extern size_t GetApplicationNameA(const char *pathname, UTF16 *out_name, size_t max_size);
411
419extern loader_loaded_t *LoadProgramA(const char *pathname);
420
428extern int FreeProgram(loader_loaded_t *applet);
429
448extern int ExecuteProgram(loader_loaded_t *applet, int subroutine, const void *applet_arg1, const void *applet_arg2);
449
456extern const char *GetCurrentPathA(void);
457
465extern loader_loaded_t *ProgramIsRunningA(const char *pathname);
466
476extern int RunApplicationW(const UTF16 *pathname, int subroutine, void *applet_arg1, void *applet_arg2);
477
488extern size_t GetApplicationNameW(const UTF16 *pathname, UTF16 *out_name, size_t max_size);
489
497extern loader_loaded_t *LoadProgramW(const UTF16 *pathname);
498
505extern const UTF16 *GetCurrentPathW(void);
506
514extern loader_loaded_t *ProgramIsRunningW(const UTF16 *pathname);
515
524
532extern loader_loaded_t *LoadHFileProgramA(loader_file_descriptor_t *ldrfd, const char *pathname);
533
552extern loader_loaded_t *GetApplicationProcA(const char *pathname);
553
562extern int StayResidentProgramA(const char *pathname);
563
572extern int UnStayResidentProgramA(const char *pathname);
573
582
604
613extern int StayResidentProgramW(const UTF16 *pathname);
614
623extern int UnStayResidentProgramW(const UTF16 *pathname);
624
633extern int GetApplicationHeadInfoA(const char *pathname,loader_applet_info_t *info);
634
643extern int GetApplicationHeadInfoW(const UTF16 *pathname, loader_applet_info_t *info);
644
645#ifdef __cplusplus
646} // extern "C"
647#endif
648
649#endif // __MUTEKI_LOADER_H__
Common include file for all muteki-shims headers.
#define UTF16
"Portable" Besta UTF-16 type used by other headers.
Definition common.h:54
Low-level and built-in high-level file operation API.
struct loader_impl_s loader_impl_t
Loader implementation vtable.
loader_file_descriptor_t * _OpenFile(const char *pathname, const char *mode_or_subfile)
Open a loader file descriptor from a file.
int GetApplicationHeadInfoW(const UTF16 *pathname, loader_applet_info_t *info)
Obtain information on loaded applet by its LFN pathname.
struct loader_file_descriptor_s loader_file_descriptor_t
File descriptor specific to loader.
int UnStayResidentProgramW(const UTF16 *pathname)
Unmark a loaded applet as stay resident by its LFN pathname.
loader_loaded_t * LoadHFileProgramA(loader_file_descriptor_t *ldrfd, const char *pathname)
Load an applet executable from a loader file descriptor.
int StayResidentProgramW(const UTF16 *pathname)
Mark a loaded applet as stay resident by its LFN pathname.
struct loader_cart_descriptor_s loader_cart_descriptor_t
Cart file descriptor.
const UTF16 * GetCurrentPathW(void)
Get the path to the current running executable (argv[0]). (UTF-16 variant)
loader_file_descriptor_t * _OpenSubFile(loader_file_descriptor_t *parent, size_t base, size_t max_size)
Open a sub-file from a parent loader file descriptor.
const char * GetCurrentPathA(void)
Get the path to the current running executable (argv[0]).
loader_loaded_t * ProgramIsRunningA(const char *pathname)
Return the instance of a running applet by its DOS 8.3 path name.
int RunApplicationW(const UTF16 *pathname, int subroutine, void *applet_arg1, void *applet_arg2)
Load and execute an applet by its LFN pathname.
loader_loaded_t * LoadProgramA(const char *pathname)
Load an applet executable.
struct loader_resource_subfile_request_s loader_resource_subfile_request_t
Resource descriptor subfile request.
struct loader_loaded_s loader_loaded_t
Loaded applet executable.
loader_loaded_t * GetApplicationProcA(const char *pathname)
Search and return the applet instance by DOS 8.3 pathname.
int _FseekFile(loader_file_descriptor_t *ldrfd, size_t offset, int whence)
Seek to a specific position in an opened sub-file.
int StayResidentProgramA(const char *pathname)
Mark a loaded applet as stay resident by its DOS 8.3 pathname.
size_t _ReadFile(loader_file_descriptor_t *ldrfd, void *buf, size_t size)
Read data from a loader file descriptor.
int _CloseFile(loader_file_descriptor_t *ldrfd)
Close a loader file descriptor.
loader_file_descriptor_t * _OpenFileW(const UTF16 *pathname, const void *mode_or_subfile)
Open a loader file descriptor from a file (LFN path).
struct applet_args_v4_s applet_args_v4_t
Applet argument passing V4 struct.
loader_loaded_t * LoadHFileProgramW(loader_file_descriptor_t *ldrfd, const UTF16 *pathname)
Load an applet executable from a loader file descriptor.
loader_loaded_t * GetApplicationProcW(const UTF16 *pathname)
Search and return the applet instance by LFN.
ssize_t _TellFile(loader_file_descriptor_t *ldrfd)
Get the current offset of sub-file.
size_t GetApplicationNameA(const char *pathname, UTF16 *out_name, size_t max_size)
Get the title name of the ROM file.
int FreeProgram(loader_loaded_t *applet)
Unload a loaded applet.
int GetApplicationHeadInfoA(const char *pathname, loader_applet_info_t *info)
Obtain information on loaded applet by its DOS 8.3 pathname.
int CheckProgramIsStayResident(loader_loaded_t *applet)
Check if an loaded applet has been set to stay resident.
int ExecuteProgram(loader_loaded_t *applet, int subroutine, const void *applet_arg1, const void *applet_arg2)
Invoke a specific subroutine of the loaded applet with arguments.
loader_loaded_t * ProgramIsRunningW(const UTF16 *pathname)
Return the instance of a running applet by its LFN.
int UnStayResidentProgramA(const char *pathname)
Unmark a loaded applet as stay resident by its DOS 8.3 pathname.
struct loader_image_info_s loader_image_info_t
Executable image info.
applet_subroutine_e
Definition loader.h:25
@ APPLET_SUBROUTINE_RESET_STATES
Definition loader.h:29
@ APPLET_SUBROUTINE_MAIN
Definition loader.h:27
int RunApplicationA(const char *pathname, int subroutine, void *applet_arg1, void *applet_arg2)
Load and execute an applet by its DOS 8.3 pathname.
loader_loaded_t * LoadProgramW(const UTF16 *pathname)
Load an applet executable. (UTF-16 variant)
struct loader_resource_descriptor_s loader_resource_descriptor_t
Resource descriptor.
size_t GetApplicationNameW(const UTF16 *pathname, UTF16 *out_name, size_t max_size)
Get the title name of the ROM file (LFN path).
struct loader_applet_info_s loader_applet_info_t
Basic info on a loaded applet.
ssize_t _FileSize(loader_file_descriptor_t *ldrfd)
Get the size of sub-file.
Applet argument passing V4 struct.
Definition loader.h:37
char * dospath
Definition loader.h:39
void ** applet_arg1
Definition loader.h:43
void ** applet_arg2
Definition loader.h:45
int * subroutine
Definition loader.h:41
Basic info on a loaded applet.
Definition loader.h:267
unsigned short rom_type
Type field inside the ROM spec.
Definition loader.h:279
unsigned short unused_0x4
Unknown, seems unused.
Definition loader.h:283
unsigned short unused_0x2
Unknown, seems unused.
Definition loader.h:275
unsigned char unused_0x10[0x74]
Unknown, seems unused.
Definition loader.h:296
size_t exe_raw_size
File size of the executable.
Definition loader.h:292
unsigned short rom_magic
Magic bytes of ROM spec.
Definition loader.h:271
unsigned int exe_checksum
Checksum of the executable file.
Definition loader.h:288
Cart file descriptor.
Definition loader.h:52
unsigned char unk_0x16
Unknown.
Definition loader.h:84
unsigned int unk_0xc
Unknown.
Definition loader.h:68
unsigned char size_high_8
High 8 bits of the capacity of the cart.
Definition loader.h:80
void * unk_0x10
Unknown.
Definition loader.h:72
unsigned char unk_0x17
Unknown.
Definition loader.h:88
unsigned int unk_0x1c
Unknown.
Definition loader.h:96
unsigned int unk_0x4
Unknown.
Definition loader.h:60
unsigned int unk_0x18
Unknown.
Definition loader.h:92
size_t size_low_32
Low 32 bits of the capacity of the cart.
Definition loader.h:64
unsigned int unk_0x0
Unknown.
Definition loader.h:56
unsigned char unk_0x14
Unknown.
Definition loader.h:76
File descriptor specific to loader.
Definition loader.h:102
loader_cart_descriptor_t * cart
ROM cart descriptor.
Definition loader.h:106
size_t size
Base offset of this sub-file, within parent_fd.
Definition loader.h:119
size_t subfile_offset
Current ftell offset of this sub-file.
Definition loader.h:123
void * parent_fd
Parent file descriptor.
Definition loader.h:111
unsigned int unk_0x1c
Unknown.
Definition loader.h:139
size_t subfile_base
Base offset of the sub-file.
Definition loader.h:115
short unk_0x16
Unknown.
Definition loader.h:131
unsigned int unk_0x18
Unknown.
Definition loader.h:135
short unk_0x14
Unknown. Seems to be unused.
Definition loader.h:127
Executable image info.
Definition loader.h:167
Loader implementation vtable.
Definition loader.h:183
Loaded applet executable.
Definition loader.h:203
unsigned char * mapped_executable
Mapped executable.
Definition loader.h:223
short unk_0x64
Unknown.
Definition loader.h:231
unsigned char unk_0x78[28]
Unknown.
Definition loader.h:256
char path[80]
DOS 8.3 path to executable file.
Definition loader.h:207
loader_file_descriptor_t * asset_file
Assets bundle file descriptor.
Definition loader.h:248
unsigned int rom_spec_offset_0xc
Unknown.
Definition loader.h:240
int active_refcount
Reference counter for currently active (running) instances.
Definition loader.h:219
int refcount
Reference counter.
Definition loader.h:215
void * path_lfn
LFN path.
Definition loader.h:244
loader_file_descriptor_t * ldrfd
Executable file descriptors.
Definition loader.h:252
short type
Executable type.
Definition loader.h:235
void * posixfd_rom
POSIX file descriptor of the executable.
Definition loader.h:261
loader_impl_t * loader
Loader implementation being used to load this applet.
Definition loader.h:227
int id
Numerical ID of loaded applet.
Definition loader.h:211
Resource descriptor.
Definition loader.h:146
Resource descriptor subfile request.
Definition loader.h:158