Skip to content

3DS: enable mbedTLS #17762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025
Merged
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
1 change: 1 addition & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
@@ -2014,6 +2014,7 @@ ifeq ($(HAVE_BUILTINZLIB), 1)
$(DEPS_DIR)/libz/inflate.o \
$(DEPS_DIR)/libz/inftrees.o \
$(DEPS_DIR)/libz/trees.o \
$(DEPS_DIR)/libz/uncompr.o \
$(DEPS_DIR)/libz/zutil.o
INCLUDE_DIRS += -I$(LIBRETRO_COMM_DIR)/include/compat/zlib
else ifeq ($(HAVE_ZLIB),1)
37 changes: 21 additions & 16 deletions Makefile.ctr
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ LIBRETRO =

DEBUG = 0
CONSOLE_LOG = 0
GRIFFIN_BUILD = 1
HAVE_STATIC_DUMMY ?= 0
GRIFFIN_BUILD = 0
HAVE_STATIC_DUMMY ?= 0
WHOLE_ARCHIVE_LINK = 0
BUILD_3DSX = 1
BUILD_3DS = 0
@@ -87,23 +87,24 @@ else
HAVE_PATCH = 1
HAVE_SCREENSHOTS = 1
HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_RWAV = 1
#HAVE_NETWORKING = 1
#HAVE_IFINFO = 1
#HAVE_CHEEVOS = 1
HAVE_CHEATS = 1
HAVE_VIDEO_FILTER = 1
HAVE_DSP_FILTER = 1
HAVE_CONFIGFILE = 1
HAVE_OVERLAY = 1
HAVE_GFX_WIDGETS = 1
HAVE_NETWORKING = 1
HAVE_IFINFO = 1
HAVE_CHEEVOS = 1
#HAVE_SOCKET_LEGACY = 1
HAVE_THREADS = 1
#HAVE_SSL = 1
#HAVE_BUILTINMBEDTLS = 1
HAVE_BUILTINMBEDTLS = 1
HAVE_CORE_INFO_CACHE = 1

include Makefile.common
CFLAGS += $(DEF_FLAGS)
BLACKLIST :=
BLACKLIST += input/input_overlay.o
BLACKLIST += tasks/task_overlay.o
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
endif

ifeq ($(strip $(DEVKITPRO)),)
@@ -155,7 +156,6 @@ ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=so

CFLAGS += -mword-relocations \
-ffast-math \
-Werror=implicit-function-declaration \
$(ARCH)

#CFLAGS += -Wall
@@ -188,17 +188,17 @@ CFLAGS += -I. \
-Ideps \
-Ideps/7zip \
-Ideps/stb \
-Ideps/mbedtls \
-Ideps/rcheevos/include \
-Ilibretro-common/include \
-Ilibretro-common/include/compat/zlib

CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE
CFLAGS += -DHAVE_DSP_FILTER
CFLAGS += -DHAVE_VIDEO_FILTER
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)
CFLAGS += -DHAVE_CHEATS
CFLAGS += -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_CORES -DHAVE_UPDATE_CORE_INFO

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CFLAGS += -Werror=implicit-function-declaration

ASFLAGS := -g $(ARCH) -O3
LDFLAGS += -specs=ctr/3dsx_custom.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
@@ -222,6 +222,10 @@ else
LIBS += -lctru
endif

ifneq ($(V),1)
Q := @
endif

ifeq ($(BUILD_3DSX), 1)
TARGET_3DSX := $(TARGET).3dsx $(TARGET).smdh
endif
@@ -291,7 +295,8 @@ endif
$(CXX) -c -o $@ $< $(CXXFLAGS) $(INCDIRS)

%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS)
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS)

%.o: %.s
$(CC) -c -o $@ $< $(ASFLAGS)
2 changes: 1 addition & 1 deletion Makefile.ctr.salamander
Original file line number Diff line number Diff line change
@@ -85,7 +85,6 @@ ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=so

CFLAGS += -mword-relocations \
-fomit-frame-pointer -ffast-math \
-Werror=implicit-function-declaration \
$(ARCH)

#CFLAGS += -Wall
@@ -111,6 +110,7 @@ CFLAGS += -I. -Ideps/7zip -Ideps/stb -Ilibretro-common/include -Ilibretro-common
CFLAGS += -DRARCH_CONSOLE -DIS_SALAMANDER

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CFLAGS += -Werror=implicit-function-declaration

