//Pascal &or the FreePascal use of nintendo 2ds, 3ds regime // // Copyright (c) 2013, 2015, 2017 Kenneth Dwayne Lee Bsc. // all rights reserved // {$ifdef 3dsintf} {* * @file ipc.h * @brief Inter Process Communication helpers } {/ IPC buffer access rights. } {/< Readable } {/< Writable } {/< Readable and Writable } type IPC_BufferRights = (IPC_BUFFER_R := 1 shl 1,IPC_BUFFER_W := 1 shl 2, IPC_BUFFER_RW := 1 shl 2 or 1 shl 1); {* * @brief Creates a command header to be used for IPC * @param command_id ID of the command to create a header for. * @param normal_params Size of the normal parameters in words. Up to 63. * @param translate_params Size of the translate parameters in words. Up to 63. * @return The created IPC header. * * Normal parameters are sent directly to the process while the translate parameters might go through modifications and checks by the kernel. * The translate parameters are described by headers generated with the IPC_Desc_* functions. * * @note While #normal_params is equivalent to the number of normal parameters, #translate_params includes the size occupied by the translate parameters headers. } function IPC_MakeHeader(command_id:u16; normal_params:u32; translate_params:u32):u32;cdecl; {* * @brief Creates a header to share handles * @param number The number of handles following this header. Max 64. * @return The created shared handles header. * * The #number next values are handles that will be shared between the two processes. * * @note Zero values will have no effect. } function IPC_Desc_SharedHandles(number:cunsigned):u32;cdecl; {* * @brief Creates the header to transfer handle ownership * @param number The number of handles following this header. Max 64. * @return The created handle transfer header. * * The #number next values are handles that will be duplicated and closed by the other process. * * @note Zero values will have no effect. } function IPC_Desc_MoveHandles(number:u32):u32;cdecl; {* * @brief Returns the code to ask the kernel to fill the handle with the current process handle. * @return The code to request the current process handle. * * The next value is a placeholder that will be replaced by the current process handle by the kernel. } function IPC_Desc_CurProcessHandle:u32;cdecl; {* * @brief Creates a header describing a static buffer. * @param size Size of the buffer. Max ?0x03FFFF?. * @param buffer_id The Id of the buffer. Max 0xF. * @return The created static buffer header. * * The next value is a pointer to the buffer. It will be copied to TLS offset 0x180 + static_buffer_id*8. } function IPC_Desc_StaticBuffer(size:s32; buffer_id:u32):u32;cdecl; {* * @brief Creates a header describing a buffer to be sent over PXI. * @param size Size of the buffer. Max 0x00FFFFFF. * @param buffer_id The Id of the buffer. Max 0xF. * @param is_read_only true if the buffer is read-only. If false, the buffer is considered to have read-write access. * @return The created PXI buffer header. * * The next value is a phys-address of a table located in the BASE memregion. } function IPC_Desc_PXIBuffer(size:s32; buffer_id:u32; is_read_only:bool):u32;cdecl; {* * @brief Creates a header describing a buffer from the main memory. * @param size Size of the buffer. Max 0x0FFFFFFF. * @param rights The rights of the buffer for the destination process. * @return The created buffer header. * * The next value is a pointer to the buffer. } function IPC_Desc_Buffer(size:s32; rights:IPC_BufferRights):u32;cdecl; {$endif 3dsintf} {$ifdef 3dsimpl} function IPC_MakeHeader(command_id:u16; normal_params:u32; translate_params:u32):u32;cdecl; begin IPC_MakeHeader:= ( command_id shl 16) or ((normal_params and $3F) shl 6) or ((translate_params and $3F) shl 0); end; function IPC_Desc_SharedHandles(number:u32):u32;cdecl; begin IPC_Desc_SharedHandles:= ((number - 1) shl 26); end; function IPC_Desc_MoveHandles(number:u32):u32;cdecl; begin IPC_Desc_MoveHandles:= ((number - 1) shl 26) or $10; end; function IPC_Desc_CurProcessHandle:u32;cdecl; begin IPC_Desc_CurProcessHandle:= $20; end; function IPC_Desc_StaticBuffer(size:s32; buffer_id:u32):u32;cdecl; begin IPC_Desc_StaticBuffer:= size shl 14 or ((buffer_id and $f) shl 10) or $2; end; function IPC_Desc_PXIBuffer(size:s32; buffer_id:u32; is_read_only:bool):u32;cdecl; var RWtype: u8; begin RWtype:= $4; if is_read_only then RWtype := $6; IPC_Desc_PXIBuffer:= (size shl 8) or ((buffer_id and $f) shl 4) or RWtype; end; function IPC_Desc_Buffer(size:s32; rights:IPC_BufferRights):u32;cdecl; begin IPC_Desc_Buffer:= size shl 4 or $8 or u32(rights); end; {$endif 3dsimpl}