Merge pull request #182 from Steveice10/docs

Finish documentation in include/3ds and include/3ds/util.
This commit is contained in:
fincs 2015-10-05 00:07:48 +02:00
commit c0b4a4bae1
17 changed files with 904 additions and 362 deletions

View File

@ -1,21 +1,16 @@
/**
* @file console.h
/*! \file console.h * @brief 3ds stdio support.
\brief 3ds stdio support. *
* Provides stdio integration for printing to the 3DS screen as well as debug print
<div class="fileHeader"> * functionality provided by stderr.
Provides stdio integration for printing to the 3DS screen as well as debug print *
functionality provided by stderr. * General usage is to initialize the console by:
* consoleDemoInit()
General usage is to initialize the console by: * or to customize the console usage by:
consoleDemoInit() * consoleInit()
or to customize the console usage by:
consoleInit()
*/ */
#pragma once
#ifndef CONSOLE_H
#define CONSOLE_H
#include <3ds/types.h> #include <3ds/types.h>
#include <3ds/gfx.h> #include <3ds/gfx.h>
@ -24,73 +19,74 @@ consoleInit()
extern "C" { extern "C" {
#endif #endif
typedef bool(* ConsolePrint)(void* con, int c); /// A callback for printing a character.
typedef bool(*ConsolePrint)(void* con, int c);
//! a font struct for the console. /// A font struct for the console.
typedef struct ConsoleFont typedef struct ConsoleFont
{ {
u8* gfx; //!< A pointer to the font graphics u8* gfx; ///< A pointer to the font graphics
u16 asciiOffset; //!< Offset to the first valid character in the font table u16 asciiOffset; ///< Offset to the first valid character in the font table
u16 numChars; //!< Number of characters in the font graphics u16 numChars; ///< Number of characters in the font graphics
}ConsoleFont; }ConsoleFont;
/** \brief console structure used to store the state of a console render context. /**
* @brief console structure used to store the state of a console render context.
Default values from consoleGetDefault(); *
<div class="fixedFont"><pre> * Default values from consoleGetDefault();
PrintConsole defaultConsole = * <div class="fixedFont"><pre>
{ * PrintConsole defaultConsole =
//Font: * {
{ * //Font:
(u8*)default_font_bin, //font gfx * {
0, //first ascii character in the set * (u8*)default_font_bin, //font gfx
128, //number of characters in the font set * 0, //first ascii character in the set
}, * 128, //number of characters in the font set
0,0, //cursorX cursorY * },
0,0, //prevcursorX prevcursorY * 0,0, //cursorX cursorY
40, //console width * 0,0, //prevcursorX prevcursorY
30, //console height * 40, //console width
0, //window x * 30, //console height
0, //window y * 0, //window x
32, //window width * 0, //window y
24, //window height * 32, //window width
3, //tab size * 24, //window height
0, //font character offset * 3, //tab size
0, //print callback * 0, //font character offset
false //console initialized * 0, //print callback
}; * false //console initialized
</pre></div> * };
*/ * </pre></div>
*/
typedef struct PrintConsole typedef struct PrintConsole
{ {
ConsoleFont font; //!< font of the console. ConsoleFont font; ///< Font of the console.
u16 *frameBuffer; //!< framebuffer address. u16 *frameBuffer; ///< Framebuffer address.
int cursorX; /*!< Current X location of the cursor (as a tile offset by default) */ int cursorX; ///< Current X location of the cursor (as a tile offset by default)
int cursorY; /*!< Current Y location of the cursor (as a tile offset by default) */ int cursorY; ///< Current Y location of the cursor (as a tile offset by default)
int prevCursorX; /*!< Internal state */ int prevCursorX; ///< Internal state
int prevCursorY; /*!< Internal state */ int prevCursorY; ///< Internal state
int consoleWidth; /*!< Width of the console hardware layer in characters */ int consoleWidth; ///< Width of the console hardware layer in characters
int consoleHeight; /*!< Height of the console hardware layer in characters */ int consoleHeight; ///< Height of the console hardware layer in characters
int windowX; /*!< Window X location in characters (not implemented) */ int windowX; ///< Window X location in characters (not implemented)
int windowY; /*!< Window Y location in characters (not implemented) */ int windowY; ///< Window Y location in characters (not implemented)
int windowWidth; /*!< Window width in characters (not implemented) */ int windowWidth; ///< Window width in characters (not implemented)
int windowHeight; /*!< Window height in characters (not implemented) */ int windowHeight; ///< Window height in characters (not implemented)
int tabSize; /*!< Size of a tab*/ int tabSize; ///< Size of a tab
int fg; /*!< foreground color*/ int fg; ///< Foreground color
int bg; /*!< background color*/ int bg; ///< Background color
int flags; /*!< reverse/bright flags*/ int flags; ///< Reverse/bright flags
ConsolePrint PrintChar; /*!< callback for printing a character. Should return true if it has handled rendering the graphics ConsolePrint PrintChar; ///< Callback for printing a character. Should return true if it has handled rendering the graphics (else the print engine will attempt to render via tiles).
(else the print engine will attempt to render via tiles) */
bool consoleInitialised; /*!< True if the console is initialized */ bool consoleInitialised; ///< True if the console is initialized
}PrintConsole; }PrintConsole;
#define CONSOLE_COLOR_BOLD (1<<0) #define CONSOLE_COLOR_BOLD (1<<0)
@ -103,58 +99,61 @@ typedef struct PrintConsole
#define CONSOLE_CONCEAL (1<<7) #define CONSOLE_CONCEAL (1<<7)
#define CONSOLE_CROSSED_OUT (1<<8) #define CONSOLE_CROSSED_OUT (1<<8)
//! Console debug devices supported by libnds. /// Console debug devices supported by libnds.
typedef enum { typedef enum {
debugDevice_NULL, //!< swallows prints to stderr debugDevice_NULL, ///< swallows prints to stderr
debugDevice_3DMOO, //!< Directs stderr debug statements to 3dmoo debugDevice_3DMOO, ///< Directs stderr debug statements to 3dmoo
debugDevice_CONSOLE, //!< Directs stderr debug statements to 3DS console window debugDevice_CONSOLE, ///< Directs stderr debug statements to 3DS console window
} debugDevice; } debugDevice;
/*! \brief Loads the font into the console /**
\param console pointer to the console to update, if NULL it will update the current console * @brief Loads the font into the console.
\param font the font to load * @param console Pointer to the console to update, if NULL it will update the current console.
* @param font The font to load.
*/ */
void consoleSetFont(PrintConsole* console, ConsoleFont* font); void consoleSetFont(PrintConsole* console, ConsoleFont* font);
/*! \brief Sets the print window /**
\param console console to set, if NULL it will set the current console window * @brief Sets the print window.
\param x x location of the window * @param console Console to set, if NULL it will set the current console window.
\param y y location of the window * @param x X location of the window.
\param width width of the window * @param y Y location of the window.
\param height height of the window * @param width Width of the window.
* @param height Height of the window.
*/ */
void consoleSetWindow(PrintConsole* console, int x, int y, int width, int height); void consoleSetWindow(PrintConsole* console, int x, int y, int width, int height);
/*! \brief Gets a pointer to the console with the default values /**
this should only be used when using a single console or without changing the console that is returned, other wise use consoleInit() * @brief Gets a pointer to the console with the default values.
\return A pointer to the console with the default values * This should only be used when using a single console or without changing the console that is returned, otherwise use consoleInit().
* @return A pointer to the console with the default values.
*/ */
PrintConsole* consoleGetDefault(void); PrintConsole* consoleGetDefault(void);
/*! \brief Make the specified console the render target /**
\param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console) * @brief Make the specified console the render target.
\return a pointer to the previous console * @param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)).
* @return A pointer to the previous console.
*/ */
PrintConsole *consoleSelect(PrintConsole* console); PrintConsole *consoleSelect(PrintConsole* console);
/*! \brief Initialise the console. /**
\param screen The screen to use for the console * @brief Initialise the console.
\param console A pointer to the console data to initialze (if it's NULL, the default console will be used) * @param screen The screen to use for the console.
\return A pointer to the current console. * @param console A pointer to the console data to initialize (if it's NULL, the default console will be used).
* @return A pointer to the current console.
*/ */
PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console); PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console);
/*! \brief Initializes debug console output on stderr to the specified device /**
\param device The debug device (or devices) to output debug print statements to * @brief Initializes debug console output on stderr to the specified device.
* @param device The debug device (or devices) to output debug print statements to.
*/ */
void consoleDebugInit(debugDevice device); void consoleDebugInit(debugDevice device);
/// Clears the screan by using iprintf("\x1b[2J");
//! Clears the screan by using iprintf("\x1b[2J");
void consoleClear(void); void consoleClear(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif

View File

@ -13,10 +13,11 @@
#define RGB565(r,g,b) (((b)&0x1f)|(((g)&0x3f)<<5)|(((r)&0x1f)<<11)) #define RGB565(r,g,b) (((b)&0x1f)|(((g)&0x3f)<<5)|(((r)&0x1f)<<11))
#define RGB8_to_565(r,g,b) (((b)>>3)&0x1f)|((((g)>>2)&0x3f)<<5)|((((r)>>3)&0x1f)<<11) #define RGB8_to_565(r,g,b) (((b)>>3)&0x1f)|((((g)>>2)&0x3f)<<5)|((((r)>>3)&0x1f)<<11)
/// Available screens.
typedef enum typedef enum
{ {
GFX_TOP = 0, GFX_TOP = 0, ///< Top screen
GFX_BOTTOM = 1 GFX_BOTTOM = 1 ///< Bottom screen
}gfxScreen_t; }gfxScreen_t;
/** /**
@ -29,7 +30,6 @@ typedef enum
{ {
GFX_LEFT = 0, ///< Left eye framebuffer GFX_LEFT = 0, ///< Left eye framebuffer
GFX_RIGHT = 1,///< Right eye framebuffer GFX_RIGHT = 1,///< Right eye framebuffer
// GFX_BOTTOM = 0
}gfx3dSide_t; }gfx3dSide_t;

View File

@ -32,9 +32,7 @@ typedef enum
GX_TRANSFER_SCALE_XY = 2, ///< 2x2 anti-aliasing GX_TRANSFER_SCALE_XY = 2, ///< 2x2 anti-aliasing
} GX_TRANSFER_SCALE; } GX_TRANSFER_SCALE;
/** /// GX transfer control flags
* @brief GX transfer control flags
*/
typedef enum typedef enum
{ {
GX_FILL_TRIGGER = 0x001, ///< Trigger the PPF event GX_FILL_TRIGGER = 0x001, ///< Trigger the PPF event

View File

@ -7,11 +7,12 @@
#include <3ds/types.h> #include <3ds/types.h>
/// IPC buffer access rights.
typedef enum typedef enum
{ {
IPC_BUFFER_R = BIT(1), IPC_BUFFER_R = BIT(1), ///< Readable
IPC_BUFFER_W = BIT(2), IPC_BUFFER_W = BIT(2), ///< Writable
IPC_BUFFER_RW = IPC_BUFFER_R | IPC_BUFFER_W IPC_BUFFER_RW = IPC_BUFFER_R | IPC_BUFFER_W ///< Readable and Writable
} IPC_BufferRights; } IPC_BufferRights;

View File

@ -4,8 +4,6 @@
*/ */
#pragma once #pragma once
// Functions for allocating/deallocating memory from linear heap
/** /**
* @brief Allocates a 0x80-byte aligned buffer. * @brief Allocates a 0x80-byte aligned buffer.
* @param size Size of the buffer to allocate. * @param size Size of the buffer to allocate.

View File

@ -4,8 +4,6 @@
*/ */
#pragma once #pragma once
// Functions for allocating/deallocating mappable memory
/** /**
* @brief Allocates a page-aligned buffer. * @brief Allocates a page-aligned buffer.
* @param size Size of the buffer to allocate. * @param size Size of the buffer to allocate.

View File

@ -13,20 +13,20 @@
#define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF) #define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF)
/** /**
* Converts an address from virtual (process) memory to physical memory. * @brief Converts an address from virtual (process) memory to physical memory.
* It is sometimes required by services or when using the GPU command buffer. * It is sometimes required by services or when using the GPU command buffer.
*/ */
u32 osConvertVirtToPhys(u32 vaddr); u32 osConvertVirtToPhys(u32 vaddr);
/** /**
* Converts 0x14* vmem to 0x30*. * @brief Converts 0x14* vmem to 0x30*.
* @return The input address when it's already within the new vmem. * @return The input address when it's already within the new vmem.
* @return 0 when outside of either LINEAR mem areas. * @return 0 when outside of either LINEAR mem areas.
*/ */
u32 osConvertOldLINEARMemToNew(u32 addr); u32 osConvertOldLINEARMemToNew(u32 addr);
/** /**
* @brief Basic information about a service error. * @brief Retreives basic information about a service error.
* @return A string of the summary of an error. * @return A string of the summary of an error.
* *
* This can be used to get some details about an error returned by a service call. * This can be used to get some details about an error returned by a service call.
@ -34,14 +34,16 @@ u32 osConvertOldLINEARMemToNew(u32 addr);
const char* osStrError(u32 error); const char* osStrError(u32 error);
/** /**
* @return the Firm version * @brief Gets the system's FIRM version.
* @return The FIRM version.
* *
* This can be used to compare system versions easily with @ref SYSTEM_VERSION. * This can be used to compare system versions easily with @ref SYSTEM_VERSION.
*/ */
u32 osGetFirmVersion(void); u32 osGetFirmVersion(void);
/** /**
* @return the kernel version * @brief Gets the system's kernel version.
* @return The kernel version.
* *
* This can be used to compare system versions easily with @ref SYSTEM_VERSION. * This can be used to compare system versions easily with @ref SYSTEM_VERSION.
* *
@ -52,7 +54,8 @@ u32 osGetFirmVersion(void);
u32 osGetKernelVersion(void); u32 osGetKernelVersion(void);
/** /**
* @return number of milliseconds since 1st Jan 1900 00:00. * @brief Gets the current time.
* @return The number of milliseconds since 1st Jan 1900 00:00.
*/ */
u64 osGetTime(void); u64 osGetTime(void);

View File

@ -1,35 +1,59 @@
/**
* @file romfs.h
* @brief RomFS driver.
*/
#pragma once #pragma once
#include <3ds/types.h> #include <3ds/types.h>
/// RomFS header.
typedef struct typedef struct
{ {
u32 headerSize; u32 headerSize; ///< Size of the header.
u32 dirHashTableOff, dirHashTableSize; u32 dirHashTableOff; ///< Offset of the directory hash table.
u32 dirTableOff, dirTableSize; u32 dirHashTableSize; ///< Size of the directory hash table.
u32 fileHashTableOff, fileHashTableSize; u32 dirTableOff; ///< Offset of the directory table.
u32 fileTableOff, fileTableSize; u32 dirTableSize; ///< Size of the directory table.
u32 fileDataOff; u32 fileHashTableOff; ///< Offset of the file hash table.
u32 fileHashTableSize; ///< Size of the file hash table.
u32 fileTableOff; ///< Offset of the file table.
u32 fileTableSize; ///< Size of the file table.
u32 fileDataOff; ///< Offset of the file data.
} romfs_header; } romfs_header;
/// RomFS directory.
typedef struct typedef struct
{ {
u32 parent, sibling; u32 parent; ///< Offset of the parent directory.
u32 childDir, childFile; u32 sibling; ///< Offset of the next sibling directory.
u32 nextHash; u32 childDir; ///< Offset of the first child directory.
u32 nameLen; u32 childFile; ///< Offset of the first file.
u16 name[]; u32 nextHash; ///< Directory hash table pointer.
u32 nameLen; ///< Name length.
u16 name[]; ///< Name. (UTF-16)
} romfs_dir; } romfs_dir;
/// RomFS file.
typedef struct typedef struct
{ {
u32 parent, sibling; u32 parent; ///< Offset of the parent directory.
u64 dataOff, dataSize; u32 sibling; ///< Offset of the next sibling file.
u32 nextHash; u64 dataOff; ///< Offset of the file's data.
u32 nameLen; u64 dataSize; ///< Length of the file's data.
u16 name[]; u32 nextHash; ///< File hash table pointer.
u32 nameLen; ///< Name length.
u16 name[]; ///< Name. (UTF-16)
} romfs_file; } romfs_file;
/// Initializes the RomFS driver.
Result romfsInit(void); Result romfsInit(void);
/**
* @brief Initializes the RomFS driver from a RomFS file.
* @param file Handle of the RomFS file.
* @param offset Offset of the RomFS within the file.
*/
Result romfsInitFromFile(Handle file, u32 offset); Result romfsInitFromFile(Handle file, u32 offset);
/// Exits the RomFS driver.
Result romfsExit(void); Result romfsExit(void);

View File

@ -6,12 +6,8 @@
#include <3ds/types.h> #include <3ds/types.h>
/** /// Initializes the SDMC driver.
* @brief Initializes the SDMC driver.
*/
Result sdmcInit(void); Result sdmcInit(void);
/** /// Exits the SDMC driver.
* @brief Exits the SDMC driver.
*/
Result sdmcExit(void); Result sdmcExit(void);

View File

@ -1,72 +1,75 @@
/**
* @file FS.h
* @brief Filesystem Services
*/
#pragma once #pragma once
#include <3ds/types.h> #include <3ds/types.h>
/*! @file FS.h /**
* @defgroup fs_open_flags FS Open Flags
* *
* Filesystem Services * @sa FSUSER_OpenFile
* @sa FSUSER_OpenFileDirectly
*
* @{
*/ */
/*! @defgroup fs_open_flags FS Open Flags /// Open file for read.
*
* @sa FSUSER_OpenFile
* @sa FSUSER_OpenFileDirectly
*
* @{
*/
/*! Open file for read. */
#define FS_OPEN_READ (1<<0) #define FS_OPEN_READ (1<<0)
/*! Open file for write. */ /// Open file for write.
#define FS_OPEN_WRITE (1<<1) #define FS_OPEN_WRITE (1<<1)
/*! Create file if it doesn't exist. */ /// Create file if it doesn't exist.
#define FS_OPEN_CREATE (1<<2) #define FS_OPEN_CREATE (1<<2)
/* @} */ /// @}
/*! @defgroup fs_create_attributes FS Create Attributes /**
* @defgroup fs_create_attributes FS Create Attributes
* *
* @sa FSUSER_OpenFile * @sa FSUSER_OpenFile
* @sa FSUSER_OpenFileDirectly * @sa FSUSER_OpenFileDirectly
* *
* @{ * @{
*/ */
/*! No attributes. */ /// No attributes.
#define FS_ATTRIBUTE_NONE (0x00000000) #define FS_ATTRIBUTE_NONE (0x00000000)
/*! Create with read-only attribute. */ /// Create with read-only attribute.
#define FS_ATTRIBUTE_READONLY (0x00000001) #define FS_ATTRIBUTE_READONLY (0x00000001)
/*! Create with archive attribute. */ /// Create with archive attribute.
#define FS_ATTRIBUTE_ARCHIVE (0x00000100) #define FS_ATTRIBUTE_ARCHIVE (0x00000100)
/*! Create with hidden attribute. */ /// Create with hidden attribute.
#define FS_ATTRIBUTE_HIDDEN (0x00010000) #define FS_ATTRIBUTE_HIDDEN (0x00010000)
/*! Create with directory attribute. */ /// Create with directory attribute.
#define FS_ATTRIBUTE_DIRECTORY (0x01000000) #define FS_ATTRIBUTE_DIRECTORY (0x01000000)
/*! @} */ /// @}
/*! @defgroup fs_write_flush_flags FS Flush Flags /**
* @defgroup fs_write_flush_flags FS Flush Flags
* *
* @sa FSFILE_Write * @sa FSFILE_Write
* *
* @{ * @{
*/ */
/*! Don't flush */ /// Don't flush
#define FS_WRITE_NOFLUSH (0x00000000) #define FS_WRITE_NOFLUSH (0x00000000)
/*! Flush */ /// Flush
#define FS_WRITE_FLUSH (0x00010001) #define FS_WRITE_FLUSH (0x00010001)
/* @} */ /// @}
/*! FS path type */ /// FS path type
typedef enum typedef enum
{ {
PATH_INVALID = 0, //!< Specifies an invalid path. PATH_INVALID = 0, ///< Specifies an invalid path.
PATH_EMPTY = 1, //!< Specifies an empty path. PATH_EMPTY = 1, ///< Specifies an empty path.
PATH_BINARY = 2, //!< Specifies a binary path, which is non-text based. PATH_BINARY = 2, ///< Specifies a binary path, which is non-text based.
PATH_CHAR = 3, //!< Specifies a text based path with a 8-bit byte per character. PATH_CHAR = 3, ///< Specifies a text based path with a 8-bit byte per character.
PATH_WCHAR = 4, //!< Specifies a text based path with a 16-bit short per character. PATH_WCHAR = 4, ///< Specifies a text based path with a 16-bit short per character.
} FS_pathType; } FS_pathType;
/*! FS archive ids */ /// FS archive ids
typedef enum typedef enum
{ {
ARCH_ROMFS = 0x3, ARCH_ROMFS = 0x3,
@ -83,48 +86,48 @@ typedef enum
ARCH_NAND_RO_WRITE_ACCESS = 0x1234567F, ARCH_NAND_RO_WRITE_ACCESS = 0x1234567F,
} FS_archiveIds; } FS_archiveIds;
/*! FS path */ /// FS path
typedef struct typedef struct
{ {
FS_pathType type; //!< FS path type. FS_pathType type; ///< FS path type.
u32 size; //!< FS path size. u32 size; ///< FS path size.
const u8 *data; //!< Pointer to FS path data. const u8 *data; ///< Pointer to FS path data.
} FS_path; } FS_path;
/*! FS archive */ /// FS archive
typedef struct typedef struct
{ {
u32 id; //!< Archive ID. u32 id; ///< Archive ID.
FS_path lowPath; //!< FS path. FS_path lowPath; ///< FS path.
Handle handleLow; //!< High word of handle. Handle handleLow; ///< High word of handle.
Handle handleHigh; //!< Low word of handle. Handle handleHigh; ///< Low word of handle.
} FS_archive; } FS_archive;
/*! Directory entry */ /// Directory entry
typedef struct typedef struct
{ {
// 0x00 // 0x00
u16 name[0x106]; //!< UTF-16 encoded name u16 name[0x106]; ///< UTF-16 encoded name
// 0x20C // 0x20C
u8 shortName[0x09]; //!< 8.3 file name u8 shortName[0x09]; ///< 8.3 file name
// 0x215 // 0x215
u8 unknown1; //!< ??? u8 unknown1; ///< ???
// 0x216 // 0x216
u8 shortExt[0x04]; //!< 8.3 file extension (set to spaces for directories) u8 shortExt[0x04]; ///< 8.3 file extension (set to spaces for directories)
// 0x21A // 0x21A
u8 unknown2; //!< ??? u8 unknown2; ///< ???
// 0x21B // 0x21B
u8 unknown3; //!< ??? u8 unknown3; ///< ???
// 0x21C // 0x21C
u8 isDirectory; //!< directory bit u8 isDirectory; ///< directory bit
// 0x21D // 0x21D
u8 isHidden; //!< hidden bit u8 isHidden; ///< hidden bit
// 0x21E // 0x21E
u8 isArchive; //!< archive bit u8 isArchive; ///< archive bit
// 0x21F // 0x21F
u8 isReadOnly; //!< read-only bit u8 isReadOnly; ///< read-only bit
// 0x220 // 0x220
u64 fileSize; //!< file size u64 fileSize; ///< file size
} FS_dirent; } FS_dirent;
Result fsInit(void); Result fsInit(void);

View File

@ -1,14 +1,65 @@
/**
* @file srv.h
* @brief Service API.
*/
#pragma once #pragma once
/// Initializes the service API.
Result srvInit(void); Result srvInit(void);
/// Exits the service API.
Result srvExit(void); Result srvExit(void);
/**
* @brief Gets the current service API session handle.
* @return The current service API session handle.
*/
Handle *srvGetSessionHandle(void); Handle *srvGetSessionHandle(void);
/// Registers the current process as a client to the service API.
Result srvRegisterClient(void); Result srvRegisterClient(void);
/**
* @brief Retrieves a service handle, bypassing the handle list.
* @param out Pointer to write the handle to.
* @param name Name of the service.
*/
Result srvGetServiceHandleDirect(Handle* out, const char* name); Result srvGetServiceHandleDirect(Handle* out, const char* name);
/**
* @brief Retrieves a service handle.
* @param out Pointer to write the handle to.
* @param name Name of the service.
*/
Result srvGetServiceHandle(Handle* out, const char* name); Result srvGetServiceHandle(Handle* out, const char* name);
/**
* @brief Registers the current process as a service.
* @param out Pointer to write the service handle to.
* @param name Name of the service.
* @param maxSessions Maximum number of sessions the service can handle.
*/
Result srvRegisterService(Handle* out, const char* name, int maxSessions); Result srvRegisterService(Handle* out, const char* name, int maxSessions);
/**
* @brief Unregisters the current process as a service.
* @param name Name of the service.
*/
Result srvUnregisterService(const char* name); Result srvUnregisterService(const char* name);
/// Initializes the srv:pm port.
Result srvPmInit(void); Result srvPmInit(void);
/**
* @brief Registers a process with srv:pm.
* @param procid ID of the process to register.
* @param count Number of services to register access to.
* @param serviceaccesscontrol Service access permissions of the process.
*/
Result srvRegisterProcess(u32 procid, u32 count, void *serviceaccesscontrol); Result srvRegisterProcess(u32 procid, u32 count, void *serviceaccesscontrol);
/**
* @brief Unregisters a process with srv:pm.
* @param procid ID of the process to unregister.
*/
Result srvUnregisterProcess(u32 procid); Result srvUnregisterProcess(u32 procid);

View File

@ -2,7 +2,6 @@
* @file svc.h * @file svc.h
* @brief Syscall wrappers. * @brief Syscall wrappers.
*/ */
#pragma once #pragma once
#include "types.h" #include "types.h"
@ -27,54 +26,55 @@ typedef enum {
MEMOP_UNMAP = 5, ///< Mirror unmapping MEMOP_UNMAP = 5, ///< Mirror unmapping
MEMOP_PROT = 6, ///< Change protection MEMOP_PROT = 6, ///< Change protection
MEMOP_REGION_APP = 0x100, MEMOP_REGION_APP = 0x100, ///< APPLICATION memory region.
MEMOP_REGION_SYSTEM = 0x200, MEMOP_REGION_SYSTEM = 0x200, ///< SYSTEM memory region.
MEMOP_REGION_BASE = 0x300, MEMOP_REGION_BASE = 0x300, ///< BASE memory region.
MEMOP_OP_MASK = 0xFF, MEMOP_OP_MASK = 0xFF,
MEMOP_REGION_MASK = 0xF00, MEMOP_REGION_MASK = 0xF00,
MEMOP_LINEAR_FLAG = 0x10000, ///< Flag for linear memory operations MEMOP_LINEAR_FLAG = 0x10000, ///< Flag for linear memory operations
MEMOP_ALLOC_LINEAR = MEMOP_LINEAR_FLAG | MEMOP_ALLOC, MEMOP_ALLOC_LINEAR = MEMOP_LINEAR_FLAG | MEMOP_ALLOC, ///< Allocates linear memory.
} MemOp; } MemOp;
/// The state of a memory block.
typedef enum { typedef enum {
MEMSTATE_FREE = 0, MEMSTATE_FREE = 0, ///< Free memory
MEMSTATE_RESERVED = 1, MEMSTATE_RESERVED = 1, ///< Reserved memory
MEMSTATE_IO = 2, MEMSTATE_IO = 2, ///< I/O memory
MEMSTATE_STATIC = 3, MEMSTATE_STATIC = 3, ///< Static memory
MEMSTATE_CODE = 4, MEMSTATE_CODE = 4, ///< Code memory
MEMSTATE_PRIVATE = 5, MEMSTATE_PRIVATE = 5, ///< Private memory
MEMSTATE_SHARED = 6, MEMSTATE_SHARED = 6, ///< Shared memory
MEMSTATE_CONTINUOUS = 7, MEMSTATE_CONTINUOUS = 7, ///< Continuous memory
MEMSTATE_ALIASED = 8, MEMSTATE_ALIASED = 8, ///< Aliased memory
MEMSTATE_ALIAS = 9, MEMSTATE_ALIAS = 9, ///< Alias memory
MEMSTATE_ALIASCODE = 10, MEMSTATE_ALIASCODE = 10, ///< Aliased code memory
MEMSTATE_LOCKED = 11 MEMSTATE_LOCKED = 11 ///< Locked memory
} MemState; } MemState;
/** /// Memory permission flags
* @brief Memory permission flags
*/
typedef enum { typedef enum {
MEMPERM_READ = 1, MEMPERM_READ = 1, ///< Readable
MEMPERM_WRITE = 2, MEMPERM_WRITE = 2, ///< Writable
MEMPERM_EXECUTE = 4, MEMPERM_EXECUTE = 4, ///< Executable
MEMPERM_DONTCARE = 0x10000000 MEMPERM_DONTCARE = 0x10000000 ///< Don't care
} MemPerm; } MemPerm;
/// Memory information.
typedef struct { typedef struct {
u32 base_addr; u32 base_addr; ///< Base address.
u32 size; u32 size; ///< Size.
u32 perm; ///< See @ref MemPerm u32 perm; ///< Memory permissions. See @ref MemPerm
u32 state; ///< See @ref MemState u32 state; ///< Memory state. See @ref MemState
} MemInfo; } MemInfo;
/// Memory page information.
typedef struct { typedef struct {
u32 flags; u32 flags; ///< Page flags.
} PageInfo; } PageInfo;
/// Arbitration modes.
typedef enum { typedef enum {
ARBITRATION_SIGNAL = 0, ///< Signal #value threads for wake-up. ARBITRATION_SIGNAL = 0, ///< Signal #value threads for wake-up.
ARBITRATION_WAIT_IF_LESS_THAN = 1, ///< If the memory at the address is strictly lower than #value, then wait for signal. ARBITRATION_WAIT_IF_LESS_THAN = 1, ///< If the memory at the address is strictly lower than #value, then wait for signal.
@ -91,8 +91,9 @@ typedef enum {
///@name Multithreading ///@name Multithreading
///@{ ///@{
/// Types of thread info.
typedef enum { typedef enum {
THREADINFO_TYPE_UNKNOWN THREADINFO_TYPE_UNKNOWN ///< Unknown.
} ThreadInfoType; } ThreadInfoType;
/// Pseudo handle for the current thread /// Pseudo handle for the current thread
@ -103,127 +104,148 @@ typedef enum {
///@name Debugging ///@name Debugging
///@{ ///@{
/// Reasons for a process event.
typedef enum { typedef enum {
REASON_CREATE = 1, REASON_CREATE = 1, ///< Process created.
REASON_ATTACH = 2 REASON_ATTACH = 2 ///< Process attached.
} ProcessEventReason; } ProcessEventReason;
/// Event relating to a process.
typedef struct { typedef struct {
u64 program_id; u64 program_id; ///< ID of the program.
u8 process_name[8]; u8 process_name[8]; ///< Name of the process.
u32 process_id; u32 process_id; ///< ID of the process.
u32 reason; ///< See @ref ProcessEventReason u32 reason; ///< Reason for the event. See @ref ProcessEventReason
} ProcessEvent; } ProcessEvent;
/// Reasons for an exit process event.
typedef enum { typedef enum {
EXITPROCESS_EVENT_NONE = 0, EXITPROCESS_EVENT_NONE = 0, ///< No reason.
EXITPROCESS_EVENT_TERMINATE = 1, EXITPROCESS_EVENT_TERMINATE = 1, ///< Process terminated.
EXITPROCESS_EVENT_UNHANDLED_EXCEPTION = 2 EXITPROCESS_EVENT_UNHANDLED_EXCEPTION = 2 ///< Unhandled exception occurred.
} ExitProcessEventReason; } ExitProcessEventReason;
/// Event relating to the exiting of a process.
typedef struct { typedef struct {
u32 reason; ///< See @ref ExitProcessEventReason u32 reason; ///< Reason for exiting. See @ref ExitProcessEventReason
} ExitProcessEvent; } ExitProcessEvent;
/// Event relating to the creation of a thread.
typedef struct { typedef struct {
u32 creator_thread_id; u32 creator_thread_id; ///< ID of the creating thread.
u32 base_addr; u32 base_addr; ///< Base address.
u32 entry_point; u32 entry_point; ///< Entry point of the thread.
} CreateThreadEvent; } CreateThreadEvent;
/// Reasons for an exit thread event.
typedef enum { typedef enum {
EXITTHREAD_EVENT_NONE = 0, EXITTHREAD_EVENT_NONE = 0, ///< No reason.
EXITTHREAD_EVENT_TERMINATE = 1, EXITTHREAD_EVENT_TERMINATE = 1, ///< Thread terminated.
EXITTHREAD_EVENT_UNHANDLED_EXC = 2, EXITTHREAD_EVENT_UNHANDLED_EXC = 2, ///< Unhandled exception occurred.
EXITTHREAD_EVENT_TERMINATE_PROCESS = 3 EXITTHREAD_EVENT_TERMINATE_PROCESS = 3 ///< Process terminated.
} ExitThreadEventReason; } ExitThreadEventReason;
/// Event relating to the exiting of a thread.
typedef struct { typedef struct {
u32 reason; ///< See @ref ExitThreadEventReason u32 reason; ///< Reason for exiting. See @ref ExitThreadEventReason
} ExitThreadEvent; } ExitThreadEvent;
/// Reasons for a user break.
typedef enum { typedef enum {
USERBREAK_PANIC = 0, USERBREAK_PANIC = 0, ///< Panic.
USERBREAK_ASSERT = 1, USERBREAK_ASSERT = 1, ///< Assertion failed.
USERBREAK_USER = 2 USERBREAK_USER = 2 ///< User related.
} UserBreakType; } UserBreakType;
/// Reasons for an exception event.
typedef enum { typedef enum {
EXC_EVENT_UNDEFINED_INSTRUCTION = 0, ///< arg: (None) EXC_EVENT_UNDEFINED_INSTRUCTION = 0, ///< Undefined instruction. arg: (None)
EXC_EVENT_UNKNOWN1 = 1, ///< arg: (None) EXC_EVENT_UNKNOWN1 = 1, ///< Unknown. arg: (None)
EXC_EVENT_UNKNOWN2 = 2, ///< arg: address EXC_EVENT_UNKNOWN2 = 2, ///< Unknown. arg: address
EXC_EVENT_UNKNOWN3 = 3, ///< arg: address EXC_EVENT_UNKNOWN3 = 3, ///< Unknown. arg: address
EXC_EVENT_ATTACH_BREAK = 4, ///< arg: (None) EXC_EVENT_ATTACH_BREAK = 4, ///< Attached break. arg: (None)
EXC_EVENT_BREAKPOINT = 5, ///< arg: (None) EXC_EVENT_BREAKPOINT = 5, ///< Breakpoint reached. arg: (None)
EXC_EVENT_USER_BREAK = 6, ///< arg: @ref UserBreakType EXC_EVENT_USER_BREAK = 6, ///< User break occurred. arg: @ref UserBreakType
EXC_EVENT_DEBUGGER_BREAK = 7, ///< arg: (None) EXC_EVENT_DEBUGGER_BREAK = 7, ///< Debugger break occurred. arg: (None)
EXC_EVENT_UNDEFINED_SYSCALL = 8 ///< arg: attempted syscall EXC_EVENT_UNDEFINED_SYSCALL = 8 ///< Undefined syscall. arg: attempted syscall
} ExceptionEventType; } ExceptionEventType;
/// Event relating to exceptions.
typedef struct { typedef struct {
u32 type; ///< See @ref ExceptionEventType u32 type; ///< Type of event. See @ref ExceptionEventType
u32 address; u32 address; ///< Address of the exception.
u32 argument; ///< See @ref ExceptionEventType u32 argument; ///< Event argument. See @ref ExceptionEventType
} ExceptionEvent; } ExceptionEvent;
/// Event relating to the scheduler.
typedef struct { typedef struct {
u64 clock_tick; u64 clock_tick; ///< Clock tick that the event occurred.
} SchedulerInOutEvent; } SchedulerInOutEvent;
/// Event relating to syscalls.
typedef struct { typedef struct {
u64 clock_tick; u64 clock_tick; ///< Clock tick that the event occurred.
u32 syscall; u32 syscall; ///< Syscall sent/received.
} SyscallInOutEvent; } SyscallInOutEvent;
/// Event relating to debug output.
typedef struct { typedef struct {
u32 string_addr; u32 string_addr; ///< Address of the outputted string.
u32 string_size; u32 string_size; ///< Size of the outputted string.
} OutputStringEvent; } OutputStringEvent;
/// Event relating to the mapping of memory.
typedef struct { typedef struct {
u32 mapped_addr; u32 mapped_addr; ///< Mapped address.
u32 mapped_size; u32 mapped_size; ///< Mapped size.
u32 memperm; u32 memperm; ///< Memory permissions. See @ref MemPerm
u32 memstate; u32 memstate; ///< Memory state. See @ref MemState
} MapEvent; } MapEvent;
/// Debug event type.
typedef enum { typedef enum {
DBG_EVENT_PROCESS = 0, DBG_EVENT_PROCESS = 0, ///< Process event.
DBG_EVENT_CREATE_THREAD = 1, DBG_EVENT_CREATE_THREAD = 1, ///< Thread creation event.
DBG_EVENT_EXIT_THREAD = 2, DBG_EVENT_EXIT_THREAD = 2, ///< Thread exit event.
DBG_EVENT_EXIT_PROCESS = 3, DBG_EVENT_EXIT_PROCESS = 3, ///< Process exit event.
DBG_EVENT_EXCEPTION = 4, DBG_EVENT_EXCEPTION = 4, ///< Exception event.
DBG_EVENT_DLL_LOAD = 5, DBG_EVENT_DLL_LOAD = 5, ///< DLL load event.
DBG_EVENT_DLL_UNLOAD = 6, DBG_EVENT_DLL_UNLOAD = 6, ///< DLL unload event.
DBG_EVENT_SCHEDULE_IN = 7, DBG_EVENT_SCHEDULE_IN = 7, ///< Schedule in event.
DBG_EVENT_SCHEDULE_OUT = 8, DBG_EVENT_SCHEDULE_OUT = 8, ///< Schedule out event.
DBG_EVENT_SYSCALL_IN = 9, DBG_EVENT_SYSCALL_IN = 9, ///< Syscall in event.
DBG_EVENT_SYSCALL_OUT = 10, DBG_EVENT_SYSCALL_OUT = 10, ///< Syscall out event.
DBG_EVENT_OUTPUT_STRING = 11, DBG_EVENT_OUTPUT_STRING = 11, ///< Output string event.
DBG_EVENT_MAP = 12 DBG_EVENT_MAP = 12 ///< Map event.
} DebugEventType; } DebugEventType;
/// Information about a debug event.
typedef struct { typedef struct {
u32 type; ///< See @ref DebugEventType u32 type; ///< Type of event. See @ref DebugEventType
u32 thread_id; u32 thread_id; ///< ID of the thread.
u32 unknown[2]; u32 unknown[2]; ///< Unknown data.
union { union {
ProcessEvent process; ProcessEvent process; ///< Process event data.
CreateThreadEvent create_thread; CreateThreadEvent create_thread; ///< Thread creation event data.
ExitThreadEvent exit_thread; ExitThreadEvent exit_thread; ///< Thread exit event data.
ExitProcessEvent exit_process; ExitProcessEvent exit_process; ///< Process exit event data.
ExceptionEvent exception; ExceptionEvent exception; ///< Exception event data.
/* TODO: DLL_LOAD */ /* TODO: DLL_LOAD */
/* TODO: DLL_UNLOAD */ /* TODO: DLL_UNLOAD */
SchedulerInOutEvent scheduler; SchedulerInOutEvent scheduler; ///< Schedule in/out event data.
SyscallInOutEvent syscall; SyscallInOutEvent syscall; ///< Syscall in/out event data.
OutputStringEvent output_string; OutputStringEvent output_string; ///< Output string event data.
MapEvent map; MapEvent map; ///< Map event data.
}; };
} DebugEventInfo; } DebugEventInfo;
///@} ///@}
/**
* @brief Gets the thread local storage buffer.
* @return The thread local storage bufger.
*/
static inline void* getThreadLocalStorage(void) static inline void* getThreadLocalStorage(void)
{ {
void* ret; void* ret;
@ -231,11 +253,19 @@ static inline void* getThreadLocalStorage(void)
return ret; return ret;
} }
/**
* @brief Gets the thread command buffer.
* @return The thread command bufger.
*/
static inline u32* getThreadCommandBuffer(void) static inline u32* getThreadCommandBuffer(void)
{ {
return (u32*)((u8*)getThreadLocalStorage() + 0x80); return (u32*)((u8*)getThreadLocalStorage() + 0x80);
} }
/**
* @brief Gets the thread static buffer.
* @return The thread static bufger.
*/
static inline u32* getThreadStaticBuffers(void) static inline u32* getThreadStaticBuffers(void)
{ {
return (u32*)((u8*)getThreadLocalStorage() + 0x180); return (u32*)((u8*)getThreadLocalStorage() + 0x180);
@ -243,7 +273,6 @@ static inline u32* getThreadStaticBuffers(void)
///@name Memory management ///@name Memory management
///@{ ///@{
/** /**
* @brief Controls memory mapping * @brief Controls memory mapping
* @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0. * @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0.
@ -281,55 +310,183 @@ Result svcControlProcessMemory(Handle process, u32 addr0, u32 addr1, u32 size, u
/** /**
* @brief Creates a block of shared memory * @brief Creates a block of shared memory
* @param memblock Pointer to store the handle of the block * @param[out] memblock Pointer to store the handle of the block
* @param addr Address of the memory to map, page-aligned. So its alignment must be 0x1000. * @param addr Address of the memory to map, page-aligned. So its alignment must be 0x1000.
* @param size Size of the memory to map, a multiple of 0x1000. * @param size Size of the memory to map, a multiple of 0x1000.
* @param my_perm Memory permissions for the current process * @param my_perm Memory permissions for the current process
* @param my_perm Memory permissions for the other processes * @param other_perm Memory permissions for the other processes
* *
* @note The shared memory block, and its rights, are destroyed when the handle is closed. * @note The shared memory block, and its rights, are destroyed when the handle is closed.
*/ */
Result svcCreateMemoryBlock(Handle* memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm); Result svcCreateMemoryBlock(Handle* memblock, u32 addr, u32 size, MemPerm my_perm, MemPerm other_perm);
/**
* @brief Maps a block of shared memory
* @param memblock Handle of the block
* @param addr Address of the memory to map, page-aligned. So its alignment must be 0x1000.
* @param my_perm Memory permissions for the current process
* @param other_perm Memory permissions for the other processes
*
* @note The shared memory block, and its rights, are destroyed when the handle is closed.
*/
Result svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm); Result svcMapMemoryBlock(Handle memblock, u32 addr, MemPerm my_perm, MemPerm other_perm);
/**
* @brief Maps a block of process memory.
* @param process Handle of the process.
* @param startAddr Start address of the memory to map.
* @param endAddr End address of the memory to map.
*/
Result svcMapProcessMemory(Handle process, u32 startAddr, u32 endAddr); Result svcMapProcessMemory(Handle process, u32 startAddr, u32 endAddr);
/**
* @brief Unmaps a block of process memory.
* @param process Handle of the process.
* @param startAddr Start address of the memory to unmap.
* @param endAddr End address of the memory to unmap.
*/
Result svcUnmapProcessMemory(Handle process, u32 startAddr, u32 endAddr); Result svcUnmapProcessMemory(Handle process, u32 startAddr, u32 endAddr);
/**
* @brief Unmaps a block of shared memory
* @param memblock Handle of the block
* @param addr Address of the memory to unmap, page-aligned. So its alignment must be 0x1000.
*/
Result svcUnmapMemoryBlock(Handle memblock, u32 addr); Result svcUnmapMemoryBlock(Handle memblock, u32 addr);
Result svcStartInterProcessDma(Handle* dma, Handle dstProcess, void* dst, Handle srcProcess, const void* src, u32 size, void* dmaConfig);
Result svcStopDma(Handle dma);
Result svcGetDmaState(void* dmaState, Handle dma);
/** /**
* @brief Memory information query * @brief Begins an inter-process DMA.
* @param addr Virtual memory address * @param[out] dma Pointer to output the handle of the DMA to.
* @param dstProcess Destination process.
* @param dst Buffer to write data to.
* @param srcprocess Source process.
* @param src Buffer to read data from.
* @param size Size of the data to DMA.
* @param dmaConfig DMA configuration data.
*/
Result svcStartInterProcessDma(Handle* dma, Handle dstProcess, void* dst, Handle srcProcess, const void* src, u32 size, void* dmaConfig);
/**
* @brief Terminates an inter-process DMA.
* @param dma Handle of the DMA.
*/
Result svcStopDma(Handle dma);
/**
* @brief Gets the state of an inter-process DMA.
* @param[out] dmaState Pointer to output the state of the DMA to.
* @param dma Handle of the DMA.
*/
Result svcGetDmaState(void* dmaState, Handle dma);
/**
* @brief Queries memory information.
* @param[out] info Pointer to output memory info to.
* @param out Pointer to output page info to.
* @param addr Virtual memory address to query.
*/ */
Result svcQueryMemory(MemInfo* info, PageInfo* out, u32 addr); Result svcQueryMemory(MemInfo* info, PageInfo* out, u32 addr);
/**
* @brief Queries process memory information.
* @param[out] info Pointer to output memory info to.
* @param[out] out Pointer to output page info to.
* @param process Process to query memory from.
* @param addr Virtual memory address to query.
*/
Result svcQueryProcessMemory(MemInfo* info, PageInfo* out, Handle process, u32 addr); Result svcQueryProcessMemory(MemInfo* info, PageInfo* out, Handle process, u32 addr);
/**
* @brief Invalidates a process's data cache.
* @param process Handle of the process.
* @param addr Address to invalidate.
* @param size Size of the memory to invalidate.
*/
Result svcInvalidateProcessDataCache(Handle process, void* addr, u32 size); Result svcInvalidateProcessDataCache(Handle process, void* addr, u32 size);
/**
* @brief Flushes a process's data cache.
* @param process Handle of the process.
* @param addr Address to flush.
* @param size Size of the memory to flush.
*/
Result svcFlushProcessDataCache(Handle process, void const* addr, u32 size); Result svcFlushProcessDataCache(Handle process, void const* addr, u32 size);
/**
* @brief Reads from a process's memory.
* @param buffer Buffer to read data to.
* @param debug Debug handle of the process.
* @param addr Address to read from.
* @param size Size of the memory to read.
*/
Result svcReadProcessMemory(void* buffer, Handle debug, u32 addr, u32 size); Result svcReadProcessMemory(void* buffer, Handle debug, u32 addr, u32 size);
/**
* @brief Writes to a process's memory.
* @param debug Debug handle of the process.
* @param buffer Buffer to write data from.
* @param addr Address to write to.
* @param size Size of the memory to write.
*/
Result svcWriteProcessMemory(Handle debug, const void* buffer, u32 addr, u32 size); Result svcWriteProcessMemory(Handle debug, const void* buffer, u32 addr, u32 size);
///@} ///@}
///@name Process management ///@name Process management
///@{ ///@{
/** /**
* @brief Gets the handle of a process. * @brief Gets the handle of a process.
* @param[out] process The handle of the process * @param[out] process The handle of the process
* @param processId The ID of the process to open * @param processId The ID of the process to open
*/ */
Result svcOpenProcess(Handle* process, u32 processId); Result svcOpenProcess(Handle* process, u32 processId);
/// Exits the current process.
void svcExitProcess() __attribute__((noreturn)); void svcExitProcess() __attribute__((noreturn));
/**
* @brief Terminates a process.
* @param process Handle of the process to terminate.
*/
Result svcTerminateProcess(Handle process); Result svcTerminateProcess(Handle process);
/**
* @brief Gets information about a process.
* @param[out] out Pointer to output process info to.
* @param process Handle of the process to get information about.
* @param type Type of information to retreieve.
*/
Result svcGetProcessInfo(s64* out, Handle process, u32 type); Result svcGetProcessInfo(s64* out, Handle process, u32 type);
/**
* @brief Gets the ID of a process.
* @param[out] out Pointer to output the process ID to.
* @param handle Handle of the process to get the ID of.
*/
Result svcGetProcessId(u32 *out, Handle handle); Result svcGetProcessId(u32 *out, Handle handle);
/**
* @brief Gets a list of running processes.
* @param[out] processCount Pointer to output the process count to.
* @param[out] processIds Pointer to output the process IDs to.
* @param processIdMaxCount Maximum number of process IDs.
*/
Result svcGetProcessList(s32* processCount, u32* processIds, s32 processIdMaxCount); Result svcGetProcessList(s32* processCount, u32* processIds, s32 processIdMaxCount);
/**
* @brief Creates a port.
* @param[out] portServer Pointer to output the port server handle to.
* @param[out] portClient Pointer to output the port client handle to.
* @param name Name of the port.
* @param maxSessions Maximum number of sessions that can connect to the port.
*/
Result svcCreatePort(Handle* portServer, Handle* portClient, const char* name, s32 maxSessions); Result svcCreatePort(Handle* portServer, Handle* portClient, const char* name, s32 maxSessions);
/**
* @brief Connects to a port.
* @param[out] out Pointer to output the port handle to.
* @param portName Name of the port.
*/
Result svcConnectToPort(volatile Handle* out, const char* portName); Result svcConnectToPort(volatile Handle* out, const char* portName);
///@} ///@}
@ -378,9 +535,7 @@ void svcExitThread(void) __attribute__((noreturn));
*/ */
void svcSleepThread(s64 ns); void svcSleepThread(s64 ns);
/** /// Retrieves the priority of a thread.
* @brief Retrieves the priority of a thread.
*/
Result svcGetThreadPriority(s32 *out, Handle handle); Result svcGetThreadPriority(s32 *out, Handle handle);
/** /**
@ -390,9 +545,35 @@ Result svcGetThreadPriority(s32 *out, Handle handle);
* Low values gives the thread higher priority. * Low values gives the thread higher priority.
*/ */
Result svcSetThreadPriority(Handle thread, s32 prio); Result svcSetThreadPriority(Handle thread, s32 prio);
/**
* @brief Gets a thread's affinity mask.
* @param[out] affinitymask Pointer to output the affinity masks to.
* @param thread Handle of the thread.
* @param processorcount Number of processors.
*/
Result svcGetThreadAffinityMask(u8* affinitymask, Handle thread, s32 processorcount); Result svcGetThreadAffinityMask(u8* affinitymask, Handle thread, s32 processorcount);
/**
* @brief Sets a thread's affinity mask.
* @param thread Handle of the thread.
* @param affinitymask Pointer to retreive the affinity masks from.
* @param processorcount Number of processors.
*/
Result svcSetThreadAffinityMask(Handle thread, u8* affinitymask, s32 processorcount); Result svcSetThreadAffinityMask(Handle thread, u8* affinitymask, s32 processorcount);
/**
* @brief Gets a thread's ideal processor.
* @param[out] processorid Pointer to output the ID of the thread's ideal processor to.
* @param thread Handle of the thread.
*/
Result svcGetThreadIdealProcessor(s32* processorid, Handle thread); Result svcGetThreadIdealProcessor(s32* processorid, Handle thread);
/**
* Sets a thread's ideal processor.
* @param thread Handle of the thread.
* @param processorid ID of the thread's ideal processor.
*/
Result svcSetThreadIdealProcessor(Handle thread, s32 processorid); Result svcSetThreadIdealProcessor(Handle thread, s32 processorid);
/** /**
@ -402,12 +583,16 @@ Result svcSetThreadIdealProcessor(Handle thread, s32 processorid);
s32 svcGetProcessorID(); s32 svcGetProcessorID();
/** /**
* @param out The thread ID of the thread @p handle. * @brief Gets the ID of a thread.
* @param[out] out Pointer to output the thread ID of the thread @p handle to.
* @param handle Handle of the thread.
*/ */
Result svcGetThreadId(u32 *out, Handle handle); Result svcGetThreadId(u32 *out, Handle handle);
/** /**
* @param out The process ID of the thread @p handle. * @brief Gets the process ID of a thread.
* @param[out] out Pointer to output the process ID of the thread @p handle to.
* @param handle Handle of the thread.
* @sa svcOpenProcess * @sa svcOpenProcess
*/ */
Result svcGetProcessIdOfThread(u32 *out, Handle handle); Result svcGetProcessIdOfThread(u32 *out, Handle handle);
@ -424,21 +609,74 @@ Result svcGetThreadInfo(s64* out, Handle thread, ThreadInfoType type);
///@name Synchronization ///@name Synchronization
///@{ ///@{
/**
* @brief Creates a mutex.
* @param[out] mutex Pointer to output the handle of the created mutex to.
* @param initially_locked Whether the mutex should be initially locked.
*/
Result svcCreateMutex(Handle* mutex, bool initially_locked); Result svcCreateMutex(Handle* mutex, bool initially_locked);
/**
* @brief Releases a mutex.
* @param handle Handle of the mutex.
*/
Result svcReleaseMutex(Handle handle); Result svcReleaseMutex(Handle handle);
/**
* @brief Creates a semaphore.
* @param[out] semaphore Pointer to output the handle of the created semaphore to.
* @param initial_count Initial count of the semaphore.
* @param max_count Maximum count of the semaphore.
*/
Result svcCreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count); Result svcCreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count);
/**
* @brief Releases a semaphore.
* @param[out] count Pointer to output the current count of the semaphore to.
* @param semaphore Handle of the semaphore.
* @param release_count Number to increase the semaphore count by.
*/
Result svcReleaseSemaphore(s32* count, Handle semaphore, s32 release_count); Result svcReleaseSemaphore(s32* count, Handle semaphore, s32 release_count);
/**
* @brief Creates an event handle.
* @param[out] event Pointer to output the created event handle to.
* @param reset_type Type of reset the event uses.
*/
Result svcCreateEvent(Handle* event, u8 reset_type); Result svcCreateEvent(Handle* event, u8 reset_type);
/**
* @brief Signals an event.
* @param handle Handle of the event to signal.
*/
Result svcSignalEvent(Handle handle); Result svcSignalEvent(Handle handle);
/**
* @brief Clears an event.
* @param handle Handle of the event to clear.
*/
Result svcClearEvent(Handle handle); Result svcClearEvent(Handle handle);
/**
* @brief Waits for synchronization on a handle.
* @param handle Handle to wait on.
* @param nanoseconds Maximum nanoseconds to wait for.
*/
Result svcWaitSynchronization(Handle handle, s64 nanoseconds); Result svcWaitSynchronization(Handle handle, s64 nanoseconds);
/**
* @brief Waits for synchronization on multiple handles.
* @param[out] out Pointer to output the index of the synchronized handle to.
* @param handles Handles to wait on.
* @param handles_num Number of handles.
* @param wait_all Whether to wait for synchronization on all handles.
* @param nanoseconds Maximum nanoseconds to wait for.
*/
Result svcWaitSynchronizationN(s32* out, Handle* handles, s32 handles_num, bool wait_all, s64 nanoseconds); Result svcWaitSynchronizationN(s32* out, Handle* handles, s32 handles_num, bool wait_all, s64 nanoseconds);
/** /**
* @brief Creates an address arbiter * @brief Creates an address arbiter
* @param[out] mutex Pointer to output the handle of the created address arbiter to.
* @sa svcArbitrateAddress * @sa svcArbitrateAddress
*/ */
Result svcCreateAddressArbiter(Handle *arbiter); Result svcCreateAddressArbiter(Handle *arbiter);
@ -462,40 +700,151 @@ Result svcCreateAddressArbiter(Handle *arbiter);
*/ */
Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 nanoseconds); Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 nanoseconds);
/**
* @brief Sends a synchronized request to a session handle.
* @param session Handle of the session.
*/
Result svcSendSyncRequest(Handle session); Result svcSendSyncRequest(Handle session);
/**
* @brief Accepts a session.
* @param[out] session Pointer to output the created session handle to.
* @param port Handle of the port to accept a session from.
*/
Result svcAcceptSession(Handle* session, Handle port); Result svcAcceptSession(Handle* session, Handle port);
/**
* @brief Replies to and receives a new request.
* @param index Pointer to the index of the request.
* @param handles Session handles to receive requests from.
* @param handleCount Number of handles.
* @param replyTarget Handle of the session to reply to.
*/
Result svcReplyAndReceive(s32* index, Handle* handles, s32 handleCount, Handle replyTarget); Result svcReplyAndReceive(s32* index, Handle* handles, s32 handleCount, Handle replyTarget);
///@} ///@}
///@name Time ///@name Time
///@{ ///@{
/**
* @brief Creates a timer.
* @param[out] timer Pointer to output the handle of the created timer to.
* @param reset_type Type of reset to perform on the timer.
*/
Result svcCreateTimer(Handle* timer, u8 reset_type); Result svcCreateTimer(Handle* timer, u8 reset_type);
/**
* @brief Sets a timer.
* @param timer Handle of the timer to set.
* @param initial Initial value of the timer.
* @param interval Interval of the timer.
*/
Result svcSetTimer(Handle timer, s64 initial, s64 interval); Result svcSetTimer(Handle timer, s64 initial, s64 interval);
/**
* @brief Cancels a timer.
* @param timer Handle of the timer to cancel.
*/
Result svcCancelTimer(Handle timer); Result svcCancelTimer(Handle timer);
/**
* @brief Clears a timer.
* @param timer Handle of the timer to clear.
*/
Result svcClearTimer(Handle timer); Result svcClearTimer(Handle timer);
/**
* @brief Gets the current system tick.
* @return The current system tick.
*/
u64 svcGetSystemTick(); u64 svcGetSystemTick();
///@} ///@}
///@name System ///@name System
///@{ ///@{
/**
* @brief Closes a handle.
* @param handle Handle to close.
*/
Result svcCloseHandle(Handle handle); Result svcCloseHandle(Handle handle);
/**
* @brief Duplicates a handle.
* @param[out] out Pointer to output the duplicated handle to.
* @param original Handle to duplicate.
*/
Result svcDuplicateHandle(Handle* out, Handle original); Result svcDuplicateHandle(Handle* out, Handle original);
/**
* @brief Gets the system info.
* @param[out] out Pointer to output the system info to.
* @param type Type of system info to retreive.
* @param param Parameter clarifying the system info type.
*/
Result svcGetSystemInfo(s64* out, u32 type, s32 param); Result svcGetSystemInfo(s64* out, u32 type, s32 param);
/**
* @brief Sets the current kernel state.
* @param type Type of state to set.
* @param param0 First parameter of the state.
* @param param1 Second parameter of the state.
* @param param2 Third parameter of the state.
*/
Result svcKernelSetState(u32 type, u32 param0, u32 param1, u32 param2); Result svcKernelSetState(u32 type, u32 param0, u32 param1, u32 param2);
///@} ///@}
///@name Debugging ///@name Debugging
///@{ ///@{
/**
* @brief Breaks execution.
* @param breakReason Reason for breaking.
*/
void svcBreak(UserBreakType breakReason); void svcBreak(UserBreakType breakReason);
/**
* @brief Outputs a debug string.
* @param str String to output.
* @param length Length of the string to output.
*/
Result svcOutputDebugString(const char* str, int length); Result svcOutputDebugString(const char* str, int length);
/**
* @brief Creates a debug handle for an active process.
* @param[out] debug Pointer to output the created debug handle to.
* @param processId ID of the process to debug.
*/
Result svcDebugActiveProcess(Handle* debug, u32 processId); Result svcDebugActiveProcess(Handle* debug, u32 processId);
/**
* @brief Breaks a debugged process.
* @param debug Debug handle of the process.
*/
Result svcBreakDebugProcess(Handle debug); Result svcBreakDebugProcess(Handle debug);
/**
* @brief Terminates a debugged process.
* @param debug Debug handle of the process.
*/
Result svcTerminateDebugProcess(Handle debug); Result svcTerminateDebugProcess(Handle debug);
/**
* @brief Gets the current debug event of a debugged process.
* @param[out] info Pointer to output the debug event information to.
* @param debug Debug handle of the process.
*/
Result svcGetProcessDebugEvent(DebugEventInfo* info, Handle debug); Result svcGetProcessDebugEvent(DebugEventInfo* info, Handle debug);
/**
* @brief Continues the current debug event of a debugged process.
* @param debug Debug handle of the process.
* @param flags Flags to continue with.
*/
Result svcContinueDebugEvent(Handle debug, u32 flags); Result svcContinueDebugEvent(Handle debug, u32 flags);
///@} ///@}
/**
* @brief Executes a function in kernel mode.
* @param callback Function to execute.
*/
Result svcBackdoor(s32 (*callback)(void)); Result svcBackdoor(s32 (*callback)(void));

View File

@ -1,19 +1,31 @@
/**
* @file synchronization.h
* @brief Provides synchronization locks.
*/
#pragma once #pragma once
/// A light lock.
typedef s32 LightLock; typedef s32 LightLock;
/// A recursive lock.
typedef struct typedef struct
{ {
LightLock lock; LightLock lock; ///< Inner light lock.
u32 thread_tag; u32 thread_tag; ///< Tag of the thread that currently has the lock.
u32 counter; u32 counter; ///< Lock count.
} RecursiveLock; } RecursiveLock;
/// Performs a clrex operation.
static inline void __clrex(void) static inline void __clrex(void)
{ {
__asm__ __volatile__("clrex"); __asm__ __volatile__("clrex");
} }
/**
* @brief Performs a ldrex operation.
* @param addr Address to perform the operation on.
* @return The resulting value.
*/
static inline s32 __ldrex(s32* addr) static inline s32 __ldrex(s32* addr)
{ {
s32 val; s32 val;
@ -21,6 +33,12 @@ static inline s32 __ldrex(s32* addr)
return val; return val;
} }
/**
* @brief Performs a strex operation.
* @param addr Address to perform the operation on.
* @param val Value to store.
* @return Whether the operation was successful.
*/
static inline bool __strex(s32* addr, s32 val) static inline bool __strex(s32* addr, s32 val)
{ {
bool res; bool res;
@ -28,10 +46,38 @@ static inline bool __strex(s32* addr, s32 val)
return res; return res;
} }
/**
* @brief Initializes a light lock.
* @param lock Pointer to the lock.
*/
void LightLock_Init(LightLock* lock); void LightLock_Init(LightLock* lock);
/**
* @brief Locks a light lock.
* @param lock Pointer to the lock.
*/
void LightLock_Lock(LightLock* lock); void LightLock_Lock(LightLock* lock);
/**
* @brief Unlocks a light lock.
* @param lock Pointer to the lock.
*/
void LightLock_Unlock(LightLock* lock); void LightLock_Unlock(LightLock* lock);
/**
* @brief Initializes a recursive lock.
* @param lock Pointer to the lock.
*/
void RecursiveLock_Init(RecursiveLock* lock); void RecursiveLock_Init(RecursiveLock* lock);
/**
* @brief Locks a recursive lock.
* @param lock Pointer to the lock.
*/
void RecursiveLock_Lock(RecursiveLock* lock); void RecursiveLock_Lock(RecursiveLock* lock);
/**
* @brief Unlocks a recursive lock.
* @param lock Pointer to the lock.
*/
void RecursiveLock_Unlock(RecursiveLock* lock); void RecursiveLock_Unlock(RecursiveLock* lock);

View File

@ -1,54 +1,57 @@
/* /**
types.h _ Various system types. * @file types.h
*/ * @brief Various system types.
*/
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
/// The maximum value of a u64.
#define U64_MAX UINT64_MAX #define U64_MAX UINT64_MAX
/// Possible media types.
typedef enum typedef enum
{ {
mediatype_NAND, mediatype_NAND, ///< NAND
mediatype_SDMC, mediatype_SDMC, ///< SDMC
mediatype_GAMECARD, mediatype_GAMECARD, ///< Game card
} mediatypes_enum; } mediatypes_enum;
typedef uint8_t u8; typedef uint8_t u8; ///< 8-bit unsigned integer
typedef uint16_t u16; typedef uint16_t u16; ///< 16-bit unsigned integer
typedef uint32_t u32; typedef uint32_t u32; ///< 32-bit unsigned integer
typedef uint64_t u64; typedef uint64_t u64; ///< 64-bit unsigned integer
typedef int8_t s8; typedef int8_t s8; ///< 8-bit signed integer
typedef int16_t s16; typedef int16_t s16; ///< 16-bit signed integer
typedef int32_t s32; typedef int32_t s32; ///< 32-bit signed integer
typedef int64_t s64; typedef int64_t s64; ///< 64-bit signed integer
typedef volatile u8 vu8; typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
typedef volatile u16 vu16; typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
typedef volatile u32 vu32; typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
typedef volatile u64 vu64; typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
typedef volatile s8 vs8; typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
typedef volatile s16 vs16; typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
typedef volatile s32 vs32; typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
typedef volatile s64 vs64; typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
typedef u32 Handle; typedef u32 Handle; ///< Resource handle.
typedef s32 Result; typedef s32 Result; ///< Function result.
typedef void (*ThreadFunc)(void *); typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function.
/// Creates a bitmask from a bit number.
#define BIT(n) (1U<<(n)) #define BIT(n) (1U<<(n))
//! aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. /// aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m.
#define ALIGN(m) __attribute__((aligned(m))) #define ALIGN(m) __attribute__((aligned(m)))
//! packs a struct (and other types?) so it won't include padding bytes. /// packs a struct (and other types?) so it won't include padding bytes.
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
//! flags a function as deprecated. /// flags a function as deprecated.
#ifndef LIBCTRU_NO_DEPRECATION #ifndef LIBCTRU_NO_DEPRECATION
#define DEPRECATED __attribute__ ((deprecated)) #define DEPRECATED __attribute__ ((deprecated))
#else #else

View File

@ -1,74 +1,145 @@
/**
* @file rbtree.h
* @brief Red-black trees.
*/
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
/// brief Retreives an rbtree item.
#define rbtree_item(ptr, type, member) \ #define rbtree_item(ptr, type, member) \
((type*)(((char*)ptr) - offsetof(type, member))) ((type*)(((char*)ptr) - offsetof(type, member)))
typedef struct rbtree rbtree_t; typedef struct rbtree rbtree_t; ///< rbtree type.
typedef struct rbtree_node rbtree_node_t; typedef struct rbtree_node rbtree_node_t; ///< rbtree node type.
typedef void (*rbtree_node_destructor_t)(rbtree_node_t *Node); typedef void (*rbtree_node_destructor_t)(rbtree_node_t *Node); ///< rbtree node destructor.
typedef int (*rbtree_node_comparator_t)(const rbtree_node_t *lhs, typedef int (*rbtree_node_comparator_t)(const rbtree_node_t *lhs,
const rbtree_node_t *rhs); const rbtree_node_t *rhs); ///< rbtree node comparator.
/// An rbtree node.
struct rbtree_node struct rbtree_node
{ {
uintptr_t parent_color; uintptr_t parent_color; ///< Parent color.
rbtree_node_t *child[2]; rbtree_node_t *child[2]; ///< Node children.
}; };
/// An rbtree.
struct rbtree struct rbtree
{ {
rbtree_node_t *root; rbtree_node_t *root; ///< Root node.
rbtree_node_comparator_t comparator; rbtree_node_comparator_t comparator; ///< Node comparator.
size_t size; size_t size; ///< Size.
}; };
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/**
* @brief Initializes an rbtree.
* @param tree Pointer to the tree.
* @param comparator Comparator to use.
*/
void void
rbtree_init(rbtree_t *tree, rbtree_init(rbtree_t *tree,
rbtree_node_comparator_t comparator); rbtree_node_comparator_t comparator);
/**
* @brief Gets whether an rbtree is empty
* @param tree Pointer to the tree.
* @return A non-zero value if the tree is not empty.
*/
int int
rbtree_empty(const rbtree_t *tree); rbtree_empty(const rbtree_t *tree);
/**
* @brief Gets the size of an rbtree.
* @param tree Pointer to the tree.
*/
size_t size_t
rbtree_size(const rbtree_t *tree); rbtree_size(const rbtree_t *tree);
/**
* @brief Inserts a node into an rbtree.
* @param tree Pointer to the tree.
* @param node Pointer to the node.
* @return The inserted node.
*/
__attribute__((warn_unused_result)) __attribute__((warn_unused_result))
rbtree_node_t* rbtree_node_t*
rbtree_insert(rbtree_t *tree, rbtree_insert(rbtree_t *tree,
rbtree_node_t *node); rbtree_node_t *node);
/**
* @brief Inserts multiple nodes into an rbtree.
* @param tree Pointer to the tree.
* @param node Pointer to the nodes.
*/
void void
rbtree_insert_multi(rbtree_t *tree, rbtree_insert_multi(rbtree_t *tree,
rbtree_node_t *node); rbtree_node_t *node);
/**
* @brief Finds a node within an rbtree.
* @param tree Pointer to the tree.
* @param node Pointer to the node.
* @return The located node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_find(const rbtree_t *tree, rbtree_find(const rbtree_t *tree,
const rbtree_node_t *node); const rbtree_node_t *node);
/**
* @brief Gets the minimum node of an rbtree.
* @param tree Pointer to the tree.
* @return The minimum node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_min(const rbtree_t *tree); rbtree_min(const rbtree_t *tree);
/**
* @brief Gets the maximum node of an rbtree.
* @param tree Pointer to the tree.
* @return The maximum node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_max(const rbtree_t *tree); rbtree_max(const rbtree_t *tree);
/**
* @brief Gets the next node from an rbtree node.
* @param node Pointer to the node.
* @return The next node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_node_next(const rbtree_node_t *node); rbtree_node_next(const rbtree_node_t *node);
/**
* @brief Gets the previous node from an rbtree node.
* @param node Pointer to the node.
* @return The previous node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_node_prev(const rbtree_node_t *node); rbtree_node_prev(const rbtree_node_t *node);
/**
* @brief Removes a node from an rbtree.
* @param tree Pointer to the tree.
* @param node Pointer to the node.
* @param destructor Destructor to use when removing the node.
* @return The removed node.
*/
rbtree_node_t* rbtree_node_t*
rbtree_remove(rbtree_t *tree, rbtree_remove(rbtree_t *tree,
rbtree_node_t *node, rbtree_node_t *node,
rbtree_node_destructor_t destructor); rbtree_node_destructor_t destructor);
/**
* @brief Clears an rbtree.
* @param tree Pointer to the tree.
* @param destructor Destructor to use when clearing the tree's nodes.
*/
void void
rbtree_clear(rbtree_t *tree, rbtree_clear(rbtree_t *tree,
rbtree_node_destructor_t destructor); rbtree_node_destructor_t destructor);

View File

@ -1,9 +1,13 @@
/**
* @file utf.h
* @brief UTF conversion functions.
*/
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
/*! Convert a UTF-8 sequence into a UTF-32 codepoint /** Convert a UTF-8 sequence into a UTF-32 codepoint
* *
* @param[out] out Output codepoint * @param[out] out Output codepoint
* @param[in] in Input sequence * @param[in] in Input sequence
@ -13,7 +17,7 @@
*/ */
ssize_t decode_utf8 (uint32_t *out, const uint8_t *in); ssize_t decode_utf8 (uint32_t *out, const uint8_t *in);
/*! Convert a UTF-16 sequence into a UTF-32 codepoint /** Convert a UTF-16 sequence into a UTF-32 codepoint
* *
* @param[out] out Output codepoint * @param[out] out Output codepoint
* @param[in] in Input sequence * @param[in] in Input sequence
@ -23,7 +27,7 @@ ssize_t decode_utf8 (uint32_t *out, const uint8_t *in);
*/ */
ssize_t decode_utf16(uint32_t *out, const uint16_t *in); ssize_t decode_utf16(uint32_t *out, const uint16_t *in);
/*! Convert a UTF-32 codepoint into a UTF-8 sequence /** Convert a UTF-32 codepoint into a UTF-8 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input codepoint * @param[in] in Input codepoint
@ -35,7 +39,7 @@ ssize_t decode_utf16(uint32_t *out, const uint16_t *in);
*/ */
ssize_t encode_utf8 (uint8_t *out, uint32_t in); ssize_t encode_utf8 (uint8_t *out, uint32_t in);
/*! Convert a UTF-32 codepoint into a UTF-16 sequence /** Convert a UTF-32 codepoint into a UTF-16 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input codepoint * @param[in] in Input codepoint
@ -47,7 +51,7 @@ ssize_t encode_utf8 (uint8_t *out, uint32_t in);
*/ */
ssize_t encode_utf16(uint16_t *out, uint32_t in); ssize_t encode_utf16(uint16_t *out, uint32_t in);
/*! Convert a UTF-8 sequence into a UTF-16 sequence /** Convert a UTF-8 sequence into a UTF-16 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence
@ -57,7 +61,7 @@ ssize_t encode_utf16(uint16_t *out, uint32_t in);
*/ */
size_t utf8_to_utf16(uint16_t *out, const uint8_t *in, size_t len); size_t utf8_to_utf16(uint16_t *out, const uint8_t *in, size_t len);
/*! Convert a UTF-8 sequence into a UTF-32 sequence /** Convert a UTF-8 sequence into a UTF-32 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence
@ -67,7 +71,7 @@ size_t utf8_to_utf16(uint16_t *out, const uint8_t *in, size_t len);
*/ */
size_t utf8_to_utf32(uint32_t *out, const uint8_t *in, size_t len); size_t utf8_to_utf32(uint32_t *out, const uint8_t *in, size_t len);
/*! Convert a UTF-16 sequence into a UTF-8 sequence /** Convert a UTF-16 sequence into a UTF-8 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence
@ -77,7 +81,7 @@ size_t utf8_to_utf32(uint32_t *out, const uint8_t *in, size_t len);
*/ */
size_t utf16_to_utf8(uint8_t *out, const uint16_t *in, size_t len); size_t utf16_to_utf8(uint8_t *out, const uint16_t *in, size_t len);
/*! Convert a UTF-16 sequence into a UTF-32 sequence /** Convert a UTF-16 sequence into a UTF-32 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence
@ -87,7 +91,7 @@ size_t utf16_to_utf8(uint8_t *out, const uint16_t *in, size_t len);
*/ */
size_t utf16_to_utf32(uint32_t *out, const uint16_t *in, size_t len); size_t utf16_to_utf32(uint32_t *out, const uint16_t *in, size_t len);
/*! Convert a UTF-32 sequence into a UTF-8 sequence /** Convert a UTF-32 sequence into a UTF-8 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence
@ -97,7 +101,7 @@ size_t utf16_to_utf32(uint32_t *out, const uint16_t *in, size_t len);
*/ */
size_t utf32_to_utf8(uint8_t *out, const uint32_t *in, size_t len); size_t utf32_to_utf8(uint8_t *out, const uint32_t *in, size_t len);
/*! Convert a UTF-32 sequence into a UTF-16 sequence /** Convert a UTF-32 sequence into a UTF-16 sequence
* *
* @param[out] out Output sequence * @param[out] out Output sequence
* @param[in] in Input sequence * @param[in] in Input sequence

View File

@ -4,8 +4,6 @@
*/ */
#pragma once #pragma once
// Functions for allocating/deallocating VRAM
/** /**
* @brief Allocates a 0x80-byte aligned buffer. * @brief Allocates a 0x80-byte aligned buffer.
* @param size Size of the buffer to allocate. * @param size Size of the buffer to allocate.