Skip to content

Commit

Permalink
OnionFS 2.0 ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohackandglitch committed Nov 24, 2018
1 parent 5de0340 commit dfd9223
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 189 deletions.
12 changes: 1 addition & 11 deletions 3ds.ld
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PHDRS
SECTIONS
{
/* =========== CODE section =========== */
. = 0x00100000;
. = 0x07000100;
__start__ = . ;
.text ALIGN(0x4) :
{
Expand Down Expand Up @@ -123,16 +123,6 @@ SECTIONS
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} : data

.rel.plt ALIGN(4):
{
*(.__rel_dyn_start)
*(.rel*)
*(.rel.*)
*(.rel.dyn)
*(.__rel_dyn_end)
} : data


.bss ALIGN(4):
{ *(.__bss_start)
Expand Down
266 changes: 140 additions & 126 deletions Includes/csvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,135 +16,149 @@

#pragma once

#include <types.h>

// For accessing physmem uncached (and directly)
#define PA_PTR(addr) (void *)((u32)(addr) | 1 << 31)
#ifndef PA_FROM_VA_PTR
#define PA_FROM_VA_PTR(addr) PA_PTR(svcConvertVAToPA((const void *)(addr), false))
#endif

#ifdef __cplusplus
extern "C" {
#endif

/// Operations for svcControlService
typedef enum ServiceOp
{
SERVICEOP_STEAL_CLIENT_SESSION = 0, ///< Steal a client session given a service or global port name
SERVICEOP_GET_NAME, ///< Get the name of a service or global port given a client or session handle
} ServiceOp;

/**
* @brief Executes a function in supervisor mode, using the supervisor-mode stack.
* @param func Function to execute.
* @param ... Function parameters, up to 3 registers.
*/
Result svcCustomBackdoor(void *func, ...);

///@name I/O
///@{
/**
* @brief Gives the physical address corresponding to a virtual address.
* @param VA Virtual address.
* @param writeCheck whether to check if the VA is writable in supervisor mode
* @return The corresponding physical address, or NULL.
*/
u32 svcConvertVAToPA(const void *VA, bool writeCheck);

/**
* @brief Flushes a range of the data cache (L2C included).
* @param addr Start address.
* @param len Length of the range.
*/
void svcFlushDataCacheRange(void *addr, u32 len);

/**
* @brief Flushes the data cache entirely (L2C included).
*/
void svcFlushEntireDataCache(void);

/**
* @brief Invalidates a range of the instruction cache.
* @param addr Start address.
* @param len Length of the range.
*/
void svcInvalidateInstructionCacheRange(void *addr, u32 len);

/**
* @brief Invalidates the data cache entirely.
*/
void svcInvalidateEntireInstructionCache(void);
///@}

///@name Memory management
///@{
/**
* @brief Maps a block of process memory.
* @param process Handle of the process.
* @param destAddress Address of the mapped block in the current process.
* @param srcAddress Address of the mapped block in the source process.
* @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes).
*/
Result svcMapProcessMemoryEx(Handle process, u32 destAddr, u32 srcAddr, u32 size);

/**
* @brief Unmaps a block of process memory.
* @param process Handle of the process.
* @param destAddress Address of the block of memory to unmap, in the current (destination) process.
* @param size Size of the block of memory to unmap (truncated to a multiple of 0x1000 bytes).
*/
Result svcUnmapProcessMemoryEx(Handle process, u32 destAddress, u32 size);

/**
* @brief Controls memory mapping, with the choice to use region attributes or not.
* @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0.
* @param addr0 The virtual address to be used for the operation.
* @param addr1 The virtual address to be (un)mirrored by @p addr0 when using @ref MEMOP_MAP or @ref MEMOP_UNMAP.
* It has to be pointing to a RW memory.
* Use NULL if the operation is @ref MEMOP_FREE or @ref MEMOP_ALLOC.
* @param size The requested size for @ref MEMOP_ALLOC and @ref MEMOP_ALLOC_LINEAR.
* @param op Operation flags. See @ref MemOp.
* @param perm A combination of @ref MEMPERM_READ and @ref MEMPERM_WRITE. Using MEMPERM_EXECUTE will return an error.
* Value 0 is used when unmapping memory.
* @param isLoader Whether to use the region attributes
* If a memory is mapped for two or more addresses, you have to use MEMOP_UNMAP before being able to MEMOP_FREE it.
* MEMOP_MAP will fail if @p addr1 was already mapped to another address.
*
* @sa svcControlMemory
*/
Result svcControlMemoryEx(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
///@}

///@name System
///@{
/**
* @brief Performs actions related to services or global handles.
* @param op The operation to perform, see @ref ServiceOp.
*
* Examples:
* svcControlService(SERVICEOP_GET_NAME, (char [12])outName, (Handle)clientOrSessionHandle);
* svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, (Handle *)&outHandle, (const char *)name);
*/
Result svcControlService(ServiceOp op, ...);

/**
* @brief Copy a handle from a process to another one.
* @param[out] out The output handle.
* @param outProcess Handle of the process of the output handle.
* @param in The input handle. Pseudo-handles are not accepted.
* @param inProcess Handle of the process of the input handle.
*/
Result svcCopyHandle(Handle *out, Handle outProcess, Handle in, Handle inProcess);

/**
* @brief Get the address and class name of the underlying kernel object corresponding to a handle.
* @param[out] outKAddr The output kernel address.
* @param[out] outName Output class name. The buffer should be large enough to contain it.
* @param in The input handle.
*/
Result svcTranslateHandle(u32 *outKAddr, char *outClassName, Handle in);
///@}
#include "types.h"

#define PA_RWX(add) (add == 0 ? 0 : (add < 0x30000000 ? (u32)((add) | (1u << 31)) : add))
#define PA_FROM_VA(addr) PA_RWX(svcConvertVAToPA((void *)addr, false))

/// Operations for svcControlService
typedef enum ServiceOp
{
SERVICEOP_STEAL_CLIENT_SESSION = 0, ///< Steal a client session given a service or global port name
SERVICEOP_GET_NAME, ///< Get the name of a service or global port given a client or session handle
} ServiceOp;

/**
* @brief Executes a function in supervisor mode, using the supervisor-mode stack.
* @param func Function to execute.
* @param ... Function parameters, up to 3 registers.
*/
Result svcCustomBackdoor(void *func, ...);

///@name I/O
///@{
/**
* @brief Gives the physical address corresponding to a virtual address.
* @param VA Virtual address.
* @param writeCheck whether to check if the VA is writable in supervisor mode
* @return The corresponding physical address, or NULL.
*/
u32 svcConvertVAToPA(const void *VA, bool writeCheck);

/**
* @brief Flushes a range of the data cache (L2C included).
* @param addr Start address.
* @param len Length of the range.
*/
void svcFlushDataCacheRange(void *addr, u32 len);

/**
* @brief Flushes the data cache entirely (L2C included).
*/
void svcFlushEntireDataCache(void);

/**
* @brief Invalidates a range of the instruction cache.
* @param addr Start address.
* @param len Length of the range.
*/
void svcInvalidateInstructionCacheRange(void *addr, u32 len);

/**
* @brief Invalidates the data cache entirely.
*/
void svcInvalidateEntireInstructionCache(void);
///@}

///@name Memory management
///@{
/**
* @brief Maps a block of process memory.
* @param process Handle of the process.
* @param destAddress Address of the mapped block in the current process.
* @param srcAddress Address of the mapped block in the source process.
* @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes).
*/
Result svcMapProcessMemoryEx(Handle dstProcessHandle, u32 vaDst, Handle srcProcessHandle, u32 vaSrc, u32 size);

/**
* @brief Unmaps a block of process memory.
* @param process Handle of the process.
* @param destAddress Address of the block of memory to unmap, in the current (destination) process.
* @param size Size of the block of memory to unmap (truncated to a multiple of 0x1000 bytes).
*/
Result svcUnmapProcessMemoryEx(Handle process, u32 destAddress, u32 size);

/**
* @brief Controls memory mapping, with the choice to use region attributes or not.
* @param[out] addr_out The virtual address resulting from the operation. Usually the same as addr0.
* @param addr0 The virtual address to be used for the operation.
* @param addr1 The virtual address to be (un)mirrored by @p addr0 when using @ref MEMOP_MAP or @ref MEMOP_UNMAP.
* It has to be pointing to a RW memory.
* Use NULL if the operation is @ref MEMOP_FREE or @ref MEMOP_ALLOC.
* @param size The requested size for @ref MEMOP_ALLOC and @ref MEMOP_ALLOC_LINEAR.
* @param op Operation flags. See @ref MemOp.
* @param perm A combination of @ref MEMPERM_READ and @ref MEMPERM_WRITE. Using MEMPERM_EXECUTE will return an error.
* Value 0 is used when unmapping memory.
* @param isLoader Whether to use the region attributes
* If a memory is mapped for two or more addresses, you have to use MEMOP_UNMAP before being able to MEMOP_FREE it.
* MEMOP_MAP will fail if @p addr1 was already mapped to another address.
*
* @sa svcControlMemory
*/
Result svcControlMemoryEx(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
///@}

///@name System
///@{
/**
* @brief Performs actions related to services or global handles.
* @param op The operation to perform, see @ref ServiceOp.
*
* Examples:
* svcControlService(SERVICEOP_GET_NAME, (char [12])outName, (Handle)clientOrSessionHandle);
* svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, (Handle *)&outHandle, (const char *)name);
*/
Result svcControlService(ServiceOp op, ...);

/**
* @brief Copy a handle from a process to another one.
* @param[out] out The output handle.
* @param outProcess Handle of the process of the output handle.
* @param in The input handle. Pseudo-handles are not accepted.
* @param inProcess Handle of the process of the input handle.
*/
Result svcCopyHandle(Handle *out, Handle outProcess, Handle in, Handle inProcess);

/**
* @brief Get the address and class name of the underlying kernel object corresponding to a handle.
* @param[out] outKAddr The output kernel address.
* @param[out] outName Output class name. The buffer should be large enough to contain it.
* @param in The input handle.
*/
Result svcTranslateHandle(u32 *outKAddr, char *outClassName, Handle in);
///@}

/// Operations for svcControlProcess
typedef enum ProcessOp
{
PROCESSOP_GET_ALL_HANDLES, ///< List all handles of the process, varg3 can be either 0 to fetch all handles, or token of the type to fetch
///< svcControlProcess(handle, PROCESSOP_GET_ALL_HANDLES, (u32)&outBuf, 0)
PROCESSOP_SET_MMU_TO_RWX, ///< Set the whole memory of the process with rwx access
///< svcControlProcess(handle, PROCESSOP_SET_MMU_TO_RWX, 0, 0)
PROCESSOP_GET_ON_MEMORY_CHANGE_EVENT,
PROCESSOP_GET_ON_EXIT_EVENT,
PROCESSOP_GET_PA_FROM_VA, ///< Get the physical address of the va within the process
///< svcControlProcess(handle, PROCESSOP_GET_PA_FROM_VA, (u32)&outPa, va)
PROCESSOP_SCHEDULE_THREADS,
} ProcessOp;

Result svcControlProcess(Handle process, ProcessOp op, u32 varg2, u32 varg3);

#ifdef __cplusplus
}
#endif
#endif
Loading

0 comments on commit dfd9223

Please sign in to comment.