Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libctru/include/3ds/services/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
* After initializing this service you will be able to use system calls from netdb.h, sys/socket.h etc.
*/
#pragma once
#include <3ds/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

/// The config level to be used with @ref SOCU_GetNetworkOpt
#define SOL_CONFIG 0xfffe

/// Default number of SOC sessions to initialize, for backwards compatibility
#define SOC_DEFAULT_NUM_SESSIONS 1

/// Options to be used with @ref SOCU_GetNetworkOpt
typedef enum
{
Expand Down Expand Up @@ -101,9 +105,19 @@ typedef struct
* @param context_addr Address of a page-aligned (0x1000) buffer to be used.
* @param context_size Size of the buffer, a multiple of 0x1000.
* @note The specified context buffer can no longer be accessed by the process which called this function, since the userland permissions for this block are set to no-access.
* @note The SOC service can only be used in a single thread when using this function to initialize SOC services. In order to enable usage across multiple threads, use @ref socInitMulti, otherwise threads will block when using socket functions concurrently.
*/
Result socInit(u32 *context_addr, u32 context_size);

/**
* @brief Initializes the SOC service for use across multiple threads.
* @param context_addr Address of a page-aligned (0x1000) buffer to be used.
* @param context_size Size of the buffer, a multiple of 0x1000.
* @param num_sessions The number of sessions to initialize. This value determines how many socket functions can be run concurrently. Setting it to 1 means only one thread can safely use socket functions.
* @note The specified context buffer can no longer be accessed by the process which called this function, since the userland permissions for this block are set to no-access.
*/
Result socInitMulti(u32 *context_addr, u32 context_size, u32 num_sessions);

/**
* @brief Closes the soc service.
* @note You need to call this in order to be able to use the buffer again.
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
staticbufs[0] = IPC_Desc_StaticBuffer(tmp_addrlen,0);
staticbufs[1] = (u32)tmpaddr;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

staticbufs[0] = saved_threadstorage[0];
staticbufs[1] = saved_threadstorage[1];
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_addglobalsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int SOCU_AddGlobalSocket(int sockfd)
cmdbuf[0] = IPC_MakeHeader(0x23,1,0); // 0x230040
cmdbuf[1] = (u32)sockfd;

int ret = svcSendSyncRequest(SOCU_handle);
int ret = socSendSyncRequest();
if(R_FAILED(ret))return ret;
return cmdbuf[1];
}
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
cmdbuf[5] = IPC_Desc_StaticBuffer(tmp_addrlen,0);
cmdbuf[6] = (u32)tmpaddr;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();
if(ret != 0) {
errno = SYNC_ERROR;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_closesockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int SOCU_CloseSockets(void)
cmdbuf[0] = IPC_MakeHeader(0x21,0,2); // 0x210002;
cmdbuf[1] = IPC_Desc_CurProcessId();

int ret = svcSendSyncRequest(SOCU_handle);
int ret = socSendSyncRequest();
if(R_FAILED(ret))return ret;
return cmdbuf[1];
}
6 changes: 2 additions & 4 deletions libctru/source/services/soc/soc_common.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "soc_common.h"
#include <errno.h>
#include <sys/iosupport.h>
#include <errno.h>
#include "soc_common.h"

Handle SOCU_handle = 0;
Handle socMemhandle = 0;
int h_errno = 0;

//This is based on the array from libogc network_wii.c.
Expand Down
5 changes: 2 additions & 3 deletions libctru/source/services/soc/soc_common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <errno.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/iosupport.h>
#include <sys/socket.h>
#include <3ds/types.h>
Expand All @@ -12,8 +12,7 @@
#define SYNC_ERROR ENODEV
#define ADDR_STORAGE_LEN sizeof(struct sockaddr_storage)

extern Handle SOCU_handle;
extern Handle socMemhandle;
Result socSendSyncRequest();

static inline int
soc_get_fd(int fd)
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
cmdbuf[5] = IPC_Desc_StaticBuffer(tmp_addrlen,0);
cmdbuf[6] = (u32)tmpaddr;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();
if(ret != 0) {
errno = SYNC_ERROR;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int fcntl(int sockfd, int cmd, ...)
cmdbuf[3] = (u32)arg;
cmdbuf[4] = IPC_Desc_CurProcessId();

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();
if(ret != 0) {
errno = SYNC_ERROR;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static int getaddrinfo_detail(const char *node, const char *service, const struc
staticbufs[0] = IPC_Desc_StaticBuffer(sizeof(addrinfo_3ds_t) * info_count, 0);
staticbufs[1] = (u32)info;

int ret = svcSendSyncRequest(SOCU_handle);
int ret = socSendSyncRequest();

// Restore the thread storage values
for(i = 0 ; i < 2 ; ++i)
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_gethostbyaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct hostent* gethostbyaddr(const void *addr, socklen_t len, int type)
cmdbuf[0x100>>2] = (sizeof(outbuf) << 14) | 2;
cmdbuf[0x104>>2] = (u32)outbuf;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();
if(ret != 0) {
h_errno = NO_RECOVERY;
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_gethostbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct hostent* gethostbyname(const char *name)
staticbufs[0] = IPC_Desc_StaticBuffer(sizeof(outbuf),0);
staticbufs[1] = (u32)outbuf;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

staticbufs[0] = saved_threadstorage[0];
staticbufs[1] = saved_threadstorage[1];
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_gethostid.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ long gethostid(void)

cmdbuf[0] = IPC_MakeHeader(0x16,0,0); // 0x160000

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();
if(ret != 0) {
errno = SYNC_ERROR;
return -1;
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_
staticbufs[2] = IPC_Desc_StaticBuffer(servlen,0);
staticbufs[3] = (u32)serv;

Result ret = svcSendSyncRequest(SOCU_handle);
Result ret = socSendSyncRequest();

// Restore the thread storage values
for(i = 0 ; i < 4 ; ++i)
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getnetworkopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int SOCU_GetNetworkOpt(int level, NetworkOpt optname, void * optval, socklen_t *
staticbufs[0] = IPC_Desc_StaticBuffer(*optlen, 0);
staticbufs[1] = (u32)optval;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

// Restore the thread storage values
for(i = 0 ; i < 2 ; ++i)
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getpeername.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
staticbufs[0] = IPC_Desc_StaticBuffer(ADDR_STORAGE_LEN,0);
staticbufs[1] = (u32)tmpaddr;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

staticbufs[0] = saved_threadstorage[0];
staticbufs[1] = saved_threadstorage[1];
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getsockname.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
staticbufs[0] = IPC_Desc_StaticBuffer(ADDR_STORAGE_LEN,0);
staticbufs[1] = (u32)tmpaddr;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

staticbufs[0] = saved_threadstorage[0];
staticbufs[1] = saved_threadstorage[1];
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/soc/soc_getsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl
staticbufs[0] = IPC_Desc_StaticBuffer(*optlen,0);
staticbufs[1] = (u32)optval;

ret = svcSendSyncRequest(SOCU_handle);
ret = socSendSyncRequest();

staticbufs[0] = saved_threadstorage[0];
staticbufs[1] = saved_threadstorage[1];
Expand Down
Loading