libnx
env.h
Go to the documentation of this file.
1 /**
2  * @file env.h
3  * @brief Homebrew environment definitions and utilities.
4  * @author plutoo
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 
10 /// Structure representing an entry in the homebrew environment configuration.
11 typedef struct {
12  u32 Key; ///< Type of entry
13  u32 Flags; ///< Entry flags
14  u64 Value[2]; ///< Entry arguments (type-specific)
15 } ConfigEntry;
16 
17 /// Entry flags
18 enum {
19  EntryFlag_IsMandatory = BIT(0), ///< Specifies that the entry **must** be processed by the homebrew application.
20 };
21 
22 ///< Types of entry
23 enum {
24  EntryType_EndOfList=0, ///< Entry list terminator.
25  EntryType_MainThreadHandle=1, ///< Provides the handle to the main thread.
26  EntryType_NextLoadPath=2, ///< Provides a buffer containing information about the next homebrew application to load.
27  EntryType_OverrideHeap=3, ///< Provides heap override information.
28  EntryType_OverrideService=4, ///< Provides service override information.
29  EntryType_Argv=5, ///< Provides argv.
30  EntryType_SyscallAvailableHint=6, ///< Provides syscall availability hints.
31  EntryType_AppletType=7, ///< Provides APT applet type.
32  EntryType_AppletWorkaround=8, ///< Indicates that APT is broken and should not be used.
33  EntryType_StdioSockets=9, ///< Provides socket-based standard stream redirection information.
34  EntryType_ProcessHandle=10, ///< Provides the process handle.
35  EntryType_LastLoadResult=11 ///< Provides the last load result.
36 };
37 
38 /// Loader return function.
39 typedef void NORETURN (*LoaderReturnFn)(int result_code);
40 
41 /**
42  * @brief Parses the homebrew loader environment block (internally called).
43  * @param ctx Reserved.
44  * @param main_thread Reserved.
45  * @param saved_lr Reserved.
46  */
47 void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr);
48 
49 /// Retrieves the handle to the main thread.
51 /// Returns true if the application is running as NSO, otherwise NRO.
52 bool envIsNso(void);
53 
54 /// Returns true if the environment has a heap override.
55 bool envHasHeapOverride(void);
56 /// Returns the address of the overriden heap.
57 void* envGetHeapOverrideAddr(void);
58 /// Returns the size of the overriden heap.
60 
61 /// Returns true if the environment has an argv array.
62 bool envHasArgv(void);
63 /// Returns the pointer to the argv array.
64 void* envGetArgv(void);
65 
66 /**
67  * @brief Returns whether a syscall is hinted to be available.
68  * @param svc Syscall number to test.
69  * @returns true if the syscall is available.
70  */
71 bool envIsSyscallHinted(u8 svc);
72 
73 /// Returns the handle to the running homebrew process.
75 
76 /// Returns the loader's return function, to be called on program exit.
78 
79 /**
80  * @brief Configures the next homebrew application to load.
81  * @param path Path to the next homebrew application to load (.nro).
82  * @param argv Argument string to pass.
83  */
84 Result envSetNextLoad(const char* path, const char* argv);
85 
86 /// Returns true if the environment supports envSetNextLoad.
87 bool envHasNextLoad(void);
88 
89 /// Returns the Result from the last NRO.
u64 envGetHeapOverrideSize(void)
Returns the size of the overriden heap.
bool envIsNso(void)
Returns true if the application is running as NSO, otherwise NRO.
Provides the handle to the main thread.
Definition: env.h:25
Provides a buffer containing information about the next homebrew application to load.
Definition: env.h:26
u32 Key
Type of entry.
Definition: env.h:12
Provides syscall availability hints.
Definition: env.h:30
Specifies that the entry must be processed by the homebrew application.
Definition: env.h:19
u32 Handle
Kernel object handle.
Definition: types.h:45
Structure representing an entry in the homebrew environment configuration.
Definition: env.h:11
u32 Result
Function error code result type.
Definition: types.h:46
Provides the process handle.
Definition: env.h:34
Handle envGetOwnProcessHandle(void)
Returns the handle to the running homebrew process.
uint8_t u8
8-bit unsigned integer.
Definition: types.h:21
Provides APT applet type.
Definition: env.h:31
uint64_t u64
64-bit unsigned integer.
Definition: types.h:24
Provides argv.
Definition: env.h:29
uint32_t u32
32-bit unsigned integer.
Definition: types.h:23
Handle envGetMainThreadHandle(void)
Retrieves the handle to the main thread.
u32 Flags
Entry flags.
Definition: env.h:13
Entry list terminator.
Definition: env.h:24
bool envHasNextLoad(void)
Returns true if the environment supports envSetNextLoad.
bool envIsSyscallHinted(u8 svc)
Returns whether a syscall is hinted to be available.
Result envGetLastLoadResult(void)
Returns the Result from the last NRO.
Provides the last load result.
Definition: env.h:35
void * envGetArgv(void)
Returns the pointer to the argv array.
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:51
void(* LoaderReturnFn)(int result_code)
Loader return function.
Definition: env.h:39
void envSetup(void *ctx, Handle main_thread, LoaderReturnFn saved_lr)
Parses the homebrew loader environment block (internally called).
Result envSetNextLoad(const char *path, const char *argv)
Configures the next homebrew application to load.
bool envHasHeapOverride(void)
Returns true if the environment has a heap override.
Provides service override information.
Definition: env.h:28
bool envHasArgv(void)
Returns true if the environment has an argv array.
void * envGetHeapOverrideAddr(void)
Returns the address of the overriden heap.
Provides heap override information.
Definition: env.h:27
Indicates that APT is broken and should not be used.
Definition: env.h:32
Provides socket-based standard stream redirection information.
Definition: env.h:33
LoaderReturnFn envGetExitFuncPtr(void)
Returns the loader&#39;s return function, to be called on program exit.