ASFLAGS := -g $(ARCH) -O3
LDFLAGS += -specs=ctr/3dsx_custom.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
4 changes: 3 additions & 1 deletion audio/drivers/ctr_dsp_audio.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@

#include "../audio_driver.h"
#include "../../ctr/ctr_debug.h"
#include "../../retroarch.h"
#include "../../verbosity.h"

typedef struct
{
@@ -113,7 +115,7 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t len)
* changed, this prevents a hang on sleep. */
if (!aptMainLoop())
{
command_event(CMD_EVENT_QUIT, NULL);
retroarch_main_quit();
return true;
}

2 changes: 2 additions & 0 deletions audio/drivers/ctr_dsp_thread_audio.c
Original file line number Diff line number Diff line change
@@ -16,11 +16,13 @@
#include <3ds.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <queues/fifo_queue.h>
#include <rthreads/rthreads.h>

#include "../audio_driver.h"
#include "../../ctr/ctr_debug.h"
#include "../../verbosity.h"

typedef struct
{
2 changes: 2 additions & 0 deletions ctr/gpu_old.c
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@
#include <3ds/gpu/gx.h>
#include <3ds/gpu/shbin.h>

#define DEPRECATED
#include "gpu_old.h"
#undef DEPRECATED

void GPU_Init(Handle *gsphandle)
{
10 changes: 10 additions & 0 deletions deps/mbedtls/mbedtls/config.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,14 @@
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H

#ifdef _3DS
#define unix
#define MBEDTLS_NO_IPV6
#ifndef _SOCKLEN_T_DECLARED
#define _SOCKLEN_T_DECLARED
#endif
#endif

#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
@@ -2020,7 +2028,9 @@
*
* This module is used by the HAVEGE random number generator.
*/
#ifndef _3DS
#define MBEDTLS_TIMING_C
#endif

/**
* \def MBEDTLS_VERSION_C
2 changes: 2 additions & 0 deletions deps/mbedtls/net_sockets.c
Original file line number Diff line number Diff line change
@@ -400,6 +400,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,

memcpy( client_ip, &addr4->sin_addr.s_addr, *ip_len );
}
#ifndef MBEDTLS_NO_IPV6
else
{
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr;
@@ -410,6 +411,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,

memcpy( client_ip, &addr6->sin6_addr.s6_addr, *ip_len);
}
#endif
}

return( 0 );
27 changes: 27 additions & 0 deletions deps/rcheevos/src/rc_compat.c
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@
#include <ctype.h>
#include <stdarg.h>

#if defined(_3DS) && !defined(_POSIX_THREADS)
#include <../rthreads/ctr_pthread.h>
#endif

#ifdef RC_C89_HELPERS

int rc_strncasecmp(const char* left, const char* right, size_t length)
@@ -138,6 +142,29 @@ void rc_mutex_unlock(rc_mutex_t* mutex)
LWP_MutexUnlock(mutex);
}

#elif defined(_3DS)

void rc_mutex_init(rc_mutex_t* mutex)
{
RecursiveLock_Init(mutex);
}

void rc_mutex_destroy(rc_mutex_t* mutex)
{
/* Nothing to do here */
(void)mutex;
}

void rc_mutex_lock(rc_mutex_t* mutex)
{
RecursiveLock_Lock(mutex);
}

void rc_mutex_unlock(rc_mutex_t* mutex)
{
RecursiveLock_Unlock(mutex);
}

#else

void rc_mutex_init(rc_mutex_t* mutex)
3 changes: 3 additions & 0 deletions deps/rcheevos/src/rc_compat.h
Original file line number Diff line number Diff line change
@@ -81,6 +81,9 @@ RC_BEGIN_C_DECLS
typedef struct rc_mutex_t {
void* handle; /* HANDLE is defined as "void*" */
} rc_mutex_t;
#elif defined(_3DS)
#include <3ds/synchronization.h>
typedef RecursiveLock rc_mutex_t;
#else
#include <pthread.h>
typedef pthread_mutex_t rc_mutex_t;
13 changes: 9 additions & 4 deletions frontend/drivers/platform_ctr.c
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@
#endif
#endif

#include "../../audio/audio_driver.h"
#include "../../menu/menu_entries.h"

static enum frontend_fork ctr_fork_mode = FRONTEND_FORK_NONE;
static const char* elf_path_cst = "sdmc:/retroarch/retroarch.3dsx";

@@ -139,6 +142,12 @@ static void frontend_ctr_get_env(int* argc, char* argv[],
#endif
}

#ifdef USE_CTRULIB_2
u8* gfxTopLeftFramebuffers[2];
u8* gfxTopRightFramebuffers[2];
u8* gfxBottomFramebuffers[2];
#endif

static void frontend_ctr_deinit(void* data)
{
Handle lcd_handle;
@@ -371,10 +380,6 @@ __attribute__((weak)) u32 __ctr_patch_services;
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id);

#ifdef USE_CTRULIB_2
u8* gfxTopLeftFramebuffers[2];
u8* gfxTopRightFramebuffers[2];
u8* gfxBottomFramebuffers[2];

void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
{
if (screen==GFX_TOP)
3 changes: 3 additions & 0 deletions gfx/drivers/ctr_gfx.c
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@
#endif

#include "../font_driver.h"
#define DEPRECATED
#include "../../ctr/gpu_old.h"
#undef DEPRECATED
#include "ctr_gu.h"

#include "../../configuration.h"
@@ -49,6 +51,7 @@
#include "../../retroarch.h"
#include "../../runloop.h"
#include "../../verbosity.h"
#include "../../paths.h"

#include "../common/ctr_defines.h"
#ifndef HAVE_THREADS
5 changes: 5 additions & 0 deletions gfx/video_thread_wrapper.c
Original file line number Diff line number Diff line change
@@ -23,6 +23,11 @@
#include <features/features_cpu.h>
#include <string/stdstring.h>

#ifdef _3DS
#include <3ds/types.h>
#include <3ds/allocator/linear.h> /* linearMemAlign() */
#endif

#include "video_driver.h"
#include "video_thread_wrapper.h"
#include "font_driver.h"
22 changes: 21 additions & 1 deletion libretro-common/net/net_socket_ssl_mbed.c
Original file line number Diff line number Diff line change
@@ -25,6 +25,11 @@
#include <net/net_socket.h>
#include <net/net_socket_ssl.h>

#ifdef _3DS
#include <3ds/types.h>
#include <3ds/services/ps.h>
#endif

#if defined(HAVE_BUILTINMBEDTLS)
#include "../../deps/mbedtls/mbedtls/config.h"
#include "../../deps/mbedtls/mbedtls/certs.h"
@@ -76,6 +81,15 @@ static void ssl_debug(void *ctx, int level,
fflush((FILE*)ctx);
}

#ifdef _3DS
int ctr_entropy_func(void *data, unsigned char *buffer, size_t size)
{
(void)data;
PS_GenerateRandomBytes(buffer, size);
return 0;
}
#endif

void* ssl_socket_init(int fd, const char *domain)
{
static const char *pers = "libretro";
@@ -98,7 +112,13 @@ void* ssl_socket_init(int fd, const char *domain)

state->net_ctx.fd = fd;

if (mbedtls_ctr_drbg_seed(&state->ctr_drbg, mbedtls_entropy_func, &state->entropy, (const unsigned char*)pers, strlen(pers)) != 0)
if (mbedtls_ctr_drbg_seed(&state->ctr_drbg,
#ifdef _3DS
ctr_entropy_func,
#else
mbedtls_entropy_func,
#endif
&state->entropy, (const unsigned char*)pers, strlen(pers)) != 0)
goto error;

#if defined(MBEDTLS_X509_CRT_PARSE_C)
2 changes: 1 addition & 1 deletion libretro-common/queues/task_queue.c
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#endif
#ifdef EMSCRIPTEN
#if defined(EMSCRIPTEN) || defined(_3DS)
#include <retro_timers.h>
#endif
#ifdef HAVE_GCD
4 changes: 4 additions & 0 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
@@ -140,6 +140,10 @@
#include "../steam/steam.h"
#endif

#ifdef _3DS
#include <3ds/services/cfgu.h> /* CFGU_GetSystemModel */
#endif

/* Spacers used for '<content> - <core name>' labels
* in playlists */
#define PL_LABEL_SPACER_DEFAULT " | "