diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml
new file mode 100644
index 0000000000..cd8cc2c70b
--- /dev/null
+++ b/.github/workflows/crowdin.yml
@@ -0,0 +1,28 @@
+# Upload sources to Crowdin for translation
+
+name: Crowdin Workflow
+
+on:
+ push:
+ branches:
+ - master
+ paths:
+ - 'intl/*_us.h'
+ - 'intl/*_us.json'
+
+jobs:
+ sync:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Setup Java JDK
+ uses: actions/setup-java@v1.3.0
+ with:
+ java-version: 1.8
+ - name: Setup Python
+ uses: actions/setup-python@v2
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Crowdin Sync
+ run: |
+ cd intl
+ python3 crowdin_sync.py
diff --git a/.gitignore b/.gitignore
index 1a132fbd29..ebb953d4a9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,7 +76,9 @@ convert_rumble.awk
*~
assets
info
+content_history.lpl
content_image_history.lpl
+content_music_history.lpl
saves
screenshots
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2dc110ece3..edc28e0361 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -63,7 +63,6 @@
"xtree": "c",
"xutility": "c",
"menu_input_dialog.h": "c",
- "menu_filebrowser.h": "c",
"ozone_sidebar.h": "c",
"menu_thumbnail_path.h": "c",
"badges.h": "c"
diff --git a/CHANGES.md b/CHANGES.md
index 153d3486b0..edde89bcd3 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,4 +1,24 @@
# Future
+- BLUETOOTH: Add a Bluetooth driver (Lakka-only for now)
+- CHEEVOS: Option to play sound on achievement unlock.
+- CHEEVOS: Upgrade to rcheevos 9.1
+- CHEEVOS: Restore display of unlocked achievements across hardcore modes
+- CHEEVOS: Hash buffered data when available
+- CHEEVOS: Fix 'Auto Save State freezes RetroArch while Cheevos is enabled'
+- CONFIG FILE: Optimise parsing of configuration files
+- D3D9/D3D11: Fix core-initiated D3D9/D3D11 driver switches
+- DRIVERS: Implemented protection to avoid setting critical drivers to nothing thus preventing the user from locking him/herself out of the program
+- EMSCRIPTEN: Fix input code to ignore unknown keys
+- FILE I/O: VFS and NBIO interfaces will now use 64-bit fseek/ftell where possible, should allow for reading/writing to files bigger than 2GB
+- IOS: Fixed iOS 6 version
+- LOCALIZATION: Updates for several languages (synchronized from Crowdin)
+- MENU: Enlarged INT/UINT selection limit from 999 to 9999
+- MENU: Fix cursor forced to first entry after displaying lists
+- MENU/WIDGETS: Add optional widget-based 'load content' launch feedback animation
+- ODROID GO ADVANCE: Video driver - fix race condition with RGUI callback
+- SHADERS/SLANG: Increased Slang max Parameters, Textures & Passes
+- WINDOWS/RAWINPUT: Fix invalid calls to dinput_handle_message when input driver is not set to dinput
+- X11: Add lightgun support
# 1.8.9
- AUTO SAVESTATES: Ensure save states are correctly flushed to disk when quitting RetroArch (fixes broken save states when exiting RetroArch - without first closing content - with 'Auto Save State' enabled)
diff --git a/Makefile b/Makefile
index 00e0258c00..669bd55283 100644
--- a/Makefile
+++ b/Makefile
@@ -217,7 +217,7 @@ $(OBJDIR)/%.o: %.m
.FORCE:
-$(OBJDIR)/git_version.o: git_version.c .FORCE
+$(OBJDIR)/version_git.o: version_git.c .FORCE
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<
@@ -233,7 +233,7 @@ $(OBJDIR)/%.o: %.rc $(HEADERS)
$(Q)$(WINDRES) -o $@ $<
install: $(TARGET)
- rm -f $(OBJDIR)/git_version.o
+ rm -f $(OBJDIR)/version_git.o
mkdir -p $(DESTDIR)$(BIN_DIR) 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)$(GLOBAL_CONFIG_DIR) 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)$(DATA_DIR)/applications 2>/dev/null || /bin/true
diff --git a/Makefile.common b/Makefile.common
index 5e102ce1dc..033ec64f98 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -175,8 +175,14 @@ OBJ += frontend/frontend_driver.o \
msg_hash.o \
intl/msg_hash_us.o \
$(LIBRETRO_COMM_DIR)/queues/task_queue.o \
- tasks/task_content.o \
- tasks/task_patch.o \
+ tasks/task_content.o
+
+ifeq ($(HAVE_PATCH), 1)
+ DEFINES += -DHAVE_PATCH
+ OBJ += tasks/task_patch.o
+endif
+
+OBJ += \
tasks/task_save.o \
tasks/task_file_transfer.o \
tasks/task_image.o \
@@ -184,8 +190,13 @@ OBJ += frontend/frontend_driver.o \
tasks/task_manual_content_scan.o \
tasks/task_core_backup.o \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.o \
- $(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o \
- $(LIBRETRO_COMM_DIR)/encodings/encoding_base64.o \
+ $(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o
+
+ifeq ($(HAVE_TRANSLATE), 1)
+ OBJ += $(LIBRETRO_COMM_DIR)/encodings/encoding_base64.o
+endif
+
+OBJ += \
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.o \
$(LIBRETRO_COMM_DIR)/lists/file_list.o \
$(LIBRETRO_COMM_DIR)/lists/dir_list.o \
@@ -195,8 +206,9 @@ OBJ += frontend/frontend_driver.o \
$(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.o \
$(LIBRETRO_COMM_DIR)/streams/interface_stream.o \
$(LIBRETRO_COMM_DIR)/streams/memory_stream.o \
- $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o \
- $(LIBRETRO_COMM_DIR)/media/media_detect_cd.o \
+ $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o
+
+OBJ += \
$(LIBRETRO_COMM_DIR)/lists/string_list.o \
$(LIBRETRO_COMM_DIR)/string/stdstring.o \
$(LIBRETRO_COMM_DIR)/memmap/memalign.o \
@@ -236,34 +248,68 @@ OBJ += \
configuration.o \
$(LIBRETRO_COMM_DIR)/dynamic/dylib.o \
cores/dynamic_dummy.o \
- $(LIBRETRO_COMM_DIR)/queues/message_queue.o \
- managers/state_manager.o \
+ $(LIBRETRO_COMM_DIR)/queues/message_queue.o
+
+ifeq ($(HAVE_REWIND), 1)
+DEFINES += -DHAVE_REWIND
+OBJ += managers/state_manager.o
+endif
+
+OBJ += \
gfx/drivers_font_renderer/bitmapfont.o \
tasks/task_autodetect.o \
input/input_autodetect_builtin.o \
input/input_keymaps.o \
$(LIBRETRO_COMM_DIR)/queues/fifo_queue.o \
$(LIBRETRO_COMM_DIR)/compat/compat_fnmatch.o \
- $(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o \
- managers/cheat_manager.o \
+ $(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o
+
+ifeq ($(HAVE_CHEATS), 1)
+ DEFINES += -DHAVE_CHEATS
+ OBJ += managers/cheat_manager.o
+endif
+
+OBJ += \
core_info.o \
core_backup.o \
$(LIBRETRO_COMM_DIR)/file/config_file.o \
$(LIBRETRO_COMM_DIR)/file/config_file_userdata.o \
runtime_file.o \
- disk_index_file.o \
- tasks/task_screenshot.o \
+ disk_index_file.o
+
+ifeq ($(HAVE_SCREENSHOTS), 1)
+ DEFINES += -DHAVE_SCREENSHOTS
+ OBJ += tasks/task_screenshot.o
+endif
+
+OBJ += \
tasks/task_powerstate.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/pixconv.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_int.o \
$(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_filter.o \
- gfx/font_driver.o \
- gfx/video_filter.o \
- $(LIBRETRO_COMM_DIR)/audio/resampler/audio_resampler.o \
- $(LIBRETRO_COMM_DIR)/audio/dsp_filter.o \
- $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.o \
- $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/nearest_resampler.o \
+ gfx/font_driver.o
+
+ifeq ($(HAVE_VIDEO_FILTER), 1)
+DEFINES += -DHAVE_VIDEO_FILTER
+OBJ += gfx/video_filter.o
+endif
+
+OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/audio_resampler.o
+
+ifeq ($(HAVE_DSP_FILTER), 1)
+DEFINES += -DHAVE_DSP_FILTER
+OBJ += $(LIBRETRO_COMM_DIR)/audio/dsp_filter.o
+endif
+
+OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.o
+
+ifeq ($(HAVE_NEAREST_RESAMPLER), 1)
+ DEFINES += -DHAVE_NEAREST_RESAMPLER
+ OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/nearest_resampler.o
+endif
+
+OBJ += \
$(LIBRETRO_COMM_DIR)/utils/md5.o \
playlist.o \
$(LIBRETRO_COMM_DIR)/features/features_cpu.o \
@@ -275,7 +321,6 @@ OBJ += \
ifeq ($(HAVE_CONFIGFILE), 1)
DEFINES += -DHAVE_CONFIGFILE
- OBJ += input/input_remapping.o
endif
ifeq ($(HAVE_BLISSBOX), 1)
@@ -290,6 +335,10 @@ ifeq ($(HAVE_AUDIOMIXER), 1)
$(LIBRETRO_COMM_DIR)/audio/audio_mixer.o
endif
+ifeq ($(HAVE_BSV_MOVIE), 1)
+ DEFINES += -DHAVE_BSV_MOVIE
+endif
+
ifeq ($(HAVE_RUNAHEAD), 1)
DEFINES += -DHAVE_RUNAHEAD
endif
@@ -486,27 +535,20 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/ccm.o \
deps/mbedtls/cipher.o \
deps/mbedtls/cipher_wrap.o \
- deps/mbedtls/cmac.o \
deps/mbedtls/ctr_drbg.o \
deps/mbedtls/des.o \
deps/mbedtls/dhm.o \
deps/mbedtls/ecdh.o \
deps/mbedtls/ecdsa.o \
- deps/mbedtls/ecjpake.o \
deps/mbedtls/ecp.o \
deps/mbedtls/ecp_curves.o \
deps/mbedtls/entropy.o \
deps/mbedtls/entropy_poll.o \
- deps/mbedtls/error.o \
deps/mbedtls/gcm.o \
- deps/mbedtls/havege.o \
deps/mbedtls/hmac_drbg.o \
deps/mbedtls/md.o \
- deps/mbedtls/md2.o \
- deps/mbedtls/md4.o \
deps/mbedtls/md5.o \
deps/mbedtls/md_wrap.o \
- deps/mbedtls/memory_buffer_alloc.o \
deps/mbedtls/oid.o \
deps/mbedtls/padlock.o \
deps/mbedtls/pem.o \
@@ -516,7 +558,6 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/pkcs5.o \
deps/mbedtls/pkparse.o \
deps/mbedtls/pkwrite.o \
- deps/mbedtls/platform.o \
deps/mbedtls/ripemd160.o \
deps/mbedtls/rsa.o \
deps/mbedtls/sha1.o \
@@ -524,12 +565,9 @@ ifeq ($(HAVE_BUILTINMBEDTLS), 1)
deps/mbedtls/sha512.o \
deps/mbedtls/threading.o \
deps/mbedtls/timing.o \
- deps/mbedtls/version.o \
- deps/mbedtls/version_features.o \
deps/mbedtls/xtea.o
OBJS_TLS_X509 = deps/mbedtls/certs.o \
- deps/mbedtls/pkcs11.o \
deps/mbedtls/x509.o \
deps/mbedtls/x509_create.o \
deps/mbedtls/x509_crl.o \
@@ -568,6 +606,16 @@ ifeq ($(HAVE_EMSCRIPTEN), 1)
camera/drivers/rwebcam.o
endif
+ifeq ($(HAVE_BLUETOOTH), 1)
+ OBJ += bluetooth/drivers/bluetoothctl.o
+endif
+
+ifeq ($(HAVE_BLUETOOTH), 1)
+ ifeq ($(HAVE_DBUS), 1)
+ OBJ += bluetooth/drivers/bluez.o
+ endif
+endif
+
ifeq ($(HAVE_LAKKA), 1)
OBJ += wifi/drivers/connmanctl.o
endif
@@ -720,8 +768,11 @@ ifeq ($(HAVE_NEON),1)
endif
OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float.o \
- $(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16.o \
- $(LIBRETRO_COMM_DIR)/formats/wav/rwav.o
+ $(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16.o
+
+ifeq ($(HAVE_RWAV), 1)
+OBJ += $(LIBRETRO_COMM_DIR)/formats/wav/rwav.o
+endif
ifeq ($(HAVE_NEON),1)
OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float_neon.o \
@@ -810,6 +861,10 @@ ifeq ($(HAVE_MENU), 1)
endif
endif
+ifeq ($(HAVE_BLUETOOTH), 1)
+ DEFINES += -DHAVE_BLUETOOTH
+endif
+
ifeq ($(HAVE_LAKKA), 1)
DEFINES += -DHAVE_LAKKA
endif
@@ -820,9 +875,6 @@ endif
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/menu_setting.o \
- menu/widgets/menu_filebrowser.o \
- menu/widgets/menu_dialog.o \
- menu/widgets/menu_input_bind_dialog.o \
menu/cbs/menu_cbs_ok.o \
menu/cbs/menu_cbs_cancel.o \
menu/cbs/menu_cbs_select.o \
@@ -844,11 +896,18 @@ ifeq ($(HAVE_MENU_COMMON), 1)
endif
ifeq ($(HAVE_GFX_WIDGETS), 1)
- OBJ += gfx/gfx_widgets.o \
- gfx/widgets/gfx_widget_screenshot.o \
+ OBJ += gfx/gfx_widgets.o
+
+ ifeq ($(HAVE_SCREENSHOTS), 1)
+ OBJ += gfx/widgets/gfx_widget_screenshot.o
+ endif
+
+ OBJ += \
gfx/widgets/gfx_widget_volume.o \
gfx/widgets/gfx_widget_generic_message.o \
- gfx/widgets/gfx_widget_libretro_message.o
+ gfx/widgets/gfx_widget_libretro_message.o \
+ gfx/widgets/gfx_widget_progress_message.o \
+ gfx/widgets/gfx_widget_load_content_animation.o
ifeq ($(HAVE_CHEEVOS), 1)
OBJ += gfx/widgets/gfx_widget_achievement_popup.o
endif
@@ -993,11 +1052,17 @@ endif
ifeq ($(HAVE_WAYLAND), 1)
OBJ += gfx/drivers_context/wayland_ctx.o \
+ input/common/wayland_common.o \
input/drivers/wayland_input.o \
gfx/common/wayland/xdg-shell.o \
gfx/common/wayland/xdg-shell-unstable-v6.o \
gfx/common/wayland/idle-inhibit-unstable-v1.o \
gfx/common/wayland/xdg-decoration-unstable-v1.o
+
+ ifeq ($(HAVE_VULKAN), 1)
+ OBJ += gfx/drivers_context/wayland_vk_ctx.o
+ endif
+
DEF_FLAGS += $(WAYLAND_CFLAGS) $(WAYLAND_CURSOR_CFLAGS)
LIBS += $(WAYLAND_LIBS) $(WAYLAND_CURSOR_LIBS)
@@ -1044,6 +1109,9 @@ ifeq ($(HAVE_X11), 1)
ifneq ($(HAVE_OPENGLES), 1)
OBJ += gfx/drivers_context/x_ctx.o
endif
+ ifeq ($(HAVE_VULKAN), 1)
+ OBJ += gfx/drivers_context/x_vk_ctx.o
+ endif
endif
ifeq ($(HAVE_XCB),1)
@@ -1106,7 +1174,10 @@ ifeq ($(HAVE_PARPORT), 1)
endif
ifneq ($(findstring Win32,$(OS)),)
- OBJ += input/drivers/winraw_input.o
+ifeq ($(HAVE_WINRAWINPUT), 1)
+ DEFINES += -DHAVE_WINRAWINPUT
+ OBJ += input/drivers/winraw_input.o
+endif
endif
# Companion UI
@@ -1145,8 +1216,8 @@ endif
ifeq ($(HAVE_SIXEL), 1)
DEFINES += -DHAVE_SIXEL
INCLUDE_DIRS += -I/usr/include/sixel
- OBJ += gfx/drivers/sixel_gfx.o gfx/drivers_font/sixel_font.o \
- gfx/drivers_context/sixel_ctx.o
+ OBJ += gfx/drivers/sixel_gfx.o \
+ gfx/drivers_font/sixel_font.o
LIBS += $(SIXEL_LIBS)
DEF_FLAGS += $(SIXEL_CFLAGS)
endif
@@ -1165,8 +1236,7 @@ ifeq ($(HAVE_NETWORK_VIDEO), 1)
endif
DEFINES += -DHAVE_NETWORK_VIDEO
- OBJ += gfx/drivers/network_gfx.o \
- gfx/drivers_context/network_ctx.o
+ OBJ += gfx/drivers/network_gfx.o
endif
ifeq ($(HAVE_PLAIN_DRM), 1)
@@ -1550,12 +1620,15 @@ ifeq ($(HAVE_BUILTINGLSLANG), 1)
GLSLANG_SOURCES := \
gfx/drivers_shader/glslang.cpp \
- $(wildcard $(DEPS_DIR)/glslang/glslang/SPIRV/*.cpp) \
+ $(DEPS_DIR)/glslang/glslang/SPIRV/GlslangToSpv.cpp \
+ $(DEPS_DIR)/glslang/glslang/SPIRV/InReadableOrder.cpp \
+ $(DEPS_DIR)/glslang/glslang/SPIRV/Logger.cpp \
+ $(DEPS_DIR)/glslang/glslang/SPIRV/SpvBuilder.cpp \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/GenericCodeGen/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/OGLCompilersDLL/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/*.cpp) \
$(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/preprocessor/*.cpp) \
- $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM)/*.cpp)
+ $(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM)/ossource.cpp
ifneq ($(findstring Win32,$(OS)),)
DEFINES += -DENABLE_HLSL
@@ -1594,6 +1667,9 @@ endif
ifeq ($(WANT_WGL), 1)
OBJ += gfx/drivers_context/wgl_ctx.o
+ ifeq ($(HAVE_VULKAN),1)
+ OBJ += gfx/drivers_context/w_vk_ctx.o
+ endif
LIBS += -lcomctl32
endif
@@ -1665,7 +1741,6 @@ endif
ifeq ($(HAVE_BUILTINZLIB), 1)
HAVE_ZLIB_COMMON = 1
OBJ += $(DEPS_DIR)/libz/adler32.o \
- $(DEPS_DIR)/libz/compress.o \
$(DEPS_DIR)/libz/libz-crc32.o \
$(DEPS_DIR)/libz/deflate.o \
$(DEPS_DIR)/libz/gzclose.o \
@@ -1676,7 +1751,6 @@ 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)
@@ -1719,7 +1793,8 @@ ifeq ($(HAVE_CDROM), 1)
DEFINES += -DHAVE_CDROM
OBJ += $(LIBRETRO_COMM_DIR)/cdrom/cdrom.o \
- $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_cdrom.o
+ $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_cdrom.o \
+ $(LIBRETRO_COMM_DIR)/media/media_detect_cd.o
endif
ifeq ($(HAVE_RTGA), 1)
@@ -1795,6 +1870,7 @@ ifeq ($(HAVE_NETWORKING), 1)
tasks/task_http.o \
tasks/task_netplay_lan_scan.o \
tasks/task_netplay_nat_traversal.o \
+ tasks/task_bluetooth.o \
tasks/task_wifi.o \
tasks/task_pl_thumbnail_download.o \
tasks/task_netplay_find_content.o
@@ -1965,8 +2041,7 @@ ifeq ($(HAVE_NETWORKING), 1)
endif
ifneq ($(findstring FPGA,$(OS)),)
- OBJ += gfx/drivers/fpga_gfx.o \
- gfx/drivers_context/fpga_ctx.o
+ OBJ += gfx/drivers/fpga_gfx.o
endif
ifneq ($(findstring Win32,$(OS)),)
@@ -1977,7 +2052,6 @@ ifneq ($(findstring Win32,$(OS)),)
ifeq ($(HAVE_GDI), 1)
OBJ += gfx/drivers/gdi_gfx.o \
- gfx/drivers_context/gdi_ctx.o \
gfx/drivers_font/gdi_font.o \
gfx/drivers_display/gfx_display_gdi.o
LIBS += -lmsimg32
@@ -2093,8 +2167,14 @@ ifeq ($(HAVE_MATH_NEON), 1)
endif
ifeq ($(HAVE_VITAGL), 1)
- DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING
- INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source
+ INCLUDE_DIRS += -I$(DEPS_DIR)/vitaShaRK/source
+ SOURCES := $(DEPS_DIR)/vitaShaRK/source
+ OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
+endif
+
+ifeq ($(HAVE_VITAGL), 1)
+ DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING -DHAVE_SHARK
+ INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source -I$(DEPS_DIR)/vitaShaRK/include
SOURCES := $(DEPS_DIR)/vitaGL/source $(DEPS_DIR)/vitaGL/source/utils
OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif
diff --git a/Makefile.ctr b/Makefile.ctr
index 3fe03430a6..bde79c9f5f 100644
--- a/Makefile.ctr
+++ b/Makefile.ctr
@@ -53,6 +53,9 @@ ifeq ($(GRIFFIN_BUILD), 1)
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_ZLIB -DHAVE_7ZIP -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA
DEFINES += -DHAVE_NETWORKING -DHAVE_CHEEVOS -DRC_DISABLE_LUA
+ DEFINES += -DHAVE_PATCH -DHAVE_RWAV
+ DEFINES += -DHAVE_SCREENSHOTS
+ DEFINES += -DHAVE_REWIND
#DEFINES += -DHAVE_SOCKET_LEGACY -DHAVE_THREADS
#-DHAVE_SSL -DHAVE_BUILTINMBEDTLS -DMBEDTLS_SSL_DEBUG_ALL
#ssl is currently incompatible with griffin due to use of the "static" flag on repeating functions that will conflict when included in one file
@@ -73,6 +76,11 @@ else
HAVE_XMB = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
+ HAVE_PATCH = 1
+ HAVE_SCREENSHOTS = 1
+ HAVE_REWIND = 1
+ HAVE_AUDIOMIXER = 1
+ HAVE_RWAV = 1
#HAVE_NETWORKING = 1
#HAVE_CHEEVOS = 1
#HAVE_SOCKET_LEGACY = 1
@@ -141,7 +149,10 @@ CFLAGS += -I. \
-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
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
diff --git a/Makefile.dingux b/Makefile.dingux
index 7b00ae1370..9948435266 100644
--- a/Makefile.dingux
+++ b/Makefile.dingux
@@ -4,10 +4,14 @@ PACKAGE_NAME = retroarch
DEBUG ?= 0
+HAVE_SCREENSHOTS = 1
+HAVE_REWIND = 1
HAVE_7ZIP = 1
HAVE_AL = 1
# this freezes when switching back from menu
HAVE_ALSA = 0
+HAVE_DSP_FILTER = 1
+HAVE_VIDEO_FILTER = 1
HAVE_BUILTINMBEDTLS = 1
HAVE_BUILTINZLIB = 1
HAVE_C99 = 1
@@ -62,6 +66,8 @@ HAVE_VIDEO_LAYOUT = 1
HAVE_XMB = 1
HAVE_ZLIB = 1
HAVE_CONFIGFILE = 1
+HAVE_PATCH = 1
+HAVE_CHEATS = 1
OS = Linux
TARGET = retroarch
@@ -160,7 +166,7 @@ $(OBJDIR)/%.o: %.m
.FORCE:
-$(OBJDIR)/git_version.o: git_version.c .FORCE
+$(OBJDIR)/version_git.o: version_git.c .FORCE
@mkdir -p $(dir $@)
@$(if $(Q), $(shell echo echo CC $<),)
$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<
diff --git a/Makefile.emscripten b/Makefile.emscripten
index 5336030fb8..19a98ef475 100644
--- a/Makefile.emscripten
+++ b/Makefile.emscripten
@@ -9,8 +9,12 @@ OBJ :=
DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN -s USE_PTHREADS=$(PTHREAD)
DEFINES += -DHAVE_FILTERS_BUILTIN
+HAVE_DSP_FILTER = 1
+HAVE_VIDEO_FILTER = 1
HAVE_OVERLAY = 1
HAVE_GLSL = 1
+HAVE_SCREENSHOTS = 1
+HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_VIDEO_LAYOUT = 0
HAVE_CC_RESAMPLER = 1
@@ -30,6 +34,7 @@ HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_STB_FONT = 1
HAVE_CONFIGFILE = 1
+HAVE_CHEATS = 1
MEMORY = 134217728
diff --git a/Makefile.griffin b/Makefile.griffin
index 634ccc1472..9d1a607db3 100644
--- a/Makefile.griffin
+++ b/Makefile.griffin
@@ -191,8 +191,9 @@ else ifeq ($(libogc_platform), 1)
CFLAGS += -DGEKKO -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
- HAVE_AUDIOMIXER := 1
HAVE_RUNAHEAD := 1
+ HAVE_DSP_FILTER := 1
+ HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_THREADS := 1
HAVE_RPNG := 1
@@ -204,11 +205,16 @@ else ifeq ($(libogc_platform), 1)
HAVE_VIDEO_LAYOUT := 0
HAVE_ZLIB := 1
HAVE_7ZIP := 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
+ HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
RARCH_CONSOLE = 1
ifeq ($(platform), wii)
- HAVE_AUDIOMIXER := 1
#HAVE_LANGEXTRA := 1
HAVE_WIIUSB_HID := 1
HAVE_RARCH_EXEC := 1
@@ -244,7 +250,9 @@ else ifeq ($(platform), xenon360)
HAVE_THREADS := 1
HAVE_GETOPT_LONG := 1
RARCH_CONSOLE = 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
# PSP
else ifeq ($(platform), psp1)
@@ -269,7 +277,9 @@ else ifeq ($(platform), psp1)
HAVE_KERNEL_PRX := 1
#HAVE_LANGEXTRA := 1
RARCH_CONSOLE = 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
ifeq ($(BUILD_PRX), 1)
LDFLAGS += $(addprefix -L,$(PSPSDK)/lib) -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx $(LDFLAGS)
@@ -309,6 +319,8 @@ else ifeq ($(platform), vita)
LIBDIRS += -L.
LDFLAGS += -Wl,-q
+ HAVE_DSP_FILTER := 1
+ HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 1
HAVE_RPNG := 1
@@ -327,7 +339,9 @@ else ifeq ($(platform), vita)
HAVE_THREADS := 1
HAVE_LIBRETRODB := 1
RARCH_CONSOLE = 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
else ifeq ($(platform), windows_msvc6_x86)
HAVE_RPNG := 1
HAVE_RJPEG := 1
@@ -351,7 +365,9 @@ else ifeq ($(platform), windows_msvc6_x86)
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -395,7 +411,9 @@ else ifeq ($(platform), windows_msvc2003_x86)
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -445,7 +463,9 @@ else ifeq ($(platform), windows_msvc2005_x86)
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
HAVE_DIRECTX ?= 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -472,7 +492,10 @@ else ifeq ($(platform), windows_msvc2005_x86)
endif
else ifneq (,$(findstring windows_msvc2010,$(platform)))
HAVE_GDI := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -497,7 +520,9 @@ else ifneq (,$(findstring windows_msvc2010,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -547,7 +572,10 @@ else ifneq (,$(findstring windows_msvc2010,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2012,$(platform)))
HAVE_GDI := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -572,7 +600,9 @@ else ifneq (,$(findstring windows_msvc2012,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -626,7 +656,10 @@ else ifneq (,$(findstring windows_msvc2012,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2013,$(platform)))
HAVE_GDI := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -651,7 +684,9 @@ else ifneq (,$(findstring windows_msvc2013,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -705,7 +740,10 @@ else ifneq (,$(findstring windows_msvc2013,$(platform)))
endif
else ifneq (,$(findstring windows_msvc2015,$(platform)))
HAVE_GDI := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -730,7 +768,9 @@ else ifneq (,$(findstring windows_msvc2015,$(platform)))
HAVE_GRIFFIN_CPP := 1
HAVE_RUNAHEAD := 1
HAVE_DIRECTX ?= 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -799,7 +839,10 @@ else ifneq (,$(findstring windows_msvc2015,$(platform)))
export LIB := $(LIB)
endif
else ifeq (qnx,$(platform))
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -823,7 +866,10 @@ else ifeq (qnx,$(platform))
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 0
WANT_GLSLANG := 0
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
+
CC=qcc -Vgcc_ntoarmv7le
CXX=QCC -Vgcc_ntoarmv7le
@@ -831,13 +877,16 @@ else ifeq (qnx,$(platform))
LDFLAGS += -g
endif
- PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_XCB -DHAVE_EGL -DHAVE_BB10 -DHAVE_GLSL -DHAVE_AL -DRARCH_MOBILE
+ PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_XCB -DHAVE_EGL -DHAVE_BB10 -DHAVE_GLSL -DHAVE_AL -DHAVE_BSV_MOVIE -DRARCH_MOBILE
EXT_TARGET := $(TARGET_NAME)
EXT_INTER_TARGET := $(TARGET_NAME)
INCLUDE += -Ilibretro-common/include -Igfx/include -Ideps -Ideps/stb -Ideps/rcheevos/include -Ideps/SPIRV-Cross -Ideps/glslang -I.
LIBS += -lEGL -lbps -lscreen -lsocket -lm -lGLESv2 -lOpenAL
else ifneq (,$(findstring unix,$(platform)))
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -861,15 +910,16 @@ else ifneq (,$(findstring unix,$(platform)))
HAVE_DYNAMIC := 1
HAVE_GRIFFIN_CPP := 1
WANT_GLSLANG := 1
- HAVE_CONFIGFILE := 1
+ HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
- PLATCFLAGS += -D__MMX__ -D__SSE__ -DHAVE_OPENGL -DHAVE_OPENGL1 -DHAVE_GLSL -DHAVE_SHADERPIPELINE -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_SLANG -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_VULKAN -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_X11 -DHAVE_XCB -DHAVE_UDEV -DHAVE_PULSE
+ PLATCFLAGS += -D__MMX__ -D__SSE__ -DHAVE_OPENGL -DHAVE_OPENGL1 -DHAVE_GLSL -DHAVE_SHADERPIPELINE -DHAVE_OZONE -DHAVE_CC_RESAMPLER -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_GL_SYNC -DHAVE_SLANG -DHAVE_GLSLANG -DHAVE_BUILTINGLSLANG -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_RUNAHEAD -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES -DHAVE_VULKAN -DHAVE_XMB -DRARCH_INTERNAL -DWANT_GLSLANG -DHAVE_X11 -DHAVE_XCB -DHAVE_UDEV -DHAVE_BSV_MOVIE -DHAVE_PULSE
EXT_TARGET := $(TARGET_NAME)
EXT_INTER_TARGET := $(TARGET_NAME)
INCLUDE += -Ilibretro-common/include -Igfx/include -Ideps -Ideps/stb -Ideps/rcheevos/include -Ideps/SPIRV-Cross -Ideps/glslang -I.
LIBS += -ldl -lm -lpthread -lGL -ludev -lpulse -lX11 -lX11-xcb -lXxf86vm
else ifeq (dos,$(platform))
- HAVE_AUDIOMIXER := 1
HAVE_RPNG := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
@@ -881,7 +931,7 @@ else ifeq (dos,$(platform))
HAVE_NETPLAYDISCOVERY := 0
HAVE_OVERLAY := 1
HAVE_VIDEO_LAYOUT := 0
- HAVE_MATERIALUI := 1
+ HAVE_MATERIALUI := 0
HAVE_XMB := 0
HAVE_STB_FONT := 1
HAVE_THREADS := 0
@@ -894,6 +944,8 @@ else ifeq (dos,$(platform))
HAVE_GRIFFIN_CPP := 0
WANT_GLSLANG := 0
HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 0
+ HAVE_CHEATS := 0
CC=i586-pc-msdosdjgpp-gcc
CXX=i586-pc-msdosdjgpp-g++
@@ -901,7 +953,7 @@ else ifeq (dos,$(platform))
LDFLAGS += -g
endif
- PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_CC_RESAMPLER -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DRARCH_INTERNAL -DHAVE_XCB
+ PLATCFLAGS += -DHAVE_SHADERPIPELINE -DHAVE_CC_RESAMPLER -DRC_DISABLE_LUA -DHAVE_FBO -DHAVE_IMAGEVIEWER -DHAVE_LANGEXTRA -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SPIRV_CROSS -DHAVE_STB_FONT -DRARCH_INTERNAL -DHAVE_XCB
TARGET_NAME := retrodos
EXT_TARGET := $(TARGET_NAME).exe
EXT_INTER_TARGET := $(TARGET_NAME).exe
@@ -995,6 +1047,10 @@ ifeq ($(HAVE_IMAGEVIEWER), 1)
CFLAGS += -DHAVE_IMAGEVIEWER
endif
+ifeq ($(HAVE_BSV_MOVIE), 1)
+ CFLAGS += -DHAVE_BSV_MOVIE
+endif
+
ifeq ($(HAVE_RUNAHEAD), 1)
CFLAGS += -DHAVE_RUNAHEAD
endif
@@ -1003,10 +1059,22 @@ ifeq ($(HAVE_7ZIP), 1)
CFLAGS += -DHAVE_7ZIP
endif
+ifeq ($(HAVE_SCREENSHOTS), 1)
+ CFLAGS += -DHAVE_SCREENSHOTS
+endif
+
+ifeq ($(HAVE_REWIND), 1)
+ CFLAGS += -DHAVE_REWIND
+endif
+
ifeq ($(HAVE_AUDIOMIXER), 1)
CFLAGS += -DHAVE_AUDIOMIXER
endif
+ifeq ($(HAVE_RWAV), 1)
+ CFLAGS += -DHAVE_RWAV
+endif
+
ifeq ($(HAVE_OVERLAY), 1)
CFLAGS += -DHAVE_OVERLAY
endif
@@ -1053,6 +1121,14 @@ ifeq ($(HAVE_LANGEXTRA), 1)
CFLAGS += -DHAVE_LANGEXTRA
endif
+ifeq ($(HAVE_DSP_FILTER), 1)
+ CFLAGS += -DHAVE_DSP_FILTER
+endif
+
+ifeq ($(HAVE_VIDEO_FILTER), 1)
+ CFLAGS += -DHAVE_VIDEO_FILTER
+endif
+
ifeq ($(HAVE_FILTERS_BUILTIN), 1)
CFLAGS += -DHAVE_FILTERS_BUILTIN
endif
@@ -1073,6 +1149,14 @@ ifeq ($(HAVE_CONFIGFILE), 1)
CFLAGS += -DHAVE_CONFIGFILE
endif
+ifeq ($(HAVE_PATCH), 1)
+ CFLAGS += -DHAVE_PATCH
+endif
+
+ifeq ($(HAVE_CHEATS), 1)
+ CFLAGS += -DHAVE_CHEATS
+endif
+
ifeq ($(HAVE_RSOUND), 1)
CFLAGS += -DHAVE_RSOUND
endif
diff --git a/Makefile.libnx b/Makefile.libnx
index 14da9d7456..7146809040 100644
--- a/Makefile.libnx
+++ b/Makefile.libnx
@@ -23,6 +23,8 @@ DEFINES := -D__SWITCH__=1 -U__linux__ -U__linux -DGLM_FORCE_PURE=1 -DRARCH_CONSO
HAVE_DR_MP3 = 1
HAVE_TRANSLATE = 1
+HAVE_SCREENSHOTS = 1
+HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
HAVE_CC_RESAMPLER = 1
HAVE_MENU_COMMON = 1
@@ -33,10 +35,14 @@ HAVE_RBMP = 1
HAVE_ZLIB = 1
HAVE_BUILTINZLIB = 1
HAVE_LIBRETRODB = 1
+HAVE_DSP_FILTER = 1
+HAVE_VIDEO_FILTER = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_MENU = 1
HAVE_CONFIGFILE = 1
+HAVE_PATCH = 1
+HAVE_CHEATS = 1
HAVE_RUNAHEAD = 1
HAVE_NETWORKING = 1
HAVE_NETPLAYDISCOVERY = 1
diff --git a/Makefile.msvc b/Makefile.msvc
index 5426f38aef..d847e77b23 100644
--- a/Makefile.msvc
+++ b/Makefile.msvc
@@ -11,6 +11,10 @@ WindowsSdkDir = C:\Program Files (x86)\Windows Kits\10\$(NOTHING)
WindowsSDKVersion := 10.0.14393.0\$(NOTHING)
VCINSTALLDIR := C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\$(NOTHING)
+HAVE_DSP_FILTER := 1
+HAVE_VIDEO_FILTER := 1
+HAVE_SCREENSHOTS := 1
+HAVE_REWIND := 1
HAVE_AUDIOMIXER := 1
HAVE_D3DX := 1
HAVE_D3D8 := 0
@@ -32,6 +36,7 @@ HAVE_WINMM := 1
HAVE_RPNG := 1
HAVE_ZLIB := 1
HAVE_CONFIGFILE := 1
+HAVE_PATCH := 1
HAVE_MENU := 1
HAVE_RGUI := 1
HAVE_XMB := 1
@@ -60,6 +65,8 @@ HAVE_LANGEXTRA := 1
HAVE_CHEEVOS := 1
HAVE_SHADERPIPELINE := 1
HAVE_IMAGEVIEWER := 1
+HAVE_BSV_MOVIE := 1
+HAVE_CHEATS := 1
ifeq ($(HAVE_D3D8), 1)
D3D8_LIBS := -ld3d8
@@ -192,7 +199,7 @@ else
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
endif
-DEFINES += -DRARCH_INTERNAL -DHAVE_DYNAMIC -DJSON_STATIC
+DEFINES += -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_DYNAMIC -DJSON_STATIC
INCLUDE_DIRS += -I. -Igfx/include
#OBJ := version_git.o
diff --git a/Makefile.openpandora b/Makefile.openpandora
index d33950adb8..0f5e4f79cc 100644
--- a/Makefile.openpandora
+++ b/Makefile.openpandora
@@ -15,7 +15,9 @@ LDFLAGS = -L$(PNDSDK)/usr/lib -Wl,-rpath,$(PNDSDK)/usr/lib
LIBS = -lGLESv2 -lEGL -ldl -lm -lpthread -lrt -lasound
DEFINES = -std=gnu99 -DHAVE_THREADS -DHAVE_GETOPT_LONG=1 -DHAVE_GRIFFIN -DRARCH_INTERNAL
-DEFINES += -DHAVE_CONFIGFILE -D__ARM_ARCH_6__ -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_GLSL -DHAVE_DYNAMIC -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_OVERLAY -DHAVE_VIDEO_LAYOUT -DHAVE_ALSA -DHAVE_ZLIB -D__linux__
+DEFINES += -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SCREENSHOTS -DHAVE_REWIND -D__ARM_ARCH_6__ -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_GLSL -DHAVE_DYNAMIC -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_OVERLAY -DHAVE_VIDEO_LAYOUT -DHAVE_ALSA -DHAVE_ZLIB -D__linux__
+DEFINES += -DHAVE_DSP_FILTER
+DEFINES += -DHAVE_VIDEO_FILTER
DEFINES += $(INCDIRS)
DEFINES += -D__OPENPANDORA__ -DPANDORA
DEFINES += -marm -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize
diff --git a/Makefile.orbis b/Makefile.orbis
index 2945fd14aa..55f5cca216 100644
--- a/Makefile.orbis
+++ b/Makefile.orbis
@@ -16,13 +16,16 @@ DEFINES :=
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1
- DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE
+ DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SCREENSHOTS -DHAVE_CHEATS
+ DEFINES += -DHAVE_REWIND
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
ifeq ($(DEBUG), 1)
DEFINES += -DHAVE_NETLOGGER
endif
else
+ HAVE_DSP_FILTER := 1
+ HAVE_VIDEO_FILTER := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 0
HAVE_RPNG := 1
@@ -42,6 +45,10 @@ else
HAVE_MENU := 1
HAVE_MENU_COMMON := 1
HAVE_CONFIGFILE := 1
+ HAVE_SCREENSHOTS := 1
+ HAVE_REWIND := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
HAVE_RGUI := 0
HAVE_MATERIALUI := 0
HAVE_XMB := 1
diff --git a/Makefile.ps2 b/Makefile.ps2
index 9ffe65da9f..73bfeb9b6c 100644
--- a/Makefile.ps2
+++ b/Makefile.ps2
@@ -6,12 +6,11 @@ HAVE_THREADS = 0
MUTE_WARNINGS = 1
PS2_IP = 192.168.1.150
-TARGET = retroarchps2.elf
-TARGET_RELEASE = retroarchps2-release.elf
+TARGET = retroarchps2-debug.elf
+TARGET_RELEASE = retroarchps2.elf
# Compile the IRXs first
IRX_DIR = ps2/irx
-IRX_FILES = $(wildcard ps2/irx/*.c)
ifeq ($(DEBUG), 1)
OPTIMIZE_LV := -O0 -g
@@ -31,12 +30,14 @@ INCDIR += -Ideps/pthreads -Ideps/pthreads/platform/ps2 -Ideps/pthreads/platform/
CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant
ASFLAGS = $(CFLAGS)
-RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI
+RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI
RARCH_DEFINES += -DHAVE_ZLIB -DHAVE_NO_BUILTINZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
+RARCH_DEFINES += -DHAVE_DSP_FILTER
+RARCH_DEFINES += -DHAVE_VIDEO_FILTER
LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L.
# Lib cdvd is needed to get proper time
-LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd
+LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd -lelf-loader
ifeq ($(BUILD_FOR_PCSX2), 1)
RARCH_DEFINES += -DBUILD_FOR_PCSX2
diff --git a/Makefile.ps2.salamander b/Makefile.ps2.salamander
new file mode 100644
index 0000000000..b25103d2ea
--- /dev/null
+++ b/Makefile.ps2.salamander
@@ -0,0 +1,103 @@
+BUILD_FOR_PCSX2 = 0
+DEBUG = 0
+HAVE_FILE_LOGGER = 0
+MUTE_WARNINGS = 1
+PS2_IP = 192.168.1.150
+
+TARGET = raboot-debug.elf
+TARGET_RELEASE = raboot.elf
+
+# Compile the IRXs first
+IRX_DIR = ps2/irx
+
+ifeq ($(DEBUG), 1)
+ OPTIMIZE_LV := -O0 -g
+ RARCH_DEFINES += -DDEBUG
+else
+ OPTIMIZE_LV := -O3
+ LDFLAGS := -s
+endif
+
+ifeq ($(MUTE_WARNINGS), 1)
+ DISABLE_WARNINGS := -Wno-sign-compare -Wno-unused -Wno-parentheses
+endif
+
+INCDIR = -Ilibretro-common/include
+INCDIR += -Ips2/include
+CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant
+ASFLAGS = $(CFLAGS)
+
+RARCH_DEFINES += -DPS2 -DIS_SALAMANDER -DRARCH_CONSOLE
+
+LIBDIR =
+LDFLAGS =
+LIBS = -lm -lelf-loader -lpatches -lpoweroff
+
+ifeq ($(BUILD_FOR_PCSX2), 1)
+RARCH_DEFINES += -DBUILD_FOR_PCSX2
+endif
+
+ifeq ($(HAVE_FILE_LOGGER), 1)
+CFLAGS += -DHAVE_FILE_LOGGER
+endif
+
+CFLAGS += $(RARCH_DEFINES)
+
+EE_OBJS = frontend/frontend_salamander.o \
+ frontend/frontend_driver.o \
+ frontend/drivers/platform_ps2.o \
+ libretro-common/file/file_path.o \
+ libretro-common/file/file_path_io.o \
+ libretro-common/string/stdstring.o \
+ libretro-common/lists/string_list.o \
+ libretro-common/lists/dir_list.o \
+ libretro-common/file/retro_dirent.o \
+ libretro-common/encodings/encoding_utf.o \
+ libretro-common/compat/fopen_utf8.o \
+ libretro-common/compat/compat_strl.o \
+ libretro-common/compat/compat_strcasestr.o \
+ libretro-common/file/config_file.o \
+ libretro-common/streams/file_stream.o \
+ libretro-common/vfs/vfs_implementation.o \
+ libretro-common/hash/rhash.o \
+ libretro-common/time/rtime.o \
+ file_path_str.o \
+ verbosity.o \
+ ps2/compat_files/ps2_devices.o
+
+# Needed IRX objects
+EE_OBJS += $(IRX_DIR)/freesio2_irx.o $(IRX_DIR)/iomanX_irx.o $(IRX_DIR)/cdfs_irx.o
+EE_OBJS += $(IRX_DIR)/fileXio_irx.o $(IRX_DIR)/mcman_irx.o $(IRX_DIR)/mcserv_irx.o $(IRX_DIR)/usbd_irx.o
+EE_OBJS += $(IRX_DIR)/usbhdfsd_irx.o $(IRX_DIR)/freesd_irx.o $(IRX_DIR)/poweroff_irx.o
+
+EE_CFLAGS = $(CFLAGS)
+EE_CXXFLAGS = $(CFLAGS)
+EE_LDFLAGS = $(LDFLAGS)
+EE_LIBS = $(LIBS)
+EE_ASFLAGS = $(ASFLAGS)
+EE_INCS = $(INCDIR)
+EE_BIN = $(TARGET)
+EE_GPVAL = $(GPVAL)
+
+all: irxdir $(EE_BIN)
+
+irxdir:
+ $(MAKE) -C $(IRX_DIR)
+
+clean:
+ rm -f $(EE_BIN) $(EE_OBJS)
+ $(MAKE) -C $(IRX_DIR) clean
+
+debug: clean all run
+
+run:
+ ps2client -h $(PS2_IP) execee host:$(EE_BIN)
+
+package:
+ ps2-packer $(EE_BIN) $(TARGET_RELEASE)
+
+release: clean all package
+
+#Include preferences
+include $(PS2SDK)/samples/Makefile.pref
+include $(PS2SDK)/samples/Makefile.eeglobal_cpp
diff --git a/Makefile.ps3 b/Makefile.ps3
index 4ca9937ff9..2412aa97ec 100644
--- a/Makefile.ps3
+++ b/Makefile.ps3
@@ -70,7 +70,7 @@ endif
PPU_SRCS = griffin/griffin.c
DEFINES += -DHAVE_VIDEO_LAYOUT
-DEFINES += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_GFX_WIDGETS -DHAVE_RGUI -DHAVE_XMB -DHAVE_OZONE -DHAVE_LIBRETRODB -DHAVE_MATERIALUI -DHAVE_SHADERPIPELINE -DRARCH_INTERNAL -DHAVE_OVERLAY -DHAVE_CC_RESAMPLER -DHAVE_STB_VORBIS -DHAVE_STB_FONT -DHAVE_RUNAHEAD -DHAVE_DR_MP3 -DHAVE_DR_FLAC
+DEFINES += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_GFX_WIDGETS -DHAVE_RGUI -DHAVE_XMB -DHAVE_OZONE -DHAVE_LIBRETRODB -DHAVE_MATERIALUI -DHAVE_SHADERPIPELINE -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_OVERLAY -DHAVE_CC_RESAMPLER -DHAVE_STB_VORBIS -DHAVE_STB_FONT -DHAVE_RUNAHEAD -DHAVE_DR_MP3 -DHAVE_DR_FLAC
DEFINES += -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORES
ifeq ($(DEX_BUILD), 1)
@@ -117,7 +117,7 @@ PPU_LDLIBS = $(FONT_LIBS) $(GL_LIBS) $(WHOLE_START) -lretro_ps3 $(WHOLE_END) -l
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
-DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_HEADSET -DHAVE_LANGEXTRA -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_7Z -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_FILTERS_BUILTIN -DHAVE_CHEEVOS -DRC_DISABLE_LUA
+DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_HEADSET -DHAVE_LANGEXTRA -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_7Z -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_FILTERS_BUILTIN -DHAVE_CHEEVOS -DRC_DISABLE_LUA -DHAVE_DSP_FILTER -DHAVE_VIDEO_FILTER
#DEFINES += -DHAVE_IMAGEVIEWER
diff --git a/Makefile.ps3.cobra b/Makefile.ps3.cobra
index 52e99e742b..3ba5423e5b 100644
--- a/Makefile.ps3.cobra
+++ b/Makefile.ps3.cobra
@@ -108,7 +108,7 @@ PPU_LDLIBS = $(FONT_LIBS) $(GL_LIBS) $(WHOLE_START) -lretro_ps3 $(WHOLE_END) -l
PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe
#DEFINES += -DHAVE_VIDEO_LAYOUT
-DEFINES += -DHAVE_THREADS -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=0 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_STB_VORBIS
+DEFINES += -DHAVE_THREADS -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_PATCH -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RSOUND -DHAVE_ZLIB -DHAVE_RPNG -D__CELLOS_LV2__ -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=0 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -DHAVE_STB_VORBIS
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g
diff --git a/Makefile.psl1ght b/Makefile.psl1ght
index 9ac19921bc..1fae26721f 100644
--- a/Makefile.psl1ght
+++ b/Makefile.psl1ght
@@ -66,7 +66,7 @@ endif
SHARED_FLAGS :=
SHARED_FLAGS += -DHAVE_VIDEO_LAYOUT
-SHARED_FLAGS += -DHAVE_MENU -DHAVE_CONFIGFILE -DRARCH_CONSOLE -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_GCMGL -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_MOUSE -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_GRIFFIN=1 -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -Wno-char-subscripts -DHAVE_CC_RESAMPLER -DRARCH_INTERNAL -DHAVE_MULTIMAN -DHAVE_RGUI
+SHARED_FLAGS += -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DRARCH_CONSOLE -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_GCMGL -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_MOUSE -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_GRIFFIN=1 -DHAVE_NETWORKING=1 -DHAVE_SOCKET_LEGACY=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -Wno-char-subscripts -DHAVE_CC_RESAMPLER -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DHAVE_MULTIMAN -DHAVE_RGUI
CFLAGS += -std=gnu99 $(SHARED_FLAGS)
CXXFLAGS += $(SHARED_FLAGS)
diff --git a/Makefile.psp1 b/Makefile.psp1
index d59acb3521..1562480544 100644
--- a/Makefile.psp1
+++ b/Makefile.psp1
@@ -25,7 +25,7 @@ INCDIR = deps deps/stb deps/7zip deps/pthreads deps/pthreads/platform/psp deps/p
CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math -fsingle-precision-constant
ASFLAGS = $(CFLAGS)
-RARCH_DEFINES = -DPSP -D_MIPS_ARCH_ALLEGREX -DHAVE_LANGEXTRA -DHAVE_ZLIB -DHAVE_AUDIOMIXER -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
+RARCH_DEFINES = -DPSP -D_MIPS_ARCH_ALLEGREX -DHAVE_LANGEXTRA -DHAVE_ZLIB -DHAVE_AUDIOMIXER -DHAVE_RWAV -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_DSP_FILTER -DHAVE_VIDEO_FILTER -DHAVE_7ZIP -DHAVE_CC_RESAMPLER
LIBDIR =
LDFLAGS =
diff --git a/Makefile.switch b/Makefile.switch
index f876a1de84..e5b32bd3c3 100644
--- a/Makefile.switch
+++ b/Makefile.switch
@@ -6,16 +6,18 @@ WHOLE_ARCHIVE_LINK = 0
OBJ :=
-DEFINES := -DSWITCH=1 -U__linux__ -U__linux -DRARCH_INTERNAL -DHAVE_DYNAMIC
+DEFINES := -DSWITCH=1 -U__linux__ -U__linux -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_DYNAMIC -DHAVE_REWIND
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_NEON -DHAVE_MATERIALUI -DHAVE_LIBRETRODB -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA
DEFINES += -DHAVE_RUNAHEAD -DHAVE_DYNAMIC
- DEFINES += -DHAVE_CONFIGFILE
+ DEFINES += -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS
else
+ HAVE_REWIND = 1
HAVE_AUDIOMIXER = 1
+ HAVE_RWAV = 1
HAVE_CC_RESAMPLER = 1
HAVE_MENU_COMMON = 1
HAVE_RTGA = 1
@@ -24,6 +26,8 @@ else
HAVE_RBMP = 1
HAVE_RGUI = 1
HAVE_ZLIB = 1
+ HAVE_DSP_FILTER = 1
+ HAVE_VIDEO_FILTER = 1
HAVE_BUILTINZLIB = 1
HAVE_LIBRETRODB = 1
HAVE_MATERIALUI = 0 # enable later?
@@ -34,6 +38,8 @@ else
HAVE_CONFIGFILE = 1
HAVE_RUNAHEAD = 1
HAVE_DYNAMIC = 1
+ HAVE_PATCH = 1
+ HAVE_CHEATS = 1
include Makefile.common
CFLAGS += $(DEF_FLAGS)
diff --git a/Makefile.vita b/Makefile.vita
index fbb85cd20c..d4aa224d52 100644
--- a/Makefile.vita
+++ b/Makefile.vita
@@ -18,18 +18,22 @@ INCDIRS :=
ifeq ($(GRIFFIN_BUILD), 1)
OBJ += griffin/griffin.o
DEFINES += -DHAVE_GRIFFIN=1
- DEFINES += -DHAVE_NEON -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB DEFINES -DHAVE_KEYMAPPER
+ DEFINES += -DHAVE_REWIND
+ DEFINES += -DHAVE_NEON -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_XMB -DHAVE_MATERIALUI -DHAVE_LIBRETRODB DEFINES -DHAVE_KEYMAPPER
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
ifeq ($(DEBUG), 1)
DEFINES += -DHAVE_NETLOGGER
endif
INCDIRS += -I. -Ideps/7zip -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -Ideps/stb
else
-
+ HAVE_REWIND := 1
HAVE_UPDATE_ASSETS := 1
HAVE_ONLINE_UPDATER := 1
HAVE_NEON := 1
HAVE_MATH_NEON := 1
+ HAVE_DSP_FILTER := 1
+ HAVE_VIDEO_FILTER := 1
+ HAVE_SCREENSHOTS := 1
HAVE_FILTERS_BUILTIN := 1
HAVE_LANGEXTRA := 1
HAVE_RPNG := 1
@@ -46,6 +50,8 @@ else
HAVE_MENU_COMMON := 1
HAVE_GFX_WIDGETS := 1
HAVE_CONFIGFILE := 1
+ HAVE_PATCH := 1
+ HAVE_CHEATS := 1
HAVE_OVERLAY := 1
HAVE_VIDEO_LAYOUT := 0
HAVE_MATERIALUI := 1
@@ -61,6 +67,7 @@ else
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
HAVE_AUDIOMIXER := 1
+ HAVE_RWAV := 1
ifeq ($(DEBUG), 1)
HAVE_NETLOGGER = 1
@@ -103,7 +110,9 @@ ASFLAGS := $(CFLAGS)
LDFLAGS := -Wl,-q
CFLAGS += -Wall -ffast-math -g
-CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE
+CFLAGS += -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DRARCH_CONSOLE
+CFLAGS += -DHAVE_DSP_FILTER
+CFLAGS += -DHAVE_VIDEO_FILTER
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)
ifneq ($(PC_DEVELOPMENT_IP_ADDRESS),)
@@ -123,7 +132,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
VITA_LIBS := -lSceDisplay_stub -lSceGxm_stub -lSceNet_stub -lSceNetCtl_stub -lSceAppUtil_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub -lSceAudio_stub \
-lScePower_stub -lSceRtc_stub -lSceCommonDialog_stub -lScePgf_stub -lSceMotion_stub \
- -lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz
+ -lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz -lSceShaccCg_stub
LIBS := $(WHOLE_START) -lretro_vita $(WHOLE_END) $(VITA_LIBS) -lm -lc
@@ -156,7 +165,13 @@ all: $(TARGETS)
%.depend: ;
-$(TARGET).elf: $(OBJ) libretro_vita.a
+libSceShaccCg_stub.a:
+ mkdir -p deps/vitaShaRK/SceShaccCg
+ vita-libs-gen deps/vitaShaRK/SceShaccCg.yml deps/vitaShaRK/SceShaccCg
+ make -C deps/vitaShaRK/SceShaccCg ARCH=arm-vita-eabi
+ cp deps/vitaShaRK/SceShaccCg/libSceShaccCg_stub.a .
+
+$(TARGET).elf: $(OBJ) libretro_vita.a libSceShaccCg_stub.a
$(LD) $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@
%.velf: %.elf
@@ -172,7 +187,8 @@ $(TARGET).elf: $(OBJ) libretro_vita.a
vita-pack-vpk -s param.sfo -b $< $@
clean:
- rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk
+ rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk libSceShaccCg_stub.a
+ rm -rf deps/vitaShaRK/SceShaccCg
rm -f $(OBJ:.o=.depend)
# Useful for developers
diff --git a/Makefile.wiiu b/Makefile.wiiu
index 9e39411c0a..4691d9cf72 100644
--- a/Makefile.wiiu
+++ b/Makefile.wiiu
@@ -74,6 +74,7 @@ ifeq ($(SALAMANDER_BUILD),1)
# $(SALAMANDER_BUILD),0
else
DEFINES += -DRARCH_INTERNAL
+ DEFINES += -DHAVE_SCREENSHOTS
DEFINES += -DHAVE_KEYMAPPER
DEFINES += -DHAVE_ONLINE_UPDATER
DEFINES += -DHAVE_UPDATE_ASSETS
@@ -108,7 +109,9 @@ endif
INCDIRS += -Ideps/SPIRV-Cross
DEFINES += -DHAVE_AUDIOMIXER
- DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_RGUI -DHAVE_LIBRETRODB
+ DEFINES += -DHAVE_RWAV
+ DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_GFX_WIDGETS -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI -DHAVE_LIBRETRODB
+ DEFINES += -DHAVE_REWIND
DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER
DEFINES += -DHAVE_SPIRV_CROSS -DHAVE_SLANG
DEFINES += -DHAVE_STB_FONT -DHAVE_STB_VORBIS -DHAVE_LANGEXTRA -DHAVE_LIBRETRODB -DHAVE_NETWORKING -DHAVE_NETPLAYDISCOVERY
@@ -121,7 +124,9 @@ endif
# $(GRIFFIN_BUILD),0
else
+ HAVE_SCREENSHOTS = 1
HAVE_AUDIOMIXER = 1
+ HAVE_RWAV = 1
HAVE_MENU_COMMON = 1
HAVE_GFX_WIDGETS = 1
HAVE_RTGA = 1
@@ -129,6 +134,9 @@ endif
HAVE_RJPEG = 1
HAVE_RBMP = 1
HAVE_CONFIGFILE = 1
+ HAVE_PATCH = 1
+ HAVE_REWIND = 1
+ HAVE_CHEATS = 1
HAVE_MENU = 1
HAVE_RGUI = 1
HAVE_7ZIP = 1
@@ -149,6 +157,8 @@ endif
HAVE_SPIRV_CROSS = 1
HAVE_SLANG = 1
HAVE_VIDEO_LAYOUT = 0
+ HAVE_DSP_FILTER = 1
+ HAVE_VIDEO_FILTER = 1
HAVE_STATIC_VIDEO_FILTERS = 1
HAVE_STATIC_AUDIO_FILTERS = 1
WANT_LIBFAT = 1
diff --git a/Makefile.win b/Makefile.win
index b86dda3a92..21117a56c4 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -1,6 +1,8 @@
TARGET = retroarch.exe
+HAVE_SCREENSHOTS = 1
HAVE_AUDIOMIXER = 1
+HAVE_RWAV = 1
HAVE_DINPUT = 1
HAVE_XAUDIO = 1
HAVE_DSOUND = 1
@@ -15,8 +17,13 @@ HAVE_COMMAND = 1
HAVE_THREADS = 1
HAVE_MENU = 1
HAVE_CONFIGFILE = 1
+HAVE_PATCH = 1
+HAVE_REWIND = 1
+HAVE_CHEATS = 1
HAVE_RGUI = 1
HAVE_MATERIALUI = 1
+HAVE_DSP_FILTER = 1
+HAVE_VIDEO_FILTER = 1
HAVE_7ZIP = 1
HAVE_PYTHON = 0
DYNAMIC = 1
@@ -96,7 +103,7 @@ OS := Win32
OBJ :=
LIBS := -lm
DEFINES :=
-DEFINES += -I. -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -DRARCH_INTERNAL -DHAVE_OVERLAY
+DEFINES += -I. -Ilibretro-common/include -Ilibretro-common/include/compat/zlib -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_OVERLAY
#DEFINES += -DHAVE_VIDEO_LAYOUT
LDFLAGS := -L. -static-libgcc
@@ -162,7 +169,7 @@ $(OBJDIR)/%.o: %.c
.FORCE:
-$(OBJDIR)/git_version.o: git_version.c .FORCE
+$(OBJDIR)/version_git.o: version_git.c .FORCE
@-mkdir -p $(dir $@) || mkdir $(subst /,\,$(dir $@)) || echo .
@$(if $(Q), $(shell echo echo CC $<),)
$(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -c -o $@ $<
diff --git a/audio/audio_defines.h b/audio/audio_defines.h
index 14693aa296..c9c1264f4d 100644
--- a/audio/audio_defines.h
+++ b/audio/audio_defines.h
@@ -30,7 +30,7 @@ RETRO_BEGIN_DECLS
#define AUDIO_MIXER_MAX_STREAMS 16
-#define AUDIO_MIXER_MAX_SYSTEM_STREAMS (AUDIO_MIXER_MAX_STREAMS + 4)
+#define AUDIO_MIXER_MAX_SYSTEM_STREAMS (AUDIO_MIXER_MAX_STREAMS + 5)
/* do not define more than (MAX_SYSTEM_STREAMS - MAX_STREAMS) */
enum audio_mixer_system_slot
@@ -38,7 +38,8 @@ enum audio_mixer_system_slot
AUDIO_MIXER_SYSTEM_SLOT_OK = AUDIO_MIXER_MAX_STREAMS,
AUDIO_MIXER_SYSTEM_SLOT_CANCEL,
AUDIO_MIXER_SYSTEM_SLOT_NOTICE,
- AUDIO_MIXER_SYSTEM_SLOT_BGM
+ AUDIO_MIXER_SYSTEM_SLOT_BGM,
+ AUDIO_MIXER_SYSTEM_SLOT_ACHIEVEMENT_UNLOCK
};
enum audio_action
diff --git a/audio/drivers/alsathread.c b/audio/drivers/alsathread.c
index c58dcc0515..339803fd49 100644
--- a/audio/drivers/alsathread.c
+++ b/audio/drivers/alsathread.c
@@ -66,7 +66,7 @@ static void alsa_worker_thread(void *data)
size_t fifo_size;
snd_pcm_sframes_t frames;
slock_lock(alsa->fifo_lock);
- avail = fifo_read_avail(alsa->buffer);
+ avail = FIFO_READ_AVAIL(alsa->buffer);
fifo_size = MIN(alsa->period_size, avail);
fifo_read(alsa->buffer, buf, fifo_size);
scond_signal(alsa->cond);
@@ -256,7 +256,7 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
size_t write_amt;
slock_lock(alsa->fifo_lock);
- avail = fifo_write_avail(alsa->buffer);
+ avail = FIFO_WRITE_AVAIL(alsa->buffer);
write_amt = MIN(avail, size);
fifo_write(alsa->buffer, buf, write_amt);
@@ -271,7 +271,7 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
{
size_t avail;
slock_lock(alsa->fifo_lock);
- avail = fifo_write_avail(alsa->buffer);
+ avail = FIFO_WRITE_AVAIL(alsa->buffer);
if (avail == 0)
{
@@ -334,7 +334,7 @@ static size_t alsa_thread_write_avail(void *data)
if (alsa->thread_dead)
return 0;
slock_lock(alsa->fifo_lock);
- val = fifo_write_avail(alsa->buffer);
+ val = FIFO_WRITE_AVAIL(alsa->buffer);
slock_unlock(alsa->fifo_lock);
return val;
}
diff --git a/audio/drivers/coreaudio.c b/audio/drivers/coreaudio.c
index 32cf09abda..6354fcb6df 100644
--- a/audio/drivers/coreaudio.c
+++ b/audio/drivers/coreaudio.c
@@ -103,7 +103,7 @@ static OSStatus audio_write_cb(void *userdata,
slock_lock(dev->lock);
- if (fifo_read_avail(dev->buffer) < write_avail)
+ if (FIFO_READ_AVAIL(dev->buffer) < write_avail)
{
*action_flags = kAudioUnitRenderAction_OutputIsSilence;
@@ -356,14 +356,14 @@ static ssize_t coreaudio_write(void *data, const void *buf_, size_t size)
slock_lock(dev->lock);
- write_avail = fifo_write_avail(dev->buffer);
+ write_avail = FIFO_WRITE_AVAIL(dev->buffer);
if (write_avail > size)
write_avail = size;
fifo_write(dev->buffer, buf, write_avail);
- buf += write_avail;
+ buf += write_avail;
written += write_avail;
- size -= write_avail;
+ size -= write_avail;
if (dev->nonblock)
{
@@ -430,7 +430,7 @@ static size_t coreaudio_write_avail(void *data)
coreaudio_t *dev = (coreaudio_t*)data;
slock_lock(dev->lock);
- avail = fifo_write_avail(dev->buffer);
+ avail = FIFO_WRITE_AVAIL(dev->buffer);
slock_unlock(dev->lock);
return avail;
diff --git a/audio/drivers/dsound.c b/audio/drivers/dsound.c
index 00176873f7..9bca87a9d2 100644
--- a/audio/drivers/dsound.c
+++ b/audio/drivers/dsound.c
@@ -155,7 +155,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
avail = write_avail(read_ptr, write_ptr, ds->buffer_size);
EnterCriticalSection(&ds->crit);
- fifo_avail = fifo_read_avail(ds->buffer);
+ fifo_avail = FIFO_READ_AVAIL(ds->buffer);
LeaveCriticalSection(&ds->crit);
if (avail < CHUNK_SIZE || ((fifo_avail < CHUNK_SIZE) && (avail < ds->buffer_size / 2)))
@@ -511,7 +511,7 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size)
size_t avail;
EnterCriticalSection(&ds->crit);
- avail = fifo_write_avail(ds->buffer);
+ avail = FIFO_WRITE_AVAIL(ds->buffer);
if (avail > size)
avail = size;
@@ -530,7 +530,7 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size)
size_t avail;
EnterCriticalSection(&ds->crit);
- avail = fifo_write_avail(ds->buffer);
+ avail = FIFO_WRITE_AVAIL(ds->buffer);
if (avail > size)
avail = size;
@@ -558,7 +558,7 @@ static size_t dsound_write_avail(void *data)
dsound_t *ds = (dsound_t*)data;
EnterCriticalSection(&ds->crit);
- avail = fifo_write_avail(ds->buffer);
+ avail = FIFO_WRITE_AVAIL(ds->buffer);
LeaveCriticalSection(&ds->crit);
return avail;
}
diff --git a/audio/drivers/gx_audio.c b/audio/drivers/gx_audio.c
index f4f2be0ca8..29679fd986 100644
--- a/audio/drivers/gx_audio.c
+++ b/audio/drivers/gx_audio.c
@@ -109,7 +109,7 @@ static INLINE void copy_swapped(uint32_t * restrict dst,
{
uint32_t s = *src++;
*dst++ = (s >> 16) | (s << 16);
- }while(--size);
+ } while (--size);
}
static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)
diff --git a/audio/drivers/opensl.c b/audio/drivers/opensl.c
index fac2335fc7..4d02b15d14 100644
--- a/audio/drivers/opensl.c
+++ b/audio/drivers/opensl.c
@@ -67,7 +67,7 @@ static void opensl_callback(SLAndroidSimpleBufferQueueItf bq, void *ctx)
#define GOTO_IF_FAIL(x) do { \
if ((res = (x)) != SL_RESULT_SUCCESS) \
goto error; \
-} while(0)
+} while (0)
static void sl_free(void *data)
{
diff --git a/audio/drivers/ps3_audio.c b/audio/drivers/ps3_audio.c
index 958374a8fd..d8ffa73805 100644
--- a/audio/drivers/ps3_audio.c
+++ b/audio/drivers/ps3_audio.c
@@ -61,7 +61,7 @@ static void event_loop(uint64_t data)
sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT);
sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT);
- if (fifo_read_avail(aud->buffer) >= sizeof(out_tmp))
+ if (FIFO_READ_AVAIL(aud->buffer) >= sizeof(out_tmp))
fifo_read(aud->buffer, out_tmp, sizeof(out_tmp));
else
memset(out_tmp, 0, sizeof(out_tmp));
@@ -152,11 +152,11 @@ static ssize_t ps3_audio_write(void *data, const void *buf, size_t size)
if (aud->nonblock)
{
- if (fifo_write_avail(aud->buffer) < size)
+ if (FIFO_WRITE_AVAIL(aud->buffer) < size)
return 0;
}
- while (fifo_write_avail(aud->buffer) < size)
+ while (FIFO_WRITE_AVAIL(aud->buffer) < size)
sys_lwcond_wait(&aud->cond, 0);
sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT);
diff --git a/audio/drivers/rsound.c b/audio/drivers/rsound.c
index c017ae44e9..b5d10ebf99 100644
--- a/audio/drivers/rsound.c
+++ b/audio/drivers/rsound.c
@@ -39,9 +39,8 @@ typedef struct rsd
static ssize_t rsound_audio_cb(void *data, size_t bytes, void *userdata)
{
- rsd_t *rsd = (rsd_t*)userdata;
-
- size_t avail = fifo_read_avail(rsd->buffer);
+ rsd_t *rsd = (rsd_t*)userdata;
+ size_t avail = FIFO_READ_AVAIL(rsd->buffer);
size_t write_size = bytes > avail ? avail : bytes;
fifo_read(rsd->buffer, data, write_size);
scond_signal(rsd->cond);
@@ -115,7 +114,7 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
rsd_callback_lock(rsd->rd);
- avail = fifo_write_avail(rsd->buffer);
+ avail = FIFO_WRITE_AVAIL(rsd->buffer);
write_amt = avail > size ? size : avail;
fifo_write(rsd->buffer, buf, write_amt);
@@ -130,7 +129,7 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
size_t avail;
rsd_callback_lock(rsd->rd);
- avail = fifo_write_avail(rsd->buffer);
+ avail = FIFO_WRITE_AVAIL(rsd->buffer);
if (avail == 0)
{
@@ -209,7 +208,7 @@ static size_t rs_write_avail(void *data)
if (rsd->has_error)
return 0;
rsd_callback_lock(rsd->rd);
- val = fifo_write_avail(rsd->buffer);
+ val = FIFO_WRITE_AVAIL(rsd->buffer);
rsd_callback_unlock(rsd->rd);
return val;
}
diff --git a/audio/drivers/sdl_audio.c b/audio/drivers/sdl_audio.c
index 5726bd7371..5f03253eac 100644
--- a/audio/drivers/sdl_audio.c
+++ b/audio/drivers/sdl_audio.c
@@ -46,7 +46,7 @@ typedef struct sdl_audio
static void sdl_audio_cb(void *data, Uint8 *stream, int len)
{
sdl_audio_t *sdl = (sdl_audio_t*)data;
- size_t avail = fifo_read_avail(sdl->buffer);
+ size_t avail = FIFO_READ_AVAIL(sdl->buffer);
size_t write_size = len > (int)avail ? avail : len;
fifo_read(sdl->buffer, stream, write_size);
@@ -151,7 +151,7 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
size_t avail, write_amt;
SDL_LockAudio();
- avail = fifo_write_avail(sdl->buffer);
+ avail = FIFO_WRITE_AVAIL(sdl->buffer);
write_amt = avail > size ? size : avail;
fifo_write(sdl->buffer, buf, write_amt);
SDL_UnlockAudio();
@@ -166,7 +166,7 @@ static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
size_t avail;
SDL_LockAudio();
- avail = fifo_write_avail(sdl->buffer);
+ avail = FIFO_WRITE_AVAIL(sdl->buffer);
if (avail == 0)
{
diff --git a/audio/drivers/switch_libnx_audren_audio.c b/audio/drivers/switch_libnx_audren_audio.c
index 0820e68001..144c6b6b4b 100644
--- a/audio/drivers/switch_libnx_audren_audio.c
+++ b/audio/drivers/switch_libnx_audren_audio.c
@@ -241,7 +241,7 @@ static ssize_t libnx_audren_audio_write(void *data,
if (aud->nonblock)
{
- while(written < size)
+ while (written < size)
{
written += libnx_audren_audio_append(
aud, buf + written, size - written);
@@ -251,7 +251,7 @@ static ssize_t libnx_audren_audio_write(void *data,
}
else
{
- while(written < size)
+ while (written < size)
{
written += libnx_audren_audio_append(
aud, buf + written, size - written);
diff --git a/audio/drivers/switch_libnx_audren_thread_audio.c b/audio/drivers/switch_libnx_audren_thread_audio.c
index c44f18aab4..d6ae246962 100644
--- a/audio/drivers/switch_libnx_audren_thread_audio.c
+++ b/audio/drivers/switch_libnx_audren_thread_audio.c
@@ -96,7 +96,7 @@ static void thread_job(void* data)
if (current_wavebuf)
{
mutexLock(&aud->fifo_lock);
- available = aud->paused ? 0 : fifo_read_avail(aud->fifo);
+ available = aud->paused ? 0 : FIFO_READ_AVAIL(aud->fifo);
written_tmp = MIN(available, aud->buffer_size - current_size);
dstbuf = current_pool_ptr + current_size;
if (written_tmp > 0)
@@ -295,7 +295,7 @@ static ssize_t libnx_audren_thread_audio_write(void *data,
if (aud->nonblock)
{
mutexLock(&aud->fifo_lock);
- available = fifo_write_avail(aud->fifo);
+ available = FIFO_WRITE_AVAIL(aud->fifo);
written = MIN(available, size);
if (written > 0)
fifo_write(aud->fifo, buf, written);
@@ -307,7 +307,7 @@ static ssize_t libnx_audren_thread_audio_write(void *data,
while (written < size && aud->running)
{
mutexLock(&aud->fifo_lock);
- available = fifo_write_avail(aud->fifo);
+ available = FIFO_WRITE_AVAIL(aud->fifo);
if (available)
{
written_tmp = MIN(size - written, available);
@@ -407,7 +407,7 @@ static size_t libnx_audren_thread_audio_write_avail(void *data)
return 0;
mutexLock(&aud->fifo_lock);
- available = fifo_write_avail(aud->fifo);
+ available = FIFO_WRITE_AVAIL(aud->fifo);
mutexUnlock(&aud->fifo_lock);
return available;
diff --git a/audio/drivers/switch_thread_audio.c b/audio/drivers/switch_thread_audio.c
index 5ccc455921..d206683e0f 100644
--- a/audio/drivers/switch_thread_audio.c
+++ b/audio/drivers/switch_thread_audio.c
@@ -107,7 +107,7 @@ static void mainLoop(void* data)
compat_mutex_lock(&swa->fifoLock);
- avail = fifo_read_avail(swa->fifo);
+ avail = FIFO_READ_AVAIL(swa->fifo);
to_write = MIN(avail, buf_avail);
if (to_write > 0)
{
@@ -349,7 +349,7 @@ static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t siz
if (swa->nonblock)
{
compat_mutex_lock(&swa->fifoLock);
- avail = fifo_write_avail(swa->fifo);
+ avail = FIFO_WRITE_AVAIL(swa->fifo);
written = MIN(avail, size);
if (written > 0)
fifo_write(swa->fifo, buf, written);
@@ -361,7 +361,7 @@ static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t siz
while (written < size && swa->running)
{
compat_mutex_lock(&swa->fifoLock);
- avail = fifo_write_avail(swa->fifo);
+ avail = FIFO_WRITE_AVAIL(swa->fifo);
if (avail == 0)
{
compat_mutex_unlock(&swa->fifoLock);
@@ -413,7 +413,7 @@ static size_t switch_thread_audio_write_avail(void *data)
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
compat_mutex_lock(&swa->fifoLock);
- val = fifo_write_avail(swa->fifo);
+ val = FIFO_WRITE_AVAIL(swa->fifo);
compat_mutex_unlock(&swa->fifoLock);
return val;
diff --git a/audio/drivers/wasapi.c b/audio/drivers/wasapi.c
index 63ffe8a925..2a5fb52ccb 100644
--- a/audio/drivers/wasapi.c
+++ b/audio/drivers/wasapi.c
@@ -632,7 +632,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
{
ssize_t written = -1;
UINT32 padding = 0;
- size_t write_avail = fifo_write_avail(w->buffer);
+ size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
@@ -643,7 +643,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return -1;
- read_avail = fifo_read_avail(w->buffer);
+ read_avail = FIFO_READ_AVAIL(w->buffer);
write_avail = w->engine_buffer_size - padding * w->frame_size;
written = read_avail < write_avail ? read_avail : write_avail;
if (written)
@@ -651,7 +651,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
return -1;
}
- write_avail = fifo_write_avail(w->buffer);
+ write_avail = FIFO_WRITE_AVAIL(w->buffer);
written = size < write_avail ? size : write_avail;
if (written)
fifo_write(w->buffer, data, written);
@@ -685,20 +685,20 @@ static ssize_t wasapi_write_sh(wasapi_t *w, const void * data, size_t size)
static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t size)
{
- size_t write_avail = 0;
- ssize_t written = -1;
- UINT32 padding = 0;
+ size_t write_avail = 0;
+ ssize_t written = -1;
+ UINT32 padding = 0;
if (w->buffer)
{
- write_avail = fifo_write_avail(w->buffer);
+ write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
size_t read_avail = 0;
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return -1;
- read_avail = fifo_read_avail(w->buffer);
+ read_avail = FIFO_READ_AVAIL(w->buffer);
write_avail = w->engine_buffer_size - padding * w->frame_size;
written = read_avail < write_avail ? read_avail : write_avail;
if (written)
@@ -706,7 +706,7 @@ static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t s
return -1;
}
- write_avail = fifo_write_avail(w->buffer);
+ write_avail = FIFO_WRITE_AVAIL(w->buffer);
written = size < write_avail ? size : write_avail;
if (written)
fifo_write(w->buffer, data, written);
@@ -731,7 +731,7 @@ static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t s
static ssize_t wasapi_write_ex(wasapi_t *w, const void * data, size_t size, DWORD ms)
{
ssize_t written = 0;
- size_t write_avail = fifo_write_avail(w->buffer);
+ size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
if (!write_avail)
{
@@ -890,7 +890,7 @@ static size_t wasapi_write_avail(void *wh)
UINT32 padding = 0;
if (w->buffer)
- return fifo_write_avail(w->buffer);
+ return FIFO_WRITE_AVAIL(w->buffer);
if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return 0;
diff --git a/audio/drivers/wiiu_audio.c b/audio/drivers/wiiu_audio.c
index 6d4339f2f8..62a868ae32 100644
--- a/audio/drivers/wiiu_audio.c
+++ b/audio/drivers/wiiu_audio.c
@@ -219,7 +219,7 @@ static ssize_t ax_audio_write(void* data, const void* buf, size_t size)
else if (count_avail < count)
{
/* Sync, wait for free memory */
- while(AXIsMultiVoiceRunning(ax->mvoice) && (count_avail < count))
+ while (AXIsMultiVoiceRunning(ax->mvoice) && (count_avail < count))
{
OSYieldThread(); /* Gives threads with same priority time to run */
count_avail = (ax->written > AX_AUDIO_MAX_FREE ? 0 : (AX_AUDIO_MAX_FREE - ax->written));
diff --git a/audio/librsound.c b/audio/librsound.c
index 1f813e6651..fb23914180 100644
--- a/audio/librsound.c
+++ b/audio/librsound.c
@@ -765,13 +765,13 @@ static void rsnd_drain(rsound_t *rd)
delta /= 1000000;
/* Calculates the amount of data we have in our virtual buffer. Only used to calculate delay. */
slock_lock(rd->thread.mutex);
- rd->bytes_in_buffer = (int)((int64_t)rd->total_written + (int64_t)fifo_read_avail(rd->fifo_buffer) - delta);
+ rd->bytes_in_buffer = (int)((int64_t)rd->total_written + (int64_t)FIFO_READ_AVAIL(rd->fifo_buffer) - delta);
slock_unlock(rd->thread.mutex);
}
else
{
slock_lock(rd->thread.mutex);
- rd->bytes_in_buffer = fifo_read_avail(rd->fifo_buffer);
+ rd->bytes_in_buffer = FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
}
}
@@ -789,7 +789,7 @@ static size_t rsnd_fill_buffer(rsound_t *rd, const char *buf, size_t size)
return 0;
slock_lock(rd->thread.mutex);
- if ( fifo_write_avail(rd->fifo_buffer) >= size )
+ if (FIFO_WRITE_AVAIL(rd->fifo_buffer) >= size)
{
slock_unlock(rd->thread.mutex);
break;
@@ -886,7 +886,7 @@ static size_t rsnd_get_ptr(rsound_t *rd)
{
int ptr;
slock_lock(rd->thread.mutex);
- ptr = fifo_read_avail(rd->fifo_buffer);
+ ptr = FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
return ptr;
@@ -1060,7 +1060,7 @@ static int rsnd_update_server_info(rsound_t *rd)
int delay = rsd_delay(rd);
int delta = (int)(client_ptr - serv_ptr);
slock_lock(rd->thread.mutex);
- delta += fifo_read_avail(rd->fifo_buffer);
+ delta += FIFO_READ_AVAIL(rd->fifo_buffer);
slock_unlock(rd->thread.mutex);
RSD_DEBUG("[RSound] Delay: %d, Delta: %d.\n", delay, delta);
@@ -1116,7 +1116,7 @@ static void rsnd_thread ( void * thread_data )
/* If the buffer is empty or we've stopped the stream, jump out of this for loop */
slock_lock(rd->thread.mutex);
- if ( fifo_read_avail(rd->fifo_buffer) < rd->backend_info.chunk_size || !rd->thread_active )
+ if (FIFO_READ_AVAIL(rd->fifo_buffer) < rd->backend_info.chunk_size || !rd->thread_active)
{
slock_unlock(rd->thread.mutex);
break;
@@ -1382,11 +1382,10 @@ int rsd_exec(rsound_t *rsound)
fcntl(rsound->conn.socket, F_SETFL, O_NONBLOCK);
#endif
- // Flush the buffer
-
- if ( fifo_read_avail(rsound->fifo_buffer) > 0 )
+ /* Flush the buffer */
+ if (FIFO_READ_AVAIL(rsound->fifo_buffer) > 0 )
{
- char buffer[fifo_read_avail(rsound->fifo_buffer)];
+ char buffer[FIFO_READ_AVAIL(rsound->fifo_buffer)];
fifo_read(rsound->fifo_buffer, buffer, sizeof(buffer));
if ( rsnd_send_chunk(fd, buffer, sizeof(buffer), 1) != (ssize_t)sizeof(buffer) )
{
diff --git a/bluetooth/bluetooth_driver.h b/bluetooth/bluetooth_driver.h
new file mode 100644
index 0000000000..404dec082b
--- /dev/null
+++ b/bluetooth/bluetooth_driver.h
@@ -0,0 +1,78 @@
+/* RetroArch - A frontend for libretro.
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#ifndef __BLUETOOTH_DRIVER__H
+#define __BLUETOOTH_DRIVER__H
+
+#include
+
+#include
+#include
+#include
+
+RETRO_BEGIN_DECLS
+
+enum rarch_bluetooth_ctl_state
+{
+ RARCH_BLUETOOTH_CTL_NONE = 0,
+ RARCH_BLUETOOTH_CTL_DESTROY,
+ RARCH_BLUETOOTH_CTL_DEINIT,
+ RARCH_BLUETOOTH_CTL_FIND_DRIVER,
+ RARCH_BLUETOOTH_CTL_INIT
+};
+
+typedef struct bluetooth_driver
+{
+ void *(*init)(void);
+
+ void (*free)(void *data);
+
+ void (*scan)(void *data);
+ void (*get_devices)(void *data, struct string_list *list);
+ bool (*device_is_connected)(void *data, unsigned i);
+ void (*device_get_sublabel)(void *data, char *s, unsigned i, size_t len);
+ bool (*connect_device)(void *data, unsigned i);
+
+ const char *ident;
+} bluetooth_driver_t;
+
+extern bluetooth_driver_t bluetooth_bluetoothctl;
+extern bluetooth_driver_t bluetooth_bluez;
+
+/**
+ * config_get_bluetooth_driver_options:
+ *
+ * Get an enumerated list of all bluetooth driver names,
+ * separated by '|'.
+ *
+ * Returns: string listing of all bluetooth driver names,
+ * separated by '|'.
+ **/
+const char* config_get_bluetooth_driver_options(void);
+
+void driver_bluetooth_scan(void);
+
+void driver_bluetooth_get_devices(struct string_list *list);
+
+bool driver_bluetooth_device_is_connected(unsigned i);
+
+void driver_bluetooth_device_get_sublabel(char *s, unsigned i, size_t len);
+
+bool driver_bluetooth_connect_device(unsigned i);
+
+bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data);
+
+RETRO_END_DECLS
+
+#endif
diff --git a/bluetooth/drivers/bluetoothctl.c b/bluetooth/drivers/bluetoothctl.c
new file mode 100644
index 0000000000..6741931454
--- /dev/null
+++ b/bluetooth/drivers/bluetoothctl.c
@@ -0,0 +1,215 @@
+/* RetroArch - A frontend for libretro.
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include
+#include
+
+#include "../bluetooth_driver.h"
+#include "../../retroarch.h"
+
+typedef struct
+{
+ bool bluetoothctl_cache[256];
+ unsigned bluetoothctl_counter[256];
+ struct string_list* lines;
+ char command[256];
+} bluetoothctl_t;
+
+static void *bluetoothctl_init(void)
+{
+ return calloc(1, sizeof(bluetoothctl_t));
+}
+
+static void bluetoothctl_free(void *data)
+{
+ if (data)
+ free(data);
+}
+
+static void bluetoothctl_scan(void *data)
+{
+ char line[512];
+ union string_list_elem_attr attr;
+ FILE *dev_file = NULL;
+ bluetoothctl_t *btctl = (bluetoothctl_t*) data;
+
+ attr.i = 0;
+ if (btctl->lines)
+ free(btctl->lines);
+ btctl->lines = string_list_new();
+
+ pclose(popen("bluetoothctl -- power on", "r"));
+
+ pclose(popen("bluetoothctl --timeout 10 scan on", "r"));
+
+ runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE),
+ 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
+ MESSAGE_QUEUE_CATEGORY_INFO);
+
+ dev_file = popen("bluetoothctl -- devices", "r");
+
+ while (fgets(line, 512, dev_file))
+ {
+ size_t len = strlen(line);
+ if (len > 0 && line[len-1] == '\n')
+ line[--len] = '\0';
+
+ string_list_append(btctl->lines, line, attr);
+ }
+
+ pclose(dev_file);
+}
+
+static void bluetoothctl_get_devices(void *data, struct string_list* devices)
+{
+ unsigned i;
+ union string_list_elem_attr attr;
+ bluetoothctl_t *btctl = (bluetoothctl_t*) data;
+
+ attr.i = 0;
+
+ if (!btctl->lines)
+ return;
+
+ for (i = 0; i < btctl->lines->size; i++)
+ {
+ char device[64];
+ const char *line = btctl->lines->elems[i].data;
+
+ /* bluetoothctl devices outputs lines of the format:
+ * $ bluetoothctl devices
+ * 'Device (mac address) (device name)'
+ */
+ strlcpy(device, line+24, sizeof(device));
+ string_list_append(devices, device, attr);
+ }
+}
+
+static bool bluetoothctl_device_is_connected(void *data, unsigned i)
+{
+ bluetoothctl_t *btctl = (bluetoothctl_t*) data;
+ char ln[512] = {0};
+ char device[18] = {0};
+ const char *line = btctl->lines->elems[i].data;
+ FILE *command_file = NULL;
+
+ if (btctl->bluetoothctl_counter[i] == 60)
+ {
+ static struct string_list* list = NULL;
+ btctl->bluetoothctl_counter[i] = 0;
+ list = string_split(line, " ");
+ if (!list)
+ return false;
+
+ if (list->size == 0)
+ {
+ string_list_free(list);
+ return false;
+ }
+
+ strlcpy(device, list->elems[1].data, sizeof(device));
+ string_list_free(list);
+
+ snprintf(btctl->command, sizeof(btctl->command), "\
+ bluetoothctl -- info %s | grep 'Connected: yes'",
+ device);
+
+ command_file = popen(btctl->command, "r");
+
+ while (fgets(ln, 512, command_file))
+ {
+ btctl->bluetoothctl_cache[i] = true;
+ return true;
+ }
+ pclose(command_file);
+ btctl->bluetoothctl_cache[i] = false;
+ }
+ else
+ {
+ btctl->bluetoothctl_counter[i]++;
+ return btctl->bluetoothctl_cache[i];
+ }
+
+ return false;
+}
+
+static bool bluetoothctl_connect_device(void *data, unsigned idx)
+{
+ unsigned i;
+ bluetoothctl_t *btctl = (bluetoothctl_t*) data;
+ char device[18] = {0};
+ const char *line = btctl->lines->elems[idx].data;
+ static struct string_list* list = NULL;
+
+ /* bluetoothctl devices outputs lines of the format:
+ * $ bluetoothctl devices
+ * 'Device (mac address) (device name)'
+ */
+ list = string_split(line, " ");
+ if (!list)
+ return false;
+
+ if (list->size == 0)
+ {
+ string_list_free(list);
+ return false;
+ }
+
+ strlcpy(device, list->elems[1].data, sizeof(device));
+ string_list_free(list);
+
+ snprintf(btctl->command, sizeof(btctl->command), "\
+ bluetoothctl -- trust %s",
+ device);
+
+ pclose(popen(btctl->command, "r"));
+
+ snprintf(btctl->command, sizeof(btctl->command), "\
+ bluetoothctl -- pair %s",
+ device);
+
+ pclose(popen(btctl->command, "r"));
+
+ snprintf(btctl->command, sizeof(btctl->command), "\
+ bluetoothctl -- connect %s",
+ device);
+
+ pclose(popen(btctl->command, "r"));
+
+ btctl->bluetoothctl_counter[idx] = 0;
+ return true;
+}
+
+static void bluetoothctl_device_get_sublabel(
+ void *data, char *s, unsigned i, size_t len)
+{
+ bluetoothctl_t *btctl = (bluetoothctl_t*) data;
+ /* bluetoothctl devices outputs lines of the format:
+ * $ bluetoothctl devices
+ * 'Device (mac address) (device name)'
+ */
+ const char *line = btctl->lines->elems[i].data;
+ strlcpy(s, line+7, 18);
+}
+
+bluetooth_driver_t bluetooth_bluetoothctl = {
+ bluetoothctl_init,
+ bluetoothctl_free,
+ bluetoothctl_scan,
+ bluetoothctl_get_devices,
+ bluetoothctl_device_is_connected,
+ bluetoothctl_device_get_sublabel,
+ bluetoothctl_connect_device,
+ "bluetoothctl",
+};
diff --git a/bluetooth/drivers/bluez.c b/bluetooth/drivers/bluez.c
new file mode 100644
index 0000000000..82239c319d
--- /dev/null
+++ b/bluetooth/drivers/bluez.c
@@ -0,0 +1,616 @@
+/* RetroArch - A frontend for libretro.
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "../bluetooth_driver.h"
+#include "../../retroarch.h"
+
+typedef struct
+{
+ /* object path. usually looks like /org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF
+ * technically unlimited, but should be enough */
+ char path[128];
+
+ /* for display purposes 64 bytes should be enough */
+ char name[64];
+
+ /* MAC address, 17 bytes */
+ char address[18];
+
+ /* freedesktop.org icon name
+ * See bluez/src/dbus-common.c
+ * Can be NULL */
+ char icon[64];
+
+ int connected;
+ int paired;
+ int trusted;
+} device_info_t;
+
+#define VECTOR_LIST_TYPE device_info_t
+#define VECTOR_LIST_NAME device_info
+#include "../../libretro-common/lists/vector_list.c"
+#undef VECTOR_LIST_TYPE
+#undef VECTOR_LIST_NAME
+
+typedef struct
+{
+ struct device_info_vector_list *devices;
+ char adapter[256];
+ DBusConnection* dbus_connection;
+ bool bluez_cache[256];
+ int bluez_cache_counter[256];
+} bluez_t;
+
+static void *bluez_init (void)
+{
+ return calloc(1, sizeof(bluez_t));
+}
+
+static void bluez_free (void *data)
+{
+ if (data)
+ free(data);
+}
+
+static int
+set_bool_property (
+ bluez_t *bluez,
+ const char *path,
+ const char *arg_adapter,
+ const char *arg_property,
+ int value)
+{
+ DBusError err;
+ DBusMessage *message, *reply;
+ DBusMessageIter req_iter, req_subiter;
+
+ dbus_error_init(&err);
+
+ message = dbus_message_new_method_call(
+ "org.bluez",
+ path,
+ "org.freedesktop.DBus.Properties",
+ "Set"
+ );
+ if (!message)
+ return 1;
+
+ dbus_message_iter_init_append(message, &req_iter);
+ if (!dbus_message_iter_append_basic(
+ &req_iter, DBUS_TYPE_STRING, &arg_adapter))
+ goto fault;
+ if (!dbus_message_iter_append_basic(
+ &req_iter, DBUS_TYPE_STRING, &arg_property))
+ goto fault;
+ if (!dbus_message_iter_open_container(
+ &req_iter, DBUS_TYPE_VARIANT,
+ DBUS_TYPE_BOOLEAN_AS_STRING, &req_subiter))
+ goto fault;
+ if (!dbus_message_iter_append_basic(
+ &req_subiter, DBUS_TYPE_BOOLEAN, &value))
+ goto fault;
+ if (!dbus_message_iter_close_container(
+ &req_iter, &req_subiter))
+ goto fault;
+
+ reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
+ message, 1000, &err);
+ if (!reply)
+ goto fault;
+ dbus_message_unref(reply);
+ dbus_message_unref(message);
+ return 0;
+
+fault:
+ dbus_message_iter_abandon_container_if_open(&req_iter, &req_subiter);
+ dbus_message_unref(message);
+ return 1;
+}
+
+static int get_bool_property(
+ bluez_t *bluez,
+ const char *path,
+ const char *arg_adapter,
+ const char *arg_property,
+ int *value)
+{
+ DBusMessage *message, *reply;
+ DBusError err;
+ DBusMessageIter root_iter, variant_iter;
+
+ dbus_error_init(&err);
+
+ message = dbus_message_new_method_call( "org.bluez", path,
+ "org.freedesktop.DBus.Properties", "Get");
+ if (!message)
+ return 1;
+
+ if (!dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &arg_adapter,
+ DBUS_TYPE_STRING, &arg_property,
+ DBUS_TYPE_INVALID))
+ return 1;
+
+ reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
+ message, 1000, &err);
+
+ dbus_message_unref(message);
+
+ if (!reply)
+ return 1;
+
+ if (!dbus_message_iter_init(reply, &root_iter))
+ return 1;
+
+ if (DBUS_TYPE_VARIANT != dbus_message_iter_get_arg_type(&root_iter))
+ return 1;
+
+ dbus_message_iter_recurse(&root_iter, &variant_iter);
+ dbus_message_iter_get_basic(&variant_iter, value);
+
+ dbus_message_unref(reply);
+ return 0;
+}
+
+static int adapter_discovery (bluez_t *bluez, const char *method)
+{
+ DBusMessage *message = dbus_message_new_method_call(
+ "org.bluez", bluez->adapter,
+ "org.bluez.Adapter1", method);
+ if (!message)
+ return 1;
+
+ if (!dbus_connection_send(bluez->dbus_connection, message, NULL))
+ return 1;
+
+ dbus_connection_flush(bluez->dbus_connection);
+ dbus_message_unref(message);
+
+ return 0;
+}
+
+static int get_managed_objects (bluez_t *bluez, DBusMessage **reply)
+{
+ DBusMessage *message;
+ DBusError err;
+
+ dbus_error_init(&err);
+
+ message = dbus_message_new_method_call("org.bluez", "/",
+ "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ if (!message)
+ return 1;
+
+ *reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
+ message, -1, &err);
+ /* if (!reply) is done by the caller in this one */
+
+ dbus_message_unref(message);
+ return 0;
+}
+
+static int device_method (bluez_t *bluez, const char *path, const char *method)
+{
+ DBusMessage *message, *reply;
+ DBusError err;
+
+ dbus_error_init(&err);
+
+ message = dbus_message_new_method_call( "org.bluez", path,
+ "org.bluez.Device1", method);
+ if (!message)
+ return 1;
+
+ reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
+ message, 10000, &err);
+ if (!reply)
+ return 1;
+
+ dbus_connection_flush(bluez->dbus_connection);
+ dbus_message_unref(message);
+
+ return 0;
+}
+
+static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
+{
+ /* "...an application would discover the available adapters by
+ * performing a ObjectManager.GetManagedObjects call and look for any
+ * returned objects with an “org.bluez.Adapter1″ interface.
+ * The concept of a default adapter was always a bit fuzzy and the
+ * value could’t be changed, so if applications need something like it
+ * they could e.g. just pick the first adapter they encounter in the
+ * GetManagedObjects reply."
+ * -- http://www.bluez.org/bluez-5-api-introduction-and-porting-guide/
+ */
+
+ DBusMessageIter root_iter;
+ DBusMessageIter dict_1_iter, dict_2_iter;
+ DBusMessageIter array_1_iter, array_2_iter;
+
+ char *obj_path, *interface_name;
+
+ /* a{oa{sa{sv}}} */
+ if (!dbus_message_iter_init(reply, &root_iter))
+ return 1;
+
+ /* a */
+ if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&root_iter))
+ return 1;
+ dbus_message_iter_recurse(&root_iter, &array_1_iter);
+ do
+ {
+ /* a{...} */
+ if (DBUS_TYPE_DICT_ENTRY != dbus_message_iter_get_arg_type(&array_1_iter))
+ return 1;
+ dbus_message_iter_recurse(&array_1_iter, &dict_1_iter);
+
+ /* a{o...} */
+ if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&dict_1_iter))
+ return 1;
+ dbus_message_iter_get_basic(&dict_1_iter, &obj_path);
+
+ if (!dbus_message_iter_next(&dict_1_iter))
+ return 1;
+ /* a{oa} */
+ if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&dict_1_iter))
+ return 1;
+ dbus_message_iter_recurse(&dict_1_iter, &array_2_iter);
+ do
+ {
+ /* empty array? */
+ if (DBUS_TYPE_INVALID ==
+ dbus_message_iter_get_arg_type(&array_2_iter))
+ continue;
+
+ /* a{oa{...}} */
+ if (DBUS_TYPE_DICT_ENTRY !=
+ dbus_message_iter_get_arg_type(&array_2_iter))
+ return 1;
+ dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);
+
+ /* a{oa{s...}} */
+ if (DBUS_TYPE_STRING !=
+ dbus_message_iter_get_arg_type(&dict_2_iter))
+ return 1;
+ dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
+
+ if (string_is_equal(interface_name, "org.bluez.Adapter1"))
+ {
+ strlcpy(bluez->adapter, obj_path, 256);
+ return 0;
+ }
+ } while (dbus_message_iter_next(&array_2_iter));
+ } while (dbus_message_iter_next(&array_1_iter));
+
+ /* Couldn't find an adapter */
+ return 1;
+}
+
+static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
+{
+ device_info_t device;
+ DBusMessageIter root_iter;
+ DBusMessageIter dict_1_iter, dict_2_iter, dict_3_iter;
+ DBusMessageIter array_1_iter, array_2_iter, array_3_iter;
+ DBusMessageIter variant_iter;
+ char *obj_path, *interface_name, *interface_property_name;
+ char *found_device_address, *found_device_name, *found_device_icon;
+
+ /* a{oa{sa{sv}}} */
+ if (!dbus_message_iter_init(reply, &root_iter))
+ return 1;
+
+ /* a */
+ if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&root_iter))
+ return 1;
+
+ dbus_message_iter_recurse(&root_iter, &array_1_iter);
+
+ do
+ {
+ /* a{...} */
+ if (DBUS_TYPE_DICT_ENTRY !=
+ dbus_message_iter_get_arg_type(&array_1_iter))
+ return 1;
+
+ dbus_message_iter_recurse(&array_1_iter, &dict_1_iter);
+
+ /* a{o...} */
+ if (DBUS_TYPE_OBJECT_PATH !=
+ dbus_message_iter_get_arg_type(&dict_1_iter))
+ return 1;
+
+ dbus_message_iter_get_basic(&dict_1_iter, &obj_path);
+
+ if (!dbus_message_iter_next(&dict_1_iter))
+ return 1;
+
+ /* a{oa} */
+ if (DBUS_TYPE_ARRAY !=
+ dbus_message_iter_get_arg_type(&dict_1_iter))
+ return 1;
+
+ dbus_message_iter_recurse(&dict_1_iter, &array_2_iter);
+ do
+ {
+ /* empty array? */
+ if (DBUS_TYPE_INVALID ==
+ dbus_message_iter_get_arg_type(&array_2_iter))
+ continue;
+
+ /* a{oa{...}} */
+ if (DBUS_TYPE_DICT_ENTRY !=
+ dbus_message_iter_get_arg_type(&array_2_iter))
+ return 1;
+ dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);
+
+ /* a{oa{s...}} */
+ if (DBUS_TYPE_STRING !=
+ dbus_message_iter_get_arg_type(&dict_2_iter))
+ return 1;
+ dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
+
+ if (!string_is_equal(interface_name, "org.bluez.Device1"))
+ continue;
+
+ memset(&device, 0, sizeof(device));
+ strlcpy(device.path, obj_path, 128);
+
+ if (!dbus_message_iter_next(&dict_2_iter))
+ return 1;
+
+ /* a{oa{sa}} */
+ if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&dict_2_iter))
+ return 1;
+
+ dbus_message_iter_recurse(&dict_2_iter, &array_3_iter);
+
+ do {
+ /* empty array? */
+ if (DBUS_TYPE_INVALID ==
+ dbus_message_iter_get_arg_type(&array_3_iter))
+ continue;
+
+ /* a{oa{sa{...}}} */
+ if (DBUS_TYPE_DICT_ENTRY !=
+ dbus_message_iter_get_arg_type(&array_3_iter))
+ return 1;
+ dbus_message_iter_recurse(&array_3_iter, &dict_3_iter);
+
+ /* a{oa{sa{s...}}} */
+ if (DBUS_TYPE_STRING !=
+ dbus_message_iter_get_arg_type(&dict_3_iter))
+ return 1;
+
+ dbus_message_iter_get_basic(&dict_3_iter,
+ &interface_property_name);
+
+ if (!dbus_message_iter_next(&dict_3_iter))
+ return 1;
+ /* a{oa{sa{sv}}} */
+ if (DBUS_TYPE_VARIANT !=
+ dbus_message_iter_get_arg_type(&dict_3_iter))
+ return 1;
+
+ /* Below, "Alias" property is used instead of "Name".
+ * "This value ("Name") is only present for
+ * completeness. It is better to always use
+ * the Alias property when displaying the
+ * devices name."
+ * -- bluez/doc/device-api.txt
+ */
+
+ /* DBUS_TYPE_VARIANT is a container type */
+ dbus_message_iter_recurse(&dict_3_iter, &variant_iter);
+ if (string_is_equal(interface_property_name, "Address"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &found_device_address);
+ strlcpy(device.address, found_device_address, 18);
+ }
+ else if (string_is_equal(interface_property_name, "Alias"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &found_device_name);
+ strlcpy(device.name, found_device_name, 64);
+ }
+ else if (string_is_equal(interface_property_name, "Icon"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &found_device_icon);
+ strlcpy(device.icon, found_device_icon, 64);
+ }
+ else if (string_is_equal(interface_property_name, "Connected"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &device.connected);
+ }
+ else if (string_is_equal(interface_property_name, "Paired"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &device.paired);
+ }
+ else if (string_is_equal(interface_property_name, "Trusted"))
+ {
+ dbus_message_iter_get_basic(&variant_iter,
+ &device.trusted);
+ }
+ } while (dbus_message_iter_next(&array_3_iter));
+
+ if (!device_info_vector_list_append(bluez->devices, device))
+ return 1;
+
+ } while (dbus_message_iter_next(&array_2_iter));
+ } while (dbus_message_iter_next(&array_1_iter));
+
+ return 0;
+}
+
+static void bluez_dbus_connect(bluez_t *bluez)
+{
+ DBusError err;
+ dbus_error_init(&err);
+ bluez->dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
+}
+
+static void bluez_dbus_disconnect(bluez_t *bluez)
+{
+ if (!bluez->dbus_connection)
+ return;
+
+ dbus_connection_close(bluez->dbus_connection);
+ dbus_connection_unref(bluez->dbus_connection);
+ bluez->dbus_connection = NULL;
+}
+
+static void bluez_scan(void *data)
+{
+ DBusError err;
+ DBusMessage *reply;
+ bluez_t *bluez = (bluez_t*)data;
+
+ bluez_dbus_connect(bluez);
+
+ if (get_managed_objects(bluez, &reply))
+ return;
+ if (!reply)
+ return;
+
+ /* Get default adapter */
+ if (get_default_adapter(bluez, reply))
+ return;
+ dbus_message_unref(reply);
+
+ /* Power device on */
+ if (set_bool_property(bluez, bluez->adapter,
+ "org.bluez.Adapter1", "Powered", 1))
+ return;
+
+ /* Start discovery */
+ if (adapter_discovery(bluez, "StartDiscovery"))
+ return;
+
+ retro_sleep(10000);
+
+ /* Stop discovery */
+ if (adapter_discovery(bluez, "StopDiscovery"))
+ return;
+
+ /* Get scanned devices */
+ if (get_managed_objects(bluez, &reply))
+ return;
+ if (!reply)
+ return;
+
+ if (bluez->devices)
+ device_info_vector_list_free(bluez->devices);
+ bluez->devices = device_info_vector_list_new();
+
+ read_scanned_devices(bluez, reply);
+ dbus_message_unref(reply);
+ bluez_dbus_disconnect(bluez);
+}
+
+static void bluez_get_devices(void *data,
+ struct string_list* devices_string_list)
+{
+ unsigned i;
+ union string_list_elem_attr attr;
+ bluez_t *bluez = (bluez_t*)data;
+
+ attr.i = 0;
+
+ if (!bluez->devices)
+ return;
+
+ for (i = 0; i < bluez->devices->count; i++)
+ {
+ char device[64];
+ strlcpy(device, bluez->devices->data[i].name, sizeof(device));
+ string_list_append(devices_string_list, device, attr);
+ }
+}
+
+static bool bluez_device_is_connected(void *data, unsigned i)
+{
+ int value;
+ bluez_t *bluez = (bluez_t*)data;
+
+ if (bluez->bluez_cache_counter[i] == 60)
+ {
+ bluez->bluez_cache_counter[i] = 0;
+ bluez_dbus_connect(bluez);
+
+ /* Device disappeared */
+ if (get_bool_property(bluez, bluez->devices->data[i].path,
+ "org.bluez.Device1", "Connected", &value))
+ value = false;
+
+ bluez_dbus_disconnect(bluez);
+
+ bluez->bluez_cache[i] = value;
+ return value;
+ }
+
+ bluez->bluez_cache_counter[i]++;
+ return bluez->bluez_cache[i];
+}
+
+static void bluez_device_get_sublabel(
+ void *data, char *s, unsigned i, size_t len)
+{
+ bluez_t *bluez = (bluez_t*)data;
+ strlcpy(s, bluez->devices->data[i].address, len);
+}
+
+static bool bluez_connect_device(void *data, unsigned i)
+{
+ bluez_t *bluez = (bluez_t*)data;
+ bluez_dbus_connect(bluez);
+
+ /* Trust the device */
+ if (set_bool_property(bluez, bluez->devices->data[i].path,
+ "org.bluez.Device1", "Trusted", 1))
+ return false;
+
+ /* Pair the device */
+ device_method(bluez, bluez->devices->data[i].path, "Pair");
+
+ /* Can be "Already Exists" */
+ /* Connect the device */
+ if (device_method(bluez, bluez->devices->data[i].path, "Connect"))
+ return false;
+
+ bluez_dbus_disconnect(bluez);
+ bluez->bluez_cache_counter[i] = 0;
+ return true;
+}
+
+bluetooth_driver_t bluetooth_bluez = {
+ bluez_init,
+ bluez_free,
+ bluez_scan,
+ bluez_get_devices,
+ bluez_device_is_connected,
+ bluez_device_get_sublabel,
+ bluez_connect_device,
+ "bluez",
+};
diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c
index 06d8936a0f..435fa3ea26 100644
--- a/cheevos/cheevos.c
+++ b/cheevos/cheevos.c
@@ -145,8 +145,8 @@ typedef struct rcheevos_async_io_request
int attempt_count;
char type;
char hardcore;
- char* success_message;
- char* failure_message;
+ const char* success_message;
+ const char* failure_message;
char user_agent[256];
} rcheevos_async_io_request;
@@ -443,7 +443,7 @@ static retro_time_t rcheevos_async_send_rich_presence(
{
if (settings->bools.discord_enable
&& discord_is_ready())
- discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS, false);
+ discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS);
}
#endif
@@ -521,7 +521,8 @@ static void rcheevos_async_task_callback(
case CHEEVOS_ASYNC_AWARD_ACHIEVEMENT:
/* ignore already unlocked */
- if (string_starts_with(buffer, "User already has "))
+ if (string_starts_with_size(buffer, "User already has ",
+ STRLEN_CONST("User already has ")))
break;
/* fallthrough to default */
@@ -820,12 +821,16 @@ static void rcheevos_async_award_achievement(rcheevos_async_io_request* request)
rcheevos_log_url("rc_url_award_cheevo", buffer);
task_push_http_transfer_with_user_agent(buffer, true, NULL, request->user_agent, rcheevos_async_task_callback, request);
+
+#ifdef HAVE_AUDIOMIXER
+ if (settings->bools.cheevos_unlock_sound_enable)
+ audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_ACHIEVEMENT_UNLOCK);
+#endif
}
static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode)
{
char buffer[256];
- settings_t *settings = config_get_ptr();
buffer[0] = 0;
CHEEVOS_LOG(RCHEEVOS_TAG "awarding cheevo %u: %s (%s)\n",
@@ -865,24 +870,29 @@ static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode)
rcheevos_async_award_achievement(request);
}
- /* Take a screenshot of the achievement. */
- if (settings && settings->bools.cheevos_auto_screenshot)
+#ifdef HAVE_SCREENSHOTS
{
- char shotname[8192];
+ settings_t *settings = config_get_ptr();
+ /* Take a screenshot of the achievement. */
+ if (settings && settings->bools.cheevos_auto_screenshot)
+ {
+ char shotname[8192];
- snprintf(shotname, sizeof(shotname), "%s/%s-cheevo-%u",
- settings->paths.directory_screenshot,
- path_basename(path_get(RARCH_PATH_BASENAME)),
- cheevo->info->id);
- shotname[sizeof(shotname) - 1] = '\0';
+ snprintf(shotname, sizeof(shotname), "%s/%s-cheevo-%u",
+ settings->paths.directory_screenshot,
+ path_basename(path_get(RARCH_PATH_BASENAME)),
+ cheevo->info->id);
+ shotname[sizeof(shotname) - 1] = '\0';
- if (take_screenshot(settings->paths.directory_screenshot,
- shotname, true,
- video_driver_cached_frame_has_valid_framebuffer(), false, true))
- CHEEVOS_LOG(RCHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id);
- else
- CHEEVOS_LOG(RCHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id);
+ if (take_screenshot(settings->paths.directory_screenshot,
+ shotname, true,
+ video_driver_cached_frame_has_valid_framebuffer(), false, true))
+ CHEEVOS_LOG(RCHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id);
+ else
+ CHEEVOS_LOG(RCHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id);
+ }
}
+#endif
}
static int rcheevos_has_indirect_memref(const rc_memref_value_t* memrefs)
@@ -994,14 +1004,6 @@ static void rcheevos_lboard_submit(rcheevos_lboard_t* lboard)
/* Deactivate the leaderboard. */
lboard->active = 0;
- /* Failsafe for improper leaderboards. */
- if (lboard->last_value == 0)
- {
- CHEEVOS_ERR(RCHEEVOS_TAG "Leaderboard %s tried to submit 0\n", lboard->info->title);
- runloop_msg_queue_push("Leaderboard attempt cancelled!", 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
- return;
- }
-
/* Show the OSD message. */
rc_format_value(value, sizeof(value), lboard->last_value, lboard->format);
@@ -1150,16 +1152,23 @@ void rcheevos_get_achievement_state(unsigned index, char *buffer, size_t buffer_
{
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNSUPPORTED_ENTRY;
}
+ else if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE))
+ {
+ enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE;
+ }
+ else if (!(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
+ {
+ /* if in hardcore mode, track progress towards hardcore unlock */
+ const settings_t* settings = config_get_ptr();
+ const bool hardcore = settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused;
+ check_measured = hardcore;
+
+ enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY;
+ }
else
{
- settings_t* settings = config_get_ptr();
- bool hardcore = settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused;
- if (hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE))
- enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE;
- else if (!hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
- enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY;
- else /* Use either "Locked" for core or "Unofficial" for unofficial as set above */
- check_measured = true;
+ /* Use either "Locked" for core or "Unofficial" for unofficial as set above and track progress */
+ check_measured = true;
}
strlcpy(buffer, msg_hash_to_str(enum_idx), buffer_size);
@@ -1548,7 +1557,7 @@ static int rcheevos_iterate(rcheevos_coro_t* coro)
CORO_STOP();
/* iterate over the possible hashes for the file being loaded */
- rc_hash_initialize_iterator(&coro->iterator, coro->path, NULL, 0);
+ rc_hash_initialize_iterator(&coro->iterator, coro->path, (uint8_t*)coro->data, coro->len);
#ifdef CHEEVOS_TIME_HASH
start = cpu_features_get_time_usec();
#endif
diff --git a/cheevos/parser.c b/cheevos/parser.c
index a2688d4b78..13cffaa6e9 100644
--- a/cheevos/parser.c
+++ b/cheevos/parser.c
@@ -291,7 +291,7 @@ typedef struct
static char* rcheevos_unescape_string(const char* string, size_t length)
{
const char* end = string + length;
- char* buffer = (char*)malloc(length + 1);
+ char* buffer = (char*)malloc(length + 1);
char* buffer_it = buffer;
if (buffer == NULL)
@@ -329,18 +329,19 @@ static char* rcheevos_unescape_string(const char* string, size_t length)
{
char temp[5];
- string += 2;
+ string += 2;
memcpy(temp, string, 4);
- temp[4] = '\0';
- utf16[j] = string_hex_to_unsigned(temp);
- string += 4;
+ temp[4] = '\0';
+ utf16[j] = string_hex_to_unsigned(temp);
+ string += 4;
}
utf16[j] = 0;
if (utf16_to_char_string(utf16, utf8, sizeof(utf8)))
{
- memcpy(buffer_it, utf8, strlen(utf8));
- buffer_it += strlen(utf8);
+ size_t utf8_len = strlen(utf8);
+ memcpy(buffer_it, utf8, utf8_len);
+ buffer_it += utf8_len;
}
}
break;
diff --git a/config.def.h b/config.def.h
index 21314eb899..60658fc8d9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -53,48 +53,6 @@
#define DEFAULT_ASPECT_RATIO -1.0f
#endif
-#if defined(ANDROID)
-#define DEFAULT_MAX_PADS 8
-#define ANDROID_KEYBOARD_PORT DEFAULT_MAX_PADS
-#elif defined(_3DS)
-#define DEFAULT_MAX_PADS 1
-#elif defined(SWITCH) || defined(HAVE_LIBNX)
-#define DEFAULT_MAX_PADS 8
-#elif defined(WIIU)
-#ifdef WIIU_HID
-#define DEFAULT_MAX_PADS 16
-#else
-#define DEFAULT_MAX_PADS 5
-#endif
-#elif defined(DJGPP)
-#define DEFAULT_MAX_PADS 1
-#define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS
-#elif defined(XENON)
-#define DEFAULT_MAX_PADS 4
-#elif defined(VITA) || defined(SN_TARGET_PSP2)
-#define DEFAULT_MAX_PADS 4
-#elif defined(PSP)
-#define DEFAULT_MAX_PADS 1
-#elif defined(PS2)
-#define DEFAULT_MAX_PADS 2
-#elif defined(GEKKO) || defined(HW_RVL)
-#define DEFAULT_MAX_PADS 4
-#elif defined(__linux__) || (defined(BSD) && !defined(__MACH__))
-#define DEFAULT_MAX_PADS 8
-#elif defined(__QNX__)
-#define DEFAULT_MAX_PADS 8
-#elif defined(__CELLOS_LV2__)
-#define DEFAULT_MAX_PADS 7
-#elif defined(_XBOX)
-#define DEFAULT_MAX_PADS 4
-#elif defined(HAVE_XINPUT) && !defined(HAVE_DINPUT)
-#define DEFAULT_MAX_PADS 4
-#elif defined(DINGUX)
-#define DEFAULT_MAX_PADS 2
-#else
-#define DEFAULT_MAX_PADS 16
-#endif
-
#if defined(GEKKO)
#define DEFAULT_MOUSE_SCALE 1
#endif
@@ -258,6 +216,18 @@
#endif
#define DEFAULT_CHECK_FIRMWARE_BEFORE_LOADING false
+/* Specifies whether to 'reload' (fork and quit)
+ * RetroArch when launching content with the
+ * currently loaded core
+ * > Only relevant on platforms without dynamic core
+ * loading support
+ * > Setting this to 'false' will decrease loading
+ * times when required core is already running,
+ * but may cause stability issues (if core misbehaves) */
+#ifndef HAVE_DYNAMIC
+#define DEFAULT_ALWAYS_RELOAD_CORE_ON_RUN_CONTENT true
+#endif
+
/* Forcibly disable composition.
* Only valid on Windows Vista/7/8 for now. */
#define DEFAULT_DISABLE_COMPOSITION false
@@ -645,6 +615,8 @@ static const unsigned input_backtouch_enable = false;
static const unsigned input_backtouch_toggle = false;
#endif
+#define DEFAULT_OVERLAY_ENABLE_AUTOPREFERRED true
+
#define DEFAULT_SHOW_PHYSICAL_INPUTS true
#define DEFAULT_ALL_USERS_CONTROL_MENU false
@@ -755,6 +727,40 @@ static const bool audio_enable_menu_bgm = false;
#define DEFAULT_MENU_ENABLE_WIDGETS false
#endif
+/* Display an animation when loading content
+ * > Currently implemented only as a widget */
+#define DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION DEFAULT_MENU_ENABLE_WIDGETS
+
+/* Display a notification when successfully
+ * connecting/disconnecting an autoconfigured
+ * controller
+ * > Disabled by default on the Switch */
+#if defined(HAVE_LIBNX) && defined(HAVE_GFX_WIDGETS)
+#define DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG false
+#else
+#define DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG true
+#endif
+
+/* Display a notification when cheats are being
+ * applied */
+#define DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED true
+
+/* Display a notification when loading an
+ * input remap file */
+#define DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD true
+
+/* Display a notification when loading a
+ * configuration override file */
+#define DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD true
+
+/* Display a notification when automatically restoring
+ * at launch the last used disk of multi-disk content */
+#define DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK true
+
+/* Display a notification when fast forwarding
+ * content */
+#define DEFAULT_NOTIFICATION_SHOW_FAST_FORWARD true
+
/* Output samplerate. */
#ifdef GEKKO
#define DEFAULT_OUTPUT_RATE 32000
@@ -1286,4 +1292,18 @@ static const bool enable_device_vibration = false;
#define DEFAULT_AI_SERVICE_URL "http://localhost:4404/"
+#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
+#define DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE true
+#else
+#define DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE false
+#endif
+
+#if defined(HAVE_IMAGEVIEWER)
+#define DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE true
+#else
+#define DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE false
+#endif
+
+#define DEFAULT_FILTER_BY_CURRENT_CORE false
+
#endif
diff --git a/configuration.c b/configuration.c
index f28e885e62..a8eeac4c32 100644
--- a/configuration.c
+++ b/configuration.c
@@ -2,7 +2,7 @@
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2014-2017 - Jean-André Santoni
- * Copyright (C) 2015-2019 - Andrés Suárez
+ * Copyright (C) 2015-2019 - Andrés Suárez (input remapping + other things)
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
@@ -271,9 +271,16 @@ enum camera_driver_enum
CAMERA_NULL
};
+enum bluetooth_driver_enum
+{
+ BLUETOOTH_BLUETOOTHCTL = CAMERA_NULL + 1,
+ BLUETOOTH_BLUEZ,
+ BLUETOOTH_NULL
+};
+
enum wifi_driver_enum
{
- WIFI_CONNMANCTL = CAMERA_NULL + 1,
+ WIFI_CONNMANCTL = BLUETOOTH_NULL + 1,
WIFI_NULL
};
@@ -559,6 +566,16 @@ static const enum camera_driver_enum CAMERA_DEFAULT_DRIVER = CAMERA_ANDROID;
static const enum camera_driver_enum CAMERA_DEFAULT_DRIVER = CAMERA_NULL;
#endif
+#if defined(HAVE_BLUETOOTH)
+# if defined(HAVE_DBUS)
+static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_BLUEZ;
+# else
+static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_BLUETOOTHCTL;
+# endif
+#else
+static const enum bluetooth_driver_enum BLUETOOTH_DEFAULT_DRIVER = BLUETOOTH_NULL;
+#endif
+
#if defined(HAVE_LAKKA)
static const enum wifi_driver_enum WIFI_DEFAULT_DRIVER = WIFI_CONNMANCTL;
#else
@@ -629,6 +646,10 @@ static void config_parse_file(global_t *global);
struct defaults g_defaults;
+/* TODO/FIXME - static public global variables */
+static unsigned old_analog_dpad_mode[MAX_USERS];
+static unsigned old_libretro_device[MAX_USERS];
+
/**
* config_get_default_audio:
*
@@ -1010,6 +1031,30 @@ const char *config_get_default_camera(void)
return "null";
}
+/**
+ * config_get_default_bluetooth:
+ *
+ * Gets default bluetooth driver.
+ *
+ * Returns: Default bluetooth driver.
+ **/
+const char *config_get_default_bluetooth(void)
+{
+ enum bluetooth_driver_enum default_driver = BLUETOOTH_DEFAULT_DRIVER;
+
+ switch (default_driver)
+ {
+ case BLUETOOTH_BLUETOOTHCTL:
+ return "bluetoothctl";
+ case BLUETOOTH_BLUEZ:
+ return "bluez";
+ case BLUETOOTH_NULL:
+ break;
+ }
+
+ return "null";
+}
+
/**
* config_get_default_wifi:
*
@@ -1144,6 +1189,7 @@ static struct config_array_setting *populate_settings_array(settings_t *settings
SETTING_ARRAY("video_driver", settings->arrays.video_driver, false, NULL, true);
SETTING_ARRAY("record_driver", settings->arrays.record_driver, false, NULL, true);
SETTING_ARRAY("camera_driver", settings->arrays.camera_driver, false, NULL, true);
+ SETTING_ARRAY("bluetooth_driver", settings->arrays.bluetooth_driver, false, NULL, true);
SETTING_ARRAY("wifi_driver", settings->arrays.wifi_driver, false, NULL, true);
SETTING_ARRAY("location_driver", settings->arrays.location_driver,false, NULL, true);
#ifdef HAVE_MENU
@@ -1376,8 +1422,11 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("input_descriptor_hide_unbound", &settings->bools.input_descriptor_hide_unbound, true, input_descriptor_hide_unbound, false);
SETTING_BOOL("load_dummy_on_core_shutdown", &settings->bools.load_dummy_on_core_shutdown, true, DEFAULT_LOAD_DUMMY_ON_CORE_SHUTDOWN, false);
SETTING_BOOL("check_firmware_before_loading", &settings->bools.check_firmware_before_loading, true, DEFAULT_CHECK_FIRMWARE_BEFORE_LOADING, false);
- SETTING_BOOL("builtin_mediaplayer_enable", &settings->bools.multimedia_builtin_mediaplayer_enable, false, false /* TODO */, false);
- SETTING_BOOL("builtin_imageviewer_enable", &settings->bools.multimedia_builtin_imageviewer_enable, true, true, false);
+#ifndef HAVE_DYNAMIC
+ SETTING_BOOL("always_reload_core_on_run_content", &settings->bools.always_reload_core_on_run_content, true, DEFAULT_ALWAYS_RELOAD_CORE_ON_RUN_CONTENT, false);
+#endif
+ SETTING_BOOL("builtin_mediaplayer_enable", &settings->bools.multimedia_builtin_mediaplayer_enable, true, DEFAULT_BUILTIN_MEDIAPLAYER_ENABLE, false);
+ SETTING_BOOL("builtin_imageviewer_enable", &settings->bools.multimedia_builtin_imageviewer_enable, true, DEFAULT_BUILTIN_IMAGEVIEWER_ENABLE, false);
SETTING_BOOL("fps_show", &settings->bools.video_fps_show, true, DEFAULT_FPS_SHOW, false);
SETTING_BOOL("statistics_show", &settings->bools.video_statistics_show, true, DEFAULT_STATISTICS_SHOW, false);
SETTING_BOOL("framecount_show", &settings->bools.video_framecount_show, true, DEFAULT_FRAMECOUNT_SHOW, false);
@@ -1423,6 +1472,13 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("core_set_supports_no_game_enable", &settings->bools.set_supports_no_game_enable, true, true, false);
SETTING_BOOL("audio_enable", &settings->bools.audio_enable, true, DEFAULT_AUDIO_ENABLE, false);
SETTING_BOOL("menu_enable_widgets", &settings->bools.menu_enable_widgets, true, DEFAULT_MENU_ENABLE_WIDGETS, false);
+ SETTING_BOOL("menu_show_load_content_animation", &settings->bools.menu_show_load_content_animation, true, DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION, false);
+ SETTING_BOOL("notification_show_autoconfig", &settings->bools.notification_show_autoconfig, true, DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG, false);
+ SETTING_BOOL("notification_show_cheats_applied", &settings->bools.notification_show_cheats_applied, true, DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED, false);
+ SETTING_BOOL("notification_show_remap_load", &settings->bools.notification_show_remap_load, true, DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD, false);
+ SETTING_BOOL("notification_show_config_override_load", &settings->bools.notification_show_config_override_load, true, DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, false);
+ SETTING_BOOL("notification_show_set_initial_disk", &settings->bools.notification_show_set_initial_disk, true, DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK, false);
+ SETTING_BOOL("notification_show_fast_forward", &settings->bools.notification_show_fast_forward, true, DEFAULT_NOTIFICATION_SHOW_FAST_FORWARD, false);
SETTING_BOOL("menu_widget_scale_auto", &settings->bools.menu_widget_scale_auto, true, DEFAULT_MENU_WIDGET_SCALE_AUTO, false);
SETTING_BOOL("audio_enable_menu", &settings->bools.audio_enable_menu, true, audio_enable_menu, false);
SETTING_BOOL("audio_enable_menu_ok", &settings->bools.audio_enable_menu_ok, true, audio_enable_menu_ok, false);
@@ -1554,7 +1610,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("menu_show_online_updater", &settings->bools.menu_show_online_updater, true, menu_show_online_updater, false);
SETTING_BOOL("menu_show_core_updater", &settings->bools.menu_show_core_updater, true, menu_show_core_updater, false);
SETTING_BOOL("menu_show_legacy_thumbnail_updater", &settings->bools.menu_show_legacy_thumbnail_updater, true, menu_show_legacy_thumbnail_updater, false);
- SETTING_BOOL("filter_by_current_core", &settings->bools.filter_by_current_core, false, false /* TODO */, false);
+ SETTING_BOOL("filter_by_current_core", &settings->bools.filter_by_current_core, true, DEFAULT_FILTER_BY_CURRENT_CORE, false);
SETTING_BOOL("rgui_show_start_screen", &settings->bools.menu_show_start_screen, false, false /* TODO */, false);
SETTING_BOOL("menu_navigation_wraparound_enable", &settings->bools.menu_navigation_wraparound_enable, true, true, false);
SETTING_BOOL("menu_navigation_browser_filter_supported_extensions_enable",
@@ -1588,6 +1644,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("cheevos_hardcore_mode_enable", &settings->bools.cheevos_hardcore_mode_enable, true, false, false);
SETTING_BOOL("cheevos_leaderboards_enable", &settings->bools.cheevos_leaderboards_enable, true, false, false);
SETTING_BOOL("cheevos_richpresence_enable", &settings->bools.cheevos_richpresence_enable, true, true, false);
+ SETTING_BOOL("cheevos_unlock_sound_enable", &settings->bools.cheevos_unlock_sound_enable, true, false, false);
SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false);
SETTING_BOOL("cheevos_auto_screenshot", &settings->bools.cheevos_auto_screenshot, true, false, false);
SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false);
@@ -1595,8 +1652,8 @@ static struct config_bool_setting *populate_settings_bool(
#endif
#ifdef HAVE_OVERLAY
SETTING_BOOL("input_overlay_enable", &settings->bools.input_overlay_enable, true, config_overlay_enable_default(), false);
- SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, true, false);
- SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, false, false);
+ SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, DEFAULT_OVERLAY_ENABLE_AUTOPREFERRED, false);
+ SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, DEFAULT_SHOW_PHYSICAL_INPUTS, false);
SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, DEFAULT_OVERLAY_HIDE_IN_MENU, false);
SETTING_BOOL("input_overlay_show_mouse_cursor", &settings->bools.input_overlay_show_mouse_cursor, true, DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR, false);
SETTING_BOOL("input_overlay_auto_rotate", &settings->bools.input_overlay_auto_rotate, true, DEFAULT_OVERLAY_AUTO_ROTATE, false);
@@ -1676,7 +1733,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("log_to_file", &settings->bools.log_to_file, true, DEFAULT_LOG_TO_FILE, false);
SETTING_OVERRIDE(RARCH_OVERRIDE_SETTING_LOG_TO_FILE);
SETTING_BOOL("log_to_file_timestamp", &settings->bools.log_to_file_timestamp, true, DEFAULT_LOG_TO_FILE_TIMESTAMP, false);
- SETTING_BOOL("ai_service_enable", &settings->bools.ai_service_enable, DEFAULT_AI_SERVICE_ENABLE, false, false);
+ SETTING_BOOL("ai_service_enable", &settings->bools.ai_service_enable, true, DEFAULT_AI_SERVICE_ENABLE, false);
SETTING_BOOL("ai_service_pause", &settings->bools.ai_service_pause, true, DEFAULT_AI_SERVICE_PAUSE, false);
*size = count;
@@ -1894,9 +1951,9 @@ static struct config_uint_setting *populate_settings_uint(
SETTING_UINT("video_windowed_position_y", &settings->uints.window_position_y, true, 0, false);
SETTING_UINT("video_windowed_position_width", &settings->uints.window_position_width, true, DEFAULT_WINDOW_WIDTH, false);
SETTING_UINT("video_windowed_position_height", &settings->uints.window_position_height, true, DEFAULT_WINDOW_HEIGHT, false);
- SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, DEFAULT_AI_SERVICE_MODE, 0, false);
- SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, 0, 0, false);
- SETTING_UINT("ai_service_source_lang", &settings->uints.ai_service_source_lang, 0, 0, false);
+ SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, true, DEFAULT_AI_SERVICE_MODE, false);
+ SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, true, 0, false);
+ SETTING_UINT("ai_service_source_lang", &settings->uints.ai_service_source_lang, true, 0, false);
SETTING_UINT("video_record_threads", &settings->uints.video_record_threads, true, DEFAULT_VIDEO_RECORD_THREADS, false);
@@ -1975,6 +2032,20 @@ static struct config_int_setting *populate_settings_int(
return tmp;
}
+static void video_driver_default_settings(void)
+{
+ global_t *global = global_get_ptr();
+
+ if (!global)
+ return;
+
+ global->console.screen.gamma_correction = DEFAULT_GAMMA;
+ global->console.flickerfilter_enable = false;
+ global->console.softfilter_enable = false;
+
+ global->console.screen.resolutions.current.id = 0;
+}
+
/**
* config_set_defaults:
*
@@ -2002,6 +2073,7 @@ void config_set_defaults(void *data)
const char *def_menu = config_get_default_menu();
#endif
const char *def_camera = config_get_default_camera();
+ const char *def_bluetooth = config_get_default_bluetooth();
const char *def_wifi = config_get_default_wifi();
const char *def_led = config_get_default_led();
const char *def_location = config_get_default_location();
@@ -2073,6 +2145,10 @@ void config_set_defaults(void *data)
configuration_set_string(settings,
settings->arrays.camera_driver,
def_camera);
+ if (def_bluetooth)
+ configuration_set_string(settings,
+ settings->arrays.bluetooth_driver,
+ def_bluetooth);
if (def_wifi)
configuration_set_string(settings,
settings->arrays.wifi_driver,
@@ -2141,11 +2217,6 @@ void config_set_defaults(void *data)
#endif
#endif
-#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
- configuration_set_bool(settings, settings->bools.multimedia_builtin_mediaplayer_enable, true);
-#else
- configuration_set_bool(settings, settings->bools.multimedia_builtin_mediaplayer_enable, false);
-#endif
settings->floats.video_scale = DEFAULT_SCALE;
video_driver_set_threaded(DEFAULT_VIDEO_THREADED);
@@ -2200,7 +2271,6 @@ void config_set_defaults(void *data)
#ifdef HAVE_CONFIGFILE
input_remapping_set_defaults(true);
#endif
- input_autoconfigure_reset();
/* Verify that binds are in proper order. */
for (i = 0; i < MAX_USERS; i++)
@@ -2515,7 +2585,7 @@ static bool check_menu_driver_compatibility(settings_t *settings)
return true;
/* TODO/FIXME - maintenance hazard */
- if (string_starts_with(video_driver, "d3d"))
+ if (string_starts_with_size(video_driver, "d3d", STRLEN_CONST("d3d")))
if (
string_is_equal(video_driver, "d3d9") ||
string_is_equal(video_driver, "d3d10") ||
@@ -2523,7 +2593,7 @@ static bool check_menu_driver_compatibility(settings_t *settings)
string_is_equal(video_driver, "d3d12")
)
return true;
- if (string_starts_with(video_driver, "gl"))
+ if (string_starts_with_size(video_driver, "gl", STRLEN_CONST("gl")))
if (
string_is_equal(video_driver, "gl") ||
string_is_equal(video_driver, "gl1") ||
@@ -2754,6 +2824,39 @@ error:
free(app_path);
return NULL;
}
+
+#ifdef RARCH_CONSOLE
+static void video_driver_load_settings(config_file_t *conf)
+{
+ bool tmp_bool = false;
+ global_t *global = global_get_ptr();
+
+ if (!conf)
+ return;
+
+ CONFIG_GET_INT_BASE(conf, global,
+ console.screen.gamma_correction, "gamma_correction");
+
+ if (config_get_bool(conf, "flicker_filter_enable",
+ &tmp_bool))
+ global->console.flickerfilter_enable = tmp_bool;
+
+ if (config_get_bool(conf, "soft_filter_enable",
+ &tmp_bool))
+ global->console.softfilter_enable = tmp_bool;
+
+ CONFIG_GET_INT_BASE(conf, global,
+ console.screen.soft_filter_index,
+ "soft_filter_index");
+ CONFIG_GET_INT_BASE(conf, global,
+ console.screen.resolutions.current.id,
+ "current_resolution_id");
+ CONFIG_GET_INT_BASE(conf, global,
+ console.screen.flicker_filter_index,
+ "flicker_filter_index");
+}
+#endif
+
/**
* config_load:
* @path : path to be read from.
@@ -3326,6 +3429,7 @@ bool config_load_override(void *data)
system->info.library_name : NULL;
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename);
+ settings_t *settings = config_get_ptr();
char content_dir_name[PATH_MAX_LENGTH];
if (!string_is_empty(rarch_path_basename))
@@ -3464,15 +3568,16 @@ bool config_load_override(void *data)
retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL);
if (!config_load_file(global_get_ptr(),
- path_get(RARCH_PATH_CONFIG), config_get_ptr()))
+ path_get(RARCH_PATH_CONFIG), settings))
goto error;
/* Restore the libretro_path we're using
* since it will be overwritten by the override when reloading. */
path_set(RARCH_PATH_CORE, buf);
- runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED),
- 1, 100, false,
- NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
+ if (settings->bools.notification_show_config_override_load)
+ runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED),
+ 1, 100, false,
+ NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
/* Reset save paths. */
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL);
@@ -3550,6 +3655,8 @@ bool config_load_remap(const char *directory_input_remapping,
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename);
enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED;
+ settings_t *settings = config_get_ptr();
+ bool notification_show_remap_load = settings->bools.notification_show_remap_load;
char content_dir_name[PATH_MAX_LENGTH];
if (string_is_empty(core_name) || string_is_empty(game_name))
@@ -3650,9 +3757,11 @@ bool config_load_remap(const char *directory_input_remapping,
return false;
success:
- runloop_msg_queue_push(
- msg_hash_to_str(msg_remap_loaded), 1, 100, false,
- NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
+ if (notification_show_remap_load)
+ runloop_msg_queue_push(
+ msg_hash_to_str(msg_remap_loaded), 1, 100, false,
+ NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
+
free(content_path);
free(remap_directory);
free(core_path);
@@ -3684,6 +3793,28 @@ static void config_parse_file(global_t *global)
}
}
}
+
+static void video_driver_save_settings(config_file_t *conf)
+{
+ global_t *global = global_get_ptr();
+ if (!conf)
+ return;
+
+ config_set_int(conf, "gamma_correction",
+ global->console.screen.gamma_correction);
+ config_set_bool(conf, "flicker_filter_enable",
+ global->console.flickerfilter_enable);
+ config_set_bool(conf, "soft_filter_enable",
+ global->console.softfilter_enable);
+
+ config_set_int(conf, "soft_filter_index",
+ global->console.screen.soft_filter_index);
+ config_set_int(conf, "current_resolution_id",
+ global->console.screen.resolutions.current.id);
+ config_set_int(conf, "flicker_filter_index",
+ global->console.screen.flicker_filter_index);
+}
+
/**
* config_save_autoconf_profile:
* @path : Path that shall be written to.
@@ -3773,8 +3904,8 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
config_set_string(conf, "input_device",
input_config_get_device_name(user));
- pid_user = input_config_get_pid(user);
- vid_user = input_config_get_vid(user);
+ pid_user = input_config_get_device_pid(user);
+ vid_user = input_config_get_device_vid(user);
if (pid_user && vid_user)
{
@@ -4304,4 +4435,288 @@ bool config_replace(bool config_replace_save_on_exit, char *path)
return task_push_start_dummy_core(&content_info);
}
+
+/**
+ * input_remapping_load_file:
+ * @data : Path to config file.
+ *
+ * Loads a remap file from disk to memory.
+ *
+ * Returns: true (1) if successful, otherwise false (0).
+ **/
+bool input_remapping_load_file(void *data, const char *path)
+{
+ unsigned i, j, k;
+ config_file_t *conf = (config_file_t*)data;
+ settings_t *settings = config_get_ptr();
+ global_t *global = global_get_ptr();
+
+ if (!conf || string_is_empty(path))
+ return false;
+
+ if (!string_is_empty(global->name.remapfile))
+ input_remapping_set_defaults(true);
+ global->name.remapfile = strdup(path);
+
+ for (i = 0; i < MAX_USERS; i++)
+ {
+ char s1[64], s2[64], s3[64];
+ char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
+ char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
+ char stk_ident[8][192] = {{0}};
+
+ char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
+ "b", "y", "select", "start",
+ "up", "down", "left", "right",
+ "a", "x", "l", "r", "l2", "r2",
+ "l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
+
+ old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i];
+ old_libretro_device[i] = settings->uints.input_libretro_device[i];
+
+ s1[0] = '\0';
+ s2[0] = '\0';
+ s3[0] = '\0';
+
+ snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1);
+ snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
+ snprintf(s3, sizeof(s3), "input_player%u_stk", i + 1);
+
+ for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
+ {
+ if (j < RARCH_FIRST_CUSTOM_BIND)
+ {
+ int btn_remap = -1;
+ int key_remap = -1;
+
+ fill_pathname_join_delim(btn_ident[j], s1,
+ key_strings[j], '_', sizeof(btn_ident[j]));
+ fill_pathname_join_delim(key_ident[j], s2,
+ key_strings[j], '_', sizeof(btn_ident[j]));
+
+ if (config_get_int(conf, btn_ident[j], &btn_remap))
+ {
+ if (btn_remap == -1)
+ btn_remap = RARCH_UNMAPPED;
+
+ configuration_set_uint(settings,
+ settings->uints.input_remap_ids[i][j], btn_remap);
+ }
+
+ if (!config_get_int(conf, key_ident[j], &key_remap))
+ key_remap = RETROK_UNKNOWN;
+
+ configuration_set_uint(settings,
+ settings->uints.input_keymapper_ids[i][j], key_remap);
+ }
+ else
+ {
+ int stk_remap = -1;
+ k = j - RARCH_FIRST_CUSTOM_BIND;
+
+ fill_pathname_join_delim(stk_ident[k], s3,
+ key_strings[j], '$', sizeof(stk_ident[k]));
+
+ snprintf(stk_ident[k],
+ sizeof(stk_ident[k]),
+ "%s_%s",
+ s3,
+ key_strings[j]);
+
+ if (config_get_int(conf, stk_ident[k], &stk_remap))
+ {
+ if (stk_remap == -1)
+ stk_remap = RARCH_UNMAPPED;
+
+ configuration_set_uint(settings,
+ settings->uints.input_remap_ids[i][j], stk_remap);
+ }
+ }
+ }
+
+ snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
+ CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1);
+
+ snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
+ CONFIG_GET_INT_BASE(conf, settings, uints.input_libretro_device[i], s1);
+ }
+
+ config_file_free(conf);
+
+ return true;
+}
+
+/**
+ * input_remapping_save_file:
+ * @path : Path to remapping file (relative path).
+ *
+ * Saves remapping values to file.
+ *
+ * Returns: true (1) if successful, otherwise false (0).
+ **/
+bool input_remapping_save_file(const char *path)
+{
+ bool ret;
+ unsigned i, j, k;
+ size_t path_size = PATH_MAX_LENGTH * sizeof(char);
+ char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
+ char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
+ config_file_t *conf = NULL;
+ unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
+ settings_t *settings = config_get_ptr();
+ const char *dir_input_remapping = settings->paths.directory_input_remapping;
+
+ buf[0] = remap_file[0] = '\0';
+
+ fill_pathname_join(buf, dir_input_remapping, path, path_size);
+ fill_pathname_noext(remap_file, buf, ".rmp", path_size);
+
+ free(buf);
+
+ if (!(conf = config_file_new_from_path_to_string(remap_file)))
+ {
+ if (!(conf = config_file_new_alloc()))
+ {
+ free(remap_file);
+ return false;
+ }
+ }
+
+ for (i = 0; i < max_users; i++)
+ {
+ char s1[64], s2[64], s3[64];
+ char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
+ char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
+ char stk_ident[8][128] = {{0}};
+
+ char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
+ "b", "y", "select", "start",
+ "up", "down", "left", "right",
+ "a", "x", "l", "r", "l2", "r2",
+ "l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
+
+ s1[0] = '\0';
+ s2[0] = '\0';
+
+ snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1);
+ snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
+ snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1);
+
+ for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
+ {
+ unsigned remap_id = settings->uints.input_remap_ids[i][j];
+ unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
+
+ if (j < RARCH_FIRST_CUSTOM_BIND)
+ {
+ fill_pathname_join_delim(btn_ident[j], s1,
+ key_strings[j], '_', sizeof(btn_ident[j]));
+ fill_pathname_join_delim(key_ident[j], s2,
+ key_strings[j], '_', sizeof(btn_ident[j]));
+
+ /* only save values that have been modified */
+ if (remap_id != j && remap_id != RARCH_UNMAPPED)
+ config_set_int(conf, btn_ident[j],
+ settings->uints.input_remap_ids[i][j]);
+ else if (remap_id != j && remap_id == RARCH_UNMAPPED)
+ config_set_int(conf, btn_ident[j], -1);
+ else
+ config_unset(conf, btn_ident[j]);
+
+ if (keymap_id != RETROK_UNKNOWN)
+ config_set_int(conf, key_ident[j],
+ settings->uints.input_keymapper_ids[i][j]);
+ }
+ else
+ {
+ k = j - RARCH_FIRST_CUSTOM_BIND;
+ fill_pathname_join_delim(stk_ident[k], s3,
+ key_strings[j], '_', sizeof(stk_ident[k]));
+ if (remap_id != j && remap_id != RARCH_UNMAPPED)
+ config_set_int(conf, stk_ident[k],
+ settings->uints.input_remap_ids[i][j]);
+ else if (remap_id != j && remap_id == RARCH_UNMAPPED)
+ config_set_int(conf, stk_ident[k],
+ -1);
+ else
+ config_unset(conf, stk_ident[k]);
+ }
+ }
+
+ snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
+ config_set_int(conf, s1, input_config_get_device(i));
+ snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
+ config_set_int(conf, s1, settings->uints.input_analog_dpad_mode[i]);
+ }
+
+ ret = config_file_write(conf, remap_file, true);
+ config_file_free(conf);
+
+ free(remap_file);
+ return ret;
+}
+
+bool input_remapping_remove_file(const char *path,
+ const char *dir_input_remapping)
+{
+ bool ret = false;
+ size_t path_size = PATH_MAX_LENGTH * sizeof(char);
+ char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
+ char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
+ buf[0] = remap_file[0] = '\0';
+
+ fill_pathname_join(buf, dir_input_remapping, path, path_size);
+ fill_pathname_noext(remap_file, buf, ".rmp", path_size);
+
+ ret = filestream_delete(remap_file) == 0 ? true : false;
+ free(buf);
+ free(remap_file);
+ return ret;
+}
+
+void input_remapping_set_defaults(bool deinit)
+{
+ unsigned i, j;
+ settings_t *settings = config_get_ptr();
+ global_t *global = global_get_ptr();
+
+ if (!global)
+ return;
+
+ if (deinit)
+ {
+ if (!string_is_empty(global->name.remapfile))
+ free(global->name.remapfile);
+ global->name.remapfile = NULL;
+ rarch_ctl(RARCH_CTL_UNSET_REMAPS_CORE_ACTIVE, NULL);
+ rarch_ctl(RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE, NULL);
+ rarch_ctl(RARCH_CTL_UNSET_REMAPS_GAME_ACTIVE, NULL);
+ }
+
+ for (i = 0; i < MAX_USERS; i++)
+ {
+ for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
+ {
+ if (j < RARCH_FIRST_CUSTOM_BIND)
+ {
+ const struct retro_keybind *keybind = &input_config_binds[i][j];
+ if (keybind)
+ configuration_set_uint(settings,
+ settings->uints.input_remap_ids[i][j], keybind->id);
+ configuration_set_uint(settings,
+ settings->uints.input_keymapper_ids[i][j], RETROK_UNKNOWN);
+ }
+ else
+ configuration_set_uint(settings,
+ settings->uints.input_remap_ids[i][j], j);
+ }
+
+ if (old_analog_dpad_mode[i])
+ configuration_set_uint(settings,
+ settings->uints.input_analog_dpad_mode[i], old_analog_dpad_mode[i]);
+ if (old_libretro_device[i])
+ configuration_set_uint(settings,
+ settings->uints.input_libretro_device[i], old_libretro_device[i]);
+ }
+}
#endif
diff --git a/configuration.h b/configuration.h
index c906a79b65..16cf0ade4d 100644
--- a/configuration.h
+++ b/configuration.h
@@ -158,6 +158,13 @@ typedef struct settings
/* Menu */
bool filter_by_current_core;
bool menu_enable_widgets;
+ bool menu_show_load_content_animation;
+ bool notification_show_autoconfig;
+ bool notification_show_cheats_applied;
+ bool notification_show_remap_load;
+ bool notification_show_config_override_load;
+ bool notification_show_set_initial_disk;
+ bool notification_show_fast_forward;
bool menu_widget_scale_auto;
bool menu_show_start_screen;
bool menu_pause_libretro;
@@ -306,10 +313,14 @@ typedef struct settings
bool cheevos_verbose_enable;
bool cheevos_auto_screenshot;
bool cheevos_start_active;
+ bool cheevos_unlock_sound_enable;
/* Camera */
bool camera_allow;
+ /* Bluetooth */
+ bool bluetooth_allow;
+
/* WiFi */
bool wifi_allow;
@@ -356,6 +367,9 @@ typedef struct settings
bool network_remote_enable_user[MAX_USERS];
bool load_dummy_on_core_shutdown;
bool check_firmware_before_loading;
+#ifndef HAVE_DYNAMIC
+ bool always_reload_core_on_run_content;
+#endif
bool game_specific_options;
bool auto_overrides_enable;
@@ -639,6 +653,7 @@ typedef struct settings
char video_driver[32];
char record_driver[32];
char camera_driver[32];
+ char bluetooth_driver[32];
char wifi_driver[32];
char led_driver[32];
char location_driver[32];
@@ -759,6 +774,15 @@ typedef struct settings
**/
const char *config_get_default_camera(void);
+/**
+ * config_get_default_bluetooth:
+ *
+ * Gets default bluetooth driver.
+ *
+ * Returns: Default bluetooth driver.
+ **/
+const char *config_get_default_bluetooth(void);
+
/**
* config_get_default_wifi:
*
diff --git a/content.h b/content.h
index e2b8ee6ed9..fb979003b6 100644
--- a/content.h
+++ b/content.h
@@ -51,8 +51,8 @@ bool content_load_state(const char* path, bool load_to_backup_buffer, bool autol
/* Save a state from memory to disk. */
bool content_save_state(const char *path, bool save_to_disk, bool autosave);
-/* Returns true if a save state task is in progress */
-bool content_save_state_in_progress(void);
+/* Waits for any in-progress save state tasks to finish */
+void content_wait_for_save_state_task(void);
/* Copy a save state. */
bool content_rename_state(const char *origin, const char *dest);
diff --git a/core.h b/core.h
index 35d7961ca0..470ca98b5f 100644
--- a/core.h
+++ b/core.h
@@ -156,7 +156,9 @@ typedef struct retro_callbacks
bool core_set_default_callbacks(struct retro_callbacks *cbs);
+#ifdef HAVE_REWIND
bool core_set_rewind_callbacks(void);
+#endif
#ifdef HAVE_NETWORKING
bool core_set_netplay_callbacks(void);
diff --git a/core_backup.c b/core_backup.c
index 71097ffb66..776d2c2b66 100644
--- a/core_backup.c
+++ b/core_backup.c
@@ -536,23 +536,27 @@ core_backup_list_t *core_backup_list_init(
dir_list_sort(dir_list, true);
/* Create core backup list */
- backup_list = (core_backup_list_t*)calloc(1, sizeof(*backup_list));
+ backup_list = (core_backup_list_t*)malloc(sizeof(*backup_list));
if (!backup_list)
goto error;
+ backup_list->entries = NULL;
+ backup_list->capacity = 0;
+ backup_list->size = 0;
+
/* Create entries array
* (Note: Set this to the full size of the directory
* list - this may be larger than we need, but saves
* many inefficiencies later) */
- entries = (core_backup_list_entry_t*)calloc(dir_list->size, sizeof(*entries));
+ entries = (core_backup_list_entry_t*)
+ calloc(dir_list->size, sizeof(*entries));
if (!entries)
goto error;
backup_list->entries = entries;
backup_list->capacity = dir_list->size;
- backup_list->size = 0;
/* Loop over backup files and parse file names */
for (i = 0; i < dir_list->size; i++)
diff --git a/core_info.c b/core_info.c
index 63a2fd167d..252f6972da 100644
--- a/core_info.c
+++ b/core_info.c
@@ -114,31 +114,25 @@ static void core_info_list_resolve_all_firmware(
char path_key[64];
char desc_key[64];
char opt_key[64];
+ struct config_entry_list
+ *entry = NULL;
bool tmp_bool = false;
- char *tmp = NULL;
path_key[0] = desc_key[0] = opt_key[0] = '\0';
snprintf(path_key, sizeof(path_key), "firmware%u_path", c);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
- if (config_get_string(config, path_key, &tmp))
- {
- if (!string_is_empty(tmp))
- info->firmware[c].path = strdup(tmp);
- free(tmp);
- tmp = NULL;
- }
- if (config_get_string(config, desc_key, &tmp))
- {
- if (!string_is_empty(tmp))
- info->firmware[c].desc = strdup(tmp);
- free(tmp);
- tmp = NULL;
- }
- if (tmp)
- free(tmp);
- tmp = NULL;
+ entry = config_get_entry(config, path_key, NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ info->firmware[c].path = strdup(entry->value);
+
+ entry = config_get_entry(config, desc_key, NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ info->firmware[c].desc = strdup(entry->value);
+
if (config_get_bool(config, opt_key , &tmp_bool))
info->firmware[c].optional = tmp_bool;
}
@@ -304,14 +298,20 @@ static core_info_list_t *core_info_list_new(const char *path,
if (!contents)
return NULL;
- core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
+ core_info_list = (core_info_list_t*)malloc(sizeof(*core_info_list));
if (!core_info_list)
{
string_list_free(contents);
return NULL;
}
- core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
+ core_info_list->list = NULL;
+ core_info_list->count = 0;
+ core_info_list->all_ext = NULL;
+
+ core_info = (core_info_t*)
+ calloc(contents->size, sizeof(*core_info));
+
if (!core_info)
{
core_info_list_free(core_info_list);
@@ -319,8 +319,8 @@ static core_info_list_t *core_info_list_new(const char *path,
return NULL;
}
- core_info_list->list = core_info;
- core_info_list->count = contents->size;
+ core_info_list->list = core_info;
+ core_info_list->count = contents->size;
for (i = 0; i < contents->size; i++)
{
@@ -330,188 +330,130 @@ static core_info_list_t *core_info_list_new(const char *path,
if (conf)
{
- char *tmp = NULL;
+ bool tmp_bool = false;
+ unsigned tmp_uint = 0;
+ struct config_entry_list
+ *entry = config_get_entry(conf, "display_name", NULL);
- if (config_get_string(conf, "display_name", &tmp))
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].display_name = strdup(entry->value);
+
+ entry = config_get_entry(conf, "display_version", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].display_version = strdup(entry->value);
+
+ entry = config_get_entry(conf, "corename", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].core_name = strdup(entry->value);
+
+ entry = config_get_entry(conf, "systemname", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].systemname = strdup(entry->value);
+
+ entry = config_get_entry(conf, "systemid", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].system_id = strdup(entry->value);
+
+ entry = config_get_entry(conf, "manufacturer", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].system_manufacturer = strdup(entry->value);
+
+ config_get_uint(conf, "firmware_count", &tmp_uint);
+ core_info[i].firmware_count = tmp_uint;
+
+ entry = config_get_entry(conf, "supported_extensions", NULL);
+
+ if (entry && !string_is_empty(entry->value))
{
- if (!string_is_empty(tmp))
- core_info[i].display_name = strdup(tmp);
- free(tmp);
- tmp = NULL;
- }
- if (config_get_string(conf, "display_version", &tmp))
- {
- if (!string_is_empty(tmp))
- core_info[i].display_version = strdup(tmp);
- free(tmp);
- tmp = NULL;
- }
- if (config_get_string(conf, "corename", &tmp))
- {
- if (!string_is_empty(tmp))
- core_info[i].core_name = strdup(tmp);
- free(tmp);
- tmp = NULL;
+ core_info[i].supported_extensions = strdup(entry->value);
+ core_info[i].supported_extensions_list =
+ string_split(core_info[i].supported_extensions, "|");
}
- if (config_get_string(conf, "systemname", &tmp))
+ entry = config_get_entry(conf, "authors", NULL);
+
+ if (entry && !string_is_empty(entry->value))
{
- if (!string_is_empty(tmp))
- core_info[i].systemname = strdup(tmp);
- free(tmp);
- tmp = NULL;
+ core_info[i].authors = strdup(entry->value);
+ core_info[i].authors_list =
+ string_split(core_info[i].authors, "|");
}
- if (config_get_string(conf, "systemid", &tmp))
+ entry = config_get_entry(conf, "permissions", NULL);
+
+ if (entry && !string_is_empty(entry->value))
{
- if (!string_is_empty(tmp))
- core_info[i].system_id = strdup(tmp);
- free(tmp);
- tmp = NULL;
+ core_info[i].permissions = strdup(entry->value);
+ core_info[i].permissions_list =
+ string_split(core_info[i].permissions, "|");
}
- if (config_get_string(conf, "manufacturer", &tmp))
+ entry = config_get_entry(conf, "license", NULL);
+
+ if (entry && !string_is_empty(entry->value))
{
- if (!string_is_empty(tmp))
- core_info[i].system_manufacturer = strdup(tmp);
- free(tmp);
- tmp = NULL;
+ core_info[i].licenses = strdup(entry->value);
+ core_info[i].licenses_list =
+ string_split(core_info[i].licenses, "|");
}
+ entry = config_get_entry(conf, "categories", NULL);
+
+ if (entry && !string_is_empty(entry->value))
{
- unsigned count = 0;
- config_get_uint(conf, "firmware_count", &count);
- core_info[i].firmware_count = count;
+ core_info[i].categories = strdup(entry->value);
+ core_info[i].categories_list =
+ string_split(core_info[i].categories, "|");
}
- if (config_get_string(conf, "supported_extensions", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].supported_extensions = strdup(tmp);
- core_info[i].supported_extensions_list =
- string_split(core_info[i].supported_extensions, "|");
- }
+ entry = config_get_entry(conf, "database", NULL);
- free(tmp);
- tmp = NULL;
+ if (entry && !string_is_empty(entry->value))
+ {
+ core_info[i].databases = strdup(entry->value);
+ core_info[i].databases_list =
+ string_split(core_info[i].databases, "|");
}
- if (config_get_string(conf, "authors", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].authors = strdup(tmp);
- core_info[i].authors_list =
- string_split(core_info[i].authors, "|");
- }
+ entry = config_get_entry(conf, "notes", NULL);
- free(tmp);
- tmp = NULL;
+ if (entry && !string_is_empty(entry->value))
+ {
+ core_info[i].notes = strdup(entry->value);
+ core_info[i].note_list =
+ string_split(core_info[i].notes, "|");
}
- if (config_get_string(conf, "permissions", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].permissions = strdup(tmp);
- core_info[i].permissions_list =
- string_split(core_info[i].permissions, "|");
- }
+ entry = config_get_entry(conf, "required_hw_api", NULL);
- free(tmp);
- tmp = NULL;
+ if (entry && !string_is_empty(entry->value))
+ {
+ core_info[i].required_hw_api = strdup(entry->value);
+ core_info[i].required_hw_api_list =
+ string_split(core_info[i].required_hw_api, "|");
}
- if (config_get_string(conf, "license", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].licenses = strdup(tmp);
- core_info[i].licenses_list =
- string_split(core_info[i].licenses, "|");
- }
+ entry = config_get_entry(conf, "description", NULL);
- free(tmp);
- tmp = NULL;
- }
+ if (entry && !string_is_empty(entry->value))
+ core_info[i].description = strdup(entry->value);
- if (config_get_string(conf, "categories", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].categories = strdup(tmp);
- core_info[i].categories_list =
- string_split(core_info[i].categories, "|");
- }
+ if (config_get_bool(conf, "supports_no_game",
+ &tmp_bool))
+ core_info[i].supports_no_game = tmp_bool;
- free(tmp);
- tmp = NULL;
- }
+ if (config_get_bool(conf, "database_match_archive_member",
+ &tmp_bool))
+ core_info[i].database_match_archive_member = tmp_bool;
- if (config_get_string(conf, "database", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].databases = strdup(tmp);
- core_info[i].databases_list =
- string_split(core_info[i].databases, "|");
- }
-
- free(tmp);
- tmp = NULL;
- }
-
- if (config_get_string(conf, "notes", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].notes = strdup(tmp);
- core_info[i].note_list = string_split(core_info[i].notes, "|");
- }
-
- free(tmp);
- tmp = NULL;
- }
-
- if (config_get_string(conf, "required_hw_api", &tmp))
- {
- if (!string_is_empty(tmp))
- {
- core_info[i].required_hw_api = strdup(tmp);
- core_info[i].required_hw_api_list = string_split(core_info[i].required_hw_api, "|");
- }
-
- free(tmp);
- tmp = NULL;
- }
-
- if (config_get_string(conf, "description", &tmp))
- {
- if (!string_is_empty(tmp))
- core_info[i].description = strdup(tmp);
- free(tmp);
- tmp = NULL;
- }
-
- if (tmp)
- free(tmp);
- tmp = NULL;
-
- {
- bool tmp_bool = false;
- if (config_get_bool(conf, "supports_no_game",
- &tmp_bool))
- core_info[i].supports_no_game = tmp_bool;
-
- if (config_get_bool(conf, "database_match_archive_member",
- &tmp_bool))
- core_info[i].database_match_archive_member = tmp_bool;
-
- if (config_get_bool(conf, "is_experimental",
- &tmp_bool))
- core_info[i].is_experimental = tmp_bool;
- }
+ if (config_get_bool(conf, "is_experimental",
+ &tmp_bool))
+ core_info[i].is_experimental = tmp_bool;
core_info[i].config_data = conf;
}
@@ -735,11 +677,47 @@ void core_info_free_current_core(core_info_state_t *p_coreinfo)
bool core_info_init_current_core(void)
{
- core_info_state_t *p_coreinfo = coreinfo_get_ptr();
- core_info_t *current = (core_info_t*)calloc(1, sizeof(*current));
+ core_info_state_t *p_coreinfo = coreinfo_get_ptr();
+ core_info_t *current = (core_info_t*)
+ malloc(sizeof(*current));
if (!current)
return false;
- p_coreinfo->current = current;
+ current->supports_no_game = false;
+ current->database_match_archive_member = false;
+ current->is_experimental = false;
+ current->is_locked = false;
+ current->firmware_count = 0;
+ current->path = NULL;
+ current->config_data = NULL;
+ current->display_name = NULL;
+ current->display_version = NULL;
+ current->core_name = NULL;
+ current->system_manufacturer = NULL;
+ current->systemname = NULL;
+ current->system_id = NULL;
+ current->supported_extensions = NULL;
+ current->authors = NULL;
+ current->permissions = NULL;
+ current->licenses = NULL;
+ current->categories = NULL;
+ current->databases = NULL;
+ current->notes = NULL;
+ current->required_hw_api = NULL;
+ current->description = NULL;
+ current->categories_list = NULL;
+ current->databases_list = NULL;
+ current->note_list = NULL;
+ current->supported_extensions_list = NULL;
+ current->authors_list = NULL;
+ current->permissions_list = NULL;
+ current->licenses_list = NULL;
+ current->required_hw_api_list = NULL;
+ current->firmware = NULL;
+ current->core_file_id.str = NULL;
+ current->core_file_id.len = 0;
+ current->userdata = NULL;
+
+ p_coreinfo->current = current;
return true;
}
@@ -912,8 +890,9 @@ void core_info_get_name(const char *path, char *s, size_t len,
for (i = 0; i < contents->size; i++)
{
+ struct config_entry_list
+ *entry = NULL;
config_file_t *conf = NULL;
- char *new_core_name = NULL;
const char *current_path = contents->elems[i].data;
if (!string_is_equal(path_basename(current_path), core_path_basename))
@@ -925,13 +904,13 @@ void core_info_get_name(const char *path, char *s, size_t len,
if (!conf)
continue;
- if (config_get_string(conf, get_display_name
- ? "display_name" : "corename",
- &new_core_name))
- {
- strlcpy(s, new_core_name, len);
- free(new_core_name);
- }
+ if (get_display_name)
+ entry = config_get_entry(conf, "display_name", NULL);
+ else
+ entry = config_get_entry(conf, "corename", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ strlcpy(s, entry->value, len);
config_file_free(conf);
break;
@@ -1077,17 +1056,17 @@ bool core_info_list_get_display_name(core_info_list_t *core_info_list,
bool core_info_get_display_name(const char *path, char *s, size_t len)
{
- char *tmp = NULL;
+ struct config_entry_list
+ *entry = NULL;
config_file_t *conf = config_file_new_from_path_to_string(path);
if (!conf)
return false;
- if (config_get_string(conf, "display_name", &tmp))
- {
- strlcpy(s, tmp, len);
- free(tmp);
- }
+ entry = config_get_entry(conf, "display_name", NULL);
+
+ if (entry && !string_is_empty(entry->value))
+ strlcpy(s, entry->value, len);
config_file_free(conf);
return true;
@@ -1100,7 +1079,8 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
* Returns NULL if 'path' is invalid. */
core_updater_info_t *core_info_get_core_updater_info(const char *path)
{
- char *tmp_str = NULL;
+ struct config_entry_list
+ *entry = NULL;
bool tmp_bool = false;
core_updater_info_t *info = NULL;
config_file_t *conf = NULL;
@@ -1115,53 +1095,39 @@ core_updater_info_t *core_info_get_core_updater_info(const char *path)
return NULL;
/* Create info struct */
- info = (core_updater_info_t*)calloc(1, sizeof(*info));
+ info = (core_updater_info_t*)malloc(sizeof(*info));
if (!info)
return NULL;
+ info->is_experimental = false;
+ info->display_name = NULL;
+ info->description = NULL;
+ info->licenses = NULL;
+
/* Fetch required parameters */
/* > is_experimental */
- info->is_experimental = false;
if (config_get_bool(conf, "is_experimental", &tmp_bool))
- info->is_experimental = tmp_bool;
+ info->is_experimental = tmp_bool;
/* > display_name */
- info->display_name = NULL;
- if (config_get_string(conf, "display_name", &tmp_str))
- {
- if (!string_is_empty(tmp_str))
- info->display_name = tmp_str;
- else
- free(tmp_str);
+ entry = config_get_entry(conf, "display_name", NULL);
- tmp_str = NULL;
- }
+ if (entry && !string_is_empty(entry->value))
+ info->display_name = strdup(entry->value);
/* > description */
- info->description = NULL;
- if (config_get_string(conf, "description", &tmp_str))
- {
- if (!string_is_empty(tmp_str))
- info->description = tmp_str;
- else
- free(tmp_str);
+ entry = config_get_entry(conf, "description", NULL);
- tmp_str = NULL;
- }
+ if (entry && !string_is_empty(entry->value))
+ info->description = strdup(entry->value);
/* > licenses */
- info->licenses = NULL;
- if (config_get_string(conf, "license", &tmp_str))
- {
- if (!string_is_empty(tmp_str))
- info->licenses = tmp_str;
- else
- free(tmp_str);
+ entry = config_get_entry(conf, "license", NULL);
- tmp_str = NULL;
- }
+ if (entry && !string_is_empty(entry->value))
+ info->licenses = strdup(entry->value);
/* Clean up */
config_file_free(conf);
diff --git a/core_updater_list.c b/core_updater_list.c
index 3bd973cbb0..60f7457b02 100644
--- a/core_updater_list.c
+++ b/core_updater_list.c
@@ -109,7 +109,7 @@ core_updater_list_t *core_updater_list_init(size_t max_size)
return NULL;
/* Create core updater list */
- core_list = (core_updater_list_t*)calloc(1, sizeof(*core_list));
+ core_list = (core_updater_list_t*)malloc(sizeof(*core_list));
if (!core_list)
return NULL;
diff --git a/cores/libretro-ffmpeg/ffmpeg_core.c b/cores/libretro-ffmpeg/ffmpeg_core.c
index c5f48592eb..c4c2d5e232 100644
--- a/cores/libretro-ffmpeg/ffmpeg_core.c
+++ b/cores/libretro-ffmpeg/ffmpeg_core.c
@@ -67,6 +67,8 @@ extern "C" {
s ##_version() & 0xFF);
static bool reset_triggered;
+static bool libretro_supports_bitmasks = false;
+
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
va_list va;
@@ -193,11 +195,20 @@ static struct
{
unsigned width;
unsigned height;
-
+
double interpolate_fps;
unsigned sample_rate;
float aspect;
+
+ struct
+ {
+ double time;
+ unsigned hours;
+ unsigned minutes;
+ unsigned seconds;
+ } duration;
+
} media;
#ifdef HAVE_SSA
@@ -231,10 +242,15 @@ void CORE_PREFIX(retro_init)(void)
reset_triggered = false;
av_register_all();
+
+ if (CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
+ libretro_supports_bitmasks = true;
}
void CORE_PREFIX(retro_deinit)(void)
-{}
+{
+ libretro_supports_bitmasks = false;
+}
unsigned CORE_PREFIX(retro_api_version)(void)
{
@@ -473,7 +489,13 @@ static void check_variables(bool firststart)
static void seek_frame(int seek_frames)
{
char msg[256];
- struct retro_message msg_obj = {0};
+ struct retro_message_ext msg_obj = {0};
+ unsigned seek_hours = 0;
+ unsigned seek_minutes = 0;
+ unsigned seek_seconds = 0;
+ int8_t seek_progress = -1;
+
+ msg[0] = '\0';
if ((seek_frames < 0 && (unsigned)-seek_frames > frame_cnt) || reset_triggered)
frame_cnt = 0;
@@ -484,10 +506,34 @@ static void seek_frame(int seek_frames)
do_seek = true;
seek_time = frame_cnt / media.interpolate_fps;
- snprintf(msg, sizeof(msg), "Seek: %u s.", (unsigned)seek_time);
- msg_obj.msg = msg;
- msg_obj.frames = 180;
- CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
+ /* Convert seek time to a printable format */
+ seek_seconds = (unsigned)seek_time;
+ seek_minutes = seek_seconds / 60;
+ seek_seconds %= 60;
+ seek_hours = seek_minutes / 60;
+ seek_minutes %= 60;
+
+ snprintf(msg, sizeof(msg), "%02d:%02d:%02d / %02d:%02d:%02d",
+ seek_hours, seek_minutes, seek_seconds,
+ media.duration.hours, media.duration.minutes, media.duration.seconds);
+
+ /* Get current progress */
+ if (media.duration.time > 0.0)
+ {
+ seek_progress = (int8_t)((100.0 * seek_time / media.duration.time) + 0.5);
+ seek_progress = (seek_progress < -1) ? -1 : seek_progress;
+ seek_progress = (seek_progress > 100) ? 100 : seek_progress;
+ }
+
+ /* Send message to frontend */
+ msg_obj.msg = msg;
+ msg_obj.duration = 2000;
+ msg_obj.priority = 3;
+ msg_obj.level = RETRO_LOG_INFO;
+ msg_obj.target = RETRO_MESSAGE_TARGET_OSD;
+ msg_obj.type = RETRO_MESSAGE_TYPE_PROGRESS;
+ msg_obj.progress = seek_progress;
+ CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
if (seek_frames < 0)
{
@@ -522,6 +568,7 @@ void CORE_PREFIX(retro_run)(void)
double min_pts;
int16_t audio_buffer[2048];
bool left, right, up, down, l, r;
+ int16_t ret = 0;
size_t to_read_frames = 0;
int seek_frames = 0;
bool updated = false;
@@ -552,20 +599,28 @@ void CORE_PREFIX(retro_run)(void)
CORE_PREFIX(input_poll_cb)();
- left = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_LEFT);
- right = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_RIGHT);
- up = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_UP) ||
- CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP);
- down = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_DOWN) ||
- CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN);
- l = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_L);
- r = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0,
- RETRO_DEVICE_ID_JOYPAD_R);
+ if (libretro_supports_bitmasks)
+ ret = CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD,
+ 0, RETRO_DEVICE_ID_JOYPAD_MASK);
+ else
+ {
+ unsigned i;
+ for (i = RETRO_DEVICE_ID_JOYPAD_B; i <= RETRO_DEVICE_ID_JOYPAD_R; i++)
+ if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_JOYPAD, 0, i))
+ ret |= (1 << i);
+ }
+
+ if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP))
+ ret |= (1 << RETRO_DEVICE_ID_JOYPAD_UP);
+ if (CORE_PREFIX(input_state_cb)(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN))
+ ret |= (1 << RETRO_DEVICE_ID_JOYPAD_DOWN);
+
+ left = ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT);
+ right = ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT);
+ up = ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP);
+ down = ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN);
+ l = ret & (1 << RETRO_DEVICE_ID_JOYPAD_L);
+ r = ret & (1 << RETRO_DEVICE_ID_JOYPAD_R);
if (left && !last_left)
seek_frames -= 10 * media.interpolate_fps;
@@ -579,7 +634,9 @@ void CORE_PREFIX(retro_run)(void)
if (l && !last_l && audio_streams_num > 0)
{
char msg[256];
- struct retro_message msg_obj = {0};
+ struct retro_message_ext msg_obj = {0};
+
+ msg[0] = '\0';
slock_lock(decode_thread_lock);
audio_streams_ptr = (audio_streams_ptr + 1) % audio_streams_num;
@@ -587,23 +644,36 @@ void CORE_PREFIX(retro_run)(void)
snprintf(msg, sizeof(msg), "Audio Track #%d.", audio_streams_ptr);
- msg_obj.msg = msg;
- msg_obj.frames = 180;
- CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
+ msg_obj.msg = msg;
+ msg_obj.duration = 3000;
+ msg_obj.priority = 1;
+ msg_obj.level = RETRO_LOG_INFO;
+ msg_obj.target = RETRO_MESSAGE_TARGET_ALL;
+ msg_obj.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
+ msg_obj.progress = -1;
+ CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
}
else if (r && !last_r && subtitle_streams_num > 0)
{
char msg[256];
- struct retro_message msg_obj = {0};
+ struct retro_message_ext msg_obj = {0};
+
+ msg[0] = '\0';
slock_lock(decode_thread_lock);
subtitle_streams_ptr = (subtitle_streams_ptr + 1) % subtitle_streams_num;
slock_unlock(decode_thread_lock);
snprintf(msg, sizeof(msg), "Subtitle Track #%d.", subtitle_streams_ptr);
- msg_obj.msg = msg;
- msg_obj.frames = 180;
- CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg_obj);
+
+ msg_obj.msg = msg;
+ msg_obj.duration = 3000;
+ msg_obj.priority = 1;
+ msg_obj.level = RETRO_LOG_INFO;
+ msg_obj.target = RETRO_MESSAGE_TARGET_ALL;
+ msg_obj.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
+ msg_obj.progress = -1;
+ CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg_obj);
}
last_left = left;
@@ -649,7 +719,7 @@ void CORE_PREFIX(retro_run)(void)
to_read_bytes = to_read_frames * sizeof(int16_t) * 2;
slock_lock(fifo_lock);
- while (!decode_thread_dead && fifo_read_avail(audio_decode_fifo) < to_read_bytes)
+ while (!decode_thread_dead && FIFO_READ_AVAIL(audio_decode_fifo) < to_read_bytes)
{
main_sleeping = true;
scond_signal(fifo_decode_cond);
@@ -658,7 +728,7 @@ void CORE_PREFIX(retro_run)(void)
}
reading_pts = decode_last_audio_time -
- (double)fifo_read_avail(audio_decode_fifo) / (media.sample_rate * sizeof(int16_t) * 2);
+ (double)FIFO_READ_AVAIL(audio_decode_fifo) / (media.sample_rate * sizeof(int16_t) * 2);
expected_pts = (double)audio_frames / media.sample_rate;
old_pts_bias = pts_bias;
pts_bias = reading_pts - expected_pts;
@@ -707,15 +777,17 @@ void CORE_PREFIX(retro_run)(void)
if (!decode_thread_dead)
{
unsigned y;
- const uint8_t *src;
int stride, width;
- uint32_t *data = video_frame_temp_buffer;
-
+ const uint8_t *src = NULL;
video_decoder_context_t *ctx = NULL;
+ uint32_t *data = NULL;
+
video_buffer_get_finished_slot(video_buffer, &ctx);
pts = ctx->pts;
-#ifndef HAVE_OPENGLES
+#ifdef HAVE_OPENGLES
+ data = video_frame_temp_buffer;
+#else
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, frames[1].pbo);
#ifdef __MACH__
data = (uint32_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
@@ -1190,6 +1262,28 @@ static bool init_media_info(void)
av_q2d(vctx->sample_aspect_ratio) / vctx->height;
}
+ if (fctx)
+ {
+ if (fctx->duration != AV_NOPTS_VALUE)
+ {
+ int64_t duration = fctx->duration + (fctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
+ media.duration.time = (double)(duration / AV_TIME_BASE);
+ media.duration.seconds = (unsigned)media.duration.time;
+ media.duration.minutes = media.duration.seconds / 60;
+ media.duration.seconds %= 60;
+ media.duration.hours = media.duration.minutes / 60;
+ media.duration.minutes %= 60;
+ }
+ else
+ {
+ media.duration.time = 0.0;
+ media.duration.hours = 0;
+ media.duration.minutes = 0;
+ media.duration.seconds = 0;
+ log_cb(RETRO_LOG_ERROR, "[FFMPEG] Could not determine media duration\n");
+ }
+ }
+
#ifdef HAVE_SSA
if (sctx[0])
{
@@ -1496,7 +1590,8 @@ static int16_t *decode_audio(AVCodecContext *ctx, AVPacket *pkt,
pts = frame->best_effort_timestamp;
slock_lock(fifo_lock);
- while (!decode_thread_dead && fifo_write_avail(audio_decode_fifo) < required_buffer)
+ while (!decode_thread_dead &&
+ FIFO_WRITE_AVAIL(audio_decode_fifo) < required_buffer)
{
if (!main_sleeping)
scond_wait(fifo_decode_cond, fifo_lock);
diff --git a/cores/libretro-ffmpeg/packet_buffer.c b/cores/libretro-ffmpeg/packet_buffer.c
index 5b9fd7a06b..85fa8127a4 100644
--- a/cores/libretro-ffmpeg/packet_buffer.c
+++ b/cores/libretro-ffmpeg/packet_buffer.c
@@ -1,10 +1,12 @@
#include "packet_buffer.h"
-struct AVPacketNode {
+struct AVPacketNode
+{
AVPacket *data;
struct AVPacketNode *next;
struct AVPacketNode *previous;
};
+
typedef struct AVPacketNode AVPacketNode_t;
struct packet_buffer
@@ -14,7 +16,7 @@ struct packet_buffer
size_t size;
};
-packet_buffer_t *packet_buffer_create()
+packet_buffer_t *packet_buffer_create(void)
{
packet_buffer_t *b = (packet_buffer_t*)malloc(sizeof(packet_buffer_t));
if (!b)
diff --git a/cores/libretro-ffmpeg/packet_buffer.h b/cores/libretro-ffmpeg/packet_buffer.h
index 2cbf9cc656..f268be97f4 100644
--- a/cores/libretro-ffmpeg/packet_buffer.h
+++ b/cores/libretro-ffmpeg/packet_buffer.h
@@ -6,7 +6,13 @@
#include
#include
+#ifdef __cplusplus
+extern "C" {
+#endif
#include
+#ifdef __cplusplus
+}
+#endif
#include
diff --git a/cores/libretro-ffmpeg/video_buffer.c b/cores/libretro-ffmpeg/video_buffer.c
index d59354ae09..603a5e89ad 100644
--- a/cores/libretro-ffmpeg/video_buffer.c
+++ b/cores/libretro-ffmpeg/video_buffer.c
@@ -1,4 +1,10 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
#include
+#ifdef __cplusplus
+}
+#endif
#include
@@ -6,7 +12,7 @@
enum kbStatus
{
- KB_OPEN,
+ KB_OPEN = 0,
KB_IN_PROGRESS,
KB_FINISHED
};
@@ -23,32 +29,41 @@ struct video_buffer
int64_t tail;
};
-video_buffer_t *video_buffer_create(size_t capacity, int frame_size, int width, int height)
+video_buffer_t *video_buffer_create(
+ size_t capacity, int frame_size, int width, int height)
{
+ unsigned i;
video_buffer_t *b = (video_buffer_t*)malloc(sizeof(video_buffer_t));
if (!b)
return NULL;
- memset(b, 0, sizeof(video_buffer_t));
- b->capacity = capacity;
+ b->buffer = NULL;
+ b->capacity = capacity;
+ b->lock = NULL;
+ b->open_cond = NULL;
+ b->finished_cond = NULL;
+ b->head = 0;
+ b->tail = 0;
+ b->status = (enum kbStatus*)malloc(sizeof(enum kbStatus) * capacity);
- b->status = (enum kbStatus*)malloc(sizeof(enum kbStatus) * capacity);
if (!b->status)
goto fail;
- for (int i = 0; i < capacity; i++)
- b->status[i] = KB_OPEN;
- b->lock = slock_new();
- b->open_cond = scond_new();
+ for (i = 0; i < capacity; i++)
+ b->status[i] = KB_OPEN;
+
+ b->lock = slock_new();
+ b->open_cond = scond_new();
b->finished_cond = scond_new();
if (!b->lock || !b->open_cond || !b->finished_cond)
goto fail;
- b->buffer = (video_decoder_context_t*)malloc(sizeof(video_decoder_context_t) * capacity);
+ b->buffer = (video_decoder_context_t*)
+ malloc(sizeof(video_decoder_context_t) * capacity);
if (!b->buffer)
goto fail;
- for (int i = 0; i < capacity; i++)
+ for (i = 0; i < (unsigned)capacity; i++)
{
b->buffer[i].index = i;
b->buffer[i].pts = 0;
@@ -60,15 +75,17 @@ video_buffer_t *video_buffer_create(size_t capacity, int frame_size, int width,
b->buffer[i].target = av_frame_alloc();
b->buffer[i].frame_buf = (uint8_t*)av_malloc(frame_size);
- avpicture_fill((AVPicture*)b->buffer[i].target, (const uint8_t*)b->buffer[i].frame_buf,
+ avpicture_fill((AVPicture*)
+ b->buffer[i].target,
+ (const uint8_t*)b->buffer[i].frame_buf,
PIX_FMT_RGB32, width, height);
- if (!b->buffer[i].sws ||
- !b->buffer[i].source ||
+ if (!b->buffer[i].sws ||
+ !b->buffer[i].source ||
#if LIBAVUTIL_VERSION_MAJOR > 55
!b->buffer[i].hw_source ||
#endif
- !b->buffer[i].target ||
+ !b->buffer[i].target ||
!b->buffer[i].frame_buf)
goto fail;
}
@@ -81,6 +98,7 @@ fail:
void video_buffer_destroy(video_buffer_t *video_buffer)
{
+ unsigned i;
if (!video_buffer)
return;
@@ -89,22 +107,25 @@ void video_buffer_destroy(video_buffer_t *video_buffer)
scond_free(video_buffer->finished_cond);
free(video_buffer->status);
if (video_buffer->buffer)
- for (int i = 0; i < video_buffer->capacity; i++)
+ {
+ for (i = 0; i < video_buffer->capacity; i++)
{
- #if LIBAVUTIL_VERSION_MAJOR > 55
+#if LIBAVUTIL_VERSION_MAJOR > 55
av_frame_free(&video_buffer->buffer[i].hw_source);
- #endif
+#endif
av_frame_free(&video_buffer->buffer[i].source);
av_frame_free(&video_buffer->buffer[i].target);
av_freep(&video_buffer->buffer[i].frame_buf);
sws_freeContext(video_buffer->buffer[i].sws);
}
+ }
free(video_buffer->buffer);
free(video_buffer);
}
void video_buffer_clear(video_buffer_t *video_buffer)
{
+ unsigned i;
if (!video_buffer)
return;
@@ -115,13 +136,14 @@ void video_buffer_clear(video_buffer_t *video_buffer)
video_buffer->head = 0;
video_buffer->tail = 0;
- for (int i = 0; i < video_buffer->capacity; i++)
+ for (i = 0; i < video_buffer->capacity; i++)
video_buffer->status[i] = KB_OPEN;
slock_unlock(video_buffer->lock);
}
-void video_buffer_get_open_slot(video_buffer_t *video_buffer, video_decoder_context_t **context)
+void video_buffer_get_open_slot(
+ video_buffer_t *video_buffer, video_decoder_context_t **context)
{
slock_lock(video_buffer->lock);
@@ -136,7 +158,8 @@ void video_buffer_get_open_slot(video_buffer_t *video_buffer, video_decoder_cont
slock_unlock(video_buffer->lock);
}
-void video_buffer_return_open_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
+void video_buffer_return_open_slot(
+ video_buffer_t *video_buffer, video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);
@@ -150,7 +173,9 @@ void video_buffer_return_open_slot(video_buffer_t *video_buffer, video_decoder_c
slock_unlock(video_buffer->lock);
}
-void video_buffer_open_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
+void video_buffer_open_slot(
+ video_buffer_t *video_buffer,
+ video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);
@@ -165,7 +190,9 @@ void video_buffer_open_slot(video_buffer_t *video_buffer, video_decoder_context_
slock_unlock(video_buffer->lock);
}
-void video_buffer_get_finished_slot(video_buffer_t *video_buffer, video_decoder_context_t **context)
+void video_buffer_get_finished_slot(
+ video_buffer_t *video_buffer,
+ video_decoder_context_t **context)
{
slock_lock(video_buffer->lock);
@@ -175,7 +202,9 @@ void video_buffer_get_finished_slot(video_buffer_t *video_buffer, video_decoder_
slock_unlock(video_buffer->lock);
}
-void video_buffer_finish_slot(video_buffer_t *video_buffer, video_decoder_context_t *context)
+void video_buffer_finish_slot(
+ video_buffer_t *video_buffer,
+ video_decoder_context_t *context)
{
slock_lock(video_buffer->lock);
diff --git a/cores/libretro-ffmpeg/video_buffer.h b/cores/libretro-ffmpeg/video_buffer.h
index d9b5d3bd3a..c5ea2093a5 100644
--- a/cores/libretro-ffmpeg/video_buffer.h
+++ b/cores/libretro-ffmpeg/video_buffer.h
@@ -10,9 +10,17 @@
#include
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include
#include
+#ifdef __cplusplus
+}
+#endif
+
#include
RETRO_BEGIN_DECLS
diff --git a/ctr/ctr_system.c b/ctr/ctr_system.c
index 515eab1f50..4f690d6eaa 100644
--- a/ctr/ctr_system.c
+++ b/ctr/ctr_system.c
@@ -82,9 +82,8 @@ void __attribute__((weak)) __libctru_init(void (*retAddr)(void))
{
/* Store the return address */
__system_retAddr = NULL;
- if (envIsHomebrew()) {
+ if (envIsHomebrew())
__system_retAddr = retAddr;
- }
/* Initialize the synchronization subsystem */
__sync_init();
diff --git a/ctr/gpu_old.c b/ctr/gpu_old.c
index c79ff9ffc0..249418387e 100644
--- a/ctr/gpu_old.c
+++ b/ctr/gpu_old.c
@@ -28,11 +28,12 @@ void GPU_Reset(u32* gxbuf, u32* gpuBuf, u32 gpuBufSize)
void GPU_SetFloatUniform(GPU_SHADER_TYPE type,
u32 startreg, u32* data, u32 numreg)
{
- int regOffset;
- if(!data)
+ int regOffset = 0x0;;
+ if (!data)
return;
- regOffset = (type == GPU_GEOMETRY_SHADER) ? (-0x30) : (0x0);
+ if (type == GPU_GEOMETRY_SHADER)
+ regOffset = (-0x30);
GPUCMD_AddWrite(GPUREG_VSH_FLOATUNIFORM_CONFIG+regOffset,
0x80000000 | startreg);
@@ -153,28 +154,28 @@ void GPU_SetTextureEnable(GPU_TEXUNIT units)
void GPU_SetTexture(GPU_TEXUNIT unit, u32* data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType)
{
switch (unit)
- {
- case GPU_TEXUNIT0:
- GPUCMD_AddWrite(GPUREG_TEXUNIT0_TYPE, colorType);
- GPUCMD_AddWrite(GPUREG_TEXUNIT0_ADDR1, ((u32)data) >> 3);
- GPUCMD_AddWrite(GPUREG_TEXUNIT0_DIM, (width << 16)|height);
- GPUCMD_AddWrite(GPUREG_TEXUNIT0_PARAM, param);
- break;
+ {
+ case GPU_TEXUNIT0:
+ GPUCMD_AddWrite(GPUREG_TEXUNIT0_TYPE, colorType);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT0_ADDR1, ((u32)data) >> 3);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT0_DIM, (width << 16)|height);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT0_PARAM, param);
+ break;
- case GPU_TEXUNIT1:
- GPUCMD_AddWrite(GPUREG_TEXUNIT1_TYPE, colorType);
- GPUCMD_AddWrite(GPUREG_TEXUNIT1_ADDR, ((u32)data) >> 3);
- GPUCMD_AddWrite(GPUREG_TEXUNIT1_DIM, (width << 16)|height);
- GPUCMD_AddWrite(GPUREG_TEXUNIT1_PARAM, param);
- break;
+ case GPU_TEXUNIT1:
+ GPUCMD_AddWrite(GPUREG_TEXUNIT1_TYPE, colorType);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT1_ADDR, ((u32)data) >> 3);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT1_DIM, (width << 16)|height);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT1_PARAM, param);
+ break;
- case GPU_TEXUNIT2:
- GPUCMD_AddWrite(GPUREG_TEXUNIT2_TYPE, colorType);
- GPUCMD_AddWrite(GPUREG_TEXUNIT2_ADDR, ((u32)data) >> 3);
- GPUCMD_AddWrite(GPUREG_TEXUNIT2_DIM, (width << 16)|height);
- GPUCMD_AddWrite(GPUREG_TEXUNIT2_PARAM, param);
- break;
- }
+ case GPU_TEXUNIT2:
+ GPUCMD_AddWrite(GPUREG_TEXUNIT2_TYPE, colorType);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT2_ADDR, ((u32)data) >> 3);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT2_DIM, (width << 16)|height);
+ GPUCMD_AddWrite(GPUREG_TEXUNIT2_PARAM, param);
+ break;
+ }
}
void GPU_SetTextureBorderColor(GPU_TEXUNIT unit,u32 borderColor)
@@ -266,7 +267,6 @@ void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16
u32 param[0x5];
if(id > 6)
return;
- memset(param, 0x00, 5*4);
param[0x0] = (alphaSources << 16) | (rgbSources);
param[0x1] = (alphaOperands << 12) | (rgbOperands);
diff --git a/database_info.c b/database_info.c
index b5fe450856..6f9fe9366c 100644
--- a/database_info.c
+++ b/database_info.c
@@ -217,7 +217,8 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur,
if (!string_is_empty(val_string))
db_info->franchise = strdup(val_string);
}
- else if (string_ends_with(str, "_rating"))
+ else if (string_ends_with_size(str, "_rating",
+ strlen(str), STRLEN_CONST("_rating")))
{
if (string_is_equal(str, "bbfc_rating"))
{
@@ -364,7 +365,7 @@ database_info_handle_t *database_info_dir_init(const char *dir,
core_info_list_t *core_info_list = NULL;
struct string_list *list = NULL;
database_info_handle_t *db = (database_info_handle_t*)
- calloc(1, sizeof(*db));
+ malloc(sizeof(*db));
if (!db)
return NULL;
@@ -383,10 +384,10 @@ database_info_handle_t *database_info_dir_init(const char *dir,
dir_list_prioritize(list);
- db->list = list;
- db->list_ptr = 0;
- db->status = DATABASE_STATUS_ITERATE;
- db->type = type;
+ db->status = DATABASE_STATUS_ITERATE;
+ db->type = type;
+ db->list_ptr = 0;
+ db->list = list;
return db;
}
@@ -397,7 +398,7 @@ database_info_handle_t *database_info_file_init(const char *path,
union string_list_elem_attr attr;
struct string_list *list = NULL;
database_info_handle_t *db = (database_info_handle_t*)
- calloc(1, sizeof(*db));
+ malloc(sizeof(*db));
if (!db)
return NULL;
@@ -414,10 +415,10 @@ database_info_handle_t *database_info_file_init(const char *path,
string_list_append(list, path, attr);
- db->list_ptr = 0;
- db->list = list;
- db->status = DATABASE_STATUS_ITERATE;
- db->type = type;
+ db->status = DATABASE_STATUS_ITERATE;
+ db->type = type;
+ db->list_ptr = 0;
+ db->list = list;
return db;
}
@@ -498,6 +499,10 @@ database_info_list_t *database_info_list_new(
free(db_info.rom_name);
if (db_info.serial)
free(db_info.serial);
+ if (db_info.md5)
+ free(db_info.md5);
+ if (db_info.sha1)
+ free(db_info.sha1);
database_info_list_free(database_info_list);
free(database_info);
free(database_info_list);
diff --git a/database_info.h b/database_info.h
index 5349269a90..bba0c525ee 100644
--- a/database_info.h
+++ b/database_info.h
@@ -76,7 +76,6 @@ typedef struct
enum database_type type;
size_t list_ptr;
struct string_list *list;
- file_archive_transfer_t state;
} database_info_handle_t;
typedef struct
diff --git a/deps/7zip/7zDec.c b/deps/7zip/7zDec.c
index 4ed17b2340..71943924a9 100644
--- a/deps/7zip/7zDec.c
+++ b/deps/7zip/7zDec.c
@@ -23,44 +23,60 @@
#define k_SPARC 0x03030805
#define k_BCJ2 0x0303011B
-static SRes SzDecodeLzma(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream,
- uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
+static SRes SzDecodeLzma(CSzCoderInfo *coder,
+ uint64_t inSize, ILookInStream *inStream,
+ uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
+ int result;
CLzmaDec state;
- SRes res = SZ_OK;
+ SRes res = SZ_OK;
LzmaDec_Construct(&state);
- RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
- state.dic = outBuffer;
+ result = LzmaDec_AllocateProbs(
+ &state, coder->Props.data,
+ (unsigned)coder->Props.size, allocMain);
+ if (result != 0)
+ return result;
+ state.dic = outBuffer;
state.dicBufSize = outSize;
LzmaDec_Init(&state);
for (;;)
{
- uint8_t *inBuf = NULL;
+ uint8_t *inBuf = NULL;
size_t lookahead = (1 << 18);
if (lookahead > inSize)
- lookahead = (size_t)inSize;
- res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
+ lookahead = (size_t)inSize;
+ res = inStream->Look(
+ (void *)inStream, (const void **)&inBuf, &lookahead);
+
if (res != SZ_OK)
break;
{
- size_t inProcessed = (size_t)lookahead, dicPos = state.dicPos;
ELzmaStatus status;
- res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
- lookahead -= inProcessed;
- inSize -= inProcessed;
+ size_t inProcessed = (size_t)lookahead, dicPos = state.dicPos;
+ res = LzmaDec_DecodeToDic(
+ &state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ lookahead -= inProcessed;
+ inSize -= inProcessed;
+
if (res != SZ_OK)
break;
- if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
+
+ if (
+ state.dicPos == state.dicBufSize ||
+ (inProcessed == 0 && dicPos == state.dicPos))
{
- if (state.dicBufSize != outSize || lookahead != 0 ||
+ if (
+ state.dicBufSize != outSize ||
+ lookahead != 0 ||
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
res = SZ_ERROR_DATA;
break;
}
+
res = inStream->Skip((void *)inStream, inProcessed);
if (res != SZ_OK)
break;
@@ -71,153 +87,185 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *in
return res;
}
-static SRes SzDecodeLzma2(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream,
- uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
+static SRes SzDecodeLzma2(CSzCoderInfo *coder,
+ uint64_t inSize, ILookInStream *inStream,
+ uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
- CLzma2Dec state;
- SRes res = SZ_OK;
+ int result;
+ CLzma2Dec state;
+ SRes res = SZ_OK;
- Lzma2Dec_Construct(&state);
- if (coder->Props.size != 1)
- return SZ_ERROR_DATA;
- RINOK(Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain));
- state.decoder.dic = outBuffer;
- state.decoder.dicBufSize = outSize;
- Lzma2Dec_Init(&state);
+ Lzma2Dec_Construct(&state);
+ if (coder->Props.size != 1)
+ return SZ_ERROR_DATA;
- for (;;)
- {
- uint8_t *inBuf = NULL;
- size_t lookahead = (1 << 18);
- if (lookahead > inSize)
- lookahead = (size_t)inSize;
- res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
- if (res != SZ_OK)
- break;
+ result = Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain);
+ if (result != 0)
+ return result;
- {
- size_t inProcessed = (size_t)lookahead, dicPos = state.decoder.dicPos;
- ELzmaStatus status;
- res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
- lookahead -= inProcessed;
- inSize -= inProcessed;
+ state.decoder.dic = outBuffer;
+ state.decoder.dicBufSize = outSize;
+ Lzma2Dec_Init(&state);
+
+ for (;;)
+ {
+ uint8_t *inBuf = NULL;
+ size_t lookahead = (1 << 18);
+ if (lookahead > inSize)
+ lookahead = (size_t)inSize;
+ res = inStream->Look(
+ (void *)inStream, (const void **)&inBuf, &lookahead);
if (res != SZ_OK)
- break;
- if (state.decoder.dicPos == state.decoder.dicBufSize || (inProcessed == 0 && dicPos == state.decoder.dicPos))
+ break;
+
{
- if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
- (status != LZMA_STATUS_FINISHED_WITH_MARK))
- res = SZ_ERROR_DATA;
- break;
+ ELzmaStatus status;
+ size_t inProcessed = (size_t)lookahead, dicPos = state.decoder.dicPos;
+ res = Lzma2Dec_DecodeToDic(
+ &state, outSize, inBuf, &inProcessed,
+ LZMA_FINISH_END, &status);
+ lookahead -= inProcessed;
+ inSize -= inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (
+ state.decoder.dicPos == state.decoder.dicBufSize ||
+ (inProcessed == 0 && dicPos == state.decoder.dicPos))
+ {
+ if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ res = inStream->Skip((void *)inStream, inProcessed);
+ if (res != SZ_OK)
+ break;
}
- res = inStream->Skip((void *)inStream, inProcessed);
- if (res != SZ_OK)
- break;
- }
- }
+ }
- Lzma2Dec_FreeProbs(&state, allocMain);
- return res;
+ Lzma2Dec_FreeProbs(&state, allocMain);
+ return res;
}
-static SRes SzDecodeCopy(uint64_t inSize, ILookInStream *inStream, uint8_t *outBuffer)
+static SRes SzDecodeCopy(uint64_t inSize,
+ ILookInStream *inStream, uint8_t *outBuffer)
{
- while (inSize > 0)
- {
- void *inBuf;
- size_t curSize = (1 << 18);
- if (curSize > inSize)
- curSize = (size_t)inSize;
- RINOK(inStream->Look((void *)inStream, (const void **)&inBuf, &curSize));
- if (curSize == 0)
- return SZ_ERROR_INPUT_EOF;
- memcpy(outBuffer, inBuf, curSize);
- outBuffer += curSize;
- inSize -= curSize;
- RINOK(inStream->Skip((void *)inStream, curSize));
- }
- return SZ_OK;
+ while (inSize > 0)
+ {
+ int result;
+ void *inBuf = NULL;
+ size_t curSize = (1 << 18);
+ if (curSize > inSize)
+ curSize = (size_t)inSize;
+ result = inStream->Look(
+ (void *)inStream, (const void **)&inBuf, &curSize);
+
+ if (result != 0)
+ return result;
+ if (curSize == 0)
+ return SZ_ERROR_INPUT_EOF;
+
+ memcpy(outBuffer, inBuf, curSize);
+ outBuffer += curSize;
+ inSize -= curSize;
+ result = inStream->Skip((void *)inStream, curSize);
+
+ if (result != 0)
+ return result;
+ }
+ return SZ_OK;
}
-static bool IS_MAIN_METHOD(uint32_t m)
+static bool is_main_method(uint32_t m)
{
- switch(m)
- {
- case k_Copy:
- case k_LZMA:
- case k_LZMA2:
- return true;
- }
- return false;
+ switch(m)
+ {
+ case k_Copy:
+ case k_LZMA:
+ case k_LZMA2:
+ return true;
+ default:
+ break;
+ }
+ return false;
}
-static bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
+static bool is_supported_coder(const CSzCoderInfo *c)
{
return
c->NumInStreams == 1 &&
c->NumOutStreams == 1 &&
c->MethodID <= (uint32_t)0xFFFFFFFF &&
- IS_MAIN_METHOD((uint32_t)c->MethodID);
+ is_main_method((uint32_t)c->MethodID);
}
#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumInStreams == 4 && (c)->NumOutStreams == 1)
-static SRes CheckSupportedFolder(const CSzFolder *f)
+static SRes check_supported_folder(const CSzFolder *f)
{
if (f->NumCoders < 1 || f->NumCoders > 4)
return SZ_ERROR_UNSUPPORTED;
- if (!IS_SUPPORTED_CODER(&f->Coders[0]))
+
+ if (!is_supported_coder(&f->Coders[0]))
return SZ_ERROR_UNSUPPORTED;
- if (f->NumCoders == 1)
+
+ switch (f->NumCoders)
{
- if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)
- return SZ_ERROR_UNSUPPORTED;
- return SZ_OK;
- }
- if (f->NumCoders == 2)
- {
- CSzCoderInfo *c = &f->Coders[1];
- if (c->MethodID > (uint32_t)0xFFFFFFFF ||
- c->NumInStreams != 1 ||
- c->NumOutStreams != 1 ||
- f->NumPackStreams != 1 ||
- f->PackStreams[0] != 0 ||
- f->NumBindPairs != 1 ||
- f->BindPairs[0].InIndex != 1 ||
- f->BindPairs[0].OutIndex != 0)
- return SZ_ERROR_UNSUPPORTED;
- switch ((uint32_t)c->MethodID)
- {
- case k_BCJ:
- case k_ARM:
- break;
- default:
- return SZ_ERROR_UNSUPPORTED;
- }
- return SZ_OK;
- }
- if (f->NumCoders == 4)
- {
- if (!IS_SUPPORTED_CODER(&f->Coders[1]) ||
- !IS_SUPPORTED_CODER(&f->Coders[2]) ||
- !IS_BCJ2(&f->Coders[3]))
- return SZ_ERROR_UNSUPPORTED;
- if (f->NumPackStreams != 4 ||
- f->PackStreams[0] != 2 ||
- f->PackStreams[1] != 6 ||
- f->PackStreams[2] != 1 ||
- f->PackStreams[3] != 0 ||
- f->NumBindPairs != 3 ||
- f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||
- f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||
- f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)
- return SZ_ERROR_UNSUPPORTED;
- return SZ_OK;
+ case 1:
+ if ( f->NumPackStreams != 1
+ || f->PackStreams[0] != 0
+ || f->NumBindPairs != 0)
+ return SZ_ERROR_UNSUPPORTED;
+ return SZ_OK;
+ case 2:
+ {
+ CSzCoderInfo *c = &f->Coders[1];
+
+ if (c->MethodID > (uint32_t)0xFFFFFFFF ||
+ c->NumInStreams != 1 ||
+ c->NumOutStreams != 1 ||
+ f->NumPackStreams != 1 ||
+ f->PackStreams[0] != 0 ||
+ f->NumBindPairs != 1 ||
+ f->BindPairs[0].InIndex != 1 ||
+ f->BindPairs[0].OutIndex != 0)
+ return SZ_ERROR_UNSUPPORTED;
+
+ switch ((uint32_t)c->MethodID)
+ {
+ case k_BCJ:
+ case k_ARM:
+ break;
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ }
+ return SZ_OK;
+ case 4:
+ if (!is_supported_coder(&f->Coders[1]) ||
+ !is_supported_coder(&f->Coders[2]) ||
+ !IS_BCJ2(&f->Coders[3]))
+ return SZ_ERROR_UNSUPPORTED;
+
+ if (f->NumPackStreams != 4 ||
+ f->PackStreams[0] != 2 ||
+ f->PackStreams[1] != 6 ||
+ f->PackStreams[2] != 1 ||
+ f->PackStreams[3] != 0 ||
+ f->NumBindPairs != 3 ||
+ f->BindPairs[0].InIndex != 5 ||
+ f->BindPairs[0].OutIndex != 0 ||
+ f->BindPairs[1].InIndex != 4 ||
+ f->BindPairs[1].OutIndex != 1 ||
+ f->BindPairs[2].InIndex != 3 ||
+ f->BindPairs[2].OutIndex != 2)
+ return SZ_ERROR_UNSUPPORTED;
+ return SZ_OK;
}
return SZ_ERROR_UNSUPPORTED;
}
-static uint64_t GetSum(const uint64_t *values, uint32_t idx)
+static uint64_t get_sum(const uint64_t *values, uint32_t idx)
{
uint64_t sum = 0;
uint32_t i;
@@ -226,134 +274,169 @@ static uint64_t GetSum(const uint64_t *values, uint32_t idx)
return sum;
}
-#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;
-
-static SRes SzFolder_Decode2(const CSzFolder *folder, const uint64_t *packSizes,
- ILookInStream *inStream, uint64_t startPos,
- uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain,
- uint8_t *tempBuf[])
+static SRes SzFolder_Decode2(const CSzFolder *folder,
+ const uint64_t *packSizes,
+ ILookInStream *inStream, uint64_t startPos,
+ uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain,
+ uint8_t *tempBuf[])
{
- uint32_t ci;
- size_t tempSizes[3] = { 0, 0, 0};
- size_t tempSize3 = 0;
- uint8_t *tempBuf3 = 0;
+ uint32_t ci;
+ size_t tempSizes[3] = { 0, 0, 0};
+ size_t tempSize3 = 0;
+ uint8_t *tempBuf3 = 0;
+ int result = check_supported_folder(folder);
- RINOK(CheckSupportedFolder(folder));
+ if (result != 0)
+ return result;
- for (ci = 0; ci < folder->NumCoders; ci++)
- {
- CSzCoderInfo *coder = &folder->Coders[ci];
+ for (ci = 0; ci < folder->NumCoders; ci++)
+ {
+ CSzCoderInfo *coder = &folder->Coders[ci];
- if (IS_MAIN_METHOD((uint32_t)coder->MethodID))
- {
- uint32_t si = 0;
- uint64_t offset;
- uint64_t inSize;
- uint8_t *outBufCur = outBuffer;
- size_t outSizeCur = outSize;
- if (folder->NumCoders == 4)
+ if (is_main_method((uint32_t)coder->MethodID))
{
- uint32_t indices[] = { 3, 2, 0 };
- uint64_t unpackSize = folder->UnpackSizes[ci];
- si = indices[ci];
- if (ci < 2)
- {
- uint8_t *temp;
- outSizeCur = (size_t)unpackSize;
- if (outSizeCur != unpackSize)
+ int result;
+ uint64_t offset = 0;
+ uint64_t inSize = 0;
+ uint32_t si = 0;
+ uint8_t *outBufCur = outBuffer;
+ size_t outSizeCur = outSize;
+
+ if (folder->NumCoders == 4)
+ {
+ uint32_t indices[] = { 3, 2, 0 };
+ uint64_t unpackSize = folder->UnpackSizes[ci];
+ si = indices[ci];
+
+ if (ci < 2)
+ {
+ uint8_t *temp;
+ outSizeCur = (size_t)unpackSize;
+ if (outSizeCur != unpackSize)
+ return SZ_ERROR_MEM;
+ temp = (uint8_t *)IAlloc_Alloc(allocMain, outSizeCur);
+ if (temp == 0 && outSizeCur != 0)
+ return SZ_ERROR_MEM;
+ outBufCur = tempBuf[1 - ci] = temp;
+ tempSizes[1 - ci] = outSizeCur;
+ }
+ else if (ci == 2)
+ {
+ if (unpackSize > outSize) /* check it */
+ return SZ_ERROR_PARAM;
+ tempBuf3 = outBufCur = outBuffer
+ + (outSize - (size_t)unpackSize);
+ tempSize3 = outSizeCur = (size_t)unpackSize;
+ }
+ else
+ return SZ_ERROR_UNSUPPORTED;
+ }
+
+ offset = get_sum(packSizes, si);
+ inSize = packSizes[si];
+ result = LookInStream_SeekTo(inStream, startPos + offset);
+
+ if (result != 0)
+ return result;
+
+ switch (coder->MethodID)
+ {
+ case k_Copy:
+ if (inSize != outSizeCur) /* check it */
+ return SZ_ERROR_DATA;
+ result = SzDecodeCopy(inSize, inStream, outBufCur);
+ if (result != 0)
+ return result;
+ break;
+ case k_LZMA:
+ result = SzDecodeLzma(
+ coder, inSize, inStream,
+ outBufCur, outSizeCur, allocMain);
+ if (result != 0)
+ return result;
+ break;
+ case k_LZMA2:
+ result = SzDecodeLzma2(
+ coder, inSize, inStream,
+ outBufCur, outSizeCur, allocMain);
+ if (result != 0)
+ return result;
+ break;
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ }
+ else if (coder->MethodID == k_BCJ2)
+ {
+ SRes res;
+ int result;
+ uint64_t offset = get_sum(packSizes, 1);
+ uint64_t s3Size = packSizes[1];
+
+ if (ci != 3)
+ return SZ_ERROR_UNSUPPORTED;
+
+ result = LookInStream_SeekTo(inStream, startPos + offset);
+
+ if (result != 0)
+ return result;
+
+ tempSizes[2] = (size_t)s3Size;
+ if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM;
- temp = (uint8_t *)IAlloc_Alloc(allocMain, outSizeCur);
- if (temp == 0 && outSizeCur != 0)
- return SZ_ERROR_MEM;
- outBufCur = tempBuf[1 - ci] = temp;
- tempSizes[1 - ci] = outSizeCur;
- }
- else if (ci == 2)
- {
- if (unpackSize > outSize) /* check it */
- return SZ_ERROR_PARAM;
- tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
- tempSize3 = outSizeCur = (size_t)unpackSize;
- }
- else
- return SZ_ERROR_UNSUPPORTED;
- }
- offset = GetSum(packSizes, si);
- inSize = packSizes[si];
- RINOK(LookInStream_SeekTo(inStream, startPos + offset));
- if (coder->MethodID == k_Copy)
- {
- if (inSize != outSizeCur) /* check it */
- return SZ_ERROR_DATA;
- RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
- }
- else if (coder->MethodID == k_LZMA)
- {
- RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
- }
- else if (coder->MethodID == k_LZMA2)
- {
- RINOK(SzDecodeLzma2(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
+ tempBuf[2] = (uint8_t *)IAlloc_Alloc(allocMain, tempSizes[2]);
+ if (tempBuf[2] == 0 && tempSizes[2] != 0)
+ return SZ_ERROR_MEM;
+
+ res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
+ if (res != 0)
+ return res;
+
+ res = Bcj2_Decode(
+ tempBuf3, tempSize3,
+ tempBuf[0], tempSizes[0],
+ tempBuf[1], tempSizes[1],
+ tempBuf[2], tempSizes[2],
+ outBuffer, outSize);
+
+ if (res != 0)
+ return res;
}
else
- return SZ_ERROR_UNSUPPORTED;
- }
- else if (coder->MethodID == k_BCJ2)
- {
- uint64_t offset = GetSum(packSizes, 1);
- uint64_t s3Size = packSizes[1];
- SRes res;
- if (ci != 3)
- return SZ_ERROR_UNSUPPORTED;
- RINOK(LookInStream_SeekTo(inStream, startPos + offset));
- tempSizes[2] = (size_t)s3Size;
- if (tempSizes[2] != s3Size)
- return SZ_ERROR_MEM;
- tempBuf[2] = (uint8_t *)IAlloc_Alloc(allocMain, tempSizes[2]);
- if (tempBuf[2] == 0 && tempSizes[2] != 0)
- return SZ_ERROR_MEM;
- res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
- RINOK(res)
-
- res = Bcj2_Decode(
- tempBuf3, tempSize3,
- tempBuf[0], tempSizes[0],
- tempBuf[1], tempSizes[1],
- tempBuf[2], tempSizes[2],
- outBuffer, outSize);
- RINOK(res)
- }
- else
- {
- if (ci != 1)
- return SZ_ERROR_UNSUPPORTED;
- switch(coder->MethodID)
{
- case k_BCJ:
- {
- uint32_t state;
- x86_Convert_Init(state);
- x86_Convert(outBuffer, outSize, 0, &state, 0);
- break;
- }
- CASE_BRA_CONV(ARM)
- default:
- return SZ_ERROR_UNSUPPORTED;
+ if (ci != 1)
+ return SZ_ERROR_UNSUPPORTED;
+ switch(coder->MethodID)
+ {
+ case k_BCJ:
+ {
+ uint32_t state;
+ x86_Convert_Init(state);
+ x86_Convert(outBuffer, outSize, 0, &state, 0);
+ break;
+ }
+ case k_ARM:
+ ARM_Convert(outBuffer, outSize, 0, 0);
+ break;
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
}
- }
- }
- return SZ_OK;
+ }
+ return SZ_OK;
}
SRes SzFolder_Decode(const CSzFolder *folder, const uint64_t *packSizes,
ILookInStream *inStream, uint64_t startPos,
uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
- uint8_t *tempBuf[3] = { 0, 0, 0};
int i;
- SRes res = SzFolder_Decode2(folder, packSizes, inStream, startPos,
- outBuffer, (size_t)outSize, allocMain, tempBuf);
+ uint8_t *tempBuf[3] = { 0, 0, 0};
+ SRes res = SzFolder_Decode2(folder,
+ packSizes, inStream, startPos,
+ outBuffer, (size_t)outSize, allocMain, tempBuf);
+
for (i = 0; i < 3; i++)
IAlloc_Free(allocMain, tempBuf[i]);
return res;
diff --git a/deps/7zip/7zFile.c b/deps/7zip/7zFile.c
index 6dc10da40c..25f4452f91 100644
--- a/deps/7zip/7zFile.c
+++ b/deps/7zip/7zFile.c
@@ -2,236 +2,110 @@
2009-11-24 : Igor Pavlov : Public domain */
#include
+#define SKIP_STDIO_REDEFINES
+#include
#include "7zFile.h"
-#ifndef USE_WINDOWS_FILE
-
#ifndef UNDER_CE
#include
#endif
-#else
-
-/*
- ReadFile and WriteFile functions in Windows have BUG:
- If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
- from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
- (Insufficient system resources exist to complete the requested service).
- Probably in some version of Windows there are problems with other sizes:
- for 32 MB (maybe also for 16 MB).
- And message can be "Network connection was lost"
- */
-
-#define kChunkSizeMax (1 << 22)
-
-#endif
-
void File_Construct(CSzFile *p)
{
-#ifdef USE_WINDOWS_FILE
- p->handle = INVALID_HANDLE_VALUE;
-#else
p->file = NULL;
-#endif
}
-#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
{
-#ifdef USE_WINDOWS_FILE
- p->handle = CreateFileA(name,
- writeMode ? GENERIC_WRITE : GENERIC_READ,
- FILE_SHARE_READ, NULL,
- writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
- return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
-#else
- p->file = fopen(name, writeMode ? "wb+" : "rb");
- return (p->file != 0) ? 0 :
+ p->file = rfopen(name, writeMode ? "wb+" : "rb");
+ if (!p->file)
+ {
#ifdef UNDER_CE
- 2; /* ENOENT */
+ return 2; /* ENOENT */
#else
- errno;
-#endif
+ return errno;
#endif
+ }
+
+ return 0;
}
-WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
-WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
-#endif
-
-#ifdef USE_WINDOWS_FILE
-static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)
+WRes InFile_Open(CSzFile *p, const char *name)
{
- p->handle = CreateFileW(name,
- writeMode ? GENERIC_WRITE : GENERIC_READ,
- FILE_SHARE_READ, NULL,
- writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
- return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
+ return File_Open(p, name, 0);
+}
+
+WRes OutFile_Open(CSzFile *p, const char *name)
+{
+ return File_Open(p, name, 1);
}
-WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }
-WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }
-#endif
WRes File_Close(CSzFile *p)
{
-#ifdef USE_WINDOWS_FILE
- if (p->handle != INVALID_HANDLE_VALUE)
+ if (p->file)
{
- if (!CloseHandle(p->handle))
- return GetLastError();
- p->handle = INVALID_HANDLE_VALUE;
- }
-#else
- if (p->file != NULL)
- {
- int res = fclose(p->file);
+ int res = rfclose((RFILE*)p->file);
if (res != 0)
return res;
p->file = NULL;
}
-#endif
return 0;
}
WRes File_Read(CSzFile *p, void *data, size_t *size)
{
- size_t originalSize = *size;
+ int64_t originalSize = *size;
if (originalSize == 0)
return 0;
-#ifdef USE_WINDOWS_FILE
-
- *size = 0;
- do
- {
- DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
- DWORD processed = 0;
- BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
- data = (void *)((uint8_t*)data + processed);
- originalSize -= processed;
- *size += processed;
- if (!res)
- return GetLastError();
- if (processed == 0)
- break;
- }
- while (originalSize > 0);
- return 0;
-
-#else
-
- *size = fread(data, 1, originalSize, p->file);
+ *size = rfread(data, 1, originalSize, (RFILE*)p->file);
if (*size == originalSize)
return 0;
- return ferror(p->file);
-
-#endif
+ return rferror((RFILE*)p->file);
}
WRes File_Write(CSzFile *p, const void *data, size_t *size)
{
- size_t originalSize = *size;
+ int64_t originalSize = *size;
if (originalSize == 0)
return 0;
-#ifdef USE_WINDOWS_FILE
-
- *size = 0;
- do
- {
- DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
- DWORD processed = 0;
- BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
- data = (void *)((uint8_t*)data + processed);
- originalSize -= processed;
- *size += processed;
- if (!res)
- return GetLastError();
- if (processed == 0)
- break;
- }
- while (originalSize > 0);
- return 0;
-
-#else
-
- *size = fwrite(data, 1, originalSize, p->file);
+ *size = rfwrite(data, 1, originalSize, (RFILE*)p->file);
if (*size == originalSize)
return 0;
- return ferror(p->file);
-
-#endif
+ return rferror((RFILE*)p->file);
}
WRes File_Seek(CSzFile *p, int64_t *pos, ESzSeek origin)
{
-#ifdef USE_WINDOWS_FILE
-
- LARGE_INTEGER value;
- DWORD moveMethod;
- value.LowPart = (DWORD)*pos;
- value.HighPart = (LONG)((uint64_t)*pos >> 16 >> 16); /* for case when uint64_t is 32-bit only */
+ int whence;
+ int64_t res;
switch (origin)
{
- case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
- case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
- case SZ_SEEK_END: moveMethod = FILE_END; break;
- default: return ERROR_INVALID_PARAMETER;
+ case SZ_SEEK_SET:
+ whence = SEEK_SET;
+ break;
+ case SZ_SEEK_CUR:
+ whence = SEEK_CUR;
+ break;
+ case SZ_SEEK_END:
+ whence = SEEK_END;
+ break;
+ default:
+ return 1;
}
- value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
- if (value.LowPart == 0xFFFFFFFF)
- {
- WRes res = GetLastError();
- if (res != NO_ERROR)
- return res;
- }
- *pos = ((int64_t)value.HighPart << 32) | value.LowPart;
- return 0;
-
-#else
-
- int moveMethod;
- int res;
- switch (origin)
- {
- case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
- case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
- case SZ_SEEK_END: moveMethod = SEEK_END; break;
- default: return 1;
- }
- res = fseek(p->file, (long)*pos, moveMethod);
- *pos = ftell(p->file);
+ res = rfseek((RFILE*)p->file, (int64_t)*pos, whence);
+ *pos = rftell((RFILE*)p->file);
return res;
-
-#endif
}
WRes File_GetLength(CSzFile *p, uint64_t *length)
{
-#ifdef USE_WINDOWS_FILE
-
- DWORD sizeHigh;
- DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
- if (sizeLow == 0xFFFFFFFF)
- {
- DWORD res = GetLastError();
- if (res != NO_ERROR)
- return res;
- }
- *length = (((uint64_t)sizeHigh) << 32) + sizeLow;
- return 0;
-
-#else
-
- long pos = ftell(p->file);
- int res = fseek(p->file, 0, SEEK_END);
- *length = ftell(p->file);
- fseek(p->file, pos, SEEK_SET);
+ int64_t pos = rftell((RFILE*)p->file);
+ int64_t res = rfseek((RFILE*)p->file, 0, SEEK_END);
+ *length = rftell((RFILE*)p->file);
+ rfseek((RFILE*)p->file, pos, SEEK_SET);
return res;
-
-#endif
}
@@ -248,7 +122,6 @@ void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
p->s.Read = FileSeqInStream_Read;
}
-
/* ---------- FileInStream ---------- */
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
@@ -283,3 +156,5 @@ void FileOutStream_CreateVTable(CFileOutStream *p)
{
p->s.Write = FileOutStream_Write;
}
+
+#undef SKIP_STDIO_REDEFINES
diff --git a/deps/7zip/7zFile.h b/deps/7zip/7zFile.h
index 33910ec420..f89e2f8e24 100644
--- a/deps/7zip/7zFile.h
+++ b/deps/7zip/7zFile.h
@@ -4,15 +4,7 @@
#ifndef __7Z_FILE_H
#define __7Z_FILE_H
-#ifdef _WIN32
-#define USE_WINDOWS_FILE
-#endif
-
-#ifdef USE_WINDOWS_FILE
-#include
-#else
#include
-#endif
#include "7zTypes.h"
@@ -24,22 +16,12 @@ extern "C" {
typedef struct
{
- #ifdef USE_WINDOWS_FILE
- HANDLE handle;
- #else
- FILE *file;
- #endif
+ void *file;
} CSzFile;
void File_Construct(CSzFile *p);
-#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
WRes InFile_Open(CSzFile *p, const char *name);
WRes OutFile_Open(CSzFile *p, const char *name);
-#endif
-#ifdef USE_WINDOWS_FILE
-WRes InFile_OpenW(CSzFile *p, const WCHAR *name);
-WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);
-#endif
WRes File_Close(CSzFile *p);
/* reads max(*size, remain file's size) bytes */
diff --git a/deps/7zip/7zIn.c b/deps/7zip/7zIn.c
index 62c1d5eb82..0e4ec7e4c9 100644
--- a/deps/7zip/7zIn.c
+++ b/deps/7zip/7zIn.c
@@ -10,13 +10,33 @@
uint8_t k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
-#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }
-
#define NUM_FOLDER_CODERS_MAX 32
#define NUM_CODER_STREAMS_MAX 32
+#ifdef MY_CPU_LE_UNALIGN
+#define GetUi16(p) (*(const uint16_t *)(p))
+#define GetUi32(p) (*(const uint32_t *)(p))
+#define GetUi64(p) (*(const uint64_t *)(p))
+#else
+#define GetUi16(p) (((const uint8_t *)(p))[0] | ((uint16_t)((const uint8_t *)(p))[1] << 8))
+#define GetUi32(p) ( \
+ ((const uint8_t *)(p))[0] | \
+ ((uint32_t)((const uint8_t *)(p))[1] << 8) | \
+ ((uint32_t)((const uint8_t *)(p))[2] << 16) | \
+ ((uint32_t)((const uint8_t *)(p))[3] << 24))
+#define GetUi64(p) (GetUi32(p) | ((uint64_t)GetUi32(((const uint8_t *)(p)) + 4) << 32))
+#endif
+
+typedef struct _CSzState
+{
+ uint8_t *Data;
+ size_t Size;
+}CSzData;
+
+/* Forward declarations */
void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc);
-int SzFolder_FindBindPairForOutStream(CSzFolder *p, uint32_t outStreamIndex);
+int SzFolder_FindBindPairForOutStream(CSzFolder *p,
+ uint32_t outStreamIndex);
void SzCoderInfo_Init(CSzCoderInfo *p)
{
@@ -31,15 +51,15 @@ void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)
void SzFolder_Init(CSzFolder *p)
{
- p->Coders = 0;
- p->BindPairs = 0;
- p->PackStreams = 0;
- p->UnpackSizes = 0;
- p->NumCoders = 0;
- p->NumBindPairs = 0;
- p->NumPackStreams = 0;
+ p->Coders = 0;
+ p->BindPairs = 0;
+ p->PackStreams = 0;
+ p->UnpackSizes = 0;
+ p->NumCoders = 0;
+ p->NumBindPairs = 0;
+ p->NumPackStreams = 0;
p->UnpackCRCDefined = 0;
- p->UnpackCRC = 0;
+ p->UnpackCRC = 0;
p->NumUnpackStreams = 0;
}
@@ -58,8 +78,8 @@ void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
uint32_t SzFolder_GetNumOutStreams(CSzFolder *p)
{
- uint32_t result = 0;
uint32_t i;
+ uint32_t result = 0;
for (i = 0; i < p->NumCoders; i++)
result += p->Coders[i].NumOutStreams;
return result;
@@ -92,29 +112,28 @@ uint64_t SzFolder_GetUnpackSize(CSzFolder *p)
for (i--; i >= 0; i--)
if (SzFolder_FindBindPairForOutStream(p, i) < 0)
return p->UnpackSizes[i];
- /* throw 1; */
return 0;
}
void SzFile_Init(CSzFileItem *p)
{
- p->HasStream = 1;
- p->IsDir = 0;
- p->IsAnti = 0;
- p->CrcDefined = 0;
+ p->HasStream = 1;
+ p->IsDir = 0;
+ p->IsAnti = 0;
+ p->CrcDefined = 0;
p->MTimeDefined = 0;
}
void SzAr_Init(CSzAr *p)
{
- p->PackSizes = 0;
+ p->PackSizes = 0;
p->PackCRCsDefined = 0;
- p->PackCRCs = 0;
- p->Folders = 0;
- p->Files = 0;
- p->NumPackStreams = 0;
- p->NumFolders = 0;
- p->NumFiles = 0;
+ p->PackCRCs = 0;
+ p->Folders = 0;
+ p->Files = 0;
+ p->NumPackStreams = 0;
+ p->NumFolders = 0;
+ p->NumFiles = 0;
}
void SzAr_Free(CSzAr *p, ISzAlloc *alloc)
@@ -137,10 +156,10 @@ void SzArEx_Init(CSzArEx *p)
{
SzAr_Init(&p->db);
p->FolderStartPackStreamIndex = 0;
- p->PackStreamStartPositions = 0;
- p->FolderStartFileIndex = 0;
- p->FileIndexToFolderIndexMap = 0;
- p->FileNameOffsets = 0;
+ p->PackStreamStartPositions = 0;
+ p->FolderStartFileIndex = 0;
+ p->FileIndexToFolderIndexMap = 0;
+ p->FileNameOffsets = 0;
Buf_Init(&p->FileNames);
}
@@ -158,34 +177,34 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
SzArEx_Init(p);
}
-/*
- uint64_t GetFolderPackStreamSize(int folderIndex, int streamIndex) const
- {
+#if 0
+uint64_t GetFolderPackStreamSize(int folderIndex, int streamIndex)
+{
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
- }
+}
- uint64_t GetFilePackSize(int fileIndex) const
- {
+uint64_t GetFilePackSize(int fileIndex)
+{
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex >= 0)
{
- const CSzFolder &folderInfo = Folders[folderIndex];
- if (FolderStartFileIndex[folderIndex] == fileIndex)
- return GetFolderFullPackSize(folderIndex);
+ const CSzFolder &folderInfo = Folders[folderIndex];
+ if (FolderStartFileIndex[folderIndex] == fileIndex)
+ return GetFolderFullPackSize(folderIndex);
}
return 0;
- }
- */
+}
+#endif
#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \
if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }
static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
{
- uint32_t startPos = 0;
- uint64_t startPosSize = 0;
uint32_t i;
- uint32_t folderIndex = 0;
+ uint32_t startPos = 0;
+ uint64_t startPosSize = 0;
+ uint32_t folderIndex = 0;
uint32_t indexInFolder = 0;
MY_ALLOC(uint32_t, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);
for (i = 0; i < p->db.NumFolders; i++)
@@ -208,7 +227,8 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
for (i = 0; i < p->db.NumFiles; i++)
{
CSzFileItem *file = p->db.Files + i;
- int emptyStream = !file->HasStream;
+ int emptyStream = !file->HasStream;
+
if (emptyStream && indexInFolder == 0)
{
p->FileIndexToFolderIndexMap[i] = (uint32_t)-1;
@@ -230,10 +250,14 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
folderIndex++;
}
}
+
p->FileIndexToFolderIndexMap[i] = folderIndex;
+
if (emptyStream)
continue;
+
indexInFolder++;
+
if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)
{
folderIndex++;
@@ -244,18 +268,21 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
}
-uint64_t SzArEx_GetFolderStreamPos(const CSzArEx *p, uint32_t folderIndex, uint32_t indexInFolder)
+uint64_t SzArEx_GetFolderStreamPos(
+ const CSzArEx *p, uint32_t folderIndex, uint32_t indexInFolder)
{
return p->dataPos +
p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
-int SzArEx_GetFolderFullPackSize(const CSzArEx *p, uint32_t folderIndex, uint64_t *resSize)
+int SzArEx_GetFolderFullPackSize(
+ const CSzArEx *p, uint32_t folderIndex, uint64_t *resSize)
{
- uint32_t packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
- CSzFolder *folder = p->db.Folders + folderIndex;
- uint64_t size = 0;
uint32_t i;
+ uint64_t size = 0;
+ uint32_t packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
+ CSzFolder *folder = p->db.Folders + folderIndex;
+
for (i = 0; i < folder->NumPackStreams; i++)
{
uint64_t t = size + p->db.PackSizes[packStreamIndex + i];
@@ -277,12 +304,6 @@ static int TestSignatureCandidate(uint8_t *testuint8_ts)
return 1;
}
-typedef struct _CSzState
-{
- uint8_t *Data;
- size_t Size;
-}CSzData;
-
static SRes SzReaduint8_t(CSzData *sd, uint8_t *b)
{
if (sd->Size == 0)
@@ -297,7 +318,9 @@ static SRes SzReaduint8_ts(CSzData *sd, uint8_t *data, size_t size)
size_t i;
for (i = 0; i < size; i++)
{
- RINOK(SzReaduint8_t(sd, data + i));
+ int result = SzReaduint8_t(sd, data + i);
+ if (result != 0)
+ return result;
}
return SZ_OK;
}
@@ -308,8 +331,10 @@ static SRes SzReaduint32_t(CSzData *sd, uint32_t *value)
*value = 0;
for (i = 0; i < 4; i++)
{
- uint8_t b;
- RINOK(SzReaduint8_t(sd, &b));
+ uint8_t b = 0;
+ int result = SzReaduint8_t(sd, &b);
+ if (result != 0)
+ return result;
*value |= ((uint32_t)(b) << (8 * i));
}
return SZ_OK;
@@ -317,21 +342,30 @@ static SRes SzReaduint32_t(CSzData *sd, uint32_t *value)
static SRes SzReadNumber(CSzData *sd, uint64_t *value)
{
- uint8_t firstuint8_t;
- uint8_t mask = 0x80;
int i;
- RINOK(SzReaduint8_t(sd, &firstuint8_t));
- *value = 0;
+ uint8_t firstuint8_t = 0;
+ uint8_t mask = 0x80;
+ int result = SzReaduint8_t(sd, &firstuint8_t);
+
+ if (result != 0)
+ return result;
+
+ *value = 0;
+
for (i = 0; i < 8; i++)
{
- uint8_t b;
+ int result;
+ uint8_t b = 0;
if ((firstuint8_t & mask) == 0)
{
uint64_t highPart = firstuint8_t & (mask - 1);
*value += (highPart << (8 * i));
return SZ_OK;
}
- RINOK(SzReaduint8_t(sd, &b));
+ result = SzReaduint8_t(sd, &b);
+
+ if (result != 0)
+ return result;
*value |= ((uint64_t)b << (8 * i));
mask >>= 1;
}
@@ -341,7 +375,9 @@ static SRes SzReadNumber(CSzData *sd, uint64_t *value)
static SRes SzReadNumber32(CSzData *sd, uint32_t *value)
{
uint64_t value64;
- RINOK(SzReadNumber(sd, &value64));
+ int result = SzReadNumber(sd, &value64);
+ if (result != 0)
+ return result;
if (value64 >= 0x80000000)
return SZ_ERROR_UNSUPPORTED;
if (value64 >= ((uint64_t)(1) << ((sizeof(size_t) - 1) * 8 + 2)))
@@ -367,7 +403,9 @@ static SRes SzSkeepDataSize(CSzData *sd, uint64_t size)
static SRes SzSkeepData(CSzData *sd)
{
uint64_t size;
- RINOK(SzReadNumber(sd, &size));
+ int result = SzReadNumber(sd, &size);
+ if (result != 0)
+ return result;
return SzSkeepDataSize(sd, size);
}
@@ -376,7 +414,9 @@ static SRes SzReadArchiveProperties(CSzData *sd)
for (;;)
{
uint64_t type;
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
if (type == k7zIdEnd)
break;
SzSkeepData(sd);
@@ -389,27 +429,34 @@ static SRes SzWaitAttribute(CSzData *sd, uint64_t attribute)
for (;;)
{
uint64_t type;
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
if (type == attribute)
return SZ_OK;
if (type == k7zIdEnd)
return SZ_ERROR_ARCHIVE;
- RINOK(SzSkeepData(sd));
+ result = SzSkeepData(sd);
+ if (result != 0)
+ return result;
}
}
-static SRes SzReadBoolVector(CSzData *sd, size_t numItems, uint8_t **v, ISzAlloc *alloc)
+static SRes SzReadBoolVector(
+ CSzData *sd, size_t numItems, uint8_t **v, ISzAlloc *alloc)
{
- uint8_t b = 0;
- uint8_t mask = 0;
size_t i;
+ uint8_t b = 0;
+ uint8_t mask = 0;
MY_ALLOC(uint8_t, *v, numItems, alloc);
for (i = 0; i < numItems; i++)
{
if (mask == 0)
{
- RINOK(SzReaduint8_t(sd, &b));
- mask = 0x80;
+ int result = SzReaduint8_t(sd, &b);
+ if (result != 0)
+ return result;
+ mask = 0x80;
}
(*v)[i] = (uint8_t)(((b & mask) != 0) ? 1 : 0);
mask >>= 1;
@@ -419,9 +466,12 @@ static SRes SzReadBoolVector(CSzData *sd, size_t numItems, uint8_t **v, ISzAlloc
static SRes SzReadBoolVector2(CSzData *sd, size_t numItems, uint8_t **v, ISzAlloc *alloc)
{
- uint8_t allAreDefined;
size_t i;
- RINOK(SzReaduint8_t(sd, &allAreDefined));
+ uint8_t allAreDefined = 0;
+ int result = SzReaduint8_t(sd, &allAreDefined);
+
+ if (result != 0)
+ return result;
if (allAreDefined == 0)
return SzReadBoolVector(sd, numItems, v, alloc);
MY_ALLOC(uint8_t, *v, numItems, alloc);
@@ -438,13 +488,22 @@ static SRes SzReadHashDigests(
ISzAlloc *alloc)
{
size_t i;
- RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));
+ int result = SzReadBoolVector2(sd, numItems, digestsDefined, alloc);
+
+ if (result != 0)
+ return result;
+
MY_ALLOC(uint32_t, *digests, numItems, alloc);
+
for (i = 0; i < numItems; i++)
+ {
if ((*digestsDefined)[i])
{
- RINOK(SzReaduint32_t(sd, (*digests) + i));
+ int result = SzReaduint32_t(sd, (*digests) + i);
+ if (result != 0)
+ return result;
}
+ }
return SZ_OK;
}
@@ -458,30 +517,44 @@ static SRes SzReadPackInfo(
ISzAlloc *alloc)
{
uint32_t i;
- RINOK(SzReadNumber(sd, dataOffset));
- RINOK(SzReadNumber32(sd, numPackStreams));
+ int result = SzReadNumber(sd, dataOffset);
- RINOK(SzWaitAttribute(sd, k7zIdSize));
+ if (result != 0)
+ return result;
+ result = SzReadNumber32(sd, numPackStreams);
+ if (result != 0)
+ return result;
+ result = SzWaitAttribute(sd, k7zIdSize);
+ if (result != 0)
+ return result;
MY_ALLOC(uint64_t, *packSizes, (size_t)*numPackStreams, alloc);
for (i = 0; i < *numPackStreams; i++)
{
- RINOK(SzReadNumber(sd, (*packSizes) + i));
+ result = SzReadNumber(sd, (*packSizes) + i);
+ if (result != 0)
+ return result;
}
for (;;)
{
uint64_t type;
- RINOK(SzReadID(sd, &type));
+ result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
if (type == k7zIdEnd)
break;
if (type == k7zIdCRC)
{
- RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));
+ result = SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc);
+ if (result != 0)
+ return result;
continue;
}
- RINOK(SzSkeepData(sd));
+ result = SzSkeepData(sd);
+ if (result != 0)
+ return result;
}
if (*packCRCsDefined == 0)
{
@@ -498,17 +571,27 @@ static SRes SzReadPackInfo(
static SRes SzReadSwitch(CSzData *sd)
{
- uint8_t external;
- RINOK(SzReaduint8_t(sd, &external));
- return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;
+ uint8_t external = 0;
+ int result = SzReaduint8_t(sd, &external);
+ if (result != 0)
+ return result;
+ if (external != 0)
+ return SZ_ERROR_UNSUPPORTED;
+ return SZ_OK;
}
static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
{
- uint32_t numCoders, numBindPairs, numPackStreams, i;
- uint32_t numInStreams = 0, numOutStreams = 0;
+ unsigned i;
+ uint32_t numBindPairs = 0;
+ uint32_t numPackStreams = 0;
+ uint32_t numInStreams = 0;
+ uint32_t numOutStreams = 0;
+ uint32_t numCoders = 0;
+ int result = SzReadNumber32(sd, &numCoders);
- RINOK(SzReadNumber32(sd, &numCoders));
+ if (result != 0)
+ return result;
if (numCoders > NUM_FOLDER_CODERS_MAX)
return SZ_ERROR_UNSUPPORTED;
folder->NumCoders = numCoders;
@@ -520,57 +603,89 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
for (i = 0; i < numCoders; i++)
{
- uint8_t mainuint8_t;
+ unsigned idSize, j;
+ uint8_t longID[15];
+ uint8_t mainuint8_t = 0;
CSzCoderInfo *coder = folder->Coders + i;
- {
- unsigned idSize, j;
- uint8_t longID[15];
- RINOK(SzReaduint8_t(sd, &mainuint8_t));
- idSize = (unsigned)(mainuint8_t & 0xF);
- RINOK(SzReaduint8_ts(sd, longID, idSize));
- if (idSize > sizeof(coder->MethodID))
- return SZ_ERROR_UNSUPPORTED;
- coder->MethodID = 0;
- for (j = 0; j < idSize; j++)
- coder->MethodID |= (uint64_t)longID[idSize - 1 - j] << (8 * j);
+ int result = SzReaduint8_t(sd, &mainuint8_t);
- if ((mainuint8_t & 0x10) != 0)
- {
- RINOK(SzReadNumber32(sd, &coder->NumInStreams));
- RINOK(SzReadNumber32(sd, &coder->NumOutStreams));
- if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||
- coder->NumOutStreams > NUM_CODER_STREAMS_MAX)
- return SZ_ERROR_UNSUPPORTED;
- }
- else
- {
- coder->NumInStreams = 1;
- coder->NumOutStreams = 1;
- }
- if ((mainuint8_t & 0x20) != 0)
- {
- uint64_t propertiesSize = 0;
- RINOK(SzReadNumber(sd, &propertiesSize));
- if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))
- return SZ_ERROR_MEM;
- RINOK(SzReaduint8_ts(sd, coder->Props.data, (size_t)propertiesSize));
- }
+ if (result != 0)
+ return result;
+
+ idSize = (unsigned)(mainuint8_t & 0xF);
+
+ result = SzReaduint8_ts(sd, longID, idSize);
+
+ if (result != 0)
+ return result;
+ if (idSize > sizeof(coder->MethodID))
+ return SZ_ERROR_UNSUPPORTED;
+
+ coder->MethodID = 0;
+ for (j = 0; j < idSize; j++)
+ coder->MethodID |= (uint64_t)longID[idSize - 1 - j] << (8 * j);
+
+ if ((mainuint8_t & 0x10) != 0)
+ {
+ int result = SzReadNumber32(sd, &coder->NumInStreams);
+
+ if (result != 0)
+ return result;
+
+ result = SzReadNumber32(sd, &coder->NumOutStreams);
+
+ if (result != 0)
+ return result;
+
+ if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||
+ coder->NumOutStreams > NUM_CODER_STREAMS_MAX)
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ else
+ {
+ coder->NumInStreams = 1;
+ coder->NumOutStreams = 1;
+ }
+ if ((mainuint8_t & 0x20) != 0)
+ {
+ uint64_t propertiesSize = 0;
+ int result = SzReadNumber(sd, &propertiesSize);
+
+ if (result != 0)
+ return result;
+ if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))
+ return SZ_ERROR_MEM;
+ result = SzReaduint8_ts(sd, coder->Props.data, (size_t)propertiesSize);
+ if (result != 0)
+ return result;
}
while ((mainuint8_t & 0x80) != 0)
{
- RINOK(SzReaduint8_t(sd, &mainuint8_t));
- RINOK(SzSkeepDataSize(sd, (mainuint8_t & 0xF)));
+ result = SzReaduint8_t(sd, &mainuint8_t);
+ if (result != 0)
+ return result;
+ result = SzSkeepDataSize(sd, (mainuint8_t & 0xF));
+ if (result != 0)
+ return result;
if ((mainuint8_t & 0x10) != 0)
{
uint32_t n;
- RINOK(SzReadNumber32(sd, &n));
- RINOK(SzReadNumber32(sd, &n));
+ int result = SzReadNumber32(sd, &n);
+ if (result != 0)
+ return result;
+ result = SzReadNumber32(sd, &n);
+ if (result != 0)
+ return result;
}
if ((mainuint8_t & 0x20) != 0)
{
uint64_t propertiesSize = 0;
- RINOK(SzReadNumber(sd, &propertiesSize));
- RINOK(SzSkeepDataSize(sd, propertiesSize));
+ int result = SzReadNumber(sd, &propertiesSize);
+ if (result != 0)
+ return result;
+ result = SzSkeepDataSize(sd, propertiesSize);
+ if (result != 0)
+ return result;
}
}
numInStreams += coder->NumInStreams;
@@ -586,8 +701,13 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
for (i = 0; i < numBindPairs; i++)
{
CSzBindPair *bp = folder->BindPairs + i;
- RINOK(SzReadNumber32(sd, &bp->InIndex));
- RINOK(SzReadNumber32(sd, &bp->OutIndex));
+ int result = SzReadNumber32(sd, &bp->InIndex);
+
+ if (result != 0)
+ return result;
+ result = SzReadNumber32(sd, &bp->OutIndex);
+ if (result != 0)
+ return result;
}
if (numInStreams < numBindPairs)
@@ -608,7 +728,9 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
else
for (i = 0; i < numPackStreams; i++)
{
- RINOK(SzReadNumber32(sd, folder->PackStreams + i));
+ int result = SzReadNumber32(sd, folder->PackStreams + i);
+ if (result != 0)
+ return result;
}
return SZ_OK;
}
@@ -621,10 +743,21 @@ static SRes SzReadUnpackInfo(
ISzAlloc *allocTemp)
{
uint32_t i;
- RINOK(SzWaitAttribute(sd, k7zIdFolder));
- RINOK(SzReadNumber32(sd, numFolders));
+ int result = SzWaitAttribute(sd, k7zIdFolder);
+
+ if (result != 0)
+ return result;
+
+ result = SzReadNumber32(sd, numFolders);
+
+ if (result != 0)
+ return result;
+
{
- RINOK(SzReadSwitch(sd));
+ result = SzReadSwitch(sd);
+
+ if (result != 0)
+ return result;
MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);
@@ -633,11 +766,17 @@ static SRes SzReadUnpackInfo(
for (i = 0; i < *numFolders; i++)
{
- RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));
+ result = SzGetNextFolderItem(sd, (*folders) + i, alloc);
+
+ if (result != 0)
+ return result;
}
}
- RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));
+ result = SzWaitAttribute(sd, k7zIdCodersUnpackSize);
+
+ if (result != 0)
+ return result;
for (i = 0; i < *numFolders; i++)
{
@@ -649,22 +788,27 @@ static SRes SzReadUnpackInfo(
for (j = 0; j < numOutStreams; j++)
{
- RINOK(SzReadNumber(sd, folder->UnpackSizes + j));
+ int result = SzReadNumber(sd, folder->UnpackSizes + j);
+ if (result != 0)
+ return result;
}
}
for (;;)
{
uint64_t type;
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
if (type == k7zIdEnd)
return SZ_OK;
if (type == k7zIdCRC)
{
- SRes res;
uint8_t *crcsDefined = 0;
- uint32_t *crcs = 0;
- res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);
+ uint32_t *crcs = 0;
+ SRes res = SzReadHashDigests(
+ sd, *numFolders, &crcsDefined, &crcs, allocTemp);
+
if (res == SZ_OK)
{
for (i = 0; i < *numFolders; i++)
@@ -676,10 +820,13 @@ static SRes SzReadUnpackInfo(
}
IAlloc_Free(allocTemp, crcs);
IAlloc_Free(allocTemp, crcsDefined);
- RINOK(res);
+ if (res != 0)
+ return res;
continue;
}
- RINOK(SzSkeepData(sd));
+ result = SzSkeepData(sd);
+ if (result != 0)
+ return result;
}
}
@@ -693,9 +840,10 @@ static SRes SzReadSubStreamsInfo(
uint32_t **digests,
ISzAlloc *allocTemp)
{
- uint64_t type = 0;
+ int result;
uint32_t i;
- uint32_t si = 0;
+ uint64_t type = 0;
+ uint32_t si = 0;
uint32_t numDigests = 0;
for (i = 0; i < numFolders; i++)
@@ -704,16 +852,21 @@ static SRes SzReadSubStreamsInfo(
for (;;)
{
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
if (type == k7zIdNumUnpackStream)
{
*numUnpackStreams = 0;
for (i = 0; i < numFolders; i++)
{
- uint32_t numStreams;
- RINOK(SzReadNumber32(sd, &numStreams));
- folders[i].NumUnpackStreams = numStreams;
- *numUnpackStreams += numStreams;
+ uint32_t numStreams = 0;
+ int result = SzReadNumber32(sd, &numStreams);
+
+ if (result != 0)
+ return result;
+ folders[i].NumUnpackStreams = numStreams;
+ *numUnpackStreams += numStreams;
}
continue;
}
@@ -721,23 +874,28 @@ static SRes SzReadSubStreamsInfo(
break;
if (type == k7zIdEnd)
break;
- RINOK(SzSkeepData(sd));
+ result = SzSkeepData(sd);
+ if (result != 0)
+ return result;
}
if (*numUnpackStreams == 0)
{
- *unpackSizes = 0;
+ *unpackSizes = 0;
*digestsDefined = 0;
- *digests = 0;
+ *digests = 0;
}
else
{
*unpackSizes = (uint64_t *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(uint64_t));
- RINOM(*unpackSizes);
+ if (*unpackSizes == 0)
+ return SZ_ERROR_MEM;
*digestsDefined = (uint8_t *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(uint8_t));
- RINOM(*digestsDefined);
+ if (*digestsDefined == 0)
+ return SZ_ERROR_MEM;
*digests = (uint32_t *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(uint32_t));
- RINOM(*digests);
+ if (*digests == 0)
+ return SZ_ERROR_MEM;
}
for (i = 0; i < numFolders; i++)
@@ -755,15 +913,20 @@ static SRes SzReadSubStreamsInfo(
for (j = 1; j < numSubstreams; j++)
{
uint64_t size;
- RINOK(SzReadNumber(sd, &size));
+ int result = SzReadNumber(sd, &size);
+
+ if (result != 0)
+ return result;
(*unpackSizes)[si++] = size;
- sum += size;
+ sum += size;
}
(*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;
}
if (type == k7zIdSize)
{
- RINOK(SzReadID(sd, &type));
+ result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
}
for (i = 0; i < *numUnpackStreams; i++)
@@ -816,15 +979,20 @@ static SRes SzReadSubStreamsInfo(
}
IAlloc_Free(allocTemp, digestsDefined2);
IAlloc_Free(allocTemp, digests2);
- RINOK(res);
+ if (res != 0)
+ return res;
}
else if (type == k7zIdEnd)
return SZ_OK;
else
{
- RINOK(SzSkeepData(sd));
+ result = SzSkeepData(sd);
+ if (result != 0)
+ return result;
}
- RINOK(SzReadID(sd, &type));
+ result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
}
}
@@ -843,7 +1011,10 @@ static SRes SzReadStreamsInfo(
for (;;)
{
uint64_t type;
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+
+ if (result != 0)
+ return result;
if ((uint64_t)(int)type != type)
return SZ_ERROR_UNSUPPORTED;
switch((int)type)
@@ -852,19 +1023,26 @@ static SRes SzReadStreamsInfo(
return SZ_OK;
case k7zIdPackInfo:
{
- RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
- &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));
+ int result = SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
+ &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc);
+ if (result != 0)
+ return result;
+
break;
}
case k7zIdUnpackInfo:
{
- RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));
+ int result = SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp);
+ if (result != 0)
+ return result;
break;
}
case k7zIdSubStreamsInfo:
{
- RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
- numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));
+ int result = SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
+ numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp);
+ if (result != 0)
+ return result;
break;
}
default:
@@ -873,20 +1051,24 @@ static SRes SzReadStreamsInfo(
}
}
-size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, uint16_t *dest)
+size_t SzArEx_GetFileNameUtf16(const CSzArEx *p,
+ size_t fileIndex, uint16_t *dest)
{
- size_t len = p->FileNameOffsets[fileIndex + 1] - p->FileNameOffsets[fileIndex];
+ size_t len = p->FileNameOffsets[fileIndex + 1] -
+ p->FileNameOffsets[fileIndex];
if (dest != 0)
{
size_t i;
- const uint8_t *src = p->FileNames.data + (p->FileNameOffsets[fileIndex] * 2);
+ const uint8_t *src = p->FileNames.data +
+ (p->FileNameOffsets[fileIndex] * 2);
for (i = 0; i < len; i++)
dest[i] = GetUi16(src + i * 2);
}
return len;
}
-static SRes SzReadFileNames(const uint8_t *p, size_t size, uint32_t numFiles, size_t *sizes)
+static SRes SzReadFileNames(const uint8_t *p,
+ size_t size, uint32_t numFiles, size_t *sizes)
{
uint32_t i;
size_t pos = 0;
@@ -919,33 +1101,43 @@ static SRes SzReadHeader2(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
+ uint32_t i;
uint64_t type;
uint32_t numUnpackStreams = 0;
- uint32_t numFiles = 0;
- CSzFileItem *files = 0;
- uint32_t numEmptyStreams = 0;
- uint32_t i;
+ uint32_t numFiles = 0;
+ CSzFileItem *files = 0;
+ uint32_t numEmptyStreams = 0;
+ int result = SzReadID(sd, &type);
- RINOK(SzReadID(sd, &type));
+ if (result != 0)
+ return result;
if (type == k7zIdArchiveProperties)
{
- RINOK(SzReadArchiveProperties(sd));
- RINOK(SzReadID(sd, &type));
+ result = SzReadArchiveProperties(sd);
+ if (result != 0)
+ return result;
+ result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
}
if (type == k7zIdMainStreamsInfo)
{
- RINOK(SzReadStreamsInfo(sd,
+ result = SzReadStreamsInfo(sd,
&p->dataPos,
&p->db,
&numUnpackStreams,
unpackSizes,
digestsDefined,
- digests, allocMain, allocTemp));
+ digests, allocMain, allocTemp);
+ if (result != 0)
+ return result;
p->dataPos += p->startPosAfterHeader;
- RINOK(SzReadID(sd, &type));
+ result = SzReadID(sd, &type);
+ if (result != 0)
+ return result;
}
if (type == k7zIdEnd)
@@ -953,7 +1145,9 @@ static SRes SzReadHeader2(
if (type != k7zIdFilesInfo)
return SZ_ERROR_ARCHIVE;
- RINOK(SzReadNumber32(sd, &numFiles));
+ result = SzReadNumber32(sd, &numFiles);
+ if (result != 0)
+ return result;
p->db.NumFiles = numFiles;
MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);
@@ -965,37 +1159,54 @@ static SRes SzReadHeader2(
for (;;)
{
uint64_t size;
- RINOK(SzReadID(sd, &type));
+ int result = SzReadID(sd, &type);
+
+ if (result != 0)
+ return result;
if (type == k7zIdEnd)
break;
- RINOK(SzReadNumber(sd, &size));
+
+ result = SzReadNumber(sd, &size);
+
+ if (result != 0)
+ return result;
if (size > sd->Size)
return SZ_ERROR_ARCHIVE;
+
if ((uint64_t)(int)type != type)
{
- RINOK(SzSkeepDataSize(sd, size));
+ int result = SzSkeepDataSize(sd, size);
+ if (result != 0)
+ return result;
}
else
switch((int)type)
{
case k7zIdName:
{
- size_t namesSize;
- RINOK(SzReadSwitch(sd));
- namesSize = (size_t)size - 1;
+ int result = SzReadSwitch(sd);
+ size_t namesSize = (size_t)size - 1;
+ if (result != 0)
+ return result;
if ((namesSize & 1) != 0)
return SZ_ERROR_ARCHIVE;
if (!Buf_Create(&p->FileNames, namesSize, allocMain))
return SZ_ERROR_MEM;
MY_ALLOC(size_t, p->FileNameOffsets, numFiles + 1, allocMain);
memcpy(p->FileNames.data, sd->Data, namesSize);
- RINOK(SzReadFileNames(sd->Data, namesSize >> 1, numFiles, p->FileNameOffsets))
- RINOK(SzSkeepDataSize(sd, namesSize));
+ result = SzReadFileNames(sd->Data, namesSize >> 1, numFiles, p->FileNameOffsets);
+ if (result != 0)
+ return result;
+ result = SzSkeepDataSize(sd, namesSize);
+ if (result != 0)
+ return result;
break;
}
case k7zIdEmptyStream:
{
- RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));
+ int result = SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp);
+ if (result != 0)
+ return result;
numEmptyStreams = 0;
for (i = 0; i < numFiles; i++)
if ((*emptyStreamVector)[i])
@@ -1004,22 +1215,31 @@ static SRes SzReadHeader2(
}
case k7zIdEmptyFile:
{
- RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));
+ int result = SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp);
+ if (result != 0)
+ return result;
break;
}
case k7zIdWinAttributes:
{
- RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));
- RINOK(SzReadSwitch(sd));
+ int result = SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp);
+ if (result != 0)
+ return result;
+ result = SzReadSwitch(sd);
+ if (result != 0)
+ return result;
+
for (i = 0; i < numFiles; i++)
{
- CSzFileItem *f = &files[i];
- uint8_t defined = (*lwtVector)[i];
+ CSzFileItem *f = &files[i];
+ uint8_t defined = (*lwtVector)[i];
f->AttribDefined = defined;
- f->Attrib = 0;
+ f->Attrib = 0;
if (defined)
{
- RINOK(SzReaduint32_t(sd, &f->Attrib));
+ result = SzReaduint32_t(sd, &f->Attrib);
+ if (result != 0)
+ return result;
}
}
IAlloc_Free(allocTemp, *lwtVector);
@@ -1028,18 +1248,28 @@ static SRes SzReadHeader2(
}
case k7zIdMTime:
{
- RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));
- RINOK(SzReadSwitch(sd));
+ int result = SzReadBoolVector2(sd,
+ numFiles, lwtVector, allocTemp);
+ if (result != 0)
+ return result;
+ result = SzReadSwitch(sd);
+ if (result != 0)
+ return result;
+
for (i = 0; i < numFiles; i++)
{
- CSzFileItem *f = &files[i];
+ CSzFileItem *f = &files[i];
uint8_t defined = (*lwtVector)[i];
f->MTimeDefined = defined;
- f->MTime.Low = f->MTime.High = 0;
+ f->MTime.Low = f->MTime.High = 0;
if (defined)
{
- RINOK(SzReaduint32_t(sd, &f->MTime.Low));
- RINOK(SzReaduint32_t(sd, &f->MTime.High));
+ result = SzReaduint32_t(sd, &f->MTime.Low);
+ if (result != 0)
+ return result;
+ result = SzReaduint32_t(sd, &f->MTime.High);
+ if (result != 0)
+ return result;
}
}
IAlloc_Free(allocTemp, *lwtVector);
@@ -1048,27 +1278,31 @@ static SRes SzReadHeader2(
}
default:
{
- RINOK(SzSkeepDataSize(sd, size));
+ result = SzSkeepDataSize(sd, size);
+ if (result != 0)
+ return result;
}
}
}
{
uint32_t emptyFileIndex = 0;
- uint32_t sizeIndex = 0;
+ uint32_t sizeIndex = 0;
for (i = 0; i < numFiles; i++)
{
- CSzFileItem *file = files + i;
- file->IsAnti = 0;
+ CSzFileItem *file = files + i;
+ file->IsAnti = 0;
+
if (*emptyStreamVector == 0)
- file->HasStream = 1;
+ file->HasStream = 1;
else
- file->HasStream = (uint8_t)((*emptyStreamVector)[i] ? 0 : 1);
+ file->HasStream = (uint8_t)((*emptyStreamVector)[i] ? 0 : 1);
+
if (file->HasStream)
{
- file->IsDir = 0;
- file->Size = (*unpackSizes)[sizeIndex];
- file->Crc = (*digests)[sizeIndex];
+ file->IsDir = 0;
+ file->Size = (*unpackSizes)[sizeIndex];
+ file->Crc = (*digests)[sizeIndex];
file->CrcDefined = (uint8_t)(*digestsDefined)[sizeIndex];
sizeIndex++;
}
@@ -1077,10 +1311,11 @@ static SRes SzReadHeader2(
if (*emptyFileVector == 0)
file->IsDir = 1;
else
- file->IsDir = (uint8_t)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);
+ file->IsDir = (uint8_t)
+ ((*emptyFileVector)[emptyFileIndex] ? 0 : 1);
emptyFileIndex++;
- file->Size = 0;
- file->Crc = 0;
+ file->Size = 0;
+ file->Crc = 0;
file->CrcDefined = 0;
}
}
@@ -1094,13 +1329,13 @@ static SRes SzReadHeader(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
- uint64_t *unpackSizes = 0;
- uint8_t *digestsDefined = 0;
- uint32_t *digests = 0;
+ uint64_t *unpackSizes = 0;
+ uint8_t *digestsDefined = 0;
+ uint32_t *digests = 0;
uint8_t *emptyStreamVector = 0;
- uint8_t *emptyFileVector = 0;
- uint8_t *lwtVector = 0;
- SRes res = SzReadHeader2(p, sd,
+ uint8_t *emptyFileVector = 0;
+ uint8_t *lwtVector = 0;
+ SRes res = SzReadHeader2(p, sd,
&unpackSizes, &digestsDefined, &digests,
&emptyStreamVector, &emptyFileVector, &lwtVector,
allocMain, allocTemp);
@@ -1124,25 +1359,29 @@ static SRes SzReadAndDecodePackedStreams2(
uint32_t **digests,
ISzAlloc *allocTemp)
{
-
- uint32_t numUnpackStreams = 0;
- uint64_t dataStartPos;
- CSzFolder *folder;
- uint64_t unpackSize;
SRes res;
-
- RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
+ CSzFolder *folder = NULL;
+ uint64_t dataStartPos = 0;
+ uint64_t unpackSize = 0;
+ uint32_t numUnpackStreams = 0;
+ int result = SzReadStreamsInfo(sd, &dataStartPos, p,
&numUnpackStreams, unpackSizes, digestsDefined, digests,
- allocTemp, allocTemp));
+ allocTemp, allocTemp);
+
+ if (result != 0)
+ return result;
dataStartPos += baseOffset;
if (p->NumFolders != 1)
return SZ_ERROR_ARCHIVE;
- folder = p->Folders;
+ folder = p->Folders;
unpackSize = SzFolder_GetUnpackSize(folder);
- RINOK(LookInStream_SeekTo(inStream, dataStartPos));
+ result = LookInStream_SeekTo(inStream, dataStartPos);
+
+ if (result != 0)
+ return result;
if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
return SZ_ERROR_MEM;
@@ -1150,7 +1389,8 @@ static SRes SzReadAndDecodePackedStreams2(
res = SzFolder_Decode(folder, p->PackSizes,
inStream, dataStartPos,
outBuffer->data, (size_t)unpackSize, allocTemp);
- RINOK(res);
+ if (res != 0)
+ return res;
if (folder->UnpackCRCDefined)
if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)
return SZ_ERROR_CRC;
@@ -1165,14 +1405,17 @@ static SRes SzReadAndDecodePackedStreams(
ISzAlloc *allocTemp)
{
CSzAr p;
- uint64_t *unpackSizes = 0;
- uint8_t *digestsDefined = 0;
- uint32_t *digests = 0;
SRes res;
+ uint64_t *unpackSizes = 0;
+ uint8_t *digestsDefined = 0;
+ uint32_t *digests = 0;
+
SzAr_Init(&p);
+
res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,
&p, &unpackSizes, &digestsDefined, &digests,
allocTemp);
+
SzAr_Free(&p, allocTemp);
IAlloc_Free(allocTemp, unpackSizes);
IAlloc_Free(allocTemp, digestsDefined);
@@ -1186,27 +1429,33 @@ static SRes SzArEx_Open2(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
+ SRes res;
+ CBuf buffer;
uint8_t header[k7zStartHeaderSize];
- int64_t startArcPos;
uint64_t nextHeaderOffset, nextHeaderSize;
size_t nextHeaderSizeT;
uint32_t nextHeaderCRC;
- CBuf buffer;
- SRes res;
+ int64_t startArcPos = 0;
+ int result = inStream->Seek(inStream, &startArcPos, SZ_SEEK_CUR);
- startArcPos = 0;
- RINOK(inStream->Seek(inStream, &startArcPos, SZ_SEEK_CUR));
+ if (result != 0)
+ return result;
- RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));
+ result = LookInStream_Read2(inStream, header,
+ k7zStartHeaderSize,
+ SZ_ERROR_NO_ARCHIVE);
+
+ if (result != 0)
+ return result;
if (!TestSignatureCandidate(header))
return SZ_ERROR_NO_ARCHIVE;
if (header[6] != k7zMajorVersion)
return SZ_ERROR_UNSUPPORTED;
- nextHeaderOffset = GetUi64(header + 12);
- nextHeaderSize = GetUi64(header + 20);
- nextHeaderCRC = GetUi32(header + 28);
+ nextHeaderOffset = GetUi64(header + 12);
+ nextHeaderSize = GetUi64(header + 20);
+ nextHeaderCRC = GetUi32(header + 28);
p->startPosAfterHeader = startArcPos + k7zStartHeaderSize;
@@ -1224,14 +1473,19 @@ static SRes SzArEx_Open2(
{
int64_t pos = 0;
- RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));
+ int result = inStream->Seek(inStream, &pos, SZ_SEEK_END);
+
+ if (result != 0)
+ return result;
if ((uint64_t)pos < startArcPos + nextHeaderOffset ||
(uint64_t)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset ||
(uint64_t)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
return SZ_ERROR_INPUT_EOF;
}
- RINOK(LookInStream_SeekTo(inStream, startArcPos + k7zStartHeaderSize + nextHeaderOffset));
+ result = LookInStream_SeekTo(inStream, startArcPos + k7zStartHeaderSize + nextHeaderOffset);
+ if (result != 0)
+ return result;
if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))
return SZ_ERROR_MEM;
@@ -1280,7 +1534,8 @@ static SRes SzArEx_Open2(
return res;
}
-SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
+SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
+ ISzAlloc *allocMain, ISzAlloc *allocTemp)
{
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK)
@@ -1301,32 +1556,35 @@ SRes SzArEx_Extract(
ISzAlloc *allocTemp)
{
uint32_t folderIndex = p->FileIndexToFolderIndexMap[fileIndex];
- SRes res = SZ_OK;
- *offset = 0;
- *outSizeProcessed = 0;
+ SRes res = SZ_OK;
+ *offset = 0;
+ *outSizeProcessed = 0;
+
if (folderIndex == (uint32_t)-1)
{
IAlloc_Free(allocMain, *outBuffer);
- *blockIndex = folderIndex;
- *outBuffer = 0;
+ *blockIndex = folderIndex;
+ *outBuffer = 0;
*outBufferSize = 0;
return SZ_OK;
}
if (*outBuffer == 0 || *blockIndex != folderIndex)
{
- CSzFolder *folder = p->db.Folders + folderIndex;
+ int result;
+ CSzFolder *folder = p->db.Folders + folderIndex;
uint64_t unpackSizeSpec = SzFolder_GetUnpackSize(folder);
- size_t unpackSize = (size_t)unpackSizeSpec;
- uint64_t startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
+ size_t unpackSize = (size_t)unpackSizeSpec;
+ uint64_t startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
if (unpackSize != unpackSizeSpec)
return SZ_ERROR_MEM;
*blockIndex = folderIndex;
IAlloc_Free(allocMain, *outBuffer);
*outBuffer = 0;
-
- RINOK(LookInStream_SeekTo(inStream, startOffset));
+ result = LookInStream_SeekTo(inStream, startOffset);
+ if (result != 0)
+ return result;
if (res == SZ_OK)
{
@@ -1337,6 +1595,7 @@ SRes SzArEx_Extract(
if (*outBuffer == 0)
res = SZ_ERROR_MEM;
}
+
if (res == SZ_OK)
{
res = SzFolder_Decode(folder,
@@ -1354,6 +1613,7 @@ SRes SzArEx_Extract(
}
}
}
+
if (res == SZ_OK)
{
uint32_t i;
diff --git a/deps/7zip/7zStream.c b/deps/7zip/7zStream.c
index 1fc86d064c..1aac4d777b 100644
--- a/deps/7zip/7zStream.c
+++ b/deps/7zip/7zStream.c
@@ -7,18 +7,29 @@
#include "7zTypes.h"
-SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf);
+SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf)
+{
+ size_t processed = 1;
+ int result = stream->Read(stream, buf, &processed);
+ if (result != 0)
+ return result;
+ if (processed != 1)
+ return SZ_ERROR_INPUT_EOF;
+ return SZ_OK;
+}
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
- RINOK(stream->Read(stream, buf, &processed));
+ int result = stream->Read(stream, buf, &processed);
+ if (result != 0)
+ return result;
if (processed == 0)
return errorType;
- buf = (void *)((uint8_t *)buf + processed);
- size -= processed;
+ buf = (void *)((uint8_t *)buf + processed);
+ size -= processed;
}
return SZ_OK;
}
@@ -28,12 +39,6 @@ SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
}
-SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf)
-{
- size_t processed = 1;
- RINOK(stream->Read(stream, buf, &processed));
- return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
-}
SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset)
{
@@ -43,24 +48,30 @@ SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset)
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
{
+ int result;
const void *lookBuf;
if (*size == 0)
return SZ_OK;
- RINOK(stream->Look(stream, &lookBuf, size));
+ result = stream->Look(stream, &lookBuf, size);
+ if (result != 0)
+ return result;
memcpy(buf, lookBuf, *size);
return stream->Skip(stream, *size);
}
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
+SRes LookInStream_Read2(ILookInStream *stream,
+ void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
- RINOK(stream->Read(stream, buf, &processed));
+ int result = stream->Read(stream, buf, &processed);
+ if (result != 0)
+ return result;
if (processed == 0)
return errorType;
- buf = (void *)((uint8_t *)buf + processed);
- size -= processed;
+ buf = (void *)((uint8_t *)buf + processed);
+ size -= processed;
}
return SZ_OK;
}
diff --git a/deps/7zip/7zTypes.h b/deps/7zip/7zTypes.h
index 7d2217d891..6332d868a8 100644
--- a/deps/7zip/7zTypes.h
+++ b/deps/7zip/7zTypes.h
@@ -41,13 +41,9 @@ EXTERN_C_BEGIN
#define SZ_ERROR_ARCHIVE 16
#define SZ_ERROR_NO_ARCHIVE 17
-typedef int SRes;
+typedef int64_t SRes;
-#ifdef _WIN32
-typedef unsigned WRes;
-#else
-typedef int WRes;
-#endif
+typedef int64_t WRes;
#ifndef RINOK
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
diff --git a/deps/7zip/CpuArch.h b/deps/7zip/CpuArch.h
index fc9ee527cb..c26a5a99bd 100644
--- a/deps/7zip/CpuArch.h
+++ b/deps/7zip/CpuArch.h
@@ -11,9 +11,10 @@
extern "C" {
#endif
-/*
-MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
-If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
+/* MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and
+ CPU supports unaligned memory accesses.
+ If MY_CPU_LE_UNALIGN is not defined, we don't know
+ about these properties of platform.
*/
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
@@ -48,23 +49,6 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
#define MY_CPU_LE_UNALIGN
#endif
-#ifdef MY_CPU_LE_UNALIGN
-
-#define GetUi16(p) (*(const uint16_t *)(p))
-#define GetUi32(p) (*(const uint32_t *)(p))
-#define GetUi64(p) (*(const uint64_t *)(p))
-#else
-#define GetUi16(p) (((const uint8_t *)(p))[0] | ((uint16_t)((const uint8_t *)(p))[1] << 8))
-
-#define GetUi32(p) ( \
- ((const uint8_t *)(p))[0] | \
- ((uint32_t)((const uint8_t *)(p))[1] << 8) | \
- ((uint32_t)((const uint8_t *)(p))[2] << 16) | \
- ((uint32_t)((const uint8_t *)(p))[3] << 24))
-
-#define GetUi64(p) (GetUi32(p) | ((uint64_t)GetUi32(((const uint8_t *)(p)) + 4) << 32))
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/7zip/Lzma2Dec.c b/deps/7zip/Lzma2Dec.c
index 5b8a61c7d5..0a4ed84907 100644
--- a/deps/7zip/Lzma2Dec.c
+++ b/deps/7zip/Lzma2Dec.c
@@ -66,14 +66,18 @@ static SRes Lzma2Dec_GetOldProps(uint8_t prop, uint8_t *props)
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, uint8_t prop, ISzAlloc *alloc)
{
uint8_t props[LZMA_PROPS_SIZE];
- RINOK(Lzma2Dec_GetOldProps(prop, props));
+ int result = Lzma2Dec_GetOldProps(prop, props);
+ if (result != 0)
+ return result;
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
}
SRes Lzma2Dec_Allocate(CLzma2Dec *p, uint8_t prop, ISzAlloc *alloc)
{
uint8_t props[LZMA_PROPS_SIZE];
- RINOK(Lzma2Dec_GetOldProps(prop, props));
+ int result = Lzma2Dec_GetOldProps(prop, props);
+ if (result != 0)
+ return result;
return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
}
@@ -259,7 +263,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, size_t dicLimit,
outSizeProcessed = p->decoder.dicPos - dicPos;
p->unpackSize -= (uint32_t)outSizeProcessed;
- RINOK(res);
+ if (res != 0)
+ return res;
if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
return res;
@@ -321,8 +326,9 @@ SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, uint8_t *dest, size_t *destLen, const ui
SRes Lzma2Decode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
uint8_t prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
{
- CLzma2Dec decoder;
SRes res;
+ int result;
+ CLzma2Dec decoder;
size_t outSize = *destLen, inSize = *srcLen;
uint8_t props[LZMA_PROPS_SIZE];
@@ -333,8 +339,12 @@ SRes Lzma2Decode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *src
decoder.decoder.dic = dest;
decoder.decoder.dicBufSize = outSize;
- RINOK(Lzma2Dec_GetOldProps(prop, props));
- RINOK(LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc));
+ result = Lzma2Dec_GetOldProps(prop, props);
+ if (result != 0)
+ return result;
+ result = LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc);
+ if (result != 0)
+ return result;
*srcLen = inSize;
res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);
diff --git a/deps/7zip/LzmaDec.c b/deps/7zip/LzmaDec.c
index 5325053939..909f6ac29d 100644
--- a/deps/7zip/LzmaDec.c
+++ b/deps/7zip/LzmaDec.c
@@ -494,6 +494,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
{
do
{
+ int result;
size_t limit2 = limit;
if (p->checkDicSize == 0)
{
@@ -501,12 +502,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
if (limit - p->dicPos > rem)
limit2 = p->dicPos + rem;
}
- RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
+ result = LzmaDec_DecodeReal(p, limit2, bufLimit);
+ if (result != 0)
+ return result;
if (p->processedPos >= p->prop.dicSize)
p->checkDicSize = p->prop.dicSize;
LzmaDec_WriteRem(p, limit);
}
- while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
+ while (
+ p->dicPos < limit &&
+ p->buf < bufLimit &&
+ p->remainLen < kMatchSpecLenStart);
if (p->remainLen > kMatchSpecLenStart)
{
@@ -517,101 +523,108 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uin
typedef enum
{
- DUMMY_ERROR, /* unexpected end of input stream */
+ DUMMY_ERROR = 0, /* unexpected end of input stream */
DUMMY_LIT,
DUMMY_MATCH,
DUMMY_REP
} ELzmaDummy;
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t inSize)
+static ELzmaDummy LzmaDec_TryDummy(
+ const CLzmaDec *p, const uint8_t *buf, size_t inSize)
{
- uint32_t range = p->range;
- uint32_t codes = p->code;
- const uint8_t *bufLimit = buf + inSize;
- uint16_t *probs = p->probs;
- unsigned state = p->state;
ELzmaDummy res;
+ uint32_t bound;
+ unsigned ttt;
+ uint32_t range = p->range;
+ uint32_t codes = p->code;
+ const uint8_t *bufLimit = buf + inSize;
+ uint16_t *probs = p->probs;
+ unsigned state = p->state;
+ unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
+ uint16_t *prob = probs + IsMatch +
+ (state << kNumPosBitsMax) + posState;
+ IF_BIT_0_CHECK(prob)
{
- uint16_t *prob;
- uint32_t bound;
- unsigned ttt;
- unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
+ UPDATE_0_CHECK
- prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
+ /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
+
+ prob = probs + Literal;
+ if (p->checkDicSize != 0 || p->processedPos != 0)
+ prob += (LZMA_LIT_SIZE *
+ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+ (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+
+ if (state < kNumLitStates)
{
- UPDATE_0_CHECK
-
- /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
-
- prob = probs + Literal;
- if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += (LZMA_LIT_SIZE *
- ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
- (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
-
- if (state < kNumLitStates)
- {
- unsigned symbol = 1;
- do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
- }
- else
- {
- unsigned matchuint8_t = p->dic[p->dicPos - p->reps[0] +
- ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
- unsigned offs = 0x100;
- unsigned symbol = 1;
- do
- {
- unsigned bit;
- uint16_t *probLit;
- matchuint8_t <<= 1;
- bit = (matchuint8_t & offs);
- probLit = prob + offs + bit + symbol;
- GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
- }
- while (symbol < 0x100);
- }
- res = DUMMY_LIT;
+ unsigned symbol = 1;
+ do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
}
else
{
- unsigned len;
- UPDATE_1_CHECK;
+ unsigned matchuint8_t = p->dic[p->dicPos - p->reps[0] +
+ ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
+ unsigned offs = 0x100;
+ unsigned symbol = 1;
+ do
+ {
+ unsigned bit;
+ uint16_t *probLit;
+ matchuint8_t <<= 1;
+ bit = (matchuint8_t & offs);
+ probLit = prob + offs + bit + symbol;
+ GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
+ }
+ while (symbol < 0x100);
+ }
+ res = DUMMY_LIT;
+ }
+ else
+ {
+ unsigned len;
+ UPDATE_1_CHECK;
- prob = probs + IsRep + state;
+ prob = probs + IsRep + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ state = 0;
+ prob = probs + LenCoder;
+ res = DUMMY_MATCH;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ res = DUMMY_REP;
+ prob = probs + IsRepG0 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
- state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
+ prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK;
+ NORMALIZE_CHECK;
+ return DUMMY_REP;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ }
}
else
{
UPDATE_1_CHECK;
- res = DUMMY_REP;
- prob = probs + IsRepG0 + state;
+ prob = probs + IsRepG1 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
- prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- NORMALIZE_CHECK;
- return DUMMY_REP;
- }
- else
- {
- UPDATE_1_CHECK;
- }
}
else
{
UPDATE_1_CHECK;
- prob = probs + IsRepG1 + state;
+ prob = probs + IsRepG2 + state;
IF_BIT_0_CHECK(prob)
{
UPDATE_0_CHECK;
@@ -619,92 +632,83 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t
else
{
UPDATE_1_CHECK;
- prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- }
}
}
- state = kNumStates;
- prob = probs + RepLenCoder;
}
+ state = kNumStates;
+ prob = probs + RepLenCoder;
+ }
+ {
+ unsigned limit, offset;
+ uint16_t *probLen = prob + LenChoice;
+ IF_BIT_0_CHECK(probLen)
{
- unsigned limit, offset;
- uint16_t *probLen = prob + LenChoice;
+ UPDATE_0_CHECK;
+ probLen = prob + LenLow + (posState << kLenNumLowBits);
+ offset = 0;
+ limit = 1 << kLenNumLowBits;
+ }
+ else
+ {
+ UPDATE_1_CHECK;
+ probLen = prob + LenChoice2;
IF_BIT_0_CHECK(probLen)
{
UPDATE_0_CHECK;
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- limit = 1 << kLenNumLowBits;
+ probLen = prob + LenMid + (posState << kLenNumMidBits);
+ offset = kLenNumLowSymbols;
+ limit = 1 << kLenNumMidBits;
}
else
{
UPDATE_1_CHECK;
- probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumMidBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- limit = 1 << kLenNumHighBits;
- }
+ probLen = prob + LenHigh;
+ offset = kLenNumLowSymbols + kLenNumMidSymbols;
+ limit = 1 << kLenNumHighBits;
}
- TREE_DECODE_CHECK(probLen, limit, len);
- len += offset;
}
+ TREE_DECODE_CHECK(probLen, limit, len);
+ len += offset;
+ }
- if (state < 4)
+ if (state < 4)
+ {
+ unsigned posSlot;
+ prob = probs + PosSlot +
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
+ kNumPosSlotBits);
+ TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
+ if (posSlot >= kStartPosModelIndex)
{
- unsigned posSlot;
- prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
+ int numDirectBits = ((posSlot >> 1) - 1);
+
+ /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
+
+ if (posSlot < kEndPosModelIndex)
{
- int numDirectBits = ((posSlot >> 1) - 1);
-
- /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
-
- if (posSlot < kEndPosModelIndex)
+ prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
+ }
+ else
+ {
+ numDirectBits -= kNumAlignBits;
+ do
{
- prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
+ NORMALIZE_CHECK
+ range >>= 1;
+ codes -= range & (((codes - range) >> 31) - 1);
+ /* if (codes >= range) codes -= range; */
}
- else
+ while (--numDirectBits != 0);
+ prob = probs + Align;
+ numDirectBits = kNumAlignBits;
+ }
+ {
+ unsigned i = 1;
+ do
{
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE_CHECK
- range >>= 1;
- codes -= range & (((codes - range) >> 31) - 1);
- /* if (codes >= range) codes -= range; */
- }
- while (--numDirectBits != 0);
- prob = probs + Align;
- numDirectBits = kNumAlignBits;
- }
- {
- unsigned i = 1;
- do
- {
- GET_BIT_CHECK(prob + i, i);
- }
- while (--numDirectBits != 0);
+ GET_BIT_CHECK(prob + i, i);
}
+ while (--numDirectBits != 0);
}
}
}
@@ -713,26 +717,27 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t
return res;
}
-
static void LzmaDec_InitRc(CLzmaDec *p, const uint8_t *data)
{
- p->code = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 8) | ((uint32_t)data[4]);
- p->range = 0xFFFFFFFF;
+ p->code = (
+ (uint32_t)data[1] << 24) |
+ ((uint32_t)data[2] << 16) |
+ ((uint32_t)data[3] << 8) |
+ ((uint32_t)data[4]);
+ p->range = 0xFFFFFFFF;
p->needFlush = 0;
}
-void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState);
-
void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState)
{
- p->needFlush = 1;
- p->remainLen = 0;
- p->tempBufSize = 0;
+ p->needFlush = 1;
+ p->remainLen = 0;
+ p->tempBufSize = 0;
if (initDic)
{
- p->processedPos = 0;
- p->checkDicSize = 0;
+ p->processedPos = 0;
+ p->checkDicSize = 0;
p->needInitState = 1;
}
if (initState)
@@ -747,17 +752,19 @@ void LzmaDec_Init(CLzmaDec *p)
static void LzmaDec_InitStateReal(CLzmaDec *p)
{
- uint32_t numProbs = Literal + ((uint32_t)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
uint32_t i;
- uint16_t *probs = p->probs;
+ uint32_t numProbs = Literal +
+ ((uint32_t)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
+ uint16_t *probs = p->probs;
for (i = 0; i < numProbs; i++)
- probs[i] = kBitModelTotal >> 1;
- p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
- p->needInitState = 0;
+ probs[i] = kBitModelTotal >> 1;
+ p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
+ p->state = 0;
+ p->needInitState = 0;
}
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_t *srcLen,
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit,
+ const uint8_t *src, size_t *srcLen,
ELzmaFinishMode finishMode, ELzmaStatus *status)
{
size_t inSize = *srcLen;
@@ -772,7 +779,8 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_
if (p->needFlush != 0)
{
- for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+ for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE;
+ (*srcLen)++, inSize--)
p->tempBuf[p->tempBufSize++] = *src++;
if (p->tempBufSize < RC_INIT_SIZE)
{
@@ -881,36 +889,37 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{
size_t outSize = *destLen;
- size_t inSize = *srcLen;
- *srcLen = *destLen = 0;
+ size_t inSize = *srcLen;
+ *srcLen = *destLen = 0;
+
for (;;)
{
- size_t inSizeCur = inSize, outSizeCur, dicPos;
- ELzmaFinishMode curFinishMode;
SRes res;
+ ELzmaFinishMode curFinishMode;
+ size_t inSizeCur = inSize, outSizeCur, dicPos;
if (p->dicPos == p->dicBufSize)
- p->dicPos = 0;
- dicPos = p->dicPos;
+ p->dicPos = 0;
+ dicPos = p->dicPos;
if (outSize > p->dicBufSize - dicPos)
{
- outSizeCur = p->dicBufSize;
+ outSizeCur = p->dicBufSize;
curFinishMode = LZMA_FINISH_ANY;
}
else
{
- outSizeCur = dicPos + outSize;
+ outSizeCur = dicPos + outSize;
curFinishMode = finishMode;
}
- res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
- src += inSizeCur;
- inSize -= inSizeCur;
- *srcLen += inSizeCur;
- outSizeCur = p->dicPos - dicPos;
+ res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
+ src += inSizeCur;
+ inSize -= inSizeCur;
+ *srcLen += inSizeCur;
+ outSizeCur = p->dicPos - dicPos;
memcpy(dest, p->dic + dicPos, outSizeCur);
- dest += outSizeCur;
- outSize -= outSizeCur;
- *destLen += outSizeCur;
+ dest += outSizeCur;
+ outSize -= outSizeCur;
+ *destLen += outSizeCur;
if (res != 0)
return res;
if (outSizeCur == 0 || outSize == 0)
@@ -944,25 +953,29 @@ SRes LzmaProps_Decode(CLzmaProps *p, const uint8_t *data, unsigned size)
if (size < LZMA_PROPS_SIZE)
return SZ_ERROR_UNSUPPORTED;
else
- dicSize = data[1] | ((uint32_t)data[2] << 8) | ((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24);
+ dicSize = data[1] |
+ ((uint32_t)data[2] << 8) |
+ ((uint32_t)data[3] << 16) |
+ ((uint32_t)data[4] << 24);
if (dicSize < LZMA_DIC_MIN)
dicSize = LZMA_DIC_MIN;
p->dicSize = dicSize;
- d = data[0];
+ d = data[0];
if (d >= (9 * 5 * 5))
return SZ_ERROR_UNSUPPORTED;
- p->lc = d % 9;
- d /= 9;
- p->pb = d / 5;
- p->lp = d % 5;
+ p->lc = d % 9;
+ d /= 9;
+ p->pb = d / 5;
+ p->lp = d % 5;
return SZ_OK;
}
-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
+static SRes LzmaDec_AllocateProbs2(
+ CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
{
uint32_t numProbs = LzmaProps_GetNumProbs(propNew);
if (p->probs == 0 || numProbs != p->numProbs)
@@ -976,22 +989,37 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
return SZ_OK;
}
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
+SRes LzmaDec_AllocateProbs(CLzmaDec *p,
+ const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
{
CLzmaProps propNew;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
- p->prop = propNew;
+ int result = LzmaProps_Decode(&propNew, props, propsSize);
+ if (result != 0)
+ return result;
+ result = LzmaDec_AllocateProbs2(p, &propNew, alloc);
+ if (result != 0)
+ return result;
+ p->prop = propNew;
return SZ_OK;
}
-SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
+SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props,
+ unsigned propsSize, ISzAlloc *alloc)
{
CLzmaProps propNew;
size_t dicBufSize;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+ int result = LzmaProps_Decode(&propNew, props, propsSize);
+
+ if (result != 0)
+ return result;
+
+ result = LzmaDec_AllocateProbs2(p, &propNew, alloc);
+
+ if (result != 0)
+ return result;
+
dicBufSize = propNew.dicSize;
+
if (p->dic == 0 || dicBufSize != p->dicBufSize)
{
LzmaDec_FreeDict(p, alloc);
@@ -1007,7 +1035,8 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISz
return SZ_OK;
}
-SRes LzmaDecode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
+SRes LzmaDecode(uint8_t *dest, size_t *destLen,
+ const uint8_t *src, size_t *srcLen,
const uint8_t *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc)
{
diff --git a/deps/7zip/LzmaEnc.c b/deps/7zip/LzmaEnc.c
index d66c0acb08..c05244a8a2 100644
--- a/deps/7zip/LzmaEnc.c
+++ b/deps/7zip/LzmaEnc.c
@@ -38,47 +38,66 @@
void LzmaEncProps_Init(CLzmaEncProps *p)
{
- p->level = 5;
- p->dictSize = p->mc = 0;
- p->reduceSize = (uint64_t)(int64_t)-1;
- p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
+ p->level = 5;
+ p->dictSize = p->mc = 0;
+ p->reduceSize = (uint64_t)(int64_t)-1;
+ p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
p->writeEndMark = 0;
}
void LzmaEncProps_Normalize(CLzmaEncProps *p)
{
int level = p->level;
- if (level < 0) level = 5;
- p->level = level;
+ if (level < 0)
+ level = 5;
+ p->level = level;
- if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
+ if (p->dictSize == 0)
+ p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
if (p->dictSize > p->reduceSize)
{
unsigned i;
for (i = 11; i <= 30; i++)
{
- if ((uint32_t)p->reduceSize <= ((uint32_t)2 << i)) { p->dictSize = ((uint32_t)2 << i); break; }
- if ((uint32_t)p->reduceSize <= ((uint32_t)3 << i)) { p->dictSize = ((uint32_t)3 << i); break; }
+ if ((uint32_t)p->reduceSize <= ((uint32_t)2 << i))
+ {
+ p->dictSize = ((uint32_t)2 << i);
+ break;
+ }
+ if ((uint32_t)p->reduceSize <= ((uint32_t)3 << i))
+ {
+ p->dictSize = ((uint32_t)3 << i);
+ break;
+ }
}
}
- if (p->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
+ if (p->lc < 0)
+ p->lc = 3;
+ if (p->lp < 0)
+ p->lp = 0;
+ if (p->pb < 0)
+ p->pb = 2;
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = 4;
- if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
+ if (p->algo < 0)
+ p->algo = (level < 5 ? 0 : 1);
+ if (p->fb < 0)
+ p->fb = (level < 7 ? 32 : 64);
+ if (p->btMode < 0)
+ p->btMode = (p->algo == 0 ? 0 : 1);
+ if (p->numHashBytes < 0)
+ p->numHashBytes = 4;
+ if (p->mc == 0)
+ p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
if (p->numThreads < 0)
- p->numThreads =
- #ifndef _7ZIP_ST
- ((p->btMode && p->algo) ? 2 : 1);
- #else
- 1;
- #endif
+ {
+#ifndef _7ZIP_ST
+ p->numThreads = ((p->btMode && p->algo) ? 2 : 1);
+#else
+ p->numThreads = 1;
+#endif
+ }
}
uint32_t LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
@@ -96,14 +115,14 @@ uint32_t LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
static void LzmaEnc_FastPosInit(unsigned char *g_FastPos)
{
unsigned slot;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
- g_FastPos += 2;
+ g_FastPos[0] = 0;
+ g_FastPos[1] = 1;
+ g_FastPos += 2;
for (slot = 2; slot < kNumLogBits * 2; slot++)
{
- size_t k = ((size_t)1 << ((slot >> 1) - 1));
size_t j;
+ size_t k = ((size_t)1 << ((slot >> 1) - 1));
for (j = 0; j < k; j++)
g_FastPos[j] = (unsigned char)slot;
g_FastPos += k;
@@ -244,123 +263,123 @@ typedef struct
typedef struct
{
- void *matchFinderObj;
- IMatchFinder matchFinder;
+ void *matchFinderObj;
+ IMatchFinder matchFinder;
- uint32_t optimumEndIndex;
- uint32_t optimumCurrentIndex;
+ uint32_t optimumEndIndex;
+ uint32_t optimumCurrentIndex;
- uint32_t longestMatchLength;
- uint32_t numPairs;
- uint32_t numAvail;
+ uint32_t longestMatchLength;
+ uint32_t numPairs;
+ uint32_t numAvail;
- uint32_t numFastBytes;
- uint32_t additionalOffset;
- uint32_t reps[LZMA_NUM_REPS];
- uint32_t state;
+ uint32_t numFastBytes;
+ uint32_t additionalOffset;
+ uint32_t reps[LZMA_NUM_REPS];
+ uint32_t state;
- unsigned lc, lp, pb;
- unsigned lpMask, pbMask;
- unsigned lclp;
+ unsigned lc, lp, pb;
+ unsigned lpMask, pbMask;
+ unsigned lclp;
- CLzmaProb *litProbs;
+ CLzmaProb *litProbs;
- bool fastMode;
- bool writeEndMark;
- bool finished;
- bool multiThread;
- bool needInit;
+ bool fastMode;
+ bool writeEndMark;
+ bool finished;
+ bool multiThread;
+ bool needInit;
- uint64_t nowPos64;
+ uint64_t nowPos64;
- uint32_t matchPriceCount;
- uint32_t alignPriceCount;
+ uint32_t matchPriceCount;
+ uint32_t alignPriceCount;
- uint32_t distTableSize;
+ uint32_t distTableSize;
- uint32_t dictSize;
- SRes result;
+ uint32_t dictSize;
+ SRes result;
- CRangeEnc rc;
+ CRangeEnc rc;
- #ifndef _7ZIP_ST
- bool mtMode;
- CMatchFinderMt matchFinderMt;
- #endif
+#ifndef _7ZIP_ST
+ bool mtMode;
+ CMatchFinderMt matchFinderMt;
+#endif
- CMatchFinder matchFinderBase;
+ CMatchFinder matchFinderBase;
- #ifndef _7ZIP_ST
- unsigned char pad[128];
- #endif
+#ifndef _7ZIP_ST
+ unsigned char pad[128];
+#endif
- COptimal opt[kNumOpts];
+ COptimal opt[kNumOpts];
- unsigned char g_FastPos[1 << kNumLogBits];
+ unsigned char g_FastPos[1 << kNumLogBits];
- uint32_t ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
- uint32_t matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
+ uint32_t ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+ uint32_t matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
- uint32_t posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
- uint32_t distancesPrices[kNumLenToPosStates][kNumFullDistances];
- uint32_t alignPrices[kAlignTableSize];
+ uint32_t posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+ uint32_t distancesPrices[kNumLenToPosStates][kNumFullDistances];
+ uint32_t alignPrices[kAlignTableSize];
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isRep[kNumStates];
+ CLzmaProb isRepG0[kNumStates];
+ CLzmaProb isRepG1[kNumStates];
+ CLzmaProb isRepG2[kNumStates];
+ CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+ CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+ CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
+ CLzmaProb posAlignEncoder[1 << kNumAlignBits];
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
+ CLenPriceEnc lenEnc;
+ CLenPriceEnc repLenEnc;
- CSaveState saveState;
+ CSaveState saveState;
- #ifndef _7ZIP_ST
- unsigned char pad2[128];
- #endif
+#ifndef _7ZIP_ST
+ unsigned char pad2[128];
+#endif
} CLzmaEnc;
void LzmaEnc_SaveState(CLzmaEncHandle pp)
{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CSaveState *dest = &p->saveState;
- int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
+ int i;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
+ CSaveState *dest = &p->saveState;
+ dest->lenEnc = p->lenEnc;
+ dest->repLenEnc = p->repLenEnc;
+ dest->state = p->state;
- for (i = 0; i < kNumStates; i++)
- {
- memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
- memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
- }
- for (i = 0; i < kNumLenToPosStates; i++)
- memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
- memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
- memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
- memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
- memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
- memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
- memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
- memcpy(dest->reps, p->reps, sizeof(p->reps));
- memcpy(dest->litProbs, p->litProbs, ((uint32_t)0x300 << p->lclp) * sizeof(CLzmaProb));
+ for (i = 0; i < kNumStates; i++)
+ {
+ memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
+ memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
+ }
+ for (i = 0; i < kNumLenToPosStates; i++)
+ memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
+ memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
+ memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
+ memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
+ memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
+ memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
+ memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
+ memcpy(dest->reps, p->reps, sizeof(p->reps));
+ memcpy(dest->litProbs, p->litProbs, ((uint32_t)0x300 << p->lclp) * sizeof(CLzmaProb));
}
void LzmaEnc_RestoreState(CLzmaEncHandle pp)
{
- CLzmaEnc *dest = (CLzmaEnc *)pp;
- const CSaveState *p = &dest->saveState;
int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
+ CLzmaEnc *dest = (CLzmaEnc *)pp;
+ const CSaveState *p = &dest->saveState;
+ dest->lenEnc = p->lenEnc;
+ dest->repLenEnc = p->repLenEnc;
+ dest->state = p->state;
for (i = 0; i < kNumStates; i++)
{
@@ -381,11 +400,13 @@ void LzmaEnc_RestoreState(CLzmaEncHandle pp)
SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
{
- CLzmaEnc *p = (CLzmaEnc *)pp;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
CLzmaEncProps props = *props2;
+
LzmaEncProps_Normalize(&props);
- if (props.lc > LZMA_LC_MAX
+ if (
+ props.lc > LZMA_LC_MAX
|| props.lp > LZMA_LP_MAX
|| props.pb > LZMA_PB_MAX
|| props.dictSize > ((uint64_t)1 << kDicLogSizeMaxCompress)
@@ -394,17 +415,17 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
p->dictSize = props.dictSize;
{
- unsigned fb = props.fb;
+ unsigned fb = props.fb;
if (fb < 5)
- fb = 5;
+ fb = 5;
if (fb > LZMA_MATCH_LEN_MAX)
- fb = LZMA_MATCH_LEN_MAX;
- p->numFastBytes = fb;
+ fb = LZMA_MATCH_LEN_MAX;
+ p->numFastBytes = fb;
}
- p->lc = props.lc;
- p->lp = props.lp;
- p->pb = props.pb;
- p->fastMode = (props.algo == 0);
+ p->lc = props.lc;
+ p->lp = props.lp;
+ p->pb = props.pb;
+ p->fastMode = (props.algo == 0);
p->matchFinderBase.btMode = (unsigned char)(props.btMode ? 1 : 0);
{
uint32_t numHashBytes = 4;
@@ -422,16 +443,16 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
p->writeEndMark = props.writeEndMark;
- #ifndef _7ZIP_ST
- /*
+#ifndef _7ZIP_ST
+#if 0
if (newMultiThread != _multiThread)
{
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
+ ReleaseMatchFinder();
+ _multiThread = newMultiThread;
}
- */
+#endif
p->multiThread = (props.numThreads > 1);
- #endif
+#endif
return SZ_OK;
}
@@ -449,8 +470,8 @@ static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11,
static void RangeEnc_Construct(CRangeEnc *p)
{
- p->outStream = NULL;
- p->bufBase = NULL;
+ p->outStream = NULL;
+ p->bufBase = NULL;
}
#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
@@ -458,112 +479,113 @@ static void RangeEnc_Construct(CRangeEnc *p)
#define RC_BUF_SIZE (1 << 16)
static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
{
- if (!p->bufBase)
- {
- p->bufBase = (unsigned char *)alloc->Alloc(alloc, RC_BUF_SIZE);
- if (!p->bufBase)
- return 0;
- p->bufLim = p->bufBase + RC_BUF_SIZE;
- }
- return 1;
+ if (!p->bufBase)
+ {
+ p->bufBase = (unsigned char *)alloc->Alloc(alloc, RC_BUF_SIZE);
+ if (!p->bufBase)
+ return 0;
+ p->bufLim = p->bufBase + RC_BUF_SIZE;
+ }
+ return 1;
}
static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
{
- alloc->Free(alloc, p->bufBase);
- p->bufBase = 0;
+ alloc->Free(alloc, p->bufBase);
+ p->bufBase = 0;
}
static void RangeEnc_Init(CRangeEnc *p)
{
- /* Stream.Init(); */
- p->low = 0;
- p->range = 0xFFFFFFFF;
- p->cacheSize = 1;
- p->cache = 0;
+ /* Stream.Init(); */
+ p->low = 0;
+ p->range = 0xFFFFFFFF;
+ p->cacheSize = 1;
+ p->cache = 0;
- p->buf = p->bufBase;
+ p->buf = p->bufBase;
- p->processed = 0;
- p->res = SZ_OK;
+ p->processed = 0;
+ p->res = SZ_OK;
}
static void RangeEnc_FlushStream(CRangeEnc *p)
{
- size_t num;
- if (p->res != SZ_OK)
- return;
- num = p->buf - p->bufBase;
- if (num != p->outStream->Write(p->outStream, p->bufBase, num))
- p->res = SZ_ERROR_WRITE;
- p->processed += num;
- p->buf = p->bufBase;
+ size_t num;
+ if (p->res != SZ_OK)
+ return;
+ num = p->buf - p->bufBase;
+ if (num != p->outStream->Write(p->outStream, p->bufBase, num))
+ p->res = SZ_ERROR_WRITE;
+ p->processed += num;
+ p->buf = p->bufBase;
}
static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
{
- if ((uint32_t)p->low < (uint32_t)0xFF000000 || (unsigned)(p->low >> 32) != 0)
- {
- unsigned char temp = p->cache;
- do
- {
- unsigned char *buf = p->buf;
- *buf++ = (unsigned char)(temp + (unsigned char)(p->low >> 32));
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- temp = 0xFF;
- }
- while (--p->cacheSize != 0);
- p->cache = (unsigned char)((uint32_t)p->low >> 24);
- }
- p->cacheSize++;
- p->low = (uint32_t)p->low << 8;
+ if ((uint32_t)p->low < (uint32_t)0xFF000000 || (unsigned)(p->low >> 32) != 0)
+ {
+ unsigned char temp = p->cache;
+ do
+ {
+ unsigned char *buf = p->buf;
+ *buf++ = (unsigned char)(temp + (unsigned char)(p->low >> 32));
+ p->buf = buf;
+ if (buf == p->bufLim)
+ RangeEnc_FlushStream(p);
+ temp = 0xFF;
+ }
+ while (--p->cacheSize != 0);
+ p->cache = (unsigned char)((uint32_t)p->low >> 24);
+ }
+ p->cacheSize++;
+ p->low = (uint32_t)p->low << 8;
}
static void RangeEnc_FlushData(CRangeEnc *p)
{
- int i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
+ int i;
+ for (i = 0; i < 5; i++)
+ RangeEnc_ShiftLow(p);
}
-static void RangeEnc_EncodeDirectBits(CRangeEnc *p, uint32_t value, unsigned numBits)
+static void RangeEnc_EncodeDirectBits(
+ CRangeEnc *p, uint32_t value, unsigned numBits)
{
- do
- {
- p->range >>= 1;
- p->low += p->range & (0 - ((value >> --numBits) & 1));
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
- }
- while (numBits != 0);
+ do
+ {
+ p->range >>= 1;
+ p->low += p->range & (0 - ((value >> --numBits) & 1));
+ if (p->range < kTopValue)
+ {
+ p->range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
+ }
+ while (numBits != 0);
}
static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, uint32_t symbol)
{
- uint32_t ttt = *prob;
- uint32_t newBound = (p->range >> kNumBitModelTotalBits) * ttt;
- if (symbol == 0)
- {
- p->range = newBound;
- ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
- }
- else
- {
- p->low += newBound;
- p->range -= newBound;
- ttt -= ttt >> kNumMoveBits;
- }
- *prob = (CLzmaProb)ttt;
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
+ uint32_t ttt = *prob;
+ uint32_t newBound = (p->range >> kNumBitModelTotalBits) * ttt;
+ if (symbol == 0)
+ {
+ p->range = newBound;
+ ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
+ }
+ else
+ {
+ p->low += newBound;
+ p->range -= newBound;
+ ttt -= ttt >> kNumMoveBits;
+ }
+ *prob = (CLzmaProb)ttt;
+ if (p->range < kTopValue)
+ {
+ p->range <<= 8;
+ RangeEnc_ShiftLow(p);
+ }
}
static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, uint32_t symbol)
@@ -627,101 +649,103 @@ static void LzmaEnc_InitPriceTables(uint32_t *ProbPrices)
#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-static uint32_t LitEnc_GetPrice(const CLzmaProb *probs, uint32_t symbol, const uint32_t *ProbPrices)
+static uint32_t LitEnc_GetPrice(
+ const CLzmaProb *probs, uint32_t symbol,
+ const uint32_t *ProbPrices)
{
- uint32_t price = 0;
- symbol |= 0x100;
- do
- {
- price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
- symbol <<= 1;
- }
- while (symbol < 0x10000);
- return price;
+ uint32_t price = 0;
+ symbol |= 0x100;
+ do
+ {
+ price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
+ symbol <<= 1;
+ }while (symbol < 0x10000);
+ return price;
}
static uint32_t LitEnc_GetPriceMatched(const CLzmaProb *probs, uint32_t symbol, uint32_t matchByte, const uint32_t *ProbPrices)
{
- uint32_t price = 0;
- uint32_t offs = 0x100;
- symbol |= 0x100;
- do
- {
- matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
- }
- while (symbol < 0x10000);
- return price;
+ uint32_t price = 0;
+ uint32_t offs = 0x100;
+ symbol |= 0x100;
+ do
+ {
+ matchByte <<= 1;
+ price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
+ symbol <<= 1;
+ offs &= ~(matchByte ^ symbol);
+ }while (symbol < 0x10000);
+ return price;
}
-static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, uint32_t symbol)
+static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs,
+ int numBitLevels, uint32_t symbol)
{
- uint32_t m = 1;
- int i;
- for (i = numBitLevels; i != 0;)
- {
- uint32_t bit;
- i--;
- bit = (symbol >> i) & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- }
+ uint32_t m = 1;
+ int i;
+ for (i = numBitLevels; i != 0;)
+ {
+ uint32_t bit;
+ i--;
+ bit = (symbol >> i) & 1;
+ RangeEnc_EncodeBit(rc, probs + m, bit);
+ m = (m << 1) | bit;
+ }
}
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, uint32_t symbol)
+static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs,
+ int numBitLevels, uint32_t symbol)
{
- uint32_t m = 1;
- int i;
- for (i = 0; i < numBitLevels; i++)
- {
- uint32_t bit = symbol & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- symbol >>= 1;
- }
+ uint32_t m = 1;
+ int i;
+ for (i = 0; i < numBitLevels; i++)
+ {
+ uint32_t bit = symbol & 1;
+ RangeEnc_EncodeBit(rc, probs + m, bit);
+ m = (m << 1) | bit;
+ symbol >>= 1;
+ }
}
-static uint32_t RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, uint32_t symbol, const uint32_t *ProbPrices)
+static uint32_t RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels,
+ uint32_t symbol, const uint32_t *ProbPrices)
{
- uint32_t price = 0;
- symbol |= (1 << numBitLevels);
- while (symbol != 1)
- {
- price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
- symbol >>= 1;
- }
- return price;
+ uint32_t price = 0;
+ symbol |= (1 << numBitLevels);
+ while (symbol != 1)
+ {
+ price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
+ symbol >>= 1;
+ }
+ return price;
}
static uint32_t RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, uint32_t symbol, const uint32_t *ProbPrices)
{
- uint32_t price = 0;
- uint32_t m = 1;
- int i;
- for (i = numBitLevels; i != 0; i--)
- {
- uint32_t bit = symbol & 1;
- symbol >>= 1;
- price += GET_PRICEa(probs[m], bit);
- m = (m << 1) | bit;
- }
- return price;
+ uint32_t price = 0;
+ uint32_t m = 1;
+ int i;
+ for (i = numBitLevels; i != 0; i--)
+ {
+ uint32_t bit = symbol & 1;
+ symbol >>= 1;
+ price += GET_PRICEa(probs[m], bit);
+ m = (m << 1) | bit;
+ }
+ return price;
}
-
static void LenEnc_Init(CLenEnc *p)
{
- unsigned i;
- p->choice = p->choice2 = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
- p->low[i] = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
- p->mid[i] = kProbInitValue;
- for (i = 0; i < kLenNumHighSymbols; i++)
- p->high[i] = kProbInitValue;
+ unsigned i;
+ p->choice = p->choice2 = kProbInitValue;
+ for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
+ p->low[i] = kProbInitValue;
+ for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
+ p->mid[i] = kProbInitValue;
+ for (i = 0; i < kLenNumHighSymbols; i++)
+ p->high[i] = kProbInitValue;
}
static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, uint32_t symbol, uint32_t posState)
@@ -1715,160 +1739,164 @@ void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, bool useLimits, uint32_t maxPackSize, uint32_t maxUnpackSize)
{
- uint32_t nowPos32, startPos32;
- if (p->needInit)
- {
- p->matchFinder.Init(p->matchFinderObj);
- p->needInit = 0;
- }
+ int result;
+ uint32_t nowPos32, startPos32;
+ if (p->needInit)
+ {
+ p->matchFinder.Init(p->matchFinderObj);
+ p->needInit = 0;
+ }
- if (p->finished)
- return p->result;
- RINOK(CheckErrors(p));
+ if (p->finished)
+ return p->result;
+ result = CheckErrors(p);
- nowPos32 = (uint32_t)p->nowPos64;
- startPos32 = nowPos32;
+ if (result != 0)
+ return result;
- if (p->nowPos64 == 0)
- {
- uint32_t numPairs;
- unsigned char curByte;
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- return Flush(p, nowPos32);
- ReadMatchDistances(p, &numPairs);
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
- p->state = kLiteralNextStates[p->state];
- curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);
- LitEnc_Encode(&p->rc, p->litProbs, curByte);
- p->additionalOffset--;
- nowPos32++;
- }
+ nowPos32 = (uint32_t)p->nowPos64;
+ startPos32 = nowPos32;
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
- for (;;)
- {
- uint32_t pos, len, posState;
-
- if (p->fastMode)
- len = GetOptimumFast(p, &pos);
- else
- len = GetOptimum(p, nowPos32, &pos);
-
- posState = nowPos32 & p->pbMask;
- if (len == 1 && pos == (uint32_t)-1)
- {
+ if (p->nowPos64 == 0)
+ {
+ uint32_t numPairs;
unsigned char curByte;
- CLzmaProb *probs;
- const unsigned char *data;
-
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
- curByte = *data;
- probs = LIT_PROBS(nowPos32, *(data - 1));
- if (IsCharState(p->state))
- LitEnc_Encode(&p->rc, probs, curByte);
- else
- LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
- p->state = kLiteralNextStates[p->state];
- }
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
- if (pos < LZMA_NUM_REPS)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
- if (pos == 0)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
- RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
- }
- else
- {
- uint32_t distance = p->reps[pos];
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
- if (pos == 1)
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
- RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
- if (pos == 3)
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- }
- p->reps[1] = p->reps[0];
- p->reps[0] = distance;
- }
- if (len == 1)
- p->state = kShortRepNextStates[p->state];
- else
- {
- LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- p->state = kRepNextStates[p->state];
- }
- }
- else
- {
- uint32_t posSlot;
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
- p->state = kMatchNextStates[p->state];
- LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- pos -= LZMA_NUM_REPS;
- GetPosSlot(pos, posSlot);
- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
-
- if (posSlot >= kStartPosModelIndex)
- {
- uint32_t footerBits = ((posSlot >> 1) - 1);
- uint32_t base = ((2 | (posSlot & 1)) << footerBits);
- uint32_t posReduced = pos - base;
-
- if (posSlot < kEndPosModelIndex)
- RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
- else
- {
- RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
- p->alignPriceCount++;
- }
- }
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- p->reps[1] = p->reps[0];
- p->reps[0] = pos;
- p->matchPriceCount++;
- }
- }
- p->additionalOffset -= len;
- nowPos32 += len;
- if (p->additionalOffset == 0)
- {
- uint32_t processed;
- if (!p->fastMode)
- {
- if (p->matchPriceCount >= (1 << 7))
- FillDistancesPrices(p);
- if (p->alignPriceCount >= kAlignTableSize)
- FillAlignPrices(p);
- }
if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- break;
- processed = nowPos32 - startPos32;
- if (useLimits)
+ return Flush(p, nowPos32);
+ ReadMatchDistances(p, &numPairs);
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
+ p->state = kLiteralNextStates[p->state];
+ curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);
+ LitEnc_Encode(&p->rc, p->litProbs, curByte);
+ p->additionalOffset--;
+ nowPos32++;
+ }
+
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
+ for (;;)
{
- if (processed + kNumOpts + 300 >= maxUnpackSize ||
- RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
- break;
+ uint32_t pos, len, posState;
+
+ if (p->fastMode)
+ len = GetOptimumFast(p, &pos);
+ else
+ len = GetOptimum(p, nowPos32, &pos);
+
+ posState = nowPos32 & p->pbMask;
+ if (len == 1 && pos == (uint32_t)-1)
+ {
+ unsigned char curByte;
+ CLzmaProb *probs;
+ const unsigned char *data;
+
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+ curByte = *data;
+ probs = LIT_PROBS(nowPos32, *(data - 1));
+ if (IsCharState(p->state))
+ LitEnc_Encode(&p->rc, probs, curByte);
+ else
+ LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
+ p->state = kLiteralNextStates[p->state];
+ }
+ else
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
+ if (pos < LZMA_NUM_REPS)
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
+ if (pos == 0)
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
+ RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
+ }
+ else
+ {
+ uint32_t distance = p->reps[pos];
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
+ if (pos == 1)
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
+ else
+ {
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
+ RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
+ if (pos == 3)
+ p->reps[3] = p->reps[2];
+ p->reps[2] = p->reps[1];
+ }
+ p->reps[1] = p->reps[0];
+ p->reps[0] = distance;
+ }
+ if (len == 1)
+ p->state = kShortRepNextStates[p->state];
+ else
+ {
+ LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+ p->state = kRepNextStates[p->state];
+ }
+ }
+ else
+ {
+ uint32_t posSlot;
+ RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
+ p->state = kMatchNextStates[p->state];
+ LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+ pos -= LZMA_NUM_REPS;
+ GetPosSlot(pos, posSlot);
+ RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
+
+ if (posSlot >= kStartPosModelIndex)
+ {
+ uint32_t footerBits = ((posSlot >> 1) - 1);
+ uint32_t base = ((2 | (posSlot & 1)) << footerBits);
+ uint32_t posReduced = pos - base;
+
+ if (posSlot < kEndPosModelIndex)
+ RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
+ else
+ {
+ RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
+ RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
+ p->alignPriceCount++;
+ }
+ }
+ p->reps[3] = p->reps[2];
+ p->reps[2] = p->reps[1];
+ p->reps[1] = p->reps[0];
+ p->reps[0] = pos;
+ p->matchPriceCount++;
+ }
+ }
+ p->additionalOffset -= len;
+ nowPos32 += len;
+ if (p->additionalOffset == 0)
+ {
+ uint32_t processed;
+ if (!p->fastMode)
+ {
+ if (p->matchPriceCount >= (1 << 7))
+ FillDistancesPrices(p);
+ if (p->alignPriceCount >= kAlignTableSize)
+ FillAlignPrices(p);
+ }
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+ break;
+ processed = nowPos32 - startPos32;
+ if (useLimits)
+ {
+ if (processed + kNumOpts + 300 >= maxUnpackSize ||
+ RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
+ break;
+ }
+ else if (processed >= (1 << 17))
+ {
+ p->nowPos64 += nowPos32 - startPos32;
+ return CheckErrors(p);
+ }
+ }
}
- else if (processed >= (1 << 17))
- {
- p->nowPos64 += nowPos32 - startPos32;
- return CheckErrors(p);
- }
- }
- }
- p->nowPos64 += nowPos32 - startPos32;
- return Flush(p, nowPos32);
+ p->nowPos64 += nowPos32 - startPos32;
+ return Flush(p, nowPos32);
}
#define kBigHashDicLimit ((uint32_t)1 << 24)
@@ -1904,20 +1932,26 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, uint32_t keepWindowSize, ISzAlloc *alloc,
if (beforeSize + p->dictSize < keepWindowSize)
beforeSize = keepWindowSize - p->dictSize;
- #ifndef _7ZIP_ST
+#ifndef _7ZIP_ST
if (p->mtMode)
{
- RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
- p->matchFinderObj = &p->matchFinderMt;
- MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
+ int result = MatchFinderMt_Create(&p->matchFinderMt,
+ p->dictSize, beforeSize, p->numFastBytes,
+ LZMA_MATCH_LEN_MAX, allocBig);
+ if (result != 0)
+ return result;
+ p->matchFinderObj = &p->matchFinderMt;
+ MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
}
else
- #endif
+#endif
{
- if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
- return SZ_ERROR_MEM;
- p->matchFinderObj = &p->matchFinderBase;
- MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
+ if (!MatchFinder_Create(&p->matchFinderBase,
+ p->dictSize, beforeSize, p->numFastBytes,
+ LZMA_MATCH_LEN_MAX, allocBig))
+ return SZ_ERROR_MEM;
+ p->matchFinderObj = &p->matchFinderBase;
+ MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
}
return SZ_OK;
@@ -1926,32 +1960,31 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, uint32_t keepWindowSize, ISzAlloc *alloc,
void LzmaEnc_Init(CLzmaEnc *p)
{
uint32_t i;
- p->state = 0;
+ p->state = 0;
for (i = 0 ; i < LZMA_NUM_REPS; i++)
- p->reps[i] = 0;
+ p->reps[i] = 0;
RangeEnc_Init(&p->rc);
-
for (i = 0; i < kNumStates; i++)
{
uint32_t j;
for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
{
- p->isMatch[i][j] = kProbInitValue;
+ p->isMatch[i][j] = kProbInitValue;
p->isRep0Long[i][j] = kProbInitValue;
}
- p->isRep[i] = kProbInitValue;
- p->isRepG0[i] = kProbInitValue;
- p->isRepG1[i] = kProbInitValue;
- p->isRepG2[i] = kProbInitValue;
+ p->isRep[i] = kProbInitValue;
+ p->isRepG0[i] = kProbInitValue;
+ p->isRepG1[i] = kProbInitValue;
+ p->isRepG2[i] = kProbInitValue;
}
{
- uint32_t num = (uint32_t)0x300 << (p->lp + p->lc);
- CLzmaProb *probs = p->litProbs;
+ uint32_t num = (uint32_t)0x300 << (p->lp + p->lc);
+ CLzmaProb *probs = p->litProbs;
for (i = 0; i < num; i++)
- probs[i] = kProbInitValue;
+ probs[i] = kProbInitValue;
}
{
@@ -1974,12 +2007,12 @@ void LzmaEnc_Init(CLzmaEnc *p)
for (i = 0; i < (1 << kNumAlignBits); i++)
p->posAlignEncoder[i] = kProbInitValue;
- p->optimumEndIndex = 0;
+ p->optimumEndIndex = 0;
p->optimumCurrentIndex = 0;
- p->additionalOffset = 0;
+ p->additionalOffset = 0;
- p->pbMask = (1 << p->pb) - 1;
- p->lpMask = (1 << p->lp) - 1;
+ p->pbMask = (1 << p->pb) - 1;
+ p->lpMask = (1 << p->lp) - 1;
}
void LzmaEnc_InitPrices(CLzmaEnc *p)
@@ -1990,37 +2023,45 @@ void LzmaEnc_InitPrices(CLzmaEnc *p)
FillAlignPrices(p);
}
- p->lenEnc.tableSize =
+ p->lenEnc.tableSize =
p->repLenEnc.tableSize =
p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
}
-static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p,
+ uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
{
- uint32_t i;
- for (i = 0; i < (uint32_t)kDicLogSizeMaxCompress; i++)
- if (p->dictSize <= ((uint32_t)1 << i))
- break;
- p->distTableSize = i * 2;
+ uint32_t i;
+ int result;
+ for (i = 0; i < (uint32_t)kDicLogSizeMaxCompress; i++)
+ if (p->dictSize <= ((uint32_t)1 << i))
+ break;
+ p->distTableSize = i * 2;
- p->finished = false;
- p->result = SZ_OK;
- RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- p->nowPos64 = 0;
- return SZ_OK;
+ p->finished = false;
+ p->result = SZ_OK;
+
+ result = LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig);
+
+ if (result != 0)
+ return result;
+
+ LzmaEnc_Init(p);
+ LzmaEnc_InitPrices(p);
+ p->nowPos64 = 0;
+ return SZ_OK;
}
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
- ISzAlloc *alloc, ISzAlloc *allocBig)
+static SRes LzmaEnc_Prepare(CLzmaEncHandle pp,
+ ISeqOutStream *outStream, ISeqInStream *inStream,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
{
- CLzmaEnc *p = (CLzmaEnc *)pp;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
p->matchFinderBase.stream = inStream;
- p->needInit = 1;
- p->rc.outStream = outStream;
+ p->needInit = 1;
+ p->rc.outStream = outStream;
return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
}
@@ -2028,21 +2069,23 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
ISeqInStream *inStream, uint32_t keepWindowSize,
ISzAlloc *alloc, ISzAlloc *allocBig)
{
- CLzmaEnc *p = (CLzmaEnc *)pp;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
p->matchFinderBase.stream = inStream;
- p->needInit = 1;
+ p->needInit = 1;
return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
}
-static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const unsigned char *src, size_t srcLen)
+static void LzmaEnc_SetInputBuf(CLzmaEnc *p,
+ const unsigned char *src, size_t srcLen)
{
- p->matchFinderBase.directInput = 1;
- p->matchFinderBase.bufferBase = (unsigned char *)src;
+ p->matchFinderBase.directInput = 1;
+ p->matchFinderBase.bufferBase = (unsigned char *)src;
p->matchFinderBase.directInputRem = srcLen;
}
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const unsigned char *src, size_t srcLen,
- uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp,
+ const unsigned char *src, size_t srcLen,
+ uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
{
CLzmaEnc *p = (CLzmaEnc *)pp;
LzmaEnc_SetInputBuf(p, src, srcLen);
@@ -2060,7 +2103,6 @@ void LzmaEnc_Finish(CLzmaEncHandle pp)
#endif
}
-
typedef struct
{
ISeqOutStream funcTable;
@@ -2071,16 +2113,16 @@ typedef struct
static size_t MyWrite(void *pp, const void *data, size_t size)
{
- CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
- if (p->rem < size)
- {
- size = p->rem;
- p->overflow = true;
- }
- memcpy(p->data, data, size);
- p->rem -= size;
- p->data += size;
- return size;
+ CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
+ if (p->rem < size)
+ {
+ size = p->rem;
+ p->overflow = true;
+ }
+ memcpy(p->data, data, size);
+ p->rem -= size;
+ p->data += size;
+ return size;
}
@@ -2107,25 +2149,26 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, bool reInit,
CSeqOutStreamBuf outStream;
outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = false;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = false;
- p->writeEndMark = false;
- p->finished = false;
- p->result = SZ_OK;
+ p->writeEndMark = false;
+ p->finished = false;
+ p->result = SZ_OK;
if (reInit)
LzmaEnc_Init(p);
LzmaEnc_InitPrices(p);
- nowPos64 = p->nowPos64;
+ nowPos64 = p->nowPos64;
RangeEnc_Init(&p->rc);
- p->rc.outStream = &outStream.funcTable;
+ p->rc.outStream = &outStream.funcTable;
- res = LzmaEnc_CodeOneBlock(p, true, desiredPackSize, *unpackSize);
+ res = LzmaEnc_CodeOneBlock(p, true,
+ desiredPackSize, *unpackSize);
- *unpackSize = (uint32_t)(p->nowPos64 - nowPos64);
- *destLen -= outStream.rem;
+ *unpackSize = (uint32_t)(p->nowPos64 - nowPos64);
+ *destLen -= outStream.rem;
if (outStream.overflow)
return SZ_ERROR_OUTPUT_EOF;
@@ -2135,53 +2178,61 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, bool reInit,
static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
{
- SRes res = SZ_OK;
+ SRes res = SZ_OK;
+#ifndef _7ZIP_ST
+ unsigned char allocaDummy[0x300];
+ allocaDummy[0] = 0;
+ allocaDummy[1] = allocaDummy[0];
+#endif
- #ifndef _7ZIP_ST
- unsigned char allocaDummy[0x300];
- allocaDummy[0] = 0;
- allocaDummy[1] = allocaDummy[0];
- #endif
-
- for (;;)
- {
- res = LzmaEnc_CodeOneBlock(p, false, 0, 0);
- if (res != SZ_OK || p->finished)
- break;
- if (progress)
- {
- res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
- if (res != SZ_OK)
+ for (;;)
+ {
+ res = LzmaEnc_CodeOneBlock(p, false, 0, 0);
+ if (res != SZ_OK || p->finished)
+ break;
+ if (progress)
{
- res = SZ_ERROR_PROGRESS;
- break;
+ res = progress->Progress(
+ progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
+
+ if (res != SZ_OK)
+ {
+ res = SZ_ERROR_PROGRESS;
+ break;
+ }
}
- }
- }
+ }
- LzmaEnc_Finish(p);
+ LzmaEnc_Finish(p);
- return res;
+ return res;
}
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
- ISzAlloc *alloc, ISzAlloc *allocBig)
+SRes LzmaEnc_Encode(CLzmaEncHandle pp,
+ ISeqOutStream *outStream,
+ ISeqInStream *inStream, ICompressProgress *progress,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
{
- RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
- return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
+ int result = LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig);
+ if (result != 0)
+ return result;
+ return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
}
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, unsigned char *props, size_t *size)
+SRes LzmaEnc_WriteProperties(
+ CLzmaEncHandle pp, unsigned char *props, size_t *size)
{
- CLzmaEnc *p = (CLzmaEnc *)pp;
unsigned i;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
uint32_t dictSize = p->dictSize;
+
if (*size < LZMA_PROPS_SIZE)
return SZ_ERROR_PARAM;
- *size = LZMA_PROPS_SIZE;
- props[0] = (unsigned char)((p->pb * 5 + p->lp) * 9 + p->lc);
+
+ *size = LZMA_PROPS_SIZE;
+ props[0] = (unsigned char)((p->pb * 5 + p->lp) * 9 + p->lc);
if (dictSize >= ((uint32_t)1 << 22))
{
@@ -2201,23 +2252,26 @@ SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, unsigned char *props, size_t *si
}
-SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+SRes LzmaEnc_MemEncode(CLzmaEncHandle pp,
+ unsigned char *dest, size_t *destLen,
+ const unsigned char *src, size_t srcLen,
+ int writeEndMark, ICompressProgress *progress,
+ ISzAlloc *alloc, ISzAlloc *allocBig)
{
SRes res;
- CLzmaEnc *p = (CLzmaEnc *)pp;
-
CSeqOutStreamBuf outStream;
+ CLzmaEnc *p = (CLzmaEnc *)pp;
outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = false;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = false;
- p->writeEndMark = writeEndMark;
- p->rc.outStream = &outStream.funcTable;
+ p->writeEndMark = writeEndMark;
+ p->rc.outStream = &outStream.funcTable;
- res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);
+ res = LzmaEnc_MemPrepare(
+ pp, src, srcLen, 0, alloc, allocBig);
if (res == SZ_OK)
{
@@ -2233,24 +2287,26 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, unsigned char *dest, size_t *destLen,
}
-SRes LzmaEncode(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
- const CLzmaEncProps *props, unsigned char *propsEncoded, size_t *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+SRes LzmaEncode(unsigned char *dest, size_t *destLen,
+ const unsigned char *src, size_t srcLen,
+ const CLzmaEncProps *props,
+ unsigned char *propsEncoded, size_t *propsSize, int writeEndMark,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
{
- CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
- SRes res;
- if (!p)
- return SZ_ERROR_MEM;
+ SRes res;
+ CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
+ if (!p)
+ return SZ_ERROR_MEM;
- res = LzmaEnc_SetProps(p, props);
- if (res == SZ_OK)
- {
- res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
- if (res == SZ_OK)
- res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
- writeEndMark, progress, alloc, allocBig);
- }
+ res = LzmaEnc_SetProps(p, props);
+ if (res == SZ_OK)
+ {
+ res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
+ if (res == SZ_OK)
+ res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
+ writeEndMark, progress, alloc, allocBig);
+ }
- LzmaEnc_Destroy(p, alloc, allocBig);
- return res;
+ LzmaEnc_Destroy(p, alloc, allocBig);
+ return res;
}
diff --git a/deps/libz/adler32.c b/deps/libz/adler32.c
index 3958febd72..66210cb406 100644
--- a/deps/libz/adler32.c
+++ b/deps/libz/adler32.c
@@ -48,17 +48,19 @@
/* ========================================================================= */
uint32_t adler32(uint32_t adler, const uint8_t *buf, size_t len)
{
+ int k;
uint32_t s1 = adler & 0xffff;
uint32_t s2 = (adler >> 16) & 0xffff;
- int k;
if (buf == NULL)
return 1L;
- while (len > 0) {
- k = len < NMAX ? (int)len : NMAX;
+ while (len > 0)
+ {
+ k = len < NMAX ? (int)len : NMAX;
len -= k;
- while (k >= 16) {
+ while (k >= 16)
+ {
DO16(buf);
buf += 16;
k -= 16;
diff --git a/deps/libz/compress.c b/deps/libz/compress.c
index 37eb4d9699..924939dc1d 100644
--- a/deps/libz/compress.c
+++ b/deps/libz/compress.c
@@ -21,34 +21,38 @@
*/
int compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
{
- z_stream stream;
int err;
+ z_stream stream;
- stream.next_in = (Bytef *)source;
+ stream.next_in = (Bytef *)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
- if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+ if ((uLong)stream.avail_in != sourceLen)
+ return Z_BUF_ERROR;
#endif
- stream.next_out = dest;
+ stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
- if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+ if ((uLong)stream.avail_out != *destLen)
+ return Z_BUF_ERROR;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
- stream.opaque = (voidpf)0;
+ stream.zalloc = Z_NULL;
+ stream.zfree = Z_NULL;
+ stream.opaque = (voidpf)0;
- err = deflateInit(&stream, level);
- if (err != Z_OK) return err;
+ err = deflateInit(&stream, level);
+ if (err != Z_OK)
+ return err;
- err = deflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END)
+ {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
- err = deflateEnd(&stream);
+ err = deflateEnd(&stream);
return err;
}
@@ -65,6 +69,8 @@ int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen
*/
uLong compressBound (uLong sourceLen)
{
- return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
+ return sourceLen +
+ (sourceLen >> 12) +
+ (sourceLen >> 14) +
(sourceLen >> 25) + 13;
}
diff --git a/deps/libz/deflate.c b/deps/libz/deflate.c
index 10b188540c..9e9a31dd41 100644
--- a/deps/libz/deflate.c
+++ b/deps/libz/deflate.c
@@ -49,10 +49,6 @@
/* @(#) $Id$ */
-#ifdef DEBUG
-#include
-#endif
-
#include "deflate.h"
const char deflate_copyright[] =
" deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
@@ -76,23 +72,13 @@ typedef enum {
typedef block_state (*compress_func) (deflate_state *s, int flush);
/* Compression function. Returns the block state after the call. */
-static void fill_window (deflate_state *s);
static block_state deflate_stored (deflate_state *s, int flush);
static block_state deflate_fast (deflate_state *s, int flush);
#ifndef FASTEST
static block_state deflate_slow (deflate_state *s, int flush);
#endif
-static block_state deflate_rle (deflate_state *s, int flush);
-static block_state deflate_huff (deflate_state *s, int flush);
-static void lm_init (deflate_state *s);
-static void putShortMSB (deflate_state *s, uInt b);
-static void flush_pending (z_streamp strm);
-static int read_buf (z_streamp strm, Bytef *buf, unsigned size);
#ifdef ASMV
void match_init (void); /* asm code initialization */
-uInt longest_match (deflate_state *s, IPos cur_match);
-#else
-static uInt longest_match (deflate_state *s, IPos cur_match);
#endif
/* ===========================================================================
@@ -191,9 +177,52 @@ static const config configuration_table[10] = {
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
-int deflateResetKeep (z_streamp strm);
+/* ========================================================================= */
+int deflateResetKeep (z_streamp strm)
+{
+ deflate_state *s;
-int deflatePending (z_streamp strm, unsigned *pending, int *bits);
+ if ( strm == Z_NULL
+ || strm->state == Z_NULL
+ )
+ return Z_STREAM_ERROR;
+
+ strm->total_in = strm->total_out = 0;
+ strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
+ strm->data_type = Z_UNKNOWN;
+
+ s = (deflate_state *)strm->state;
+ s->pending = 0;
+ s->pending_out = s->pending_buf;
+
+ if (s->wrap < 0)
+ s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
+ s->status = s->wrap ? INIT_STATE : BUSY_STATE;
+ strm->adler =
+#ifdef GZIP
+ s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
+#endif
+ adler32(0L, Z_NULL, 0);
+ s->last_flush = Z_NO_FLUSH;
+
+ _tr_init(s);
+
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int deflatePending (z_streamp strm, unsigned *pending, int *bits)
+{
+ struct internal_state_deflate *state =
+ (struct internal_state_deflate*)strm->state;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ if (pending != Z_NULL)
+ *pending = state->pending;
+ if (bits != Z_NULL)
+ *bits = state->bi_valid;
+ return Z_OK;
+}
/* ========================================================================= */
int deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
@@ -217,94 +246,281 @@ int deflateInit2_(z_streamp strm, int level, int method, int windowBits, int mem
*/
if (version == Z_NULL || version[0] != my_version[0] ||
- stream_size != sizeof(z_stream)) {
+ stream_size != sizeof(z_stream))
return Z_VERSION_ERROR;
- }
- if (strm == Z_NULL) return Z_STREAM_ERROR;
- strm->msg = Z_NULL;
- if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
+ if (strm == Z_NULL)
return Z_STREAM_ERROR;
-#else
- strm->zalloc = zcalloc;
- strm->opaque = (voidpf)0;
-#endif
- }
- if (strm->zfree == NULL)
-#ifdef Z_SOLO
- return Z_STREAM_ERROR;
-#else
- strm->zfree = zcfree;
-#endif
+
+ strm->msg = Z_NULL;
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ strm->zfree = zcfree;
#ifdef FASTEST
- if (level != 0) level = 1;
+ if (level != 0)
+ level = 1;
#else
- if (level == Z_DEFAULT_COMPRESSION) level = 6;
+ if (level == Z_DEFAULT_COMPRESSION)
+ level = 6;
#endif
- if (windowBits < 0) { /* suppress zlib wrapper */
- wrap = 0;
+ if (windowBits < 0)
+ { /* suppress zlib wrapper */
+ wrap = 0;
windowBits = -windowBits;
}
#ifdef GZIP
- else if (windowBits > 15) {
- wrap = 2; /* write gzip wrapper instead */
+ else if (windowBits > 15)
+ {
+ wrap = 2; /* write gzip wrapper instead */
windowBits -= 16;
}
#endif
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
- strategy < 0 || strategy > Z_FIXED) {
+ strategy < 0 || strategy > Z_FIXED)
return Z_STREAM_ERROR;
- }
- if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
- s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
- if (s == Z_NULL) return Z_MEM_ERROR;
- strm->state = (struct internal_state*)s;
- s->strm = strm;
- s->wrap = wrap;
- s->gzhead = Z_NULL;
- s->w_bits = windowBits;
- s->w_size = 1 << s->w_bits;
- s->w_mask = s->w_size - 1;
+ if (windowBits == 8)
+ windowBits = 9; /* until 256-byte window bug fixed */
+ s = (deflate_state *)calloc(1, sizeof(deflate_state));
- s->hash_bits = memLevel + 7;
- s->hash_size = 1 << s->hash_bits;
- s->hash_mask = s->hash_size - 1;
- s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+ if (s == Z_NULL)
+ return Z_MEM_ERROR;
- s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
- s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
- s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
+ strm->state = (struct internal_state*)s;
+ s->strm = strm;
- s->high_water = 0; /* nothing written to s->window yet */
+ s->wrap = wrap;
+ s->gzhead = Z_NULL;
+ s->w_bits = windowBits;
+ s->w_size = 1 << s->w_bits;
+ s->w_mask = s->w_size - 1;
+
+ s->hash_bits = memLevel + 7;
+ s->hash_size = 1 << s->hash_bits;
+ s->hash_mask = s->hash_size - 1;
+ s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+
+ s->window = (Bytef*)calloc(s->w_size, 2*sizeof(Byte));
+ s->prev = (Posf*) calloc(s->w_size, sizeof(Pos));
+ s->head = (Posf*) calloc(s->hash_size, sizeof(Pos));
+
+ s->high_water = 0; /* nothing written to s->window yet */
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
- overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+ overlay = (ushf *)calloc(s->lit_bufsize, sizeof(ush)+2);
s->pending_buf = (uchf *) overlay;
s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
- s->pending_buf == Z_NULL) {
+ s->pending_buf == Z_NULL)
+ {
s->status = FINISH_STATE;
strm->msg = ERR_MSG(Z_MEM_ERROR);
deflateEnd (strm);
return Z_MEM_ERROR;
}
- s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
- s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+ s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+ s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
- s->level = level;
+ s->level = level;
s->strategy = strategy;
- s->method = (Byte)method;
+ s->method = (Byte)method;
return deflateReset(strm);
}
+/* ===========================================================================
+ * Read a new buffer from the current input stream, update the adler32
+ * and total number of bytes read. All deflate() input goes through
+ * this function so some applications may wish to modify it to avoid
+ * allocating a large strm->next_in buffer and copying from it.
+ * (See also flush_pending()).
+ */
+static int read_buf(z_streamp strm, Bytef *buf, unsigned size)
+{
+ struct internal_state_deflate
+ *state = (struct internal_state_deflate*)strm->state;
+ unsigned len = strm->avail_in;
+
+ if (len > size)
+ len = size;
+ if (len == 0)
+ return 0;
+
+ strm->avail_in -= len;
+
+ memcpy(buf, strm->next_in, len);
+ if (state->wrap == 1)
+ strm->adler = adler32(strm->adler, buf, len);
+#ifdef GZIP
+ else if (state->wrap == 2)
+ strm->adler = crc32(strm->adler, buf, len);
+#endif
+ strm->next_in += len;
+ strm->total_in += len;
+
+ return (int)len;
+}
+
+
+/* ===========================================================================
+ * Fill the window when the lookahead becomes insufficient.
+ * Updates strstart and lookahead.
+ *
+ * IN assertion: lookahead < MIN_LOOKAHEAD
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
+ * At least one byte has been read, or avail_in == 0; reads are
+ * performed for at least two bytes (required for the zip translate_eol
+ * option -- not supported here).
+ */
+static void fill_window(deflate_state *s)
+{
+ register unsigned n, m;
+ register Posf *p;
+ unsigned more; /* Amount of free space at the end of the window. */
+ uInt wsize = s->w_size;
+
+ Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+
+ do {
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
+
+ /* Deal with !@#$% 64K limit: */
+ if (sizeof(int) <= 2) {
+ if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+ more = wsize;
+
+ } else if (more == (unsigned)(-1)) {
+ /* Very unlikely, but possible on 16 bit machine if
+ * strstart == 0 && lookahead == 1 (input done a byte at time)
+ */
+ more--;
+ }
+ }
+
+ /* If the window is almost full and there is insufficient lookahead,
+ * move the upper half to the lower one to make room in the upper half.
+ */
+ if (s->strstart >= wsize+MAX_DIST(s)) {
+
+ memcpy(s->window, s->window+wsize, (unsigned)wsize);
+ s->match_start -= wsize;
+ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
+ s->block_start -= (long) wsize;
+
+ /* Slide the hash table (could be avoided with 32 bit values
+ at the expense of memory usage). We slide even when level == 0
+ to keep the hash table consistent if we switch back to level > 0
+ later. (Using level 0 permanently is not an optimal usage of
+ zlib, so we don't care about this pathological case.)
+ */
+ n = s->hash_size;
+ p = &s->head[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ } while (--n);
+
+ n = wsize;
+#ifndef FASTEST
+ p = &s->prev[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
+#endif
+ more += wsize;
+ }
+ if (s->strm->avail_in == 0) break;
+
+ /* If there was no sliding:
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
+ * more == window_size - lookahead - strstart
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
+ * => more >= window_size - 2*WSIZE + 2
+ * In the BIG_MEM or MMAP case (not yet supported),
+ * window_size == input_size + MIN_LOOKAHEAD &&
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
+ */
+ Assert(more >= 2, "more < 2");
+
+ n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
+ s->lookahead += n;
+
+ /* Initialize the hash value now that we have some input: */
+ if (s->lookahead + s->insert >= MIN_MATCH) {
+ uInt str = s->strstart - s->insert;
+ s->ins_h = s->window[str];
+ UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ while (s->insert) {
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+ s->head[s->ins_h] = (Pos)str;
+ str++;
+ s->insert--;
+ if (s->lookahead + s->insert < MIN_MATCH)
+ break;
+ }
+ }
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+ * but this is not important since only literal bytes will be emitted.
+ */
+
+ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
+
+ /* If the WIN_INIT bytes after the end of the current data have never been
+ * written, then zero those bytes in order to avoid memory check reports of
+ * the use of uninitialized (or uninitialised as Julian writes) bytes by
+ * the longest match routines. Update the high water mark for the next
+ * time through here. WIN_INIT is set to MAX_MATCH since the longest match
+ * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
+ */
+ if (s->high_water < s->window_size) {
+ ulg curr = s->strstart + (ulg)(s->lookahead);
+ ulg init;
+
+ if (s->high_water < curr) {
+ /* Previous high water mark below current data -- zero WIN_INIT
+ * bytes or up to end of window, whichever is less.
+ */
+ init = s->window_size - curr;
+ if (init > WIN_INIT)
+ init = WIN_INIT;
+ zmemzero(s->window + curr, (unsigned)init);
+ s->high_water = curr + init;
+ }
+ else if (s->high_water < (ulg)curr + WIN_INIT) {
+ /* High water mark at or above current data, but below current data
+ * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
+ * to end of window, whichever is less.
+ */
+ init = (ulg)curr + WIN_INIT - s->high_water;
+ if (init > s->window_size - s->high_water)
+ init = s->window_size - s->high_water;
+ zmemzero(s->window + s->high_water, (unsigned)init);
+ s->high_water += init;
+ }
+ }
+
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+ "not enough room for search");
+}
+
+
/* ========================================================================= */
int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
{
@@ -327,24 +543,28 @@ int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLeng
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
/* if dictionary would fill window, just replace the history */
- if (dictLength >= s->w_size) {
- if (wrap == 0) { /* already empty otherwise */
+ if (dictLength >= s->w_size)
+ {
+ if (wrap == 0)
+ {
+ /* already empty otherwise */
CLEAR_HASH(s);
s->strstart = 0;
s->block_start = 0L;
s->insert = 0;
}
dictionary += dictLength - s->w_size; /* use the tail */
- dictLength = s->w_size;
+ dictLength = s->w_size;
}
/* insert dictionary into window and hash */
- avail = strm->avail_in;
- next = strm->next_in;
+ avail = strm->avail_in;
+ next = strm->next_in;
strm->avail_in = dictLength;
- strm->next_in = (Bytef *)dictionary;
+ strm->next_in = (Bytef *)dictionary;
fill_window(s);
- while (s->lookahead >= MIN_MATCH) {
+ while (s->lookahead >= MIN_MATCH)
+ {
str = s->strstart;
n = s->lookahead - (MIN_MATCH-1);
do {
@@ -359,58 +579,53 @@ int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLeng
s->lookahead = MIN_MATCH-1;
fill_window(s);
}
- s->strstart += s->lookahead;
- s->block_start = (long)s->strstart;
- s->insert = s->lookahead;
- s->lookahead = 0;
- s->match_length = s->prev_length = MIN_MATCH-1;
+ s->strstart += s->lookahead;
+ s->block_start = (long)s->strstart;
+ s->insert = s->lookahead;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
- strm->next_in = next;
- strm->avail_in = avail;
- s->wrap = wrap;
+ strm->next_in = next;
+ strm->avail_in = avail;
+ s->wrap = wrap;
return Z_OK;
}
-/* ========================================================================= */
-int deflateResetKeep (z_streamp strm)
+/* ===========================================================================
+ * Initialize the "longest match" routines for a new zlib stream
+ */
+static void lm_init (deflate_state *s)
{
- deflate_state *s;
+ s->window_size = (ulg)2L*s->w_size;
- if (strm == Z_NULL || strm->state == Z_NULL ||
- strm->zalloc == Z_NULL || strm->zfree == Z_NULL) {
- return Z_STREAM_ERROR;
- }
+ CLEAR_HASH(s);
- strm->total_in = strm->total_out = 0;
- strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
- strm->data_type = Z_UNKNOWN;
+ /* Set the default configuration parameters:
+ */
+ s->max_lazy_match = configuration_table[s->level].max_lazy;
+ s->good_match = configuration_table[s->level].good_length;
+ s->nice_match = configuration_table[s->level].nice_length;
+ s->max_chain_length = configuration_table[s->level].max_chain;
- s = (deflate_state *)strm->state;
- s->pending = 0;
- s->pending_out = s->pending_buf;
-
- if (s->wrap < 0) {
- s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
- }
- s->status = s->wrap ? INIT_STATE : BUSY_STATE;
- strm->adler =
-#ifdef GZIP
- s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->lookahead = 0;
+ s->insert = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ s->ins_h = 0;
+#ifndef FASTEST
+#ifdef ASMV
+ match_init(); /* initialize the asm code */
+#endif
#endif
- adler32(0L, Z_NULL, 0);
- s->last_flush = Z_NO_FLUSH;
-
- _tr_init(s);
-
- return Z_OK;
}
+
/* ========================================================================= */
int deflateReset (z_streamp strm)
{
- int ret;
-
- ret = deflateResetKeep(strm);
+ int ret = deflateResetKeep(strm);
if (ret == Z_OK)
lm_init((deflate_state*)strm->state);
return ret;
@@ -419,36 +634,30 @@ int deflateReset (z_streamp strm)
/* ========================================================================= */
int deflateSetHeader (z_streamp strm, gz_headerp head)
{
- struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ struct internal_state_deflate *state =
+ (struct internal_state_deflate*)strm->state;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
if (state->wrap != 2)
return Z_STREAM_ERROR;
state->gzhead = head;
return Z_OK;
}
-/* ========================================================================= */
-int deflatePending (z_streamp strm, unsigned *pending, int *bits)
-{
- struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- if (pending != Z_NULL)
- *pending = state->pending;
- if (bits != Z_NULL)
- *bits = state->bi_valid;
- return Z_OK;
-}
-
/* ========================================================================= */
int deflatePrime (z_streamp strm, int bits, int value)
{
deflate_state *s;
int put;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
s = (deflate_state*)strm->state;
+
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
return Z_BUF_ERROR;
+
do {
put = Buf_size - s->bi_valid;
if (put > bits)
@@ -469,28 +678,34 @@ int deflateParams(z_streamp strm, int level, int strategy)
compress_func func;
int err = Z_OK;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
s = (deflate_state*)strm->state;
#ifdef FASTEST
- if (level != 0) level = 1;
+ if (level != 0)
+ level = 1;
#else
- if (level == Z_DEFAULT_COMPRESSION) level = 6;
+ if (level == Z_DEFAULT_COMPRESSION)
+ level = 6;
#endif
- if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
+ if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED)
return Z_STREAM_ERROR;
- }
+
func = configuration_table[s->level].func;
if ((strategy != s->strategy || func != configuration_table[level].func) &&
- strm->total_in != 0) {
+ strm->total_in != 0)
+ {
/* Flush the last buffer: */
err = deflate(strm, Z_BLOCK);
if (err == Z_BUF_ERROR && s->pending == 0)
err = Z_OK;
}
- if (s->level != level) {
- s->level = level;
+ if (s->level != level)
+ {
+ s->level = level;
s->max_lazy_match = configuration_table[level].max_lazy;
s->good_match = configuration_table[level].good_length;
s->nice_match = configuration_table[level].nice_length;
@@ -505,11 +720,13 @@ int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
{
deflate_state *s;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- s = (deflate_state*)strm->state;
- s->good_match = good_length;
- s->max_lazy_match = max_lazy;
- s->nice_match = nice_length;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
+ s = (deflate_state*)strm->state;
+ s->good_match = good_length;
+ s->max_lazy_match = max_lazy;
+ s->nice_match = nice_length;
s->max_chain_length = max_chain;
return Z_OK;
}
@@ -534,11 +751,11 @@ int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
uLong deflateBound(z_streamp strm, uLong sourceLen)
{
deflate_state *s;
- uLong complen, wraplen;
+ uLong wraplen;
Bytef *str;
/* conservative upper bound for compressed data */
- complen = sourceLen +
+ uLong complen = sourceLen +
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
/* if can't get parameters, return conservative bound plus zlib wrapper */
@@ -547,7 +764,9 @@ uLong deflateBound(z_streamp strm, uLong sourceLen)
/* compute wrapper length */
s = (deflate_state*)strm->state;
- switch (s->wrap) {
+
+ switch (s->wrap)
+ {
case 0: /* raw deflate */
wraplen = 0;
break;
@@ -556,7 +775,8 @@ uLong deflateBound(z_streamp strm, uLong sourceLen)
break;
case 2: /* gzip wrapper */
wraplen = 18;
- if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
+ if (s->gzhead != Z_NULL)
+ { /* user-supplied gzip header */
if (s->gzhead->extra != Z_NULL)
wraplen += 2 + s->gzhead->extra_len;
str = s->gzhead->name;
@@ -611,19 +831,158 @@ static void flush_pending(z_streamp strm)
_tr_flush_bits(s);
len = s->pending;
if (len > strm->avail_out) len = strm->avail_out;
- if (len == 0) return;
+ if (len == 0)
+ return;
- zmemcpy(strm->next_out, s->pending_out, len);
+ memcpy(strm->next_out, s->pending_out, len);
strm->next_out += len;
s->pending_out += len;
strm->total_out += len;
strm->avail_out -= len;
s->pending -= len;
- if (s->pending == 0) {
+ if (s->pending == 0)
s->pending_out = s->pending_buf;
- }
}
+/* ===========================================================================
+ * Flush the current block, with given end-of-file flag.
+ * IN assertion: strstart is set to the end of the current match.
+ */
+#define FLUSH_BLOCK_ONLY(s, last) { \
+ _tr_flush_block(s, (s->block_start >= 0L ? \
+ (charf *)&s->window[(unsigned)s->block_start] : \
+ (charf *)Z_NULL), \
+ (ulg)((long)s->strstart - s->block_start), \
+ (last)); \
+ s->block_start = s->strstart; \
+ flush_pending(s->strm); \
+}
+
+/* Same but force premature exit if necessary. */
+#define FLUSH_BLOCK(s, last) { \
+ FLUSH_BLOCK_ONLY(s, last); \
+ if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
+}
+
+
+/* ===========================================================================
+ * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
+ * (It will be regenerated if this run of deflate switches away from Huffman.)
+ */
+static block_state deflate_huff(deflate_state *s, int flush)
+{
+ int bflush; /* set if current block must be flushed */
+
+ for (;;)
+ {
+ /* Make sure that we have a literal to write. */
+ if (s->lookahead == 0)
+ {
+ fill_window(s);
+ if (s->lookahead == 0)
+ {
+ if (flush == Z_NO_FLUSH)
+ return need_more;
+ break; /* flush the current block */
+ }
+ }
+
+ /* Output a literal byte */
+ s->match_length = 0;
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ s->insert = 0;
+ if (flush == Z_FINISH)
+ {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+}
+
+/* ===========================================================================
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
+ * one. Do not maintain a hash table. (It will be regenerated if this run of
+ * deflate switches away from Z_RLE.)
+ */
+static block_state deflate_rle(deflate_state *s, int flush)
+{
+ int bflush; /* set if current block must be flushed */
+ uInt prev; /* byte at distance one to match */
+ Bytef *scan, *strend; /* scan goes up to strend for length of run */
+
+ for (;;)
+ {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the longest run, plus one for the unrolled loop.
+ */
+ if (s->lookahead <= MAX_MATCH)
+ {
+ fill_window(s);
+ if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH)
+ return need_more;
+ if (s->lookahead == 0)
+ break; /* flush the current block */
+ }
+
+ /* See how many times the previous byte repeats */
+ s->match_length = 0;
+ if (s->lookahead >= MIN_MATCH && s->strstart > 0)
+ {
+ scan = s->window + s->strstart - 1;
+ prev = *scan;
+ if (prev == *++scan && prev == *++scan && prev == *++scan)
+ {
+ strend = s->window + s->strstart + MAX_MATCH;
+ do {
+ } while (prev == *++scan && prev == *++scan &&
+ prev == *++scan && prev == *++scan &&
+ prev == *++scan && prev == *++scan &&
+ prev == *++scan && prev == *++scan &&
+ scan < strend);
+ s->match_length = MAX_MATCH - (int)(strend - scan);
+ if (s->match_length > s->lookahead)
+ s->match_length = s->lookahead;
+ }
+ Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
+ }
+
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
+ if (s->match_length >= MIN_MATCH)
+ {
+ _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
+
+ s->lookahead -= s->match_length;
+ s->strstart += s->match_length;
+ s->match_length = 0;
+ }
+ else
+ {
+ /* No match, output a literal byte */
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ s->insert = 0;
+ if (flush == Z_FINISH)
+ {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+}
+
+
/* ========================================================================= */
int deflate (z_streamp strm, int flush)
{
@@ -631,9 +990,9 @@ int deflate (z_streamp strm, int flush)
deflate_state *s;
if (strm == Z_NULL || strm->state == Z_NULL ||
- flush > Z_BLOCK || flush < 0) {
+ flush > Z_BLOCK || flush < 0)
return Z_STREAM_ERROR;
- }
+
s = (deflate_state*)strm->state;
if (strm->next_out == Z_NULL ||
@@ -643,19 +1002,22 @@ int deflate (z_streamp strm, int flush)
}
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
- s->strm = strm; /* just in case */
- old_flush = s->last_flush;
+ s->strm = strm; /* just in case */
+ old_flush = s->last_flush;
s->last_flush = flush;
/* Write the header */
- if (s->status == INIT_STATE) {
+ if (s->status == INIT_STATE)
+ {
#ifdef GZIP
- if (s->wrap == 2) {
+ if (s->wrap == 2)
+ {
strm->adler = crc32(0L, Z_NULL, 0);
put_byte(s, 31);
put_byte(s, 139);
put_byte(s, 8);
- if (s->gzhead == Z_NULL) {
+ if (s->gzhead == Z_NULL)
+ {
put_byte(s, 0);
put_byte(s, 0);
put_byte(s, 0);
@@ -667,7 +1029,8 @@ int deflate (z_streamp strm, int flush)
put_byte(s, OS_CODE);
s->status = BUSY_STATE;
}
- else {
+ else
+ {
put_byte(s, (s->gzhead->text ? 1 : 0) +
(s->gzhead->hcrc ? 2 : 0) +
(s->gzhead->extra == Z_NULL ? 0 : 4) +
@@ -942,27 +1305,28 @@ int deflateEnd (z_streamp strm)
struct internal_state_deflate *state;
int status;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- state = (struct internal_state_deflate*)strm->state;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ state = (struct internal_state_deflate*)strm->state;
status = state->status;
+
if (status != INIT_STATE &&
status != EXTRA_STATE &&
status != NAME_STATE &&
status != COMMENT_STATE &&
status != HCRC_STATE &&
status != BUSY_STATE &&
- status != FINISH_STATE) {
+ status != FINISH_STATE)
return Z_STREAM_ERROR;
- }
/* Deallocate in reverse order of allocations: */
- TRY_FREE(strm, state->pending_buf);
- TRY_FREE(strm, state->head);
- TRY_FREE(strm, state->prev);
- TRY_FREE(strm, state->window);
+ free(state->pending_buf);
+ free(state->head);
+ free(state->prev);
+ free(state->window);
- ZFREE(strm, state);
+ free(state);
state = Z_NULL;
return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
@@ -982,112 +1346,50 @@ int deflateCopy (z_streamp dest, z_streamp source)
deflate_state *ss;
ushf *overlay;
-
- if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL)
return Z_STREAM_ERROR;
- }
- ss = (deflate_state*)source->state;
+ ss = (deflate_state*)source->state;
- zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+ memcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
- ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
- if (ds == Z_NULL) return Z_MEM_ERROR;
- dest->state = (struct internal_state FAR *) ds;
- zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
- ds->strm = dest;
+ ds = (deflate_state *)calloc(1, sizeof(deflate_state));
+ if (ds == Z_NULL)
+ return Z_MEM_ERROR;
+ dest->state = (struct internal_state FAR *) ds;
+ memcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
+ ds->strm = dest;
- ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
- ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
- ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
- overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+ ds->window = (Bytef *)calloc(ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) calloc(ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) calloc(ds->hash_size, sizeof(Pos));
+ overlay = (ushf *) calloc(ds->lit_bufsize, sizeof(ush)+2);
ds->pending_buf = (uchf *) overlay;
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
- ds->pending_buf == Z_NULL) {
+ ds->pending_buf == Z_NULL)
+ {
deflateEnd (dest);
return Z_MEM_ERROR;
}
- /* following zmemcpy do not work for 16-bit MSDOS */
- zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
- zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
- zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
- zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
- ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
- ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
- ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+ memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
+ memcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
+ memcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
+ memcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
- ds->l_desc.dyn_tree = ds->dyn_ltree;
- ds->d_desc.dyn_tree = ds->dyn_dtree;
+ ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+ ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+ ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+
+ ds->l_desc.dyn_tree = ds->dyn_ltree;
+ ds->d_desc.dyn_tree = ds->dyn_dtree;
ds->bl_desc.dyn_tree = ds->bl_tree;
return Z_OK;
#endif /* MAXSEG_64K */
}
-/* ===========================================================================
- * Read a new buffer from the current input stream, update the adler32
- * and total number of bytes read. All deflate() input goes through
- * this function so some applications may wish to modify it to avoid
- * allocating a large strm->next_in buffer and copying from it.
- * (See also flush_pending()).
- */
-static int read_buf(z_streamp strm, Bytef *buf, unsigned size)
-{
- struct internal_state_deflate *state = (struct internal_state_deflate*)strm->state;
- unsigned len = strm->avail_in;
-
- if (len > size) len = size;
- if (len == 0) return 0;
-
- strm->avail_in -= len;
-
- zmemcpy(buf, strm->next_in, len);
- if (state->wrap == 1) {
- strm->adler = adler32(strm->adler, buf, len);
- }
-#ifdef GZIP
- else if (state->wrap == 2) {
- strm->adler = crc32(strm->adler, buf, len);
- }
-#endif
- strm->next_in += len;
- strm->total_in += len;
-
- return (int)len;
-}
-
-/* ===========================================================================
- * Initialize the "longest match" routines for a new zlib stream
- */
-static void lm_init (deflate_state *s)
-{
- s->window_size = (ulg)2L*s->w_size;
-
- CLEAR_HASH(s);
-
- /* Set the default configuration parameters:
- */
- s->max_lazy_match = configuration_table[s->level].max_lazy;
- s->good_match = configuration_table[s->level].good_length;
- s->nice_match = configuration_table[s->level].nice_length;
- s->max_chain_length = configuration_table[s->level].max_chain;
-
- s->strstart = 0;
- s->block_start = 0L;
- s->lookahead = 0;
- s->insert = 0;
- s->match_length = s->prev_length = MIN_MATCH-1;
- s->match_available = 0;
- s->ins_h = 0;
-#ifndef FASTEST
-#ifdef ASMV
- match_init(); /* initialize the asm code */
-#endif
-#endif
-}
-
#ifndef FASTEST
/* ===========================================================================
* Set match_start to the longest match starting at the given string and
@@ -1104,12 +1406,14 @@ static void lm_init (deflate_state *s)
*/
static uInt longest_match(deflate_state *s, IPos cur_match)
{
- unsigned chain_length = s->max_chain_length;/* max hash chain length */
- register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */
register int len; /* length of current match */
- int best_len = s->prev_length; /* best match length so far */
- int nice_match = s->nice_match; /* stop if match long enough */
+ unsigned chain_length = s->max_chain_length; /* max hash chain length */
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ int best_len = s->prev_length;
+ /* best match length so far */
+ int nice_match = s->nice_match;
+ /* stop if match long enough */
IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
s->strstart - (IPos)MAX_DIST(s) : NIL;
/* Stop when cur_match becomes <= limit. To simplify the code,
@@ -1122,11 +1426,11 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
/* Compare two bytes at a time. Note: this is not always beneficial.
* Try with and without -DUNALIGNED_OK to check.
*/
- register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
- register ush scan_start = *(ushf*)scan;
- register ush scan_end = *(ushf*)(scan+best_len-1);
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
+ register ush scan_start = *(ushf*)scan;
+ register ush scan_end = *(ushf*)(scan+best_len-1);
#else
- register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
register Byte scan_end1 = scan[best_len-1];
register Byte scan_end = scan[best_len];
#endif
@@ -1137,13 +1441,14 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
/* Do not waste too much time if we already have a good match: */
- if (s->prev_length >= s->good_match) {
+ if (s->prev_length >= s->good_match)
chain_length >>= 2;
- }
+
/* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic.
*/
- if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
+ if ((uInt)nice_match > s->lookahead)
+ nice_match = s->lookahead;
Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
@@ -1197,7 +1502,8 @@ static uInt longest_match(deflate_state *s, IPos cur_match)
if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 ||
*match != *scan ||
- *++match != scan[1]) continue;
+ *++match != scan[1])
+ continue;
/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
@@ -1304,180 +1610,6 @@ static uInt longest_match(s, cur_match)
#endif /* FASTEST */
-/* ===========================================================================
- * Fill the window when the lookahead becomes insufficient.
- * Updates strstart and lookahead.
- *
- * IN assertion: lookahead < MIN_LOOKAHEAD
- * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
- * At least one byte has been read, or avail_in == 0; reads are
- * performed for at least two bytes (required for the zip translate_eol
- * option -- not supported here).
- */
-static void fill_window(deflate_state *s)
-{
- register unsigned n, m;
- register Posf *p;
- unsigned more; /* Amount of free space at the end of the window. */
- uInt wsize = s->w_size;
-
- Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
-
- do {
- more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
-
- /* Deal with !@#$% 64K limit: */
- if (sizeof(int) <= 2) {
- if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
- more = wsize;
-
- } else if (more == (unsigned)(-1)) {
- /* Very unlikely, but possible on 16 bit machine if
- * strstart == 0 && lookahead == 1 (input done a byte at time)
- */
- more--;
- }
- }
-
- /* If the window is almost full and there is insufficient lookahead,
- * move the upper half to the lower one to make room in the upper half.
- */
- if (s->strstart >= wsize+MAX_DIST(s)) {
-
- zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
- s->match_start -= wsize;
- s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
- s->block_start -= (long) wsize;
-
- /* Slide the hash table (could be avoided with 32 bit values
- at the expense of memory usage). We slide even when level == 0
- to keep the hash table consistent if we switch back to level > 0
- later. (Using level 0 permanently is not an optimal usage of
- zlib, so we don't care about this pathological case.)
- */
- n = s->hash_size;
- p = &s->head[n];
- do {
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- } while (--n);
-
- n = wsize;
-#ifndef FASTEST
- p = &s->prev[n];
- do {
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- /* If n is not on any hash chain, prev[n] is garbage but
- * its value will never be used.
- */
- } while (--n);
-#endif
- more += wsize;
- }
- if (s->strm->avail_in == 0) break;
-
- /* If there was no sliding:
- * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
- * more == window_size - lookahead - strstart
- * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
- * => more >= window_size - 2*WSIZE + 2
- * In the BIG_MEM or MMAP case (not yet supported),
- * window_size == input_size + MIN_LOOKAHEAD &&
- * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
- * Otherwise, window_size == 2*WSIZE so more >= 2.
- * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
- */
- Assert(more >= 2, "more < 2");
-
- n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
- s->lookahead += n;
-
- /* Initialize the hash value now that we have some input: */
- if (s->lookahead + s->insert >= MIN_MATCH) {
- uInt str = s->strstart - s->insert;
- s->ins_h = s->window[str];
- UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
-#if MIN_MATCH != 3
- Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
- while (s->insert) {
- UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
-#ifndef FASTEST
- s->prev[str & s->w_mask] = s->head[s->ins_h];
-#endif
- s->head[s->ins_h] = (Pos)str;
- str++;
- s->insert--;
- if (s->lookahead + s->insert < MIN_MATCH)
- break;
- }
- }
- /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
- * but this is not important since only literal bytes will be emitted.
- */
-
- } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
-
- /* If the WIN_INIT bytes after the end of the current data have never been
- * written, then zero those bytes in order to avoid memory check reports of
- * the use of uninitialized (or uninitialised as Julian writes) bytes by
- * the longest match routines. Update the high water mark for the next
- * time through here. WIN_INIT is set to MAX_MATCH since the longest match
- * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
- */
- if (s->high_water < s->window_size) {
- ulg curr = s->strstart + (ulg)(s->lookahead);
- ulg init;
-
- if (s->high_water < curr) {
- /* Previous high water mark below current data -- zero WIN_INIT
- * bytes or up to end of window, whichever is less.
- */
- init = s->window_size - curr;
- if (init > WIN_INIT)
- init = WIN_INIT;
- zmemzero(s->window + curr, (unsigned)init);
- s->high_water = curr + init;
- }
- else if (s->high_water < (ulg)curr + WIN_INIT) {
- /* High water mark at or above current data, but below current data
- * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
- * to end of window, whichever is less.
- */
- init = (ulg)curr + WIN_INIT - s->high_water;
- if (init > s->window_size - s->high_water)
- init = s->window_size - s->high_water;
- zmemzero(s->window + s->high_water, (unsigned)init);
- s->high_water += init;
- }
- }
-
- Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
- "not enough room for search");
-}
-
-/* ===========================================================================
- * Flush the current block, with given end-of-file flag.
- * IN assertion: strstart is set to the end of the current match.
- */
-#define FLUSH_BLOCK_ONLY(s, last) { \
- _tr_flush_block(s, (s->block_start >= 0L ? \
- (charf *)&s->window[(unsigned)s->block_start] : \
- (charf *)Z_NULL), \
- (ulg)((long)s->strstart - s->block_start), \
- (last)); \
- s->block_start = s->strstart; \
- flush_pending(s->strm); \
- Tracev((stderr,"[FLUSH]")); \
-}
-
-/* Same but force premature exit if necessary. */
-#define FLUSH_BLOCK(s, last) { \
- FLUSH_BLOCK_ONLY(s, last); \
- if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
-}
-
/* ===========================================================================
* Copy without compression as much as possible from the input stream, return
* the current block state.
@@ -1495,15 +1627,15 @@ static block_state deflate_stored(deflate_state *s, int flush)
ulg max_block_size = 0xffff;
ulg max_start;
- if (max_block_size > s->pending_buf_size - 5) {
+ if (max_block_size > s->pending_buf_size - 5)
max_block_size = s->pending_buf_size - 5;
- }
/* Copy as much as possible from input to output: */
- for (;;) {
+ for (;;)
+ {
/* Fill the window as much as possible: */
- if (s->lookahead <= 1) {
-
+ if (s->lookahead <= 1)
+ {
Assert(s->strstart < s->w_size+MAX_DIST(s) ||
s->block_start >= (long)s->w_size, "slide too late");
@@ -1519,7 +1651,8 @@ static block_state deflate_stored(deflate_state *s, int flush)
/* Emit a stored block if pending_buf will be full: */
max_start = s->block_start + max_block_size;
- if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
+ if (s->strstart == 0 || (ulg)s->strstart >= max_start)
+ {
/* strstart == 0 is possible when wraparound on 16-bit machine */
s->lookahead = (uInt)(s->strstart - max_start);
s->strstart = (uInt)max_start;
@@ -1533,7 +1666,8 @@ static block_state deflate_stored(deflate_state *s, int flush)
}
}
s->insert = 0;
- if (flush == Z_FINISH) {
+ if (flush == Z_FINISH)
+ {
FLUSH_BLOCK(s, 1);
return finish_done;
}
@@ -1554,32 +1688,36 @@ static block_state deflate_fast(deflate_state *s, int flush)
IPos hash_head; /* head of the hash chain */
int bflush; /* set if current block must be flushed */
- for (;;) {
+ for (;;)
+ {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
- if (s->lookahead < MIN_LOOKAHEAD) {
+ if (s->lookahead < MIN_LOOKAHEAD)
+ {
fill_window(s);
- if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)
return need_more;
- }
- if (s->lookahead == 0) break; /* flush the current block */
+ if (s->lookahead == 0)
+ break; /* flush the current block */
}
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
hash_head = NIL;
- if (s->lookahead >= MIN_MATCH) {
+ if (s->lookahead >= MIN_MATCH)
+ {
INSERT_STRING(s, s->strstart, hash_head);
}
/* Find the longest match, discarding those <= prev_length.
* At this point we have always match_length < MIN_MATCH
*/
- if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
+ if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s))
+ {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
@@ -1587,7 +1725,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
s->match_length = longest_match (s, hash_head);
/* longest_match() sets match_start */
}
- if (s->match_length >= MIN_MATCH) {
+ if (s->match_length >= MIN_MATCH)
+ {
_tr_tally_dist(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH, bflush);
@@ -1598,7 +1737,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
*/
#ifndef FASTEST
if (s->match_length <= s->max_insert_length &&
- s->lookahead >= MIN_MATCH) {
+ s->lookahead >= MIN_MATCH)
+ {
s->match_length--; /* string at strstart already in table */
do {
s->strstart++;
@@ -1608,7 +1748,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
*/
} while (--s->match_length != 0);
s->strstart++;
- } else
+ }
+ else
#endif
{
s->strstart += s->match_length;
@@ -1622,9 +1763,10 @@ static block_state deflate_fast(deflate_state *s, int flush)
* matter since it will be recomputed at next deflate call.
*/
}
- } else {
+ }
+ else
+ {
/* No match, output a literal byte */
- Tracevv((stderr,"%c", s->window[s->strstart]));
_tr_tally_lit (s, s->window[s->strstart], bflush);
s->lookahead--;
s->strstart++;
@@ -1632,7 +1774,8 @@ static block_state deflate_fast(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0);
}
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
- if (flush == Z_FINISH) {
+ if (flush == Z_FINISH)
+ {
FLUSH_BLOCK(s, 1);
return finish_done;
}
@@ -1653,25 +1796,28 @@ static block_state deflate_slow(deflate_state *s, int flush)
int bflush; /* set if current block must be flushed */
/* Process the input block. */
- for (;;) {
+ for (;;)
+ {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
- if (s->lookahead < MIN_LOOKAHEAD) {
+ if (s->lookahead < MIN_LOOKAHEAD)
+ {
fill_window(s);
- if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)
return need_more;
- }
- if (s->lookahead == 0) break; /* flush the current block */
+ if (s->lookahead == 0)
+ break; /* flush the current block */
}
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
hash_head = NIL;
- if (s->lookahead >= MIN_MATCH) {
+ if (s->lookahead >= MIN_MATCH)
+ {
INSERT_STRING(s, s->strstart, hash_head);
}
@@ -1681,7 +1827,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
s->match_length = MIN_MATCH-1;
if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
- s->strstart - hash_head <= MAX_DIST(s)) {
+ s->strstart - hash_head <= MAX_DIST(s))
+ {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
@@ -1694,7 +1841,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
|| (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR)
#endif
- )) {
+ ))
+ {
/* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway.
@@ -1705,7 +1853,8 @@ static block_state deflate_slow(deflate_state *s, int flush)
/* If there was a match at the previous step and the current
* match is not better, output the previous match:
*/
- if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+ if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length)
+ {
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */
@@ -1730,12 +1879,13 @@ static block_state deflate_slow(deflate_state *s, int flush)
if (bflush) FLUSH_BLOCK(s, 0);
- } else if (s->match_available) {
+ }
+ else if (s->match_available)
+ {
/* If there was no match at the previous position, output a
* single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal.
*/
- Tracevv((stderr,"%c", s->window[s->strstart-1]));
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
if (bflush) {
FLUSH_BLOCK_ONLY(s, 0);
@@ -1743,7 +1893,9 @@ static block_state deflate_slow(deflate_state *s, int flush)
s->strstart++;
s->lookahead--;
if (s->strm->avail_out == 0) return need_more;
- } else {
+ }
+ else
+ {
/* There is no previous match to compare with, wait for
* the next step to decide.
*/
@@ -1753,13 +1905,14 @@ static block_state deflate_slow(deflate_state *s, int flush)
}
}
Assert (flush != Z_NO_FLUSH, "no flush?");
- if (s->match_available) {
- Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ if (s->match_available)
+ {
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0;
}
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
- if (flush == Z_FINISH) {
+ if (flush == Z_FINISH)
+ {
FLUSH_BLOCK(s, 1);
return finish_done;
}
@@ -1769,109 +1922,3 @@ static block_state deflate_slow(deflate_state *s, int flush)
}
#endif /* FASTEST */
-/* ===========================================================================
- * For Z_RLE, simply look for runs of bytes, generate matches only of distance
- * one. Do not maintain a hash table. (It will be regenerated if this run of
- * deflate switches away from Z_RLE.)
- */
-static block_state deflate_rle(deflate_state *s, int flush)
-{
- int bflush; /* set if current block must be flushed */
- uInt prev; /* byte at distance one to match */
- Bytef *scan, *strend; /* scan goes up to strend for length of run */
-
- for (;;) {
- /* Make sure that we always have enough lookahead, except
- * at the end of the input file. We need MAX_MATCH bytes
- * for the longest run, plus one for the unrolled loop.
- */
- if (s->lookahead <= MAX_MATCH) {
- fill_window(s);
- if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
- return need_more;
- }
- if (s->lookahead == 0) break; /* flush the current block */
- }
-
- /* See how many times the previous byte repeats */
- s->match_length = 0;
- if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
- scan = s->window + s->strstart - 1;
- prev = *scan;
- if (prev == *++scan && prev == *++scan && prev == *++scan) {
- strend = s->window + s->strstart + MAX_MATCH;
- do {
- } while (prev == *++scan && prev == *++scan &&
- prev == *++scan && prev == *++scan &&
- prev == *++scan && prev == *++scan &&
- prev == *++scan && prev == *++scan &&
- scan < strend);
- s->match_length = MAX_MATCH - (int)(strend - scan);
- if (s->match_length > s->lookahead)
- s->match_length = s->lookahead;
- }
- Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
- }
-
- /* Emit match if have run of MIN_MATCH or longer, else emit literal */
- if (s->match_length >= MIN_MATCH) {
- _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
-
- s->lookahead -= s->match_length;
- s->strstart += s->match_length;
- s->match_length = 0;
- } else {
- /* No match, output a literal byte */
- Tracevv((stderr,"%c", s->window[s->strstart]));
- _tr_tally_lit (s, s->window[s->strstart], bflush);
- s->lookahead--;
- s->strstart++;
- }
- if (bflush) FLUSH_BLOCK(s, 0);
- }
- s->insert = 0;
- if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
- return finish_done;
- }
- if (s->last_lit)
- FLUSH_BLOCK(s, 0);
- return block_done;
-}
-
-/* ===========================================================================
- * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
- * (It will be regenerated if this run of deflate switches away from Huffman.)
- */
-static block_state deflate_huff(deflate_state *s, int flush)
-{
- int bflush; /* set if current block must be flushed */
-
- for (;;) {
- /* Make sure that we have a literal to write. */
- if (s->lookahead == 0) {
- fill_window(s);
- if (s->lookahead == 0) {
- if (flush == Z_NO_FLUSH)
- return need_more;
- break; /* flush the current block */
- }
- }
-
- /* Output a literal byte */
- s->match_length = 0;
- Tracevv((stderr,"%c", s->window[s->strstart]));
- _tr_tally_lit (s, s->window[s->strstart], bflush);
- s->lookahead--;
- s->strstart++;
- if (bflush) FLUSH_BLOCK(s, 0);
- }
- s->insert = 0;
- if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
- return finish_done;
- }
- if (s->last_lit)
- FLUSH_BLOCK(s, 0);
- return block_done;
-}
diff --git a/deps/libz/deflate.h b/deps/libz/deflate.h
index 82fe93e224..dc15703aff 100644
--- a/deps/libz/deflate.h
+++ b/deps/libz/deflate.h
@@ -249,11 +249,6 @@ typedef struct internal_state_deflate {
uInt matches; /* number of string matches in current block */
uInt insert; /* bytes at end of window left to insert */
-#ifdef DEBUG
- ulg compressed_len; /* total bit length of compressed file mod 2^32 */
- ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
-#endif
-
ush bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
@@ -309,16 +304,10 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used.
*/
-#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */
-#if defined(GEN_TREES_H) || !defined(STDC)
- extern uch ZLIB_INTERNAL _length_code[];
- extern uch ZLIB_INTERNAL _dist_code[];
-#else
- extern const uch ZLIB_INTERNAL _length_code[];
- extern const uch ZLIB_INTERNAL _dist_code[];
-#endif
+extern const uch ZLIB_INTERNAL _length_code[];
+extern const uch ZLIB_INTERNAL _dist_code[];
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
@@ -337,10 +326,5 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
-#else
-# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
-# define _tr_tally_dist(s, distance, length, flush) \
- flush = _tr_tally(s, distance, length)
-#endif
#endif /* DEFLATE_H */
diff --git a/deps/libz/gzclose.c b/deps/libz/gzclose.c
index edeee0344b..bed49eaa39 100644
--- a/deps/libz/gzclose.c
+++ b/deps/libz/gzclose.c
@@ -20,8 +20,8 @@ int gzclose(gzFile file)
return Z_STREAM_ERROR;
state = (gz_statep)file;
- return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
-#else
- return gzclose_r(file);
+ if (state->mode != GZ_READ)
+ return gzclose_w(file);
#endif
+ return gzclose_r(file);
}
diff --git a/deps/libz/gzlib.c b/deps/libz/gzlib.c
index 2d17b27ebd..cf3641a015 100644
--- a/deps/libz/gzlib.c
+++ b/deps/libz/gzlib.c
@@ -15,14 +15,6 @@
#endif
#endif
-/* Forward declarations */
-z_off_t gzoffset(gzFile file);
-int gzbuffer(gzFile file, unsigned size);
-
-/* Local functions */
-static void gz_reset OF((gz_statep));
-static gzFile gz_open OF((const void *, int, const char *));
-
#if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message
@@ -34,8 +26,7 @@ static gzFile gz_open OF((const void *, int, const char *));
The gz_strwinerror function does not change the current setting of
GetLastError. */
-char ZLIB_INTERNAL *gz_strwinerror (error)
- DWORD error;
+char ZLIB_INTERNAL *gz_strwinerror (DWORD error)
{
static char buf[1024];
@@ -78,24 +69,25 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
/* Reset gzip file state */
static void gz_reset(gz_statep state)
{
- state->x.have = 0; /* no output data available */
- if (state->mode == GZ_READ) { /* for reading ... */
- state->eof = 0; /* not at end of file */
- state->past = 0; /* have not read past end yet */
- state->how = LOOK; /* look for gzip header */
+ state->x.have = 0; /* no output data available */
+ if (state->mode == GZ_READ) /* for reading ... */
+ {
+ state->eof = 0; /* not at end of file */
+ state->past = 0; /* have not read past end yet */
+ state->how = LOOK; /* look for gzip header */
}
- state->seek = 0; /* no seek request pending */
+ state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */
- state->x.pos = 0; /* no uncompressed data yet */
+ state->x.pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */
}
/* Open a gzip file either by name or file descriptor. */
static gzFile gz_open(const void *path, int fd, const char *mode)
{
+ int oflag;
gz_statep state;
size_t len;
- int oflag;
#ifdef O_CLOEXEC
int cloexec = 0;
#endif
@@ -108,23 +100,25 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
return NULL;
/* allocate gzFile structure to return */
- state = (gz_statep)malloc(sizeof(gz_state));
+ state = (gz_statep)malloc(sizeof(gz_state));
if (state == NULL)
return NULL;
state->size = 0; /* no buffers allocated yet */
state->want = GZBUFSIZE; /* requested buffer size */
- state->msg = NULL; /* no error message yet */
+ state->msg = NULL; /* no error message yet */
/* interpret mode */
- state->mode = GZ_NONE;
- state->level = Z_DEFAULT_COMPRESSION;
+ state->mode = GZ_NONE;
+ state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY;
- state->direct = 0;
- while (*mode) {
+ state->direct = 0;
+ while (*mode)
+ {
if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0';
else
- switch (*mode) {
+ switch (*mode)
+ {
case 'r':
state->mode = GZ_READ;
break;
@@ -173,14 +167,17 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
}
/* must provide an "r", "w", or "a" */
- if (state->mode == GZ_NONE) {
+ if (state->mode == GZ_NONE)
+ {
free(state);
return NULL;
}
/* can't force transparent read */
- if (state->mode == GZ_READ) {
- if (state->direct) {
+ if (state->mode == GZ_READ)
+ {
+ if (state->direct)
+ {
free(state);
return NULL;
}
@@ -189,7 +186,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
/* save the path name for error messages */
#ifdef _WIN32
- if (fd == -2) {
+ if (fd == -2)
+ {
len = wcstombs(NULL, (const wchar_t*)path, 0);
if (len == (size_t)-1)
len = 0;
@@ -198,7 +196,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
#endif
len = strlen((const char *)path);
state->path = (char *)malloc(len + 1);
- if (state->path == NULL) {
+ if (state->path == NULL)
+ {
free(state);
return NULL;
}
@@ -252,7 +251,8 @@ static gzFile gz_open(const void *path, int fd, const char *mode)
state->mode = GZ_WRITE; /* simplify later checks */
/* save the current position for rewinding (only if reading) */
- if (state->mode == GZ_READ) {
+ if (state->mode == GZ_READ)
+ {
state->start = LSEEK(state->fd, 0, SEEK_CUR);
if (state->start == -1) state->start = 0;
}
@@ -330,8 +330,10 @@ int gzrewind(gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
+ if (
+ state->mode != GZ_READ ||
+ ( state->err != Z_OK
+ && state->err != Z_BUF_ERROR))
return -1;
/* back up and start over */
@@ -344,22 +346,24 @@ int gzrewind(gzFile file)
z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
{
unsigned n;
- z_off64_t ret;
gz_statep state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+ if ( state->mode != GZ_READ &&
+ state->mode != GZ_WRITE)
return -1;
/* check that there's no error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR)
+ if ( state->err != Z_OK &&
+ state->err != Z_BUF_ERROR)
return -1;
/* can only seek from start or relative to current position */
- if (whence != SEEK_SET && whence != SEEK_CUR)
+ if ( whence != SEEK_SET &&
+ whence != SEEK_CUR)
return -1;
/* normalize offset to a SEEK_CUR specification */
@@ -370,23 +374,28 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
state->seek = 0;
/* if within raw area while reading, just go there */
- if (state->mode == GZ_READ && state->how == MODE_COPY &&
- state->x.pos + offset >= 0) {
- ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
+ if ( state->mode == GZ_READ &&
+ state->how == MODE_COPY &&
+ state->x.pos + offset >= 0)
+ {
+ z_off64_t ret = LSEEK(
+ state->fd, offset - state->x.have, SEEK_CUR);
if (ret == -1)
return -1;
- state->x.have = 0;
- state->eof = 0;
- state->past = 0;
- state->seek = 0;
+ state->x.have = 0;
+ state->eof = 0;
+ state->past = 0;
+ state->seek = 0;
gz_error(state, Z_OK, NULL);
- state->strm.avail_in = 0;
- state->x.pos += offset;
+ state->strm.avail_in = 0;
+ state->x.pos += offset;
return state->x.pos;
}
- /* calculate skip amount, rewinding if needed for back seek when reading */
- if (offset < 0) {
+ /* calculate skip amount, rewinding if
+ * needed for back seek when reading */
+ if (offset < 0)
+ {
if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1;
offset += state->x.pos;
@@ -397,17 +406,19 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
}
/* if reading, skip what's in output buffer (one less gzgetc() check) */
- if (state->mode == GZ_READ) {
+ if (state->mode == GZ_READ)
+ {
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
(unsigned)offset : state->x.have;
state->x.have -= n;
state->x.next += n;
- state->x.pos += n;
- offset -= n;
+ state->x.pos += n;
+ offset -= n;
}
/* request skip (if not zero) */
- if (offset) {
+ if (offset)
+ {
state->seek = 1;
state->skip = offset;
}
@@ -416,9 +427,7 @@ z_off64_t gzseek64(gzFile file, z_off64_t offset, int whence)
z_off_t gzseek(gzFile file, z_off_t offset, int whence)
{
- z_off64_t ret;
-
- ret = gzseek64(file, (z_off64_t)offset, whence);
+ z_off64_t ret = gzseek64(file, (z_off64_t)offset, whence);
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
}
@@ -430,7 +439,8 @@ z_off64_t gztell64(gzFile file)
if (file == NULL)
return -1;
state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+ if ( state->mode != GZ_READ &&
+ state->mode != GZ_WRITE)
return -1;
/* return position */
@@ -439,9 +449,7 @@ z_off64_t gztell64(gzFile file)
z_off_t gztell(gzFile file)
{
- z_off64_t ret;
-
- ret = gztell64(file);
+ z_off64_t ret = gztell64(file);
return ret == (z_off_t)ret ? (z_off_t)ret : -1;
}
@@ -480,7 +488,8 @@ int gzeof(gzFile file)
if (file == NULL)
return 0;
state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+ if ( state->mode != GZ_READ &&
+ state->mode != GZ_WRITE)
return 0;
/* return end-of-file state */
@@ -495,7 +504,9 @@ const char * gzerror(gzFile file, int *errnum)
if (file == NULL)
return NULL;
state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+
+ if ( state->mode != GZ_READ &&
+ state->mode != GZ_WRITE)
return NULL;
/* return error information */
@@ -513,12 +524,15 @@ void gzclearerr(gzFile file)
if (file == NULL)
return;
state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
+
+ if ( state->mode != GZ_READ &&
+ state->mode != GZ_WRITE)
return;
/* clear error and end-of-file */
- if (state->mode == GZ_READ) {
- state->eof = 0;
+ if (state->mode == GZ_READ)
+ {
+ state->eof = 0;
state->past = 0;
}
gz_error(state, Z_OK, NULL);
@@ -533,7 +547,8 @@ void gzclearerr(gzFile file)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
{
/* free previously allocated message and clear */
- if (state->msg != NULL) {
+ if (state->msg != NULL)
+ {
if (state->err != Z_MEM_ERROR)
free(state->msg);
state->msg = NULL;
@@ -554,7 +569,8 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
/* construct error message with path */
if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
- NULL) {
+ NULL)
+ {
state->err = Z_MEM_ERROR;
return;
}
@@ -566,7 +582,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
strlcat(state->msg, ": ", sizeof(state->msg));
strlcat(state->msg, msg, sizeof(state->msg));
#endif
- return;
}
#ifndef INT_MAX
@@ -574,7 +589,7 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */
-unsigned ZLIB_INTERNAL gz_intmax()
+unsigned ZLIB_INTERNAL gz_intmax(void)
{
unsigned p, q;
diff --git a/deps/libz/gzread.c b/deps/libz/gzread.c
index 966125baee..92dc9b3993 100644
--- a/deps/libz/gzread.c
+++ b/deps/libz/gzread.c
@@ -5,16 +5,6 @@
#include "gzguts.h"
-/* Local functions */
-static int gz_load (gz_statep, unsigned char *, unsigned, unsigned *);
-static int gz_avail (gz_statep);
-static int gz_look (gz_statep);
-static int gz_decomp (gz_statep);
-static int gz_fetch (gz_statep);
-static int gz_skip (gz_statep, z_off64_t);
-
-int gzgetc_(gzFile file);
-
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate.
This function needs to loop on read(), since read() is not guaranteed to
@@ -30,7 +20,8 @@ static int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *
break;
*have += ret;
} while (*have < len);
- if (ret < 0) {
+ if (ret < 0)
+ {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
@@ -53,8 +44,10 @@ static int gz_avail(gz_statep state)
if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
- if (state->eof == 0) {
- if (strm->avail_in) { /* copy what's there to the start */
+ if (state->eof == 0)
+ {
+ if (strm->avail_in) /* copy what's there to the start */
+ {
unsigned char *p = state->in;
unsigned const char *q = strm->next_in;
unsigned n = strm->avail_in;
@@ -85,11 +78,13 @@ static int gz_look(gz_statep state)
z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */
- if (state->size == 0) {
+ if (state->size == 0)
+ {
/* allocate buffers */
state->in = (unsigned char *)malloc(state->want);
state->out = (unsigned char *)malloc(state->want << 1);
- if (state->in == NULL || state->out == NULL) {
+ if (state->in == NULL || state->out == NULL)
+ {
if (state->out != NULL)
free(state->out);
if (state->in != NULL)
@@ -105,7 +100,8 @@ static int gz_look(gz_statep state)
state->strm.opaque = Z_NULL;
state->strm.avail_in = 0;
state->strm.next_in = Z_NULL;
- if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
+ if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) /* gunzip */
+ {
free(state->out);
free(state->in);
state->size = 0;
@@ -115,7 +111,8 @@ static int gz_look(gz_statep state)
}
/* get at least the magic bytes in the input buffer */
- if (strm->avail_in < 2) {
+ if (strm->avail_in < 2)
+ {
if (gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0)
@@ -129,8 +126,10 @@ static int gz_look(gz_statep state)
file -- for here we assume that if a gzip file is being written, then
the header will be written in a single operation, so that reading a
single byte is sufficient indication that it is not a gzip file) */
- if (strm->avail_in > 1 &&
- strm->next_in[0] == 31 && strm->next_in[1] == 139) {
+ if ( strm->avail_in > 1 &&
+ strm->next_in[0] == 31 &&
+ strm->next_in[1] == 139)
+ {
inflateReset(strm);
state->how = MODE_GZIP;
state->direct = 0;
@@ -139,10 +138,11 @@ static int gz_look(gz_statep state)
/* no gzip header -- if we were decoding gzip before, then this is trailing
garbage. Ignore the trailing garbage and finish. */
- if (state->direct == 0) {
+ if (state->direct == 0)
+ {
strm->avail_in = 0;
- state->eof = 1;
- state->x.have = 0;
+ state->eof = 1;
+ state->x.have = 0;
return 0;
}
@@ -150,12 +150,13 @@ static int gz_look(gz_statep state)
the output buffer is larger than the input buffer, which also assures
space for gzungetc() */
state->x.next = state->out;
- if (strm->avail_in) {
+ if (strm->avail_in)
+ {
memcpy(state->x.next, strm->next_in, strm->avail_in);
state->x.have = strm->avail_in;
strm->avail_in = 0;
}
- state->how = MODE_COPY;
+ state->how = MODE_COPY;
state->direct = 1;
return 0;
}
@@ -168,32 +169,36 @@ static int gz_look(gz_statep state)
static int gz_decomp(gz_statep state)
{
int ret = Z_OK;
- unsigned had;
z_streamp strm = &(state->strm);
-
/* fill output buffer up to end of deflate stream */
- had = strm->avail_out;
- do {
+ unsigned had = strm->avail_out;
+
+ do
+ {
/* get more input for inflate() */
if (strm->avail_in == 0 && gz_avail(state) == -1)
return -1;
- if (strm->avail_in == 0) {
+ if (strm->avail_in == 0)
+ {
gz_error(state, Z_BUF_ERROR, "unexpected end of file");
break;
}
/* decompress and handle errors */
ret = inflate(strm, Z_NO_FLUSH);
- if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
+ if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT)
+ {
gz_error(state, Z_STREAM_ERROR,
"internal error: inflate stream corrupt");
return -1;
}
- if (ret == Z_MEM_ERROR) {
+ if (ret == Z_MEM_ERROR)
+ {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
- if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
+ if (ret == Z_DATA_ERROR) /* deflate stream invalid */
+ {
gz_error(state, Z_DATA_ERROR,
strm->msg == NULL ? "compressed data error" : strm->msg);
return -1;
@@ -201,7 +206,7 @@ static int gz_decomp(gz_statep state)
} while (strm->avail_out && ret != Z_STREAM_END);
/* update available output */
- state->x.have = had - strm->avail_out;
+ state->x.have = had - strm->avail_out;
state->x.next = strm->next_out - state->x.have;
/* if the gzip stream completed successfully, look for another */
@@ -222,8 +227,10 @@ static int gz_fetch(gz_statep state)
{
z_streamp strm = &(state->strm);
- do {
- switch(state->how) {
+ do
+ {
+ switch(state->how)
+ {
case LOOK: /* -> LOOK, MODE_COPY (only if never GZIP), or MODE_GZIP */
if (gz_look(state) == -1)
return -1;
@@ -254,7 +261,8 @@ static int gz_skip(gz_statep state, z_off64_t len)
/* skip over len bytes or reach end-of-file, whichever comes first */
while (len)
/* skip over whatever is in output buffer */
- if (state->x.have) {
+ if (state->x.have)
+ {
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
(unsigned)len : state->x.have;
state->x.have -= n;
@@ -268,7 +276,8 @@ static int gz_skip(gz_statep state, z_off64_t len)
break;
/* need more data to skip -- load up output buffer */
- else {
+ else
+ {
/* get more output, looking for header if required */
if (gz_fetch(state) == -1)
return -1;
@@ -286,16 +295,19 @@ int gzread(gzFile file, voidp buf, unsigned len)
if (file == NULL)
return -1;
state = (gz_statep)file;
- strm = &(state->strm);
+ strm = &(state->strm);
/* check that we're reading and that there's no (serious) error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
+ if (
+ state->mode != GZ_READ ||
+ ( state->err != Z_OK &&
+ state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
- if ((int)len < 0) {
+ if ((int)len < 0)
+ {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1;
}
@@ -305,7 +317,8 @@ int gzread(gzFile file, voidp buf, unsigned len)
return 0;
/* process a skip request */
- if (state->seek) {
+ if (state->seek)
+ {
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return -1;
@@ -313,10 +326,12 @@ int gzread(gzFile file, voidp buf, unsigned len)
/* get len bytes to buf, or less than len if at the end */
got = 0;
- n = 0;
- do {
+ n = 0;
+ do
+ {
/* first just try copying data from the output buffer */
- if (state->x.have) {
+ if (state->x.have)
+ {
n = state->x.have > len ? len : state->x.have;
memcpy(buf, state->x.next, n);
state->x.next += n;
@@ -324,14 +339,16 @@ int gzread(gzFile file, voidp buf, unsigned len)
}
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && strm->avail_in == 0) {
+ else if (state->eof && strm->avail_in == 0)
+ {
state->past = 1; /* tried to read past end */
break;
}
/* need output data -- for small len or new stream load up our output
buffer */
- else if (state->how == LOOK || len < (state->size << 1)) {
+ else if (state->how == LOOK || len < (state->size << 1))
+ {
/* get more output, looking for header if required */
if (gz_fetch(state) == -1)
return -1;
@@ -341,26 +358,28 @@ int gzread(gzFile file, voidp buf, unsigned len)
}
/* large len -- read directly into user buffer */
- else if (state->how == MODE_COPY) { /* read directly */
+ else if (state->how == MODE_COPY) /* read directly */
+ {
if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
return -1;
}
/* large len -- decompress directly into user buffer */
- else { /* state->how == GZIP */
+ else /* state->how == GZIP */
+ {
strm->avail_out = len;
- strm->next_out = (unsigned char *)buf;
+ strm->next_out = (unsigned char *)buf;
if (gz_decomp(state) == -1)
return -1;
- n = state->x.have;
- state->x.have = 0;
+ n = state->x.have;
+ state->x.have = 0;
}
/* update progress */
- len -= n;
- buf = (char *)buf + n;
- got += n;
- state->x.pos += n;
+ len -= n;
+ buf = (char *)buf + n;
+ got += n;
+ state->x.pos += n;
} while (len);
/* return number of bytes read into user buffer (will fit in int) */
@@ -384,12 +403,15 @@ int gzgetc(gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
+ if (
+ state->mode != GZ_READ ||
+ (state->err != Z_OK &&
+ state->err != Z_BUF_ERROR))
return -1;
/* try output buffer (no need to check for skip request) */
- if (state->x.have) {
+ if (state->x.have)
+ {
state->x.have--;
state->x.pos++;
return *(state->x.next)++;
@@ -415,12 +437,15 @@ int gzungetc(int c, gzFile file)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
+ if (
+ state->mode != GZ_READ ||
+ (state->err != Z_OK &&
+ state->err != Z_BUF_ERROR))
return -1;
/* process a skip request */
- if (state->seek) {
+ if (state->seek)
+ {
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return -1;
@@ -431,34 +456,37 @@ int gzungetc(int c, gzFile file)
return -1;
/* if output buffer empty, put byte at end (allows more pushing) */
- if (state->x.have == 0) {
- state->x.have = 1;
- state->x.next = state->out + (state->size << 1) - 1;
+ if (state->x.have == 0)
+ {
+ state->x.have = 1;
+ state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = c;
state->x.pos--;
- state->past = 0;
+ state->past = 0;
return c;
}
/* if no room, give up (must have already done a gzungetc()) */
- if (state->x.have == (state->size << 1)) {
+ if (state->x.have == (state->size << 1))
+ {
gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1;
}
/* slide output data if needed and insert byte before existing data */
- if (state->x.next == state->out) {
- unsigned char *src = state->out + state->x.have;
+ if (state->x.next == state->out)
+ {
+ unsigned char *src = state->out + state->x.have;
unsigned char *dest = state->out + (state->size << 1);
while (src > state->out)
*--dest = *--src;
- state->x.next = dest;
+ state->x.next = dest;
}
state->x.have++;
state->x.next--;
state->x.next[0] = c;
state->x.pos--;
- state->past = 0;
+ state->past = 0;
return c;
}
@@ -475,12 +503,15 @@ char * gzgets(gzFile file, char *buf, int len)
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
+ if (
+ state->mode != GZ_READ ||
+ (state->err != Z_OK &&
+ state->err != Z_BUF_ERROR))
return NULL;
/* process a skip request */
- if (state->seek) {
+ if (state->seek)
+ {
state->seek = 0;
if (gz_skip(state, state->skip) == -1)
return NULL;
@@ -495,13 +526,15 @@ char * gzgets(gzFile file, char *buf, int len)
/* assure that something is in the output buffer */
if (state->x.have == 0 && gz_fetch(state) == -1)
return NULL; /* error */
- if (state->x.have == 0) { /* end of file */
+
+ if (state->x.have == 0) /* end of file */
+ {
state->past = 1; /* read past end */
break; /* return what we have */
}
/* look for end-of-line in current output buffer */
- n = state->x.have > left ? left : state->x.have;
+ n = state->x.have > left ? left : state->x.have;
eol = (unsigned char *)memchr(state->x.next, '\n', n);
if (eol != NULL)
n = (unsigned)(eol - state->x.next) + 1;
@@ -510,9 +543,9 @@ char * gzgets(gzFile file, char *buf, int len)
memcpy(buf, state->x.next, n);
state->x.have -= n;
state->x.next += n;
- state->x.pos += n;
- left -= n;
- buf += n;
+ state->x.pos += n;
+ left -= n;
+ buf += n;
} while (left && eol == NULL);
/* return terminated string, or if nothing, end of file */
@@ -533,7 +566,9 @@ int gzdirect(gzFile file)
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
- if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+ if ( state->mode == GZ_READ &&
+ state->how == LOOK &&
+ state->x.have == 0)
(void)gz_look(state);
/* return 1 if transparent, 0 if processing a gzip stream */
@@ -555,7 +590,8 @@ int gzclose_r(gzFile file)
return Z_STREAM_ERROR;
/* free memory and close file */
- if (state->size) {
+ if (state->size)
+ {
inflateEnd(&(state->strm));
free(state->out);
free(state->in);
diff --git a/deps/libz/gzwrite.c b/deps/libz/gzwrite.c
index a73adb4644..3eaf1fca84 100644
--- a/deps/libz/gzwrite.c
+++ b/deps/libz/gzwrite.c
@@ -3,15 +3,10 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
+#include
+
#include "gzguts.h"
-/* Local functions */
-static int gz_init (gz_statep);
-static int gz_comp (gz_statep, int);
-static int gz_zero (gz_statep, z_off64_t);
-
-int gzvprintf(gzFile file, const char *format, va_list va);
-
/* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on failure or 0 on success. */
static int gz_init(gz_statep state)
@@ -21,43 +16,48 @@ static int gz_init(gz_statep state)
/* allocate input buffer */
state->in = (unsigned char *)malloc(state->want);
- if (state->in == NULL) {
+ if (state->in == NULL)
+ {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
/* only need output buffer and deflate state if compressing */
- if (!state->direct) {
- /* allocate output buffer */
- state->out = (unsigned char *)malloc(state->want);
- if (state->out == NULL) {
- free(state->in);
- gz_error(state, Z_MEM_ERROR, "out of memory");
- return -1;
- }
+ if (!state->direct)
+ {
+ /* allocate output buffer */
+ state->out = (unsigned char *)malloc(state->want);
+ if (state->out == NULL)
+ {
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
- /* allocate deflate memory, set up for gzip compression */
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
- ret = deflateInit2(strm, state->level, Z_DEFLATED,
- MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
- if (ret != Z_OK) {
- free(state->out);
- free(state->in);
- gz_error(state, Z_MEM_ERROR, "out of memory");
- return -1;
- }
+ /* allocate deflate memory, set up for gzip compression */
+ strm->zalloc = Z_NULL;
+ strm->zfree = Z_NULL;
+ strm->opaque = Z_NULL;
+ ret = deflateInit2(strm, state->level, Z_DEFLATED,
+ MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+ if (ret != Z_OK)
+ {
+ free(state->out);
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
}
/* mark state as initialized */
- state->size = state->want;
+ state->size = state->want;
/* initialize write buffer if compressing */
- if (!state->direct) {
- strm->avail_out = state->size;
- strm->next_out = state->out;
- state->x.next = strm->next_out;
+ if (!state->direct)
+ {
+ strm->avail_out = state->size;
+ strm->next_out = state->out;
+ state->x.next = strm->next_out;
}
return 0;
}
@@ -79,9 +79,11 @@ static int gz_comp(gz_statep state, int flush)
return -1;
/* write directly if requested */
- if (state->direct) {
+ if (state->direct)
+ {
got = write(state->fd, strm->next_in, strm->avail_in);
- if (got < 0 || (unsigned)got != strm->avail_in) {
+ if (got < 0 || (unsigned)got != strm->avail_in)
+ {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
@@ -95,24 +97,28 @@ static int gz_comp(gz_statep state, int flush)
/* write out current buffer contents if full, or if flushing, but if
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
- (flush != Z_FINISH || ret == Z_STREAM_END))) {
- have = (unsigned)(strm->next_out - state->x.next);
- if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
- (unsigned)got != have)) {
- gz_error(state, Z_ERRNO, zstrerror());
- return -1;
- }
- if (strm->avail_out == 0) {
- strm->avail_out = state->size;
- strm->next_out = state->out;
- }
- state->x.next = strm->next_out;
+ (flush != Z_FINISH || ret == Z_STREAM_END)))
+ {
+ have = (unsigned)(strm->next_out - state->x.next);
+ if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
+ (unsigned)got != have))
+ {
+ gz_error(state, Z_ERRNO, zstrerror());
+ return -1;
+ }
+ if (strm->avail_out == 0)
+ {
+ strm->avail_out = state->size;
+ strm->next_out = state->out;
+ }
+ state->x.next = strm->next_out;
}
/* compress */
have = strm->avail_out;
- ret = deflate(strm, flush);
- if (ret == Z_STREAM_ERROR) {
+ ret = deflate(strm, flush);
+ if (ret == Z_STREAM_ERROR)
+ {
gz_error(state, Z_STREAM_ERROR,
"internal error: deflate stream corrupt");
return -1;
@@ -132,7 +138,6 @@ static int gz_comp(gz_statep state, int flush)
static int gz_zero(gz_statep state, z_off64_t len)
{
int first;
- unsigned n;
z_streamp strm = &(state->strm);
/* consume whatever's left in the input buffer */
@@ -141,16 +146,18 @@ static int gz_zero(gz_statep state, z_off64_t len)
/* compress len zeros (len guaranteed > 0) */
first = 1;
- while (len) {
- n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
+ while (len)
+ {
+ unsigned n = GT_OFF(state->size) || (z_off64_t)state->size > len ?
(unsigned)len : state->size;
- if (first) {
+ if (first)
+ {
memset(state->in, 0, n);
first = 0;
}
strm->avail_in = n;
- strm->next_in = state->in;
- state->x.pos += n;
+ strm->next_in = state->in;
+ state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return -1;
len -= n;
@@ -160,23 +167,25 @@ static int gz_zero(gz_statep state, z_off64_t len)
int gzwrite(gzFile file, voidpc buf, unsigned len)
{
- unsigned put = len;
gz_statep state;
z_streamp strm;
+ unsigned put = len;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
- strm = &(state->strm);
+ strm = &(state->strm);
/* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
+ if ( state->mode != GZ_WRITE ||
+ state->err != Z_OK)
return 0;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
- if ((int)len < 0) {
+ if ((int)len < 0)
+ {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
@@ -190,44 +199,47 @@ int gzwrite(gzFile file, voidpc buf, unsigned len)
return 0;
/* check for seek request */
- if (state->seek) {
+ if (state->seek)
+ {
state->seek = 0;
if (gz_zero(state, state->skip) == -1)
return 0;
}
/* for small len, copy to input buffer, otherwise compress directly */
- if (len < state->size) {
- /* copy to input buffer, compress when full */
- do {
- unsigned have, copy;
+ if (len < state->size)
+ {
+ /* copy to input buffer, compress when full */
+ do {
+ unsigned have, copy;
- if (strm->avail_in == 0)
- strm->next_in = state->in;
- have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
- copy = state->size - have;
- if (copy > len)
- copy = len;
- memcpy(state->in + have, buf, copy);
- strm->avail_in += copy;
- state->x.pos += copy;
- buf = (const char *)buf + copy;
- len -= copy;
- if (len && gz_comp(state, Z_NO_FLUSH) == -1)
- return 0;
- } while (len);
+ if (strm->avail_in == 0)
+ strm->next_in = state->in;
+ have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
+ copy = state->size - have;
+ if (copy > len)
+ copy = len;
+ memcpy(state->in + have, buf, copy);
+ strm->avail_in += copy;
+ state->x.pos += copy;
+ buf = (const char *)buf + copy;
+ len -= copy;
+ if (len && gz_comp(state, Z_NO_FLUSH) == -1)
+ return 0;
+ } while (len);
}
- else {
- /* consume whatever's left in the input buffer */
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
- return 0;
+ else
+ {
+ /* consume whatever's left in the input buffer */
+ if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
+ return 0;
- /* directly compress user buffer to file */
- strm->avail_in = len;
- strm->next_in = (Bytef *)buf;
- state->x.pos += len;
- if (gz_comp(state, Z_NO_FLUSH) == -1)
- return 0;
+ /* directly compress user buffer to file */
+ strm->avail_in = len;
+ strm->next_in = (Bytef *)buf;
+ state->x.pos += len;
+ if (gz_comp(state, Z_NO_FLUSH) == -1)
+ return 0;
}
/* input was all buffered or compressed (put will fit in int) */
@@ -236,314 +248,244 @@ int gzwrite(gzFile file, voidpc buf, unsigned len)
int gzputc(gzFile file, int c)
{
- unsigned have;
- unsigned char buf[1];
- gz_statep state;
- z_streamp strm;
+ unsigned have;
+ unsigned char buf[1];
+ gz_statep state;
+ z_streamp strm;
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- strm = &(state->strm);
+ /* get internal structure */
+ if (file == NULL)
+ return -1;
+ state = (gz_statep)file;
+ strm = &(state->strm);
- /* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
- return -1;
+ /* check that we're writing and that there's no error */
+ if ( state->mode != GZ_WRITE ||
+ state->err != Z_OK)
+ return -1;
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- return -1;
- }
+ /* check for seek request */
+ if (state->seek)
+ {
+ state->seek = 0;
+ if (gz_zero(state, state->skip) == -1)
+ return -1;
+ }
- /* try writing to input buffer for speed (state->size == 0 if buffer not
- initialized) */
- if (state->size) {
- if (strm->avail_in == 0)
- strm->next_in = state->in;
- have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
- if (have < state->size) {
- state->in[have] = c;
- strm->avail_in++;
- state->x.pos++;
- return c & 0xff;
- }
- }
+ /* try writing to input buffer for speed (state->size == 0 if buffer not
+ initialized) */
+ if (state->size)
+ {
+ if (strm->avail_in == 0)
+ strm->next_in = state->in;
+ have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
+ if (have < state->size)
+ {
+ state->in[have] = c;
+ strm->avail_in++;
+ state->x.pos++;
+ return c & 0xff;
+ }
+ }
- /* no room in buffer or not initialized, use gz_write() */
- buf[0] = c;
- if (gzwrite(file, buf, 1) != 1)
- return -1;
- return c & 0xff;
+ /* no room in buffer or not initialized, use gz_write() */
+ buf[0] = c;
+ if (gzwrite(file, buf, 1) != 1)
+ return -1;
+ return c & 0xff;
}
int gzputs(gzFile file, const char *str)
{
- int ret;
- unsigned len;
-
- /* write string */
- len = (unsigned)strlen(str);
- ret = gzwrite(file, str, len);
- return ret == 0 && len != 0 ? -1 : ret;
+ /* write string */
+ unsigned len = (unsigned)strlen(str);
+ int ret = gzwrite(file, str, len);
+ return ret == 0 && len != 0 ? -1 : ret;
}
-#if defined(STDC) || defined(Z_HAVE_STDARG_H)
-#include
-
int gzvprintf(gzFile file, const char *format, va_list va)
{
- int size, len;
- gz_statep state;
- z_streamp strm;
+ int size, len;
+ gz_statep state;
+ z_streamp strm;
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- strm = &(state->strm);
+ /* get internal structure */
+ if (file == NULL)
+ return -1;
+ state = (gz_statep)file;
+ strm = &(state->strm);
- /* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
- return 0;
+ /* check that we're writing and that there's no error */
+ if (state->mode != GZ_WRITE || state->err != Z_OK)
+ return 0;
- /* make sure we have some buffer space */
- if (state->size == 0 && gz_init(state) == -1)
- return 0;
+ /* make sure we have some buffer space */
+ if (state->size == 0 && gz_init(state) == -1)
+ return 0;
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- return 0;
- }
+ /* check for seek request */
+ if (state->seek) {
+ state->seek = 0;
+ if (gz_zero(state, state->skip) == -1)
+ return 0;
+ }
- /* consume whatever's left in the input buffer */
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
- return 0;
+ /* consume whatever's left in the input buffer */
+ if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
+ return 0;
- /* do the printf() into the input buffer, put length in len */
- size = (int)(state->size);
- state->in[size - 1] = 0;
+ /* do the printf() into the input buffer, put length in len */
+ size = (int)(state->size);
+ state->in[size - 1] = 0;
#ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void
- (void)vsprintf((char *)(state->in), format, va);
- for (len = 0; len < size; len++)
- if (state->in[len] == 0) break;
+ (void)vsprintf((char *)(state->in), format, va);
+ for (len = 0; len < size; len++)
+ if (state->in[len] == 0) break;
# else
- len = vsprintf((char *)(state->in), format, va);
+ len = vsprintf((char *)(state->in), format, va);
# endif
#else
# ifdef HAS_vsnprintf_void
- (void)vsnprintf((char *)(state->in), size, format, va);
- len = strlen((char *)(state->in));
+ (void)vsnprintf((char *)(state->in), size, format, va);
+ len = strlen((char *)(state->in));
# else
- len = vsnprintf((char *)(state->in), size, format, va);
+ len = vsnprintf((char *)(state->in), size, format, va);
# endif
#endif
- /* check that printf() results fit in buffer */
- if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
- return 0;
+ /* check that printf() results fit in buffer */
+ if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
+ return 0;
- /* update buffer and position, defer compression until needed */
- strm->avail_in = (unsigned)len;
- strm->next_in = state->in;
- state->x.pos += len;
- return len;
+ /* update buffer and position, defer compression until needed */
+ strm->avail_in = (unsigned)len;
+ strm->next_in = state->in;
+ state->x.pos += len;
+ return len;
}
int gzprintf(gzFile file, const char *format, ...)
{
- va_list va;
- int ret;
+ va_list va;
+ int ret;
- va_start(va, format);
- ret = gzvprintf(file, format, va);
- va_end(va);
- return ret;
+ va_start(va, format);
+ ret = gzvprintf(file, format, va);
+ va_end(va);
+ return ret;
}
-#else /* !STDC && !Z_HAVE_STDARG_H */
-
-int gzprintf (gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10,
- int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
-{
- int size, len;
- gz_statep state;
- z_streamp strm;
-
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- strm = &(state->strm);
-
- /* check that can really pass pointer in ints */
- if (sizeof(int) != sizeof(void *))
- return 0;
-
- /* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
- return 0;
-
- /* make sure we have some buffer space */
- if (state->size == 0 && gz_init(state) == -1)
- return 0;
-
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- return 0;
- }
-
- /* consume whatever's left in the input buffer */
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
- return 0;
-
- /* do the printf() into the input buffer, put length in len */
- size = (int)(state->size);
- state->in[size - 1] = 0;
-#ifdef NO_snprintf
-# ifdef HAS_sprintf_void
- sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- for (len = 0; len < size; len++)
- if (state->in[len] == 0) break;
-# else
- len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
-# endif
-#else
-# ifdef HAS_snprintf_void
- snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- len = strlen((char *)(state->in));
-# else
- len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
- a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
- a19, a20);
-# endif
-#endif
-
- /* check that printf() results fit in buffer */
- if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
- return 0;
-
- /* update buffer and position, defer compression until needed */
- strm->avail_in = (unsigned)len;
- strm->next_in = state->in;
- state->x.pos += len;
- return len;
-}
-
-#endif
-
int gzflush(gzFile file, int flush)
{
- gz_statep state;
+ gz_statep state;
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
+ /* get internal structure */
+ if (file == NULL)
+ return -1;
+ state = (gz_statep)file;
- /* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
- return Z_STREAM_ERROR;
+ /* check that we're writing and that there's no error */
+ if (state->mode != GZ_WRITE || state->err != Z_OK)
+ return Z_STREAM_ERROR;
- /* check flush parameter */
- if (flush < 0 || flush > Z_FINISH)
- return Z_STREAM_ERROR;
+ /* check flush parameter */
+ if (flush < 0 || flush > Z_FINISH)
+ return Z_STREAM_ERROR;
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- return -1;
- }
+ /* check for seek request */
+ if (state->seek)
+ {
+ state->seek = 0;
+ if (gz_zero(state, state->skip) == -1)
+ return -1;
+ }
- /* compress remaining data with requested flush */
- gz_comp(state, flush);
- return state->err;
+ /* compress remaining data with requested flush */
+ gz_comp(state, flush);
+ return state->err;
}
int gzsetparams(gzFile file, int level, int strategy)
{
- gz_statep state;
- z_streamp strm;
+ gz_statep state;
+ z_streamp strm;
- /* get internal structure */
- if (file == NULL)
- return Z_STREAM_ERROR;
- state = (gz_statep)file;
- strm = &(state->strm);
+ /* get internal structure */
+ if (file == NULL)
+ return Z_STREAM_ERROR;
+ state = (gz_statep)file;
+ strm = &(state->strm);
- /* check that we're writing and that there's no error */
- if (state->mode != GZ_WRITE || state->err != Z_OK)
- return Z_STREAM_ERROR;
+ /* check that we're writing and that there's no error */
+ if ( state->mode != GZ_WRITE ||
+ state->err != Z_OK)
+ return Z_STREAM_ERROR;
- /* if no change is requested, then do nothing */
- if (level == state->level && strategy == state->strategy)
- return Z_OK;
+ /* if no change is requested, then do nothing */
+ if ( level == state->level &&
+ strategy == state->strategy)
+ return Z_OK;
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- return -1;
- }
+ /* check for seek request */
+ if (state->seek)
+ {
+ state->seek = 0;
+ if (gz_zero(state, state->skip) == -1)
+ return -1;
+ }
- /* change compression parameters for subsequent input */
- if (state->size) {
- /* flush previous input with previous parameters before changing */
- if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
- return state->err;
- deflateParams(strm, level, strategy);
- }
- state->level = level;
- state->strategy = strategy;
- return Z_OK;
+ /* change compression parameters for subsequent input */
+ if (state->size)
+ {
+ /* flush previous input with previous parameters before changing */
+ if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
+ return state->err;
+ deflateParams(strm, level, strategy);
+ }
+ state->level = level;
+ state->strategy = strategy;
+ return Z_OK;
}
int gzclose_w(gzFile file)
{
- int ret = Z_OK;
- gz_statep state;
+ int ret = Z_OK;
+ gz_statep state;
- /* get internal structure */
- if (file == NULL)
- return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ /* get internal structure */
+ if (file == NULL)
+ return Z_STREAM_ERROR;
+ state = (gz_statep)file;
- /* check that we're writing */
- if (state->mode != GZ_WRITE)
- return Z_STREAM_ERROR;
+ /* check that we're writing */
+ if (state->mode != GZ_WRITE)
+ return Z_STREAM_ERROR;
- /* check for seek request */
- if (state->seek) {
- state->seek = 0;
- if (gz_zero(state, state->skip) == -1)
- ret = state->err;
- }
+ /* check for seek request */
+ if (state->seek)
+ {
+ state->seek = 0;
+ if (gz_zero(state, state->skip) == -1)
+ ret = state->err;
+ }
- /* flush, free memory, and close file */
- if (gz_comp(state, Z_FINISH) == -1)
- ret = state->err;
- if (state->size) {
- if (!state->direct) {
- (void)deflateEnd(&(state->strm));
- free(state->out);
- }
- free(state->in);
- }
- gz_error(state, Z_OK, NULL);
- free(state->path);
- if (close(state->fd) == -1)
- ret = Z_ERRNO;
- free(state);
- return ret;
+ /* flush, free memory, and close file */
+ if (gz_comp(state, Z_FINISH) == -1)
+ ret = state->err;
+ if (state->size)
+ {
+ if (!state->direct)
+ {
+ (void)deflateEnd(&(state->strm));
+ free(state->out);
+ }
+ free(state->in);
+ }
+ gz_error(state, Z_OK, NULL);
+ free(state->path);
+ if (close(state->fd) == -1)
+ ret = Z_ERRNO;
+ free(state);
+ return ret;
}
diff --git a/deps/libz/inffast.c b/deps/libz/inffast.c
index a88859f37d..74c893eac8 100644
--- a/deps/libz/inffast.c
+++ b/deps/libz/inffast.c
@@ -10,25 +10,6 @@
#ifndef ASMINF
-/* Allow machine dependent optimization for post-increment or pre-increment.
- Based on testing to date,
- Pre-increment preferred for:
- - PowerPC G3 (Adler)
- - MIPS R5000 (Randers-Pehrson)
- Post-increment preferred for:
- - none
- No measurable difference:
- - Pentium III (Anderson)
- - M68060 (Nikl)
- */
-#ifdef POSTINC
-# define OFF 0
-# define PUP(a) *(a)++
-#else
-# define OFF 1
-# define PUP(a) *++(a)
-#endif
-
/*
Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is
@@ -66,26 +47,7 @@ output space.
*/
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
{
- struct inflate_state FAR *state;
- unsigned char FAR *in; /* local strm->next_in */
- unsigned char FAR *last; /* have enough input while in < last */
- unsigned char FAR *out; /* local strm->next_out */
- unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
- unsigned char FAR *end; /* while out < end, enough space available */
-#ifdef INFLATE_STRICT
- unsigned dmax; /* maximum distance from zlib header */
-#endif
- unsigned wsize; /* window size or zero if not using window */
- unsigned whave; /* valid bytes in the window */
- unsigned wnext; /* window write index */
- unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
- unsigned long hold; /* local strm->hold */
- unsigned bits; /* local strm->bits */
- code const FAR *lcode; /* local strm->lencode */
- code const FAR *dcode; /* local strm->distcode */
- unsigned lmask; /* mask for first level of length codes */
- unsigned dmask; /* mask for first level of distance codes */
- code here; /* retrieved table entry */
+ code const *here; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */
@@ -93,211 +55,209 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
unsigned char FAR *from; /* where to copy match from */
/* copy state to local variables */
- state = (struct inflate_state FAR *)strm->state;
- in = strm->next_in - OFF;
- last = in + (strm->avail_in - 5);
- out = strm->next_out - OFF;
- beg = out - (start - strm->avail_out);
- end = out + (strm->avail_out - 257);
-#ifdef INFLATE_STRICT
- dmax = state->dmax;
-#endif
- wsize = state->wsize;
- whave = state->whave;
- wnext = state->wnext;
- window = state->window;
- hold = state->hold;
- bits = state->bits;
- lcode = state->lencode;
- dcode = state->distcode;
- lmask = (1U << state->lenbits) - 1;
- dmask = (1U << state->distbits) - 1;
+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
+ unsigned char FAR *in = strm->next_in;
+ unsigned char FAR *last = in + (strm->avail_in - 5);
+ unsigned char FAR *out = strm->next_out;
+ unsigned char FAR *beg = out - (start - strm->avail_out);
+ unsigned char FAR *end = out + (strm->avail_out - 257);
+ unsigned wsize = state->wsize;
+ unsigned whave = state->whave;
+ unsigned wnext = state->wnext;
+ unsigned char FAR *window = state->window;
+ unsigned long hold = state->hold;
+ unsigned bits = state->bits;
+ code const FAR *lcode = state->lencode;
+ code const FAR *dcode = state->distcode;
+ unsigned lmask = (1U << state->lenbits) - 1;
+ unsigned dmask = (1U << state->distbits) - 1;
/* decode literals and length/distances until end-of-block or not enough
input data or output space */
- do {
- if (bits < 15) {
- hold += (unsigned long)(PUP(in)) << bits;
+ do
+ {
+ if (bits < 15)
+ {
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
- here = lcode[hold & lmask];
+ here = lcode + (hold & lmask);
dolen:
- op = (unsigned)(here.bits);
+ op = (unsigned)(here->bits);
hold >>= op;
bits -= op;
- op = (unsigned)(here.op);
- if (op == 0) { /* literal */
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
- PUP(out) = (unsigned char)(here.val);
- }
- else if (op & 16) { /* length base */
- len = (unsigned)(here.val);
+ op = (unsigned)(here->op);
+ if (op == 0) /* literal */
+ *out++ = (unsigned char)(here->val);
+ else if (op & 16) /* length base */
+ {
+ len = (unsigned)(here->val);
op &= 15; /* number of extra bits */
- if (op) {
- if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ if (op)
+ {
+ if (bits < op)
+ {
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
- len += (unsigned)hold & ((1U << op) - 1);
+ len += (unsigned)hold & ((1U << op) - 1);
hold >>= op;
- bits -= op;
+ bits -= op;
}
- Tracevv((stderr, "inflate: length %u\n", len));
- if (bits < 15) {
- hold += (unsigned long)(PUP(in)) << bits;
+
+ if (bits < 15)
+ {
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
- hold += (unsigned long)(PUP(in)) << bits;
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
- here = dcode[hold & dmask];
+
+ here = dcode + (hold & dmask);
+
dodist:
- op = (unsigned)(here.bits);
+ op = (unsigned)(here->bits);
hold >>= op;
bits -= op;
- op = (unsigned)(here.op);
- if (op & 16) { /* distance base */
- dist = (unsigned)(here.val);
+ op = (unsigned)(here->op);
+ if (op & 16) /* distance base */
+ {
+ dist = (unsigned)(here->val);
op &= 15; /* number of extra bits */
- if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ if (bits < op)
+ {
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
- if (bits < op) {
- hold += (unsigned long)(PUP(in)) << bits;
+ if (bits < op)
+ {
+ hold += (unsigned long)(*in++) << bits;
bits += 8;
}
}
- dist += (unsigned)hold & ((1U << op) - 1);
-#ifdef INFLATE_STRICT
- if (dist > dmax) {
- strm->msg = (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#endif
+ dist += (unsigned)hold & ((1U << op) - 1);
hold >>= op;
- bits -= op;
- Tracevv((stderr, "inflate: distance %u\n", dist));
- op = (unsigned)(out - beg); /* max distance in output */
- if (dist > op) { /* see if copy from window */
- op = dist - op; /* distance back in window */
- if (op > whave) {
- if (state->sane) {
+ bits -= op;
+ op = (unsigned)(out - beg); /* max distance in output */
+ if (dist > op) /* see if copy from window */
+ {
+ op = dist - op; /* distance back in window */
+ if (op > whave)
+ {
+ if (state->sane)
+ {
strm->msg =
(char *)"invalid distance too far back";
state->mode = BAD;
break;
}
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- if (len <= op - whave) {
- do {
- PUP(out) = 0;
- } while (--len);
- continue;
- }
- len -= op - whave;
- do {
- PUP(out) = 0;
- } while (--op > whave);
- if (op == 0) {
- from = out - dist;
- do {
- PUP(out) = PUP(from);
- } while (--len);
- continue;
- }
-#endif
}
- from = window - OFF;
- if (wnext == 0) { /* very common case */
+ from = window;
+ if (wnext == 0) /* very common case */
+ {
from += wsize - op;
- if (op < len) { /* some from window */
+ if (op < len) /* some from window */
+ {
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
- else if (wnext < op) { /* wrap around window */
+ else if (wnext < op) /* wrap around window */
+ {
from += wsize + wnext - op;
op -= wnext;
- if (op < len) { /* some from end of window */
+ if (op < len) /* some from end of window */
+ {
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
- from = window - OFF;
- if (wnext < len) { /* some from start of window */
+ from = window;
+ if (wnext < len) /* some from start of window */
+ {
op = wnext;
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
}
- else { /* contiguous in window */
+ else /* contiguous in window */
+ {
from += wnext - op;
- if (op < len) { /* some from window */
+ if (op < len) /* some from window */
+ {
len -= op;
do {
- PUP(out) = PUP(from);
+ *out++ = *from++;
} while (--op);
from = out - dist; /* rest from output */
}
}
- while (len > 2) {
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
+
+ while (len > 2)
+ {
+ *out++ = *from++;
+ *out++ = *from++;
+ *out++ = *from++;
len -= 3;
}
- if (len) {
- PUP(out) = PUP(from);
+
+ if (len)
+ {
+ *out++ = *from++;
if (len > 1)
- PUP(out) = PUP(from);
+ *out++ = *from++;
}
}
- else {
+ else
+ {
from = out - dist; /* copy direct from output */
do { /* minimum length is three */
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
- PUP(out) = PUP(from);
+ *out++ = *from++;
+ *out++ = *from++;
+ *out++ = *from++;
len -= 3;
- } while (len > 2);
- if (len) {
- PUP(out) = PUP(from);
+ }while(len > 2);
+
+ if (len)
+ {
+ *out++ = *from++;
if (len > 1)
- PUP(out) = PUP(from);
+ *out++ = *from++;
}
}
}
- else if ((op & 64) == 0) { /* 2nd level distance code */
- here = dcode[here.val + (hold & ((1U << op) - 1))];
+ else if ((op & 64) == 0) /* 2nd level distance code */
+ {
+ here = dcode + here->val + (hold & ((1U << op) - 1));
goto dodist;
}
- else {
- strm->msg = (char *)"invalid distance code";
+ else
+ {
+ strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
}
- else if ((op & 64) == 0) { /* 2nd level length code */
- here = lcode[here.val + (hold & ((1U << op) - 1))];
+ else if ((op & 64) == 0) /* 2nd level length code */
+ {
+ here = lcode + here->val + (hold & ((1U << op) - 1));
goto dolen;
}
- else if (op & 32) { /* end-of-block */
- Tracevv((stderr, "inflate: end of block\n"));
+ else if (op & 32) /* end-of-block */
+ {
state->mode = TYPE;
break;
}
- else {
+ else
+ {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
@@ -305,20 +265,19 @@ dodist:
} while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
- len = bits >> 3;
- in -= len;
- bits -= len << 3;
- hold &= (1U << bits) - 1;
+ len = bits >> 3;
+ in -= len;
+ bits -= len << 3;
+ hold &= (1U << bits) - 1;
/* update state and return */
- strm->next_in = in + OFF;
- strm->next_out = out + OFF;
- strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
- strm->avail_out = (unsigned)(out < end ?
+ strm->next_in = in;
+ strm->next_out = out;
+ strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
+ strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
- state->hold = hold;
- state->bits = bits;
- return;
+ state->hold = hold;
+ state->bits = bits;
}
/*
diff --git a/deps/libz/inflate.c b/deps/libz/inflate.c
index 183a75784b..3e6d9688fa 100644
--- a/deps/libz/inflate.c
+++ b/deps/libz/inflate.c
@@ -95,59 +95,51 @@
#define Z_TREES 6
#endif
- /* function prototypes */
-int inflateReset2(z_streamp strm, int windowBits);
- static void fixedtables (struct inflate_state FAR *state);
- static int updatewindow (z_streamp strm, const unsigned char FAR *end,
- unsigned copy);
-#ifdef BUILDFIXED
-void makefixed (void);
-#endif
-static unsigned syncsearch (unsigned FAR *have, const unsigned char FAR *buf,
- unsigned len);
-
-long inflateMark(z_streamp strm);
-
-int inflateResetKeep(z_streamp strm);
-
-int inflateUndermine(z_streamp strm, int subvert);
-
-int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);
-
int inflateResetKeep(z_streamp strm)
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- strm->total_in = strm->total_out = state->total = 0;
- strm->msg = Z_NULL;
- if (state->wrap) /* to support ill-conceived Java test suite */
- strm->adler = state->wrap & 1;
- state->mode = HEAD;
- state->last = 0;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
+ state = (struct inflate_state FAR *)strm->state;
+ strm->total_in = strm->total_out = state->total = 0;
+ strm->msg = Z_NULL;
+
+ /* to support ill-conceived Java test suite */
+ if (state->wrap)
+ strm->adler = state->wrap & 1;
+
+ state->mode = HEAD;
+ state->last = 0;
state->havedict = 0;
- state->dmax = 32768U;
- state->head = Z_NULL;
- state->hold = 0;
- state->bits = 0;
- state->lencode = state->distcode = state->next = state->codes;
- state->sane = 1;
- state->back = -1;
- Tracev((stderr, "inflate: reset\n"));
+ state->head = Z_NULL;
+ state->hold = 0;
+ state->bits = 0;
+ state->lencode = state->distcode = state->next = state->codes;
+ state->sane = 1;
+ state->back = -1;
return Z_OK;
}
int inflateReset(z_streamp strm)
{
+ int ret;
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
+ state = (struct inflate_state FAR *)strm->state;
state->wsize = 0;
state->whave = 0;
state->wnext = 0;
- return inflateResetKeep(strm);
+
+ ret = inflateResetKeep(strm);
+
+ return ret;
}
int inflateReset2(z_streamp strm, int windowBits)
@@ -156,17 +148,20 @@ int inflateReset2(z_streamp strm, int windowBits)
struct inflate_state FAR *state = NULL;
/* get the state */
- if (strm == Z_NULL || strm->state == Z_NULL)
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
+ state = (struct inflate_state FAR *)strm->state;
/* extract wrap request from windowBits parameter */
- if (windowBits < 0) {
- wrap = 0;
- windowBits = -windowBits;
+ if (windowBits < 0)
+ {
+ wrap = 0;
+ windowBits = -windowBits;
}
- else {
- wrap = (windowBits >> 4) + 1;
+ else
+ {
+ wrap = (windowBits >> 4) + 5;
#ifdef GUNZIP
if (windowBits < 48)
windowBits &= 15;
@@ -176,50 +171,86 @@ int inflateReset2(z_streamp strm, int windowBits)
/* set number of window bits, free window if different */
if (windowBits && (windowBits < 8 || windowBits > 15))
return Z_STREAM_ERROR;
- if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
- ZFREE(strm, state->window);
+
+ if ( state->window != Z_NULL &&
+ state->wbits != (unsigned)windowBits)
+ {
+ free(state->window);
state->window = Z_NULL;
}
/* update state and reset the rest of it */
- state->wrap = wrap;
+ state->wrap = wrap;
state->wbits = (unsigned)windowBits;
return inflateReset(strm);
}
-int inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
+int inflateInit2_(z_streamp strm, int windowBits,
+ const char *version, int stream_size)
{
int ret;
+ unsigned i;
struct inflate_state FAR *state;
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ if ( version == Z_NULL ||
+ version[0] != ZLIB_VERSION[0] ||
stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
- if (strm == Z_NULL) return Z_STREAM_ERROR;
- strm->msg = Z_NULL; /* in case we return an error */
- if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
+ if (strm == Z_NULL)
return Z_STREAM_ERROR;
-#else
- strm->zalloc = zcalloc;
- strm->opaque = (voidpf)0;
-#endif
+ strm->msg = Z_NULL; /* in case we return an error */
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ strm->zfree = zcfree;
+ state = (struct inflate_state FAR *)
+ malloc(sizeof(*state));
+ if (state == Z_NULL)
+ return Z_MEM_ERROR;
+ state->mode = HEAD;
+ state->last = 0;
+ state->wrap = 0;
+ state->havedict = 0;
+ state->flags = 0;
+ state->check = 0;
+ state->total = 0;
+ state->head = Z_NULL;
+ state->wbits = 0;
+ state->wsize = 0;
+ state->whave = 0;
+ state->wnext = 0;
+ state->window = Z_NULL;
+ state->hold = 0;
+ state->bits = 0;
+ state->length = 0;
+ state->offset = 0;
+ state->extra = 0;
+ state->lencode = Z_NULL;
+ state->distcode = Z_NULL;
+ state->lenbits = 0;
+ state->distbits = 0;
+ state->ncode = 0;
+ state->nlen = 0;
+ state->ndist = 0;
+ state->have = 0;
+ state->next = Z_NULL;
+ for (i = 0; i < 320; i++)
+ state->lens[i] = 0;
+ for (i = 0; i < 288; i++)
+ state->work[i] = 0;
+ for (i = 0; i < ENOUGH; i++)
+ {
+ state->codes[i].op = 0;
+ state->codes[i].bits = 0;
+ state->codes[i].val = 0;
}
- if (strm->zfree == Z_NULL)
-#ifdef Z_SOLO
- return Z_STREAM_ERROR;
-#else
- strm->zfree = zcfree;
-#endif
- state = (struct inflate_state FAR *)
- ZALLOC(strm, 1, sizeof(struct inflate_state));
- if (state == Z_NULL) return Z_MEM_ERROR;
- Tracev((stderr, "inflate: allocated\n"));
- strm->state = (struct internal_state FAR *)state;
- state->window = Z_NULL;
- ret = inflateReset2(strm, windowBits);
- if (ret != Z_OK) {
- ZFREE(strm, state);
+ state->sane = 0;
+ state->back = 0;
+ state->was = 0;
+ strm->state = (struct internal_state FAR *)state;
+ ret = inflateReset2(strm, windowBits);
+ if (ret != Z_OK)
+ {
+ free(state);
strm->state = Z_NULL;
}
return ret;
@@ -234,17 +265,24 @@ int inflatePrime(z_streamp strm, int bits, int value)
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (bits < 0) {
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
+ state = (struct inflate_state FAR *)strm->state;
+
+ if (bits < 0)
+ {
state->hold = 0;
state->bits = 0;
return Z_OK;
}
- if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
- value &= (1L << bits) - 1;
- state->hold += value << state->bits;
- state->bits += bits;
+ if (bits > 16 || state->bits + bits > 32)
+ return Z_STREAM_ERROR;
+
+ value &= (1L << bits) - 1;
+ state->hold += (unsigned)value << state->bits;
+ state->bits += bits;
+
return Z_OK;
}
@@ -266,24 +304,29 @@ static void fixedtables(struct inflate_state FAR *state)
static code fixed[544];
/* build fixed huffman tables if first call (may not be thread safe) */
- if (virgin) {
- unsigned sym, bits;
+ if (virgin)
+ {
+ unsigned bits;
static code *next;
-
/* literal/length table */
- sym = 0;
- while (sym < 144) state->lens[sym++] = 8;
- while (sym < 256) state->lens[sym++] = 9;
- while (sym < 280) state->lens[sym++] = 7;
- while (sym < 288) state->lens[sym++] = 8;
- next = fixed;
- lenfix = next;
- bits = 9;
+ unsigned sym = 0;
+ while (sym < 144)
+ state->lens[sym++] = 8;
+ while (sym < 256)
+ state->lens[sym++] = 9;
+ while (sym < 280)
+ state->lens[sym++] = 7;
+ while (sym < 288)
+ state->lens[sym++] = 8;
+ next = fixed;
+ lenfix = next;
+ bits = 9;
inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
/* distance table */
- sym = 0;
- while (sym < 32) state->lens[sym++] = 5;
+ sym = 0;
+ while (sym < 32)
+ state->lens[sym++] = 5;
distfix = next;
bits = 5;
inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
@@ -294,8 +337,8 @@ static void fixedtables(struct inflate_state FAR *state)
#else /* !BUILDFIXED */
# include "inffixed.h"
#endif /* BUILDFIXED */
- state->lencode = lenfix;
- state->lenbits = 9;
+ state->lencode = lenfix;
+ state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
@@ -377,46 +420,53 @@ void makefixed(void)
*/
static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
{
- struct inflate_state FAR *state;
unsigned dist;
-
- state = (struct inflate_state FAR *)strm->state;
+ struct inflate_state FAR *state = (struct inflate_state FAR *)strm->state;
/* if it hasn't been done already, allocate space for the window */
- if (state->window == Z_NULL) {
+ if (state->window == Z_NULL)
+ {
state->window = (unsigned char FAR *)
- ZALLOC(strm, 1U << state->wbits,
+ calloc(1U << state->wbits,
sizeof(unsigned char));
- if (state->window == Z_NULL) return 1;
+ if (state->window == Z_NULL)
+ return 1;
}
/* if window not in use yet, initialize */
- if (state->wsize == 0) {
+ if (state->wsize == 0)
+ {
state->wsize = 1U << state->wbits;
state->wnext = 0;
state->whave = 0;
}
/* copy state->wsize or less output bytes into the circular window */
- if (copy >= state->wsize) {
- zmemcpy(state->window, end - state->wsize, state->wsize);
+ if (copy >= state->wsize)
+ {
+ memcpy(state->window, end - state->wsize, state->wsize);
state->wnext = 0;
state->whave = state->wsize;
}
- else {
+ else
+ {
dist = state->wsize - state->wnext;
if (dist > copy) dist = copy;
- zmemcpy(state->window + state->wnext, end - copy, dist);
+ memcpy(state->window + state->wnext, end - copy, dist);
copy -= dist;
- if (copy) {
- zmemcpy(state->window, end - copy, copy);
+ if (copy)
+ {
+ memcpy(state->window, end - copy, copy);
state->wnext = copy;
state->whave = state->wsize;
}
- else {
+ else
+ {
state->wnext += dist;
- if (state->wnext == state->wsize) state->wnext = 0;
- if (state->whave < state->wsize) state->whave += dist;
+ if (state->wnext == state->wsize)
+ state->wnext = 0;
+ if (state->whave < state->wsize)
+ state->whave += dist;
}
}
return 0;
@@ -516,88 +566,6 @@ static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
bits -= bits & 7; \
} while (0)
-/*
- inflate() uses a state machine to process as much input data and generate as
- much output data as possible before returning. The state machine is
- structured roughly as follows:
-
- for (;;) switch (state) {
- ...
- case STATEn:
- if (not enough input data or output space to make progress)
- return;
- ... make progress ...
- state = STATEm;
- break;
- ...
- }
-
- so when inflate() is called again, the same case is attempted again, and
- if the appropriate resources are provided, the machine proceeds to the
- next state. The NEEDBITS() macro is usually the way the state evaluates
- whether it can proceed or should return. NEEDBITS() does the return if
- the requested bits are not available. The typical use of the BITS macros
-is:
-
-NEEDBITS(n);
-... do something with BITS(n) ...
-DROPBITS(n);
-
-where NEEDBITS(n) either returns from inflate() if there isn't enough
-input left to load n bits into the accumulator, or it continues. BITS(n)
-gives the low n bits in the accumulator. When done, DROPBITS(n) drops
-the low n bits off the accumulator. INITBITS() clears the accumulator
-and sets the number of available bits to zero. BYTEBITS() discards just
-enough bits to put the accumulator on a byte boundary. After BYTEBITS()
-and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
-
-NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
-if there is no input available. The decoding of variable length codes uses
-PULLBYTE() directly in order to pull just enough bytes to decode the next
-code, and no more.
-
-Some states loop until they get enough input, making sure that enough
-state information is maintained to continue the loop where it left off
-if NEEDBITS() returns in the loop. For example, want, need, and keep
-would all have to actually be part of the saved state in case NEEDBITS()
-returns:
-
-case STATEw:
-while (want < need) {
-NEEDBITS(n);
-keep[want++] = BITS(n);
-DROPBITS(n);
-}
-state = STATEx;
-case STATEx:
-
-As shown above, if the next state is also the next case, then the break
-is omitted.
-
-A state may also return if there is not enough output space available to
-complete that state. Those states are copying stored data, writing a
-literal byte, and copying a matching string.
-
-When returning, a "goto inf_leave" is used to update the total counters,
-update the check value, and determine whether any progress has been made
-during that inflate() call in order to return the proper return code.
-Progress is defined as a change in either strm->avail_in or strm->avail_out.
-When there is a window, goto inf_leave will update the window with the last
-output written. If a goto inf_leave occurs in the middle of decompression
-and there is no window currently, goto inf_leave will create one and copy
-output to the window for the next call of inflate().
-
-In this implementation, the flush parameter of inflate() only affects the
-return code (per zlib.h). inflate() always writes as much as possible to
-strm->next_out, given the space available and the provided input--the effect
-documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
-the allocation of and copying into a sliding window until necessary, which
-provides the effect documented in zlib.h for Z_FINISH when the entire input
-stream available. So the only thing the flush parameter actually does is:
-when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
-will return Z_BUF_ERROR if it has not reached the end of the stream.
-*/
-
int inflate(z_streamp strm, int flush)
{
struct inflate_state FAR *state;
@@ -639,6 +607,8 @@ int inflate(z_streamp strm, int flush)
NEEDBITS(16);
#ifdef GUNZIP
if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
+ if (state->wbits == 0)
+ state->wbits = 15;
state->check = crc32(0L, Z_NULL, 0);
CRC2(state->check, hold);
INITBITS();
@@ -665,14 +635,12 @@ int inflate(z_streamp strm, int flush)
DROPBITS(4);
len = BITS(4) + 8;
if (state->wbits == 0)
- state->wbits = len;
- else if (len > state->wbits) {
+ state->wbits = len;
+ if (len > 15 || len > state->wbits) {
strm->msg = (char *)"invalid window size";
state->mode = BAD;
break;
}
- state->dmax = 1U << len;
- Tracev((stderr, "inflate: zlib header ok\n"));
strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = hold & 0x200 ? DICTID : TYPE;
INITBITS();
@@ -693,14 +661,16 @@ int inflate(z_streamp strm, int flush)
}
if (state->head != Z_NULL)
state->head->text = (int)((hold >> 8) & 1);
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
state->mode = TIME;
case TIME:
NEEDBITS(32);
if (state->head != Z_NULL)
state->head->time = hold;
- if (state->flags & 0x0200) CRC4(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC4(state->check, hold);
INITBITS();
state->mode = OS;
case OS:
@@ -709,7 +679,8 @@ int inflate(z_streamp strm, int flush)
state->head->xflags = (int)(hold & 0xff);
state->head->os = (int)(hold >> 8);
}
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
state->mode = EXLEN;
case EXLEN:
@@ -718,7 +689,8 @@ int inflate(z_streamp strm, int flush)
state->length = (unsigned)(hold);
if (state->head != Z_NULL)
state->head->extra_len = (unsigned)hold;
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if ((state->flags & 0x0200) && (state->wrap & 4))
+ CRC2(state->check, hold);
INITBITS();
}
else if (state->head != Z_NULL)
@@ -732,11 +704,11 @@ int inflate(z_streamp strm, int flush)
if (state->head != Z_NULL &&
state->head->extra != Z_NULL) {
len = state->head->extra_len - state->length;
- zmemcpy(state->head->extra + len, next,
+ memcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ?
state->head->extra_max - len : copy);
}
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -757,7 +729,7 @@ int inflate(z_streamp strm, int flush)
state->length < state->head->name_max)
state->head->name[state->length++] = len;
} while (len && copy < have);
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -778,7 +750,7 @@ int inflate(z_streamp strm, int flush)
state->length < state->head->comm_max)
state->head->comment[state->length++] = len;
} while (len && copy < have);
- if (state->flags & 0x0200)
+ if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
@@ -790,7 +762,7 @@ int inflate(z_streamp strm, int flush)
case HCRC:
if (state->flags & 0x0200) {
NEEDBITS(16);
- if (hold != (state->check & 0xffff)) {
+ if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
strm->msg = (char *)"header crc mismatch";
state->mode = BAD;
break;
@@ -830,14 +802,10 @@ int inflate(z_streamp strm, int flush)
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
- state->last ? " (last)" : ""));
state->mode = LEN_; /* decode codes */
if (flush == Z_TREES) {
DROPBITS(2);
@@ -845,8 +813,6 @@ int inflate(z_streamp strm, int flush)
}
break;
case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- state->last ? " (last)" : ""));
state->mode = TABLE;
break;
case 3:
@@ -864,8 +830,6 @@ int inflate(z_streamp strm, int flush)
break;
}
state->length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
- state->length));
INITBITS();
state->mode = COPY_;
if (flush == Z_TREES) goto inf_leave;
@@ -877,7 +841,7 @@ int inflate(z_streamp strm, int flush)
if (copy > have) copy = have;
if (copy > left) copy = left;
if (copy == 0) goto inf_leave;
- zmemcpy(put, next, copy);
+ memcpy(put, next, copy);
have -= copy;
next += copy;
left -= copy;
@@ -885,7 +849,6 @@ int inflate(z_streamp strm, int flush)
state->length -= copy;
break;
}
- Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE;
break;
case TABLE:
@@ -903,7 +866,6 @@ int inflate(z_streamp strm, int flush)
break;
}
#endif
- Tracev((stderr, "inflate: table sizes ok\n"));
state->have = 0;
state->mode = LENLENS;
case LENLENS:
@@ -924,7 +886,6 @@ int inflate(z_streamp strm, int flush)
state->mode = BAD;
break;
}
- Tracev((stderr, "inflate: code lengths ok\n"));
state->have = 0;
state->mode = CODELENS;
case CODELENS:
@@ -1007,7 +968,6 @@ int inflate(z_streamp strm, int flush)
state->mode = BAD;
break;
}
- Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN_;
if (flush == Z_TREES) goto inf_leave;
case LEN_:
@@ -1042,14 +1002,10 @@ int inflate(z_streamp strm, int flush)
state->back += here.bits;
state->length = (unsigned)here.val;
if ((int)(here.op) == 0) {
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
state->mode = LIT;
break;
}
if (here.op & 32) {
- Tracevv((stderr, "inflate: end of block\n"));
state->back = -1;
state->mode = TYPE;
break;
@@ -1068,7 +1024,6 @@ int inflate(z_streamp strm, int flush)
DROPBITS(state->extra);
state->back += state->extra;
}
- Tracevv((stderr, "inflate: length %u\n", state->length));
state->was = state->length;
state->mode = DIST;
case DIST:
@@ -1105,14 +1060,6 @@ int inflate(z_streamp strm, int flush)
DROPBITS(state->extra);
state->back += state->extra;
}
-#ifdef INFLATE_STRICT
- if (state->offset > state->dmax) {
- strm->msg = (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#endif
- Tracevv((stderr, "inflate: distance %u\n", state->offset));
state->mode = MATCH;
case MATCH:
if (left == 0) goto inf_leave;
@@ -1125,19 +1072,6 @@ int inflate(z_streamp strm, int flush)
state->mode = BAD;
break;
}
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- Trace((stderr, "inflate.c too far\n"));
- copy -= state->whave;
- if (copy > state->length) copy = state->length;
- if (copy > left) copy = left;
- left -= copy;
- state->length -= copy;
- do {
- *put++ = 0;
- } while (--copy);
- if (state->length == 0) state->mode = LEN;
- break;
-#endif
}
if (copy > state->wnext) {
copy -= state->wnext;
@@ -1171,11 +1105,11 @@ int inflate(z_streamp strm, int flush)
out -= left;
strm->total_out += out;
state->total += out;
- if (out)
+ if ((state->wrap & 4) && out)
strm->adler = state->check =
UPDATE(state->check, put - out, out);
out = left;
- if ((
+ if ((state->wrap & 4) && (
#ifdef GUNZIP
state->flags ? hold :
#endif
@@ -1185,7 +1119,6 @@ int inflate(z_streamp strm, int flush)
break;
}
INITBITS();
- Tracev((stderr, "inflate: check matches trailer\n"));
}
#ifdef GUNZIP
state->mode = LENGTH;
@@ -1198,7 +1131,6 @@ int inflate(z_streamp strm, int flush)
break;
}
INITBITS();
- Tracev((stderr, "inflate: length matches trailer\n"));
}
#endif
state->mode = DONE;
@@ -1234,7 +1166,7 @@ inf_leave:
strm->total_in += in;
strm->total_out += out;
state->total += out;
- if (state->wrap && out)
+ if ((state->wrap & 4) && out)
strm->adler = state->check =
UPDATE(state->check, strm->next_out - out, out);
strm->data_type = state->bits + (state->last ? 64 : 0) +
@@ -1248,13 +1180,16 @@ inf_leave:
int inflateEnd(z_streamp strm)
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
+ if (
+ strm == Z_NULL ||
+ strm->state == Z_NULL
+ )
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
- if (state->window != Z_NULL) ZFREE(strm, state->window);
- ZFREE(strm, strm->state);
+ if (state->window != Z_NULL)
+ free(state->window);
+ free(strm->state);
strm->state = Z_NULL;
- Tracev((stderr, "inflate: end\n"));
return Z_OK;
}
@@ -1263,36 +1198,47 @@ int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
struct inflate_state FAR *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (
+ strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
/* copy dictionary */
- if (state->whave && dictionary != Z_NULL) {
- zmemcpy(dictionary, state->window + state->wnext,
+ if (state->whave && dictionary != Z_NULL)
+ {
+ memcpy(dictionary, state->window + state->wnext,
state->whave - state->wnext);
- zmemcpy(dictionary + state->whave - state->wnext,
+ memcpy(dictionary + state->whave - state->wnext,
state->window, state->wnext);
}
+
if (dictLength != Z_NULL)
*dictLength = state->whave;
+
return Z_OK;
}
-int inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
+int inflateSetDictionary(z_streamp strm,
+ const Bytef *dictionary, uInt dictLength)
{
- struct inflate_state FAR *state;
- unsigned long dictid;
int ret;
+ struct inflate_state FAR *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
state = (struct inflate_state FAR *)strm->state;
- if (state->wrap != 0 && state->mode != DICT)
+ if ( state->wrap != 0 &&
+ state->mode != DICT)
return Z_STREAM_ERROR;
/* check for correct dictionary identifier */
- if (state->mode == DICT) {
- dictid = adler32(0L, Z_NULL, 0);
+ if (state->mode == DICT)
+ {
+ unsigned long dictid = adler32(0L, Z_NULL, 0);
dictid = adler32(dictid, dictionary, dictLength);
if (dictid != state->check)
return Z_DATA_ERROR;
@@ -1301,12 +1247,14 @@ int inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLengt
/* copy dictionary to window using updatewindow(), which will amend the
existing dictionary if appropriate */
ret = updatewindow(strm, dictionary + dictLength, dictLength);
- if (ret) {
+
+ if (ret)
+ {
state->mode = MEM;
return Z_MEM_ERROR;
}
+
state->havedict = 1;
- Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
}
@@ -1315,13 +1263,18 @@ int inflateGetHeader(z_streamp strm, gz_headerp head)
struct inflate_state FAR *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+
state = (struct inflate_state FAR *)strm->state;
- if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
+
+ if ((state->wrap & 2) == 0)
+ return Z_STREAM_ERROR;
/* save header structure */
state->head = head;
- head->done = 0;
+ head->done = 0;
return Z_OK;
}
@@ -1336,14 +1289,14 @@ int inflateGetHeader(z_streamp strm, gz_headerp head)
called again with more data and the *have state. *have is initialized to
zero for the first call.
*/
-static unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
+static unsigned syncsearch(unsigned FAR *have,
+ const unsigned char FAR *buf, unsigned len)
{
- unsigned got;
- unsigned next;
+ unsigned got = *have;
+ unsigned next = 0;
- got = *have;
- next = 0;
- while (next < len && got < 4) {
+ while (next < len && got < 4)
+ {
if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
got++;
else if (buf[next])
@@ -1364,37 +1317,48 @@ int inflateSync(z_streamp strm)
struct inflate_state FAR *state;
/* check parameters */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
- if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
+ if (strm->avail_in == 0 && state->bits < 8)
+ return Z_BUF_ERROR;
/* if first time, start search in bit buffer */
- if (state->mode != SYNC) {
- state->mode = SYNC;
+ if (state->mode != SYNC)
+ {
+ state->mode = SYNC;
state->hold <<= state->bits & 7;
- state->bits -= state->bits & 7;
- len = 0;
- while (state->bits >= 8) {
- buf[len++] = (unsigned char)(state->hold);
+ state->bits -= state->bits & 7;
+ len = 0;
+ while (state->bits >= 8)
+ {
+ buf[len++] = (unsigned char)(state->hold);
state->hold >>= 8;
- state->bits -= 8;
+ state->bits -= 8;
}
- state->have = 0;
+ state->have = 0;
syncsearch(&(state->have), buf, len);
}
/* search available input */
- len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
+ len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
strm->avail_in -= len;
- strm->next_in += len;
+ strm->next_in += len;
strm->total_in += len;
/* return no joy or set up to restart inflate() on a new block */
- if (state->have != 4) return Z_DATA_ERROR;
- in = strm->total_in; out = strm->total_out;
+ if (state->have != 4)
+ return Z_DATA_ERROR;
+ if (state->mode == HEAD)
+ state->wrap = 0; /* never processed header, so assume raw */
+
+ in = strm->total_in;
+ out = strm->total_out;
inflateReset(strm);
- strm->total_in = in; strm->total_out = out;
- state->mode = TYPE;
+ strm->total_in = in;
+ strm->total_out = out;
+ state->mode = TYPE;
return Z_OK;
}
@@ -1410,53 +1374,106 @@ int inflateSyncPoint(z_streamp strm)
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
return state->mode == STORED && state->bits == 0;
}
int inflateCopy(z_streamp dest, z_streamp source)
{
+ unsigned i;
+ unsigned wsize;
struct inflate_state FAR *state;
struct inflate_state FAR *copy;
unsigned char FAR *window;
- unsigned wsize;
/* check input */
- if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
- source->zalloc == Z_NULL || source->zfree == Z_NULL)
+ if ( dest == Z_NULL ||
+ source == Z_NULL ||
+ source->state == Z_NULL
+ )
return Z_STREAM_ERROR;
+
state = (struct inflate_state FAR *)source->state;
/* allocate space */
copy = (struct inflate_state FAR *)
- ZALLOC(source, 1, sizeof(struct inflate_state));
- if (copy == Z_NULL) return Z_MEM_ERROR;
- window = Z_NULL;
- if (state->window != Z_NULL) {
+ malloc(sizeof(*copy));
+ if (copy == Z_NULL)
+ return Z_MEM_ERROR;
+ window = Z_NULL;
+ copy->mode = HEAD;
+ copy->last = 0;
+ copy->wrap = 0;
+ copy->havedict = 0;
+ copy->flags = 0;
+ copy->check = 0;
+ copy->total = 0;
+ copy->head = Z_NULL;
+ copy->wbits = 0;
+ copy->wsize = 0;
+ copy->whave = 0;
+ copy->wnext = 0;
+ copy->window = Z_NULL;
+ copy->hold = 0;
+ copy->bits = 0;
+ copy->length = 0;
+ copy->offset = 0;
+ copy->extra = 0;
+ copy->lencode = Z_NULL;
+ copy->distcode = Z_NULL;
+ copy->lenbits = 0;
+ copy->distbits = 0;
+ copy->ncode = 0;
+ copy->nlen = 0;
+ copy->ndist = 0;
+ copy->have = 0;
+ copy->next = Z_NULL;
+ for (i = 0; i < 320; i++)
+ copy->lens[i] = 0;
+ for (i = 0; i < 288; i++)
+ copy->work[i] = 0;
+ for (i = 0; i < ENOUGH; i++)
+ {
+ copy->codes[i].op = 0;
+ copy->codes[i].bits = 0;
+ copy->codes[i].val = 0;
+ }
+ copy->sane = 0;
+ copy->back = 0;
+ copy->was = 0;
+ if (state->window != Z_NULL)
+ {
window = (unsigned char FAR *)
- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
- if (window == Z_NULL) {
- ZFREE(source, copy);
+ calloc(1U << state->wbits, sizeof(unsigned char));
+ if (window == Z_NULL)
+ {
+ free(copy);
return Z_MEM_ERROR;
}
}
/* copy state */
- zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
- zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
- if (state->lencode >= state->codes &&
- state->lencode <= state->codes + ENOUGH - 1) {
- copy->lencode = copy->codes + (state->lencode - state->codes);
+ memcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+ memcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
+
+ if ( state->lencode >= state->codes &&
+ state->lencode <= state->codes + ENOUGH - 1)
+ {
+ copy->lencode = copy->codes + (state->lencode - state->codes);
copy->distcode = copy->codes + (state->distcode - state->codes);
}
copy->next = copy->codes + (state->next - state->codes);
- if (window != Z_NULL) {
+
+ if (window != Z_NULL)
+ {
wsize = 1U << state->wbits;
- zmemcpy(window, state->window, wsize);
+ memcpy(window, state->window, wsize);
}
copy->window = window;
- dest->state = (struct internal_state FAR *)copy;
+ dest->state = (struct internal_state FAR *)copy;
return Z_OK;
}
@@ -1466,24 +1483,38 @@ int inflateUndermine(z_streamp strm, int subvert)
if (strm == Z_NULL || strm->state == Z_NULL)
return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- state->sane = !subvert;
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- return Z_OK;
-#else
+
+ state = (struct inflate_state FAR *)strm->state;
state->sane = 1;
+
return Z_DATA_ERROR;
-#endif
+}
+
+int inflateValidate(z_streamp strm, int check)
+{
+ struct inflate_state FAR *state;
+
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (check && state->wrap)
+ state->wrap |= 4;
+ else
+ state->wrap &= ~4;
+ return Z_OK;
}
long inflateMark(z_streamp strm)
{
struct inflate_state FAR *state = NULL;
- if (strm == Z_NULL || strm->state == Z_NULL)
- return -1L << 16;
+ if ( strm == Z_NULL ||
+ strm->state == Z_NULL)
+ return -(1L << 16);
+
state = (struct inflate_state FAR *)strm->state;
- return ((long)(state->back) << 16) +
- (state->mode == COPY ? state->length :
+ return (long)(((unsigned long)((long)state->back)) << 16) +
+ (state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0));
}
diff --git a/deps/libz/inflate.h b/deps/libz/inflate.h
index dbc173afb0..656455ead4 100644
--- a/deps/libz/inflate.h
+++ b/deps/libz/inflate.h
@@ -84,10 +84,10 @@ typedef enum {
struct inflate_state {
inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */
- int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
+ bit 2 true to validate check value */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */
- unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */
gz_headerp head; /* where to save gzip header information */
diff --git a/deps/libz/trees.c b/deps/libz/trees.c
index b2e9f9f15a..0d609ae15f 100644
--- a/deps/libz/trees.c
+++ b/deps/libz/trees.c
@@ -32,14 +32,8 @@
/* @(#) $Id$ */
-/* #define GEN_TREES_H */
-
#include "deflate.h"
-#ifdef DEBUG
-# include
-#endif
-
/* ===========================================================================
* Constants
*/
@@ -80,39 +74,7 @@ static const uch bl_order[BL_CODES]
#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
-#if defined(GEN_TREES_H) || !defined(STDC)
-/* non ANSI compilers may not accept trees.h */
-
-static ct_data static_ltree[L_CODES+2];
-/* The static literal tree. Since the bit lengths are imposed, there is no
- * need for the L_CODES extra codes used during heap construction. However
- * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
- * below).
- */
-
-static ct_data static_dtree[D_CODES];
-/* The static distance tree. (Actually a trivial tree since all codes use
- * 5 bits.)
- */
-
-uch _dist_code[DIST_CODE_LEN];
-/* Distance codes. The first 256 values correspond to the distances
- * 3 .. 258, the last 256 values correspond to the top 8 bits of
- * the 15 bit distances.
- */
-
-uch _length_code[MAX_MATCH-MIN_MATCH+1];
-/* length code for each normalized match length (0 == MIN_MATCH) */
-
-static int base_length[LENGTH_CODES];
-/* First normalized length for each code (0 = MIN_MATCH) */
-
-static int base_dist[D_CODES];
-/* First normalized distance for each code (0 = distance of 1) */
-
-#else
-# include "trees.h"
-#endif /* GEN_TREES_H */
+#include "trees.h"
struct static_tree_desc_s {
const ct_data *static_tree; /* static tree or NULL */
@@ -135,29 +97,12 @@ static static_tree_desc static_bl_desc =
* Local (static) routines in this file.
*/
-static void tr_static_init (void);
-static void init_block (deflate_state *s);
-static void pqdownheap (deflate_state *s, ct_data *tree, int k);
-static void gen_bitlen (deflate_state *s, tree_desc *desc);
-static void gen_codes (ct_data *tree, int max_code, ushf *bl_count);
-static void build_tree (deflate_state *s, tree_desc *desc);
-static void scan_tree (deflate_state *s, ct_data *tree, int max_code);
-static void send_tree (deflate_state *s, ct_data *tree, int max_code);
-static int build_bl_tree (deflate_state *s);
-static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
- int blcodes);
static void compress_block (deflate_state *s, const ct_data *ltree,
const ct_data *dtree);
static int detect_data_type (deflate_state *s);
static unsigned bi_reverse (unsigned value, int length);
static void bi_windup (deflate_state *s);
static void bi_flush (deflate_state *s);
-static void copy_block (deflate_state *s, charf *buf, unsigned len,
- int header);
-
-#ifdef GEN_TREES_H
-static void gen_trees_header (void);
-#endif
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
/* Send a code of the given tree. c and tree must not have side effects */
@@ -175,30 +120,6 @@ static void gen_trees_header (void);
* Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits.
*/
-#ifdef DEBUG
-static void send_bits (deflate_state *s, int value, int length);
-
-static void send_bits(deflate_state *s, int value, int length)
-{
- Tracevv((stderr," l %2d v %4x ", length, value));
- Assert(length > 0 && length <= 15, "invalid length");
- s->bits_sent += (ulg)length;
-
- /* If not enough room in bi_buf, use (valid) bits from bi_buf and
- * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
- * unused bits in value.
- */
- if (s->bi_valid > (int)Buf_size - length) {
- s->bi_buf |= (ush)value << s->bi_valid;
- put_short(s, s->bi_buf);
- s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
- s->bi_valid += length - Buf_size;
- } else {
- s->bi_buf |= (ush)value << s->bi_valid;
- s->bi_valid += length;
- }
-}
-#else /* !DEBUG */
#define send_bits(s, value, length) \
{ int len = length;\
@@ -213,184 +134,6 @@ static void send_bits(deflate_state *s, int value, int length)
s->bi_valid += len;\
}\
}
-#endif /* DEBUG */
-
-
-/* the arguments must not have side effects */
-
-/* ===========================================================================
- * Initialize the various 'constant' tables.
- */
-static void tr_static_init(void)
-{
-#if defined(GEN_TREES_H) || !defined(STDC)
- static int static_init_done = 0;
- int n; /* iterates over tree elements */
- int bits; /* bit counter */
- int length; /* length value */
- int codes; /* code value */
- int dist; /* distance index */
- ush bl_count[MAX_BITS+1];
- /* number of codes at each bit length for an optimal tree */
-
- if (static_init_done) return;
-
- /* For some embedded targets, global variables are not initialized: */
-#ifdef NO_INIT_GLOBAL_POINTERS
- static_l_desc.static_tree = static_ltree;
- static_l_desc.extra_bits = extra_lbits;
- static_d_desc.static_tree = static_dtree;
- static_d_desc.extra_bits = extra_dbits;
- static_bl_desc.extra_bits = extra_blbits;
-#endif
-
- /* Initialize the mapping length (0..255) -> length code (0..28) */
- length = 0;
- for (codes = 0; codes < LENGTH_CODES-1; codes++) {
- base_length[codes] = length;
- for (n = 0; n < (1< dist code (0..29) */
- dist = 0;
- for (codes = 0 ; codes < 16; codes++) {
- base_dist[codes] = dist;
- for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */
- for ( ; codes < D_CODES; codes++) {
- base_dist[codes] = dist << 7;
- for (n = 0; n < (1<<(extra_dbits[codes]-7)); n++) {
- _dist_code[256 + dist++] = (uch)codes;
- }
- }
- Assert (dist == 256, "tr_static_init: 256+dist != 512");
-
- /* Construct the codes of the static literal tree */
- for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
- n = 0;
- while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
- while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
- while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
- while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
- /* Codes 286 and 287 do not exist, but we must include them in the
- * tree construction to get a canonical Huffman tree (longest code
- * all ones)
- */
- gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
-
- /* The static distance tree is trivial: */
- for (n = 0; n < D_CODES; n++) {
- static_dtree[n].Len = 5;
- static_dtree[n].Code = bi_reverse((unsigned)n, 5);
- }
- static_init_done = 1;
-
-# ifdef GEN_TREES_H
- gen_trees_header();
-# endif
-#endif /* defined(GEN_TREES_H) || !defined(STDC) */
-}
-
-/* ===========================================================================
- * Genererate the file trees.h describing the static trees.
- */
-#ifdef GEN_TREES_H
-# ifndef DEBUG
-# include
-# endif
-
-# define SEPARATOR(i, last, width) \
- ((i) == (last)? "\n};\n\n" : \
- ((i) % (width) == (width)-1 ? ",\n" : ", "))
-
-void gen_trees_header(void)
-{
- FILE *header = fopen("trees.h", "w");
- int i;
-
- Assert (header != NULL, "Can't open trees.h");
- fprintf(header,
- "/* header created automatically with -DGEN_TREES_H */\n\n");
-
- fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
- for (i = 0; i < L_CODES+2; i++) {
- fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
- static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
- }
-
- fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
- for (i = 0; i < D_CODES; i++) {
- fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
- static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
- }
-
- fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
- for (i = 0; i < DIST_CODE_LEN; i++) {
- fprintf(header, "%2u%s", _dist_code[i],
- SEPARATOR(i, DIST_CODE_LEN-1, 20));
- }
-
- fprintf(header,
- "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
- for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
- fprintf(header, "%2u%s", _length_code[i],
- SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
- }
-
- fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
- for (i = 0; i < LENGTH_CODES; i++) {
- fprintf(header, "%1u%s", base_length[i],
- SEPARATOR(i, LENGTH_CODES-1, 20));
- }
-
- fprintf(header, "local const int base_dist[D_CODES] = {\n");
- for (i = 0; i < D_CODES; i++) {
- fprintf(header, "%5u%s", base_dist[i],
- SEPARATOR(i, D_CODES-1, 10));
- }
-
- fclose(header);
-}
-#endif /* GEN_TREES_H */
-
-/* ===========================================================================
- * Initialize the tree data structures for a new zlib stream.
- */
-void ZLIB_INTERNAL _tr_init(deflate_state *s)
-{
- tr_static_init();
-
- s->l_desc.dyn_tree = s->dyn_ltree;
- s->l_desc.stat_desc = &static_l_desc;
-
- s->d_desc.dyn_tree = s->dyn_dtree;
- s->d_desc.stat_desc = &static_d_desc;
-
- s->bl_desc.dyn_tree = s->bl_tree;
- s->bl_desc.stat_desc = &static_bl_desc;
-
- s->bi_buf = 0;
- s->bi_valid = 0;
-#ifdef DEBUG
- s->compressed_len = 0L;
- s->bits_sent = 0L;
-#endif
-
- /* Initialize the first block of the first file: */
- init_block(s);
-}
/* ===========================================================================
* Initialize a new block.
@@ -409,6 +152,30 @@ static void init_block(deflate_state *s)
s->last_lit = s->matches = 0;
}
+
+/* the arguments must not have side effects */
+
+/* ===========================================================================
+ * Initialize the tree data structures for a new zlib stream.
+ */
+void ZLIB_INTERNAL _tr_init(deflate_state *s)
+{
+ s->l_desc.dyn_tree = s->dyn_ltree;
+ s->l_desc.stat_desc = &static_l_desc;
+
+ s->d_desc.dyn_tree = s->dyn_dtree;
+ s->d_desc.stat_desc = &static_d_desc;
+
+ s->bl_desc.dyn_tree = s->bl_tree;
+ s->bl_desc.stat_desc = &static_bl_desc;
+
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+
+ /* Initialize the first block of the first file: */
+ init_block(s);
+}
+
#define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */
@@ -573,7 +340,6 @@ static void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
*/
Assert (codes + bl_count[MAX_BITS]-1 == (1<opt_len += 3*(max_blindex+1) + 5+5+4;
- Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
- s->opt_len, s->static_len));
return max_blindex;
}
@@ -811,21 +575,16 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes
Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
"too many codes");
- Tracev((stderr, "\nbl counts: "));
send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
send_bits(s, dcodes-1, 5);
send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
for (rank = 0; rank < blcodes; rank++) {
- Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
}
- Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
- Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
- Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
}
/* ===========================================================================
@@ -834,11 +593,11 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
{
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
-#ifdef DEBUG
- s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
- s->compressed_len += (stored_len + 4) << 3;
-#endif
- copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
+ bi_windup(s); /* align on byte boundary */
+ put_short(s, (ush)stored_len);
+ put_short(s, (ush)~stored_len);
+ memcpy(s->pending_buf + s->pending, buf, stored_len);
+ s->pending += stored_len;
}
/* ===========================================================================
@@ -857,9 +616,6 @@ void ZLIB_INTERNAL _tr_align(deflate_state *s)
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
- s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
-#endif
bi_flush(s);
}
@@ -881,12 +637,8 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
/* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc)));
- Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
- s->static_len));
build_tree(s, (tree_desc *)(&(s->d_desc)));
- Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
- s->static_len));
/* At this point, opt_len and static_len are the total bit lengths of
* the compressed block data, excluding the tree representations.
*/
@@ -900,10 +652,6 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3;
- Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
- opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
- s->last_lit));
-
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
} else {
@@ -933,18 +681,12 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);
-#ifdef DEBUG
- s->compressed_len += 3 + s->static_len;
-#endif
} else {
send_bits(s, (DYN_TREES<<1)+last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree);
-#ifdef DEBUG
- s->compressed_len += 3 + s->opt_len;
-#endif
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
/* The above check is made mod 2^32, for files larger than 512 MB
@@ -954,12 +696,7 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
if (last) {
bi_windup(s);
-#ifdef DEBUG
- s->compressed_len += 7; /* align on byte boundary */
-#endif
}
- Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
- s->compressed_len-7*last));
}
/* ===========================================================================
@@ -997,9 +734,6 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
(5L+extra_dbits[dcode]);
}
out_length >>= 3;
- Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
- s->last_lit, in_length, out_length,
- 100L - out_length*100L/in_length));
if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
}
#endif
@@ -1141,30 +875,4 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len,
}
s->bi_buf = 0;
s->bi_valid = 0;
-#ifdef DEBUG
- s->bits_sent = (s->bits_sent+7) & ~7;
-#endif
- }
-
- /* ===========================================================================
- * Copy a stored block, storing first the length and its
- * one's complement if requested.
- */
- static void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
- {
- bi_windup(s); /* align on byte boundary */
-
- if (header) {
- put_short(s, (ush)len);
- put_short(s, (ush)~len);
-#ifdef DEBUG
- s->bits_sent += 2*16;
-#endif
- }
-#ifdef DEBUG
- s->bits_sent += (ulg)len<<3;
-#endif
- while (len--) {
- put_byte(s, *buf++);
- }
}
diff --git a/deps/libz/uncompr.c b/deps/libz/uncompr.c
index ccf666422f..222098ee6a 100644
--- a/deps/libz/uncompr.c
+++ b/deps/libz/uncompr.c
@@ -21,36 +21,44 @@
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
-int uncompress (unsigned char *dest, uint32_t *destLen, const unsigned char *source, uint32_t sourceLen)
+int uncompress (
+ unsigned char *dest,
+ uint32_t *destLen,
+ const unsigned char *source,
+ uint32_t sourceLen)
{
- z_stream stream;
int err;
+ z_stream stream;
- stream.next_in = (Bytef *)source;
- stream.avail_in = (uInt)sourceLen;
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */
- if ((uint32_t)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+ if ((uint32_t)stream.avail_in != sourceLen)
+ return Z_BUF_ERROR;
- stream.next_out = dest;
+ stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
- if ((uint32_t)stream.avail_out != *destLen) return Z_BUF_ERROR;
+ if ((uint32_t)stream.avail_out != *destLen)
+ return Z_BUF_ERROR;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
+ stream.zalloc = Z_NULL;
+ stream.zfree = Z_NULL;
err = inflateInit(&stream);
- if (err != Z_OK) return err;
+ if (err != Z_OK)
+ return err;
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
{
inflateEnd(&stream);
- if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+ if ( err == Z_NEED_DICT ||
+ (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
- err = inflateEnd(&stream);
+ err = inflateEnd(&stream);
return err;
}
diff --git a/deps/libz/zutil.c b/deps/libz/zutil.c
index 79cc2e8d85..2e97acca80 100644
--- a/deps/libz/zutil.c
+++ b/deps/libz/zutil.c
@@ -30,36 +30,63 @@ const char * zlibVersion(void)
uLong zlibCompileFlags(void)
{
- uLong flags;
+ uLong flags = 0;
- flags = 0;
- switch ((int)(sizeof(uInt))) {
- case 2: break;
- case 4: flags += 1; break;
- case 8: flags += 2; break;
- default: flags += 3;
+ switch ((int)(sizeof(uInt)))
+ {
+ case 2:
+ break;
+ case 4:
+ flags += 1;
+ break;
+ case 8:
+ flags += 2;
+ break;
+ default:
+ flags += 3;
}
- switch ((int)(sizeof(uLong))) {
- case 2: break;
- case 4: flags += 1 << 2; break;
- case 8: flags += 2 << 2; break;
- default: flags += 3 << 2;
+
+ switch ((int)(sizeof(uLong)))
+ {
+ case 2:
+ break;
+ case 4:
+ flags += 1 << 2;
+ break;
+ case 8:
+ flags += 2 << 2;
+ break;
+ default:
+ flags += 3 << 2;
}
- switch ((int)(sizeof(voidpf))) {
- case 2: break;
- case 4: flags += 1 << 4; break;
- case 8: flags += 2 << 4; break;
- default: flags += 3 << 4;
+
+ switch ((int)(sizeof(voidpf)))
+ {
+ case 2:
+ break;
+ case 4:
+ flags += 1 << 4;
+ break;
+ case 8:
+ flags += 2 << 4;
+ break;
+ default:
+ flags += 3 << 4;
}
- switch ((int)(sizeof(z_off_t))) {
- case 2: break;
- case 4: flags += 1 << 6; break;
- case 8: flags += 2 << 6; break;
- default: flags += 3 << 6;
+
+ switch ((int)(sizeof(z_off_t)))
+ {
+ case 2:
+ break;
+ case 4:
+ flags += 1 << 6;
+ break;
+ case 8:
+ flags += 2 << 6;
+ break;
+ default:
+ flags += 3 << 6;
}
-#ifdef DEBUG
- flags += 1 << 8;
-#endif
#if defined(ASMV) || defined(ASMINF)
flags += 1 << 9;
#endif
@@ -111,20 +138,6 @@ uLong zlibCompileFlags(void)
return flags;
}
-#ifdef DEBUG
-
-# ifndef verbose
-# define verbose 0
-# endif
-int ZLIB_INTERNAL z_verbose = verbose;
-
-void ZLIB_INTERNAL z_error (char *m)
-{
- fprintf(stderr, "%s\n", m);
- exit(1);
-}
-#endif
-
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
@@ -151,5 +164,4 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
{
free(ptr);
- if (opaque) return; /* make compiler happy */
}
diff --git a/deps/mbedtls/aes.c b/deps/mbedtls/aes.c
index d36b231fb4..cff9c6a48b 100644
--- a/deps/mbedtls/aes.c
+++ b/deps/mbedtls/aes.c
@@ -43,15 +43,6 @@
#include "mbedtls/aesni.h"
#endif
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_AES_ALT)
#include "arc4_alt.h"
@@ -84,273 +75,6 @@
static int aes_padlock_ace = -1;
#endif
-#if defined(MBEDTLS_AES_ROM_TABLES)
-/*
- * Forward S-box
- */
-static const unsigned char FSb[256] =
-{
- 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
- 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
- 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
- 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
- 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
- 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
- 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
- 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
- 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
- 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
- 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
- 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
- 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
- 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
- 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
- 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
- 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
- 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
- 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
- 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
- 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
- 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
- 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
- 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
- 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
- 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
- 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
- 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
- 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
- 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
- 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
- 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
-};
-
-/*
- * Forward tables
- */
-#define FT \
-\
- V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \
- V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \
- V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \
- V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \
- V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \
- V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \
- V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \
- V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \
- V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \
- V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \
- V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \
- V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \
- V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \
- V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \
- V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \
- V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \
- V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \
- V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \
- V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \
- V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \
- V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \
- V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \
- V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \
- V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \
- V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \
- V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \
- V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \
- V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \
- V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \
- V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \
- V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \
- V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \
- V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \
- V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \
- V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \
- V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \
- V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \
- V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \
- V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \
- V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \
- V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \
- V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \
- V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \
- V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \
- V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \
- V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \
- V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \
- V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \
- V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \
- V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \
- V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \
- V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \
- V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \
- V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \
- V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \
- V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \
- V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \
- V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \
- V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \
- V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \
- V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \
- V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \
- V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \
- V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
-
-#define V(a,b,c,d) 0x##a##b##c##d
-static const uint32_t FT0[256] = { FT };
-#undef V
-
-#define V(a,b,c,d) 0x##b##c##d##a
-static const uint32_t FT1[256] = { FT };
-#undef V
-
-#define V(a,b,c,d) 0x##c##d##a##b
-static const uint32_t FT2[256] = { FT };
-#undef V
-
-#define V(a,b,c,d) 0x##d##a##b##c
-static const uint32_t FT3[256] = { FT };
-#undef V
-
-#undef FT
-
-/*
- * Reverse S-box
- */
-static const unsigned char RSb[256] =
-{
- 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
- 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
- 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
- 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
- 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
- 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
- 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
- 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
- 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
- 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
- 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
- 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
- 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
- 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
- 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
- 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
- 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
- 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
- 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
- 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
- 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
- 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
- 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
- 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
- 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
- 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
- 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
- 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
- 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
- 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
- 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
- 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
-};
-
-/*
- * Reverse tables
- */
-#define RT \
-\
- V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \
- V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \
- V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \
- V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \
- V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \
- V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \
- V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \
- V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \
- V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \
- V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \
- V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \
- V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \
- V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \
- V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \
- V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \
- V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \
- V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \
- V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \
- V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \
- V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \
- V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \
- V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \
- V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \
- V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \
- V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \
- V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \
- V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \
- V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \
- V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \
- V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \
- V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \
- V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \
- V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \
- V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \
- V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \
- V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \
- V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \
- V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \
- V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \
- V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \
- V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \
- V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \
- V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \
- V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \
- V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \
- V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \
- V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \
- V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \
- V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \
- V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \
- V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \
- V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \
- V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \
- V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \
- V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \
- V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \
- V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \
- V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \
- V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \
- V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \
- V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \
- V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \
- V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \
- V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0)
-
-#define V(a,b,c,d) 0x##a##b##c##d
-static const uint32_t RT0[256] = { RT };
-#undef V
-
-#define V(a,b,c,d) 0x##b##c##d##a
-static const uint32_t RT1[256] = { RT };
-#undef V
-
-#define V(a,b,c,d) 0x##c##d##a##b
-static const uint32_t RT2[256] = { RT };
-#undef V
-
-#define V(a,b,c,d) 0x##d##a##b##c
-static const uint32_t RT3[256] = { RT };
-#undef V
-
-#undef RT
-
-/*
- * Round constants
- */
-static const uint32_t RCON[10] =
-{
- 0x00000001, 0x00000002, 0x00000004, 0x00000008,
- 0x00000010, 0x00000020, 0x00000040, 0x00000080,
- 0x0000001B, 0x00000036
-};
-
-#else /* MBEDTLS_AES_ROM_TABLES */
-
/*
* Forward S-box & tables
*/
@@ -459,8 +183,6 @@ static void aes_gen_tables( void )
}
}
-#endif /* MBEDTLS_AES_ROM_TABLES */
-
void mbedtls_aes_init( mbedtls_aes_context *ctx )
{
memset( ctx, 0, sizeof( mbedtls_aes_context ) );
@@ -484,14 +206,12 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
unsigned int i;
uint32_t *RK;
-#if !defined(MBEDTLS_AES_ROM_TABLES)
if( aes_init_done == 0 )
{
aes_gen_tables();
aes_init_done = 1;
}
-#endif
switch( keybits )
{
@@ -762,13 +482,6 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
}
#endif /* !MBEDTLS_AES_ENCRYPT_ALT */
-void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] )
-{
- mbedtls_internal_aes_encrypt( ctx, input, output );
-}
-
/*
* AES-ECB block decryption
*/
@@ -828,13 +541,6 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
}
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
-void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] )
-{
- mbedtls_internal_aes_decrypt( ctx, input, output );
-}
-
/*
* AES-ECB block encryption/decryption
*/
@@ -1050,456 +756,4 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
#endif /* !MBEDTLS_AES_ALT */
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * AES test vectors from:
- *
- * http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
- */
-static const unsigned char aes_test_ecb_dec[3][16] =
-{
- { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
- 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
- { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
- 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
- { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
- 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
-};
-
-static const unsigned char aes_test_ecb_enc[3][16] =
-{
- { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
- 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
- { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
- 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
- { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
- 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
-};
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
-static const unsigned char aes_test_cbc_dec[3][16] =
-{
- { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
- 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 },
- { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75,
- 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B },
- { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75,
- 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 }
-};
-
-static const unsigned char aes_test_cbc_enc[3][16] =
-{
- { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84,
- 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D },
- { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB,
- 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 },
- { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
- 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
-};
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
-#if defined(MBEDTLS_CIPHER_MODE_CFB)
-/*
- * AES-CFB128 test vectors from:
- *
- * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
- */
-static const unsigned char aes_test_cfb128_key[3][32] =
-{
- { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
- 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
- { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
- 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
- 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
- { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
- 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
- 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
- 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
-};
-
-static const unsigned char aes_test_cfb128_iv[16] =
-{
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
-};
-
-static const unsigned char aes_test_cfb128_pt[64] =
-{
- 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
- 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
- 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
- 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
- 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
- 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
- 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
- 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
-};
-
-static const unsigned char aes_test_cfb128_ct[3][64] =
-{
- { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
- 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
- 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F,
- 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B,
- 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40,
- 0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF,
- 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E,
- 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 },
- { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
- 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
- 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21,
- 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A,
- 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1,
- 0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9,
- 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0,
- 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF },
- { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
- 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
- 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8,
- 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B,
- 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92,
- 0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9,
- 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
- 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
-};
-#endif /* MBEDTLS_CIPHER_MODE_CFB */
-
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
-/*
- * AES-CTR test vectors from:
- *
- * http://www.faqs.org/rfcs/rfc3686.html
- */
-
-static const unsigned char aes_test_ctr_key[3][16] =
-{
- { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
- 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
- { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
- 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
- { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
- 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
-};
-
-static const unsigned char aes_test_ctr_nonce_counter[3][16] =
-{
- { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
- { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
- 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
- { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
- 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
-};
-
-static const unsigned char aes_test_ctr_pt[3][48] =
-{
- { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
- 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
-
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
-
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
- 0x20, 0x21, 0x22, 0x23 }
-};
-
-static const unsigned char aes_test_ctr_ct[3][48] =
-{
- { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79,
- 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 },
- { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9,
- 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88,
- 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8,
- 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 },
- { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
- 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
- 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
- 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
- 0x25, 0xB2, 0x07, 0x2F }
-};
-
-static const int aes_test_ctr_len[3] =
- { 16, 32, 36 };
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
-/*
- * Checkup routine
- */
-int mbedtls_aes_self_test( int verbose )
-{
- int ret = 0, i, j, u, v;
- unsigned char key[32];
- unsigned char buf[64];
-#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB)
- unsigned char iv[16];
-#endif
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- unsigned char prv[16];
-#endif
-#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB)
- size_t offset;
-#endif
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- int len;
- unsigned char nonce_counter[16];
- unsigned char stream_block[16];
-#endif
- mbedtls_aes_context ctx;
-
- memset( key, 0, 32 );
- mbedtls_aes_init( &ctx );
-
- /*
- * ECB mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " AES-ECB-%3d (%s): ", 128 + u * 64,
- ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
-
- memset( buf, 0, 16 );
-
- if( v == MBEDTLS_AES_DECRYPT )
- {
- mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
-
- for( j = 0; j < 10000; j++ )
- mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
-
- if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
- else
- {
- mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
-
- for( j = 0; j < 10000; j++ )
- mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
-
- if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- /*
- * CBC mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " AES-CBC-%3d (%s): ", 128 + u * 64,
- ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
-
- memset( iv , 0, 16 );
- memset( prv, 0, 16 );
- memset( buf, 0, 16 );
-
- if( v == MBEDTLS_AES_DECRYPT )
- {
- mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
-
- for( j = 0; j < 10000; j++ )
- mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
-
- if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
- else
- {
- mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
-
- for( j = 0; j < 10000; j++ )
- {
- unsigned char tmp[16];
-
- mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
-
- memcpy( tmp, prv, 16 );
- memcpy( prv, buf, 16 );
- memcpy( buf, tmp, 16 );
- }
-
- if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
-#if defined(MBEDTLS_CIPHER_MODE_CFB)
- /*
- * CFB128 mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " AES-CFB128-%3d (%s): ", 128 + u * 64,
- ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( iv, aes_test_cfb128_iv, 16 );
- memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 );
-
- offset = 0;
- mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
-
- if( v == MBEDTLS_AES_DECRYPT )
- {
- memcpy( buf, aes_test_cfb128_ct[u], 64 );
- mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
-
- if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
- else
- {
- memcpy( buf, aes_test_cfb128_pt, 64 );
- mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
-
- if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-#endif /* MBEDTLS_CIPHER_MODE_CFB */
-
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- /*
- * CTR mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " AES-CTR-128 (%s): ",
- ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 );
- memcpy( key, aes_test_ctr_key[u], 16 );
-
- offset = 0;
- mbedtls_aes_setkey_enc( &ctx, key, 128 );
-
- if( v == MBEDTLS_AES_DECRYPT )
- {
- len = aes_test_ctr_len[u];
- memcpy( buf, aes_test_ctr_ct[u], len );
-
- mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
- buf, buf );
-
- if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
- else
- {
- len = aes_test_ctr_len[u];
- memcpy( buf, aes_test_ctr_pt[u], len );
-
- mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
- buf, buf );
-
- if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
- ret = 0;
-
-exit:
- mbedtls_aes_free( &ctx );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_AES_C */
diff --git a/deps/mbedtls/arc4.c b/deps/mbedtls/arc4.c
index 26954c6f35..b909552c78 100644
--- a/deps/mbedtls/arc4.c
+++ b/deps/mbedtls/arc4.c
@@ -36,15 +36,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_ARC4_ALT)
#include "arc4_alt.h"
@@ -126,77 +117,4 @@ int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned
#endif /* !MBEDTLS_ARC4_ALT */
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * ARC4 tests vectors as posted by Eric Rescorla in sep. 1994:
- *
- * http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0
- */
-static const unsigned char arc4_test_key[3][8] =
-{
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-};
-
-static const unsigned char arc4_test_pt[3][8] =
-{
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-};
-
-static const unsigned char arc4_test_ct[3][8] =
-{
- { 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 },
- { 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 },
- { 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_arc4_self_test( int verbose )
-{
- int i, ret = 0;
- unsigned char ibuf[8];
- unsigned char obuf[8];
- mbedtls_arc4_context ctx;
-
- mbedtls_arc4_init( &ctx );
-
- for( i = 0; i < 3; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " ARC4 test #%d: ", i + 1 );
-
- memcpy( ibuf, arc4_test_pt[i], 8 );
-
- mbedtls_arc4_setup( &ctx, arc4_test_key[i], 8 );
- mbedtls_arc4_crypt( &ctx, 8, ibuf, obuf );
-
- if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_arc4_free( &ctx );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_ARC4_C */
diff --git a/deps/mbedtls/asn1parse.c b/deps/mbedtls/asn1parse.c
index 0e5b28eac0..1a519f5b3e 100644
--- a/deps/mbedtls/asn1parse.c
+++ b/deps/mbedtls/asn1parse.c
@@ -35,13 +35,7 @@
#include "mbedtls/bignum.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#include "arc4_alt.h"
@@ -266,7 +260,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
/* Allocate and assign next pointer */
if( *p < end )
{
- cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
+ cur->next = (mbedtls_asn1_sequence*)calloc( 1,
sizeof( mbedtls_asn1_sequence ) );
if( cur->next == NULL )
@@ -352,8 +346,8 @@ void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur )
if( cur == NULL )
return;
- mbedtls_free( cur->oid.p );
- mbedtls_free( cur->val.p );
+ free( cur->oid.p );
+ free( cur->val.p );
mbedtls_zeroize( cur, sizeof( mbedtls_asn1_named_data ) );
}
@@ -366,7 +360,7 @@ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
{
*head = cur->next;
mbedtls_asn1_free_named_data( cur );
- mbedtls_free( cur );
+ free( cur );
}
}
diff --git a/deps/mbedtls/asn1write.c b/deps/mbedtls/asn1write.c
index effb78a6db..b48d87085f 100644
--- a/deps/mbedtls/asn1write.c
+++ b/deps/mbedtls/asn1write.c
@@ -30,14 +30,7 @@
#include "mbedtls/asn1write.h"
#include
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
{
@@ -334,27 +327,27 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
{
/* Add new entry if not present yet based on OID */
- cur = (mbedtls_asn1_named_data*)mbedtls_calloc( 1,
+ cur = (mbedtls_asn1_named_data*)calloc( 1,
sizeof(mbedtls_asn1_named_data) );
if( cur == NULL )
return( NULL );
cur->oid.len = oid_len;
- cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)mbedtls_calloc( 1, oid_len );
+ cur->oid.p = (unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)(unsigned char*)calloc( 1, oid_len );
if( cur->oid.p == NULL )
{
- mbedtls_free( cur );
+ free( cur );
return( NULL );
}
memcpy( cur->oid.p, oid, oid_len );
cur->val.len = val_len;
- cur->val.p = (unsigned char*)mbedtls_calloc( 1, val_len );
+ cur->val.p = (unsigned char*)calloc( 1, val_len );
if( cur->val.p == NULL )
{
- mbedtls_free( cur->oid.p );
- mbedtls_free( cur );
+ free( cur->oid.p );
+ free( cur );
return( NULL );
}
@@ -368,11 +361,11 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
* Preserve old data until the allocation succeeded, to leave list in
* a consistent state in case allocation fails.
*/
- void *p = mbedtls_calloc( 1, val_len );
+ void *p = calloc( 1, val_len );
if( p == NULL )
return( NULL );
- mbedtls_free( cur->val.p );
+ free( cur->val.p );
cur->val.p = (unsigned char*)p;
cur->val.len = val_len;
}
diff --git a/deps/mbedtls/base64.c b/deps/mbedtls/base64.c
index f06b57b31f..af1ea2395b 100644
--- a/deps/mbedtls/base64.c
+++ b/deps/mbedtls/base64.c
@@ -31,16 +31,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#include
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
static const unsigned char base64_enc_map[64] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
@@ -227,67 +217,4 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
return( 0 );
}
-#if defined(MBEDTLS_SELF_TEST)
-
-static const unsigned char base64_test_dec[64] =
-{
- 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
- 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
- 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
- 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
- 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
- 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
- 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
- 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
-};
-
-static const unsigned char base64_test_enc[] =
- "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
- "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
-
-/*
- * Checkup routine
- */
-int mbedtls_base64_self_test( int verbose )
-{
- size_t len;
- const unsigned char *src;
- unsigned char buffer[128];
-
- if( verbose != 0 )
- mbedtls_printf( " Base64 encoding test: " );
-
- src = base64_test_dec;
-
- if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
- memcmp( base64_test_enc, buffer, 88 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n Base64 decoding test: " );
-
- src = base64_test_enc;
-
- if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
- memcmp( base64_test_dec, buffer, 64 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_BASE64_C */
diff --git a/deps/mbedtls/bignum.c b/deps/mbedtls/bignum.c
index d3a150c3c1..d887d2928a 100644
--- a/deps/mbedtls/bignum.c
+++ b/deps/mbedtls/bignum.c
@@ -48,15 +48,8 @@
#include
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
/* Implementation that should never be optimized out by the compiler */
static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n ) {
@@ -100,7 +93,7 @@ void mbedtls_mpi_free( mbedtls_mpi *X )
if( X->p != NULL )
{
mbedtls_mpi_zeroize( X->p, X->n );
- mbedtls_free( X->p );
+ free( X->p );
}
X->s = 1;
@@ -120,14 +113,14 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
if( X->n < nblimbs )
{
- if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL )
+ if( ( p = (mbedtls_mpi_uint*)calloc( nblimbs, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
if( X->p != NULL )
{
memcpy( p, X->p, X->n * ciL );
mbedtls_mpi_zeroize( X->p, X->n );
- mbedtls_free( X->p );
+ free( X->p );
}
X->n = nblimbs;
@@ -158,14 +151,14 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
if( i < nblimbs )
i = nblimbs;
- if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL )
+ if( ( p = (mbedtls_mpi_uint*)calloc( i, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
if( X->p != NULL )
{
memcpy( p, X->p, i * ciL );
mbedtls_mpi_zeroize( X->p, X->n );
- mbedtls_free( X->p );
+ free( X->p );
}
X->n = i;
@@ -658,7 +651,7 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE
return( MBEDTLS_ERR_MPI_FILE_IO_ERROR );
}
else
- mbedtls_printf( "%s%s", p, s );
+ printf( "%s%s", p, s );
cleanup:
@@ -2270,178 +2263,4 @@ cleanup:
#endif /* MBEDTLS_GENPRIME */
-#if defined(MBEDTLS_SELF_TEST)
-
-#define GCD_PAIR_COUNT 3
-
-static const int gcd_pairs[GCD_PAIR_COUNT][3] =
-{
- { 693, 609, 21 },
- { 1764, 868, 28 },
- { 768454923, 542167814, 1 }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_mpi_self_test( int verbose )
-{
- int ret, i;
- mbedtls_mpi A, E, N, X, Y, U, V;
-
- mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &X );
- mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &U ); mbedtls_mpi_init( &V );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &A, 16,
- "EFE021C2645FD1DC586E69184AF4A31E" \
- "D5F53E93B5F123FA41680867BA110131" \
- "944FE7952E2517337780CB0DB80E61AA" \
- "E7C8DDC6C5C6AADEB34EB38A2F40D5E6" ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &E, 16,
- "B2E7EFD37075B9F03FF989C7C5051C20" \
- "34D2A323810251127E7BF8625A4F49A5" \
- "F3E27F4DA8BD59C47D6DAABA4C8127BD" \
- "5B5C25763222FEFCCFC38B832366C29E" ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &N, 16,
- "0066A198186C18C10B2F5ED9B522752A" \
- "9830B69916E535C8F047518A889A43A5" \
- "94B6BED27A168D31D4A52F88925AA8F5" ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &X, &A, &N ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
- "602AB7ECA597A3D6B56FF9829A5E8B85" \
- "9E857EA95A03512E2BAE7391688D264A" \
- "A5663B0341DB9CCFD2C4C5F421FEC814" \
- "8001B72E848A38CAE1C65F78E56ABDEF" \
- "E12D3C039B8A02D6BE593F0BBBDA56F1" \
- "ECF677152EF804370C1A305CAF3B5BF1" \
- "30879B56C61DE584A0F53A2447A51E" ) );
-
- if( verbose != 0 )
- mbedtls_printf( " MPI test #1 (mul_mpi): " );
-
- if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto cleanup;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &X, &Y, &A, &N ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
- "256567336059E52CAE22925474705F39A94" ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &V, 16,
- "6613F26162223DF488E9CD48CC132C7A" \
- "0AC93C701B001B092E4E5B9F73BCD27B" \
- "9EE50D0657C77F374E903CDFA4C642" ) );
-
- if( verbose != 0 )
- mbedtls_printf( " MPI test #2 (div_mpi): " );
-
- if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ||
- mbedtls_mpi_cmp_mpi( &Y, &V ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto cleanup;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
- "36E139AEA55215609D2816998ED020BB" \
- "BD96C37890F65171D948E9BC7CBAA4D9" \
- "325D24D6A3C12710F10A09FA08AB87" ) );
-
- if( verbose != 0 )
- mbedtls_printf( " MPI test #3 (exp_mod): " );
-
- if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto cleanup;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &X, &A, &N ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16,
- "003A0AAEDD7E784FC07D8F9EC6E3BFD5" \
- "C3DBA76456363A10869622EAC2DD84EC" \
- "C5B8A74DAC4D09E03B5E0BE779F2DF61" ) );
-
- if( verbose != 0 )
- mbedtls_printf( " MPI test #4 (inv_mod): " );
-
- if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto cleanup;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " MPI test #5 (simple gcd): " );
-
- for( i = 0; i < GCD_PAIR_COUNT; i++ )
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &X, gcd_pairs[i][0] ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Y, gcd_pairs[i][1] ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &A, &X, &Y ) );
-
- if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed at %d\n", i );
-
- ret = 1;
- goto cleanup;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-cleanup:
-
- if( ret != 0 && verbose != 0 )
- mbedtls_printf( "Unexpected error, return code = %08X\n", ret );
-
- mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X );
- mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &U ); mbedtls_mpi_free( &V );
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_BIGNUM_C */
diff --git a/deps/mbedtls/camellia.c b/deps/mbedtls/camellia.c
index f8debc0744..de40f614d0 100644
--- a/deps/mbedtls/camellia.c
+++ b/deps/mbedtls/camellia.c
@@ -37,15 +37,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_CAMELLIA_ALT)
#include "arc4_alt.h"
@@ -688,382 +679,4 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
#endif /* MBEDTLS_CIPHER_MODE_CTR */
#endif /* !MBEDTLS_CAMELLIA_ALT */
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * Camellia test vectors from:
- *
- * http://info.isl.ntt.co.jp/crypt/eng/camellia/technology.html:
- * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/intermediate.txt
- * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt
- * (For each bitlength: Key 0, Nr 39)
- */
-#define CAMELLIA_TESTS_ECB 2
-
-static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] =
-{
- {
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
- },
- {
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
- },
- {
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
- 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
- },
-};
-
-static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] =
-{
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
- { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-};
-
-static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] =
-{
- {
- { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
- 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 },
- { 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE,
- 0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 }
- },
- {
- { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
- 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 },
- { 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9,
- 0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 }
- },
- {
- { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
- 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 },
- { 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C,
- 0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 }
- }
-};
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
-#define CAMELLIA_TESTS_CBC 3
-
-static const unsigned char camellia_test_cbc_key[3][32] =
-{
- { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
- 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
- ,
- { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
- 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
- 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }
- ,
- { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
- 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
- 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
- 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
-};
-
-static const unsigned char camellia_test_cbc_iv[16] =
-
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
-;
-
-static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] =
-{
- { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
- 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A },
- { 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
- 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 },
- { 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
- 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF }
-
-};
-
-static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] =
-{
- {
- { 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
- 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB },
- { 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78,
- 0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 },
- { 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B,
- 0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 }
- },
- {
- { 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
- 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 },
- { 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42,
- 0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 },
- { 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8,
- 0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 }
- },
- {
- { 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
- 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA },
- { 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40,
- 0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 },
- { 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA,
- 0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 }
- }
-};
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
-/*
- * Camellia-CTR test vectors from:
- *
- * http://www.faqs.org/rfcs/rfc5528.html
- */
-
-static const unsigned char camellia_test_ctr_key[3][16] =
-{
- { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
- 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
- { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
- 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
- { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
- 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
-};
-
-static const unsigned char camellia_test_ctr_nonce_counter[3][16] =
-{
- { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
- { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
- 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
- { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
- 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
-};
-
-static const unsigned char camellia_test_ctr_pt[3][48] =
-{
- { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
- 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
-
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
-
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
- 0x20, 0x21, 0x22, 0x23 }
-};
-
-static const unsigned char camellia_test_ctr_ct[3][48] =
-{
- { 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A,
- 0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F },
- { 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4,
- 0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44,
- 0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7,
- 0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 },
- { 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88,
- 0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73,
- 0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1,
- 0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD,
- 0xDF, 0x50, 0x86, 0x96 }
-};
-
-static const int camellia_test_ctr_len[3] =
- { 16, 32, 36 };
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
-/*
- * Checkup routine
- */
-int mbedtls_camellia_self_test( int verbose )
-{
- int i, j, u, v;
- unsigned char key[32];
- unsigned char buf[64];
- unsigned char src[16];
- unsigned char dst[16];
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- unsigned char iv[16];
-#endif
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- size_t offset, len;
- unsigned char nonce_counter[16];
- unsigned char stream_block[16];
-#endif
-
- mbedtls_camellia_context ctx;
-
- memset( key, 0, 32 );
-
- for( j = 0; j < 6; j++ ) {
- u = j >> 1;
- v = j & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
- (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
-
- for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
- memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u );
-
- if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
- mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
- memcpy( src, camellia_test_ecb_cipher[u][i], 16 );
- memcpy( dst, camellia_test_ecb_plain[i], 16 );
- } else { /* MBEDTLS_CAMELLIA_ENCRYPT */
- mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
- memcpy( src, camellia_test_ecb_plain[i], 16 );
- memcpy( dst, camellia_test_ecb_cipher[u][i], 16 );
- }
-
- mbedtls_camellia_crypt_ecb( &ctx, v, src, buf );
-
- if( memcmp( buf, dst, 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- /*
- * CBC mode
- */
- for( j = 0; j < 6; j++ )
- {
- u = j >> 1;
- v = j & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
- ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( src, camellia_test_cbc_iv, 16 );
- memcpy( dst, camellia_test_cbc_iv, 16 );
- memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u );
-
- if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
- mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 );
- } else {
- mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 );
- }
-
- for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) {
-
- if( v == MBEDTLS_CAMELLIA_DECRYPT ) {
- memcpy( iv , src, 16 );
- memcpy( src, camellia_test_cbc_cipher[u][i], 16 );
- memcpy( dst, camellia_test_cbc_plain[i], 16 );
- } else { /* MBEDTLS_CAMELLIA_ENCRYPT */
- memcpy( iv , dst, 16 );
- memcpy( src, camellia_test_cbc_plain[i], 16 );
- memcpy( dst, camellia_test_cbc_cipher[u][i], 16 );
- }
-
- mbedtls_camellia_crypt_cbc( &ctx, v, 16, iv, src, buf );
-
- if( memcmp( buf, dst, 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- /*
- * CTR mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " CAMELLIA-CTR-128 (%s): ",
- ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 );
- memcpy( key, camellia_test_ctr_key[u], 16 );
-
- offset = 0;
- mbedtls_camellia_setkey_enc( &ctx, key, 128 );
-
- if( v == MBEDTLS_CAMELLIA_DECRYPT )
- {
- len = camellia_test_ctr_len[u];
- memcpy( buf, camellia_test_ctr_ct[u], len );
-
- mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
- buf, buf );
-
- if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
- else
- {
- len = camellia_test_ctr_len[u];
- memcpy( buf, camellia_test_ctr_pt[u], len );
-
- mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
- buf, buf );
-
- if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_CAMELLIA_C */
diff --git a/deps/mbedtls/ccm.c b/deps/mbedtls/ccm.c
index a899ceecc7..3c0c912095 100644
--- a/deps/mbedtls/ccm.c
+++ b/deps/mbedtls/ccm.c
@@ -40,15 +40,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
-
#include "arc4_alt.h"
#define CCM_ENCRYPT 0
@@ -345,117 +336,4 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
return( 0 );
}
-
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
-/*
- * Examples 1 to 3 from SP800-38C Appendix C
- */
-
-#define NB_TESTS 3
-
-/*
- * The data is the same for all tests, only the used length changes
- */
-static const unsigned char ccm_key[] = {
- 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
-};
-
-static const unsigned char iv[] = {
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b
-};
-
-static const unsigned char ad[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13
-};
-
-static const unsigned char msg[] = {
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
-};
-
-static const size_t iv_len [NB_TESTS] = { 7, 8, 12 };
-static const size_t add_len[NB_TESTS] = { 8, 16, 20 };
-static const size_t msg_len[NB_TESTS] = { 4, 16, 24 };
-static const size_t tag_len[NB_TESTS] = { 4, 6, 8 };
-
-static const unsigned char res[NB_TESTS][32] = {
- { 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d },
- { 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62,
- 0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d,
- 0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd },
- { 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a,
- 0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b,
- 0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5,
- 0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 }
-};
-
-int mbedtls_ccm_self_test( int verbose )
-{
- mbedtls_ccm_context ctx;
- unsigned char out[32];
- size_t i;
- int ret;
-
- mbedtls_ccm_init( &ctx );
-
- if( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, ccm_key, 8 * sizeof ccm_key ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( " CCM: setup failed" );
-
- return( 1 );
- }
-
- for( i = 0; i < NB_TESTS; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " CCM-AES #%u: ", (unsigned int) i + 1 );
-
- ret = mbedtls_ccm_encrypt_and_tag( &ctx, msg_len[i],
- iv, iv_len[i], ad, add_len[i],
- msg, out,
- out + msg_len[i], tag_len[i] );
-
- if( ret != 0 ||
- memcmp( out, res[i], msg_len[i] + tag_len[i] ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- ret = mbedtls_ccm_auth_decrypt( &ctx, msg_len[i],
- iv, iv_len[i], ad, add_len[i],
- res[i], out,
- res[i] + msg_len[i], tag_len[i] );
-
- if( ret != 0 ||
- memcmp( out, msg, msg_len[i] ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- mbedtls_ccm_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
-
#endif /* MBEDTLS_CCM_C */
diff --git a/deps/mbedtls/cipher.c b/deps/mbedtls/cipher.c
index b5503a0279..a075b51d5d 100644
--- a/deps/mbedtls/cipher.c
+++ b/deps/mbedtls/cipher.c
@@ -45,17 +45,6 @@
#include "mbedtls/ccm.h"
#endif
-#if defined(MBEDTLS_CMAC_C)
-#include "mbedtls/cmac.h"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER)
#define MBEDTLS_CIPHER_MODE_STREAM
#endif
@@ -135,14 +124,6 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx )
if( ctx == NULL )
return;
-#if defined(MBEDTLS_CMAC_C)
- if( ctx->cmac_ctx )
- {
- mbedtls_zeroize( ctx->cmac_ctx, sizeof( mbedtls_cmac_context_t ) );
- mbedtls_free( ctx->cmac_ctx );
- }
-#endif
-
if( ctx->cipher_ctx )
ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );
@@ -846,17 +827,20 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
{
*olen = ilen;
- return( mbedtls_gcm_crypt_and_tag( ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, ilen,
- iv, iv_len, ad, ad_len, input, output,
- tag_len, tag ) );
+ return( mbedtls_gcm_crypt_and_tag(
+ (mbedtls_gcm_context*)ctx->cipher_ctx,
+ MBEDTLS_GCM_ENCRYPT, ilen,
+ iv, iv_len, ad, ad_len, input, output,
+ tag_len, tag ) );
}
#endif /* MBEDTLS_GCM_C */
#if defined(MBEDTLS_CCM_C)
if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode )
{
*olen = ilen;
- return( mbedtls_ccm_encrypt_and_tag( ctx->cipher_ctx, ilen,
- iv, iv_len, ad, ad_len, input, output,
+ return( mbedtls_ccm_encrypt_and_tag(
+ (mbedtls_ccm_context*)ctx->cipher_ctx, ilen,
+ iv, iv_len, ad, ad_len, input, output,
tag, tag_len ) );
}
#endif /* MBEDTLS_CCM_C */
@@ -880,9 +864,10 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
int ret;
*olen = ilen;
- ret = mbedtls_gcm_auth_decrypt( ctx->cipher_ctx, ilen,
- iv, iv_len, ad, ad_len,
- tag, tag_len, input, output );
+ ret = mbedtls_gcm_auth_decrypt(
+ (mbedtls_gcm_context*)ctx->cipher_ctx, ilen,
+ iv, iv_len, ad, ad_len,
+ tag, tag_len, input, output );
if( ret == MBEDTLS_ERR_GCM_AUTH_FAILED )
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
@@ -896,7 +881,8 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
int ret;
*olen = ilen;
- ret = mbedtls_ccm_auth_decrypt( ctx->cipher_ctx, ilen,
+ ret = mbedtls_ccm_auth_decrypt(
+ (mbedtls_ccm_context*)ctx->cipher_ctx, ilen,
iv, iv_len, ad, ad_len,
input, output, tag, tag_len );
diff --git a/deps/mbedtls/cipher_wrap.c b/deps/mbedtls/cipher_wrap.c
index dabc7a25d4..2e9a5fb6d2 100644
--- a/deps/mbedtls/cipher_wrap.c
+++ b/deps/mbedtls/cipher_wrap.c
@@ -61,23 +61,14 @@
#include "mbedtls/ccm.h"
#endif
-#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
-#include
-#endif
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#if defined(MBEDTLS_GCM_C)
/* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_gcm_context ) );
if( ctx != NULL )
mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
@@ -88,7 +79,7 @@ static void *gcm_ctx_alloc( void )
static void gcm_ctx_free( void *ctx )
{
mbedtls_gcm_free((mbedtls_gcm_context*)ctx);
- mbedtls_free(ctx);
+ free(ctx);
}
#endif /* MBEDTLS_GCM_C */
@@ -96,7 +87,7 @@ static void gcm_ctx_free( void *ctx )
/* shared by all CCM ciphers */
static void *ccm_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_ccm_context ) );
if( ctx != NULL )
mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
@@ -107,7 +98,7 @@ static void *ccm_ctx_alloc( void )
static void ccm_ctx_free( void *ctx )
{
mbedtls_ccm_free((mbedtls_ccm_context*)ctx);
- mbedtls_free( ctx );
+ free( ctx );
}
#endif /* MBEDTLS_CCM_C */
@@ -162,7 +153,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * aes_ctx_alloc( void )
{
- mbedtls_aes_context *aes = (mbedtls_aes_context*)mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
+ mbedtls_aes_context *aes = (mbedtls_aes_context*)calloc( 1, sizeof( mbedtls_aes_context ) );
if( aes == NULL )
return( NULL );
@@ -175,7 +166,7 @@ static void * aes_ctx_alloc( void )
static void aes_ctx_free( void *ctx )
{
mbedtls_aes_free( (mbedtls_aes_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static const mbedtls_cipher_base_t aes_info = {
@@ -519,7 +510,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * camellia_ctx_alloc( void )
{
mbedtls_camellia_context *ctx = (mbedtls_camellia_context*)
- mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
+ calloc( 1, sizeof( mbedtls_camellia_context ) );
if( ctx == NULL )
return( NULL );
@@ -532,7 +523,7 @@ static void * camellia_ctx_alloc( void )
static void camellia_ctx_free( void *ctx )
{
mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static const mbedtls_cipher_base_t camellia_info = {
@@ -907,7 +898,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
static void * des_ctx_alloc( void )
{
mbedtls_des_context *des = (mbedtls_des_context*)
- mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
+ calloc( 1, sizeof( mbedtls_des_context ) );
if( des == NULL )
return( NULL );
@@ -920,12 +911,12 @@ static void * des_ctx_alloc( void )
static void des_ctx_free( void *ctx )
{
mbedtls_des_free( (mbedtls_des_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void * des3_ctx_alloc( void )
{
- mbedtls_des3_context *des3 = (mbedtls_des3_context*)mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
+ mbedtls_des3_context *des3 = (mbedtls_des3_context*)calloc( 1, sizeof( mbedtls_des3_context ) );
if( des3 == NULL )
return( NULL );
@@ -938,7 +929,7 @@ static void * des3_ctx_alloc( void )
static void des3_ctx_free( void *ctx )
{
mbedtls_des3_free( (mbedtls_des3_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static const mbedtls_cipher_base_t des_info = {
@@ -1123,7 +1114,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
static void * blowfish_ctx_alloc( void )
{
- mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
+ mbedtls_blowfish_context *ctx = (mbedtls_blowfish_context*)calloc( 1, sizeof( mbedtls_blowfish_context ) );
if( ctx == NULL )
return( NULL );
@@ -1136,7 +1127,7 @@ static void * blowfish_ctx_alloc( void )
static void blowfish_ctx_free( void *ctx )
{
mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static const mbedtls_cipher_base_t blowfish_info = {
@@ -1232,7 +1223,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
static void * arc4_ctx_alloc( void )
{
- mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
+ mbedtls_arc4_context *ctx = (mbedtls_arc4_context*)calloc( 1, sizeof( mbedtls_arc4_context ) );
if( ctx == NULL )
return( NULL );
@@ -1245,7 +1236,7 @@ static void * arc4_ctx_alloc( void )
static void arc4_ctx_free( void *ctx )
{
mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static const mbedtls_cipher_base_t arc4_base_info = {
diff --git a/deps/mbedtls/cmac.c b/deps/mbedtls/cmac.c
deleted file mode 100644
index 0f0c772636..0000000000
--- a/deps/mbedtls/cmac.c
+++ /dev/null
@@ -1,1071 +0,0 @@
-/**
- * \file cmac.c
- *
- * \brief NIST SP800-38B compliant CMAC implementation for AES and 3DES
- *
- * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-/*
- * References:
- *
- * - NIST SP 800-38B Recommendation for Block Cipher Modes of Operation: The
- * CMAC Mode for Authentication
- * http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-38b.pdf
- *
- * - RFC 4493 - The AES-CMAC Algorithm
- * https://tools.ietf.org/html/rfc4493
- *
- * - RFC 4615 - The Advanced Encryption Standard-Cipher-based Message
- * Authentication Code-Pseudo-Random Function-128 (AES-CMAC-PRF-128)
- * Algorithm for the Internet Key Exchange Protocol (IKE)
- * https://tools.ietf.org/html/rfc4615
- *
- * Additional test vectors: ISO/IEC 9797-1
- *
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_CMAC_C)
-
-#include "mbedtls/cmac.h"
-
-#include
-
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#if defined(MBEDTLS_SELF_TEST)
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_SELF_TEST */
-#endif /* MBEDTLS_PLATFORM_C */
-
-#include "arc4_alt.h"
-
-/*
- * Multiplication by u in the Galois field of GF(2^n)
- *
- * As explained in NIST SP 800-38B, this can be computed:
- *
- * If MSB(p) = 0, then p = (p << 1)
- * If MSB(p) = 1, then p = (p << 1) ^ R_n
- * with R_64 = 0x1B and R_128 = 0x87
- *
- * Input and output MUST NOT point to the same buffer
- * Block size must be 8 bytes or 16 bytes - the block sizes for DES and AES.
- */
-static int cmac_multiply_by_u( unsigned char *output,
- const unsigned char *input,
- size_t blocksize )
-{
- const unsigned char R_128 = 0x87;
- const unsigned char R_64 = 0x1B;
- unsigned char R_n, mask;
- unsigned char overflow = 0x00;
- int i;
-
- if( blocksize == MBEDTLS_AES_BLOCK_SIZE )
- {
- R_n = R_128;
- }
- else if( blocksize == MBEDTLS_DES3_BLOCK_SIZE )
- {
- R_n = R_64;
- }
- else
- {
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- }
-
- for( i = (int)blocksize - 1; i >= 0; i-- )
- {
- output[i] = input[i] << 1 | overflow;
- overflow = input[i] >> 7;
- }
-
- /* mask = ( input[0] >> 7 ) ? 0xff : 0x00
- * using bit operations to avoid branches */
-
- /* MSVC has a warning about unary minus on unsigned, but this is
- * well-defined and precisely what we want to do here */
-#if defined(_MSC_VER)
-#pragma warning( push )
-#pragma warning( disable : 4146 )
-#endif
- mask = - ( input[0] >> 7 );
-#if defined(_MSC_VER)
-#pragma warning( pop )
-#endif
-
- output[ blocksize - 1 ] ^= R_n & mask;
-
- return( 0 );
-}
-
-/*
- * Generate subkeys
- *
- * - as specified by RFC 4493, section 2.3 Subkey Generation Algorithm
- */
-static int cmac_generate_subkeys( mbedtls_cipher_context_t *ctx,
- unsigned char* K1, unsigned char* K2 )
-{
- int ret;
- unsigned char L[MBEDTLS_CIPHER_BLKSIZE_MAX];
- size_t olen, block_size;
-
- mbedtls_zeroize( L, sizeof( L ) );
-
- block_size = ctx->cipher_info->block_size;
-
- /* Calculate Ek(0) */
- if( ( ret = mbedtls_cipher_update( ctx, L, block_size, L, &olen ) ) != 0 )
- goto exit;
-
- /*
- * Generate K1 and K2
- */
- if( ( ret = cmac_multiply_by_u( K1, L , block_size ) ) != 0 )
- goto exit;
-
- if( ( ret = cmac_multiply_by_u( K2, K1 , block_size ) ) != 0 )
- goto exit;
-
-exit:
- mbedtls_zeroize( L, sizeof( L ) );
-
- return( ret );
-}
-
-static void cmac_xor_block( unsigned char *output, const unsigned char *input1,
- const unsigned char *input2,
- const size_t block_size )
-{
- size_t index;
-
- for( index = 0; index < block_size; index++ )
- output[ index ] = input1[ index ] ^ input2[ index ];
-}
-
-/*
- * Create padded last block from (partial) last block.
- *
- * We can't use the padding option from the cipher layer, as it only works for
- * CBC and we use ECB mode, and anyway we need to XOR K1 or K2 in addition.
- */
-static void cmac_pad( unsigned char padded_block[MBEDTLS_CIPHER_BLKSIZE_MAX],
- size_t padded_block_len,
- const unsigned char *last_block,
- size_t last_block_len )
-{
- size_t j;
-
- for( j = 0; j < padded_block_len; j++ )
- {
- if( j < last_block_len )
- padded_block[j] = last_block[j];
- else if( j == last_block_len )
- padded_block[j] = 0x80;
- else
- padded_block[j] = 0x00;
- }
-}
-
-int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
- const unsigned char *key, size_t keybits )
-{
- mbedtls_cipher_type_t type;
- mbedtls_cmac_context_t *cmac_ctx;
- int retval;
-
- if( ctx == NULL || ctx->cipher_info == NULL || key == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- if( ( retval = mbedtls_cipher_setkey( ctx, key, (int)keybits,
- MBEDTLS_ENCRYPT ) ) != 0 )
- return( retval );
-
- type = ctx->cipher_info->type;
-
- switch( type )
- {
- case MBEDTLS_CIPHER_AES_128_ECB:
- case MBEDTLS_CIPHER_AES_192_ECB:
- case MBEDTLS_CIPHER_AES_256_ECB:
- case MBEDTLS_CIPHER_DES_EDE3_ECB:
- break;
- default:
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- }
-
- /* Allocated and initialise in the cipher context memory for the CMAC
- * context */
- cmac_ctx = mbedtls_calloc( 1, sizeof( mbedtls_cmac_context_t ) );
- if( cmac_ctx == NULL )
- return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
-
- ctx->cmac_ctx = cmac_ctx;
-
- mbedtls_zeroize( cmac_ctx->state, sizeof( cmac_ctx->state ) );
-
- return 0;
-}
-
-int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
- const unsigned char *input, size_t ilen )
-{
- mbedtls_cmac_context_t* cmac_ctx;
- unsigned char *state;
- int ret = 0;
- size_t n, j, olen, block_size;
-
- if( ctx == NULL || ctx->cipher_info == NULL || input == NULL ||
- ctx->cmac_ctx == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- cmac_ctx = ctx->cmac_ctx;
- block_size = ctx->cipher_info->block_size;
- state = ctx->cmac_ctx->state;
-
- /* Is there data still to process from the last call, that's greater in
- * size than a block? */
- if( cmac_ctx->unprocessed_len > 0 &&
- ilen > block_size - cmac_ctx->unprocessed_len )
- {
- memcpy( &cmac_ctx->unprocessed_block[cmac_ctx->unprocessed_len],
- input,
- block_size - cmac_ctx->unprocessed_len );
-
- cmac_xor_block( state, cmac_ctx->unprocessed_block, state, block_size );
-
- if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
- &olen ) ) != 0 )
- {
- goto exit;
- }
-
- input += block_size - cmac_ctx->unprocessed_len;
- ilen -= block_size - cmac_ctx->unprocessed_len;
- cmac_ctx->unprocessed_len = 0;
- }
-
- /* n is the number of blocks including any final partial block */
- n = ( ilen + block_size - 1 ) / block_size;
-
- /* Iterate across the input data in block sized chunks, excluding any
- * final partial or complete block */
- for( j = 1; j < n; j++ )
- {
- cmac_xor_block( state, input, state, block_size );
-
- if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
- &olen ) ) != 0 )
- goto exit;
-
- ilen -= block_size;
- input += block_size;
- }
-
- /* If there is data left over that wasn't aligned to a block */
- if( ilen > 0 )
- {
- memcpy( &cmac_ctx->unprocessed_block[cmac_ctx->unprocessed_len],
- input,
- ilen );
- cmac_ctx->unprocessed_len += ilen;
- }
-
-exit:
- return( ret );
-}
-
-int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
- unsigned char *output )
-{
- mbedtls_cmac_context_t* cmac_ctx;
- unsigned char *state, *last_block;
- unsigned char K1[MBEDTLS_CIPHER_BLKSIZE_MAX];
- unsigned char K2[MBEDTLS_CIPHER_BLKSIZE_MAX];
- unsigned char M_last[MBEDTLS_CIPHER_BLKSIZE_MAX];
- int ret;
- size_t olen, block_size;
-
- if( ctx == NULL || ctx->cipher_info == NULL || ctx->cmac_ctx == NULL ||
- output == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- cmac_ctx = ctx->cmac_ctx;
- block_size = ctx->cipher_info->block_size;
- state = cmac_ctx->state;
-
- mbedtls_zeroize( K1, sizeof( K1 ) );
- mbedtls_zeroize( K2, sizeof( K2 ) );
- cmac_generate_subkeys( ctx, K1, K2 );
-
- last_block = cmac_ctx->unprocessed_block;
-
- /* Calculate last block */
- if( cmac_ctx->unprocessed_len < block_size )
- {
- cmac_pad( M_last, block_size, last_block, cmac_ctx->unprocessed_len );
- cmac_xor_block( M_last, M_last, K2, block_size );
- }
- else
- {
- /* Last block is complete block */
- cmac_xor_block( M_last, last_block, K1, block_size );
- }
-
-
- cmac_xor_block( state, M_last, state, block_size );
- if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
- &olen ) ) != 0 )
- {
- goto exit;
- }
-
- memcpy( output, state, block_size );
-
-exit:
- /* Wipe the generated keys on the stack, and any other transients to avoid
- * side channel leakage */
- mbedtls_zeroize( K1, sizeof( K1 ) );
- mbedtls_zeroize( K2, sizeof( K2 ) );
-
- cmac_ctx->unprocessed_len = 0;
- mbedtls_zeroize( cmac_ctx->unprocessed_block,
- sizeof( cmac_ctx->unprocessed_block ) );
-
- mbedtls_zeroize( state, MBEDTLS_CIPHER_BLKSIZE_MAX );
- return( ret );
-}
-
-int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx )
-{
- mbedtls_cmac_context_t* cmac_ctx;
-
- if( ctx == NULL || ctx->cipher_info == NULL || ctx->cmac_ctx == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- cmac_ctx = ctx->cmac_ctx;
-
- /* Reset the internal state */
- cmac_ctx->unprocessed_len = 0;
- mbedtls_zeroize( cmac_ctx->unprocessed_block,
- sizeof( cmac_ctx->unprocessed_block ) );
- mbedtls_zeroize( cmac_ctx->state,
- sizeof( cmac_ctx->state ) );
-
- return( 0 );
-}
-
-int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
- const unsigned char *key, size_t keylen,
- const unsigned char *input, size_t ilen,
- unsigned char *output )
-{
- mbedtls_cipher_context_t ctx;
- int ret;
-
- if( cipher_info == NULL || key == NULL || input == NULL || output == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- mbedtls_cipher_init( &ctx );
-
- if( ( ret = mbedtls_cipher_setup( &ctx, cipher_info ) ) != 0 )
- goto exit;
-
- ret = mbedtls_cipher_cmac_starts( &ctx, key, keylen );
- if( ret != 0 )
- goto exit;
-
- ret = mbedtls_cipher_cmac_update( &ctx, input, ilen );
- if( ret != 0 )
- goto exit;
-
- ret = mbedtls_cipher_cmac_finish( &ctx, output );
-
-exit:
- mbedtls_cipher_free( &ctx );
-
- return( ret );
-}
-
-#if defined(MBEDTLS_AES_C)
-/*
- * Implementation of AES-CMAC-PRF-128 defined in RFC 4615
- */
-int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length,
- const unsigned char *input, size_t in_len,
- unsigned char *output )
-{
- int ret;
- const mbedtls_cipher_info_t *cipher_info;
- unsigned char zero_key[MBEDTLS_AES_BLOCK_SIZE];
- unsigned char int_key[MBEDTLS_AES_BLOCK_SIZE];
-
- if( key == NULL || input == NULL || output == NULL )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
-
- cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
- if( cipher_info == NULL )
- {
- /* Failing at this point must be due to a build issue */
- ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- goto exit;
- }
-
- if( key_length == MBEDTLS_AES_BLOCK_SIZE )
- {
- /* Use key as is */
- memcpy( int_key, key, MBEDTLS_AES_BLOCK_SIZE );
- }
- else
- {
- memset( zero_key, 0, MBEDTLS_AES_BLOCK_SIZE );
-
- ret = mbedtls_cipher_cmac( cipher_info, zero_key, 128, key,
- key_length, int_key );
- if( ret != 0 )
- goto exit;
- }
-
- ret = mbedtls_cipher_cmac( cipher_info, int_key, 128, input, in_len,
- output );
-
-exit:
- mbedtls_zeroize( int_key, sizeof( int_key ) );
-
- return( ret );
-}
-#endif /* MBEDTLS_AES_C */
-
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * CMAC test data for SP800-38B
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CMAC.pdf
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/TDES_CMAC.pdf
- *
- * AES-CMAC-PRF-128 test data from RFC 4615
- * https://tools.ietf.org/html/rfc4615#page-4
- */
-
-#define NB_CMAC_TESTS_PER_KEY 4
-#define NB_PRF_TESTS 3
-
-#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C)
-/* All CMAC test inputs are truncated from the same 64 byte buffer. */
-static const unsigned char test_message[] = {
- /* PT */
- 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
- 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
- 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
- 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
- 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
- 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
- 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
-};
-#endif /* MBEDTLS_AES_C || MBEDTLS_DES_C */
-
-#if defined(MBEDTLS_AES_C)
-/* Truncation point of message for AES CMAC tests */
-static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
- /* Mlen */
- 0,
- 16,
- 20,
- 64
-};
-
-/* CMAC-AES128 Test Data */
-static const unsigned char aes_128_key[16] = {
- 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
- 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
-};
-static const unsigned char aes_128_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* K1 */
- 0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66,
- 0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde
- },
- {
- /* K2 */
- 0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc,
- 0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b
- }
-};
-static const unsigned char aes_128_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* Example #1 */
- 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
- 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
- },
- {
- /* Example #2 */
- 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
- 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
- },
- {
- /* Example #3 */
- 0x7d, 0x85, 0x44, 0x9e, 0xa6, 0xea, 0x19, 0xc8,
- 0x23, 0xa7, 0xbf, 0x78, 0x83, 0x7d, 0xfa, 0xde
- },
- {
- /* Example #4 */
- 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
- 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
- }
-};
-
-/* CMAC-AES192 Test Data */
-static const unsigned char aes_192_key[24] = {
- 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
- 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
- 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
-};
-static const unsigned char aes_192_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* K1 */
- 0x44, 0x8a, 0x5b, 0x1c, 0x93, 0x51, 0x4b, 0x27,
- 0x3e, 0xe6, 0x43, 0x9d, 0xd4, 0xda, 0xa2, 0x96
- },
- {
- /* K2 */
- 0x89, 0x14, 0xb6, 0x39, 0x26, 0xa2, 0x96, 0x4e,
- 0x7d, 0xcc, 0x87, 0x3b, 0xa9, 0xb5, 0x45, 0x2c
- }
-};
-static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* Example #1 */
- 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
- 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
- },
- {
- /* Example #2 */
- 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
- 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
- },
- {
- /* Example #3 */
- 0x3d, 0x75, 0xc1, 0x94, 0xed, 0x96, 0x07, 0x04,
- 0x44, 0xa9, 0xfa, 0x7e, 0xc7, 0x40, 0xec, 0xf8
- },
- {
- /* Example #4 */
- 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
- 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
- }
-};
-
-/* CMAC-AES256 Test Data */
-static const unsigned char aes_256_key[32] = {
- 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
- 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
- 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
- 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
-};
-static const unsigned char aes_256_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* K1 */
- 0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac,
- 0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f
- },
- {
- /* K2 */
- 0x95, 0xa3, 0xda, 0x06, 0x53, 0x3d, 0xdb, 0x58,
- 0x5d, 0x35, 0x33, 0x01, 0x0c, 0x42, 0xa0, 0xd9
- }
-};
-static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
- {
- /* Example #1 */
- 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
- 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
- },
- {
- /* Example #2 */
- 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
- 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
- },
- {
- /* Example #3 */
- 0x15, 0x67, 0x27, 0xdc, 0x08, 0x78, 0x94, 0x4a,
- 0x02, 0x3c, 0x1f, 0xe0, 0x3b, 0xad, 0x6d, 0x93
- },
- {
- /* Example #4 */
- 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
- 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
- }
-};
-#endif /* MBEDTLS_AES_C */
-
-#if defined(MBEDTLS_DES_C)
-/* Truncation point of message for 3DES CMAC tests */
-static const unsigned int des3_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
- 0,
- 16,
- 20,
- 32
-};
-
-/* CMAC-TDES (Generation) - 2 Key Test Data */
-static const unsigned char des3_2key_key[24] = {
- /* Key1 */
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- /* Key2 */
- 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xEF, 0x01,
- /* Key3 */
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
-};
-static const unsigned char des3_2key_subkeys[2][8] = {
- {
- /* K1 */
- 0x0d, 0xd2, 0xcb, 0x7a, 0x3d, 0x88, 0x88, 0xd9
- },
- {
- /* K2 */
- 0x1b, 0xa5, 0x96, 0xf4, 0x7b, 0x11, 0x11, 0xb2
- }
-};
-static const unsigned char des3_2key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
- {
- /* Sample #1 */
- 0x79, 0xce, 0x52, 0xa7, 0xf7, 0x86, 0xa9, 0x60
- },
- {
- /* Sample #2 */
- 0xcc, 0x18, 0xa0, 0xb7, 0x9a, 0xf2, 0x41, 0x3b
- },
- {
- /* Sample #3 */
- 0xc0, 0x6d, 0x37, 0x7e, 0xcd, 0x10, 0x19, 0x69
- },
- {
- /* Sample #4 */
- 0x9c, 0xd3, 0x35, 0x80, 0xf9, 0xb6, 0x4d, 0xfb
- }
-};
-
-/* CMAC-TDES (Generation) - 3 Key Test Data */
-static const unsigned char des3_3key_key[24] = {
- /* Key1 */
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xaa, 0xcd, 0xef,
- /* Key2 */
- 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
- /* Key3 */
- 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
-};
-static const unsigned char des3_3key_subkeys[2][8] = {
- {
- /* K1 */
- 0x9d, 0x74, 0xe7, 0x39, 0x33, 0x17, 0x96, 0xc0
- },
- {
- /* K2 */
- 0x3a, 0xe9, 0xce, 0x72, 0x66, 0x2f, 0x2d, 0x9b
- }
-};
-static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
- {
- /* Sample #1 */
- 0x7d, 0xb0, 0xd3, 0x7d, 0xf9, 0x36, 0xc5, 0x50
- },
- {
- /* Sample #2 */
- 0x30, 0x23, 0x9c, 0xf1, 0xf5, 0x2e, 0x66, 0x09
- },
- {
- /* Sample #3 */
- 0x6c, 0x9f, 0x3e, 0xe4, 0x92, 0x3f, 0x6b, 0xe2
- },
- {
- /* Sample #4 */
- 0x99, 0x42, 0x9b, 0xd0, 0xbF, 0x79, 0x04, 0xe5
- }
-};
-
-#endif /* MBEDTLS_DES_C */
-
-#if defined(MBEDTLS_AES_C)
-/* AES AES-CMAC-PRF-128 Test Data */
-static const unsigned char PRFK[] = {
- /* Key */
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0xed, 0xcb
-};
-
-/* Sizes in bytes */
-static const size_t PRFKlen[NB_PRF_TESTS] = {
- 18,
- 16,
- 10
-};
-
-/* Message */
-static const unsigned char PRFM[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13
-};
-
-static const unsigned char PRFT[NB_PRF_TESTS][16] = {
- {
- 0x84, 0xa3, 0x48, 0xa4, 0xa4, 0x5d, 0x23, 0x5b,
- 0xab, 0xff, 0xfc, 0x0d, 0x2b, 0x4d, 0xa0, 0x9a
- },
- {
- 0x98, 0x0a, 0xe8, 0x7b, 0x5f, 0x4c, 0x9c, 0x52,
- 0x14, 0xf5, 0xb6, 0xa8, 0x45, 0x5e, 0x4c, 0x2d
- },
- {
- 0x29, 0x0d, 0x9e, 0x11, 0x2e, 0xdb, 0x09, 0xee,
- 0x14, 0x1f, 0xcf, 0x64, 0xc0, 0xb7, 0x2f, 0x3d
- }
-};
-#endif /* MBEDTLS_AES_C */
-
-static int cmac_test_subkeys( int verbose,
- const char* testname,
- const unsigned char* key,
- int keybits,
- const unsigned char* subkeys,
- mbedtls_cipher_type_t cipher_type,
- int block_size,
- int num_tests )
-{
- int i, ret;
- mbedtls_cipher_context_t ctx;
- const mbedtls_cipher_info_t *cipher_info;
- unsigned char K1[MBEDTLS_CIPHER_BLKSIZE_MAX];
- unsigned char K2[MBEDTLS_CIPHER_BLKSIZE_MAX];
-
- cipher_info = mbedtls_cipher_info_from_type( cipher_type );
- if( cipher_info == NULL )
- {
- /* Failing at this point must be due to a build issue */
- return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
- }
-
- for( i = 0; i < num_tests; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " %s CMAC subkey #%u: ", testname, i + 1 );
-
- mbedtls_cipher_init( &ctx );
-
- if( ( ret = mbedtls_cipher_setup( &ctx, cipher_info ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "test execution failed\n" );
-
- goto cleanup;
- }
-
- if( ( ret = mbedtls_cipher_setkey( &ctx, key, keybits,
- MBEDTLS_ENCRYPT ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "test execution failed\n" );
-
- goto cleanup;
- }
-
- ret = cmac_generate_subkeys( &ctx, K1, K2 );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- goto cleanup;
- }
-
- if( ( ret = memcmp( K1, subkeys, block_size ) ) != 0 ||
- ( ret = memcmp( K2, &subkeys[block_size], block_size ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- goto cleanup;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- mbedtls_cipher_free( &ctx );
- }
-
- goto exit;
-
-cleanup:
- mbedtls_cipher_free( &ctx );
-
-exit:
- return( ret );
-}
-
-static int cmac_test_wth_cipher( int verbose,
- const char* testname,
- const unsigned char* key,
- int keybits,
- const unsigned char* messages,
- const unsigned int message_lengths[4],
- const unsigned char* expected_result,
- mbedtls_cipher_type_t cipher_type,
- int block_size,
- int num_tests )
-{
- const mbedtls_cipher_info_t *cipher_info;
- int i, ret;
- unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX];
-
- cipher_info = mbedtls_cipher_info_from_type( cipher_type );
- if( cipher_info == NULL )
- {
- /* Failing at this point must be due to a build issue */
- ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
- goto exit;
- }
-
- for( i = 0; i < num_tests; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " %s CMAC #%u: ", testname, i + 1 );
-
- if( ( ret = mbedtls_cipher_cmac( cipher_info, key, keybits, messages,
- message_lengths[i], output ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
- goto exit;
- }
-
- if( ( ret = memcmp( output, &expected_result[i * block_size], block_size ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
-exit:
- return( ret );
-}
-
-#if defined(MBEDTLS_AES_C)
-static int test_aes128_cmac_prf( int verbose )
-{
- int i;
- int ret;
- unsigned char output[MBEDTLS_AES_BLOCK_SIZE];
-
- for( i = 0; i < NB_PRF_TESTS; i++ )
- {
- mbedtls_printf( " AES CMAC 128 PRF #%u: ", i );
- ret = mbedtls_aes_cmac_prf_128( PRFK, PRFKlen[i], PRFM, 20, output );
- if( ret != 0 ||
- memcmp( output, PRFT[i], MBEDTLS_AES_BLOCK_SIZE ) != 0 )
- {
-
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( ret );
- }
- else if( verbose != 0 )
- {
- mbedtls_printf( "passed\n" );
- }
- }
- return( ret );
-}
-#endif /* MBEDTLS_AES_C */
-
-int mbedtls_cmac_self_test( int verbose )
-{
- int ret;
-
-#if defined(MBEDTLS_AES_C)
- /* AES-128 */
- if( ( ret = cmac_test_subkeys( verbose,
- "AES 128",
- aes_128_key,
- 128,
- (const unsigned char*)aes_128_subkeys,
- MBEDTLS_CIPHER_AES_128_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- if( ( ret = cmac_test_wth_cipher( verbose,
- "AES 128",
- aes_128_key,
- 128,
- test_message,
- aes_message_lengths,
- (const unsigned char*)aes_128_expected_result,
- MBEDTLS_CIPHER_AES_128_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- /* AES-192 */
- if( ( ret = cmac_test_subkeys( verbose,
- "AES 192",
- aes_192_key,
- 192,
- (const unsigned char*)aes_192_subkeys,
- MBEDTLS_CIPHER_AES_192_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- if( ( ret = cmac_test_wth_cipher( verbose,
- "AES 192",
- aes_192_key,
- 192,
- test_message,
- aes_message_lengths,
- (const unsigned char*)aes_192_expected_result,
- MBEDTLS_CIPHER_AES_192_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- /* AES-256 */
- if( ( ret = cmac_test_subkeys( verbose,
- "AES 256",
- aes_256_key,
- 256,
- (const unsigned char*)aes_256_subkeys,
- MBEDTLS_CIPHER_AES_256_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- if( ( ret = cmac_test_wth_cipher ( verbose,
- "AES 256",
- aes_256_key,
- 256,
- test_message,
- aes_message_lengths,
- (const unsigned char*)aes_256_expected_result,
- MBEDTLS_CIPHER_AES_256_ECB,
- MBEDTLS_AES_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-#endif /* MBEDTLS_AES_C */
-
-#if defined(MBEDTLS_DES_C)
- /* 3DES 2 key */
- if( ( ret = cmac_test_subkeys( verbose,
- "3DES 2 key",
- des3_2key_key,
- 192,
- (const unsigned char*)des3_2key_subkeys,
- MBEDTLS_CIPHER_DES_EDE3_ECB,
- MBEDTLS_DES3_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- if( ( ret = cmac_test_wth_cipher( verbose,
- "3DES 2 key",
- des3_2key_key,
- 192,
- test_message,
- des3_message_lengths,
- (const unsigned char*)des3_2key_expected_result,
- MBEDTLS_CIPHER_DES_EDE3_ECB,
- MBEDTLS_DES3_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- /* 3DES 3 key */
- if( ( ret = cmac_test_subkeys( verbose,
- "3DES 3 key",
- des3_3key_key,
- 192,
- (const unsigned char*)des3_3key_subkeys,
- MBEDTLS_CIPHER_DES_EDE3_ECB,
- MBEDTLS_DES3_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-
- if( ( ret = cmac_test_wth_cipher( verbose,
- "3DES 3 key",
- des3_3key_key,
- 192,
- test_message,
- des3_message_lengths,
- (const unsigned char*)des3_3key_expected_result,
- MBEDTLS_CIPHER_DES_EDE3_ECB,
- MBEDTLS_DES3_BLOCK_SIZE,
- NB_CMAC_TESTS_PER_KEY ) ) != 0 )
- {
- return( ret );
- }
-#endif /* MBEDTLS_DES_C */
-
-#if defined(MBEDTLS_AES_C)
- if( ( ret = test_aes128_cmac_prf( verbose ) ) != 0 )
- return( ret );
-#endif /* MBEDTLS_AES_C */
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
-#endif /* MBEDTLS_CMAC_C */
diff --git a/deps/mbedtls/ctr_drbg.c b/deps/mbedtls/ctr_drbg.c
index 1c3d89f0b3..f886be94b3 100644
--- a/deps/mbedtls/ctr_drbg.c
+++ b/deps/mbedtls/ctr_drbg.c
@@ -40,15 +40,6 @@
#include
#endif
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#include "arc4_alt.h"
/*
@@ -472,120 +463,4 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
}
#endif /* MBEDTLS_FS_IO */
-#if defined(MBEDTLS_SELF_TEST)
-
-static const unsigned char entropy_source_pr[96] =
- { 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
- 0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
- 0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
- 0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb,
- 0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9,
- 0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95,
- 0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63,
- 0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3,
- 0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31,
- 0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4,
- 0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
- 0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 };
-
-static const unsigned char entropy_source_nopr[64] =
- { 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
- 0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
- 0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
- 0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20,
- 0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9,
- 0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46,
- 0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e,
- 0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e };
-
-static const unsigned char nonce_pers_pr[16] =
- { 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2,
- 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c };
-
-static const unsigned char nonce_pers_nopr[16] =
- { 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5,
- 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f };
-
-static const unsigned char ctr_result_pr[16] =
- { 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f,
- 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 };
-
-static const unsigned char ctr_result_nopr[16] =
- { 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88,
- 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
-
-static size_t test_offset;
-static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
- size_t len )
-{
- const unsigned char *p = data;
- memcpy( buf, p + test_offset, len );
- test_offset += len;
- return( 0 );
-}
-
-#define CHK( c ) if( (c) != 0 ) \
- { \
- if( verbose != 0 ) \
- mbedtls_printf( "failed\n" ); \
- return( 1 ); \
- }
-
-/*
- * Checkup routine
- */
-int mbedtls_ctr_drbg_self_test( int verbose )
-{
- mbedtls_ctr_drbg_context ctx;
- unsigned char buf[16];
-
- mbedtls_ctr_drbg_init( &ctx );
-
- /*
- * Based on a NIST CTR_DRBG test vector (PR = True)
- */
- if( verbose != 0 )
- mbedtls_printf( " CTR_DRBG (PR = TRUE) : " );
-
- test_offset = 0;
- CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
- (void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) );
- mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
- CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
- CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
- CHK( memcmp( buf, ctr_result_pr, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
-
- mbedtls_ctr_drbg_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- /*
- * Based on a NIST CTR_DRBG test vector (PR = FALSE)
- */
- if( verbose != 0 )
- mbedtls_printf( " CTR_DRBG (PR = FALSE): " );
-
- mbedtls_ctr_drbg_init( &ctx );
-
- test_offset = 0;
- CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
- (void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
- CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
- CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) );
- CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
- CHK( memcmp( buf, ctr_result_nopr, 16 ) );
-
- mbedtls_ctr_drbg_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_CTR_DRBG_C */
diff --git a/deps/mbedtls/debug.c b/deps/mbedtls/debug.c
index 95a61789f2..71300725e9 100644
--- a/deps/mbedtls/debug.c
+++ b/deps/mbedtls/debug.c
@@ -27,15 +27,7 @@
#if defined(MBEDTLS_DEBUG_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#define mbedtls_time_t time_t
-#define mbedtls_snprintf snprintf
-#endif
#include "mbedtls/debug.h"
@@ -66,7 +58,7 @@ static void debug_send_line( const mbedtls_ssl_context *ssl, int level,
*/
#if defined(MBEDTLS_THREADING_C)
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
- mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
+ snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
#else
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
@@ -133,7 +125,7 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
if( ret == MBEDTLS_ERR_SSL_WANT_READ )
return;
- mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
+ snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
text, ret, -ret );
debug_send_line( ssl, level, file, line, str );
@@ -150,7 +142,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
return;
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
+ snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
debug_send_line( ssl, level, file, line, str );
@@ -166,19 +158,19 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
{
if( i > 0 )
{
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
+ snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
debug_send_line( ssl, level, file, line, str );
idx = 0;
memset( txt, 0, sizeof( txt ) );
}
- idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
+ idx += snprintf( str + idx, sizeof( str ) - idx, "%04x: ",
(unsigned int) i );
}
- idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x",
+ idx += snprintf( str + idx, sizeof( str ) - idx, " %02x",
(unsigned int) buf[i] );
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
}
@@ -186,9 +178,9 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
if( len > 0 )
{
for( /* i = i */; i % 16 != 0; i++ )
- idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
+ idx += snprintf( str + idx, sizeof( str ) - idx, " " );
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
+ snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
debug_send_line( ssl, level, file, line, str );
}
}
@@ -203,10 +195,10 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold )
return;
- mbedtls_snprintf( str, sizeof( str ), "%s(X)", text );
+ snprintf( str, sizeof( str ), "%s(X)", text );
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X );
- mbedtls_snprintf( str, sizeof( str ), "%s(Y)", text );
+ snprintf( str, sizeof( str ), "%s(Y)", text );
mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->Y );
}
#endif /* MBEDTLS_ECP_C */
@@ -231,7 +223,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
if( ( ( X->p[n] >> j ) & 1 ) != 0 )
break;
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
+ snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
debug_send_line( ssl, level, file, line, str );
@@ -253,13 +245,13 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
{
if( j > 0 )
{
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
+ snprintf( str + idx, sizeof( str ) - idx, "\n" );
debug_send_line( ssl, level, file, line, str );
idx = 0;
}
}
- idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
+ idx += snprintf( str + idx, sizeof( str ) - idx, " %02x", (unsigned int)
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++;
@@ -268,9 +260,9 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
}
if( zeros == 1 )
- idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
+ idx += snprintf( str + idx, sizeof( str ) - idx, " 00" );
- mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
+ snprintf( str + idx, sizeof( str ) - idx, "\n" );
debug_send_line( ssl, level, file, line, str );
}
#endif /* MBEDTLS_BIGNUM_C */
@@ -298,7 +290,7 @@ static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
if( items[i].type == MBEDTLS_PK_DEBUG_NONE )
return;
- mbedtls_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
+ snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
name[sizeof( name ) - 1] = '\0';
if( items[i].type == MBEDTLS_PK_DEBUG_MPI )
@@ -353,7 +345,7 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
{
char buf[1024];
- mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
+ snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
debug_send_line( ssl, level, file, line, str );
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
diff --git a/deps/mbedtls/des.c b/deps/mbedtls/des.c
index 1c50f24cd9..7d7f90ba02 100644
--- a/deps/mbedtls/des.c
+++ b/deps/mbedtls/des.c
@@ -37,15 +37,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_DES_ALT)
#include "arc4_alt.h"
@@ -808,251 +799,4 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
#endif /* !MBEDTLS_DES_ALT */
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * DES and 3DES test vectors from:
- *
- * http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip
- */
-static const unsigned char des3_test_keys[24] =
-{
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
- 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
- 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
-};
-
-static const unsigned char des3_test_buf[8] =
-{
- 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
-};
-
-static const unsigned char des3_test_ecb_dec[3][8] =
-{
- { 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D },
- { 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB },
- { 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A }
-};
-
-static const unsigned char des3_test_ecb_enc[3][8] =
-{
- { 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B },
- { 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 },
- { 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 }
-};
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
-static const unsigned char des3_test_iv[8] =
-{
- 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
-};
-
-static const unsigned char des3_test_cbc_dec[3][8] =
-{
- { 0x12, 0x9F, 0x40, 0xB9, 0xD2, 0x00, 0x56, 0xB3 },
- { 0x47, 0x0E, 0xFC, 0x9A, 0x6B, 0x8E, 0xE3, 0x93 },
- { 0xC5, 0xCE, 0xCF, 0x63, 0xEC, 0xEC, 0x51, 0x4C }
-};
-
-static const unsigned char des3_test_cbc_enc[3][8] =
-{
- { 0x54, 0xF1, 0x5A, 0xF6, 0xEB, 0xE3, 0xA4, 0xB4 },
- { 0x35, 0x76, 0x11, 0x56, 0x5F, 0xA1, 0x8E, 0x4D },
- { 0xCB, 0x19, 0x1F, 0x85, 0xD1, 0xED, 0x84, 0x39 }
-};
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
-/*
- * Checkup routine
- */
-int mbedtls_des_self_test( int verbose )
-{
- int i, j, u, v, ret = 0;
- mbedtls_des_context ctx;
- mbedtls_des3_context ctx3;
- unsigned char buf[8];
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- unsigned char prv[8];
- unsigned char iv[8];
-#endif
-
- mbedtls_des_init( &ctx );
- mbedtls_des3_init( &ctx3 );
- /*
- * ECB mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " DES%c-ECB-%3d (%s): ",
- ( u == 0 ) ? ' ' : '3', 56 + u * 56,
- ( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( buf, des3_test_buf, 8 );
-
- switch( i )
- {
- case 0:
- mbedtls_des_setkey_dec( &ctx, des3_test_keys );
- break;
-
- case 1:
- mbedtls_des_setkey_enc( &ctx, des3_test_keys );
- break;
-
- case 2:
- mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
- break;
-
- case 3:
- mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
- break;
-
- case 4:
- mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
- break;
-
- case 5:
- mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
- break;
-
- default:
- return( 1 );
- }
-
- for( j = 0; j < 10000; j++ )
- {
- if( u == 0 )
- mbedtls_des_crypt_ecb( &ctx, buf, buf );
- else
- mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
- }
-
- if( ( v == MBEDTLS_DES_DECRYPT &&
- memcmp( buf, des3_test_ecb_dec[u], 8 ) != 0 ) ||
- ( v != MBEDTLS_DES_DECRYPT &&
- memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- /*
- * CBC mode
- */
- for( i = 0; i < 6; i++ )
- {
- u = i >> 1;
- v = i & 1;
-
- if( verbose != 0 )
- mbedtls_printf( " DES%c-CBC-%3d (%s): ",
- ( u == 0 ) ? ' ' : '3', 56 + u * 56,
- ( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
-
- memcpy( iv, des3_test_iv, 8 );
- memcpy( prv, des3_test_iv, 8 );
- memcpy( buf, des3_test_buf, 8 );
-
- switch( i )
- {
- case 0:
- mbedtls_des_setkey_dec( &ctx, des3_test_keys );
- break;
-
- case 1:
- mbedtls_des_setkey_enc( &ctx, des3_test_keys );
- break;
-
- case 2:
- mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
- break;
-
- case 3:
- mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
- break;
-
- case 4:
- mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
- break;
-
- case 5:
- mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
- break;
-
- default:
- return( 1 );
- }
-
- if( v == MBEDTLS_DES_DECRYPT )
- {
- for( j = 0; j < 10000; j++ )
- {
- if( u == 0 )
- mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
- else
- mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
- }
- }
- else
- {
- for( j = 0; j < 10000; j++ )
- {
- unsigned char tmp[8];
-
- if( u == 0 )
- mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
- else
- mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
-
- memcpy( tmp, prv, 8 );
- memcpy( prv, buf, 8 );
- memcpy( buf, tmp, 8 );
- }
-
- memcpy( buf, prv, 8 );
- }
-
- if( ( v == MBEDTLS_DES_DECRYPT &&
- memcmp( buf, des3_test_cbc_dec[u], 8 ) != 0 ) ||
- ( v != MBEDTLS_DES_DECRYPT &&
- memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_des_free( &ctx );
- mbedtls_des3_free( &ctx3 );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_DES_C */
diff --git a/deps/mbedtls/dhm.c b/deps/mbedtls/dhm.c
index 241e0590ae..e70a1fb755 100644
--- a/deps/mbedtls/dhm.c
+++ b/deps/mbedtls/dhm.c
@@ -47,15 +47,8 @@
#include "mbedtls/asn1.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#include "arc4_alt.h"
@@ -530,7 +523,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char*)mbedtls_calloc( 1, *n + 1 ) ) == NULL )
+ ( *buf = (unsigned char*)calloc( 1, *n + 1 ) ) == NULL )
{
fclose( f );
return( MBEDTLS_ERR_DHM_ALLOC_FAILED );
@@ -539,7 +532,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
if( fread( *buf, 1, *n, f ) != *n )
{
fclose( f );
- mbedtls_free( *buf );
+ free( *buf );
return( MBEDTLS_ERR_DHM_FILE_IO_ERROR );
}
@@ -568,57 +561,11 @@ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path )
ret = mbedtls_dhm_parse_dhm( dhm, buf, n );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
#endif /* MBEDTLS_FS_IO */
#endif /* MBEDTLS_ASN1_PARSE_C */
-#if defined(MBEDTLS_SELF_TEST)
-
-static const char mbedtls_test_dhm_params[] =
-"-----BEGIN DH PARAMETERS-----\r\n"
-"MIGHAoGBAJ419DBEOgmQTzo5qXl5fQcN9TN455wkOL7052HzxxRVMyhYmwQcgJvh\r\n"
-"1sa18fyfR9OiVEMYglOpkqVoGLN7qd5aQNNi5W7/C+VBdHTBJcGZJyyP5B3qcz32\r\n"
-"9mLJKudlVudV0Qxk5qUJaPZ/xupz0NyoVpviuiBOI1gNi8ovSXWzAgEC\r\n"
-"-----END DH PARAMETERS-----\r\n";
-
-static const size_t mbedtls_test_dhm_params_len = sizeof( mbedtls_test_dhm_params );
-
-/*
- * Checkup routine
- */
-int mbedtls_dhm_self_test( int verbose )
-{
- int ret;
- mbedtls_dhm_context dhm;
-
- mbedtls_dhm_init( &dhm );
-
- if( verbose != 0 )
- mbedtls_printf( " DHM parameter load: " );
-
- if( ( ret = mbedtls_dhm_parse_dhm( &dhm,
- (const unsigned char *) mbedtls_test_dhm_params,
- mbedtls_test_dhm_params_len ) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n\n" );
-
-exit:
- mbedtls_dhm_free( &dhm );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_DHM_C */
diff --git a/deps/mbedtls/ecdsa.c b/deps/mbedtls/ecdsa.c
index 4156f3c3c4..dbbc5a4360 100644
--- a/deps/mbedtls/ecdsa.c
+++ b/deps/mbedtls/ecdsa.c
@@ -339,18 +339,6 @@ cleanup:
return( ret );
}
-#if ! defined(MBEDTLS_DEPRECATED_REMOVED) && \
- defined(MBEDTLS_ECDSA_DETERMINISTIC)
-int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
- const unsigned char *hash, size_t hlen,
- unsigned char *sig, size_t *slen,
- mbedtls_md_type_t md_alg )
-{
- return( mbedtls_ecdsa_write_signature( ctx, md_alg, hash, hlen, sig, slen,
- NULL, NULL ) );
-}
-#endif
-
/*
* Read and check signature
*/
diff --git a/deps/mbedtls/ecjpake.c b/deps/mbedtls/ecjpake.c
deleted file mode 100644
index 9218c5d172..0000000000
--- a/deps/mbedtls/ecjpake.c
+++ /dev/null
@@ -1,1103 +0,0 @@
-/*
- * Elliptic curve J-PAKE
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-/*
- * References in the code are to the Thread v1.0 Specification,
- * available to members of the Thread Group http://threadgroup.org/
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_ECJPAKE_C)
-
-#include "mbedtls/ecjpake.h"
-
-#include
-
-/*
- * Convert a mbedtls_ecjpake_role to identifier string
- */
-static const char * const ecjpake_id[] = {
- "client",
- "server"
-};
-
-#define ID_MINE ( ecjpake_id[ ctx->role ] )
-#define ID_PEER ( ecjpake_id[ 1 - ctx->role ] )
-
-/*
- * Initialize context
- */
-void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx )
-{
- if( ctx == NULL )
- return;
-
- ctx->md_info = NULL;
- mbedtls_ecp_group_init( &ctx->grp );
- ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
-
- mbedtls_ecp_point_init( &ctx->Xm1 );
- mbedtls_ecp_point_init( &ctx->Xm2 );
- mbedtls_ecp_point_init( &ctx->Xp1 );
- mbedtls_ecp_point_init( &ctx->Xp2 );
- mbedtls_ecp_point_init( &ctx->Xp );
-
- mbedtls_mpi_init( &ctx->xm1 );
- mbedtls_mpi_init( &ctx->xm2 );
- mbedtls_mpi_init( &ctx->s );
-}
-
-/*
- * Free context
- */
-void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx )
-{
- if( ctx == NULL )
- return;
-
- ctx->md_info = NULL;
- mbedtls_ecp_group_free( &ctx->grp );
-
- mbedtls_ecp_point_free( &ctx->Xm1 );
- mbedtls_ecp_point_free( &ctx->Xm2 );
- mbedtls_ecp_point_free( &ctx->Xp1 );
- mbedtls_ecp_point_free( &ctx->Xp2 );
- mbedtls_ecp_point_free( &ctx->Xp );
-
- mbedtls_mpi_free( &ctx->xm1 );
- mbedtls_mpi_free( &ctx->xm2 );
- mbedtls_mpi_free( &ctx->s );
-}
-
-/*
- * Setup context
- */
-int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
- mbedtls_ecjpake_role role,
- mbedtls_md_type_t hash,
- mbedtls_ecp_group_id curve,
- const unsigned char *secret,
- size_t len )
-{
- int ret;
-
- ctx->role = role;
-
- if( ( ctx->md_info = mbedtls_md_info_from_type( hash ) ) == NULL )
- return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE );
-
- MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &ctx->grp, curve ) );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->s, secret, len ) );
-
-cleanup:
- if( ret != 0 )
- mbedtls_ecjpake_free( ctx );
-
- return( ret );
-}
-
-/*
- * Check if context is ready for use
- */
-int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx )
-{
- if( ctx->md_info == NULL ||
- ctx->grp.id == MBEDTLS_ECP_DP_NONE ||
- ctx->s.p == NULL )
- {
- return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
- }
-
- return( 0 );
-}
-
-/*
- * Write a point plus its length to a buffer
- */
-static int ecjpake_write_len_point( unsigned char **p,
- const unsigned char *end,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *P )
-{
- int ret;
- size_t len;
-
- /* Need at least 4 for length plus 1 for point */
- if( end < *p || end - *p < 5 )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- ret = mbedtls_ecp_point_write_binary( grp, P, pf,
- &len, *p + 4, end - ( *p + 4 ) );
- if( ret != 0 )
- return( ret );
-
- (*p)[0] = (unsigned char)( ( len >> 24 ) & 0xFF );
- (*p)[1] = (unsigned char)( ( len >> 16 ) & 0xFF );
- (*p)[2] = (unsigned char)( ( len >> 8 ) & 0xFF );
- (*p)[3] = (unsigned char)( ( len ) & 0xFF );
-
- *p += 4 + len;
-
- return( 0 );
-}
-
-/*
- * Size of the temporary buffer for ecjpake_hash:
- * 3 EC points plus their length, plus ID and its length (4 + 6 bytes)
- */
-#define ECJPAKE_HASH_BUF_LEN ( 3 * ( 4 + MBEDTLS_ECP_MAX_PT_LEN ) + 4 + 6 )
-
-/*
- * Compute hash for ZKP (7.4.2.2.2.1)
- */
-static int ecjpake_hash( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- const mbedtls_ecp_point *V,
- const mbedtls_ecp_point *X,
- const char *id,
- mbedtls_mpi *h )
-{
- int ret;
- unsigned char buf[ECJPAKE_HASH_BUF_LEN];
- unsigned char *p = buf;
- const unsigned char *end = buf + sizeof( buf );
- const size_t id_len = strlen( id );
- unsigned char hash[MBEDTLS_MD_MAX_SIZE];
-
- /* Write things to temporary buffer */
- MBEDTLS_MPI_CHK( ecjpake_write_len_point( &p, end, grp, pf, G ) );
- MBEDTLS_MPI_CHK( ecjpake_write_len_point( &p, end, grp, pf, V ) );
- MBEDTLS_MPI_CHK( ecjpake_write_len_point( &p, end, grp, pf, X ) );
-
- if( end - p < 4 )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- *p++ = (unsigned char)( ( id_len >> 24 ) & 0xFF );
- *p++ = (unsigned char)( ( id_len >> 16 ) & 0xFF );
- *p++ = (unsigned char)( ( id_len >> 8 ) & 0xFF );
- *p++ = (unsigned char)( ( id_len ) & 0xFF );
-
- if( end < p || (size_t)( end - p ) < id_len )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- memcpy( p, id, id_len );
- p += id_len;
-
- /* Compute hash */
- mbedtls_md( md_info, buf, p - buf, hash );
-
- /* Turn it into an integer mod n */
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( h, hash,
- mbedtls_md_get_size( md_info ) ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( h, h, &grp->N ) );
-
-cleanup:
- return( ret );
-}
-
-/*
- * Parse a ECShnorrZKP (7.4.2.2.2) and verify it (7.4.2.3.3)
- */
-static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- const mbedtls_ecp_point *X,
- const char *id,
- const unsigned char **p,
- const unsigned char *end )
-{
- int ret;
- mbedtls_ecp_point V, VV;
- mbedtls_mpi r, h;
- size_t r_len;
-
- mbedtls_ecp_point_init( &V );
- mbedtls_ecp_point_init( &VV );
- mbedtls_mpi_init( &r );
- mbedtls_mpi_init( &h );
-
- /*
- * struct {
- * ECPoint V;
- * opaque r<1..2^8-1>;
- * } ECSchnorrZKP;
- */
- if( end < *p )
- return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
-
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, &V, p, end - *p ) );
-
- if( end < *p || (size_t)( end - *p ) < 1 )
- {
- ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
- goto cleanup;
- }
-
- r_len = *(*p)++;
-
- if( end < *p || (size_t)( end - *p ) < r_len )
- {
- ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
- goto cleanup;
- }
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &r, *p, r_len ) );
- *p += r_len;
-
- /*
- * Verification
- */
- MBEDTLS_MPI_CHK( ecjpake_hash( md_info, grp, pf, G, &V, X, id, &h ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_muladd( (mbedtls_ecp_group *) grp,
- &VV, &h, X, &r, G ) );
-
- if( mbedtls_ecp_point_cmp( &VV, &V ) != 0 )
- {
- ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
- goto cleanup;
- }
-
-cleanup:
- mbedtls_ecp_point_free( &V );
- mbedtls_ecp_point_free( &VV );
- mbedtls_mpi_free( &r );
- mbedtls_mpi_free( &h );
-
- return( ret );
-}
-
-/*
- * Generate ZKP (7.4.2.3.2) and write it as ECSchnorrZKP (7.4.2.2.2)
- */
-static int ecjpake_zkp_write( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- const mbedtls_mpi *x,
- const mbedtls_ecp_point *X,
- const char *id,
- unsigned char **p,
- const unsigned char *end,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- mbedtls_ecp_point V;
- mbedtls_mpi v;
- mbedtls_mpi h; /* later recycled to hold r */
- size_t len;
-
- if( end < *p )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- mbedtls_ecp_point_init( &V );
- mbedtls_mpi_init( &v );
- mbedtls_mpi_init( &h );
-
- /* Compute signature */
- MBEDTLS_MPI_CHK( mbedtls_ecp_gen_keypair_base( (mbedtls_ecp_group *) grp,
- G, &v, &V, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( ecjpake_hash( md_info, grp, pf, G, &V, X, id, &h ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &h, &h, x ) ); /* x*h */
- MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &h, &v, &h ) ); /* v - x*h */
- MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &h, &h, &grp->N ) ); /* r */
-
- /* Write it out */
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_write_point( grp, &V,
- pf, &len, *p, end - *p ) );
- *p += len;
-
- len = mbedtls_mpi_size( &h ); /* actually r */
- if( end < *p || (size_t)( end - *p ) < 1 + len || len > 255 )
- {
- ret = MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
- goto cleanup;
- }
-
- *(*p)++ = (unsigned char)( len & 0xFF );
- MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &h, *p, len ) ); /* r */
- *p += len;
-
-cleanup:
- mbedtls_ecp_point_free( &V );
- mbedtls_mpi_free( &v );
- mbedtls_mpi_free( &h );
-
- return( ret );
-}
-
-/*
- * Parse a ECJPAKEKeyKP (7.4.2.2.1) and check proof
- * Output: verified public key X
- */
-static int ecjpake_kkp_read( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- mbedtls_ecp_point *X,
- const char *id,
- const unsigned char **p,
- const unsigned char *end )
-{
- int ret;
-
- if( end < *p )
- return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
-
- /*
- * struct {
- * ECPoint X;
- * ECSchnorrZKP zkp;
- * } ECJPAKEKeyKP;
- */
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, X, p, end - *p ) );
- if( mbedtls_ecp_is_zero( X ) )
- {
- ret = MBEDTLS_ERR_ECP_INVALID_KEY;
- goto cleanup;
- }
-
- MBEDTLS_MPI_CHK( ecjpake_zkp_read( md_info, grp, pf, G, X, id, p, end ) );
-
-cleanup:
- return( ret );
-}
-
-/*
- * Generate an ECJPAKEKeyKP
- * Output: the serialized structure, plus private/public key pair
- */
-static int ecjpake_kkp_write( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- mbedtls_mpi *x,
- mbedtls_ecp_point *X,
- const char *id,
- unsigned char **p,
- const unsigned char *end,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- size_t len;
-
- if( end < *p )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- /* Generate key (7.4.2.3.1) and write it out */
- MBEDTLS_MPI_CHK( mbedtls_ecp_gen_keypair_base( (mbedtls_ecp_group *) grp, G, x, X,
- f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_write_point( grp, X,
- pf, &len, *p, end - *p ) );
- *p += len;
-
- /* Generate and write proof */
- MBEDTLS_MPI_CHK( ecjpake_zkp_write( md_info, grp, pf, G, x, X, id,
- p, end, f_rng, p_rng ) );
-
-cleanup:
- return( ret );
-}
-
-/*
- * Read a ECJPAKEKeyKPPairList (7.4.2.3) and check proofs
- * Ouputs: verified peer public keys Xa, Xb
- */
-static int ecjpake_kkpp_read( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- mbedtls_ecp_point *Xa,
- mbedtls_ecp_point *Xb,
- const char *id,
- const unsigned char *buf,
- size_t len )
-{
- int ret;
- const unsigned char *p = buf;
- const unsigned char *end = buf + len;
-
- /*
- * struct {
- * ECJPAKEKeyKP ecjpake_key_kp_pair_list[2];
- * } ECJPAKEKeyKPPairList;
- */
- MBEDTLS_MPI_CHK( ecjpake_kkp_read( md_info, grp, pf, G, Xa, id, &p, end ) );
- MBEDTLS_MPI_CHK( ecjpake_kkp_read( md_info, grp, pf, G, Xb, id, &p, end ) );
-
- if( p != end )
- ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
-
-cleanup:
- return( ret );
-}
-
-/*
- * Generate a ECJPAKEKeyKPPairList
- * Outputs: the serialized structure, plus two private/public key pairs
- */
-static int ecjpake_kkpp_write( const mbedtls_md_info_t *md_info,
- const mbedtls_ecp_group *grp,
- const int pf,
- const mbedtls_ecp_point *G,
- mbedtls_mpi *xm1,
- mbedtls_ecp_point *Xa,
- mbedtls_mpi *xm2,
- mbedtls_ecp_point *Xb,
- const char *id,
- unsigned char *buf,
- size_t len,
- size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- unsigned char *p = buf;
- const unsigned char *end = buf + len;
-
- MBEDTLS_MPI_CHK( ecjpake_kkp_write( md_info, grp, pf, G, xm1, Xa, id,
- &p, end, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( ecjpake_kkp_write( md_info, grp, pf, G, xm2, Xb, id,
- &p, end, f_rng, p_rng ) );
-
- *olen = p - buf;
-
-cleanup:
- return( ret );
-}
-
-/*
- * Read and process the first round message
- */
-int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len )
-{
- return( ecjpake_kkpp_read( ctx->md_info, &ctx->grp, ctx->point_format,
- &ctx->grp.G,
- &ctx->Xp1, &ctx->Xp2, ID_PEER,
- buf, len ) );
-}
-
-/*
- * Generate and write the first round message
- */
-int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- return( ecjpake_kkpp_write( ctx->md_info, &ctx->grp, ctx->point_format,
- &ctx->grp.G,
- &ctx->xm1, &ctx->Xm1, &ctx->xm2, &ctx->Xm2,
- ID_MINE, buf, len, olen, f_rng, p_rng ) );
-}
-
-/*
- * Compute the sum of three points R = A + B + C
- */
-static int ecjpake_ecp_add3( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
- const mbedtls_ecp_point *A,
- const mbedtls_ecp_point *B,
- const mbedtls_ecp_point *C )
-{
- int ret;
- mbedtls_mpi one;
-
- mbedtls_mpi_init( &one );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &one, 1 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_muladd( grp, R, &one, A, &one, B ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_muladd( grp, R, &one, R, &one, C ) );
-
-cleanup:
- mbedtls_mpi_free( &one );
-
- return( ret );
-}
-
-/*
- * Read and process second round message (C: 7.4.2.5, S: 7.4.2.6)
- */
-int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len )
-{
- int ret;
- const unsigned char *p = buf;
- const unsigned char *end = buf + len;
- mbedtls_ecp_group grp;
- mbedtls_ecp_point G; /* C: GB, S: GA */
-
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &G );
-
- /*
- * Server: GA = X3 + X4 + X1 (7.4.2.6.1)
- * Client: GB = X1 + X2 + X3 (7.4.2.5.1)
- * Unified: G = Xm1 + Xm2 + Xp1
- * We need that before parsing in order to check Xp as we read it
- */
- MBEDTLS_MPI_CHK( ecjpake_ecp_add3( &ctx->grp, &G,
- &ctx->Xm1, &ctx->Xm2, &ctx->Xp1 ) );
-
- /*
- * struct {
- * ECParameters curve_params; // only client reading server msg
- * ECJPAKEKeyKP ecjpake_key_kp;
- * } Client/ServerECJPAKEParams;
- */
- if( ctx->role == MBEDTLS_ECJPAKE_CLIENT )
- {
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_group( &grp, &p, len ) );
- if( grp.id != ctx->grp.id )
- {
- ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
- goto cleanup;
- }
- }
-
- MBEDTLS_MPI_CHK( ecjpake_kkp_read( ctx->md_info, &ctx->grp,
- ctx->point_format,
- &G, &ctx->Xp, ID_PEER, &p, end ) );
-
- if( p != end )
- {
- ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
- goto cleanup;
- }
-
-cleanup:
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &G );
-
- return( ret );
-}
-
-/*
- * Compute R = +/- X * S mod N, taking care not to leak S
- */
-static int ecjpake_mul_secret( mbedtls_mpi *R, int sign,
- const mbedtls_mpi *X,
- const mbedtls_mpi *S,
- const mbedtls_mpi *N,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- mbedtls_mpi b; /* Blinding value, then s + N * blinding */
-
- mbedtls_mpi_init( &b );
-
- /* b = s + rnd-128-bit * N */
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &b, 16, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &b, &b, N ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &b, &b, S ) );
-
- /* R = sign * X * b mod N */
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( R, X, &b ) );
- R->s *= sign;
- MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( R, R, N ) );
-
-cleanup:
- mbedtls_mpi_free( &b );
-
- return( ret );
-}
-
-/*
- * Generate and write the second round message (S: 7.4.2.5, C: 7.4.2.6)
- */
-int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- mbedtls_ecp_point G; /* C: GA, S: GB */
- mbedtls_ecp_point Xm; /* C: Xc, S: Xs */
- mbedtls_mpi xm; /* C: xc, S: xs */
- unsigned char *p = buf;
- const unsigned char *end = buf + len;
- size_t ec_len;
-
- mbedtls_ecp_point_init( &G );
- mbedtls_ecp_point_init( &Xm );
- mbedtls_mpi_init( &xm );
-
- /*
- * First generate private/public key pair (S: 7.4.2.5.1, C: 7.4.2.6.1)
- *
- * Client: GA = X1 + X3 + X4 | xs = x2 * s | Xc = xc * GA
- * Server: GB = X3 + X1 + X2 | xs = x4 * s | Xs = xs * GB
- * Unified: G = Xm1 + Xp1 + Xp2 | xm = xm2 * s | Xm = xm * G
- */
- MBEDTLS_MPI_CHK( ecjpake_ecp_add3( &ctx->grp, &G,
- &ctx->Xp1, &ctx->Xp2, &ctx->Xm1 ) );
- MBEDTLS_MPI_CHK( ecjpake_mul_secret( &xm, 1, &ctx->xm2, &ctx->s,
- &ctx->grp.N, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &Xm, &xm, &G, f_rng, p_rng ) );
-
- /*
- * Now write things out
- *
- * struct {
- * ECParameters curve_params; // only server writing its message
- * ECJPAKEKeyKP ecjpake_key_kp;
- * } Client/ServerECJPAKEParams;
- */
- if( ctx->role == MBEDTLS_ECJPAKE_SERVER )
- {
- if( end < p )
- {
- ret = MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
- goto cleanup;
- }
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_write_group( &ctx->grp, &ec_len,
- p, end - p ) );
- p += ec_len;
- }
-
- if( end < p )
- {
- ret = MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
- goto cleanup;
- }
- MBEDTLS_MPI_CHK( mbedtls_ecp_tls_write_point( &ctx->grp, &Xm,
- ctx->point_format, &ec_len, p, end - p ) );
- p += ec_len;
-
- MBEDTLS_MPI_CHK( ecjpake_zkp_write( ctx->md_info, &ctx->grp,
- ctx->point_format,
- &G, &xm, &Xm, ID_MINE,
- &p, end, f_rng, p_rng ) );
-
- *olen = p - buf;
-
-cleanup:
- mbedtls_ecp_point_free( &G );
- mbedtls_ecp_point_free( &Xm );
- mbedtls_mpi_free( &xm );
-
- return( ret );
-}
-
-/*
- * Derive PMS (7.4.2.7 / 7.4.2.8)
- */
-int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
-{
- int ret;
- mbedtls_ecp_point K;
- mbedtls_mpi m_xm2_s, one;
- unsigned char kx[MBEDTLS_ECP_MAX_BYTES];
- size_t x_bytes;
-
- *olen = mbedtls_md_get_size( ctx->md_info );
- if( len < *olen )
- return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
-
- mbedtls_ecp_point_init( &K );
- mbedtls_mpi_init( &m_xm2_s );
- mbedtls_mpi_init( &one );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &one, 1 ) );
-
- /*
- * Client: K = ( Xs - X4 * x2 * s ) * x2
- * Server: K = ( Xc - X2 * x4 * s ) * x4
- * Unified: K = ( Xp - Xp2 * xm2 * s ) * xm2
- */
- MBEDTLS_MPI_CHK( ecjpake_mul_secret( &m_xm2_s, -1, &ctx->xm2, &ctx->s,
- &ctx->grp.N, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_muladd( &ctx->grp, &K,
- &one, &ctx->Xp,
- &m_xm2_s, &ctx->Xp2 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &K, &ctx->xm2, &K,
- f_rng, p_rng ) );
-
- /* PMS = SHA-256( K.X ) */
- x_bytes = ( ctx->grp.pbits + 7 ) / 8;
- MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &K.X, kx, x_bytes ) );
- MBEDTLS_MPI_CHK( mbedtls_md( ctx->md_info, kx, x_bytes, buf ) );
-
-cleanup:
- mbedtls_ecp_point_free( &K );
- mbedtls_mpi_free( &m_xm2_s );
- mbedtls_mpi_free( &one );
-
- return( ret );
-}
-
-#undef ID_MINE
-#undef ID_PEER
-
-
-#if defined(MBEDTLS_SELF_TEST)
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif
-
-#if !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
- !defined(MBEDTLS_SHA256_C)
-int mbedtls_ecjpake_self_test( int verbose )
-{
- (void) verbose;
- return( 0 );
-}
-#else
-
-static const unsigned char ecjpake_test_password[] = {
- 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, 0x61, 0x6b, 0x65, 0x74,
- 0x65, 0x73, 0x74
-};
-
-static const unsigned char ecjpake_test_x1[] = {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
- 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
- 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x21
-};
-
-static const unsigned char ecjpake_test_x2[] = {
- 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
- 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81
-};
-
-static const unsigned char ecjpake_test_x3[] = {
- 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
- 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81
-};
-
-static const unsigned char ecjpake_test_x4[] = {
- 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc,
- 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
- 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe1
-};
-
-static const unsigned char ecjpake_test_cli_one[] = {
- 0x41, 0x04, 0xac, 0xcf, 0x01, 0x06, 0xef, 0x85, 0x8f, 0xa2, 0xd9, 0x19,
- 0x33, 0x13, 0x46, 0x80, 0x5a, 0x78, 0xb5, 0x8b, 0xba, 0xd0, 0xb8, 0x44,
- 0xe5, 0xc7, 0x89, 0x28, 0x79, 0x14, 0x61, 0x87, 0xdd, 0x26, 0x66, 0xad,
- 0xa7, 0x81, 0xbb, 0x7f, 0x11, 0x13, 0x72, 0x25, 0x1a, 0x89, 0x10, 0x62,
- 0x1f, 0x63, 0x4d, 0xf1, 0x28, 0xac, 0x48, 0xe3, 0x81, 0xfd, 0x6e, 0xf9,
- 0x06, 0x07, 0x31, 0xf6, 0x94, 0xa4, 0x41, 0x04, 0x1d, 0xd0, 0xbd, 0x5d,
- 0x45, 0x66, 0xc9, 0xbe, 0xd9, 0xce, 0x7d, 0xe7, 0x01, 0xb5, 0xe8, 0x2e,
- 0x08, 0xe8, 0x4b, 0x73, 0x04, 0x66, 0x01, 0x8a, 0xb9, 0x03, 0xc7, 0x9e,
- 0xb9, 0x82, 0x17, 0x22, 0x36, 0xc0, 0xc1, 0x72, 0x8a, 0xe4, 0xbf, 0x73,
- 0x61, 0x0d, 0x34, 0xde, 0x44, 0x24, 0x6e, 0xf3, 0xd9, 0xc0, 0x5a, 0x22,
- 0x36, 0xfb, 0x66, 0xa6, 0x58, 0x3d, 0x74, 0x49, 0x30, 0x8b, 0xab, 0xce,
- 0x20, 0x72, 0xfe, 0x16, 0x66, 0x29, 0x92, 0xe9, 0x23, 0x5c, 0x25, 0x00,
- 0x2f, 0x11, 0xb1, 0x50, 0x87, 0xb8, 0x27, 0x38, 0xe0, 0x3c, 0x94, 0x5b,
- 0xf7, 0xa2, 0x99, 0x5d, 0xda, 0x1e, 0x98, 0x34, 0x58, 0x41, 0x04, 0x7e,
- 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62,
- 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, 0x9a, 0xc5,
- 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, 0xeb,
- 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, 0xc3, 0x35,
- 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0,
- 0x13, 0xbb, 0x2b, 0x41, 0x04, 0xa4, 0x95, 0x58, 0xd3, 0x2e, 0xd1, 0xeb,
- 0xfc, 0x18, 0x16, 0xaf, 0x4f, 0xf0, 0x9b, 0x55, 0xfc, 0xb4, 0xca, 0x47,
- 0xb2, 0xa0, 0x2d, 0x1e, 0x7c, 0xaf, 0x11, 0x79, 0xea, 0x3f, 0xe1, 0x39,
- 0x5b, 0x22, 0xb8, 0x61, 0x96, 0x40, 0x16, 0xfa, 0xba, 0xf7, 0x2c, 0x97,
- 0x56, 0x95, 0xd9, 0x3d, 0x4d, 0xf0, 0xe5, 0x19, 0x7f, 0xe9, 0xf0, 0x40,
- 0x63, 0x4e, 0xd5, 0x97, 0x64, 0x93, 0x77, 0x87, 0xbe, 0x20, 0xbc, 0x4d,
- 0xee, 0xbb, 0xf9, 0xb8, 0xd6, 0x0a, 0x33, 0x5f, 0x04, 0x6c, 0xa3, 0xaa,
- 0x94, 0x1e, 0x45, 0x86, 0x4c, 0x7c, 0xad, 0xef, 0x9c, 0xf7, 0x5b, 0x3d,
- 0x8b, 0x01, 0x0e, 0x44, 0x3e, 0xf0
-};
-
-static const unsigned char ecjpake_test_srv_one[] = {
- 0x41, 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb,
- 0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18,
- 0x40, 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47,
- 0x79, 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f,
- 0xd1, 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7,
- 0xe3, 0x2b, 0xb0, 0x13, 0xbb, 0x2b, 0x41, 0x04, 0x09, 0xf8, 0x5b, 0x3d,
- 0x20, 0xeb, 0xd7, 0x88, 0x5c, 0xe4, 0x64, 0xc0, 0x8d, 0x05, 0x6d, 0x64,
- 0x28, 0xfe, 0x4d, 0xd9, 0x28, 0x7a, 0xa3, 0x65, 0xf1, 0x31, 0xf4, 0x36,
- 0x0f, 0xf3, 0x86, 0xd8, 0x46, 0x89, 0x8b, 0xc4, 0xb4, 0x15, 0x83, 0xc2,
- 0xa5, 0x19, 0x7f, 0x65, 0xd7, 0x87, 0x42, 0x74, 0x6c, 0x12, 0xa5, 0xec,
- 0x0a, 0x4f, 0xfe, 0x2f, 0x27, 0x0a, 0x75, 0x0a, 0x1d, 0x8f, 0xb5, 0x16,
- 0x20, 0x93, 0x4d, 0x74, 0xeb, 0x43, 0xe5, 0x4d, 0xf4, 0x24, 0xfd, 0x96,
- 0x30, 0x6c, 0x01, 0x17, 0xbf, 0x13, 0x1a, 0xfa, 0xbf, 0x90, 0xa9, 0xd3,
- 0x3d, 0x11, 0x98, 0xd9, 0x05, 0x19, 0x37, 0x35, 0x14, 0x41, 0x04, 0x19,
- 0x0a, 0x07, 0x70, 0x0f, 0xfa, 0x4b, 0xe6, 0xae, 0x1d, 0x79, 0xee, 0x0f,
- 0x06, 0xae, 0xb5, 0x44, 0xcd, 0x5a, 0xdd, 0xaa, 0xbe, 0xdf, 0x70, 0xf8,
- 0x62, 0x33, 0x21, 0x33, 0x2c, 0x54, 0xf3, 0x55, 0xf0, 0xfb, 0xfe, 0xc7,
- 0x83, 0xed, 0x35, 0x9e, 0x5d, 0x0b, 0xf7, 0x37, 0x7a, 0x0f, 0xc4, 0xea,
- 0x7a, 0xce, 0x47, 0x3c, 0x9c, 0x11, 0x2b, 0x41, 0xcc, 0xd4, 0x1a, 0xc5,
- 0x6a, 0x56, 0x12, 0x41, 0x04, 0x36, 0x0a, 0x1c, 0xea, 0x33, 0xfc, 0xe6,
- 0x41, 0x15, 0x64, 0x58, 0xe0, 0xa4, 0xea, 0xc2, 0x19, 0xe9, 0x68, 0x31,
- 0xe6, 0xae, 0xbc, 0x88, 0xb3, 0xf3, 0x75, 0x2f, 0x93, 0xa0, 0x28, 0x1d,
- 0x1b, 0xf1, 0xfb, 0x10, 0x60, 0x51, 0xdb, 0x96, 0x94, 0xa8, 0xd6, 0xe8,
- 0x62, 0xa5, 0xef, 0x13, 0x24, 0xa3, 0xd9, 0xe2, 0x78, 0x94, 0xf1, 0xee,
- 0x4f, 0x7c, 0x59, 0x19, 0x99, 0x65, 0xa8, 0xdd, 0x4a, 0x20, 0x91, 0x84,
- 0x7d, 0x2d, 0x22, 0xdf, 0x3e, 0xe5, 0x5f, 0xaa, 0x2a, 0x3f, 0xb3, 0x3f,
- 0xd2, 0xd1, 0xe0, 0x55, 0xa0, 0x7a, 0x7c, 0x61, 0xec, 0xfb, 0x8d, 0x80,
- 0xec, 0x00, 0xc2, 0xc9, 0xeb, 0x12
-};
-
-static const unsigned char ecjpake_test_srv_two[] = {
- 0x03, 0x00, 0x17, 0x41, 0x04, 0x0f, 0xb2, 0x2b, 0x1d, 0x5d, 0x11, 0x23,
- 0xe0, 0xef, 0x9f, 0xeb, 0x9d, 0x8a, 0x2e, 0x59, 0x0a, 0x1f, 0x4d, 0x7c,
- 0xed, 0x2c, 0x2b, 0x06, 0x58, 0x6e, 0x8f, 0x2a, 0x16, 0xd4, 0xeb, 0x2f,
- 0xda, 0x43, 0x28, 0xa2, 0x0b, 0x07, 0xd8, 0xfd, 0x66, 0x76, 0x54, 0xca,
- 0x18, 0xc5, 0x4e, 0x32, 0xa3, 0x33, 0xa0, 0x84, 0x54, 0x51, 0xe9, 0x26,
- 0xee, 0x88, 0x04, 0xfd, 0x7a, 0xf0, 0xaa, 0xa7, 0xa6, 0x41, 0x04, 0x55,
- 0x16, 0xea, 0x3e, 0x54, 0xa0, 0xd5, 0xd8, 0xb2, 0xce, 0x78, 0x6b, 0x38,
- 0xd3, 0x83, 0x37, 0x00, 0x29, 0xa5, 0xdb, 0xe4, 0x45, 0x9c, 0x9d, 0xd6,
- 0x01, 0xb4, 0x08, 0xa2, 0x4a, 0xe6, 0x46, 0x5c, 0x8a, 0xc9, 0x05, 0xb9,
- 0xeb, 0x03, 0xb5, 0xd3, 0x69, 0x1c, 0x13, 0x9e, 0xf8, 0x3f, 0x1c, 0xd4,
- 0x20, 0x0f, 0x6c, 0x9c, 0xd4, 0xec, 0x39, 0x22, 0x18, 0xa5, 0x9e, 0xd2,
- 0x43, 0xd3, 0xc8, 0x20, 0xff, 0x72, 0x4a, 0x9a, 0x70, 0xb8, 0x8c, 0xb8,
- 0x6f, 0x20, 0xb4, 0x34, 0xc6, 0x86, 0x5a, 0xa1, 0xcd, 0x79, 0x06, 0xdd,
- 0x7c, 0x9b, 0xce, 0x35, 0x25, 0xf5, 0x08, 0x27, 0x6f, 0x26, 0x83, 0x6c
-};
-
-static const unsigned char ecjpake_test_cli_two[] = {
- 0x41, 0x04, 0x69, 0xd5, 0x4e, 0xe8, 0x5e, 0x90, 0xce, 0x3f, 0x12, 0x46,
- 0x74, 0x2d, 0xe5, 0x07, 0xe9, 0x39, 0xe8, 0x1d, 0x1d, 0xc1, 0xc5, 0xcb,
- 0x98, 0x8b, 0x58, 0xc3, 0x10, 0xc9, 0xfd, 0xd9, 0x52, 0x4d, 0x93, 0x72,
- 0x0b, 0x45, 0x54, 0x1c, 0x83, 0xee, 0x88, 0x41, 0x19, 0x1d, 0xa7, 0xce,
- 0xd8, 0x6e, 0x33, 0x12, 0xd4, 0x36, 0x23, 0xc1, 0xd6, 0x3e, 0x74, 0x98,
- 0x9a, 0xba, 0x4a, 0xff, 0xd1, 0xee, 0x41, 0x04, 0x07, 0x7e, 0x8c, 0x31,
- 0xe2, 0x0e, 0x6b, 0xed, 0xb7, 0x60, 0xc1, 0x35, 0x93, 0xe6, 0x9f, 0x15,
- 0xbe, 0x85, 0xc2, 0x7d, 0x68, 0xcd, 0x09, 0xcc, 0xb8, 0xc4, 0x18, 0x36,
- 0x08, 0x91, 0x7c, 0x5c, 0x3d, 0x40, 0x9f, 0xac, 0x39, 0xfe, 0xfe, 0xe8,
- 0x2f, 0x72, 0x92, 0xd3, 0x6f, 0x0d, 0x23, 0xe0, 0x55, 0x91, 0x3f, 0x45,
- 0xa5, 0x2b, 0x85, 0xdd, 0x8a, 0x20, 0x52, 0xe9, 0xe1, 0x29, 0xbb, 0x4d,
- 0x20, 0x0f, 0x01, 0x1f, 0x19, 0x48, 0x35, 0x35, 0xa6, 0xe8, 0x9a, 0x58,
- 0x0c, 0x9b, 0x00, 0x03, 0xba, 0xf2, 0x14, 0x62, 0xec, 0xe9, 0x1a, 0x82,
- 0xcc, 0x38, 0xdb, 0xdc, 0xae, 0x60, 0xd9, 0xc5, 0x4c
-};
-
-static const unsigned char ecjpake_test_pms[] = {
- 0xf3, 0xd4, 0x7f, 0x59, 0x98, 0x44, 0xdb, 0x92, 0xa5, 0x69, 0xbb, 0xe7,
- 0x98, 0x1e, 0x39, 0xd9, 0x31, 0xfd, 0x74, 0x3b, 0xf2, 0x2e, 0x98, 0xf9,
- 0xb4, 0x38, 0xf7, 0x19, 0xd3, 0xc4, 0xf3, 0x51
-};
-
-/* Load my private keys and generate the correponding public keys */
-static int ecjpake_test_load( mbedtls_ecjpake_context *ctx,
- const unsigned char *xm1, size_t len1,
- const unsigned char *xm2, size_t len2 )
-{
- int ret;
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm1, xm1, len1 ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->xm2, xm2, len2 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &ctx->Xm1, &ctx->xm1,
- &ctx->grp.G, NULL, NULL ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &ctx->grp, &ctx->Xm2, &ctx->xm2,
- &ctx->grp.G, NULL, NULL ) );
-
-cleanup:
- return( ret );
-}
-
-/* For tests we don't need a secure RNG;
- * use the LGC from Numerical Recipes for simplicity */
-static int ecjpake_lgc( void *p, unsigned char *out, size_t len )
-{
- static uint32_t x = 42;
- (void) p;
-
- while( len > 0 )
- {
- size_t use_len = len > 4 ? 4 : len;
- x = 1664525 * x + 1013904223;
- memcpy( out, &x, use_len );
- out += use_len;
- len -= use_len;
- }
-
- return( 0 );
-}
-
-#define TEST_ASSERT( x ) \
- do { \
- if( x ) \
- ret = 0; \
- else \
- { \
- ret = 1; \
- goto cleanup; \
- } \
- } while( 0 )
-
-/*
- * Checkup routine
- */
-int mbedtls_ecjpake_self_test( int verbose )
-{
- int ret;
- mbedtls_ecjpake_context cli;
- mbedtls_ecjpake_context srv;
- unsigned char buf[512], pms[32];
- size_t len, pmslen;
-
- mbedtls_ecjpake_init( &cli );
- mbedtls_ecjpake_init( &srv );
-
- if( verbose != 0 )
- mbedtls_printf( " ECJPAKE test #0 (setup): " );
-
- TEST_ASSERT( mbedtls_ecjpake_setup( &cli, MBEDTLS_ECJPAKE_CLIENT,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1,
- ecjpake_test_password,
- sizeof( ecjpake_test_password ) ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_setup( &srv, MBEDTLS_ECJPAKE_SERVER,
- MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1,
- ecjpake_test_password,
- sizeof( ecjpake_test_password ) ) == 0 );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " ECJPAKE test #1 (random handshake): " );
-
- TEST_ASSERT( mbedtls_ecjpake_write_round_one( &cli,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_one( &srv, buf, len ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_write_round_one( &srv,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_one( &cli, buf, len ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_write_round_two( &srv,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &cli, buf, len ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_derive_secret( &cli,
- pms, sizeof( pms ), &pmslen, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_write_round_two( &cli,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &srv, buf, len ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_derive_secret( &srv,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( len == pmslen );
- TEST_ASSERT( memcmp( buf, pms, len ) == 0 );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " ECJPAKE test #2 (reference handshake): " );
-
- /* Simulate generation of round one */
- MBEDTLS_MPI_CHK( ecjpake_test_load( &cli,
- ecjpake_test_x1, sizeof( ecjpake_test_x1 ),
- ecjpake_test_x2, sizeof( ecjpake_test_x2 ) ) );
-
- MBEDTLS_MPI_CHK( ecjpake_test_load( &srv,
- ecjpake_test_x3, sizeof( ecjpake_test_x3 ),
- ecjpake_test_x4, sizeof( ecjpake_test_x4 ) ) );
-
- /* Read round one */
- TEST_ASSERT( mbedtls_ecjpake_read_round_one( &srv,
- ecjpake_test_cli_one,
- sizeof( ecjpake_test_cli_one ) ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_one( &cli,
- ecjpake_test_srv_one,
- sizeof( ecjpake_test_srv_one ) ) == 0 );
-
- /* Skip generation of round two, read round two */
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &cli,
- ecjpake_test_srv_two,
- sizeof( ecjpake_test_srv_two ) ) == 0 );
-
- TEST_ASSERT( mbedtls_ecjpake_read_round_two( &srv,
- ecjpake_test_cli_two,
- sizeof( ecjpake_test_cli_two ) ) == 0 );
-
- /* Server derives PMS */
- TEST_ASSERT( mbedtls_ecjpake_derive_secret( &srv,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( len == sizeof( ecjpake_test_pms ) );
- TEST_ASSERT( memcmp( buf, ecjpake_test_pms, len ) == 0 );
-
- memset( buf, 0, len ); /* Avoid interferences with next step */
-
- /* Client derives PMS */
- TEST_ASSERT( mbedtls_ecjpake_derive_secret( &cli,
- buf, sizeof( buf ), &len, ecjpake_lgc, NULL ) == 0 );
-
- TEST_ASSERT( len == sizeof( ecjpake_test_pms ) );
- TEST_ASSERT( memcmp( buf, ecjpake_test_pms, len ) == 0 );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-cleanup:
- mbedtls_ecjpake_free( &cli );
- mbedtls_ecjpake_free( &srv );
-
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( ret );
-}
-
-#undef TEST_ASSERT
-
-#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED && MBEDTLS_SHA256_C */
-
-#endif /* MBEDTLS_SELF_TEST */
-
-#endif /* MBEDTLS_ECJPAKE_C */
diff --git a/deps/mbedtls/ecp.c b/deps/mbedtls/ecp.c
index 71f4e2fcb6..8de5b61705 100644
--- a/deps/mbedtls/ecp.c
+++ b/deps/mbedtls/ecp.c
@@ -55,33 +55,15 @@
#if !defined(MBEDTLS_ECP_ALT)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+
+#include
#include "mbedtls/ecp_internal.h"
-#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
-#define inline __inline
-#endif
-
#include "arc4_alt.h"
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * Counts of point addition and doubling, and field multiplications.
- * Used to test resistance of point multiplication to simple timing attacks.
- */
-static unsigned long add_count, dbl_count, mul_count;
-#endif
-
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
@@ -339,7 +321,7 @@ void mbedtls_ecp_group_free( mbedtls_ecp_group *grp )
{
for( i = 0; i < grp->T_size; i++ )
mbedtls_ecp_point_free( &grp->T[i] );
- mbedtls_free( grp->T );
+ free( grp->T );
}
mbedtls_zeroize( grp, sizeof( mbedtls_ecp_group ) );
@@ -702,11 +684,7 @@ cleanup:
/*
* Reduce a mbedtls_mpi mod p in-place, general case, to use after mbedtls_mpi_mul_mpi
*/
-#if defined(MBEDTLS_SELF_TEST)
-#define INC_MUL_COUNT mul_count++;
-#else
#define INC_MUL_COUNT
-#endif
#define MOD_MUL( N ) do { MBEDTLS_MPI_CHK( ecp_modp( &N, grp ) ); INC_MUL_COUNT } \
while( 0 )
@@ -810,7 +788,7 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
}
#endif
- if( ( c = (mbedtls_mpi*)mbedtls_calloc( t_len, sizeof( mbedtls_mpi ) ) ) == NULL )
+ if( ( c = (mbedtls_mpi*)calloc( t_len, sizeof( mbedtls_mpi ) ) ) == NULL )
return( MBEDTLS_ERR_ECP_ALLOC_FAILED );
mbedtls_mpi_init( &u ); mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi );
@@ -872,7 +850,7 @@ cleanup:
mbedtls_mpi_free( &u ); mbedtls_mpi_free( &Zi ); mbedtls_mpi_free( &ZZi );
for( i = 0; i < t_len; i++ )
mbedtls_mpi_free( &c[i] );
- mbedtls_free( c );
+ free( c );
return( ret );
}
@@ -922,10 +900,6 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
int ret;
mbedtls_mpi M, S, T, U;
-#if defined(MBEDTLS_SELF_TEST)
- dbl_count++;
-#endif
-
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
if ( mbedtls_internal_ecp_grp_capable( grp ) )
{
@@ -1020,10 +994,6 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
int ret;
mbedtls_mpi T1, T2, T3, T4, X, Y, Z;
-#if defined(MBEDTLS_SELF_TEST)
- add_count++;
-#endif
-
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
if ( mbedtls_internal_ecp_grp_capable( grp ) )
{
@@ -1405,7 +1375,7 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
if( T == NULL )
{
- T = (mbedtls_ecp_point*)mbedtls_calloc( pre_len, sizeof( mbedtls_ecp_point ) );
+ T = (mbedtls_ecp_point*)calloc( pre_len, sizeof( mbedtls_ecp_point ) );
if( T == NULL )
{
ret = MBEDTLS_ERR_ECP_ALLOC_FAILED;
@@ -1448,7 +1418,7 @@ cleanup:
{
for( i = 0; i < pre_len; i++ )
mbedtls_ecp_point_free( &T[i] );
- mbedtls_free( T );
+ free( T );
}
mbedtls_mpi_free( &M );
@@ -2057,137 +2027,6 @@ cleanup:
return( ret );
}
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * Checkup routine
- */
-int mbedtls_ecp_self_test( int verbose )
-{
- int ret;
- size_t i;
- mbedtls_ecp_group grp;
- mbedtls_ecp_point R, P;
- mbedtls_mpi m;
- unsigned long add_c_prev, dbl_c_prev, mul_c_prev;
- /* exponents especially adapted for secp192r1 */
- const char *exponents[] =
- {
- "000000000000000000000000000000000000000000000001", /* one */
- "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22830", /* N - 1 */
- "5EA6F389A38B8BC81E767753B15AA5569E1782E30ABE7D25", /* random */
- "400000000000000000000000000000000000000000000000", /* one and zeros */
- "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", /* all ones */
- "555555555555555555555555555555555555555555555555", /* 101010... */
- };
-
- mbedtls_ecp_group_init( &grp );
- mbedtls_ecp_point_init( &R );
- mbedtls_ecp_point_init( &P );
- mbedtls_mpi_init( &m );
-
- /* Use secp192r1 if available, or any available curve */
-#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
- MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &grp, MBEDTLS_ECP_DP_SECP192R1 ) );
-#else
- MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &grp, mbedtls_ecp_curve_list()->grp_id ) );
-#endif
-
- if( verbose != 0 )
- mbedtls_printf( " ECP test #1 (constant op_count, base point G): " );
-
- /* Do a dummy multiplication first to trigger precomputation */
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &m, 2 ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &P, &m, &grp.G, NULL, NULL ) );
-
- add_count = 0;
- dbl_count = 0;
- mul_count = 0;
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[0] ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL ) );
-
- for( i = 1; i < sizeof( exponents ) / sizeof( exponents[0] ); i++ )
- {
- add_c_prev = add_count;
- dbl_c_prev = dbl_count;
- mul_c_prev = mul_count;
- add_count = 0;
- dbl_count = 0;
- mul_count = 0;
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[i] ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL ) );
-
- if( add_count != add_c_prev ||
- dbl_count != dbl_c_prev ||
- mul_count != mul_c_prev )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed (%u)\n", (unsigned int) i );
-
- ret = 1;
- goto cleanup;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " ECP test #2 (constant op_count, other point): " );
- /* We computed P = 2G last time, use it */
-
- add_count = 0;
- dbl_count = 0;
- mul_count = 0;
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[0] ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &P, NULL, NULL ) );
-
- for( i = 1; i < sizeof( exponents ) / sizeof( exponents[0] ); i++ )
- {
- add_c_prev = add_count;
- dbl_c_prev = dbl_count;
- mul_c_prev = mul_count;
- add_count = 0;
- dbl_count = 0;
- mul_count = 0;
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &m, 16, exponents[i] ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_mul( &grp, &R, &m, &P, NULL, NULL ) );
-
- if( add_count != add_c_prev ||
- dbl_count != dbl_c_prev ||
- mul_count != mul_c_prev )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed (%u)\n", (unsigned int) i );
-
- ret = 1;
- goto cleanup;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-cleanup:
-
- if( ret < 0 && verbose != 0 )
- mbedtls_printf( "Unexpected error, return code = %08X\n", ret );
-
- mbedtls_ecp_group_free( &grp );
- mbedtls_ecp_point_free( &R );
- mbedtls_ecp_point_free( &P );
- mbedtls_mpi_free( &m );
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* !MBEDTLS_ECP_ALT */
#endif /* MBEDTLS_ECP_C */
diff --git a/deps/mbedtls/entropy.c b/deps/mbedtls/entropy.c
index 75e2ea7389..f91db91b10 100644
--- a/deps/mbedtls/entropy.c
+++ b/deps/mbedtls/entropy.c
@@ -27,12 +27,6 @@
#if defined(MBEDTLS_ENTROPY_C)
-#if defined(MBEDTLS_TEST_NULL_ENTROPY)
-#warning "**** WARNING! MBEDTLS_TEST_NULL_ENTROPY defined! "
-#warning "**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES "
-#warning "**** THIS BUILD IS *NOT* SUITABLE FOR PRODUCTION USE "
-#endif
-
#include "mbedtls/entropy.h"
#include "mbedtls/entropy_poll.h"
@@ -42,23 +36,6 @@
#include
#endif
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-#include "mbedtls/platform.h"
-#endif
-
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
-#if defined(MBEDTLS_HAVEGE_C)
-#include "mbedtls/havege.h"
-#endif
-
#include "arc4_alt.h"
#define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */
@@ -76,49 +53,24 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
#else
mbedtls_sha256_starts( &ctx->accumulator, 0 );
#endif
-#if defined(MBEDTLS_HAVEGE_C)
- mbedtls_havege_init( &ctx->havege_data );
-#endif
-#if defined(MBEDTLS_TEST_NULL_ENTROPY)
- mbedtls_entropy_add_source( ctx, mbedtls_null_entropy_poll, NULL,
- 1, MBEDTLS_ENTROPY_SOURCE_STRONG );
-#endif
-
-#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
-#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
mbedtls_entropy_add_source( ctx, mbedtls_platform_entropy_poll, NULL,
MBEDTLS_ENTROPY_MIN_PLATFORM,
MBEDTLS_ENTROPY_SOURCE_STRONG );
-#endif
#if defined(MBEDTLS_TIMING_C)
mbedtls_entropy_add_source( ctx, mbedtls_hardclock_poll, NULL,
MBEDTLS_ENTROPY_MIN_HARDCLOCK,
MBEDTLS_ENTROPY_SOURCE_WEAK );
#endif
-#if defined(MBEDTLS_HAVEGE_C)
- mbedtls_entropy_add_source( ctx, mbedtls_havege_poll, &ctx->havege_data,
- MBEDTLS_ENTROPY_MIN_HAVEGE,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
-#endif
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
mbedtls_entropy_add_source( ctx, mbedtls_hardware_poll, NULL,
MBEDTLS_ENTROPY_MIN_HARDWARE,
MBEDTLS_ENTROPY_SOURCE_STRONG );
#endif
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
- mbedtls_entropy_add_source( ctx, mbedtls_nv_seed_poll, NULL,
- MBEDTLS_ENTROPY_BLOCK_SIZE,
- MBEDTLS_ENTROPY_SOURCE_STRONG );
-#endif
-#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
}
void mbedtls_entropy_free( mbedtls_entropy_context *ctx )
{
-#if defined(MBEDTLS_HAVEGE_C)
- mbedtls_havege_free( &ctx->havege_data );
-#endif
#if defined(MBEDTLS_THREADING_C)
mbedtls_mutex_free( &ctx->mutex );
#endif
@@ -289,18 +241,6 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len )
if( len > MBEDTLS_ENTROPY_BLOCK_SIZE )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
- /* Update the NV entropy seed before generating any entropy for outside
- * use.
- */
- if( ctx->initial_entropy_run == 0 )
- {
- ctx->initial_entropy_run = 1;
- if( ( ret = mbedtls_entropy_update_nv_seed( ctx ) ) != 0 )
- return( ret );
- }
-#endif
-
#if defined(MBEDTLS_THREADING_C)
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
return( ret );
@@ -375,27 +315,6 @@ exit:
return( ret );
}
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx )
-{
- int ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
- unsigned char buf[ MBEDTLS_ENTROPY_MAX_SEED_SIZE ];
-
- /* Read new seed and write it to NV */
- if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 )
- return( ret );
-
- if( mbedtls_nv_seed_write( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 )
- return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR );
-
- /* Manually update the remaining stream with a separator value to diverge */
- memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
- mbedtls_entropy_update_manual( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE );
-
- return( 0 );
-}
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
-
#if defined(MBEDTLS_FS_IO)
int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path )
{
@@ -452,201 +371,4 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *
}
#endif /* MBEDTLS_FS_IO */
-#if defined(MBEDTLS_SELF_TEST)
-#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
-/*
- * Dummy source function
- */
-static int entropy_dummy_source( void *data, unsigned char *output,
- size_t len, size_t *olen )
-{
- ((void) data);
-
- memset( output, 0x2a, len );
- *olen = len;
-
- return( 0 );
-}
-#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
-
-#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
-
-static int mbedtls_entropy_source_self_test_gather( unsigned char *buf, size_t buf_len )
-{
- int ret = 0;
- size_t entropy_len = 0;
- size_t olen = 0;
- size_t attempts = buf_len;
-
- while( attempts > 0 && entropy_len < buf_len )
- {
- if( ( ret = mbedtls_hardware_poll( NULL, buf + entropy_len,
- buf_len - entropy_len, &olen ) ) != 0 )
- return( ret );
-
- entropy_len += olen;
- attempts--;
- }
-
- if( entropy_len < buf_len )
- {
- ret = 1;
- }
-
- return( ret );
-}
-
-
-static int mbedtls_entropy_source_self_test_check_bits( const unsigned char *buf,
- size_t buf_len )
-{
- unsigned char set= 0xFF;
- unsigned char unset = 0x00;
- size_t i;
-
- for( i = 0; i < buf_len; i++ )
- {
- set &= buf[i];
- unset |= buf[i];
- }
-
- return( set == 0xFF || unset == 0x00 );
-}
-
-/*
- * A test to ensure hat the entropy sources are functioning correctly
- * and there is no obvious failure. The test performs the following checks:
- * - The entropy source is not providing only 0s (all bits unset) or 1s (all
- * bits set).
- * - The entropy source is not providing values in a pattern. Because the
- * hardware could be providing data in an arbitrary length, this check polls
- * the hardware entropy source twice and compares the result to ensure they
- * are not equal.
- * - The error code returned by the entropy source is not an error.
- */
-int mbedtls_entropy_source_self_test( int verbose )
-{
- int ret = 0;
- unsigned char buf0[2 * sizeof( unsigned long long int )];
- unsigned char buf1[2 * sizeof( unsigned long long int )];
-
- if( verbose != 0 )
- mbedtls_printf( " ENTROPY_BIAS test: " );
-
- memset( buf0, 0x00, sizeof( buf0 ) );
- memset( buf1, 0x00, sizeof( buf1 ) );
-
- if( ( ret = mbedtls_entropy_source_self_test_gather( buf0, sizeof( buf0 ) ) ) != 0 )
- goto cleanup;
- if( ( ret = mbedtls_entropy_source_self_test_gather( buf1, sizeof( buf1 ) ) ) != 0 )
- goto cleanup;
-
- /* Make sure that the returned values are not all 0 or 1 */
- if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf0, sizeof( buf0 ) ) ) != 0 )
- goto cleanup;
- if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf1, sizeof( buf1 ) ) ) != 0 )
- goto cleanup;
-
- /* Make sure that the entropy source is not returning values in a
- * pattern */
- ret = memcmp( buf0, buf1, sizeof( buf0 ) ) == 0;
-
-cleanup:
- if( verbose != 0 )
- {
- if( ret != 0 )
- mbedtls_printf( "failed\n" );
- else
- mbedtls_printf( "passed\n" );
-
- mbedtls_printf( "\n" );
- }
-
- return( ret != 0 );
-}
-
-#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
-
-/*
- * The actual entropy quality is hard to test, but we can at least
- * test that the functions don't cause errors and write the correct
- * amount of data to buffers.
- */
-int mbedtls_entropy_self_test( int verbose )
-{
- int ret = 1;
-#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
- mbedtls_entropy_context ctx;
- unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
- unsigned char acc[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
- size_t i, j;
-#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
-
- if( verbose != 0 )
- mbedtls_printf( " ENTROPY test: " );
-
-#if !defined(MBEDTLS_TEST_NULL_ENTROPY)
- mbedtls_entropy_init( &ctx );
-
- /* First do a gather to make sure we have default sources */
- if( ( ret = mbedtls_entropy_gather( &ctx ) ) != 0 )
- goto cleanup;
-
- ret = mbedtls_entropy_add_source( &ctx, entropy_dummy_source, NULL, 16,
- MBEDTLS_ENTROPY_SOURCE_WEAK );
- if( ret != 0 )
- goto cleanup;
-
- if( ( ret = mbedtls_entropy_update_manual( &ctx, buf, sizeof buf ) ) != 0 )
- goto cleanup;
-
- /*
- * To test that mbedtls_entropy_func writes correct number of bytes:
- * - use the whole buffer and rely on ASan to detect overruns
- * - collect entropy 8 times and OR the result in an accumulator:
- * any byte should then be 0 with probably 2^(-64), so requiring
- * each of the 32 or 64 bytes to be non-zero has a false failure rate
- * of at most 2^(-58) which is acceptable.
- */
- for( i = 0; i < 8; i++ )
- {
- if( ( ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ) ) != 0 )
- goto cleanup;
-
- for( j = 0; j < sizeof( buf ); j++ )
- acc[j] |= buf[j];
- }
-
- for( j = 0; j < sizeof( buf ); j++ )
- {
- if( acc[j] == 0 )
- {
- ret = 1;
- goto cleanup;
- }
- }
-
-#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- if( ( ret = mbedtls_entropy_source_self_test( 0 ) ) != 0 )
- goto cleanup;
-#endif
-
-cleanup:
- mbedtls_entropy_free( &ctx );
-#endif /* !MBEDTLS_TEST_NULL_ENTROPY */
-
- if( verbose != 0 )
- {
- if( ret != 0 )
- mbedtls_printf( "failed\n" );
- else
- mbedtls_printf( "passed\n" );
-
- mbedtls_printf( "\n" );
- }
-
- return( ret != 0 );
-}
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_ENTROPY_C */
diff --git a/deps/mbedtls/entropy_poll.c b/deps/mbedtls/entropy_poll.c
index 7d0d9450ea..2b9ad1293f 100644
--- a/deps/mbedtls/entropy_poll.c
+++ b/deps/mbedtls/entropy_poll.c
@@ -34,14 +34,6 @@
#include
#include "mbedtls/timing.h"
#endif
-#if defined(MBEDTLS_HAVEGE_C)
-#include "mbedtls/havege.h"
-#endif
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-#include "mbedtls/platform.h"
-#endif
-
-#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) && !defined(__HAIKU__)
@@ -56,8 +48,9 @@
#include
#include
-int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len,
- size_t *olen )
+int mbedtls_platform_entropy_poll(
+ void *data, unsigned char *output, size_t len,
+ size_t *olen )
{
HCRYPTPROV provider;
((void) data);
@@ -65,9 +58,7 @@ int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len
if( CryptAcquireContext( &provider, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE )
- {
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
- }
if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE )
{
@@ -189,24 +180,6 @@ int mbedtls_platform_entropy_poll( void *data,
return( 0 );
}
#endif /* _WIN32 && !EFIX64 && !EFI32 */
-#endif /* !MBEDTLS_NO_PLATFORM_ENTROPY */
-
-#if defined(MBEDTLS_TEST_NULL_ENTROPY)
-int mbedtls_null_entropy_poll( void *data,
- unsigned char *output, size_t len, size_t *olen )
-{
- ((void) data);
- ((void) output);
- *olen = 0;
-
- if( len < sizeof(unsigned char) )
- return( 0 );
-
- *olen = sizeof(unsigned char);
-
- return( 0 );
-}
-#endif
#if defined(MBEDTLS_TIMING_C)
int mbedtls_hardclock_poll( void *data,
@@ -226,43 +199,4 @@ int mbedtls_hardclock_poll( void *data,
}
#endif /* MBEDTLS_TIMING_C */
-#if defined(MBEDTLS_HAVEGE_C)
-int mbedtls_havege_poll( void *data,
- unsigned char *output, size_t len, size_t *olen )
-{
- mbedtls_havege_state *hs = (mbedtls_havege_state *) data;
- *olen = 0;
-
- if( mbedtls_havege_random( hs, output, len ) != 0 )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
-
- *olen = len;
-
- return( 0 );
-}
-#endif /* MBEDTLS_HAVEGE_C */
-
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-int mbedtls_nv_seed_poll( void *data,
- unsigned char *output, size_t len, size_t *olen )
-{
- unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
- size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE;
- ((void) data);
-
- memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
-
- if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 )
- return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
-
- if( len < use_len )
- use_len = len;
-
- memcpy( output, buf, use_len );
- *olen = use_len;
-
- return( 0 );
-}
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
-
#endif /* MBEDTLS_ENTROPY_C */
diff --git a/deps/mbedtls/error.c b/deps/mbedtls/error.c
deleted file mode 100644
index 9f4f7c752a..0000000000
--- a/deps/mbedtls/error.c
+++ /dev/null
@@ -1,707 +0,0 @@
-/*
- * Error message information
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
-#include "mbedtls/error.h"
-#include
-#endif
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#define mbedtls_snprintf snprintf
-#define mbedtls_time_t time_t
-#endif
-
-#if defined(MBEDTLS_ERROR_C)
-
-#include
-
-#if defined(MBEDTLS_AES_C)
-#include "mbedtls/aes.h"
-#endif
-
-#if defined(MBEDTLS_BASE64_C)
-#include "mbedtls/base64.h"
-#endif
-
-#if defined(MBEDTLS_BIGNUM_C)
-#include "mbedtls/bignum.h"
-#endif
-
-#if defined(MBEDTLS_BLOWFISH_C)
-#include "mbedtls/blowfish.h"
-#endif
-
-#if defined(MBEDTLS_CAMELLIA_C)
-#include "mbedtls/camellia.h"
-#endif
-
-#if defined(MBEDTLS_CCM_C)
-#include "mbedtls/ccm.h"
-#endif
-
-#if defined(MBEDTLS_CIPHER_C)
-#include "mbedtls/cipher.h"
-#endif
-
-#if defined(MBEDTLS_CTR_DRBG_C)
-#include "mbedtls/ctr_drbg.h"
-#endif
-
-#if defined(MBEDTLS_DES_C)
-#include "mbedtls/des.h"
-#endif
-
-#if defined(MBEDTLS_DHM_C)
-#include "mbedtls/dhm.h"
-#endif
-
-#if defined(MBEDTLS_ECP_C)
-#include "mbedtls/ecp.h"
-#endif
-
-#if defined(MBEDTLS_ENTROPY_C)
-#include "mbedtls/entropy.h"
-#endif
-
-#if defined(MBEDTLS_GCM_C)
-#include "mbedtls/gcm.h"
-#endif
-
-#if defined(MBEDTLS_HMAC_DRBG_C)
-#include "mbedtls/hmac_drbg.h"
-#endif
-
-#if defined(MBEDTLS_MD_C)
-#include "mbedtls/md.h"
-#endif
-
-#if defined(MBEDTLS_NET_C)
-#include "mbedtls/net_sockets.h"
-#endif
-
-#if defined(MBEDTLS_OID_C)
-#include "mbedtls/oid.h"
-#endif
-
-#if defined(MBEDTLS_PADLOCK_C)
-#include "mbedtls/padlock.h"
-#endif
-
-#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
-#include "mbedtls/pem.h"
-#endif
-
-#if defined(MBEDTLS_PK_C)
-#include "mbedtls/pk.h"
-#endif
-
-#if defined(MBEDTLS_PKCS12_C)
-#include "mbedtls/pkcs12.h"
-#endif
-
-#if defined(MBEDTLS_PKCS5_C)
-#include "mbedtls/pkcs5.h"
-#endif
-
-#if defined(MBEDTLS_RSA_C)
-#include "mbedtls/rsa.h"
-#endif
-
-#if defined(MBEDTLS_SSL_TLS_C)
-#include "mbedtls/ssl.h"
-#endif
-
-#if defined(MBEDTLS_THREADING_C)
-#include "mbedtls/threading.h"
-#endif
-
-#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
-#include "mbedtls/x509.h"
-#endif
-
-#if defined(MBEDTLS_XTEA_C)
-#include "mbedtls/xtea.h"
-#endif
-
-
-void mbedtls_strerror( int ret, char *buf, size_t buflen )
-{
- size_t len;
- int use_ret;
-
- if( buflen == 0 )
- return;
-
- memset( buf, 0x00, buflen );
-
- if( ret < 0 )
- ret = -ret;
-
- if( ret & 0xFF80 )
- {
- use_ret = ret & 0xFF80;
-
- /* High level error codes
- *
- * BEGIN generated code */
-#if defined(MBEDTLS_CIPHER_C)
- if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
- mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
- mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
- mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
- if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
- mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" );
-#endif /* MBEDTLS_CIPHER_C */
-
-#if defined(MBEDTLS_DHM_C)
- if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
- mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
- if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
- if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
-#endif /* MBEDTLS_DHM_C */
-
-#if defined(MBEDTLS_ECP_C)
- if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
- if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
- if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
- mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
- if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
- if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
- mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
- if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
- mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
- if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
-#endif /* MBEDTLS_ECP_C */
-
-#if defined(MBEDTLS_MD_C)
- if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
- if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
- if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
-#endif /* MBEDTLS_MD_C */
-
-#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
- if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
- mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
- if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
- mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
- if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
- if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
- mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
- if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
- mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
- if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
- if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
- if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
- if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
-#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
-
-#if defined(MBEDTLS_PK_C)
- if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
- if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
- if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
- if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
- mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
- if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
- mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
- if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
- mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
- if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
- if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
- if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
- mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
- if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
- mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
- mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
- if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
- if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
-#endif /* MBEDTLS_PK_C */
-
-#if defined(MBEDTLS_PKCS12_C)
- if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
- if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
- mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
- if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
-#endif /* MBEDTLS_PKCS12_C */
-
-#if defined(MBEDTLS_PKCS5_C)
- if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
- mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
- if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
- if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
-#endif /* MBEDTLS_PKCS5_C */
-
-#if defined(MBEDTLS_RSA_C)
- if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
- mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
- if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
- if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
- if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
- if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
- if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
- if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
- mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
- if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
- mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
-#endif /* MBEDTLS_RSA_C */
-
-#if defined(MBEDTLS_SSL_TLS_C)
- if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
- mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
- mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
- if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
- mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
- if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
- mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
- if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
- mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
- if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
- mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
- if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
- mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
- if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
- mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
- if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
- if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
- if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
- mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
- if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
- {
- mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
- return;
- }
- if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
- mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
- mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
- mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
- if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
- mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
- if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
- mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
- mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
- if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
- mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
- if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
- if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
- mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
- if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
- mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
- if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
- mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
- if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
- mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
- if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
- mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
- if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
- if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
- mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
- if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
- mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
- if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
- mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
- if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
- mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
- if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
- mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
- if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
- mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
- if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
- mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
- if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
- mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
-#endif /* MBEDTLS_SSL_TLS_C */
-
-#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
- if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
- if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
- mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
- mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
- mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
- mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
- mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
- mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
- mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
- mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
- mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
- mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
- if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
- mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
- if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
- if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
- mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
- if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
- mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
- if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
- if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
- if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
- if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
-#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
- /* END generated code */
-
- if( strlen( buf ) == 0 )
- mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
- }
-
- use_ret = ret & ~0xFF80;
-
- if( use_ret == 0 )
- return;
-
- /* If high level code is present, make a concatenation between both
- * error strings. */
- len = strlen( buf );
-
- if( len > 0 )
- {
- if( buflen - len < 5 )
- return;
-
- mbedtls_snprintf( buf + len, buflen - len, " : " );
-
- buf += len + 3;
- buflen -= len + 3;
- }
-
- /* Low level error codes
- *
- * BEGIN generated code
- */
-#if defined(MBEDTLS_AES_C)
- if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
- mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
- if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
- mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
-#endif /* MBEDTLS_AES_C */
-
-#if defined(MBEDTLS_ASN1_PARSE_C)
- if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
- mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
- if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
-#endif /* MBEDTLS_ASN1_PARSE_C */
-
-#if defined(MBEDTLS_BASE64_C)
- if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
- if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
- mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
-#endif /* MBEDTLS_BASE64_C */
-
-#if defined(MBEDTLS_BIGNUM_C)
- if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
- if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
- if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
- if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
- if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
- if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
- if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
- mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
-#endif /* MBEDTLS_BIGNUM_C */
-
-#if defined(MBEDTLS_BLOWFISH_C)
- if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
- mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
- if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
- mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
-#endif /* MBEDTLS_BLOWFISH_C */
-
-#if defined(MBEDTLS_CAMELLIA_C)
- if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
- mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
- if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
- mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
-#endif /* MBEDTLS_CAMELLIA_C */
-
-#if defined(MBEDTLS_CCM_C)
- if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
- mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
- mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
-#endif /* MBEDTLS_CCM_C */
-
-#if defined(MBEDTLS_CTR_DRBG_C)
- if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
- mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
- if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
- mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
- if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
- mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
- if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
-#endif /* MBEDTLS_CTR_DRBG_C */
-
-#if defined(MBEDTLS_DES_C)
- if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
- mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
-#endif /* MBEDTLS_DES_C */
-
-#if defined(MBEDTLS_ENTROPY_C)
- if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
- mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
- if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
- mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
- if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
- mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
- if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
- mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
- if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
-#endif /* MBEDTLS_ENTROPY_C */
-
-#if defined(MBEDTLS_GCM_C)
- if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
- mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
- if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
- mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
-#endif /* MBEDTLS_GCM_C */
-
-#if defined(MBEDTLS_HMAC_DRBG_C)
- if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
- mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
- if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
- mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
- if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
- mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
- if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
- mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
-#endif /* MBEDTLS_HMAC_DRBG_C */
-
-#if defined(MBEDTLS_NET_C)
- if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
- if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
- if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
- if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
- if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
- if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
- if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
- mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
- if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
- mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
- if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
- mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
- if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
- if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
- mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
-#endif /* MBEDTLS_NET_C */
-
-#if defined(MBEDTLS_OID_C)
- if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
- mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
- if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
- mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
-#endif /* MBEDTLS_OID_C */
-
-#if defined(MBEDTLS_PADLOCK_C)
- if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
- mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
-#endif /* MBEDTLS_PADLOCK_C */
-
-#if defined(MBEDTLS_THREADING_C)
- if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
- mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
- if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
- mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
- if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
- mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
-#endif /* MBEDTLS_THREADING_C */
-
-#if defined(MBEDTLS_XTEA_C)
- if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
- mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
-#endif /* MBEDTLS_XTEA_C */
- /* END generated code */
-
- if( strlen( buf ) != 0 )
- return;
-
- mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
-}
-
-#else /* MBEDTLS_ERROR_C */
-
-#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
-
-/*
- * Provide an non-function in case MBEDTLS_ERROR_C is not defined
- */
-void mbedtls_strerror( int ret, char *buf, size_t buflen )
-{
- ((void) ret);
-
- if( buflen > 0 )
- buf[0] = '\0';
-}
-
-#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
-
-#endif /* MBEDTLS_ERROR_C */
diff --git a/deps/mbedtls/gcm.c b/deps/mbedtls/gcm.c
index 0939004f9a..573104379e 100644
--- a/deps/mbedtls/gcm.c
+++ b/deps/mbedtls/gcm.c
@@ -45,15 +45,6 @@
#include "mbedtls/aesni.h"
#endif
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
-
/*
* 32-bit integer manipulation macros (big endian)
*/
@@ -505,447 +496,4 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx )
mbedtls_zeroize( ctx, sizeof( mbedtls_gcm_context ) );
}
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
-/*
- * AES-GCM test vectors from:
- *
- * http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip
- */
-#define MAX_TESTS 6
-
-static const int key_index[MAX_TESTS] =
- { 0, 0, 1, 1, 1, 1 };
-
-static const unsigned char gcm_key[MAX_TESTS][32] =
-{
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
- 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
- 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
- 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
-};
-
-static const size_t gcm_iv_len[MAX_TESTS] =
- { 12, 12, 12, 12, 8, 60 };
-
-static const int iv_index[MAX_TESTS] =
- { 0, 0, 1, 1, 1, 2 };
-
-static const unsigned char gcm_iv[MAX_TESTS][64] =
-{
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00 },
- { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
- 0xde, 0xca, 0xf8, 0x88 },
- { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
- 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
- 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
- 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
- 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
- 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
- 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
- 0xa6, 0x37, 0xb3, 0x9b },
-};
-
-static const size_t gcm_add_len[MAX_TESTS] =
- { 0, 0, 0, 20, 20, 20 };
-
-static const int add_index[MAX_TESTS] =
- { 0, 0, 0, 1, 1, 1 };
-
-static const unsigned char additional[MAX_TESTS][64] =
-{
- { 0x00 },
- { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
- 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
- 0xab, 0xad, 0xda, 0xd2 },
-};
-
-static const size_t pt_len[MAX_TESTS] =
- { 0, 16, 64, 60, 60, 60 };
-
-static const int pt_index[MAX_TESTS] =
- { 0, 0, 1, 1, 1, 1 };
-
-static const unsigned char pt[MAX_TESTS][64] =
-{
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
- 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
- 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
- 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
- 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
- 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
- 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
- 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
-};
-
-static const unsigned char ct[MAX_TESTS * 3][64] =
-{
- { 0x00 },
- { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
- 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 },
- { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
- 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
- 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
- 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
- 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
- 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
- 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
- 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85 },
- { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
- 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
- 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
- 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
- 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
- 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
- 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
- 0x3d, 0x58, 0xe0, 0x91 },
- { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a,
- 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55,
- 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8,
- 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23,
- 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2,
- 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42,
- 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07,
- 0xc2, 0x3f, 0x45, 0x98 },
- { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
- 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
- 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
- 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
- 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
- 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
- 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
- 0x4c, 0x34, 0xae, 0xe5 },
- { 0x00 },
- { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
- 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 },
- { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
- 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
- 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
- 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
- 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
- 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
- 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
- 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56 },
- { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
- 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
- 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
- 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
- 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
- 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
- 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
- 0xcc, 0xda, 0x27, 0x10 },
- { 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54,
- 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8,
- 0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f,
- 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57,
- 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75,
- 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9,
- 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f,
- 0xa0, 0xf0, 0x62, 0xf7 },
- { 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
- 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
- 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
- 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
- 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
- 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
- 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
- 0xe9, 0xb7, 0x37, 0x3b },
- { 0x00 },
- { 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
- 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18 },
- { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
- 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
- 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
- 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
- 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
- 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
- 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
- 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad },
- { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
- 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
- 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
- 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
- 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
- 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
- 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
- 0xbc, 0xc9, 0xf6, 0x62 },
- { 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32,
- 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb,
- 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
- 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0,
- 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0,
- 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
- 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99,
- 0xf4, 0x7c, 0x9b, 0x1f },
- { 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1,
- 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20,
- 0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19,
- 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4,
- 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45,
- 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde,
- 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e,
- 0x44, 0xae, 0x7e, 0x3f },
-};
-
-static const unsigned char tag[MAX_TESTS * 3][16] =
-{
- { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
- 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a },
- { 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
- 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf },
- { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
- 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 },
- { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
- 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 },
- { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85,
- 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb },
- { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
- 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 },
- { 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
- 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 },
- { 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
- 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb },
- { 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
- 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 },
- { 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
- 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c },
- { 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24,
- 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8 },
- { 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
- 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9 },
- { 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
- 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b },
- { 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
- 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 },
- { 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
- 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c },
- { 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
- 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b },
- { 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4,
- 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 },
- { 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0,
- 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a },
-};
-
-int mbedtls_gcm_self_test( int verbose )
-{
- mbedtls_gcm_context ctx;
- unsigned char buf[64];
- unsigned char tag_buf[16];
- int i, j, ret;
- mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
-
- mbedtls_gcm_init( &ctx );
-
- for( j = 0; j < 3; j++ )
- {
- int key_len = 128 + 64 * j;
-
- for( i = 0; i < MAX_TESTS; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " AES-GCM-%3d #%d (%s): ",
- key_len, i, "enc" );
-
- mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
-
- ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT,
- pt_len[i],
- gcm_iv[iv_index[i]], gcm_iv_len[i],
- additional[add_index[i]], gcm_add_len[i],
- pt[pt_index[i]], buf, 16, tag_buf );
-
- if( ret != 0 ||
- memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 ||
- memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- mbedtls_gcm_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " AES-GCM-%3d #%d (%s): ",
- key_len, i, "dec" );
-
- mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
-
- ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_DECRYPT,
- pt_len[i],
- gcm_iv[iv_index[i]], gcm_iv_len[i],
- additional[add_index[i]], gcm_add_len[i],
- ct[j * 6 + i], buf, 16, tag_buf );
-
- if( ret != 0 ||
- memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 ||
- memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- mbedtls_gcm_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " AES-GCM-%3d #%d split (%s): ",
- key_len, i, "enc" );
-
- mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
-
- ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_ENCRYPT,
- gcm_iv[iv_index[i]], gcm_iv_len[i],
- additional[add_index[i]], gcm_add_len[i] );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( pt_len[i] > 32 )
- {
- size_t rest_len = pt_len[i] - 32;
- ret = mbedtls_gcm_update( &ctx, 32, pt[pt_index[i]], buf );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- ret = mbedtls_gcm_update( &ctx, rest_len, pt[pt_index[i]] + 32,
- buf + 32 );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
- else
- {
- ret = mbedtls_gcm_update( &ctx, pt_len[i], pt[pt_index[i]], buf );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
- if( ret != 0 ||
- memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 ||
- memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- mbedtls_gcm_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " AES-GCM-%3d #%d split (%s): ",
- key_len, i, "dec" );
-
- mbedtls_gcm_setkey( &ctx, cipher, gcm_key[key_index[i]], key_len );
-
- ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_DECRYPT,
- gcm_iv[iv_index[i]], gcm_iv_len[i],
- additional[add_index[i]], gcm_add_len[i] );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( pt_len[i] > 32 )
- {
- size_t rest_len = pt_len[i] - 32;
- ret = mbedtls_gcm_update( &ctx, 32, ct[j * 6 + i], buf );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- ret = mbedtls_gcm_update( &ctx, rest_len, ct[j * 6 + i] + 32,
- buf + 32 );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
- else
- {
- ret = mbedtls_gcm_update( &ctx, pt_len[i], ct[j * 6 + i], buf );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 );
- if( ret != 0 ||
- memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 ||
- memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- mbedtls_gcm_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
-
#endif /* MBEDTLS_GCM_C */
diff --git a/deps/mbedtls/havege.c b/deps/mbedtls/havege.c
deleted file mode 100644
index 8109ae8ad8..0000000000
--- a/deps/mbedtls/havege.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-/*
- * The HAVEGE RNG was designed by Andre Seznec in 2002.
- *
- * http://www.irisa.fr/caps/projects/hipsor/publi.php
- *
- * Contact: seznec(at)irisa_dot_fr - orocheco(at)irisa_dot_fr
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_HAVEGE_C)
-
-#include "mbedtls/havege.h"
-#include "mbedtls/timing.h"
-
-#include
-
-#include "arc4_alt.h"
-
-/* ------------------------------------------------------------------------
- * On average, one iteration accesses two 8-word blocks in the havege WALK
- * table, and generates 16 words in the RES array.
- *
- * The data read in the WALK table is updated and permuted after each use.
- * The result of the hardware clock counter read is used for this update.
- *
- * 25 conditional tests are present. The conditional tests are grouped in
- * two nested groups of 12 conditional tests and 1 test that controls the
- * permutation; on average, there should be 6 tests executed and 3 of them
- * should be mispredicted.
- * ------------------------------------------------------------------------
- */
-
-#define SWAP(X,Y) { int *T = X; X = Y; Y = T; }
-
-#define TST1_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
-#define TST2_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
-
-#define TST1_LEAVE U1++; }
-#define TST2_LEAVE U2++; }
-
-#define ONE_ITERATION \
- \
- PTEST = PT1 >> 20; \
- \
- TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
- TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
- TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
- \
- TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
- TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
- TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
- \
- PTX = (PT1 >> 18) & 7; \
- PT1 &= 0x1FFF; \
- PT2 &= 0x1FFF; \
- CLK = (int) mbedtls_timing_hardclock(); \
- \
- i = 0; \
- A = &WALK[PT1 ]; RES[i++] ^= *A; \
- B = &WALK[PT2 ]; RES[i++] ^= *B; \
- C = &WALK[PT1 ^ 1]; RES[i++] ^= *C; \
- D = &WALK[PT2 ^ 4]; RES[i++] ^= *D; \
- \
- IN = (*A >> (1)) ^ (*A << (31)) ^ CLK; \
- *A = (*B >> (2)) ^ (*B << (30)) ^ CLK; \
- *B = IN ^ U1; \
- *C = (*C >> (3)) ^ (*C << (29)) ^ CLK; \
- *D = (*D >> (4)) ^ (*D << (28)) ^ CLK; \
- \
- A = &WALK[PT1 ^ 2]; RES[i++] ^= *A; \
- B = &WALK[PT2 ^ 2]; RES[i++] ^= *B; \
- C = &WALK[PT1 ^ 3]; RES[i++] ^= *C; \
- D = &WALK[PT2 ^ 6]; RES[i++] ^= *D; \
- \
- if( PTEST & 1 ) SWAP( A, C ); \
- \
- IN = (*A >> (5)) ^ (*A << (27)) ^ CLK; \
- *A = (*B >> (6)) ^ (*B << (26)) ^ CLK; \
- *B = IN; CLK = (int) mbedtls_timing_hardclock(); \
- *C = (*C >> (7)) ^ (*C << (25)) ^ CLK; \
- *D = (*D >> (8)) ^ (*D << (24)) ^ CLK; \
- \
- A = &WALK[PT1 ^ 4]; \
- B = &WALK[PT2 ^ 1]; \
- \
- PTEST = PT2 >> 1; \
- \
- PT2 = (RES[(i - 8) ^ PTY] ^ WALK[PT2 ^ PTY ^ 7]); \
- PT2 = ((PT2 & 0x1FFF) & (~8)) ^ ((PT1 ^ 8) & 0x8); \
- PTY = (PT2 >> 10) & 7; \
- \
- TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
- TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
- TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
- \
- TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
- TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
- TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
- \
- C = &WALK[PT1 ^ 5]; \
- D = &WALK[PT2 ^ 5]; \
- \
- RES[i++] ^= *A; \
- RES[i++] ^= *B; \
- RES[i++] ^= *C; \
- RES[i++] ^= *D; \
- \
- IN = (*A >> ( 9)) ^ (*A << (23)) ^ CLK; \
- *A = (*B >> (10)) ^ (*B << (22)) ^ CLK; \
- *B = IN ^ U2; \
- *C = (*C >> (11)) ^ (*C << (21)) ^ CLK; \
- *D = (*D >> (12)) ^ (*D << (20)) ^ CLK; \
- \
- A = &WALK[PT1 ^ 6]; RES[i++] ^= *A; \
- B = &WALK[PT2 ^ 3]; RES[i++] ^= *B; \
- C = &WALK[PT1 ^ 7]; RES[i++] ^= *C; \
- D = &WALK[PT2 ^ 7]; RES[i++] ^= *D; \
- \
- IN = (*A >> (13)) ^ (*A << (19)) ^ CLK; \
- *A = (*B >> (14)) ^ (*B << (18)) ^ CLK; \
- *B = IN; \
- *C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \
- *D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \
- \
- PT1 = ( RES[( i - 8 ) ^ PTX] ^ \
- WALK[PT1 ^ PTX ^ 7] ) & (~1); \
- PT1 ^= (PT2 ^ 0x10) & 0x10; \
- \
- for( n++, i = 0; i < 16; i++ ) \
- hs->pool[n % MBEDTLS_HAVEGE_COLLECT_SIZE] ^= RES[i];
-
-/*
- * Entropy gathering function
- */
-static void havege_fill( mbedtls_havege_state *hs )
-{
- int i, n = 0;
- int U1, U2, *A, *B, *C, *D;
- int PT1, PT2, *WALK, RES[16];
- int PTX, PTY, CLK, PTEST, IN;
-
- WALK = hs->WALK;
- PT1 = hs->PT1;
- PT2 = hs->PT2;
-
- PTX = U1 = 0;
- PTY = U2 = 0;
-
- (void)PTX;
-
- memset( RES, 0, sizeof( RES ) );
-
- while( n < MBEDTLS_HAVEGE_COLLECT_SIZE * 4 )
- {
- ONE_ITERATION
- ONE_ITERATION
- ONE_ITERATION
- ONE_ITERATION
- }
-
- hs->PT1 = PT1;
- hs->PT2 = PT2;
-
- hs->offset[0] = 0;
- hs->offset[1] = MBEDTLS_HAVEGE_COLLECT_SIZE / 2;
-}
-
-/*
- * HAVEGE initialization
- */
-void mbedtls_havege_init( mbedtls_havege_state *hs )
-{
- memset( hs, 0, sizeof( mbedtls_havege_state ) );
-
- havege_fill( hs );
-}
-
-void mbedtls_havege_free( mbedtls_havege_state *hs )
-{
- if( hs == NULL )
- return;
-
- mbedtls_zeroize( hs, sizeof( mbedtls_havege_state ) );
-}
-
-/*
- * HAVEGE rand function
- */
-int mbedtls_havege_random( void *p_rng, unsigned char *buf, size_t len )
-{
- int val;
- size_t use_len;
- mbedtls_havege_state *hs = (mbedtls_havege_state *) p_rng;
- unsigned char *p = buf;
-
- while( len > 0 )
- {
- use_len = len;
- if( use_len > sizeof(int) )
- use_len = sizeof(int);
-
- if( hs->offset[1] >= MBEDTLS_HAVEGE_COLLECT_SIZE )
- havege_fill( hs );
-
- val = hs->pool[hs->offset[0]++];
- val ^= hs->pool[hs->offset[1]++];
-
- memcpy( p, &val, use_len );
-
- len -= use_len;
- p += use_len;
- }
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_HAVEGE_C */
diff --git a/deps/mbedtls/hmac_drbg.c b/deps/mbedtls/hmac_drbg.c
index a8ed885c82..b16a682b14 100644
--- a/deps/mbedtls/hmac_drbg.c
+++ b/deps/mbedtls/hmac_drbg.c
@@ -41,15 +41,6 @@
#include
#endif
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_SELF_TEST */
-#endif /* MBEDTLS_PLATFORM_C */
-
#include "arc4_alt.h"
/*
@@ -397,130 +388,4 @@ int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const ch
}
#endif /* MBEDTLS_FS_IO */
-
-#if defined(MBEDTLS_SELF_TEST)
-
-#if !defined(MBEDTLS_SHA1_C)
-/* Dummy checkup routine */
-int mbedtls_hmac_drbg_self_test( int verbose )
-{
- (void) verbose;
- return( 0 );
-}
-#else
-
-#define OUTPUT_LEN 80
-
-/* From a NIST PR=true test vector */
-static const unsigned char entropy_pr[] = {
- 0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f,
- 0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11,
- 0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42,
- 0x17, 0x60, 0x99, 0xd4, 0x5e, 0x13, 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3,
- 0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4 };
-static const unsigned char hmac_result_pr[OUTPUT_LEN] = {
- 0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39,
- 0x9b, 0x60, 0x81, 0x48, 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94,
- 0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, 0xfc, 0xcc, 0x2d, 0x54,
- 0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e,
- 0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab,
- 0x46, 0x05, 0x5c, 0x09, 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3,
- 0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44 };
-
-/* From a NIST PR=false test vector */
-static const unsigned char entropy_nopr[] = {
- 0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66,
- 0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8,
- 0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3,
- 0xe9, 0x9d, 0xfe, 0xdf };
-static const unsigned char hmac_result_nopr[OUTPUT_LEN] = {
- 0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f,
- 0xec, 0x5a, 0xdc, 0xa9, 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6,
- 0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, 0x4a, 0x4c, 0x0a, 0x0a,
- 0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec,
- 0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd,
- 0xb5, 0xb3, 0xe9, 0x1b, 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49,
- 0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7 };
-
-/* "Entropy" from buffer */
-static size_t test_offset;
-static int hmac_drbg_self_test_entropy( void *data,
- unsigned char *buf, size_t len )
-{
- const unsigned char *p = (const unsigned char*)data;
- memcpy( buf, p + test_offset, len );
- test_offset += len;
- return( 0 );
-}
-
-#define CHK( c ) if( (c) != 0 ) \
- { \
- if( verbose != 0 ) \
- mbedtls_printf( "failed\n" ); \
- return( 1 ); \
- }
-
-/*
- * Checkup routine for HMAC_DRBG with SHA-1
- */
-int mbedtls_hmac_drbg_self_test( int verbose )
-{
- mbedtls_hmac_drbg_context ctx;
- unsigned char buf[OUTPUT_LEN];
- const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 );
-
- mbedtls_hmac_drbg_init( &ctx );
-
- /*
- * PR = True
- */
- if( verbose != 0 )
- mbedtls_printf( " HMAC_DRBG (PR = True) : " );
-
- test_offset = 0;
- CHK( mbedtls_hmac_drbg_seed( &ctx, md_info,
- hmac_drbg_self_test_entropy, (void *) entropy_pr,
- NULL, 0 ) );
- mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
- CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
- CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
- CHK( memcmp( buf, hmac_result_pr, OUTPUT_LEN ) );
- mbedtls_hmac_drbg_free( &ctx );
-
- mbedtls_hmac_drbg_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- /*
- * PR = False
- */
- if( verbose != 0 )
- mbedtls_printf( " HMAC_DRBG (PR = False) : " );
-
- mbedtls_hmac_drbg_init( &ctx );
-
- test_offset = 0;
- CHK( mbedtls_hmac_drbg_seed( &ctx, md_info,
- hmac_drbg_self_test_entropy, (void *) entropy_nopr,
- NULL, 0 ) );
- CHK( mbedtls_hmac_drbg_reseed( &ctx, NULL, 0 ) );
- CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
- CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
- CHK( memcmp( buf, hmac_result_nopr, OUTPUT_LEN ) );
- mbedtls_hmac_drbg_free( &ctx );
-
- mbedtls_hmac_drbg_free( &ctx );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-#endif /* MBEDTLS_SHA1_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_HMAC_DRBG_C */
diff --git a/deps/mbedtls/mbedtls/aes.h b/deps/mbedtls/mbedtls/aes.h
index 3fbb3688f5..b58c2180ad 100644
--- a/deps/mbedtls/mbedtls/aes.h
+++ b/deps/mbedtls/mbedtls/aes.h
@@ -32,6 +32,8 @@
#include
#include
+#include
+
/* padlock.c and aesni.c rely on these values! */
#define MBEDTLS_AES_ENCRYPT 1
#define MBEDTLS_AES_DECRYPT 0
@@ -39,11 +41,6 @@
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
-#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
-#define inline __inline
-#endif
-
#if !defined(MBEDTLS_AES_ALT)
/* Regular implementation */
@@ -279,43 +276,6 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] );
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
-#if defined(MBEDTLS_DEPRECATED_WARNING)
-#define MBEDTLS_DEPRECATED __attribute__((deprecated))
-#else
-#define MBEDTLS_DEPRECATED
-#endif
-/**
- * \brief Deprecated internal AES block encryption function
- * without return value.
- *
- * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0
- *
- * \param ctx AES context
- * \param input Plaintext block
- * \param output Output (ciphertext) block
- */
-MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
-
-/**
- * \brief Deprecated internal AES block decryption function
- * without return value.
- *
- * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0
- *
- * \param ctx AES context
- * \param input Ciphertext block
- * \param output Output (plaintext) block
- */
-MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
-
-#undef MBEDTLS_DEPRECATED
-#endif /* !MBEDTLS_DEPRECATED_REMOVED */
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/bn_mul.h b/deps/mbedtls/mbedtls/bn_mul.h
index cac3f14577..41173e0368 100644
--- a/deps/mbedtls/mbedtls/bn_mul.h
+++ b/deps/mbedtls/mbedtls/bn_mul.h
@@ -404,78 +404,6 @@
#endif /* PPC32 */
-/*
- * The Sparc(64) assembly is reported to be broken.
- * Disable it for now, until we're able to fix it.
- */
-#if 0 && defined(__sparc__)
-#if defined(__sparc64__)
-
-#define MULADDC_INIT \
- asm( \
- "ldx %3, %%o0 \n\t" \
- "ldx %4, %%o1 \n\t" \
- "ld %5, %%o2 \n\t" \
- "ld %6, %%o3 \n\t"
-
-#define MULADDC_CORE \
- "ld [%%o0], %%o4 \n\t" \
- "inc 4, %%o0 \n\t" \
- "ld [%%o1], %%o5 \n\t" \
- "umul %%o3, %%o4, %%o4 \n\t" \
- "addcc %%o4, %%o2, %%o4 \n\t" \
- "rd %%y, %%g1 \n\t" \
- "addx %%g1, 0, %%g1 \n\t" \
- "addcc %%o4, %%o5, %%o4 \n\t" \
- "st %%o4, [%%o1] \n\t" \
- "addx %%g1, 0, %%o2 \n\t" \
- "inc 4, %%o1 \n\t"
-
- #define MULADDC_STOP \
- "st %%o2, %0 \n\t" \
- "stx %%o1, %1 \n\t" \
- "stx %%o0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "g1", "o0", "o1", "o2", "o3", "o4", \
- "o5" \
- );
-
-#else /* __sparc64__ */
-
-#define MULADDC_INIT \
- asm( \
- "ld %3, %%o0 \n\t" \
- "ld %4, %%o1 \n\t" \
- "ld %5, %%o2 \n\t" \
- "ld %6, %%o3 \n\t"
-
-#define MULADDC_CORE \
- "ld [%%o0], %%o4 \n\t" \
- "inc 4, %%o0 \n\t" \
- "ld [%%o1], %%o5 \n\t" \
- "umul %%o3, %%o4, %%o4 \n\t" \
- "addcc %%o4, %%o2, %%o4 \n\t" \
- "rd %%y, %%g1 \n\t" \
- "addx %%g1, 0, %%g1 \n\t" \
- "addcc %%o4, %%o5, %%o4 \n\t" \
- "st %%o4, [%%o1] \n\t" \
- "addx %%g1, 0, %%o2 \n\t" \
- "inc 4, %%o1 \n\t"
-
-#define MULADDC_STOP \
- "st %%o2, %0 \n\t" \
- "st %%o1, %1 \n\t" \
- "st %%o0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "g1", "o0", "o1", "o2", "o3", "o4", \
- "o5" \
- );
-
-#endif /* __sparc64__ */
-#endif /* __sparc__ */
-
#if defined(__microblaze__) || defined(microblaze)
#define MULADDC_INIT \
diff --git a/deps/mbedtls/mbedtls/ccm.h b/deps/mbedtls/mbedtls/ccm.h
index ef75839baa..65b4f7bb16 100644
--- a/deps/mbedtls/mbedtls/ccm.h
+++ b/deps/mbedtls/mbedtls/ccm.h
@@ -125,15 +125,6 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
const unsigned char *input, unsigned char *output,
const unsigned char *tag, size_t tag_len );
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
-int mbedtls_ccm_self_test( int verbose );
-#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/check_config.h b/deps/mbedtls/mbedtls/check_config.h
index fa72454e53..62350679f3 100644
--- a/deps/mbedtls/mbedtls/check_config.h
+++ b/deps/mbedtls/mbedtls/check_config.h
@@ -38,33 +38,11 @@
#error "mbed TLS requires a platform with 8-bit chars"
#endif
-#if defined(_WIN32)
-#if !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_C is required on Windows"
-#endif
-
-/* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
- * it would confuse config.pl. */
-#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
- !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
-#define MBEDTLS_PLATFORM_SNPRINTF_ALT
-#endif
-#endif /* _WIN32 */
-
#if defined(TARGET_LIKE_MBED) && \
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
#endif
-#if defined(MBEDTLS_DEPRECATED_WARNING) && \
- !defined(__GNUC__) && !defined(__clang__)
-#error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
-#endif
-
-#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
-#error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
-#endif
-
#if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
#error "MBEDTLS_AESNI_C defined, but not all prerequisites"
#endif
@@ -77,11 +55,6 @@
#error "MBEDTLS_DHM_C defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_CMAC_C) && \
- !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
-#error "MBEDTLS_CMAC_C defined, but not all prerequisites"
-#endif
-
#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
#endif
@@ -93,11 +66,6 @@
#error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_ECJPAKE_C) && \
- ( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
-#error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
-#endif
-
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
#endif
@@ -135,16 +103,6 @@
#error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
- ( !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) )
-#error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
-#endif
-#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
- ( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
- defined(MBEDTLS_HAVEGE_C) )
-#error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
-#endif
-
#if defined(MBEDTLS_GCM_C) && ( \
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) )
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
@@ -182,10 +140,6 @@
#error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
-#error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
-#endif
-
#if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
#error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
#endif
@@ -239,17 +193,6 @@
#error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
- ( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
- !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
-#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
-#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
-#endif
-
#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
#endif
@@ -275,203 +218,6 @@
#error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
#endif
-#if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
-#error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
- defined(MBEDTLS_PLATFORM_EXIT_ALT) )
-#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
-#error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
-#error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
-#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
- defined(MBEDTLS_PLATFORM_TIME_ALT) )
-#error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
- defined(MBEDTLS_PLATFORM_TIME_ALT) )
-#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
- defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
-#error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
-#error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
- defined(MBEDTLS_PLATFORM_STD_FREE)
-#error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
-#error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
-#error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
- defined(MBEDTLS_PLATFORM_STD_CALLOC)
-#error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
-#error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
- defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
-#error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
-#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
- defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
-#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
- !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
-#error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
-#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
-#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
-#error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
- !defined(MBEDTLS_PLATFORM_EXIT_ALT)
-#error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
- ( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
- !defined(MBEDTLS_HAVE_TIME) )
-#error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
- !defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
-#error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
- !defined(MBEDTLS_PLATFORM_PRINTF_ALT)
-#error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
- !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
-#error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_ENTROPY_NV_SEED) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_ENTROPY_C) )
-#error "MBEDTLS_ENTROPY_NV_SEED defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) &&\
- !defined(MBEDTLS_ENTROPY_NV_SEED)
-#error "MBEDTLS_PLATFORM_NV_SEED_ALT defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) &&\
- !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
-#error "MBEDTLS_PLATFORM_STD_NV_SEED_READ defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) &&\
- !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
-#error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) ||\
- defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
-#error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously"
-#endif
-
-#if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) ||\
- defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
-#error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
-#endif
-
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
!defined(MBEDTLS_OID_C) )
#error "MBEDTLS_RSA_C defined, but not all prerequisites"
@@ -614,10 +360,6 @@
#endif
#undef MBEDTLS_THREADING_IMPL
-#if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
-#error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
-#endif
-
#if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
!defined(MBEDTLS_PK_PARSE_C) )
diff --git a/deps/mbedtls/mbedtls/cipher.h b/deps/mbedtls/mbedtls/cipher.h
index f806573572..8148678a8b 100644
--- a/deps/mbedtls/mbedtls/cipher.h
+++ b/deps/mbedtls/mbedtls/cipher.h
@@ -243,11 +243,6 @@ typedef struct {
/** Cipher-specific context */
void *cipher_ctx;
-
-#if defined(MBEDTLS_CMAC_C)
- /** CMAC Specific context */
- mbedtls_cmac_context_t *cmac_ctx;
-#endif
} mbedtls_cipher_context_t;
/**
diff --git a/deps/mbedtls/mbedtls/cmac.h b/deps/mbedtls/mbedtls/cmac.h
index 9a2b96bc92..a95b6d86fb 100644
--- a/deps/mbedtls/mbedtls/cmac.h
+++ b/deps/mbedtls/mbedtls/cmac.h
@@ -154,15 +154,6 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
unsigned char output[16] );
#endif /* MBEDTLS_AES_C */
-#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
-int mbedtls_cmac_self_test( int verbose );
-#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/compat-1.3.h b/deps/mbedtls/mbedtls/compat-1.3.h
index bba1d2c247..bda4883d77 100644
--- a/deps/mbedtls/mbedtls/compat-1.3.h
+++ b/deps/mbedtls/mbedtls/compat-1.3.h
@@ -24,12 +24,6 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/
-#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
-
-#if defined(MBEDTLS_DEPRECATED_WARNING)
-#warning "Including compat-1.3.h is deprecated"
-#endif
-
#ifndef MBEDTLS_COMPAT13_H
#define MBEDTLS_COMPAT13_H
@@ -45,9 +39,6 @@
#if defined MBEDTLS_AES_C
#define POLARSSL_AES_C MBEDTLS_AES_C
#endif
-#if defined MBEDTLS_AES_ROM_TABLES
-#define POLARSSL_AES_ROM_TABLES MBEDTLS_AES_ROM_TABLES
-#endif
#if defined MBEDTLS_ARC4_ALT
#define POLARSSL_ARC4_ALT MBEDTLS_ARC4_ALT
#endif
@@ -117,15 +108,6 @@
#if defined MBEDTLS_CTR_DRBG_C
#define POLARSSL_CTR_DRBG_C MBEDTLS_CTR_DRBG_C
#endif
-#if defined MBEDTLS_DEBUG_C
-#define POLARSSL_DEBUG_C MBEDTLS_DEBUG_C
-#endif
-#if defined MBEDTLS_DEPRECATED_REMOVED
-#define POLARSSL_DEPRECATED_REMOVED MBEDTLS_DEPRECATED_REMOVED
-#endif
-#if defined MBEDTLS_DEPRECATED_WARNING
-#define POLARSSL_DEPRECATED_WARNING MBEDTLS_DEPRECATED_WARNING
-#endif
#if defined MBEDTLS_DES_ALT
#define POLARSSL_DES_ALT MBEDTLS_DES_ALT
#endif
@@ -204,9 +186,6 @@
#if defined MBEDTLS_ENTROPY_FORCE_SHA256
#define POLARSSL_ENTROPY_FORCE_SHA256 MBEDTLS_ENTROPY_FORCE_SHA256
#endif
-#if defined MBEDTLS_ERROR_C
-#define POLARSSL_ERROR_C MBEDTLS_ERROR_C
-#endif
#if defined MBEDTLS_ERROR_STRERROR_DUMMY
#define POLARSSL_ERROR_STRERROR_DUMMY MBEDTLS_ERROR_STRERROR_DUMMY
#endif
@@ -219,18 +198,12 @@
#if defined MBEDTLS_GENPRIME
#define POLARSSL_GENPRIME MBEDTLS_GENPRIME
#endif
-#if defined MBEDTLS_HAVEGE_C
-#define POLARSSL_HAVEGE_C MBEDTLS_HAVEGE_C
-#endif
#if defined MBEDTLS_HAVE_ASM
#define POLARSSL_HAVE_ASM MBEDTLS_HAVE_ASM
#endif
#if defined MBEDTLS_HAVE_SSE2
#define POLARSSL_HAVE_SSE2 MBEDTLS_HAVE_SSE2
#endif
-#if defined MBEDTLS_HAVE_TIME
-#define POLARSSL_HAVE_TIME MBEDTLS_HAVE_TIME
-#endif
#if defined MBEDTLS_HMAC_DRBG_C
#define POLARSSL_HMAC_DRBG_C MBEDTLS_HMAC_DRBG_C
#endif
@@ -276,24 +249,6 @@
#if defined MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
#define POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
#endif
-#if defined MBEDTLS_MD2_ALT
-#define POLARSSL_MD2_ALT MBEDTLS_MD2_ALT
-#endif
-#if defined MBEDTLS_MD2_C
-#define POLARSSL_MD2_C MBEDTLS_MD2_C
-#endif
-#if defined MBEDTLS_MD2_PROCESS_ALT
-#define POLARSSL_MD2_PROCESS_ALT MBEDTLS_MD2_PROCESS_ALT
-#endif
-#if defined MBEDTLS_MD4_ALT
-#define POLARSSL_MD4_ALT MBEDTLS_MD4_ALT
-#endif
-#if defined MBEDTLS_MD4_C
-#define POLARSSL_MD4_C MBEDTLS_MD4_C
-#endif
-#if defined MBEDTLS_MD4_PROCESS_ALT
-#define POLARSSL_MD4_PROCESS_ALT MBEDTLS_MD4_PROCESS_ALT
-#endif
#if defined MBEDTLS_MD5_ALT
#define POLARSSL_MD5_ALT MBEDTLS_MD5_ALT
#endif
@@ -309,15 +264,6 @@
#if defined MBEDTLS_MEMORY_ALIGN_MULTIPLE
#define POLARSSL_MEMORY_ALIGN_MULTIPLE MBEDTLS_MEMORY_ALIGN_MULTIPLE
#endif
-#if defined MBEDTLS_MEMORY_BACKTRACE
-#define POLARSSL_MEMORY_BACKTRACE MBEDTLS_MEMORY_BACKTRACE
-#endif
-#if defined MBEDTLS_MEMORY_BUFFER_ALLOC_C
-#define POLARSSL_MEMORY_BUFFER_ALLOC_C MBEDTLS_MEMORY_BUFFER_ALLOC_C
-#endif
-#if defined MBEDTLS_MEMORY_DEBUG
-#define POLARSSL_MEMORY_DEBUG MBEDTLS_MEMORY_DEBUG
-#endif
#if defined MBEDTLS_MPI_MAX_SIZE
#define POLARSSL_MPI_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
#endif
@@ -327,12 +273,6 @@
#if defined MBEDTLS_NET_C
#define POLARSSL_NET_C MBEDTLS_NET_C
#endif
-#if defined MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
-#define POLARSSL_NO_DEFAULT_ENTROPY_SOURCES MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
-#endif
-#if defined MBEDTLS_NO_PLATFORM_ENTROPY
-#define POLARSSL_NO_PLATFORM_ENTROPY MBEDTLS_NO_PLATFORM_ENTROPY
-#endif
#if defined MBEDTLS_OID_C
#define POLARSSL_OID_C MBEDTLS_OID_C
#endif
@@ -345,9 +285,6 @@
#if defined MBEDTLS_PEM_WRITE_C
#define POLARSSL_PEM_WRITE_C MBEDTLS_PEM_WRITE_C
#endif
-#if defined MBEDTLS_PKCS11_C
-#define POLARSSL_PKCS11_C MBEDTLS_PKCS11_C
-#endif
#if defined MBEDTLS_PKCS12_C
#define POLARSSL_PKCS12_C MBEDTLS_PKCS12_C
#endif
@@ -375,9 +312,6 @@
#if defined MBEDTLS_PK_WRITE_C
#define POLARSSL_PK_WRITE_C MBEDTLS_PK_WRITE_C
#endif
-#if defined MBEDTLS_PLATFORM_C
-#define POLARSSL_PLATFORM_C MBEDTLS_PLATFORM_C
-#endif
#if defined MBEDTLS_PLATFORM_EXIT_ALT
#define POLARSSL_PLATFORM_EXIT_ALT MBEDTLS_PLATFORM_EXIT_ALT
#endif
@@ -396,9 +330,6 @@
#if defined MBEDTLS_PLATFORM_MEMORY
#define POLARSSL_PLATFORM_MEMORY MBEDTLS_PLATFORM_MEMORY
#endif
-#if defined MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
-#define POLARSSL_PLATFORM_NO_STD_FUNCTIONS MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
-#endif
#if defined MBEDTLS_PLATFORM_PRINTF_ALT
#define POLARSSL_PLATFORM_PRINTF_ALT MBEDTLS_PLATFORM_PRINTF_ALT
#endif
@@ -411,18 +342,12 @@
#if defined MBEDTLS_PLATFORM_SNPRINTF_MACRO
#define POLARSSL_PLATFORM_SNPRINTF_MACRO MBEDTLS_PLATFORM_SNPRINTF_MACRO
#endif
-#if defined MBEDTLS_PLATFORM_STD_EXIT
-#define POLARSSL_PLATFORM_STD_EXIT MBEDTLS_PLATFORM_STD_EXIT
-#endif
#if defined MBEDTLS_PLATFORM_STD_FPRINTF
#define POLARSSL_PLATFORM_STD_FPRINTF MBEDTLS_PLATFORM_STD_FPRINTF
#endif
#if defined MBEDTLS_PLATFORM_STD_FREE
#define POLARSSL_PLATFORM_STD_FREE MBEDTLS_PLATFORM_STD_FREE
#endif
-#if defined MBEDTLS_PLATFORM_STD_MEM_HDR
-#define POLARSSL_PLATFORM_STD_MEM_HDR MBEDTLS_PLATFORM_STD_MEM_HDR
-#endif
#if defined MBEDTLS_PLATFORM_STD_PRINTF
#define POLARSSL_PLATFORM_STD_PRINTF MBEDTLS_PLATFORM_STD_PRINTF
#endif
@@ -447,12 +372,6 @@
#if defined MBEDTLS_RSA_C
#define POLARSSL_RSA_C MBEDTLS_RSA_C
#endif
-#if defined MBEDTLS_RSA_NO_CRT
-#define POLARSSL_RSA_NO_CRT MBEDTLS_RSA_NO_CRT
-#endif
-#if defined MBEDTLS_SELF_TEST
-#define POLARSSL_SELF_TEST MBEDTLS_SELF_TEST
-#endif
#if defined MBEDTLS_SHA1_ALT
#define POLARSSL_SHA1_ALT MBEDTLS_SHA1_ALT
#endif
@@ -576,18 +495,12 @@
#if defined MBEDTLS_THREADING_PTHREAD
#define POLARSSL_THREADING_PTHREAD MBEDTLS_THREADING_PTHREAD
#endif
-#if defined MBEDTLS_TIMING_ALT
-#define POLARSSL_TIMING_ALT MBEDTLS_TIMING_ALT
-#endif
#if defined MBEDTLS_TIMING_C
#define POLARSSL_TIMING_C MBEDTLS_TIMING_C
#endif
#if defined MBEDTLS_VERSION_C
#define POLARSSL_VERSION_C MBEDTLS_VERSION_C
#endif
-#if defined MBEDTLS_VERSION_FEATURES
-#define POLARSSL_VERSION_FEATURES MBEDTLS_VERSION_FEATURES
-#endif
#if defined MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
#define POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3 MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
#endif
@@ -633,9 +546,6 @@
#if defined MBEDTLS_XTEA_C
#define POLARSSL_XTEA_C MBEDTLS_XTEA_C
#endif
-#if defined MBEDTLS_ZLIB_SUPPORT
-#define POLARSSL_ZLIB_SUPPORT MBEDTLS_ZLIB_SUPPORT
-#endif
/*
* Misc names (macros, types, functions, enum constants...)
@@ -1943,7 +1853,7 @@
#define entropy_update_manual mbedtls_entropy_update_manual
#define entropy_update_seed_file mbedtls_entropy_update_seed_file
#define entropy_write_seed_file mbedtls_entropy_write_seed_file
-#define error_strerror mbedtls_strerror
+#define error_strerror strerror
#define f_source_ptr mbedtls_entropy_f_source_ptr
#define gcm_auth_decrypt mbedtls_gcm_auth_decrypt
#define gcm_context mbedtls_gcm_context
@@ -2175,15 +2085,15 @@
#define platform_set_fprintf mbedtls_platform_set_fprintf
#define platform_set_printf mbedtls_platform_set_printf
#define platform_set_snprintf mbedtls_platform_set_snprintf
-#define polarssl_exit mbedtls_exit
-#define polarssl_fprintf mbedtls_fprintf
-#define polarssl_free mbedtls_free
+#define polarssl_exit exit
+#define polarssl_fprintf fprintf
+#define polarssl_free free
#define polarssl_mutex_free mbedtls_mutex_free
#define polarssl_mutex_init mbedtls_mutex_init
#define polarssl_mutex_lock mbedtls_mutex_lock
#define polarssl_mutex_unlock mbedtls_mutex_unlock
-#define polarssl_printf mbedtls_printf
-#define polarssl_snprintf mbedtls_snprintf
+#define polarssl_printf printf
+#define polarssl_snprintf snprintf
#define polarssl_strerror mbedtls_strerror
#define ripemd160 mbedtls_ripemd160
#define ripemd160_context mbedtls_ripemd160_context
@@ -2520,4 +2430,3 @@
#define xtea_setup mbedtls_xtea_setup
#endif /* compat-1.3.h */
-#endif /* MBEDTLS_DEPRECATED_REMOVED */
diff --git a/deps/mbedtls/mbedtls/config.h b/deps/mbedtls/mbedtls/config.h
index 6ea52a9b32..fa1a83897f 100644
--- a/deps/mbedtls/mbedtls/config.h
+++ b/deps/mbedtls/mbedtls/config.h
@@ -97,21 +97,6 @@
#define MBEDTLS_HAVE_SSE2
#endif
-/**
- * \def MBEDTLS_HAVE_TIME
- *
- * System has time.h and time().
- * The time does not need to be correct, only time differences are used,
- * by contrast with MBEDTLS_HAVE_TIME_DATE
- *
- * Defining MBEDTLS_HAVE_TIME allows you to specify MBEDTLS_PLATFORM_TIME_ALT,
- * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and
- * MBEDTLS_PLATFORM_STD_TIME.
- *
- * Comment if your system does not support time functions
- */
-#define MBEDTLS_HAVE_TIME
-
/**
* \def MBEDTLS_HAVE_TIME_DATE
*
@@ -124,117 +109,6 @@
*/
#define MBEDTLS_HAVE_TIME_DATE
-/**
- * \def MBEDTLS_PLATFORM_MEMORY
- *
- * Enable the memory allocation layer.
- *
- * By default mbed TLS uses the system-provided calloc() and free().
- * This allows different allocators (self-implemented or provided) to be
- * provided to the platform abstraction layer.
- *
- * Enabling MBEDTLS_PLATFORM_MEMORY without the
- * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
- * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
- * free() function pointer at runtime.
- *
- * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
- * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
- * alternate function at compile time.
- *
- * Requires: MBEDTLS_PLATFORM_C
- *
- * Enable this layer to allow use of alternative memory allocators.
- */
-#if 0
-#define MBEDTLS_PLATFORM_MEMORY
-#endif
-
-/**
- * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
- *
- * Do not assign standard functions in the platform layer (e.g. calloc() to
- * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF)
- *
- * This makes sure there are no linking errors on platforms that do not support
- * these functions. You will HAVE to provide alternatives, either at runtime
- * via the platform_set_xxx() functions or at compile time by setting
- * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a
- * MBEDTLS_PLATFORM_XXX_MACRO.
- *
- * Requires: MBEDTLS_PLATFORM_C
- *
- * Uncomment to prevent default assignment of standard functions in the
- * platform layer.
- */
-#if 0
-#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
-#endif
-
-/**
- * \def MBEDTLS_PLATFORM_EXIT_ALT
- *
- * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
- * function in the platform abstraction layer.
- *
- * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
- * provide a function "mbedtls_platform_set_printf()" that allows you to set an
- * alternative printf function pointer.
- *
- * All these define require MBEDTLS_PLATFORM_C to be defined!
- *
- * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
- * it will be enabled automatically by check_config.h
- *
- * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
- * MBEDTLS_PLATFORM_XXX_MACRO!
- *
- * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
- *
- * Uncomment a macro to enable alternate implementation of specific base
- * platform function
- */
-#if 0
-#define MBEDTLS_PLATFORM_EXIT_ALT
-#define MBEDTLS_PLATFORM_TIME_ALT
-#define MBEDTLS_PLATFORM_FPRINTF_ALT
-#define MBEDTLS_PLATFORM_PRINTF_ALT
-#define MBEDTLS_PLATFORM_SNPRINTF_ALT
-#define MBEDTLS_PLATFORM_NV_SEED_ALT
-#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
-#endif
-
-/**
- * \def MBEDTLS_DEPRECATED_WARNING
- *
- * Mark deprecated functions so that they generate a warning if used.
- * Functions deprecated in one version will usually be removed in the next
- * version. You can enable this to help you prepare the transition to a new
- * major version by making sure your code is not using these functions.
- *
- * This only works with GCC and Clang. With other compilers, you may want to
- * use MBEDTLS_DEPRECATED_REMOVED
- *
- * Uncomment to get warnings on using deprecated functions.
- */
-#if 0
-#define MBEDTLS_DEPRECATED_WARNING
-#endif
-
-/**
- * \def MBEDTLS_DEPRECATED_REMOVED
- *
- * Remove deprecated functions so that they generate an error if used.
- * Functions deprecated in one version will usually be removed in the next
- * version. You can enable this to help you prepare the transition to a new
- * major version by making sure your code is not using these functions.
- *
- * Uncomment to get errors on using deprecated functions.
- */
-#if 0
-#define MBEDTLS_DEPRECATED_REMOVED
-#endif
-
/* \} name SECTION: System support */
/**
@@ -245,21 +119,6 @@
* \{
*/
-/**
- * \def MBEDTLS_TIMING_ALT
- *
- * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(),
- * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay()
- *
- * Only works if you have MBEDTLS_TIMING_C enabled.
- *
- * You will need to provide a header "timing_alt.h" and an implementation at
- * compile time.
- */
-#if 0
-#define MBEDTLS_TIMING_ALT
-#endif
-
/**
* \def MBEDTLS_AES_ALT
*
@@ -412,25 +271,6 @@
#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT
#endif
-/**
- * \def MBEDTLS_TEST_NULL_ENTROPY
- *
- * Enables testing and use of mbed TLS without any configured entropy sources.
- * This permits use of the library on platforms before an entropy source has
- * been integrated (see for example the MBEDTLS_ENTROPY_HARDWARE_ALT or the
- * MBEDTLS_ENTROPY_NV_SEED switches).
- *
- * WARNING! This switch MUST be disabled in production builds, and is suitable
- * only for development.
- * Enabling the switch negates any security provided by the library.
- *
- * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
- *
- */
-#if 0
-#define MBEDTLS_TEST_NULL_ENTROPY
-#endif
-
/**
* \def MBEDTLS_ENTROPY_HARDWARE_ALT
*
@@ -446,17 +286,6 @@
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#endif
-/**
- * \def MBEDTLS_AES_ROM_TABLES
- *
- * Store the AES tables in ROM.
- *
- * Uncomment this macro to store the AES tables in ROM.
- */
-#if 0
-#define MBEDTLS_AES_ROM_TABLES
-#endif
-
/**
* \def MBEDTLS_CAMELLIA_SMALL_MEMORY
*
@@ -858,27 +687,6 @@
*/
#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
-/**
- * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
- *
- * Enable the ECJPAKE based ciphersuite modes in SSL / TLS.
- *
- * \warning This is currently experimental. EC J-PAKE support is based on the
- * Thread v1.0.0 specification; incompatible changes to the specification
- * might still happen. For this reason, this is disabled by default.
- *
- * Requires: MBEDTLS_ECJPAKE_C
- * MBEDTLS_SHA256_C
- * MBEDTLS_ECP_DP_SECP256R1_ENABLED
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
- */
-#if 0
-#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
-#endif
-
/**
* \def MBEDTLS_PK_PARSE_EC_EXTENDED
*
@@ -893,23 +701,6 @@
*/
#define MBEDTLS_PK_PARSE_EC_EXTENDED
-/**
- * \def MBEDTLS_ERROR_STRERROR_DUMMY
- *
- * Enable a dummy error function to make use of mbedtls_strerror() in
- * third party libraries easier when MBEDTLS_ERROR_C is disabled
- * (no effect when MBEDTLS_ERROR_C is enabled).
- *
- * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
- * not using mbedtls_strerror() or error_strerror() in your application.
- *
- * Disable if you run into name conflicts and want to really remove the
- * mbedtls_strerror()
- */
-#if 0
-#define MBEDTLS_ERROR_STRERROR_DUMMY
-#endif
-
/**
* \def MBEDTLS_GENPRIME
*
@@ -926,34 +717,6 @@
*/
#define MBEDTLS_FS_IO
-/**
- * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
- *
- * Do not add default entropy sources. These are the platform specific,
- * mbedtls_timing_hardclock and HAVEGE based poll functions.
- *
- * This is useful to have more control over the added entropy sources in an
- * application.
- *
- * Uncomment this macro to prevent loading of default entropy functions.
- */
-#if 0
-#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
-#endif
-
-/**
- * \def MBEDTLS_NO_PLATFORM_ENTROPY
- *
- * Do not use built-in platform entropy functions.
- * This is useful if your platform does not support
- * standards like the /dev/urandom or Windows CryptoAPI.
- *
- * Uncomment this macro to disable the built-in platform entropy functions.
- */
-#if 0
-#define MBEDTLS_NO_PLATFORM_ENTROPY
-#endif
-
/**
* \def MBEDTLS_ENTROPY_FORCE_SHA256
*
@@ -972,65 +735,6 @@
#define MBEDTLS_ENTROPY_FORCE_SHA256
#endif
-/**
- * \def MBEDTLS_ENTROPY_NV_SEED
- *
- * Enable the non-volatile (NV) seed file-based entropy source.
- * (Also enables the NV seed read/write functions in the platform layer)
- *
- * This is crucial (if not required) on systems that do not have a
- * cryptographic entropy source (in hardware or kernel) available.
- *
- * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
- *
- * \note The read/write functions that are used by the entropy source are
- * determined in the platform layer, and can be modified at runtime and/or
- * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
- *
- * \note If you use the default implementation functions that read a seedfile
- * with regular fopen(), please make sure you make a seedfile with the
- * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
- * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
- * and written to or you will get an entropy source error! The default
- * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
- * bytes from the file.
- *
- * \note The entropy collector will write to the seed file before entropy is
- * given to an external source, to update it.
- */
-#if 0
-#define MBEDTLS_ENTROPY_NV_SEED
-#endif
-
-/**
- * \def MBEDTLS_MEMORY_DEBUG
- *
- * Enable debugging of buffer allocator memory issues. Automatically prints
- * (to stderr) all (fatal) messages on memory allocation issues. Enables
- * function for 'debug output' of allocated memory.
- *
- * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
- *
- * Uncomment this macro to let the buffer allocator print out error messages.
- */
-#if 0
-#define MBEDTLS_MEMORY_DEBUG
-#endif
-
-/**
- * \def MBEDTLS_MEMORY_BACKTRACE
- *
- * Include backtrace information with each allocated block.
- *
- * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
- * GLIBC-compatible backtrace() an backtrace_symbols() support
- *
- * Uncomment this macro to include backtrace information
- */
-#if 0
-#define MBEDTLS_MEMORY_BACKTRACE
-#endif
-
/**
* \def MBEDTLS_PK_RSA_ALT_SUPPORT
*
@@ -1062,27 +766,6 @@
*/
#define MBEDTLS_PKCS1_V21
-/**
- * \def MBEDTLS_RSA_NO_CRT
- *
- * Do not use the Chinese Remainder Theorem for the RSA private operation.
- *
- * Uncomment this macro to disable the use of CRT in RSA.
- *
- */
-#if 0
-#define MBEDTLS_RSA_NO_CRT
-#endif
-
-/**
- * \def MBEDTLS_SELF_TEST
- *
- * Enable the checkup functions (*_self_test).
- */
-#if 0
-#define MBEDTLS_SELF_TEST
-#endif
-
/**
* \def MBEDTLS_SHA256_SMALLER
*
@@ -1462,21 +1145,6 @@
#define MBEDTLS_THREADING_PTHREAD
#endif
-/**
- * \def MBEDTLS_VERSION_FEATURES
- *
- * Allow run-time checking of compile-time enabled features. Thus allowing users
- * to check at run-time if the library is for instance compiled with threading
- * support via mbedtls_version_check_feature().
- *
- * Requires: MBEDTLS_VERSION_C
- *
- * Comment this to disable run-time checking and save ROM space
- */
-#if 0
-#define MBEDTLS_VERSION_FEATURES
-#endif
-
/**
* \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
*
@@ -1540,29 +1208,6 @@
*/
#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
-/**
- * \def MBEDTLS_ZLIB_SUPPORT
- *
- * If set, the SSL/TLS module uses ZLIB to support compression and
- * decompression of packet data.
- *
- * \warning TLS-level compression MAY REDUCE SECURITY! See for example the
- * CRIME attack. Before enabling this option, you should examine with care if
- * CRIME or similar exploits may be a applicable to your use case.
- *
- * \note Currently compression can't be used with DTLS.
- *
- * Used in: library/ssl_tls.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- *
- * This feature requires zlib library and headers to be present.
- *
- * Uncomment to enable use of ZLIB
- */
-#if 0
-#define MBEDTLS_ZLIB_SUPPORT
-#endif
/* \} name SECTION: mbed TLS feature support */
/**
@@ -1842,21 +1487,6 @@
*/
#define MBEDTLS_CIPHER_C
-/**
- * \def MBEDTLS_CMAC_C
- *
- * Enable the CMAC (Cipher-based Message Authentication Code) mode for block
- * ciphers.
- *
- * Module: library/cmac.c
- *
- * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
- *
- */
-#if 0
-#define MBEDTLS_CMAC_C
-#endif
-
/**
* \def MBEDTLS_CTR_DRBG_C
*
@@ -1871,20 +1501,6 @@
*/
#define MBEDTLS_CTR_DRBG_C
-/**
- * \def MBEDTLS_DEBUG_C
- *
- * Enable the debug functions.
- *
- * Module: library/debug.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- *
- * This module provides debugging functions.
- */
-#define MBEDTLS_DEBUG_C
-
/**
* \def MBEDTLS_DES_C
*
@@ -1956,27 +1572,6 @@
*/
#define MBEDTLS_ECDSA_C
-/**
- * \def MBEDTLS_ECJPAKE_C
- *
- * Enable the elliptic curve J-PAKE library.
- *
- * \warning This is currently experimental. EC J-PAKE support is based on the
- * Thread v1.0.0 specification; incompatible changes to the specification
- * might still happen. For this reason, this is disabled by default.
- *
- * Module: library/ecjpake.c
- * Caller:
- *
- * This module is used by the following key exchanges:
- * ECJPAKE
- *
- * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
- */
-#if 0
-#define MBEDTLS_ECJPAKE_C
-#endif
-
/**
* \def MBEDTLS_ECP_C
*
@@ -2005,18 +1600,6 @@
*/
#define MBEDTLS_ENTROPY_C
-/**
- * \def MBEDTLS_ERROR_C
- *
- * Enable error code to error string conversion.
- *
- * Module: library/error.c
- * Caller:
- *
- * This module enables mbedtls_strerror().
- */
-#define MBEDTLS_ERROR_C
-
/**
* \def MBEDTLS_GCM_C
*
@@ -2031,31 +1614,6 @@
*/
#define MBEDTLS_GCM_C
-/**
- * \def MBEDTLS_HAVEGE_C
- *
- * Enable the HAVEGE random generator.
- *
- * Warning: the HAVEGE random generator is not suitable for virtualized
- * environments
- *
- * Warning: the HAVEGE random generator is dependent on timing and specific
- * processor traits. It is therefore not advised to use HAVEGE as
- * your applications primary random generator or primary entropy pool
- * input. As a secondary input to your entropy pool, it IS able add
- * the (limited) extra entropy it provides.
- *
- * Module: library/havege.c
- * Caller:
- *
- * Requires: MBEDTLS_TIMING_C
- *
- * Uncomment to enable the HAVEGE random generator.
- */
-#if 0
-#define MBEDTLS_HAVEGE_C
-#endif
-
/**
* \def MBEDTLS_HMAC_DRBG_C
*
@@ -2082,34 +1640,6 @@
*/
#define MBEDTLS_MD_C
-/**
- * \def MBEDTLS_MD2_C
- *
- * Enable the MD2 hash algorithm.
- *
- * Module: library/md2.c
- * Caller:
- *
- * Uncomment to enable support for (rare) MD2-signed X.509 certs.
- */
-#if 0
-#define MBEDTLS_MD2_C
-#endif
-
-/**
- * \def MBEDTLS_MD4_C
- *
- * Enable the MD4 hash algorithm.
- *
- * Module: library/md4.c
- * Caller:
- *
- * Uncomment to enable support for (rare) MD4-signed X.509 certs.
- */
-#if 0
-#define MBEDTLS_MD4_C
-#endif
-
/**
* \def MBEDTLS_MD5_C
*
@@ -2125,24 +1655,6 @@
*/
#define MBEDTLS_MD5_C
-/**
- * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
- *
- * Enable the buffer allocator implementation that makes use of a (stack)
- * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
- * calls)
- *
- * Module: library/memory_buffer_alloc.c
- *
- * Requires: MBEDTLS_PLATFORM_C
- * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
- *
- * Enable this module to enable the buffer memory allocator.
- */
-#if 0
-#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
-#endif
-
/**
* \def MBEDTLS_NET_C
*
@@ -2291,23 +1803,6 @@
*/
#define MBEDTLS_PKCS5_C
-/**
- * \def MBEDTLS_PKCS11_C
- *
- * Enable wrapper for PKCS#11 smartcard support.
- *
- * Module: library/pkcs11.c
- * Caller: library/pk.c
- *
- * Requires: MBEDTLS_PK_C
- *
- * This module enables SSL/TLS PKCS #11 smartcard support.
- * Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
- */
-#if 0
-#define MBEDTLS_PKCS11_C
-#endif
-
/**
* \def MBEDTLS_PKCS12_C
*
@@ -2324,26 +1819,6 @@
*/
#define MBEDTLS_PKCS12_C
-/**
- * \def MBEDTLS_PLATFORM_C
- *
- * Enable the platform abstraction layer that allows you to re-assign
- * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
- *
- * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
- * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
- * above to be specified at runtime or compile time respectively.
- *
- * \note This abstraction layer must be enabled on Windows (including MSYS2)
- * as other module rely on it for a fixed snprintf implementation.
- *
- * Module: library/platform.c
- * Caller: Most other .c files
- *
- * This module enables abstraction of common (libc) functions.
- */
-#define MBEDTLS_PLATFORM_C
-
/**
* \def MBEDTLS_RIPEMD160_C
*
@@ -2722,43 +2197,11 @@
#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Default minimum number of bytes required for the hardware entropy source mbedtls_hardware_poll() before entropy is released */
#endif
-/* Memory buffer allocator options */
-#if 0
-#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
-#endif
-
/* Platform options */
#if 0
-#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
-#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
-/* Note: your snprintf must correclty zero-terminate the buffer! */
-#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
-#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to read/write with default implementation */
-#endif
-
-/* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */
-/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */
-#if 0
-#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */
-#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
-#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
-#define MBEDTLS_PLATFORM_TIME_MACRO time /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
-#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
-#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
-#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
-/* Note: your snprintf must correclty zero-terminate the buffer! */
-#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
-#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
-#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
#endif
/* SSL Cache options */
diff --git a/deps/mbedtls/mbedtls/debug.h b/deps/mbedtls/mbedtls/debug.h
index 2957996407..34ba236416 100644
--- a/deps/mbedtls/mbedtls/debug.h
+++ b/deps/mbedtls/mbedtls/debug.h
@@ -35,37 +35,6 @@
#include "ecp.h"
#endif
-#if defined(MBEDTLS_DEBUG_C)
-
-#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
-
-#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
- mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
- MBEDTLS_DEBUG_STRIP_PARENS args )
-
-#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
- mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
-
-#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
- mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
-
-#if defined(MBEDTLS_BIGNUM_C)
-#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
- mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
-#endif
-
-#if defined(MBEDTLS_ECP_C)
-#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
- mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
-#endif
-
-#if defined(MBEDTLS_X509_CRT_PARSE_C)
-#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
- mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
-#endif
-
-#else /* MBEDTLS_DEBUG_C */
-
#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
@@ -73,8 +42,6 @@
#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
-#endif /* MBEDTLS_DEBUG_C */
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/deps/mbedtls/mbedtls/ecdsa.h b/deps/mbedtls/mbedtls/ecdsa.h
index a277715b3d..9c60da9343 100644
--- a/deps/mbedtls/mbedtls/ecdsa.h
+++ b/deps/mbedtls/mbedtls/ecdsa.h
@@ -162,48 +162,6 @@ int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
-#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
-#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
-#if defined(MBEDTLS_DEPRECATED_WARNING)
-#define MBEDTLS_DEPRECATED __attribute__((deprecated))
-#else
-#define MBEDTLS_DEPRECATED
-#endif
-/**
- * \brief Compute ECDSA signature and write it to buffer,
- * serialized as defined in RFC 4492 page 20.
- * Deterministic version, RFC 6979.
- * (Not thread-safe to use same context in multiple threads)
- *
- * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0
- *
- * \param ctx ECDSA context
- * \param hash Message hash
- * \param hlen Length of hash
- * \param sig Buffer that will hold the signature
- * \param slen Length of the signature written
- * \param md_alg MD algorithm used to hash the message
- *
- * \note The "sig" buffer must be at least as large as twice the
- * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit
- * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * prescribed by SEC1 4.1.3 step 5.
- *
- * \return 0 if successful,
- * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or
- * MBEDTLS_ERR_ASN1_XXX error code
- */
-int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
- const unsigned char *hash, size_t hlen,
- unsigned char *sig, size_t *slen,
- mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
-#undef MBEDTLS_DEPRECATED
-#endif /* MBEDTLS_DEPRECATED_REMOVED */
-#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
-
/**
* \brief Read and verify an ECDSA signature
*
diff --git a/deps/mbedtls/mbedtls/ecjpake.h b/deps/mbedtls/mbedtls/ecjpake.h
deleted file mode 100644
index 161a5b213f..0000000000
--- a/deps/mbedtls/mbedtls/ecjpake.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- * \file ecjpake.h
- *
- * \brief Elliptic curve J-PAKE
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_ECJPAKE_H
-#define MBEDTLS_ECJPAKE_H
-
-/*
- * J-PAKE is a password-authenticated key exchange that allows deriving a
- * strong shared secret from a (potentially low entropy) pre-shared
- * passphrase, with forward secrecy and mutual authentication.
- * https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling
- *
- * This file implements the Elliptic Curve variant of J-PAKE,
- * as defined in Chapter 7.4 of the Thread v1.0 Specification,
- * available to members of the Thread Group http://threadgroup.org/
- *
- * As the J-PAKE algorithm is inherently symmetric, so is our API.
- * Each party needs to send its first round message, in any order, to the
- * other party, then each sends its second round message, in any order.
- * The payloads are serialized in a way suitable for use in TLS, but could
- * also be use outside TLS.
- */
-
-#include "ecp.h"
-#include "md.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Roles in the EC J-PAKE exchange
- */
-typedef enum {
- MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */
- MBEDTLS_ECJPAKE_SERVER, /**< Server */
-} mbedtls_ecjpake_role;
-
-/**
- * EC J-PAKE context structure.
- *
- * J-PAKE is a symmetric protocol, except for the identifiers used in
- * Zero-Knowledge Proofs, and the serialization of the second message
- * (KeyExchange) as defined by the Thread spec.
- *
- * In order to benefit from this symmetry, we choose a different naming
- * convetion from the Thread v1.0 spec. Correspondance is indicated in the
- * description as a pair C: client name, S: server name
- */
-typedef struct
-{
- const mbedtls_md_info_t *md_info; /**< Hash to use */
- mbedtls_ecp_group grp; /**< Elliptic curve */
- mbedtls_ecjpake_role role; /**< Are we client or server? */
- int point_format; /**< Format for point export */
-
- mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */
- mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */
- mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */
- mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */
- mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */
-
- mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */
- mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */
-
- mbedtls_mpi s; /**< Pre-shared secret (passphrase) */
-} mbedtls_ecjpake_context;
-
-/**
- * \brief Initialize a context
- * (just makes it ready for setup() or free()).
- *
- * \param ctx context to initialize
- */
-void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
-
-/**
- * \brief Set up a context for use
- *
- * \note Currently the only values for hash/curve allowed by the
- * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1.
- *
- * \param ctx context to set up
- * \param role Our role: client or server
- * \param hash hash function to use (MBEDTLS_MD_XXX)
- * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX)
- * \param secret pre-shared secret (passphrase)
- * \param len length of the shared secret
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
- mbedtls_ecjpake_role role,
- mbedtls_md_type_t hash,
- mbedtls_ecp_group_id curve,
- const unsigned char *secret,
- size_t len );
-
-/**
- * \brief Check if a context is ready for use
- *
- * \param ctx Context to check
- *
- * \return 0 if the context is ready for use,
- * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise
- */
-int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
-
-/**
- * \brief Generate and write the first round message
- * (TLS: contents of the Client/ServerHello extension,
- * excluding extension type and length bytes)
- *
- * \param ctx Context to use
- * \param buf Buffer to write the contents to
- * \param len Buffer size
- * \param olen Will be updated with the number of bytes written
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
-
-/**
- * \brief Read and process the first round message
- * (TLS: contents of the Client/ServerHello extension,
- * excluding extension type and length bytes)
- *
- * \param ctx Context to use
- * \param buf Pointer to extension contents
- * \param len Extension length
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len );
-
-/**
- * \brief Generate and write the second round message
- * (TLS: contents of the Client/ServerKeyExchange)
- *
- * \param ctx Context to use
- * \param buf Buffer to write the contents to
- * \param len Buffer size
- * \param olen Will be updated with the number of bytes written
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
-
-/**
- * \brief Read and process the second round message
- * (TLS: contents of the Client/ServerKeyExchange)
- *
- * \param ctx Context to use
- * \param buf Pointer to the message
- * \param len Message length
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len );
-
-/**
- * \brief Derive the shared secret
- * (TLS: Pre-Master Secret)
- *
- * \param ctx Context to use
- * \param buf Buffer to write the contents to
- * \param len Buffer size
- * \param olen Will be updated with the number of bytes written
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \return 0 if successfull,
- * a negative error code otherwise
- */
-int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
-
-/**
- * \brief Free a context's content
- *
- * \param ctx context to free
- */
-void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
-
-#if defined(MBEDTLS_SELF_TEST)
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_ecjpake_self_test( int verbose );
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ecjpake.h */
diff --git a/deps/mbedtls/mbedtls/ecp.h b/deps/mbedtls/mbedtls/ecp.h
index 60941f526d..2cdb42e1cb 100644
--- a/deps/mbedtls/mbedtls/ecp.h
+++ b/deps/mbedtls/mbedtls/ecp.h
@@ -662,17 +662,6 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
*/
int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv );
-#if defined(MBEDTLS_SELF_TEST)
-
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_ecp_self_test( int verbose );
-
-#endif /* MBEDTLS_SELF_TEST */
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/entropy.h b/deps/mbedtls/mbedtls/entropy.h
index 747aca4dfa..75fdbe7bec 100644
--- a/deps/mbedtls/mbedtls/entropy.h
+++ b/deps/mbedtls/mbedtls/entropy.h
@@ -45,10 +45,6 @@
#include "threading.h"
#endif
-#if defined(MBEDTLS_HAVEGE_C)
-#include "havege.h"
-#endif
-
#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */
#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */
#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 /**< No sources have been added to poll. */
@@ -128,15 +124,9 @@ typedef struct
#endif
int source_count;
mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
-#if defined(MBEDTLS_HAVEGE_C)
- mbedtls_havege_state havege_data;
-#endif
#if defined(MBEDTLS_THREADING_C)
mbedtls_threading_mutex_t mutex; /*!< mutex */
#endif
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
- int initial_entropy_run;
-#endif
}
mbedtls_entropy_context;
@@ -211,18 +201,6 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
const unsigned char *data, size_t len );
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-/**
- * \brief Trigger an update of the seed file in NV by using the
- * current entropy pool.
- *
- * \param ctx Entropy context
- *
- * \return 0 if successful
- */
-int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
-
#if defined(MBEDTLS_FS_IO)
/**
* \brief Write a seed file
@@ -251,35 +229,6 @@ int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *p
int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
#endif /* MBEDTLS_FS_IO */
-#if defined(MBEDTLS_SELF_TEST)
-/**
- * \brief Checkup routine
- *
- * This module self-test also calls the entropy self-test,
- * mbedtls_entropy_source_self_test();
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_entropy_self_test( int verbose );
-
-#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
-/**
- * \brief Checkup routine
- *
- * Verifies the integrity of the hardware entropy source
- * provided by the function 'mbedtls_hardware_poll()'.
- *
- * Note this is the only hardware entropy source that is known
- * at link time, and other entropy sources configured
- * dynamically at runtime by the function
- * mbedtls_entropy_add_source() will not be tested.
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_entropy_source_self_test( int verbose );
-#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
-#endif /* MBEDTLS_SELF_TEST */
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/entropy_poll.h b/deps/mbedtls/mbedtls/entropy_poll.h
index 81258d5f39..2ae092edbf 100644
--- a/deps/mbedtls/mbedtls/entropy_poll.h
+++ b/deps/mbedtls/mbedtls/entropy_poll.h
@@ -45,31 +45,11 @@ extern "C" {
#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
#endif
-/**
- * \brief Entropy poll callback that provides 0 entropy.
- */
-#if defined(MBEDTLS_TEST_NULL_ENTROPY)
- int mbedtls_null_entropy_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
-#endif
-
-#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
/**
* \brief Platform-specific entropy poll callback
*/
int mbedtls_platform_entropy_poll( void *data,
unsigned char *output, size_t len, size_t *olen );
-#endif
-
-#if defined(MBEDTLS_HAVEGE_C)
-/**
- * \brief HAVEGE based entropy poll callback
- *
- * Requires an HAVEGE state as its data pointer.
- */
-int mbedtls_havege_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
-#endif
#if defined(MBEDTLS_TIMING_C)
/**
@@ -92,16 +72,6 @@ int mbedtls_hardware_poll( void *data,
unsigned char *output, size_t len, size_t *olen );
#endif
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-/**
- * \brief Entropy poll callback for a non-volatile seed file
- *
- * \note This must accept NULL as its first argument.
- */
-int mbedtls_nv_seed_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/error.h b/deps/mbedtls/mbedtls/error.h
deleted file mode 100644
index 5e549f6b6a..0000000000
--- a/deps/mbedtls/mbedtls/error.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * \file error.h
- *
- * \brief Error to string translation
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_ERROR_H
-#define MBEDTLS_ERROR_H
-
-#include
-
-/**
- * Error code layout.
- *
- * Currently we try to keep all error codes within the negative space of 16
- * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
- * addition we'd like to give two layers of information on the error if
- * possible.
- *
- * For that purpose the error codes are segmented in the following manner:
- *
- * 16 bit error code bit-segmentation
- *
- * 1 bit - Unused (sign bit)
- * 3 bits - High level module ID
- * 5 bits - Module-dependent error code
- * 7 bits - Low level module errors
- *
- * For historical reasons, low-level error codes are divided in even and odd,
- * even codes were assigned first, and -1 is reserved for other errors.
- *
- * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
- *
- * Module Nr Codes assigned
- * MPI 7 0x0002-0x0010
- * GCM 2 0x0012-0x0014
- * BLOWFISH 2 0x0016-0x0018
- * THREADING 3 0x001A-0x001E
- * AES 2 0x0020-0x0022
- * CAMELLIA 2 0x0024-0x0026
- * XTEA 1 0x0028-0x0028
- * BASE64 2 0x002A-0x002C
- * OID 1 0x002E-0x002E 0x000B-0x000B
- * PADLOCK 1 0x0030-0x0030
- * DES 1 0x0032-0x0032
- * CTR_DBRG 4 0x0034-0x003A
- * ENTROPY 3 0x003C-0x0040 0x003D-0x003F
- * NET 11 0x0042-0x0052 0x0043-0x0045
- * ASN1 7 0x0060-0x006C
- * PBKDF2 1 0x007C-0x007C
- * HMAC_DRBG 4 0x0003-0x0009
- * CCM 2 0x000D-0x000F
- *
- * High-level module nr (3 bits - 0x0...-0x7...)
- * Name ID Nr of Errors
- * PEM 1 9
- * PKCS#12 1 4 (Started from top)
- * X509 2 19
- * PKCS5 2 4 (Started from top)
- * DHM 3 9
- * PK 3 14 (Started from top)
- * RSA 4 9
- * ECP 4 8 (Started from top)
- * MD 5 4
- * CIPHER 6 6
- * SSL 6 17 (Started from top)
- * SSL 7 31
- *
- * Module dependent error code (5 bits 0x.00.-0x.F8.)
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * \brief Translate a mbed TLS error code into a string representation,
- * Result is truncated if necessary and always includes a terminating
- * null byte.
- *
- * \param errnum error code
- * \param buffer buffer to place representation in
- * \param buflen length of the buffer
- */
-void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* error.h */
diff --git a/deps/mbedtls/mbedtls/havege.h b/deps/mbedtls/mbedtls/havege.h
deleted file mode 100644
index dac5d31138..0000000000
--- a/deps/mbedtls/mbedtls/havege.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * \file havege.h
- *
- * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_HAVEGE_H
-#define MBEDTLS_HAVEGE_H
-
-#include
-
-#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * \brief HAVEGE state structure
- */
-typedef struct
-{
- int PT1, PT2, offset[2];
- int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
- int WALK[8192];
-}
-mbedtls_havege_state;
-
-/**
- * \brief HAVEGE initialization
- *
- * \param hs HAVEGE state to be initialized
- */
-void mbedtls_havege_init( mbedtls_havege_state *hs );
-
-/**
- * \brief Clear HAVEGE state
- *
- * \param hs HAVEGE state to be cleared
- */
-void mbedtls_havege_free( mbedtls_havege_state *hs );
-
-/**
- * \brief HAVEGE rand function
- *
- * \param p_rng A HAVEGE state
- * \param output Buffer to fill
- * \param len Length of buffer
- *
- * \return 0
- */
-int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* havege.h */
diff --git a/deps/mbedtls/mbedtls/hmac_drbg.h b/deps/mbedtls/mbedtls/hmac_drbg.h
index e010558028..f24df21027 100644
--- a/deps/mbedtls/mbedtls/hmac_drbg.h
+++ b/deps/mbedtls/mbedtls/hmac_drbg.h
@@ -282,16 +282,6 @@ int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const cha
int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
#endif /* MBEDTLS_FS_IO */
-
-#if defined(MBEDTLS_SELF_TEST)
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
-int mbedtls_hmac_drbg_self_test( int verbose );
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/mbedtls/md.h b/deps/mbedtls/mbedtls/md.h
index b691a7f3f4..5b77d6520a 100644
--- a/deps/mbedtls/mbedtls/md.h
+++ b/deps/mbedtls/mbedtls/md.h
@@ -118,30 +118,6 @@ void mbedtls_md_init( mbedtls_md_context_t *ctx );
*/
void mbedtls_md_free( mbedtls_md_context_t *ctx );
-#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
-#if defined(MBEDTLS_DEPRECATED_WARNING)
-#define MBEDTLS_DEPRECATED __attribute__((deprecated))
-#else
-#define MBEDTLS_DEPRECATED
-#endif
-/**
- * \brief Select MD to use and allocate internal structures.
- * Should be called after mbedtls_md_init() or mbedtls_md_free().
- * Makes it necessary to call mbedtls_md_free() later.
- *
- * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
- *
- * \param ctx Context to set up.
- * \param md_info Message digest to use.
- *
- * \returns \c 0 on success,
- * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
- * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
- */
-int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
-#undef MBEDTLS_DEPRECATED
-#endif /* MBEDTLS_DEPRECATED_REMOVED */
-
/**
* \brief Select MD to use and allocate internal structures.
* Should be called after mbedtls_md_init() or mbedtls_md_free().
diff --git a/deps/mbedtls/mbedtls/md_internal.h b/deps/mbedtls/mbedtls/md_internal.h
index e2441bbc49..a09db47352 100644
--- a/deps/mbedtls/mbedtls/md_internal.h
+++ b/deps/mbedtls/mbedtls/md_internal.h
@@ -83,12 +83,6 @@ struct mbedtls_md_info_t
void (*process_func)( void *ctx, const unsigned char *input );
};
-#if defined(MBEDTLS_MD2_C)
-extern const mbedtls_md_info_t mbedtls_md2_info;
-#endif
-#if defined(MBEDTLS_MD4_C)
-extern const mbedtls_md_info_t mbedtls_md4_info;
-#endif
#if defined(MBEDTLS_MD5_C)
extern const mbedtls_md_info_t mbedtls_md5_info;
#endif
diff --git a/deps/mbedtls/mbedtls/memory_buffer_alloc.h b/deps/mbedtls/mbedtls/memory_buffer_alloc.h
deleted file mode 100644
index d5df316fdd..0000000000
--- a/deps/mbedtls/mbedtls/memory_buffer_alloc.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * \file memory_buffer_alloc.h
- *
- * \brief Buffer-based memory allocator
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H
-#define MBEDTLS_MEMORY_BUFFER_ALLOC_H
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#include
-
-/**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
-
-#if !defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE)
-#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
-#endif
-
-/* \} name SECTION: Module settings */
-
-#define MBEDTLS_MEMORY_VERIFY_NONE 0
-#define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0)
-#define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1)
-#define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * \brief Initialize use of stack-based memory allocator.
- * The stack-based allocator does memory management inside the
- * presented buffer and does not call calloc() and free().
- * It sets the global mbedtls_calloc() and mbedtls_free() pointers
- * to its own functions.
- * (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if
- * MBEDTLS_THREADING_C is defined)
- *
- * \note This code is not optimized and provides a straight-forward
- * implementation of a stack-based memory allocator.
- *
- * \param buf buffer to use as heap
- * \param len size of the buffer
- */
-void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len );
-
-/**
- * \brief Free the mutex for thread-safety and clear remaining memory
- */
-void mbedtls_memory_buffer_alloc_free( void );
-
-/**
- * \brief Determine when the allocator should automatically verify the state
- * of the entire chain of headers / meta-data.
- * (Default: MBEDTLS_MEMORY_VERIFY_NONE)
- *
- * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC,
- * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS
- */
-void mbedtls_memory_buffer_set_verify( int verify );
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
-/**
- * \brief Print out the status of the allocated memory (primarily for use
- * after a program should have de-allocated all memory)
- * Prints out a list of 'still allocated' blocks and their stack
- * trace if MBEDTLS_MEMORY_BACKTRACE is defined.
- */
-void mbedtls_memory_buffer_alloc_status( void );
-
-/**
- * \brief Get the peak heap usage so far
- *
- * \param max_used Peak number of bytes in use or committed. This
- * includes bytes in allocated blocks too small to split
- * into smaller blocks but larger than the requested size.
- * \param max_blocks Peak number of blocks in use, including free and used
- */
-void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks );
-
-/**
- * \brief Reset peak statistics
- */
-void mbedtls_memory_buffer_alloc_max_reset( void );
-
-/**
- * \brief Get the current heap usage
- *
- * \param cur_used Current number of bytes in use or committed. This
- * includes bytes in allocated blocks too small to split
- * into smaller blocks but larger than the requested size.
- * \param cur_blocks Current number of blocks in use, including free and used
- */
-void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks );
-#endif /* MBEDTLS_MEMORY_DEBUG */
-
-/**
- * \brief Verifies that all headers in the memory buffer are correct
- * and contain sane values. Helps debug buffer-overflow errors.
- *
- * Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined.
- * Prints out full header information if MBEDTLS_MEMORY_DEBUG
- * is defined. (Includes stack trace information for each block if
- * MBEDTLS_MEMORY_BACKTRACE is defined as well).
- *
- * \return 0 if verified, 1 otherwise
- */
-int mbedtls_memory_buffer_alloc_verify( void );
-
-#if defined(MBEDTLS_SELF_TEST)
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_memory_buffer_alloc_self_test( int verbose );
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* memory_buffer_alloc.h */
diff --git a/deps/mbedtls/mbedtls/net.h b/deps/mbedtls/mbedtls/net.h
index 774559b3cf..57b1fabac8 100644
--- a/deps/mbedtls/mbedtls/net.h
+++ b/deps/mbedtls/mbedtls/net.h
@@ -23,9 +23,4 @@
* \deprecated Superseded by mbedtls/net_sockets.h
*/
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
#include "mbedtls/net_sockets.h"
-#if defined(MBEDTLS_DEPRECATED_WARNING)
-#warning "Deprecated header file: Superseded by mbedtls/net_sockets.h"
-#endif /* MBEDTLS_DEPRECATED_WARNING */
-#endif /* !MBEDTLS_DEPRECATED_REMOVED */
diff --git a/deps/mbedtls/mbedtls/pkcs11.h b/deps/mbedtls/mbedtls/pkcs11.h
deleted file mode 100644
index 2e88928137..0000000000
--- a/deps/mbedtls/mbedtls/pkcs11.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * \file pkcs11.h
- *
- * \brief Wrapper for PKCS#11 library libpkcs11-helper
- *
- * \author Adriaan de Jong
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_PKCS11_H
-#define MBEDTLS_PKCS11_H
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_PKCS11_C)
-
-#include "x509_crt.h"
-
-#include
-
-#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
-#define inline __inline
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Context for PKCS #11 private keys.
- */
-typedef struct {
- pkcs11h_certificate_t pkcs11h_cert;
- int len;
-} mbedtls_pkcs11_context;
-
-/**
- * Initialize a mbedtls_pkcs11_context.
- * (Just making memory references valid.)
- */
-void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
-
-/**
- * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
- *
- * \param cert X.509 certificate to fill
- * \param pkcs11h_cert PKCS #11 helper certificate
- *
- * \return 0 on success.
- */
-int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
-
-/**
- * Set up a mbedtls_pkcs11_context storing the given certificate. Note that the
- * mbedtls_pkcs11_context will take over control of the certificate, freeing it when
- * done.
- *
- * \param priv_key Private key structure to fill.
- * \param pkcs11_cert PKCS #11 helper certificate
- *
- * \return 0 on success
- */
-int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
- pkcs11h_certificate_t pkcs11_cert );
-
-/**
- * Free the contents of the given private key context. Note that the structure
- * itself is not freed.
- *
- * \param priv_key Private key structure to cleanup
- */
-void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
-
-/**
- * \brief Do an RSA private key decrypt, then remove the message
- * padding
- *
- * \param ctx PKCS #11 context
- * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
- * \param input buffer holding the encrypted data
- * \param output buffer that will hold the plaintext
- * \param olen will contain the plaintext length
- * \param output_max_len maximum length of the output buffer
- *
- * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
- *
- * \note The output buffer must be as large as the size
- * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
- * an error is thrown.
- */
-int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
- int mode, size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len );
-
-/**
- * \brief Do a private RSA to sign a message digest
- *
- * \param ctx PKCS #11 context
- * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
- * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
- * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
- * \param hash buffer holding the message digest
- * \param sig buffer that will hold the ciphertext
- *
- * \return 0 if the signing operation was successful,
- * or an MBEDTLS_ERR_RSA_XXX error code
- *
- * \note The "sig" buffer must be as large as the size
- * of ctx->N (eg. 128 bytes if RSA-1024 is used).
- */
-int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig );
-
-/**
- * SSL/TLS wrappers for PKCS#11 functions
- */
-static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
- const unsigned char *input, unsigned char *output,
- size_t output_max_len )
-{
- return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
- output_max_len );
-}
-
-static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
- const unsigned char *hash, unsigned char *sig )
-{
- ((void) f_rng);
- ((void) p_rng);
- return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
- hashlen, hash, sig );
-}
-
-static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
-{
- return ( (mbedtls_pkcs11_context *) ctx )->len;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* MBEDTLS_PKCS11_C */
-
-#endif /* MBEDTLS_PKCS11_H */
diff --git a/deps/mbedtls/mbedtls/platform.h b/deps/mbedtls/mbedtls/platform.h
index f5499fefa0..079898f6c3 100644
--- a/deps/mbedtls/mbedtls/platform.h
+++ b/deps/mbedtls/mbedtls/platform.h
@@ -29,9 +29,7 @@
#include MBEDTLS_CONFIG_FILE
#endif
-#if defined(MBEDTLS_HAVE_TIME)
-#include "platform_time.h"
-#endif
+#include
#ifdef __cplusplus
extern "C" {
@@ -45,32 +43,15 @@ extern "C" {
* \{
*/
-#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
#include
#include
#include
-#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
-#if defined(_WIN32)
-#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< Default snprintf to use */
-#else
-#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
-#endif
-#endif
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use */
#endif
#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
#endif
-#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
-#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use */
-#endif
-#if !defined(MBEDTLS_PLATFORM_STD_FREE)
-#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use */
-#endif
-#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
-#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use */
-#endif
#if !defined(MBEDTLS_PLATFORM_STD_TIME)
#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use */
#endif
@@ -80,213 +61,17 @@ extern "C" {
#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< Default exit value to use */
#endif
-#if defined(MBEDTLS_FS_IO)
-#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
-#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
-#endif
-#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
-#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
-#endif
-#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
-#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
-#endif
-#endif /* MBEDTLS_FS_IO */
-#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
-#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
-#include MBEDTLS_PLATFORM_STD_MEM_HDR
-#endif
-#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
-
/* \} name SECTION: Module settings */
-/*
- * The function pointers for calloc and free
- */
-#if defined(MBEDTLS_PLATFORM_MEMORY)
-#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
- defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
-#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
-#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
-#else
/* For size_t */
#include
-extern void * (*mbedtls_calloc)( size_t n, size_t size );
-extern void (*mbedtls_free)( void *ptr );
-
-/**
- * \brief Set your own memory implementation function pointers
- *
- * \param calloc_func the calloc function implementation
- * \param free_func the free function implementation
- *
- * \return 0 if successful
- */
-int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
- void (*free_func)( void * ) );
-#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
-#else /* !MBEDTLS_PLATFORM_MEMORY */
-#define mbedtls_free free
-#define mbedtls_calloc calloc
-#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
-
-/*
- * The function pointers for fprintf
- */
-#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
-/* We need FILE * */
-#include
-extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
-
-/**
- * \brief Set your own fprintf function pointer
- *
- * \param fprintf_func the fprintf function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
- ... ) );
-#else
-#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
-#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
-#else
-#define mbedtls_fprintf fprintf
-#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
-#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
-
-/*
- * The function pointers for printf
- */
-#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
-extern int (*mbedtls_printf)( const char *format, ... );
-
-/**
- * \brief Set your own printf function pointer
- *
- * \param printf_func the printf function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
-#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
-#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
-#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
-#else
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
-#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
-
-/*
- * The function pointers for snprintf
- *
- * The snprintf implementation should conform to C99:
- * - it *must* always correctly zero-terminate the buffer
- * (except when n == 0, then it must leave the buffer untouched)
- * - however it is acceptable to return -1 instead of the required length when
- * the destination buffer is too short.
- */
-#if defined(_WIN32)
-/* For Windows (inc. MSYS2), we provide our own fixed implementation */
-int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
-#endif
-
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
-extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
-
-/**
- * \brief Set your own snprintf function pointer
- *
- * \param snprintf_func the snprintf function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
- const char * format, ... ) );
-#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
-#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
-#else
-#define mbedtls_snprintf snprintf
-#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
-#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
-
-/*
- * The function pointers for exit
- */
-#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
-extern void (*mbedtls_exit)( int status );
-
-/**
- * \brief Set your own exit function pointer
- *
- * \param exit_func the exit function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
-#else
-#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
-#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
-#else
-#define mbedtls_exit exit
-#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
-#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
/*
* The default exit values
*/
-#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
-#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
-#else
#define MBEDTLS_EXIT_SUCCESS 0
-#endif
-#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
-#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
-#else
#define MBEDTLS_EXIT_FAILURE 1
-#endif
-
-/*
- * The function pointers for reading from and writing a seed file to
- * Non-Volatile storage (NV) in a platform-independent way
- *
- * Only enabled when the NV seed entropy source is enabled
- */
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
-/* Internal standard platform definitions */
-int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
-int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
-#endif
-
-#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
-extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
-extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
-
-/**
- * \brief Set your own seed file writing/reading functions
- *
- * \param nv_seed_read_func the seed reading function implementation
- * \param nv_seed_write_func the seed writing function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_nv_seed(
- int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
- int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
- );
-#else
-#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
- defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
-#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
-#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
-#else
-#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
-#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
-#endif
-#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
diff --git a/deps/mbedtls/mbedtls/platform_time.h b/deps/mbedtls/mbedtls/platform_time.h
deleted file mode 100644
index abb3431420..0000000000
--- a/deps/mbedtls/mbedtls/platform_time.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * \file platform_time.h
- *
- * \brief mbed TLS Platform time abstraction
- *
- * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-#ifndef MBEDTLS_PLATFORM_TIME_H
-#define MBEDTLS_PLATFORM_TIME_H
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
-
-/*
- * The time_t datatype
- */
-#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
-typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
-#else
-/* For time_t */
-#include
-typedef time_t mbedtls_time_t;
-#endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
-
-/*
- * The function pointers for time
- */
-#if defined(MBEDTLS_PLATFORM_TIME_ALT)
-extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time );
-
-/**
- * \brief Set your own time function pointer
- *
- * \param time_func the time function implementation
- *
- * \return 0
- */
-int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) );
-#else
-#if defined(MBEDTLS_PLATFORM_TIME_MACRO)
-#define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
-#else
-#define mbedtls_time time
-#endif /* MBEDTLS_PLATFORM_TIME_MACRO */
-#endif /* MBEDTLS_PLATFORM_TIME_ALT */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* platform_time.h */
diff --git a/deps/mbedtls/mbedtls/ssl.h b/deps/mbedtls/mbedtls/ssl.h
index 3c6a2ec3e4..cda76afc48 100644
--- a/deps/mbedtls/mbedtls/ssl.h
+++ b/deps/mbedtls/mbedtls/ssl.h
@@ -47,13 +47,7 @@
#include "ecdh.h"
#endif
-#if defined(MBEDTLS_ZLIB_SUPPORT)
-#include "zlib.h"
-#endif
-
-#if defined(MBEDTLS_HAVE_TIME)
-#include "platform_time.h"
-#endif
+#include
/*
* SSL Error codes
@@ -547,9 +541,7 @@ typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
*/
struct mbedtls_ssl_session
{
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t start; /*!< starting time */
-#endif
+ time_t start; /*!< starting time */
int ciphersuite; /*!< chosen ciphersuite */
int compression; /*!< chosen compression */
size_t id_len; /*!< session id length */
@@ -863,9 +855,6 @@ struct mbedtls_ssl_context
size_t out_msglen; /*!< record header: message length */
size_t out_left; /*!< amount of data not yet written */
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- unsigned char *compress_buf; /*!< zlib data buffer */
-#endif
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
signed char split_done; /*!< current record already splitted? */
#endif
diff --git a/deps/mbedtls/mbedtls/ssl_cache.h b/deps/mbedtls/mbedtls/ssl_cache.h
index 3734bb7274..74b9ddd4b6 100644
--- a/deps/mbedtls/mbedtls/ssl_cache.h
+++ b/deps/mbedtls/mbedtls/ssl_cache.h
@@ -59,9 +59,7 @@ typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry;
*/
struct mbedtls_ssl_cache_entry
{
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t timestamp; /*!< entry timestamp */
-#endif
+ time_t timestamp; /*!< entry timestamp */
mbedtls_ssl_session session; /*!< entry session */
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
@@ -107,7 +105,6 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session );
*/
int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session );
-#if defined(MBEDTLS_HAVE_TIME)
/**
* \brief Set the cache timeout
* (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day))
@@ -118,7 +115,6 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session );
* \param timeout cache entry timeout in seconds
*/
void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout );
-#endif /* MBEDTLS_HAVE_TIME */
/**
* \brief Set the maximum number of cache entries
diff --git a/deps/mbedtls/mbedtls/ssl_cookie.h b/deps/mbedtls/mbedtls/ssl_cookie.h
index 037e1c3112..37f08e4c64 100644
--- a/deps/mbedtls/mbedtls/ssl_cookie.h
+++ b/deps/mbedtls/mbedtls/ssl_cookie.h
@@ -52,9 +52,6 @@ extern "C" {
typedef struct
{
mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */
-#if !defined(MBEDTLS_HAVE_TIME)
- unsigned long serial; /*!< serial number for expiration */
-#endif
unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
or in number of tickets issued */
diff --git a/deps/mbedtls/mbedtls/ssl_internal.h b/deps/mbedtls/mbedtls/ssl_internal.h
index 756360b181..7705bba48a 100644
--- a/deps/mbedtls/mbedtls/ssl_internal.h
+++ b/deps/mbedtls/mbedtls/ssl_internal.h
@@ -23,6 +23,8 @@
#ifndef MBEDTLS_SSL_INTERNAL_H
#define MBEDTLS_SSL_INTERNAL_H
+#include
+
#include "ssl.h"
#if defined(MBEDTLS_MD5_C)
@@ -45,11 +47,6 @@
#include "ecjpake.h"
#endif
-#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
-#define inline __inline
-#endif
-
/* Determine minimum supported version */
#define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
@@ -112,11 +109,7 @@
* and allow for a maximum of 1024 of compression expansion if
* enabled.
*/
-#if defined(MBEDTLS_ZLIB_SUPPORT)
-#define MBEDTLS_SSL_COMPRESSION_ADD 1024
-#else
#define MBEDTLS_SSL_COMPRESSION_ADD 0
-#endif
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC)
/* Ciphersuites using HMAC */
@@ -315,14 +308,6 @@ struct mbedtls_ssl_transform
mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
-
- /*
- * Session specific compression layer
- */
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- z_stream ctx_deflate; /*!< compression context */
- z_stream ctx_inflate; /*!< decompression context */
-#endif
};
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -365,7 +350,7 @@ void mbedtls_ssl_sig_hash_set_const_hash( mbedtls_ssl_sig_hash_set_t *set,
mbedtls_md_type_t md_alg );
/* Setup an empty signature-hash set */
-static inline void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *set )
+static INLINE void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *set )
{
mbedtls_ssl_sig_hash_set_const_hash( set, MBEDTLS_MD_NONE );
}
@@ -518,7 +503,7 @@ int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
#endif
#if defined(MBEDTLS_X509_CRT_PARSE_C)
-static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
+static INLINE mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
{
mbedtls_ssl_key_cert *key_cert;
@@ -530,7 +515,7 @@ static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl
return( key_cert == NULL ? NULL : key_cert->key );
}
-static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
+static INLINE mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
{
mbedtls_ssl_key_cert *key_cert;
@@ -562,7 +547,7 @@ void mbedtls_ssl_write_version( int major, int minor, int transport,
void mbedtls_ssl_read_version( int *major, int *minor, int transport,
const unsigned char ver[2] );
-static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
+static INLINE size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
{
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
@@ -573,7 +558,7 @@ static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
return( 5 );
}
-static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
+static INLINE size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
{
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
@@ -597,7 +582,7 @@ void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
#endif
/* constant-time buffer comparison */
-static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
+static INLINE int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
{
size_t i;
const unsigned char *A = (const unsigned char *) a;
diff --git a/deps/mbedtls/mbedtls/timing.h b/deps/mbedtls/mbedtls/timing.h
index e307418523..522c848e8e 100644
--- a/deps/mbedtls/mbedtls/timing.h
+++ b/deps/mbedtls/mbedtls/timing.h
@@ -29,7 +29,6 @@
#include MBEDTLS_CONFIG_FILE
#endif
-#if !defined(MBEDTLS_TIMING_ALT)
/* Regular implementation */
#include
@@ -116,23 +115,10 @@ int mbedtls_timing_get_delay( void *data );
}
#endif
-#else /* MBEDTLS_TIMING_ALT */
-#include "timing_alt.h"
-#endif /* MBEDTLS_TIMING_ALT */
-
#ifdef __cplusplus
extern "C" {
#endif
-#if defined(MBEDTLS_SELF_TEST)
-/**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
-int mbedtls_timing_self_test( int verbose );
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/deps/mbedtls/md.c b/deps/mbedtls/md.c
index 4584310d81..812019677d 100644
--- a/deps/mbedtls/md.c
+++ b/deps/mbedtls/md.c
@@ -34,14 +34,7 @@
#include "mbedtls/md.h"
#include "mbedtls/md_internal.h"
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
#include
#if defined(MBEDTLS_FS_IO)
@@ -77,14 +70,6 @@ static const int supported_digests[] = {
MBEDTLS_MD_MD5,
#endif
-#if defined(MBEDTLS_MD4_C)
- MBEDTLS_MD_MD4,
-#endif
-
-#if defined(MBEDTLS_MD2_C)
- MBEDTLS_MD_MD2,
-#endif
-
MBEDTLS_MD_NONE
};
@@ -99,14 +84,6 @@ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name )
return( NULL );
/* Get the appropriate digest information */
-#if defined(MBEDTLS_MD2_C)
- if( !strcmp( "MD2", md_name ) )
- return mbedtls_md_info_from_type( MBEDTLS_MD_MD2 );
-#endif
-#if defined(MBEDTLS_MD4_C)
- if( !strcmp( "MD4", md_name ) )
- return mbedtls_md_info_from_type( MBEDTLS_MD_MD4 );
-#endif
#if defined(MBEDTLS_MD5_C)
if( !strcmp( "MD5", md_name ) )
return mbedtls_md_info_from_type( MBEDTLS_MD_MD5 );
@@ -138,14 +115,6 @@ const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type )
{
switch( md_type )
{
-#if defined(MBEDTLS_MD2_C)
- case MBEDTLS_MD_MD2:
- return( &mbedtls_md2_info );
-#endif
-#if defined(MBEDTLS_MD4_C)
- case MBEDTLS_MD_MD4:
- return( &mbedtls_md4_info );
-#endif
#if defined(MBEDTLS_MD5_C)
case MBEDTLS_MD_MD5:
return( &mbedtls_md5_info );
@@ -191,7 +160,7 @@ void mbedtls_md_free( mbedtls_md_context_t *ctx )
if( ctx->hmac_ctx != NULL )
{
mbedtls_zeroize( ctx->hmac_ctx, 2 * ctx->md_info->block_size );
- mbedtls_free( ctx->hmac_ctx );
+ free( ctx->hmac_ctx );
}
mbedtls_zeroize( ctx, sizeof( mbedtls_md_context_t ) );
@@ -212,13 +181,6 @@ int mbedtls_md_clone( mbedtls_md_context_t *dst,
return( 0 );
}
-#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
-int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info )
-{
- return mbedtls_md_setup( ctx, md_info, 1 );
-}
-#endif
-
int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac )
{
if( md_info == NULL || ctx == NULL )
@@ -229,7 +191,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf
if( hmac != 0 )
{
- ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size );
+ ctx->hmac_ctx = calloc( 2, md_info->block_size );
if( ctx->hmac_ctx == NULL )
{
md_info->ctx_free_func( ctx->md_ctx );
diff --git a/deps/mbedtls/md2.c b/deps/mbedtls/md2.c
deleted file mode 100644
index 647fce97b3..0000000000
--- a/deps/mbedtls/md2.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * RFC 1115/1319 compliant MD2 implementation
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-/*
- * The MD2 algorithm was designed by Ron Rivest in 1989.
- *
- * http://www.ietf.org/rfc/rfc1115.txt
- * http://www.ietf.org/rfc/rfc1319.txt
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_MD2_C)
-
-#include "mbedtls/md2.h"
-
-#include
-
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
-#if !defined(MBEDTLS_MD2_ALT)
-
-#include "arc4_alt.h"
-
-static const unsigned char PI_SUBST[256] =
-{
- 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36,
- 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 0x62, 0xA7, 0x05, 0xF3,
- 0xC0, 0xC7, 0x73, 0x8C, 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C,
- 0x82, 0xCA, 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
- 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, 0xBE, 0x4E,
- 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, 0xA0, 0xFB, 0xF5, 0x8E,
- 0xBB, 0x2F, 0xEE, 0x7A, 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2,
- 0x07, 0x3F, 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
- 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, 0x35, 0x3E,
- 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, 0xFF, 0x19, 0x30, 0xB3,
- 0x48, 0xA5, 0xB5, 0xD1, 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56,
- 0xAA, 0xC6, 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
- 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, 0x45, 0x9D,
- 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, 0x86, 0x5B, 0xCF, 0x65,
- 0xE6, 0x2D, 0xA8, 0x02, 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0,
- 0xB9, 0xF6, 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
- 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, 0xC3, 0x5C,
- 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, 0x2C, 0x53, 0x0D, 0x6E,
- 0x85, 0x28, 0x84, 0x09, 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81,
- 0x4D, 0x52, 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
- 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, 0x78, 0x88,
- 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE,
- 0x3B, 0x00, 0x1D, 0x39, 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58,
- 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
- 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99,
- 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14
-};
-
-void mbedtls_md2_init( mbedtls_md2_context *ctx )
-{
- memset( ctx, 0, sizeof( mbedtls_md2_context ) );
-}
-
-void mbedtls_md2_free( mbedtls_md2_context *ctx )
-{
- if( ctx == NULL )
- return;
-
- mbedtls_zeroize( ctx, sizeof( mbedtls_md2_context ) );
-}
-
-void mbedtls_md2_clone( mbedtls_md2_context *dst,
- const mbedtls_md2_context *src )
-{
- *dst = *src;
-}
-
-/*
- * MD2 context setup
- */
-void mbedtls_md2_starts( mbedtls_md2_context *ctx )
-{
- memset( ctx->cksum, 0, 16 );
- memset( ctx->state, 0, 46 );
- memset( ctx->buffer, 0, 16 );
- ctx->left = 0;
-}
-
-#if !defined(MBEDTLS_MD2_PROCESS_ALT)
-void mbedtls_md2_process( mbedtls_md2_context *ctx )
-{
- int i, j;
- unsigned char t = 0;
-
- for( i = 0; i < 16; i++ )
- {
- ctx->state[i + 16] = ctx->buffer[i];
- ctx->state[i + 32] =
- (unsigned char)( ctx->buffer[i] ^ ctx->state[i]);
- }
-
- for( i = 0; i < 18; i++ )
- {
- for( j = 0; j < 48; j++ )
- {
- ctx->state[j] = (unsigned char)
- ( ctx->state[j] ^ PI_SUBST[t] );
- t = ctx->state[j];
- }
-
- t = (unsigned char)( t + i );
- }
-
- t = ctx->cksum[15];
-
- for( i = 0; i < 16; i++ )
- {
- ctx->cksum[i] = (unsigned char)
- ( ctx->cksum[i] ^ PI_SUBST[ctx->buffer[i] ^ t] );
- t = ctx->cksum[i];
- }
-}
-#endif /* !MBEDTLS_MD2_PROCESS_ALT */
-
-/*
- * MD2 process buffer
- */
-void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen )
-{
- size_t fill;
-
- while( ilen > 0 )
- {
- if( ilen > 16 - ctx->left )
- fill = 16 - ctx->left;
- else
- fill = ilen;
-
- memcpy( ctx->buffer + ctx->left, input, fill );
-
- ctx->left += fill;
- input += fill;
- ilen -= fill;
-
- if( ctx->left == 16 )
- {
- ctx->left = 0;
- mbedtls_md2_process( ctx );
- }
- }
-}
-
-/*
- * MD2 final digest
- */
-void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] )
-{
- size_t i;
- unsigned char x;
-
- x = (unsigned char)( 16 - ctx->left );
-
- for( i = ctx->left; i < 16; i++ )
- ctx->buffer[i] = x;
-
- mbedtls_md2_process( ctx );
-
- memcpy( ctx->buffer, ctx->cksum, 16 );
- mbedtls_md2_process( ctx );
-
- memcpy( output, ctx->state, 16 );
-}
-
-#endif /* !MBEDTLS_MD2_ALT */
-
-/*
- * output = MD2( input buffer )
- */
-void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] )
-{
- mbedtls_md2_context ctx;
-
- mbedtls_md2_init( &ctx );
- mbedtls_md2_starts( &ctx );
- mbedtls_md2_update( &ctx, input, ilen );
- mbedtls_md2_finish( &ctx, output );
- mbedtls_md2_free( &ctx );
-}
-
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * RFC 1319 test vectors
- */
-static const char md2_test_str[7][81] =
-{
- { "" },
- { "a" },
- { "abc" },
- { "message digest" },
- { "abcdefghijklmnopqrstuvwxyz" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
- { "12345678901234567890123456789012345678901234567890123456789012" \
- "345678901234567890" }
-};
-
-static const unsigned char md2_test_sum[7][16] =
-{
- { 0x83, 0x50, 0xE5, 0xA3, 0xE2, 0x4C, 0x15, 0x3D,
- 0xF2, 0x27, 0x5C, 0x9F, 0x80, 0x69, 0x27, 0x73 },
- { 0x32, 0xEC, 0x01, 0xEC, 0x4A, 0x6D, 0xAC, 0x72,
- 0xC0, 0xAB, 0x96, 0xFB, 0x34, 0xC0, 0xB5, 0xD1 },
- { 0xDA, 0x85, 0x3B, 0x0D, 0x3F, 0x88, 0xD9, 0x9B,
- 0x30, 0x28, 0x3A, 0x69, 0xE6, 0xDE, 0xD6, 0xBB },
- { 0xAB, 0x4F, 0x49, 0x6B, 0xFB, 0x2A, 0x53, 0x0B,
- 0x21, 0x9F, 0xF3, 0x30, 0x31, 0xFE, 0x06, 0xB0 },
- { 0x4E, 0x8D, 0xDF, 0xF3, 0x65, 0x02, 0x92, 0xAB,
- 0x5A, 0x41, 0x08, 0xC3, 0xAA, 0x47, 0x94, 0x0B },
- { 0xDA, 0x33, 0xDE, 0xF2, 0xA4, 0x2D, 0xF1, 0x39,
- 0x75, 0x35, 0x28, 0x46, 0xC3, 0x03, 0x38, 0xCD },
- { 0xD5, 0x97, 0x6F, 0x79, 0xD8, 0x3D, 0x3A, 0x0D,
- 0xC9, 0x80, 0x6C, 0x3C, 0x66, 0xF3, 0xEF, 0xD8 }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_md2_self_test( int verbose )
-{
- int i;
- unsigned char md2sum[16];
-
- for( i = 0; i < 7; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " MD2 test #%d: ", i + 1 );
-
- mbedtls_md2( (unsigned char *) md2_test_str[i],
- strlen( md2_test_str[i] ), md2sum );
-
- if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
-#endif /* MBEDTLS_MD2_C */
diff --git a/deps/mbedtls/md4.c b/deps/mbedtls/md4.c
deleted file mode 100644
index f436191cb1..0000000000
--- a/deps/mbedtls/md4.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * RFC 1186/1320 compliant MD4 implementation
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-/*
- * The MD4 algorithm was designed by Ron Rivest in 1990.
- *
- * http://www.ietf.org/rfc/rfc1186.txt
- * http://www.ietf.org/rfc/rfc1320.txt
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_MD4_C)
-
-#include "mbedtls/md4.h"
-
-#include
-
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
-#if !defined(MBEDTLS_MD4_ALT)
-
-#include "arc4_alt.h"
-
-/*
- * 32-bit integer manipulation macros (little endian)
- */
-#ifndef GET_UINT32_LE
-#define GET_UINT32_LE(n,b,i) \
-{ \
- (n) = ( (uint32_t) (b)[(i) ] ) \
- | ( (uint32_t) (b)[(i) + 1] << 8 ) \
- | ( (uint32_t) (b)[(i) + 2] << 16 ) \
- | ( (uint32_t) (b)[(i) + 3] << 24 ); \
-}
-#endif
-
-#ifndef PUT_UINT32_LE
-#define PUT_UINT32_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
- (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
- (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
- (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
-}
-#endif
-
-void mbedtls_md4_init( mbedtls_md4_context *ctx )
-{
- memset( ctx, 0, sizeof( mbedtls_md4_context ) );
-}
-
-void mbedtls_md4_free( mbedtls_md4_context *ctx )
-{
- if( ctx == NULL )
- return;
-
- mbedtls_zeroize( ctx, sizeof( mbedtls_md4_context ) );
-}
-
-void mbedtls_md4_clone( mbedtls_md4_context *dst,
- const mbedtls_md4_context *src )
-{
- *dst = *src;
-}
-
-/*
- * MD4 context setup
- */
-void mbedtls_md4_starts( mbedtls_md4_context *ctx )
-{
- ctx->total[0] = 0;
- ctx->total[1] = 0;
-
- ctx->state[0] = 0x67452301;
- ctx->state[1] = 0xEFCDAB89;
- ctx->state[2] = 0x98BADCFE;
- ctx->state[3] = 0x10325476;
-}
-
-#if !defined(MBEDTLS_MD4_PROCESS_ALT)
-void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] )
-{
- uint32_t X[16], A, B, C, D;
-
- GET_UINT32_LE( X[ 0], data, 0 );
- GET_UINT32_LE( X[ 1], data, 4 );
- GET_UINT32_LE( X[ 2], data, 8 );
- GET_UINT32_LE( X[ 3], data, 12 );
- GET_UINT32_LE( X[ 4], data, 16 );
- GET_UINT32_LE( X[ 5], data, 20 );
- GET_UINT32_LE( X[ 6], data, 24 );
- GET_UINT32_LE( X[ 7], data, 28 );
- GET_UINT32_LE( X[ 8], data, 32 );
- GET_UINT32_LE( X[ 9], data, 36 );
- GET_UINT32_LE( X[10], data, 40 );
- GET_UINT32_LE( X[11], data, 44 );
- GET_UINT32_LE( X[12], data, 48 );
- GET_UINT32_LE( X[13], data, 52 );
- GET_UINT32_LE( X[14], data, 56 );
- GET_UINT32_LE( X[15], data, 60 );
-
-#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
-
- A = ctx->state[0];
- B = ctx->state[1];
- C = ctx->state[2];
- D = ctx->state[3];
-
-#define F(x, y, z) ((x & y) | ((~x) & z))
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x; a = S(a,s); }
-
- P( A, B, C, D, X[ 0], 3 );
- P( D, A, B, C, X[ 1], 7 );
- P( C, D, A, B, X[ 2], 11 );
- P( B, C, D, A, X[ 3], 19 );
- P( A, B, C, D, X[ 4], 3 );
- P( D, A, B, C, X[ 5], 7 );
- P( C, D, A, B, X[ 6], 11 );
- P( B, C, D, A, X[ 7], 19 );
- P( A, B, C, D, X[ 8], 3 );
- P( D, A, B, C, X[ 9], 7 );
- P( C, D, A, B, X[10], 11 );
- P( B, C, D, A, X[11], 19 );
- P( A, B, C, D, X[12], 3 );
- P( D, A, B, C, X[13], 7 );
- P( C, D, A, B, X[14], 11 );
- P( B, C, D, A, X[15], 19 );
-
-#undef P
-#undef F
-
-#define F(x,y,z) ((x & y) | (x & z) | (y & z))
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x5A827999; a = S(a,s); }
-
- P( A, B, C, D, X[ 0], 3 );
- P( D, A, B, C, X[ 4], 5 );
- P( C, D, A, B, X[ 8], 9 );
- P( B, C, D, A, X[12], 13 );
- P( A, B, C, D, X[ 1], 3 );
- P( D, A, B, C, X[ 5], 5 );
- P( C, D, A, B, X[ 9], 9 );
- P( B, C, D, A, X[13], 13 );
- P( A, B, C, D, X[ 2], 3 );
- P( D, A, B, C, X[ 6], 5 );
- P( C, D, A, B, X[10], 9 );
- P( B, C, D, A, X[14], 13 );
- P( A, B, C, D, X[ 3], 3 );
- P( D, A, B, C, X[ 7], 5 );
- P( C, D, A, B, X[11], 9 );
- P( B, C, D, A, X[15], 13 );
-
-#undef P
-#undef F
-
-#define F(x,y,z) (x ^ y ^ z)
-#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x6ED9EBA1; a = S(a,s); }
-
- P( A, B, C, D, X[ 0], 3 );
- P( D, A, B, C, X[ 8], 9 );
- P( C, D, A, B, X[ 4], 11 );
- P( B, C, D, A, X[12], 15 );
- P( A, B, C, D, X[ 2], 3 );
- P( D, A, B, C, X[10], 9 );
- P( C, D, A, B, X[ 6], 11 );
- P( B, C, D, A, X[14], 15 );
- P( A, B, C, D, X[ 1], 3 );
- P( D, A, B, C, X[ 9], 9 );
- P( C, D, A, B, X[ 5], 11 );
- P( B, C, D, A, X[13], 15 );
- P( A, B, C, D, X[ 3], 3 );
- P( D, A, B, C, X[11], 9 );
- P( C, D, A, B, X[ 7], 11 );
- P( B, C, D, A, X[15], 15 );
-
-#undef F
-#undef P
-
- ctx->state[0] += A;
- ctx->state[1] += B;
- ctx->state[2] += C;
- ctx->state[3] += D;
-}
-#endif /* !MBEDTLS_MD4_PROCESS_ALT */
-
-/*
- * MD4 process buffer
- */
-void mbedtls_md4_update( mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen )
-{
- size_t fill;
- uint32_t left;
-
- if( ilen == 0 )
- return;
-
- left = ctx->total[0] & 0x3F;
- fill = 64 - left;
-
- ctx->total[0] += (uint32_t) ilen;
- ctx->total[0] &= 0xFFFFFFFF;
-
- if( ctx->total[0] < (uint32_t) ilen )
- ctx->total[1]++;
-
- if( left && ilen >= fill )
- {
- memcpy( (void *) (ctx->buffer + left),
- (void *) input, fill );
- mbedtls_md4_process( ctx, ctx->buffer );
- input += fill;
- ilen -= fill;
- left = 0;
- }
-
- while( ilen >= 64 )
- {
- mbedtls_md4_process( ctx, input );
- input += 64;
- ilen -= 64;
- }
-
- if( ilen > 0 )
- {
- memcpy( (void *) (ctx->buffer + left),
- (void *) input, ilen );
- }
-}
-
-static const unsigned char md4_padding[64] =
-{
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/*
- * MD4 final digest
- */
-void mbedtls_md4_finish( mbedtls_md4_context *ctx, unsigned char output[16] )
-{
- uint32_t last, padn;
- uint32_t high, low;
- unsigned char msglen[8];
-
- high = ( ctx->total[0] >> 29 )
- | ( ctx->total[1] << 3 );
- low = ( ctx->total[0] << 3 );
-
- PUT_UINT32_LE( low, msglen, 0 );
- PUT_UINT32_LE( high, msglen, 4 );
-
- last = ctx->total[0] & 0x3F;
- padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
-
- mbedtls_md4_update( ctx, (unsigned char *) md4_padding, padn );
- mbedtls_md4_update( ctx, msglen, 8 );
-
- PUT_UINT32_LE( ctx->state[0], output, 0 );
- PUT_UINT32_LE( ctx->state[1], output, 4 );
- PUT_UINT32_LE( ctx->state[2], output, 8 );
- PUT_UINT32_LE( ctx->state[3], output, 12 );
-}
-
-#endif /* !MBEDTLS_MD4_ALT */
-
-/*
- * output = MD4( input buffer )
- */
-void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] )
-{
- mbedtls_md4_context ctx;
-
- mbedtls_md4_init( &ctx );
- mbedtls_md4_starts( &ctx );
- mbedtls_md4_update( &ctx, input, ilen );
- mbedtls_md4_finish( &ctx, output );
- mbedtls_md4_free( &ctx );
-}
-
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * RFC 1320 test vectors
- */
-static const char md4_test_str[7][81] =
-{
- { "" },
- { "a" },
- { "abc" },
- { "message digest" },
- { "abcdefghijklmnopqrstuvwxyz" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
- { "12345678901234567890123456789012345678901234567890123456789012" \
- "345678901234567890" }
-};
-
-static const unsigned char md4_test_sum[7][16] =
-{
- { 0x31, 0xD6, 0xCF, 0xE0, 0xD1, 0x6A, 0xE9, 0x31,
- 0xB7, 0x3C, 0x59, 0xD7, 0xE0, 0xC0, 0x89, 0xC0 },
- { 0xBD, 0xE5, 0x2C, 0xB3, 0x1D, 0xE3, 0x3E, 0x46,
- 0x24, 0x5E, 0x05, 0xFB, 0xDB, 0xD6, 0xFB, 0x24 },
- { 0xA4, 0x48, 0x01, 0x7A, 0xAF, 0x21, 0xD8, 0x52,
- 0x5F, 0xC1, 0x0A, 0xE8, 0x7A, 0xA6, 0x72, 0x9D },
- { 0xD9, 0x13, 0x0A, 0x81, 0x64, 0x54, 0x9F, 0xE8,
- 0x18, 0x87, 0x48, 0x06, 0xE1, 0xC7, 0x01, 0x4B },
- { 0xD7, 0x9E, 0x1C, 0x30, 0x8A, 0xA5, 0xBB, 0xCD,
- 0xEE, 0xA8, 0xED, 0x63, 0xDF, 0x41, 0x2D, 0xA9 },
- { 0x04, 0x3F, 0x85, 0x82, 0xF2, 0x41, 0xDB, 0x35,
- 0x1C, 0xE6, 0x27, 0xE1, 0x53, 0xE7, 0xF0, 0xE4 },
- { 0xE3, 0x3B, 0x4D, 0xDC, 0x9C, 0x38, 0xF2, 0x19,
- 0x9C, 0x3E, 0x7B, 0x16, 0x4F, 0xCC, 0x05, 0x36 }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_md4_self_test( int verbose )
-{
- int i;
- unsigned char md4sum[16];
-
- for( i = 0; i < 7; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " MD4 test #%d: ", i + 1 );
-
- mbedtls_md4( (unsigned char *) md4_test_str[i],
- strlen( md4_test_str[i] ), md4sum );
-
- if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
-#endif /* MBEDTLS_MD4_C */
diff --git a/deps/mbedtls/md5.c b/deps/mbedtls/md5.c
index 258a3af967..ae8c084c30 100644
--- a/deps/mbedtls/md5.c
+++ b/deps/mbedtls/md5.c
@@ -36,15 +36,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_MD5_ALT)
#include "arc4_alt.h"
@@ -324,78 +315,4 @@ void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[
mbedtls_md5_free( &ctx );
}
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * RFC 1321 test vectors
- */
-static const unsigned char md5_test_buf[7][81] =
-{
- { "" },
- { "a" },
- { "abc" },
- { "message digest" },
- { "abcdefghijklmnopqrstuvwxyz" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
- { "12345678901234567890123456789012345678901234567890123456789012" \
- "345678901234567890" }
-};
-
-static const int md5_test_buflen[7] =
-{
- 0, 1, 3, 14, 26, 62, 80
-};
-
-static const unsigned char md5_test_sum[7][16] =
-{
- { 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
- 0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
- { 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
- 0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
- { 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
- 0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
- { 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
- 0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
- { 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
- 0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
- { 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
- 0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
- { 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
- 0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_md5_self_test( int verbose )
-{
- int i;
- unsigned char md5sum[16];
-
- for( i = 0; i < 7; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " MD5 test #%d: ", i + 1 );
-
- mbedtls_md5( md5_test_buf[i], md5_test_buflen[i], md5sum );
-
- if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_MD5_C */
diff --git a/deps/mbedtls/md_wrap.c b/deps/mbedtls/md_wrap.c
index 2cfcae200e..984a35f9f1 100644
--- a/deps/mbedtls/md_wrap.c
+++ b/deps/mbedtls/md_wrap.c
@@ -33,14 +33,6 @@
#include "mbedtls/md_internal.h"
-#if defined(MBEDTLS_MD2_C)
-#include "mbedtls/md2.h"
-#endif
-
-#if defined(MBEDTLS_MD4_C)
-#include "mbedtls/md4.h"
-#endif
-
#if defined(MBEDTLS_MD5_C)
#include "mbedtls/md5.h"
#endif
@@ -61,139 +53,7 @@
#include "mbedtls/sha512.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
-#if defined(MBEDTLS_MD2_C)
-
-static void md2_starts_wrap( void *ctx )
-{
- mbedtls_md2_starts( (mbedtls_md2_context *) ctx );
-}
-
-static void md2_update_wrap( void *ctx, const unsigned char *input,
- size_t ilen )
-{
- mbedtls_md2_update( (mbedtls_md2_context *) ctx, input, ilen );
-}
-
-static void md2_finish_wrap( void *ctx, unsigned char *output )
-{
- mbedtls_md2_finish( (mbedtls_md2_context *) ctx, output );
-}
-
-static void *md2_ctx_alloc( void )
-{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
-
- if( ctx != NULL )
- mbedtls_md2_init( (mbedtls_md2_context *) ctx );
-
- return( ctx );
-}
-
-static void md2_ctx_free( void *ctx )
-{
- mbedtls_md2_free( (mbedtls_md2_context *) ctx );
- mbedtls_free( ctx );
-}
-
-static void md2_clone_wrap( void *dst, const void *src )
-{
- mbedtls_md2_clone( (mbedtls_md2_context *) dst,
- (const mbedtls_md2_context *) src );
-}
-
-static void md2_process_wrap( void *ctx, const unsigned char *data )
-{
- ((void) data);
-
- mbedtls_md2_process( (mbedtls_md2_context *) ctx );
-}
-
-const mbedtls_md_info_t mbedtls_md2_info = {
- MBEDTLS_MD_MD2,
- "MD2",
- 16,
- 16,
- md2_starts_wrap,
- md2_update_wrap,
- md2_finish_wrap,
- mbedtls_md2,
- md2_ctx_alloc,
- md2_ctx_free,
- md2_clone_wrap,
- md2_process_wrap,
-};
-
-#endif /* MBEDTLS_MD2_C */
-
-#if defined(MBEDTLS_MD4_C)
-
-static void md4_starts_wrap( void *ctx )
-{
- mbedtls_md4_starts( (mbedtls_md4_context *) ctx );
-}
-
-static void md4_update_wrap( void *ctx, const unsigned char *input,
- size_t ilen )
-{
- mbedtls_md4_update( (mbedtls_md4_context *) ctx, input, ilen );
-}
-
-static void md4_finish_wrap( void *ctx, unsigned char *output )
-{
- mbedtls_md4_finish( (mbedtls_md4_context *) ctx, output );
-}
-
-static void *md4_ctx_alloc( void )
-{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
-
- if( ctx != NULL )
- mbedtls_md4_init( (mbedtls_md4_context *) ctx );
-
- return( ctx );
-}
-
-static void md4_ctx_free( void *ctx )
-{
- mbedtls_md4_free( (mbedtls_md4_context *) ctx );
- mbedtls_free( ctx );
-}
-
-static void md4_clone_wrap( void *dst, const void *src )
-{
- mbedtls_md4_clone( (mbedtls_md4_context *) dst,
- (const mbedtls_md4_context *) src );
-}
-
-static void md4_process_wrap( void *ctx, const unsigned char *data )
-{
- mbedtls_md4_process( (mbedtls_md4_context *) ctx, data );
-}
-
-const mbedtls_md_info_t mbedtls_md4_info = {
- MBEDTLS_MD_MD4,
- "MD4",
- 16,
- 64,
- md4_starts_wrap,
- md4_update_wrap,
- md4_finish_wrap,
- mbedtls_md4,
- md4_ctx_alloc,
- md4_ctx_free,
- md4_clone_wrap,
- md4_process_wrap,
-};
-
-#endif /* MBEDTLS_MD4_C */
#if defined(MBEDTLS_MD5_C)
@@ -215,7 +75,7 @@ static void md5_finish_wrap( void *ctx, unsigned char *output )
static void *md5_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_md5_context ) );
if( ctx != NULL )
mbedtls_md5_init( (mbedtls_md5_context *) ctx );
@@ -226,7 +86,7 @@ static void *md5_ctx_alloc( void )
static void md5_ctx_free( void *ctx )
{
mbedtls_md5_free( (mbedtls_md5_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void md5_clone_wrap( void *dst, const void *src )
@@ -277,7 +137,7 @@ static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
static void *ripemd160_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_ripemd160_context ) );
if( ctx != NULL )
mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
@@ -288,7 +148,7 @@ static void *ripemd160_ctx_alloc( void )
static void ripemd160_ctx_free( void *ctx )
{
mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void ripemd160_clone_wrap( void *dst, const void *src )
@@ -339,7 +199,7 @@ static void sha1_finish_wrap( void *ctx, unsigned char *output )
static void *sha1_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_sha1_context ) );
if( ctx != NULL )
mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
@@ -356,7 +216,7 @@ static void sha1_clone_wrap( void *dst, const void *src )
static void sha1_ctx_free( void *ctx )
{
mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void sha1_process_wrap( void *ctx, const unsigned char *data )
@@ -410,7 +270,7 @@ static void sha224_wrap( const unsigned char *input, size_t ilen,
static void *sha224_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_sha256_context ) );
if( ctx != NULL )
mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
@@ -421,7 +281,7 @@ static void *sha224_ctx_alloc( void )
static void sha224_ctx_free( void *ctx )
{
mbedtls_sha256_free( (mbedtls_sha256_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void sha224_clone_wrap( void *dst, const void *src )
@@ -504,7 +364,7 @@ static void sha384_wrap( const unsigned char *input, size_t ilen,
static void *sha384_ctx_alloc( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_sha512_context ) );
if( ctx != NULL )
mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
@@ -515,7 +375,7 @@ static void *sha384_ctx_alloc( void )
static void sha384_ctx_free( void *ctx )
{
mbedtls_sha512_free( (mbedtls_sha512_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void sha384_clone_wrap( void *dst, const void *src )
diff --git a/deps/mbedtls/memory_buffer_alloc.c b/deps/mbedtls/memory_buffer_alloc.c
deleted file mode 100644
index 6fb45375eb..0000000000
--- a/deps/mbedtls/memory_buffer_alloc.c
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- * Buffer-based memory allocator
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
-#include "mbedtls/memory_buffer_alloc.h"
-
-/* No need for the header guard as MBEDTLS_MEMORY_BUFFER_ALLOC_C
- is dependent upon MBEDTLS_PLATFORM_C */
-#include "mbedtls/platform.h"
-
-#include
-
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
-#include
-#endif
-
-#if defined(MBEDTLS_THREADING_C)
-#include "mbedtls/threading.h"
-#endif
-
-#include "arc4_alt.h"
-
-#define MAGIC1 0xFF00AA55
-#define MAGIC2 0xEE119966
-#define MAX_BT 20
-
-typedef struct _memory_header memory_header;
-struct _memory_header
-{
- size_t magic1;
- size_t size;
- size_t alloc;
- memory_header *prev;
- memory_header *next;
- memory_header *prev_free;
- memory_header *next_free;
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- char **trace;
- size_t trace_count;
-#endif
- size_t magic2;
-};
-
-typedef struct
-{
- unsigned char *buf;
- size_t len;
- memory_header *first;
- memory_header *first_free;
- int verify;
-#if defined(MBEDTLS_MEMORY_DEBUG)
- size_t alloc_count;
- size_t free_count;
- size_t total_used;
- size_t maximum_used;
- size_t header_count;
- size_t maximum_header_count;
-#endif
-#if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex;
-#endif
-}
-buffer_alloc_ctx;
-
-static buffer_alloc_ctx heap;
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
-static void debug_header( memory_header *hdr )
-{
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- size_t i;
-#endif
-
- mbedtls_fprintf( stderr, "HDR: PTR(%10zu), PREV(%10zu), NEXT(%10zu), "
- "ALLOC(%zu), SIZE(%10zu)\n",
- (size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next,
- hdr->alloc, hdr->size );
- mbedtls_fprintf( stderr, " FPREV(%10zu), FNEXT(%10zu)\n",
- (size_t) hdr->prev_free, (size_t) hdr->next_free );
-
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- mbedtls_fprintf( stderr, "TRACE: \n" );
- for( i = 0; i < hdr->trace_count; i++ )
- mbedtls_fprintf( stderr, "%s\n", hdr->trace[i] );
- mbedtls_fprintf( stderr, "\n" );
-#endif
-}
-
-static void debug_chain()
-{
- memory_header *cur = heap.first;
-
- mbedtls_fprintf( stderr, "\nBlock list\n" );
- while( cur != NULL )
- {
- debug_header( cur );
- cur = cur->next;
- }
-
- mbedtls_fprintf( stderr, "Free list\n" );
- cur = heap.first_free;
-
- while( cur != NULL )
- {
- debug_header( cur );
- cur = cur->next_free;
- }
-}
-#endif /* MBEDTLS_MEMORY_DEBUG */
-
-static int verify_header( memory_header *hdr )
-{
- if( hdr->magic1 != MAGIC1 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: MAGIC1 mismatch\n" );
-#endif
- return( 1 );
- }
-
- if( hdr->magic2 != MAGIC2 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: MAGIC2 mismatch\n" );
-#endif
- return( 1 );
- }
-
- if( hdr->alloc > 1 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: alloc has illegal value\n" );
-#endif
- return( 1 );
- }
-
- if( hdr->prev != NULL && hdr->prev == hdr->next )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: prev == next\n" );
-#endif
- return( 1 );
- }
-
- if( hdr->prev_free != NULL && hdr->prev_free == hdr->next_free )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: prev_free == next_free\n" );
-#endif
- return( 1 );
- }
-
- return( 0 );
-}
-
-static int verify_chain()
-{
- memory_header *prv = heap.first, *cur = heap.first->next;
-
- if( verify_header( heap.first ) != 0 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: verification of first header "
- "failed\n" );
-#endif
- return( 1 );
- }
-
- if( heap.first->prev != NULL )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: verification failed: "
- "first->prev != NULL\n" );
-#endif
- return( 1 );
- }
-
- while( cur != NULL )
- {
- if( verify_header( cur ) != 0 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: verification of header "
- "failed\n" );
-#endif
- return( 1 );
- }
-
- if( cur->prev != prv )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: verification failed: "
- "cur->prev != prv\n" );
-#endif
- return( 1 );
- }
-
- prv = cur;
- cur = cur->next;
- }
-
- return( 0 );
-}
-
-static void *buffer_alloc_calloc( size_t n, size_t size )
-{
- memory_header *new, *cur = heap.first_free;
- unsigned char *p;
- void *ret;
- size_t original_len, len;
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- void *trace_buffer[MAX_BT];
- size_t trace_cnt;
-#endif
-
- if( heap.buf == NULL || heap.first == NULL )
- return( NULL );
-
- original_len = len = n * size;
-
- if( n != 0 && len / n != size )
- return( NULL );
-
- if( len % MBEDTLS_MEMORY_ALIGN_MULTIPLE )
- {
- len -= len % MBEDTLS_MEMORY_ALIGN_MULTIPLE;
- len += MBEDTLS_MEMORY_ALIGN_MULTIPLE;
- }
-
- // Find block that fits
- //
- while( cur != NULL )
- {
- if( cur->size >= len )
- break;
-
- cur = cur->next_free;
- }
-
- if( cur == NULL )
- return( NULL );
-
- if( cur->alloc != 0 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: block in free_list but allocated "
- "data\n" );
-#endif
- mbedtls_exit( 1 );
- }
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.alloc_count++;
-#endif
-
- // Found location, split block if > memory_header + 4 room left
- //
- if( cur->size - len < sizeof(memory_header) +
- MBEDTLS_MEMORY_ALIGN_MULTIPLE )
- {
- cur->alloc = 1;
-
- // Remove from free_list
- //
- if( cur->prev_free != NULL )
- cur->prev_free->next_free = cur->next_free;
- else
- heap.first_free = cur->next_free;
-
- if( cur->next_free != NULL )
- cur->next_free->prev_free = cur->prev_free;
-
- cur->prev_free = NULL;
- cur->next_free = NULL;
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.total_used += cur->size;
- if( heap.total_used > heap.maximum_used )
- heap.maximum_used = heap.total_used;
-#endif
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- trace_cnt = backtrace( trace_buffer, MAX_BT );
- cur->trace = backtrace_symbols( trace_buffer, trace_cnt );
- cur->trace_count = trace_cnt;
-#endif
-
- if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
- mbedtls_exit( 1 );
-
- ret = (unsigned char *) cur + sizeof( memory_header );
- memset( ret, 0, original_len );
-
- return( ret );
- }
-
- p = ( (unsigned char *) cur ) + sizeof(memory_header) + len;
- new = (memory_header *) p;
-
- new->size = cur->size - len - sizeof(memory_header);
- new->alloc = 0;
- new->prev = cur;
- new->next = cur->next;
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- new->trace = NULL;
- new->trace_count = 0;
-#endif
- new->magic1 = MAGIC1;
- new->magic2 = MAGIC2;
-
- if( new->next != NULL )
- new->next->prev = new;
-
- // Replace cur with new in free_list
- //
- new->prev_free = cur->prev_free;
- new->next_free = cur->next_free;
- if( new->prev_free != NULL )
- new->prev_free->next_free = new;
- else
- heap.first_free = new;
-
- if( new->next_free != NULL )
- new->next_free->prev_free = new;
-
- cur->alloc = 1;
- cur->size = len;
- cur->next = new;
- cur->prev_free = NULL;
- cur->next_free = NULL;
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.header_count++;
- if( heap.header_count > heap.maximum_header_count )
- heap.maximum_header_count = heap.header_count;
- heap.total_used += cur->size;
- if( heap.total_used > heap.maximum_used )
- heap.maximum_used = heap.total_used;
-#endif
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- trace_cnt = backtrace( trace_buffer, MAX_BT );
- cur->trace = backtrace_symbols( trace_buffer, trace_cnt );
- cur->trace_count = trace_cnt;
-#endif
-
- if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
- mbedtls_exit( 1 );
-
- ret = (unsigned char *) cur + sizeof( memory_header );
- memset( ret, 0, original_len );
-
- return( ret );
-}
-
-static void buffer_alloc_free( void *ptr )
-{
- memory_header *hdr, *old = NULL;
- unsigned char *p = (unsigned char *) ptr;
-
- if( ptr == NULL || heap.buf == NULL || heap.first == NULL )
- return;
-
- if( p < heap.buf || p > heap.buf + heap.len )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: mbedtls_free() outside of managed "
- "space\n" );
-#endif
- mbedtls_exit( 1 );
- }
-
- p -= sizeof(memory_header);
- hdr = (memory_header *) p;
-
- if( verify_header( hdr ) != 0 )
- mbedtls_exit( 1 );
-
- if( hdr->alloc != 1 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- mbedtls_fprintf( stderr, "FATAL: mbedtls_free() on unallocated "
- "data\n" );
-#endif
- mbedtls_exit( 1 );
- }
-
- hdr->alloc = 0;
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.free_count++;
- heap.total_used -= hdr->size;
-#endif
-
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- free( hdr->trace );
- hdr->trace = NULL;
- hdr->trace_count = 0;
-#endif
-
- // Regroup with block before
- //
- if( hdr->prev != NULL && hdr->prev->alloc == 0 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.header_count--;
-#endif
- hdr->prev->size += sizeof(memory_header) + hdr->size;
- hdr->prev->next = hdr->next;
- old = hdr;
- hdr = hdr->prev;
-
- if( hdr->next != NULL )
- hdr->next->prev = hdr;
-
- memset( old, 0, sizeof(memory_header) );
- }
-
- // Regroup with block after
- //
- if( hdr->next != NULL && hdr->next->alloc == 0 )
- {
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.header_count--;
-#endif
- hdr->size += sizeof(memory_header) + hdr->next->size;
- old = hdr->next;
- hdr->next = hdr->next->next;
-
- if( hdr->prev_free != NULL || hdr->next_free != NULL )
- {
- if( hdr->prev_free != NULL )
- hdr->prev_free->next_free = hdr->next_free;
- else
- heap.first_free = hdr->next_free;
-
- if( hdr->next_free != NULL )
- hdr->next_free->prev_free = hdr->prev_free;
- }
-
- hdr->prev_free = old->prev_free;
- hdr->next_free = old->next_free;
-
- if( hdr->prev_free != NULL )
- hdr->prev_free->next_free = hdr;
- else
- heap.first_free = hdr;
-
- if( hdr->next_free != NULL )
- hdr->next_free->prev_free = hdr;
-
- if( hdr->next != NULL )
- hdr->next->prev = hdr;
-
- memset( old, 0, sizeof(memory_header) );
- }
-
- // Prepend to free_list if we have not merged
- // (Does not have to stay in same order as prev / next list)
- //
- if( old == NULL )
- {
- hdr->next_free = heap.first_free;
- if( heap.first_free != NULL )
- heap.first_free->prev_free = hdr;
- heap.first_free = hdr;
- }
-
- if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_FREE ) && verify_chain() != 0 )
- mbedtls_exit( 1 );
-}
-
-void mbedtls_memory_buffer_set_verify( int verify )
-{
- heap.verify = verify;
-}
-
-int mbedtls_memory_buffer_alloc_verify()
-{
- return verify_chain();
-}
-
-#if defined(MBEDTLS_MEMORY_DEBUG)
-void mbedtls_memory_buffer_alloc_status()
-{
- mbedtls_fprintf( stderr,
- "Current use: %zu blocks / %zu bytes, max: %zu blocks / "
- "%zu bytes (total %zu bytes), alloc / free: %zu / %zu\n",
- heap.header_count, heap.total_used,
- heap.maximum_header_count, heap.maximum_used,
- heap.maximum_header_count * sizeof( memory_header )
- + heap.maximum_used,
- heap.alloc_count, heap.free_count );
-
- if( heap.first->next == NULL )
- mbedtls_fprintf( stderr, "All memory de-allocated in stack buffer\n" );
- else
- {
- mbedtls_fprintf( stderr, "Memory currently allocated:\n" );
- debug_chain();
- }
-}
-
-void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks )
-{
- *max_used = heap.maximum_used;
- *max_blocks = heap.maximum_header_count;
-}
-
-void mbedtls_memory_buffer_alloc_max_reset( void )
-{
- heap.maximum_used = 0;
- heap.maximum_header_count = 0;
-}
-
-void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks )
-{
- *cur_used = heap.total_used;
- *cur_blocks = heap.header_count;
-}
-#endif /* MBEDTLS_MEMORY_DEBUG */
-
-#if defined(MBEDTLS_THREADING_C)
-static void *buffer_alloc_calloc_mutexed( size_t n, size_t size )
-{
- void *buf;
- if( mbedtls_mutex_lock( &heap.mutex ) != 0 )
- return( NULL );
- buf = buffer_alloc_calloc( n, size );
- if( mbedtls_mutex_unlock( &heap.mutex ) )
- return( NULL );
- return( buf );
-}
-
-static void buffer_alloc_free_mutexed( void *ptr )
-{
- /* We have to good option here, but corrupting the heap seems
- * worse than loosing memory. */
- if( mbedtls_mutex_lock( &heap.mutex ) )
- return;
- buffer_alloc_free( ptr );
- (void) mbedtls_mutex_unlock( &heap.mutex );
-}
-#endif /* MBEDTLS_THREADING_C */
-
-void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len )
-{
- memset( &heap, 0, sizeof(buffer_alloc_ctx) );
- memset( buf, 0, len );
-
-#if defined(MBEDTLS_THREADING_C)
- mbedtls_mutex_init( &heap.mutex );
- mbedtls_platform_set_calloc_free( buffer_alloc_calloc_mutexed,
- buffer_alloc_free_mutexed );
-#else
- mbedtls_platform_set_calloc_free( buffer_alloc_calloc, buffer_alloc_free );
-#endif
-
- if( (size_t) buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE )
- {
- /* Adjust len first since buf is used in the computation */
- len -= MBEDTLS_MEMORY_ALIGN_MULTIPLE
- - (size_t) buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE;
- buf += MBEDTLS_MEMORY_ALIGN_MULTIPLE
- - (size_t) buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE;
- }
-
- heap.buf = buf;
- heap.len = len;
-
- heap.first = (memory_header *) buf;
- heap.first->size = len - sizeof(memory_header);
- heap.first->magic1 = MAGIC1;
- heap.first->magic2 = MAGIC2;
- heap.first_free = heap.first;
-}
-
-void mbedtls_memory_buffer_alloc_free()
-{
-#if defined(MBEDTLS_THREADING_C)
- mbedtls_mutex_free( &heap.mutex );
-#endif
- mbedtls_zeroize( &heap, sizeof(buffer_alloc_ctx) );
-}
-
-#if defined(MBEDTLS_SELF_TEST)
-static int check_pointer( void *p )
-{
- if( p == NULL )
- return( -1 );
-
- if( (size_t) p % MBEDTLS_MEMORY_ALIGN_MULTIPLE != 0 )
- return( -1 );
-
- return( 0 );
-}
-
-static int check_all_free( )
-{
- if(
-#if defined(MBEDTLS_MEMORY_DEBUG)
- heap.total_used != 0 ||
-#endif
- heap.first != heap.first_free ||
- (void *) heap.first != (void *) heap.buf )
- {
- return( -1 );
- }
-
- return( 0 );
-}
-
-#define TEST_ASSERT( condition ) \
- if( ! (condition) ) \
- { \
- if( verbose != 0 ) \
- mbedtls_printf( "failed\n" ); \
- \
- ret = 1; \
- goto cleanup; \
- }
-
-int mbedtls_memory_buffer_alloc_self_test( int verbose )
-{
- unsigned char buf[1024];
- unsigned char *p, *q, *r, *end;
- int ret = 0;
-
- if( verbose != 0 )
- mbedtls_printf( " MBA test #1 (basic alloc-free cycle): " );
-
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
-
- p = mbedtls_calloc( 1, 1 );
- q = mbedtls_calloc( 1, 128 );
- r = mbedtls_calloc( 1, 16 );
-
- TEST_ASSERT( check_pointer( p ) == 0 &&
- check_pointer( q ) == 0 &&
- check_pointer( r ) == 0 );
-
- mbedtls_free( r );
- mbedtls_free( q );
- mbedtls_free( p );
-
- TEST_ASSERT( check_all_free( ) == 0 );
-
- /* Memorize end to compare with the next test */
- end = heap.buf + heap.len;
-
- mbedtls_memory_buffer_alloc_free( );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " MBA test #2 (buf not aligned): " );
-
- mbedtls_memory_buffer_alloc_init( buf + 1, sizeof( buf ) - 1 );
-
- TEST_ASSERT( heap.buf + heap.len == end );
-
- p = mbedtls_calloc( 1, 1 );
- q = mbedtls_calloc( 1, 128 );
- r = mbedtls_calloc( 1, 16 );
-
- TEST_ASSERT( check_pointer( p ) == 0 &&
- check_pointer( q ) == 0 &&
- check_pointer( r ) == 0 );
-
- mbedtls_free( r );
- mbedtls_free( q );
- mbedtls_free( p );
-
- TEST_ASSERT( check_all_free( ) == 0 );
-
- mbedtls_memory_buffer_alloc_free( );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " MBA test #3 (full): " );
-
- mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
-
- p = mbedtls_calloc( 1, sizeof( buf ) - sizeof( memory_header ) );
-
- TEST_ASSERT( check_pointer( p ) == 0 );
- TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
-
- mbedtls_free( p );
-
- p = mbedtls_calloc( 1, sizeof( buf ) - 2 * sizeof( memory_header ) - 16 );
- q = mbedtls_calloc( 1, 16 );
-
- TEST_ASSERT( check_pointer( p ) == 0 && check_pointer( q ) == 0 );
- TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
-
- mbedtls_free( q );
-
- TEST_ASSERT( mbedtls_calloc( 1, 17 ) == NULL );
-
- mbedtls_free( p );
-
- TEST_ASSERT( check_all_free( ) == 0 );
-
- mbedtls_memory_buffer_alloc_free( );
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-cleanup:
- mbedtls_memory_buffer_alloc_free( );
-
- return( ret );
-}
-#endif /* MBEDTLS_SELF_TEST */
-
-#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
diff --git a/deps/mbedtls/net_sockets.c b/deps/mbedtls/net_sockets.c
index f8ae7f6d32..8818f13116 100644
--- a/deps/mbedtls/net_sockets.c
+++ b/deps/mbedtls/net_sockets.c
@@ -36,16 +36,11 @@
#error "This module only works on Unix and Windows, see MBEDTLS_NET_C in config.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#endif
+#include
#include "mbedtls/net_sockets.h"
-#include
-
#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
!defined(EFI32)
@@ -319,9 +314,11 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
int type_len = (int) sizeof( type );
#endif
+ client_addr.ss_family = 0;
+
/* Is this a TCP or UDP socket? */
if( getsockopt( bind_ctx->fd, SOL_SOCKET, SO_TYPE,
- (void *) &type, &type_len ) != 0 ||
+ (char *) &type, &type_len ) != 0 ||
( type != SOCK_STREAM && type != SOCK_DGRAM ) )
{
return( MBEDTLS_ERR_NET_ACCEPT_FAILED );
@@ -363,16 +360,18 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
* then bind a new socket to accept new connections */
if( type != SOCK_STREAM )
{
- struct sockaddr_storage local_addr;
int one = 1;
+ struct sockaddr_storage local_addr;
+
+ local_addr.ss_family = 0;
if( connect( bind_ctx->fd, (struct sockaddr *) &client_addr, n ) != 0 )
return( MBEDTLS_ERR_NET_ACCEPT_FAILED );
- client_ctx->fd = bind_ctx->fd;
- bind_ctx->fd = -1; /* In case we exit early */
+ client_ctx->fd = bind_ctx->fd;
+ bind_ctx->fd = -1; /* In case we exit early */
- n = sizeof( struct sockaddr_storage );
+ n = sizeof( struct sockaddr_storage );
if( getsockname( client_ctx->fd,
(struct sockaddr *) &local_addr, &n ) != 0 ||
( bind_ctx->fd = (int) socket( local_addr.ss_family,
@@ -484,7 +483,7 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len )
if( ret < 0 )
{
- if( net_would_block( ctx ) != 0 )
+ if( net_would_block((const mbedtls_net_context*)ctx ) != 0 )
return( MBEDTLS_ERR_SSL_WANT_READ );
#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
diff --git a/deps/mbedtls/oid.c b/deps/mbedtls/oid.c
index f13826ed74..2b4d733202 100644
--- a/deps/mbedtls/oid.c
+++ b/deps/mbedtls/oid.c
@@ -35,12 +35,6 @@
#include
#include
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#define mbedtls_snprintf snprintf
-#endif
-
#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
#include "mbedtls/x509.h"
#endif
@@ -315,18 +309,6 @@ typedef struct {
static const oid_sig_alg_t oid_sig_alg[] =
{
#if defined(MBEDTLS_RSA_C)
-#if defined(MBEDTLS_MD2_C)
- {
- { ADD_LEN( MBEDTLS_OID_PKCS1_MD2 ), "md2WithRSAEncryption", "RSA with MD2" },
- MBEDTLS_MD_MD2, MBEDTLS_PK_RSA,
- },
-#endif /* MBEDTLS_MD2_C */
-#if defined(MBEDTLS_MD4_C)
- {
- { ADD_LEN( MBEDTLS_OID_PKCS1_MD4 ), "md4WithRSAEncryption", "RSA with MD4" },
- MBEDTLS_MD_MD4, MBEDTLS_PK_RSA,
- },
-#endif /* MBEDTLS_MD4_C */
#if defined(MBEDTLS_MD5_C)
{
{ ADD_LEN( MBEDTLS_OID_PKCS1_MD5 ), "md5WithRSAEncryption", "RSA with MD5" },
@@ -572,18 +554,6 @@ typedef struct {
static const oid_md_alg_t oid_md_alg[] =
{
-#if defined(MBEDTLS_MD2_C)
- {
- { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD2 ), "id-md2", "MD2" },
- MBEDTLS_MD_MD2,
- },
-#endif /* MBEDTLS_MD2_C */
-#if defined(MBEDTLS_MD4_C)
- {
- { ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD4 ), "id-md4", "MD4" },
- MBEDTLS_MD_MD4,
- },
-#endif /* MBEDTLS_MD4_C */
#if defined(MBEDTLS_MD5_C)
{
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD5 ), "id-md5", "MD5" },
@@ -681,7 +651,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size,
/* First byte contains first two dots */
if( oid->len > 0 )
{
- ret = mbedtls_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
+ ret = snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
OID_SAFE_SNPRINTF;
}
@@ -698,7 +668,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size,
if( !( oid->p[i] & 0x80 ) )
{
/* Last byte */
- ret = mbedtls_snprintf( p, n, ".%d", value );
+ ret = snprintf( p, n, ".%d", value );
OID_SAFE_SNPRINTF;
value = 0;
}
diff --git a/deps/mbedtls/pem.c b/deps/mbedtls/pem.c
index 2995d7fd70..70ce7887ac 100644
--- a/deps/mbedtls/pem.c
+++ b/deps/mbedtls/pem.c
@@ -34,15 +34,8 @@
#include "mbedtls/md5.h"
#include "mbedtls/cipher.h"
-#include
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#if defined(MBEDTLS_PEM_PARSE_C)
#include "arc4_alt.h"
@@ -323,12 +316,12 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER )
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
- if( ( buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL )
+ if( ( buf = (unsigned char*)calloc( 1, len ) ) == NULL )
return( MBEDTLS_ERR_PEM_ALLOC_FAILED );
if( ( ret = mbedtls_base64_decode( buf, len, &len, s1, s2 - s1 ) ) != 0 )
{
- mbedtls_free( buf );
+ free( buf );
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
}
@@ -338,7 +331,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
if( pwd == NULL )
{
- mbedtls_free( buf );
+ free( buf );
return( MBEDTLS_ERR_PEM_PASSWORD_REQUIRED );
}
@@ -366,11 +359,11 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
*/
if( len <= 2 || buf[0] != 0x30 || buf[1] > 0x83 )
{
- mbedtls_free( buf );
+ free( buf );
return( MBEDTLS_ERR_PEM_PASSWORD_MISMATCH );
}
#else
- mbedtls_free( buf );
+ free( buf );
return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE );
#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC &&
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
@@ -384,8 +377,8 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
void mbedtls_pem_free( mbedtls_pem_context *ctx )
{
- mbedtls_free( ctx->buf );
- mbedtls_free( ctx->info );
+ free( ctx->buf );
+ free( ctx->info );
mbedtls_zeroize( ctx, sizeof( mbedtls_pem_context ) );
}
@@ -409,13 +402,13 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer,
return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
}
- if( ( encode_buf = (unsigned char*)mbedtls_calloc( 1, use_len ) ) == NULL )
+ if( ( encode_buf = (unsigned char*)calloc( 1, use_len ) ) == NULL )
return( MBEDTLS_ERR_PEM_ALLOC_FAILED );
if( ( ret = mbedtls_base64_encode( encode_buf, use_len, &use_len, der_data,
der_len ) ) != 0 )
{
- mbedtls_free( encode_buf );
+ free( encode_buf );
return( ret );
}
@@ -439,7 +432,7 @@ int mbedtls_pem_write_buffer( const char *header, const char *footer,
*p++ = '\0';
*olen = p - buf;
- mbedtls_free( encode_buf );
+ free( encode_buf );
return( 0 );
}
#endif /* MBEDTLS_PEM_WRITE_C */
diff --git a/deps/mbedtls/pk_wrap.c b/deps/mbedtls/pk_wrap.c
index 382bbb46d8..e92bae0ac1 100644
--- a/deps/mbedtls/pk_wrap.c
+++ b/deps/mbedtls/pk_wrap.c
@@ -42,14 +42,7 @@
#include "mbedtls/ecdsa.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
#include
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
@@ -143,7 +136,7 @@ static int rsa_check_pair_wrap( const void *pub, const void *prv )
static void *rsa_alloc_wrap( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_rsa_context ) );
if( ctx != NULL )
mbedtls_rsa_init( (mbedtls_rsa_context *) ctx, 0, 0 );
@@ -154,7 +147,7 @@ static void *rsa_alloc_wrap( void )
static void rsa_free_wrap( void *ctx )
{
mbedtls_rsa_free( (mbedtls_rsa_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void rsa_debug( const void *ctx, mbedtls_pk_debug_item *items )
@@ -222,7 +215,8 @@ static int eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
mbedtls_ecdsa_init( &ecdsa );
- if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 )
+ if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa,
+ (const mbedtls_ecp_keypair*)ctx ) ) == 0 )
ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len );
mbedtls_ecdsa_free( &ecdsa );
@@ -240,7 +234,8 @@ static int eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
mbedtls_ecdsa_init( &ecdsa );
- if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 )
+ if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa,
+ (const mbedtls_ecp_keypair*)ctx ) ) == 0 )
ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len,
f_rng, p_rng );
@@ -259,10 +254,10 @@ static int eckey_check_pair( const void *pub, const void *prv )
static void *eckey_alloc_wrap( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_ecp_keypair ) );
if( ctx != NULL )
- mbedtls_ecp_keypair_init( ctx );
+ mbedtls_ecp_keypair_init((mbedtls_ecp_keypair*)ctx);
return( ctx );
}
@@ -270,7 +265,7 @@ static void *eckey_alloc_wrap( void )
static void eckey_free_wrap( void *ctx )
{
mbedtls_ecp_keypair_free( (mbedtls_ecp_keypair *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
static void eckey_debug( const void *ctx, mbedtls_pk_debug_item *items )
@@ -358,7 +353,7 @@ static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
static void *ecdsa_alloc_wrap( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_ecdsa_context ) );
if( ctx != NULL )
mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx );
@@ -369,7 +364,7 @@ static void *ecdsa_alloc_wrap( void )
static void ecdsa_free_wrap( void *ctx )
{
mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx );
- mbedtls_free( ctx );
+ free( ctx );
}
const mbedtls_pk_info_t mbedtls_ecdsa_info = {
@@ -472,7 +467,7 @@ static int rsa_alt_check_pair( const void *pub, const void *prv )
static void *rsa_alt_alloc_wrap( void )
{
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_alt_context ) );
+ void *ctx = calloc( 1, sizeof( mbedtls_rsa_alt_context ) );
if( ctx != NULL )
memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) );
@@ -483,7 +478,7 @@ static void *rsa_alt_alloc_wrap( void )
static void rsa_alt_free_wrap( void *ctx )
{
mbedtls_zeroize( ctx, sizeof( mbedtls_rsa_alt_context ) );
- mbedtls_free( ctx );
+ free( ctx );
}
const mbedtls_pk_info_t mbedtls_rsa_alt_info = {
diff --git a/deps/mbedtls/pkcs11.c b/deps/mbedtls/pkcs11.c
deleted file mode 100644
index 0ea64252ee..0000000000
--- a/deps/mbedtls/pkcs11.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/**
- * \file pkcs11.c
- *
- * \brief Wrapper for PKCS#11 library libpkcs11-helper
- *
- * \author Adriaan de Jong
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#include "mbedtls/pkcs11.h"
-
-#if defined(MBEDTLS_PKCS11_C)
-
-#include "mbedtls/md.h"
-#include "mbedtls/oid.h"
-#include "mbedtls/x509_crt.h"
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
-#include
-
-void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx )
-{
- memset( ctx, 0, sizeof( mbedtls_pkcs11_context ) );
-}
-
-int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11_cert )
-{
- int ret = 1;
- unsigned char *cert_blob = NULL;
- size_t cert_blob_size = 0;
-
- if( cert == NULL )
- {
- ret = 2;
- goto cleanup;
- }
-
- if( pkcs11h_certificate_getCertificateBlob( pkcs11_cert, NULL,
- &cert_blob_size ) != CKR_OK )
- {
- ret = 3;
- goto cleanup;
- }
-
- cert_blob = mbedtls_calloc( 1, cert_blob_size );
- if( NULL == cert_blob )
- {
- ret = 4;
- goto cleanup;
- }
-
- if( pkcs11h_certificate_getCertificateBlob( pkcs11_cert, cert_blob,
- &cert_blob_size ) != CKR_OK )
- {
- ret = 5;
- goto cleanup;
- }
-
- if( 0 != mbedtls_x509_crt_parse( cert, cert_blob, cert_blob_size ) )
- {
- ret = 6;
- goto cleanup;
- }
-
- ret = 0;
-
-cleanup:
- if( NULL != cert_blob )
- mbedtls_free( cert_blob );
-
- return( ret );
-}
-
-
-int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
- pkcs11h_certificate_t pkcs11_cert )
-{
- int ret = 1;
- mbedtls_x509_crt cert;
-
- mbedtls_x509_crt_init( &cert );
-
- if( priv_key == NULL )
- goto cleanup;
-
- if( 0 != mbedtls_pkcs11_x509_cert_bind( &cert, pkcs11_cert ) )
- goto cleanup;
-
- priv_key->len = mbedtls_pk_get_len( &cert.pk );
- priv_key->pkcs11h_cert = pkcs11_cert;
-
- ret = 0;
-
-cleanup:
- mbedtls_x509_crt_free( &cert );
-
- return( ret );
-}
-
-void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key )
-{
- if( NULL != priv_key )
- pkcs11h_certificate_freeCertificate( priv_key->pkcs11h_cert );
-}
-
-int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
- int mode, size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len )
-{
- size_t input_len, output_len;
-
- if( NULL == ctx )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- if( MBEDTLS_RSA_PRIVATE != mode )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- output_len = input_len = ctx->len;
-
- if( input_len < 16 || input_len > output_max_len )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- /* Determine size of output buffer */
- if( pkcs11h_certificate_decryptAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, input,
- input_len, NULL, &output_len ) != CKR_OK )
- {
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
- }
-
- if( output_len > output_max_len )
- return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE );
-
- if( pkcs11h_certificate_decryptAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, input,
- input_len, output, &output_len ) != CKR_OK )
- {
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
- }
- *olen = output_len;
- return( 0 );
-}
-
-int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig )
-{
- size_t sig_len = 0, asn_len = 0, oid_size = 0;
- unsigned char *p = sig;
- const char *oid;
-
- if( NULL == ctx )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- if( MBEDTLS_RSA_PRIVATE != mode )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- if( md_alg != MBEDTLS_MD_NONE )
- {
- const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg );
- if( md_info == NULL )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- if( mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ) != 0 )
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
-
- hashlen = mbedtls_md_get_size( md_info );
- asn_len = 10 + oid_size;
- }
-
- sig_len = ctx->len;
- if( hashlen > sig_len || asn_len > sig_len ||
- hashlen + asn_len > sig_len )
- {
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
- }
-
- if( md_alg != MBEDTLS_MD_NONE )
- {
- /*
- * DigestInfo ::= SEQUENCE {
- * digestAlgorithm DigestAlgorithmIdentifier,
- * digest Digest }
- *
- * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
- *
- * Digest ::= OCTET STRING
- */
- *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ = (unsigned char) ( 0x08 + oid_size + hashlen );
- *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ = (unsigned char) ( 0x04 + oid_size );
- *p++ = MBEDTLS_ASN1_OID;
- *p++ = oid_size & 0xFF;
- memcpy( p, oid, oid_size );
- p += oid_size;
- *p++ = MBEDTLS_ASN1_NULL;
- *p++ = 0x00;
- *p++ = MBEDTLS_ASN1_OCTET_STRING;
- *p++ = hashlen;
- }
-
- memcpy( p, hash, hashlen );
-
- if( pkcs11h_certificate_signAny( ctx->pkcs11h_cert, CKM_RSA_PKCS, sig,
- asn_len + hashlen, sig, &sig_len ) != CKR_OK )
- {
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
- }
-
- return( 0 );
-}
-
-#endif /* defined(MBEDTLS_PKCS11_C) */
diff --git a/deps/mbedtls/pkcs5.c b/deps/mbedtls/pkcs5.c
index 2d3aea40b0..c4f6df4f08 100644
--- a/deps/mbedtls/pkcs5.c
+++ b/deps/mbedtls/pkcs5.c
@@ -42,14 +42,8 @@
#include "mbedtls/cipher.h"
#include "mbedtls/oid.h"
-#include
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_printf printf
-#endif
+#include
static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
mbedtls_asn1_buf *salt, int *iterations,
@@ -281,122 +275,4 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
return( 0 );
}
-#if defined(MBEDTLS_SELF_TEST)
-
-#if !defined(MBEDTLS_SHA1_C)
-int mbedtls_pkcs5_self_test( int verbose )
-{
- if( verbose != 0 )
- mbedtls_printf( " PBKDF2 (SHA1): skipped\n\n" );
-
- return( 0 );
-}
-#else
-
-#define MAX_TESTS 6
-
-static const size_t plen[MAX_TESTS] =
- { 8, 8, 8, 24, 9 };
-
-static const unsigned char password[MAX_TESTS][32] =
-{
- "password",
- "password",
- "password",
- "passwordPASSWORDpassword",
- "pass\0word",
-};
-
-static const size_t slen[MAX_TESTS] =
- { 4, 4, 4, 36, 5 };
-
-static const unsigned char salt[MAX_TESTS][40] =
-{
- "salt",
- "salt",
- "salt",
- "saltSALTsaltSALTsaltSALTsaltSALTsalt",
- "sa\0lt",
-};
-
-static const uint32_t it_cnt[MAX_TESTS] =
- { 1, 2, 4096, 4096, 4096 };
-
-static const uint32_t key_len[MAX_TESTS] =
- { 20, 20, 20, 25, 16 };
-
-static const unsigned char result_key[MAX_TESTS][32] =
-{
- { 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
- 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
- 0x2f, 0xe0, 0x37, 0xa6 },
- { 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
- 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
- 0xd8, 0xde, 0x89, 0x57 },
- { 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
- 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
- 0x65, 0xa4, 0x29, 0xc1 },
- { 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
- 0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
- 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
- 0x38 },
- { 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
- 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 },
-};
-
-int mbedtls_pkcs5_self_test( int verbose )
-{
- mbedtls_md_context_t sha1_ctx;
- const mbedtls_md_info_t *info_sha1;
- int ret, i;
- unsigned char key[64];
-
- mbedtls_md_init( &sha1_ctx );
-
- info_sha1 = mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 );
- if( info_sha1 == NULL )
- {
- ret = 1;
- goto exit;
- }
-
- if( ( ret = mbedtls_md_setup( &sha1_ctx, info_sha1, 1 ) ) != 0 )
- {
- ret = 1;
- goto exit;
- }
-
- for( i = 0; i < MAX_TESTS; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " PBKDF2 (SHA1) #%d: ", i );
-
- ret = mbedtls_pkcs5_pbkdf2_hmac( &sha1_ctx, password[i], plen[i], salt[i],
- slen[i], it_cnt[i], key_len[i], key );
- if( ret != 0 ||
- memcmp( result_key[i], key, key_len[i] ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_md_free( &sha1_ctx );
-
- return( ret );
-}
-#endif /* MBEDTLS_SHA1_C */
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_PKCS5_C */
diff --git a/deps/mbedtls/pkparse.c b/deps/mbedtls/pkparse.c
index 99d5c45ea1..dae2e1efdf 100644
--- a/deps/mbedtls/pkparse.c
+++ b/deps/mbedtls/pkparse.c
@@ -52,13 +52,7 @@
#include "mbedtls/pkcs12.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#if defined(MBEDTLS_FS_IO)
#include "arc4_alt.h"
@@ -89,7 +83,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n )
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL )
+ ( *buf = (unsigned char*)calloc( 1, *n + 1 ) ) == NULL )
{
fclose( f );
return( MBEDTLS_ERR_PK_ALLOC_FAILED );
@@ -98,7 +92,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n )
if( fread( *buf, 1, *n, f ) != *n )
{
fclose( f );
- mbedtls_free( *buf );
+ free( *buf );
return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
}
@@ -132,7 +126,7 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
(const unsigned char *) pwd, strlen( pwd ) );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
@@ -152,7 +146,7 @@ int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path )
ret = mbedtls_pk_parse_public_key( ctx, buf, n );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
diff --git a/deps/mbedtls/pkwrite.c b/deps/mbedtls/pkwrite.c
index 83b798c119..efbc323176 100644
--- a/deps/mbedtls/pkwrite.c
+++ b/deps/mbedtls/pkwrite.c
@@ -46,13 +46,7 @@
#include "mbedtls/pem.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#if defined(MBEDTLS_RSA_C)
/*
diff --git a/deps/mbedtls/platform.c b/deps/mbedtls/platform.c
deleted file mode 100644
index af3b2f15ec..0000000000
--- a/deps/mbedtls/platform.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Platform abstraction layer
- *
- * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_PLATFORM_C)
-
-#include "mbedtls/platform.h"
-
-#if defined(MBEDTLS_PLATFORM_MEMORY)
-#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
-static void *platform_calloc_uninit( size_t n, size_t size )
-{
- ((void) n);
- ((void) size);
- return( NULL );
-}
-
-#define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
-
-#if !defined(MBEDTLS_PLATFORM_STD_FREE)
-static void platform_free_uninit( void *ptr )
-{
- ((void) ptr);
-}
-
-#define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_FREE */
-
-void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
-void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
-
-int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
- void (*free_func)( void * ) )
-{
- mbedtls_calloc = calloc_func;
- mbedtls_free = free_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_MEMORY */
-
-#if defined(_WIN32)
-#include
-int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
-{
- int ret;
- va_list argp;
-
- /* Avoid calling the invalid parameter handler by checking ourselves */
- if( s == NULL || n == 0 || fmt == NULL )
- return( -1 );
-
- va_start( argp, fmt );
-#if defined(_TRUNCATE)
- ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
-#else
- ret = _vsnprintf( s, n, fmt, argp );
- if( ret < 0 || (size_t) ret == n )
- {
- s[n-1] = '\0';
- ret = -1;
- }
-#endif
- va_end( argp );
-
- return( ret );
-}
-#endif
-
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static int platform_snprintf_uninit( char * s, size_t n,
- const char * format, ... )
-{
- ((void) s);
- ((void) n);
- ((void) format);
- return( 0 );
-}
-
-#define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
-
-int (*mbedtls_snprintf)( char * s, size_t n,
- const char * format,
- ... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
-
-int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
- const char * format,
- ... ) )
-{
- mbedtls_snprintf = snprintf_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
-
-#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static int platform_printf_uninit( const char *format, ... )
-{
- ((void) format);
- return( 0 );
-}
-
-#define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
-
-int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
-
-int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
-{
- mbedtls_printf = printf_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
-
-#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
-{
- ((void) stream);
- ((void) format);
- return( 0 );
-}
-
-#define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
-
-int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
- MBEDTLS_PLATFORM_STD_FPRINTF;
-
-int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
-{
- mbedtls_fprintf = fprintf_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
-
-#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static void platform_exit_uninit( int status )
-{
- ((void) status);
-}
-
-#define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_EXIT */
-
-void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
-
-int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
-{
- mbedtls_exit = exit_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
-
-#if defined(MBEDTLS_HAVE_TIME)
-
-#if defined(MBEDTLS_PLATFORM_TIME_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_TIME)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static mbedtls_time_t platform_time_uninit( mbedtls_time_t* timer )
-{
- ((void) timer);
- return( 0 );
-}
-
-#define MBEDTLS_PLATFORM_STD_TIME platform_time_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_TIME */
-
-mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* timer ) = MBEDTLS_PLATFORM_STD_TIME;
-
-int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* timer ) )
-{
- mbedtls_time = time_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_TIME_ALT */
-
-#endif /* MBEDTLS_HAVE_TIME */
-
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
-#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
-/* Default implementations for the platform independent seed functions use
- * standard libc file functions to read from and write to a pre-defined filename
- */
-int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len )
-{
- FILE *file;
- size_t n;
-
- if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL )
- return -1;
-
- if( ( n = fread( buf, 1, buf_len, file ) ) != buf_len )
- {
- fclose( file );
- return -1;
- }
-
- fclose( file );
- return( (int)n );
-}
-
-int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
-{
- FILE *file;
- size_t n;
-
- if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL )
- return -1;
-
- if( ( n = fwrite( buf, 1, buf_len, file ) ) != buf_len )
- {
- fclose( file );
- return -1;
- }
-
- fclose( file );
- return( (int)n );
-}
-#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
-
-#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
-#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static int platform_nv_seed_read_uninit( unsigned char *buf, size_t buf_len )
-{
- ((void) buf);
- ((void) buf_len);
- return( -1 );
-}
-
-#define MBEDTLS_PLATFORM_STD_NV_SEED_READ platform_nv_seed_read_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_READ */
-
-#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
-/*
- * Make dummy function to prevent NULL pointer dereferences
- */
-static int platform_nv_seed_write_uninit( unsigned char *buf, size_t buf_len )
-{
- ((void) buf);
- ((void) buf_len);
- return( -1 );
-}
-
-#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE platform_nv_seed_write_uninit
-#endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_WRITE */
-
-int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
- MBEDTLS_PLATFORM_STD_NV_SEED_READ;
-int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
- MBEDTLS_PLATFORM_STD_NV_SEED_WRITE;
-
-int mbedtls_platform_set_nv_seed(
- int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
- int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len ) )
-{
- mbedtls_nv_seed_read = nv_seed_read_func;
- mbedtls_nv_seed_write = nv_seed_write_func;
- return( 0 );
-}
-#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
-
-#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
-/*
- * Placeholder platform setup that does nothing by default
- */
-int mbedtls_platform_setup( mbedtls_platform_context *ctx )
-{
- (void)ctx;
-
- return( 0 );
-}
-
-/*
- * Placeholder platform teardown that does nothing by default
- */
-void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
-{
- (void)ctx;
-}
-#endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
-
-#endif /* MBEDTLS_PLATFORM_C */
diff --git a/deps/mbedtls/ripemd160.c b/deps/mbedtls/ripemd160.c
index 20080d4fba..1c6a441617 100644
--- a/deps/mbedtls/ripemd160.c
+++ b/deps/mbedtls/ripemd160.c
@@ -37,15 +37,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
/*
* 32-bit integer manipulation macros (little endian)
*/
@@ -392,83 +383,4 @@ void mbedtls_ripemd160( const unsigned char *input, size_t ilen,
mbedtls_ripemd160_free( &ctx );
}
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * Test vectors from the RIPEMD-160 paper and
- * http://homes.esat.kuleuven.be/~bosselae/mbedtls_ripemd160.html#HMAC
- */
-#define TESTS 8
-#define KEYS 2
-static const char *ripemd160_test_input[TESTS] =
-{
- "",
- "a",
- "abc",
- "message digest",
- "abcdefghijklmnopqrstuvwxyz",
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
-};
-
-static const unsigned char ripemd160_test_md[TESTS][20] =
-{
- { 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28,
- 0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31 },
- { 0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae,
- 0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe },
- { 0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04,
- 0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc },
- { 0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8,
- 0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36 },
- { 0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb,
- 0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc },
- { 0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05,
- 0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b },
- { 0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed,
- 0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89 },
- { 0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb,
- 0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb },
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_ripemd160_self_test( int verbose )
-{
- int i;
- unsigned char output[20];
-
- memset( output, 0, sizeof output );
-
- for( i = 0; i < TESTS; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " RIPEMD-160 test #%d: ", i + 1 );
-
- mbedtls_ripemd160( (const unsigned char *) ripemd160_test_input[i],
- strlen( ripemd160_test_input[i] ),
- output );
-
- if( memcmp( output, ripemd160_test_md[i], 20 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_RIPEMD160_C */
diff --git a/deps/mbedtls/rsa.c b/deps/mbedtls/rsa.c
index 030a6326db..fb19f441ce 100644
--- a/deps/mbedtls/rsa.c
+++ b/deps/mbedtls/rsa.c
@@ -53,18 +53,8 @@
#include "mbedtls/md.h"
#endif
-#if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__)
-#include
-#endif
-
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#include "arc4_alt.h"
@@ -397,14 +387,9 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
size_t olen;
mbedtls_mpi T, T1, T2;
mbedtls_mpi P1, Q1, R;
-#if defined(MBEDTLS_RSA_NO_CRT)
- mbedtls_mpi D_blind;
- mbedtls_mpi *D = &ctx->D;
-#else
mbedtls_mpi DP_blind, DQ_blind;
mbedtls_mpi *DP = &ctx->DP;
mbedtls_mpi *DQ = &ctx->DQ;
-#endif
/* Make sure we have private key info, prevent possible misuse */
if( ctx->P.p == NULL || ctx->Q.p == NULL || ctx->D.p == NULL )
@@ -416,12 +401,8 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
if( f_rng != NULL )
{
-#if defined(MBEDTLS_RSA_NO_CRT)
- mbedtls_mpi_init( &D_blind );
-#else
mbedtls_mpi_init( &DP_blind );
mbedtls_mpi_init( &DQ_blind );
-#endif
}
@@ -453,18 +434,6 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &P1, &ctx->P, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &Q1, &ctx->Q, 1 ) );
-#if defined(MBEDTLS_RSA_NO_CRT)
- /*
- * D_blind = ( P - 1 ) * ( Q - 1 ) * R + D
- */
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING,
- f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &P1, &Q1 ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &D_blind, &R ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &D_blind, &D_blind, &ctx->D ) );
-
- D = &D_blind;
-#else
/*
* DP_blind = ( P - 1 ) * R + DP
*/
@@ -486,12 +455,8 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
&ctx->DQ ) );
DQ = &DQ_blind;
-#endif /* MBEDTLS_RSA_NO_CRT */
}
-#if defined(MBEDTLS_RSA_NO_CRT)
- MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T, &T, D, &ctx->N, &ctx->RN ) );
-#else
/*
* Faster decryption using the CRT
*
@@ -513,7 +478,6 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T1, &T, &ctx->Q ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &T, &T2, &T1 ) );
-#endif /* MBEDTLS_RSA_NO_CRT */
if( f_rng != NULL )
{
@@ -539,12 +503,8 @@ cleanup:
if( f_rng != NULL )
{
-#if defined(MBEDTLS_RSA_NO_CRT)
- mbedtls_mpi_free( &D_blind );
-#else
mbedtls_mpi_free( &DP_blind );
mbedtls_mpi_free( &DQ_blind );
-#endif
}
if( ret != 0 )
@@ -1232,14 +1192,14 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
* In order to prevent Lenstra's attack, make the signature in a
* temporary buffer and check it before returning it.
*/
- sig_try = mbedtls_calloc( 1, ctx->len );
- if( sig_try == NULL )
+ sig_try = (unsigned char*)calloc( 1, ctx->len );
+ if (!sig_try)
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
- verif = mbedtls_calloc( 1, ctx->len );
- if( verif == NULL )
+ verif = (unsigned char*)calloc( 1, ctx->len );
+ if (!verif)
{
- mbedtls_free( sig_try );
+ free( sig_try );
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
}
@@ -1260,8 +1220,8 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
memcpy( sig, sig_try, ctx->len );
cleanup:
- mbedtls_free( sig_try );
- mbedtls_free( verif );
+ free( sig_try );
+ free( verif );
return( ret );
}
@@ -1664,206 +1624,4 @@ void mbedtls_rsa_free( mbedtls_rsa_context *ctx )
#endif
}
-#if defined(MBEDTLS_SELF_TEST)
-
-#include "mbedtls/sha1.h"
-
-/*
- * Example RSA-1024 keypair, for test purposes
- */
-#define KEY_LEN 128
-
-#define RSA_N "9292758453063D803DD603D5E777D788" \
- "8ED1D5BF35786190FA2F23EBC0848AEA" \
- "DDA92CA6C3D80B32C4D109BE0F36D6AE" \
- "7130B9CED7ACDF54CFC7555AC14EEBAB" \
- "93A89813FBF3C4F8066D2D800F7C38A8" \
- "1AE31942917403FF4946B0A83D3D3E05" \
- "EE57C6F5F5606FB5D4BC6CD34EE0801A" \
- "5E94BB77B07507233A0BC7BAC8F90F79"
-
-#define RSA_E "10001"
-
-#define RSA_D "24BF6185468786FDD303083D25E64EFC" \
- "66CA472BC44D253102F8B4A9D3BFA750" \
- "91386C0077937FE33FA3252D28855837" \
- "AE1B484A8A9A45F7EE8C0C634F99E8CD" \
- "DF79C5CE07EE72C7F123142198164234" \
- "CABB724CF78B8173B9F880FC86322407" \
- "AF1FEDFDDE2BEB674CA15F3E81A1521E" \
- "071513A1E85B5DFA031F21ECAE91A34D"
-
-#define RSA_P "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
- "2C01CAD19EA484A87EA4377637E75500" \
- "FCB2005C5C7DD6EC4AC023CDA285D796" \
- "C3D9E75E1EFC42488BB4F1D13AC30A57"
-
-#define RSA_Q "C000DF51A7C77AE8D7C7370C1FF55B69" \
- "E211C2B9E5DB1ED0BF61D0D9899620F4" \
- "910E4168387E3C30AA1E00C339A79508" \
- "8452DD96A9A5EA5D9DCA68DA636032AF"
-
-#define RSA_DP "C1ACF567564274FB07A0BBAD5D26E298" \
- "3C94D22288ACD763FD8E5600ED4A702D" \
- "F84198A5F06C2E72236AE490C93F07F8" \
- "3CC559CD27BC2D1CA488811730BB5725"
-
-#define RSA_DQ "4959CBF6F8FEF750AEE6977C155579C7" \
- "D8AAEA56749EA28623272E4F7D0592AF" \
- "7C1F1313CAC9471B5C523BFE592F517B" \
- "407A1BD76C164B93DA2D32A383E58357"
-
-#define RSA_QP "9AE7FBC99546432DF71896FC239EADAE" \
- "F38D18D2B2F0E2DD275AA977E2BF4411" \
- "F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \
- "A74206CEC169D74BF5A8C50D6F48EA08"
-
-#define PT_LEN 24
-#define RSA_PT "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
- "\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
-
-#if defined(MBEDTLS_PKCS1_V15)
-static int myrand( void *rng_state, unsigned char *output, size_t len )
-{
-#if !defined(__OpenBSD__)
- size_t i;
-
- if( rng_state != NULL )
- rng_state = NULL;
-
- for( i = 0; i < len; ++i )
- output[i] = rand();
-#else
- if( rng_state != NULL )
- rng_state = NULL;
-
- arc4random_buf( output, len );
-#endif /* !OpenBSD */
-
- return( 0 );
-}
-#endif /* MBEDTLS_PKCS1_V15 */
-
-/*
- * Checkup routine
- */
-int mbedtls_rsa_self_test( int verbose )
-{
- int ret = 0;
-#if defined(MBEDTLS_PKCS1_V15)
- size_t len;
- mbedtls_rsa_context rsa;
- unsigned char rsa_plaintext[PT_LEN];
- unsigned char rsa_decrypted[PT_LEN];
- unsigned char rsa_ciphertext[KEY_LEN];
-#if defined(MBEDTLS_SHA1_C)
- unsigned char sha1sum[20];
-#endif
-
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
-
- rsa.len = KEY_LEN;
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.N , 16, RSA_N ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.E , 16, RSA_E ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.D , 16, RSA_D ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.P , 16, RSA_P ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.Q , 16, RSA_Q ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DP, 16, RSA_DP ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DQ, 16, RSA_DQ ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.QP, 16, RSA_QP ) );
-
- if( verbose != 0 )
- mbedtls_printf( " RSA key validation: " );
-
- if( mbedtls_rsa_check_pubkey( &rsa ) != 0 ||
- mbedtls_rsa_check_privkey( &rsa ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n PKCS#1 encryption : " );
-
- memcpy( rsa_plaintext, RSA_PT, PT_LEN );
-
- if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PUBLIC, PT_LEN,
- rsa_plaintext, rsa_ciphertext ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n PKCS#1 decryption : " );
-
- if( mbedtls_rsa_pkcs1_decrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, &len,
- rsa_ciphertext, rsa_decrypted,
- sizeof(rsa_decrypted) ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-#if defined(MBEDTLS_SHA1_C)
- if( verbose != 0 )
- mbedtls_printf( " PKCS#1 data sign : " );
-
- mbedtls_sha1( rsa_plaintext, PT_LEN, sha1sum );
-
- if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0,
- sha1sum, rsa_ciphertext ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n PKCS#1 sig. verify: " );
-
- if( mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0,
- sha1sum, rsa_ciphertext ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-#endif /* MBEDTLS_SHA1_C */
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-cleanup:
- mbedtls_rsa_free( &rsa );
-#else /* MBEDTLS_PKCS1_V15 */
- ((void) verbose);
-#endif /* MBEDTLS_PKCS1_V15 */
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_RSA_C */
diff --git a/deps/mbedtls/sha1.c b/deps/mbedtls/sha1.c
index 86d4e6ebb1..cc0e018bf1 100644
--- a/deps/mbedtls/sha1.c
+++ b/deps/mbedtls/sha1.c
@@ -36,15 +36,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_SHA1_ALT)
#include "arc4_alt.h"
@@ -357,89 +348,4 @@ void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output
mbedtls_sha1_free( &ctx );
}
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * FIPS-180-1 test vectors
- */
-static const unsigned char sha1_test_buf[3][57] =
-{
- { "abc" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
- { "" }
-};
-
-static const int sha1_test_buflen[3] =
-{
- 3, 56, 1000
-};
-
-static const unsigned char sha1_test_sum[3][20] =
-{
- { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
- 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
- { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
- 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
- { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
- 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_sha1_self_test( int verbose )
-{
- int i, j, buflen, ret = 0;
- unsigned char buf[1024];
- unsigned char sha1sum[20];
- mbedtls_sha1_context ctx;
-
- mbedtls_sha1_init( &ctx );
-
- /*
- * SHA-1
- */
- for( i = 0; i < 3; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " SHA-1 test #%d: ", i + 1 );
-
- mbedtls_sha1_starts( &ctx );
-
- if( i == 2 )
- {
- memset( buf, 'a', buflen = 1000 );
-
- for( j = 0; j < 1000; j++ )
- mbedtls_sha1_update( &ctx, buf, buflen );
- }
- else
- mbedtls_sha1_update( &ctx, sha1_test_buf[i],
- sha1_test_buflen[i] );
-
- mbedtls_sha1_finish( &ctx, sha1sum );
-
- if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_sha1_free( &ctx );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_SHA1_C */
diff --git a/deps/mbedtls/sha256.c b/deps/mbedtls/sha256.c
index 5f97fdf880..d8ee4d3a32 100644
--- a/deps/mbedtls/sha256.c
+++ b/deps/mbedtls/sha256.c
@@ -36,18 +36,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_SHA256_ALT)
#include "arc4_alt.h"
@@ -336,124 +324,4 @@ void mbedtls_sha256( const unsigned char *input, size_t ilen,
mbedtls_sha256_free( &ctx );
}
-#if defined(MBEDTLS_SELF_TEST)
-/*
- * FIPS-180-2 test vectors
- */
-static const unsigned char sha256_test_buf[3][57] =
-{
- { "abc" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
- { "" }
-};
-
-static const int sha256_test_buflen[3] =
-{
- 3, 56, 1000
-};
-
-static const unsigned char sha256_test_sum[6][32] =
-{
- /*
- * SHA-224 test vectors
- */
- { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
- 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
- 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
- 0xE3, 0x6C, 0x9D, 0xA7 },
- { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
- 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
- 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
- 0x52, 0x52, 0x25, 0x25 },
- { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
- 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
- 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
- 0x4E, 0xE7, 0xAD, 0x67 },
-
- /*
- * SHA-256 test vectors
- */
- { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
- 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
- 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
- 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
- { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
- 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
- 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
- 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
- { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
- 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
- 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
- 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_sha256_self_test( int verbose )
-{
- int i, j, k, buflen, ret = 0;
- unsigned char *buf;
- unsigned char sha256sum[32];
- mbedtls_sha256_context ctx;
-
- buf = mbedtls_calloc( 1024, sizeof(unsigned char) );
- if( NULL == buf )
- {
- if( verbose != 0 )
- mbedtls_printf( "Buffer allocation failed\n" );
-
- return( 1 );
- }
-
- mbedtls_sha256_init( &ctx );
-
- for( i = 0; i < 6; i++ )
- {
- j = i % 3;
- k = i < 3;
-
- if( verbose != 0 )
- mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
-
- mbedtls_sha256_starts( &ctx, k );
-
- if( j == 2 )
- {
- memset( buf, 'a', buflen = 1000 );
-
- for( j = 0; j < 1000; j++ )
- mbedtls_sha256_update( &ctx, buf, buflen );
- }
- else
- mbedtls_sha256_update( &ctx, sha256_test_buf[j],
- sha256_test_buflen[j] );
-
- mbedtls_sha256_finish( &ctx, sha256sum );
-
- if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_sha256_free( &ctx );
- mbedtls_free( buf );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_SHA256_C */
diff --git a/deps/mbedtls/sha512.c b/deps/mbedtls/sha512.c
index 0b91393ba3..db0348b8a5 100644
--- a/deps/mbedtls/sha512.c
+++ b/deps/mbedtls/sha512.c
@@ -42,18 +42,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#include
-#define mbedtls_printf printf
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_SHA512_ALT)
#include "arc4_alt.h"
@@ -371,144 +359,4 @@ void mbedtls_sha512( const unsigned char *input, size_t ilen,
mbedtls_sha512_free( &ctx );
}
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * FIPS-180-2 test vectors
- */
-static const unsigned char sha512_test_buf[3][113] =
-{
- { "abc" },
- { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
- "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" },
- { "" }
-};
-
-static const int sha512_test_buflen[3] =
-{
- 3, 112, 1000
-};
-
-static const unsigned char sha512_test_sum[6][64] =
-{
- /*
- * SHA-384 test vectors
- */
- { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
- 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
- 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
- 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
- 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
- 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 },
- { 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8,
- 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47,
- 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2,
- 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12,
- 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9,
- 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39 },
- { 0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB,
- 0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C,
- 0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52,
- 0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B,
- 0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB,
- 0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85 },
-
- /*
- * SHA-512 test vectors
- */
- { 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
- 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
- 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
- 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
- 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
- 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
- 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
- 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F },
- { 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA,
- 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F,
- 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1,
- 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18,
- 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4,
- 0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A,
- 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54,
- 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09 },
- { 0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64,
- 0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63,
- 0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, 0x44, 0x28,
- 0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB,
- 0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A,
- 0x4C, 0xB0, 0x43, 0x2C, 0xE5, 0x77, 0xC3, 0x1B,
- 0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E,
- 0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_sha512_self_test( int verbose )
-{
- int i, j, k, buflen, ret = 0;
- unsigned char *buf;
- unsigned char sha512sum[64];
- mbedtls_sha512_context ctx;
-
- buf = mbedtls_calloc( 1024, sizeof(unsigned char) );
- if( NULL == buf )
- {
- if( verbose != 0 )
- mbedtls_printf( "Buffer allocation failed\n" );
-
- return( 1 );
- }
-
- mbedtls_sha512_init( &ctx );
-
- for( i = 0; i < 6; i++ )
- {
- j = i % 3;
- k = i < 3;
-
- if( verbose != 0 )
- mbedtls_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 );
-
- mbedtls_sha512_starts( &ctx, k );
-
- if( j == 2 )
- {
- memset( buf, 'a', buflen = 1000 );
-
- for( j = 0; j < 1000; j++ )
- mbedtls_sha512_update( &ctx, buf, buflen );
- }
- else
- mbedtls_sha512_update( &ctx, sha512_test_buf[j],
- sha512_test_buflen[j] );
-
- mbedtls_sha512_finish( &ctx, sha512sum );
-
- if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_sha512_free( &ctx );
- mbedtls_free( buf );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_SHA512_C */
diff --git a/deps/mbedtls/ssl_cache.c b/deps/mbedtls/ssl_cache.c
index 9b62de2dcc..bbfeb81911 100644
--- a/deps/mbedtls/ssl_cache.c
+++ b/deps/mbedtls/ssl_cache.c
@@ -31,18 +31,11 @@
#if defined(MBEDTLS_SSL_CACHE_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#include "mbedtls/ssl_cache.h"
-#include
-
void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache )
{
memset( cache, 0, sizeof( mbedtls_ssl_cache_context ) );
@@ -57,10 +50,8 @@ void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache )
int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
{
- int ret = 1;
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t t = mbedtls_time( NULL );
-#endif
+ int ret = 1;
+ time_t t = time( NULL );
mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
mbedtls_ssl_cache_entry *cur, *entry;
@@ -77,11 +68,9 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
entry = cur;
cur = cur->next;
-#if defined(MBEDTLS_HAVE_TIME)
if( cache->timeout != 0 &&
(int) ( t - entry->timestamp ) > cache->timeout )
continue;
-#endif
if( session->ciphersuite != entry->session.ciphersuite ||
session->compression != entry->session.compression ||
@@ -102,7 +91,7 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
*/
if( entry->peer_cert.p != NULL )
{
- if( ( session->peer_cert = mbedtls_calloc( 1,
+ if( ( session->peer_cert = (mbedtls_x509_crt*)calloc( 1,
sizeof(mbedtls_x509_crt) ) ) == NULL )
{
ret = 1;
@@ -113,7 +102,7 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
if( mbedtls_x509_crt_parse( session->peer_cert, entry->peer_cert.p,
entry->peer_cert.len ) != 0 )
{
- mbedtls_free( session->peer_cert );
+ free( session->peer_cert );
session->peer_cert = NULL;
ret = 1;
goto exit;
@@ -136,11 +125,9 @@ exit:
int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
{
- int ret = 1;
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t t = time( NULL ), oldest = 0;
- mbedtls_ssl_cache_entry *old = NULL;
-#endif
+ int ret = 1;
+ time_t t = time( NULL ), oldest = 0;
+ mbedtls_ssl_cache_entry *old = NULL;
mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
mbedtls_ssl_cache_entry *cur, *prv;
int count = 0;
@@ -157,25 +144,21 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
{
count++;
-#if defined(MBEDTLS_HAVE_TIME)
if( cache->timeout != 0 &&
(int) ( t - cur->timestamp ) > cache->timeout )
{
cur->timestamp = t;
break; /* expired, reuse this slot, update timestamp */
}
-#endif
if( memcmp( session->id, cur->session.id, cur->session.id_len ) == 0 )
break; /* client reconnected, keep timestamp for session id */
-#if defined(MBEDTLS_HAVE_TIME)
if( oldest == 0 || cur->timestamp < oldest )
{
oldest = cur->timestamp;
old = cur;
}
-#endif
prv = cur;
cur = cur->next;
@@ -183,7 +166,6 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
if( cur == NULL )
{
-#if defined(MBEDTLS_HAVE_TIME)
/*
* Reuse oldest entry if max_entries reached
*/
@@ -197,32 +179,15 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
cur = old;
}
-#else /* MBEDTLS_HAVE_TIME */
- /*
- * Reuse first entry in chain if max_entries reached,
- * but move to last place
- */
- if( count >= cache->max_entries )
- {
- if( cache->chain == NULL )
- {
- ret = 1;
- goto exit;
- }
-
- cur = cache->chain;
- cache->chain = cur->next;
- cur->next = NULL;
- prv->next = cur;
- }
-#endif /* MBEDTLS_HAVE_TIME */
else
{
/*
* max_entries not reached, create new entry
*/
- cur = mbedtls_calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
- if( cur == NULL )
+ cur = (mbedtls_ssl_cache_entry*)
+ calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
+
+ if (!cur)
{
ret = 1;
goto exit;
@@ -234,9 +199,7 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
prv->next = cur;
}
-#if defined(MBEDTLS_HAVE_TIME)
cur->timestamp = t;
-#endif
}
memcpy( &cur->session, session, sizeof( mbedtls_ssl_session ) );
@@ -247,7 +210,7 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
*/
if( cur->peer_cert.p != NULL )
{
- mbedtls_free( cur->peer_cert.p );
+ free( cur->peer_cert.p );
memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
}
@@ -256,7 +219,8 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
*/
if( session->peer_cert != NULL )
{
- cur->peer_cert.p = mbedtls_calloc( 1, session->peer_cert->raw.len );
+ cur->peer_cert.p = (unsigned char*)
+ calloc( 1, session->peer_cert->raw.len );
if( cur->peer_cert.p == NULL )
{
ret = 1;
@@ -282,14 +246,13 @@ exit:
return( ret );
}
-#if defined(MBEDTLS_HAVE_TIME)
void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout )
{
- if( timeout < 0 ) timeout = 0;
+ if( timeout < 0 )
+ timeout = 0;
cache->timeout = timeout;
}
-#endif /* MBEDTLS_HAVE_TIME */
void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max )
{
@@ -312,10 +275,10 @@ void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache )
mbedtls_ssl_session_free( &prv->session );
#if defined(MBEDTLS_X509_CRT_PARSE_C)
- mbedtls_free( prv->peer_cert.p );
+ free( prv->peer_cert.p );
#endif /* MBEDTLS_X509_CRT_PARSE_C */
- mbedtls_free( prv );
+ free( prv );
}
#if defined(MBEDTLS_THREADING_C)
diff --git a/deps/mbedtls/ssl_ciphersuites.c b/deps/mbedtls/ssl_ciphersuites.c
index ed3f20c9fd..a7be9db63b 100644
--- a/deps/mbedtls/ssl_ciphersuites.c
+++ b/deps/mbedtls/ssl_ciphersuites.c
@@ -29,17 +29,12 @@
#if defined(MBEDTLS_SSL_TLS_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#endif
+#include
#include "mbedtls/ssl_ciphersuites.h"
#include "mbedtls/ssl.h"
-#include
-
/*
* Ordered from most preferred to least preferred in terms of security.
*
diff --git a/deps/mbedtls/ssl_cli.c b/deps/mbedtls/ssl_cli.c
index fcd37bd9bc..ca4d462987 100644
--- a/deps/mbedtls/ssl_cli.c
+++ b/deps/mbedtls/ssl_cli.c
@@ -27,25 +27,15 @@
#if defined(MBEDTLS_SSL_CLI_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
+#include
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/ssl_internal.h"
-#include
-
-#include
-
-#if defined(MBEDTLS_HAVE_TIME)
-#include "mbedtls/platform_time.h"
-#endif
+#include
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
#include "arc4_alt.h"
@@ -390,7 +380,7 @@ static void ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
return;
}
- ssl->handshake->ecjpake_cache = mbedtls_calloc( 1, kkpp_len );
+ ssl->handshake->ecjpake_cache = calloc( 1, kkpp_len );
if( ssl->handshake->ecjpake_cache == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "allocation failed" ) );
@@ -667,9 +657,7 @@ static int ssl_generate_random( mbedtls_ssl_context *ssl )
{
int ret;
unsigned char *p = ssl->handshake->randbytes;
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t t;
-#endif
+ time_t t;
/*
* When responding to a verify request, MUST reuse random (RFC 6347 4.2.1)
@@ -677,25 +665,16 @@ static int ssl_generate_random( mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
ssl->handshake->verify_cookie != NULL )
- {
return( 0 );
- }
#endif
-#if defined(MBEDTLS_HAVE_TIME)
- t = mbedtls_time( NULL );
+ t = time( NULL );
*p++ = (unsigned char)( t >> 24 );
*p++ = (unsigned char)( t >> 16 );
*p++ = (unsigned char)( t >> 8 );
*p++ = (unsigned char)( t );
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, current time: %lu", t ) );
-#else
- if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 4 ) ) != 0 )
- return( ret );
-
- p += 4;
-#endif /* MBEDTLS_HAVE_TIME */
if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 28 ) ) != 0 )
return( ret );
@@ -916,11 +895,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, got %d ciphersuites", n ) );
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- offer_compress = 1;
-#else
offer_compress = 0;
-#endif
/*
* We don't support compression with DTLS right now: is many records come
@@ -953,8 +928,7 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
*p++ = MBEDTLS_SSL_COMPRESS_NULL;
}
- // First write extensions, then the total length
- //
+ /* First write extensions, then the total length */
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
ssl_write_hostname_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
@@ -1207,7 +1181,7 @@ static int ssl_parse_ecjpake_kkpp( mbedtls_ssl_context *ssl,
}
/* If we got here, we no longer need our cached extension */
- mbedtls_free( ssl->handshake->ecjpake_cache );
+ free( ssl->handshake->ecjpake_cache );
ssl->handshake->ecjpake_cache = NULL;
ssl->handshake->ecjpake_cache_len = 0;
@@ -1343,9 +1317,9 @@ static int ssl_parse_hello_verify_request( mbedtls_ssl_context *ssl )
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO );
}
- mbedtls_free( ssl->handshake->verify_cookie );
+ free( ssl->handshake->verify_cookie );
- ssl->handshake->verify_cookie = mbedtls_calloc( 1, cookie_len );
+ ssl->handshake->verify_cookie = (unsigned char*)calloc( 1, cookie_len );
if( ssl->handshake->verify_cookie == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc failed (%d bytes)", cookie_len ) );
@@ -1374,17 +1348,11 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
size_t ext_len;
unsigned char *buf, *ext;
unsigned char comp;
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- int accept_comp;
-#endif
#if defined(MBEDTLS_SSL_RENEGOTIATION)
int renegotiation_info_seen = 0;
#endif
int handshake_failure = 0;
const mbedtls_ssl_ciphersuite_t *suite_info;
-#if defined(MBEDTLS_DEBUG_C)
- uint32_t t;
-#endif
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse server hello" ) );
@@ -1437,7 +1405,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
else
{
/* We made it through the verification process */
- mbedtls_free( ssl->handshake->verify_cookie );
+ free( ssl->handshake->verify_cookie );
ssl->handshake->verify_cookie = NULL;
ssl->handshake->verify_cookie_len = 0;
}
@@ -1487,14 +1455,6 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
return( MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION );
}
-#if defined(MBEDTLS_DEBUG_C)
- t = ( (uint32_t) buf[2] << 24 )
- | ( (uint32_t) buf[3] << 16 )
- | ( (uint32_t) buf[4] << 8 )
- | ( (uint32_t) buf[5] );
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", t ) );
-#endif
-
memcpy( ssl->handshake->randbytes + 32, buf + 2, 32 );
n = buf[34];
@@ -1543,20 +1503,7 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
*/
comp = buf[37 + n];
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- /* See comments in ssl_write_client_hello() */
-#if defined(MBEDTLS_SSL_PROTO_DTLS)
- if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- accept_comp = 0;
- else
-#endif
- accept_comp = 1;
-
- if( comp != MBEDTLS_SSL_COMPRESS_NULL &&
- ( comp != MBEDTLS_SSL_COMPRESS_DEFLATE || accept_comp == 0 ) )
-#else /* MBEDTLS_ZLIB_SUPPORT */
if( comp != MBEDTLS_SSL_COMPRESS_NULL )
-#endif/* MBEDTLS_ZLIB_SUPPORT */
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "server hello, bad compression: %d", comp ) );
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
@@ -1589,19 +1536,17 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_SSL_RENEGOTIATION)
ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE ||
#endif
- ssl->session_negotiate->ciphersuite != i ||
+ ssl->session_negotiate->ciphersuite != i ||
ssl->session_negotiate->compression != comp ||
- ssl->session_negotiate->id_len != n ||
+ ssl->session_negotiate->id_len != n ||
memcmp( ssl->session_negotiate->id, buf + 35, n ) != 0 )
{
ssl->state++;
- ssl->handshake->resume = 0;
-#if defined(MBEDTLS_HAVE_TIME)
- ssl->session_negotiate->start = mbedtls_time( NULL );
-#endif
+ ssl->handshake->resume = 0;
+ ssl->session_negotiate->start = time( NULL );
ssl->session_negotiate->ciphersuite = i;
ssl->session_negotiate->compression = comp;
- ssl->session_negotiate->id_len = n;
+ ssl->session_negotiate->id_len = n;
memcpy( ssl->session_negotiate->id, buf + 35, n );
}
else
@@ -1658,9 +1603,6 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
}
if( comp != MBEDTLS_SSL_COMPRESS_NULL
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- && comp != MBEDTLS_SSL_COMPRESS_DEFLATE
-#endif
)
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
@@ -2659,16 +2601,6 @@ static int ssl_parse_certificate_request( mbedtls_ssl_context *ssl )
{
size_t sig_alg_len = ( ( buf[mbedtls_ssl_hs_hdr_len( ssl ) + 1 + n] << 8 )
| ( buf[mbedtls_ssl_hs_hdr_len( ssl ) + 2 + n] ) );
-#if defined(MBEDTLS_DEBUG_C)
- unsigned char* sig_alg = buf + mbedtls_ssl_hs_hdr_len( ssl ) + 3 + n;
- size_t i;
-
- for( i = 0; i < sig_alg_len; i += 2 )
- {
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "Supported Signature Algorithm found: %d"
- ",%d", sig_alg[i], sig_alg[i + 1] ) );
- }
-#endif
n += 2 + sig_alg_len;
@@ -3260,11 +3192,11 @@ static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl )
mbedtls_zeroize( ssl->session_negotiate->ticket,
ssl->session_negotiate->ticket_len );
- mbedtls_free( ssl->session_negotiate->ticket );
+ free( ssl->session_negotiate->ticket );
ssl->session_negotiate->ticket = NULL;
ssl->session_negotiate->ticket_len = 0;
- if( ( ticket = mbedtls_calloc( 1, ticket_len ) ) == NULL )
+ if( ( ticket = (unsigned char*)calloc( 1, ticket_len ) ) == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "ticket alloc failed" ) );
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
diff --git a/deps/mbedtls/ssl_cookie.c b/deps/mbedtls/ssl_cookie.c
index f2c112e74d..6b715c14c5 100644
--- a/deps/mbedtls/ssl_cookie.c
+++ b/deps/mbedtls/ssl_cookie.c
@@ -31,13 +31,6 @@
#if defined(MBEDTLS_SSL_COOKIE_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
#include "mbedtls/ssl_cookie.h"
#include "mbedtls/ssl_internal.h"
@@ -75,9 +68,6 @@
void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx )
{
mbedtls_md_init( &ctx->hmac_ctx );
-#if !defined(MBEDTLS_HAVE_TIME)
- ctx->serial = 0;
-#endif
ctx->timeout = MBEDTLS_SSL_COOKIE_TIMEOUT;
#if defined(MBEDTLS_THREADING_C)
@@ -155,12 +145,12 @@ static int ssl_cookie_hmac( mbedtls_md_context_t *hmac_ctx,
* Generate cookie for DTLS ClientHello verification
*/
int mbedtls_ssl_cookie_write( void *p_ctx,
- unsigned char **p, unsigned char *end,
- const unsigned char *cli_id, size_t cli_id_len )
+ unsigned char **p, unsigned char *end,
+ const unsigned char *cli_id, size_t cli_id_len )
{
int ret;
- mbedtls_ssl_cookie_ctx *ctx = (mbedtls_ssl_cookie_ctx *) p_ctx;
unsigned long t;
+ mbedtls_ssl_cookie_ctx *ctx = (mbedtls_ssl_cookie_ctx *) p_ctx;
if( ctx == NULL || cli_id == NULL )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
@@ -168,11 +158,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx,
if( (size_t)( end - *p ) < COOKIE_LEN )
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
-#if defined(MBEDTLS_HAVE_TIME)
- t = (unsigned long) mbedtls_time( NULL );
-#else
- t = ctx->serial++;
-#endif
+ t = (unsigned long)time( NULL );
(*p)[0] = (unsigned char)( t >> 24 );
(*p)[1] = (unsigned char)( t >> 16 );
@@ -235,14 +221,11 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
if( ret != 0 )
return( ret );
- if( mbedtls_ssl_safer_memcmp( cookie + 4, ref_hmac, sizeof( ref_hmac ) ) != 0 )
+ if( mbedtls_ssl_safer_memcmp(
+ cookie + 4, ref_hmac, sizeof( ref_hmac ) ) != 0 )
return( -1 );
-#if defined(MBEDTLS_HAVE_TIME)
- cur_time = (unsigned long) mbedtls_time( NULL );
-#else
- cur_time = ctx->serial;
-#endif
+ cur_time = (unsigned long)time( NULL );
cookie_time = ( (unsigned long) cookie[0] << 24 ) |
( (unsigned long) cookie[1] << 16 ) |
diff --git a/deps/mbedtls/ssl_srv.c b/deps/mbedtls/ssl_srv.c
index 15cafd43e2..ba4957b0d0 100644
--- a/deps/mbedtls/ssl_srv.c
+++ b/deps/mbedtls/ssl_srv.c
@@ -27,27 +27,18 @@
#if defined(MBEDTLS_SSL_SRV_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
+#include
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/ssl_internal.h"
-#include
-
#if defined(MBEDTLS_ECP_C)
#include "mbedtls/ecp.h"
#endif
-#if defined(MBEDTLS_HAVE_TIME)
-#include "mbedtls/platform_time.h"
-#endif
+#include
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
#include "arc4_alt.h"
@@ -61,9 +52,9 @@ int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
if( ssl->conf->endpoint != MBEDTLS_SSL_IS_SERVER )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
- mbedtls_free( ssl->cli_id );
+ free( ssl->cli_id );
- if( ( ssl->cli_id = mbedtls_calloc( 1, ilen ) ) == NULL )
+ if( ( ssl->cli_id = (unsigned char*)calloc( 1, ilen ) ) == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
memcpy( ssl->cli_id, info, ilen );
@@ -267,7 +258,8 @@ static int ssl_parse_supported_elliptic_curves( mbedtls_ssl_context *ssl,
if( our_size > MBEDTLS_ECP_DP_MAX )
our_size = MBEDTLS_ECP_DP_MAX;
- if( ( curves = mbedtls_calloc( our_size, sizeof( *curves ) ) ) == NULL )
+ if( ( curves = (const mbedtls_ecp_curve_info**)
+ calloc( our_size, sizeof( *curves ) ) ) == NULL )
{
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR );
@@ -1546,16 +1538,6 @@ read_record_header:
buf + comp_offset + 1, comp_len );
ssl->session_negotiate->compression = MBEDTLS_SSL_COMPRESS_NULL;
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- for( i = 0; i < comp_len; ++i )
- {
- if( buf[comp_offset + 1 + i] == MBEDTLS_SSL_COMPRESS_DEFLATE )
- {
- ssl->session_negotiate->compression = MBEDTLS_SSL_COMPRESS_DEFLATE;
- break;
- }
- }
-#endif
/* See comments in ssl_write_client_hello() */
#if defined(MBEDTLS_SSL_PROTO_DTLS)
@@ -1932,28 +1914,6 @@ have_ciphersuite:
mbedtls_ssl_recv_flight_completed( ssl );
#endif
- /* Debugging-only output for testsuite */
-#if defined(MBEDTLS_DEBUG_C) && \
- defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
- defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
- if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
- {
- mbedtls_pk_type_t sig_alg = mbedtls_ssl_get_ciphersuite_sig_alg( ciphersuite_info );
- if( sig_alg != MBEDTLS_PK_NONE )
- {
- mbedtls_md_type_t md_alg = mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs,
- sig_alg );
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, signature_algorithm ext: %d",
- mbedtls_ssl_hash_from_md_alg( md_alg ) ) );
- }
- else
- {
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "no hash algorithm for signature algorithm "
- "%d - should not happen", sig_alg ) );
- }
- }
-#endif
-
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse client hello" ) );
return( 0 );
@@ -2322,10 +2282,8 @@ static int ssl_write_hello_verify_request( mbedtls_ssl_context *ssl )
static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
{
-#if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t t;
-#endif
int ret;
+ time_t t;
size_t olen, ext_len = 0, n;
unsigned char *buf, *p;
@@ -2365,20 +2323,13 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, chosen version: [%d:%d]",
buf[4], buf[5] ) );
-#if defined(MBEDTLS_HAVE_TIME)
- t = mbedtls_time( NULL );
+ t = time( NULL );
*p++ = (unsigned char)( t >> 24 );
*p++ = (unsigned char)( t >> 16 );
*p++ = (unsigned char)( t >> 8 );
*p++ = (unsigned char)( t );
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu", t ) );
-#else
- if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 4 ) ) != 0 )
- return( ret );
-
- p += 4;
-#endif /* MBEDTLS_HAVE_TIME */
if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng, p, 28 ) ) != 0 )
return( ret );
@@ -2414,9 +2365,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
*/
ssl->state++;
-#if defined(MBEDTLS_HAVE_TIME)
- ssl->session_negotiate->start = mbedtls_time( NULL );
-#endif
+ ssl->session_negotiate->start = time( NULL );
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
if( ssl->handshake->new_session_ticket != 0 )
diff --git a/deps/mbedtls/ssl_ticket.c b/deps/mbedtls/ssl_ticket.c
index 5c77c1c359..9c4b74287c 100644
--- a/deps/mbedtls/ssl_ticket.c
+++ b/deps/mbedtls/ssl_ticket.c
@@ -27,13 +27,7 @@
#if defined(MBEDTLS_SSL_TICKET_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#include "mbedtls/ssl_ticket.h"
@@ -65,9 +59,7 @@ static int ssl_ticket_gen_key( mbedtls_ssl_ticket_context *ctx,
unsigned char buf[MAX_KEY_BYTES];
mbedtls_ssl_ticket_key *key = ctx->keys + index;
-#if defined(MBEDTLS_HAVE_TIME)
- key->generation_time = (uint32_t) mbedtls_time( NULL );
-#endif
+ key->generation_time = (uint32_t)time( NULL );
if( ( ret = ctx->f_rng( ctx->p_rng, key->name, sizeof( key->name ) ) ) != 0 )
return( ret );
@@ -90,27 +82,20 @@ static int ssl_ticket_gen_key( mbedtls_ssl_ticket_context *ctx,
*/
static int ssl_ticket_update_keys( mbedtls_ssl_ticket_context *ctx )
{
-#if !defined(MBEDTLS_HAVE_TIME)
- ((void) ctx);
-#else
if( ctx->ticket_lifetime != 0 )
{
- uint32_t current_time = (uint32_t) mbedtls_time( NULL );
- uint32_t key_time = ctx->keys[ctx->active].generation_time;
+ uint32_t current_time = (uint32_t)time( NULL );
+ uint32_t key_time = ctx->keys[ctx->active].generation_time;
if( current_time > key_time &&
current_time - key_time < ctx->ticket_lifetime )
- {
return( 0 );
- }
ctx->active = 1 - ctx->active;
return( ssl_ticket_gen_key( ctx, ctx->active ) );
}
- else
-#endif /* MBEDTLS_HAVE_TIME */
- return( 0 );
+ return( 0 );
}
/*
@@ -240,7 +225,7 @@ static int ssl_load_session( mbedtls_ssl_session *session,
if( p + cert_len > end )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
- session->peer_cert = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
+ session->peer_cert = (mbedtls_x509_crt*)calloc( 1, sizeof( mbedtls_x509_crt ) );
if( session->peer_cert == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -251,7 +236,7 @@ static int ssl_load_session( mbedtls_ssl_session *session,
p, cert_len ) ) != 0 )
{
mbedtls_x509_crt_free( session->peer_cert );
- mbedtls_free( session->peer_cert );
+ free( session->peer_cert );
session->peer_cert = NULL;
return( ret );
}
@@ -287,14 +272,14 @@ int mbedtls_ssl_ticket_write( void *p_ticket,
uint32_t *ticket_lifetime )
{
int ret;
- mbedtls_ssl_ticket_context *ctx = p_ticket;
- mbedtls_ssl_ticket_key *key;
- unsigned char *key_name = start;
- unsigned char *iv = start + 4;
- unsigned char *state_len_bytes = iv + 12;
- unsigned char *state = state_len_bytes + 2;
unsigned char *tag;
size_t clear_len, ciph_len;
+ mbedtls_ssl_ticket_key *key = NULL;
+ mbedtls_ssl_ticket_context *ctx = (mbedtls_ssl_ticket_context*)p_ticket;
+ unsigned char *key_name = start;
+ unsigned char *iv = start + 4;
+ unsigned char *state_len_bytes = iv + 12;
+ unsigned char *state = state_len_bytes + 2;
*tlen = 0;
@@ -383,14 +368,14 @@ int mbedtls_ssl_ticket_parse( void *p_ticket,
size_t len )
{
int ret;
- mbedtls_ssl_ticket_context *ctx = p_ticket;
- mbedtls_ssl_ticket_key *key;
- unsigned char *key_name = buf;
- unsigned char *iv = buf + 4;
- unsigned char *enc_len_p = iv + 12;
- unsigned char *ticket = enc_len_p + 2;
unsigned char *tag;
size_t enc_len, clear_len;
+ mbedtls_ssl_ticket_key *key = NULL;
+ mbedtls_ssl_ticket_context *ctx = (mbedtls_ssl_ticket_context*)p_ticket;
+ unsigned char *key_name = buf;
+ unsigned char *iv = buf + 4;
+ unsigned char *enc_len_p = iv + 12;
+ unsigned char *ticket = enc_len_p + 2;
if( ctx == NULL || ctx->f_rng == NULL )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
@@ -445,10 +430,9 @@ int mbedtls_ssl_ticket_parse( void *p_ticket,
if( ( ret = ssl_load_session( session, ticket, clear_len ) ) != 0 )
goto cleanup;
-#if defined(MBEDTLS_HAVE_TIME)
{
/* Check for expiration */
- mbedtls_time_t current_time = mbedtls_time( NULL );
+ time_t current_time = time( NULL );
if( current_time < session->start ||
(uint32_t)( current_time - session->start ) > ctx->ticket_lifetime )
@@ -457,7 +441,6 @@ int mbedtls_ssl_ticket_parse( void *p_ticket,
goto cleanup;
}
}
-#endif
cleanup:
#if defined(MBEDTLS_THREADING_C)
diff --git a/deps/mbedtls/ssl_tls.c b/deps/mbedtls/ssl_tls.c
index 6c136351c9..8a29d97414 100644
--- a/deps/mbedtls/ssl_tls.c
+++ b/deps/mbedtls/ssl_tls.c
@@ -35,13 +35,7 @@
#if defined(MBEDTLS_SSL_TLS_C)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
@@ -56,7 +50,7 @@
#include "arc4_alt.h"
/* Length of the "epoch" field in the record header */
-static inline size_t ssl_ep_len( const mbedtls_ssl_context *ssl )
+static INLINE size_t ssl_ep_len( const mbedtls_ssl_context *ssl )
{
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
@@ -163,7 +157,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
{
int ret;
- dst->peer_cert = (mbedtls_x509_crt*)mbedtls_calloc( 1, sizeof(mbedtls_x509_crt) );
+ dst->peer_cert = (mbedtls_x509_crt*)calloc( 1, sizeof(mbedtls_x509_crt) );
if( dst->peer_cert == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -172,7 +166,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
if( ( ret = mbedtls_x509_crt_parse_der( dst->peer_cert, src->peer_cert->raw.p,
src->peer_cert->raw.len ) ) != 0 )
{
- mbedtls_free( dst->peer_cert );
+ free( dst->peer_cert );
dst->peer_cert = NULL;
return( ret );
}
@@ -182,7 +176,7 @@ static int ssl_session_copy( mbedtls_ssl_session *dst, const mbedtls_ssl_session
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
if( src->ticket != NULL )
{
- dst->ticket = (unsigned char*)mbedtls_calloc( 1, src->ticket_len );
+ dst->ticket = (unsigned char*)calloc( 1, src->ticket_len );
if( dst->ticket == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -919,38 +913,6 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
mbedtls_zeroize( keyblk, sizeof( keyblk ) );
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- // Initialize compression
- //
- if( session->compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
- {
- if( ssl->compress_buf == NULL )
- {
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "Allocating compression buffer" ) );
- ssl->compress_buf = mbedtls_calloc( 1, MBEDTLS_SSL_BUFFER_LEN );
- if( ssl->compress_buf == NULL )
- {
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed",
- MBEDTLS_SSL_BUFFER_LEN ) );
- return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
- }
- }
-
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "Initializing zlib states" ) );
-
- memset( &transform->ctx_deflate, 0, sizeof( transform->ctx_deflate ) );
- memset( &transform->ctx_inflate, 0, sizeof( transform->ctx_inflate ) );
-
- if( deflateInit( &transform->ctx_deflate,
- Z_DEFAULT_COMPRESSION ) != Z_OK ||
- inflateInit( &transform->ctx_inflate ) != Z_OK )
- {
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "Failed to initialize compression" ) );
- return( MBEDTLS_ERR_SSL_COMPRESSION_FAILED );
- }
- }
-#endif /* MBEDTLS_ZLIB_SUPPORT */
-
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= derive keys" ) );
return( 0 );
@@ -2054,103 +2016,6 @@ static int ssl_decrypt_buf( mbedtls_ssl_context *ssl )
#undef MAC_PLAINTEXT
#undef MAC_CIPHERTEXT
-#if defined(MBEDTLS_ZLIB_SUPPORT)
-/*
- * Compression/decompression functions
- */
-static int ssl_compress_buf( mbedtls_ssl_context *ssl )
-{
- int ret;
- unsigned char *msg_post = ssl->out_msg;
- size_t len_pre = ssl->out_msglen;
- unsigned char *msg_pre = ssl->compress_buf;
-
- MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> compress buf" ) );
-
- if( len_pre == 0 )
- return( 0 );
-
- memcpy( msg_pre, ssl->out_msg, len_pre );
-
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "before compression: msglen = %d, ",
- ssl->out_msglen ) );
-
- MBEDTLS_SSL_DEBUG_BUF( 4, "before compression: output payload",
- ssl->out_msg, ssl->out_msglen );
-
- ssl->transform_out->ctx_deflate.next_in = msg_pre;
- ssl->transform_out->ctx_deflate.avail_in = len_pre;
- ssl->transform_out->ctx_deflate.next_out = msg_post;
- ssl->transform_out->ctx_deflate.avail_out = MBEDTLS_SSL_BUFFER_LEN;
-
- ret = deflate( &ssl->transform_out->ctx_deflate, Z_SYNC_FLUSH );
- if( ret != Z_OK )
- {
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "failed to perform compression (%d)", ret ) );
- return( MBEDTLS_ERR_SSL_COMPRESSION_FAILED );
- }
-
- ssl->out_msglen = MBEDTLS_SSL_BUFFER_LEN -
- ssl->transform_out->ctx_deflate.avail_out;
-
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "after compression: msglen = %d, ",
- ssl->out_msglen ) );
-
- MBEDTLS_SSL_DEBUG_BUF( 4, "after compression: output payload",
- ssl->out_msg, ssl->out_msglen );
-
- MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= compress buf" ) );
-
- return( 0 );
-}
-
-static int ssl_decompress_buf( mbedtls_ssl_context *ssl )
-{
- int ret;
- unsigned char *msg_post = ssl->in_msg;
- size_t len_pre = ssl->in_msglen;
- unsigned char *msg_pre = ssl->compress_buf;
-
- MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> decompress buf" ) );
-
- if( len_pre == 0 )
- return( 0 );
-
- memcpy( msg_pre, ssl->in_msg, len_pre );
-
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "before decompression: msglen = %d, ",
- ssl->in_msglen ) );
-
- MBEDTLS_SSL_DEBUG_BUF( 4, "before decompression: input payload",
- ssl->in_msg, ssl->in_msglen );
-
- ssl->transform_in->ctx_inflate.next_in = msg_pre;
- ssl->transform_in->ctx_inflate.avail_in = len_pre;
- ssl->transform_in->ctx_inflate.next_out = msg_post;
- ssl->transform_in->ctx_inflate.avail_out = MBEDTLS_SSL_MAX_CONTENT_LEN;
-
- ret = inflate( &ssl->transform_in->ctx_inflate, Z_SYNC_FLUSH );
- if( ret != Z_OK )
- {
- MBEDTLS_SSL_DEBUG_MSG( 1, ( "failed to perform decompression (%d)", ret ) );
- return( MBEDTLS_ERR_SSL_COMPRESSION_FAILED );
- }
-
- ssl->in_msglen = MBEDTLS_SSL_MAX_CONTENT_LEN -
- ssl->transform_in->ctx_inflate.avail_out;
-
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "after decompression: msglen = %d, ",
- ssl->in_msglen ) );
-
- MBEDTLS_SSL_DEBUG_BUF( 4, "after decompression: input payload",
- ssl->in_msg, ssl->in_msglen );
-
- MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= decompress buf" ) );
-
- return( 0 );
-}
-#endif /* MBEDTLS_ZLIB_SUPPORT */
-
#if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_RENEGOTIATION)
static int ssl_write_hello_request( mbedtls_ssl_context *ssl );
@@ -2472,17 +2337,17 @@ static int ssl_flight_append( mbedtls_ssl_context *ssl )
/* Allocate space for current message */
if( ( msg = (mbedtls_ssl_flight_item*)
- mbedtls_calloc( 1, sizeof( mbedtls_ssl_flight_item ) ) ) == NULL )
+ calloc( 1, sizeof( mbedtls_ssl_flight_item ) ) ) == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %d bytes failed",
sizeof( mbedtls_ssl_flight_item ) ) );
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
}
- if( ( msg->p = (unsigned char*)mbedtls_calloc( 1, ssl->out_msglen ) ) == NULL )
+ if( ( msg->p = (unsigned char*)calloc( 1, ssl->out_msglen ) ) == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc %d bytes failed", ssl->out_msglen ) );
- mbedtls_free( msg );
+ free( msg );
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
}
@@ -2518,8 +2383,8 @@ static void ssl_flight_free( mbedtls_ssl_flight_item *flight )
{
next = cur->next;
- mbedtls_free( cur->p );
- mbedtls_free( cur );
+ free( cur->p );
+ free( cur );
cur = next;
}
@@ -2776,20 +2641,6 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl )
}
#endif
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- if( ssl->transform_out != NULL &&
- ssl->session_out->compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
- {
- if( ( ret = ssl_compress_buf( ssl ) ) != 0 )
- {
- MBEDTLS_SSL_DEBUG_RET( 1, "ssl_compress_buf", ret );
- return( ret );
- }
-
- len = ssl->out_msglen;
- }
-#endif /*MBEDTLS_ZLIB_SUPPORT */
-
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
if( mbedtls_ssl_hw_record_write != NULL )
{
@@ -2951,7 +2802,7 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl )
/* The bitmask needs one bit per byte of message excluding header */
alloc_len = 12 + msg_len + msg_len / 8 + ( msg_len % 8 != 0 );
- ssl->handshake->hs_msg = (unsigned char*)mbedtls_calloc( 1, alloc_len );
+ ssl->handshake->hs_msg = (unsigned char*)calloc( 1, alloc_len );
if( ssl->handshake->hs_msg == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc failed (%d bytes)", alloc_len ) );
@@ -3058,7 +2909,7 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl )
memcpy( ssl->in_msg, ssl->handshake->hs_msg, ssl->in_hslen );
- mbedtls_free( ssl->handshake->hs_msg );
+ free( ssl->handshake->hs_msg );
ssl->handshake->hs_msg = NULL;
MBEDTLS_SSL_DEBUG_BUF( 3, "reassembled handshake message",
@@ -3189,7 +3040,7 @@ static void ssl_dtls_replay_reset( mbedtls_ssl_context *ssl )
ssl->in_window = 0;
}
-static inline uint64_t ssl_load_six_bytes( unsigned char *buf )
+static INLINE uint64_t ssl_load_six_bytes( unsigned char *buf )
{
return( ( (uint64_t) buf[0] << 40 ) |
( (uint64_t) buf[1] << 32 ) |
@@ -3681,18 +3532,6 @@ static int ssl_prepare_record_content( mbedtls_ssl_context *ssl )
}
}
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- if( ssl->transform_in != NULL &&
- ssl->session_in->compression == MBEDTLS_SSL_COMPRESS_DEFLATE )
- {
- if( ( ret = ssl_decompress_buf( ssl ) ) != 0 )
- {
- MBEDTLS_SSL_DEBUG_RET( 1, "ssl_decompress_buf", ret );
- return( ret );
- }
- }
-#endif /* MBEDTLS_ZLIB_SUPPORT */
-
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
{
@@ -4451,10 +4290,10 @@ int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl )
if( ssl->session_negotiate->peer_cert != NULL )
{
mbedtls_x509_crt_free( ssl->session_negotiate->peer_cert );
- mbedtls_free( ssl->session_negotiate->peer_cert );
+ free( ssl->session_negotiate->peer_cert );
}
- if( ( ssl->session_negotiate->peer_cert = (mbedtls_x509_crt*)mbedtls_calloc( 1,
+ if( ( ssl->session_negotiate->peer_cert = (mbedtls_x509_crt*)calloc( 1,
sizeof( mbedtls_x509_crt ) ) ) == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed",
@@ -4665,18 +4504,6 @@ int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl )
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
alert );
}
-
-#if defined(MBEDTLS_DEBUG_C)
- if( ssl->session_negotiate->verify_result != 0 )
- {
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "! Certificate verification flags %x",
- ssl->session_negotiate->verify_result ) );
- }
- else
- {
- MBEDTLS_SSL_DEBUG_MSG( 3, ( "Certificate verification flags clear" ) );
- }
-#endif /* MBEDTLS_DEBUG_C */
}
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse certificate" ) );
@@ -5145,7 +4972,7 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl )
* Free our handshake params
*/
mbedtls_ssl_handshake_free( ssl->handshake );
- mbedtls_free( ssl->handshake );
+ free( ssl->handshake );
ssl->handshake = NULL;
/*
@@ -5154,7 +4981,7 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl )
if( ssl->transform )
{
mbedtls_ssl_transform_free( ssl->transform );
- mbedtls_free( ssl->transform );
+ free( ssl->transform );
}
ssl->transform = ssl->transform_negotiate;
ssl->transform_negotiate = NULL;
@@ -5188,7 +5015,7 @@ void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl )
#endif
mbedtls_ssl_session_free( ssl->session );
- mbedtls_free( ssl->session );
+ free( ssl->session );
}
ssl->session = ssl->session_negotiate;
ssl->session_negotiate = NULL;
@@ -5462,13 +5289,6 @@ static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake )
#if defined(MBEDTLS_ECDH_C)
mbedtls_ecdh_init( &handshake->ecdh_ctx );
#endif
-#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- mbedtls_ecjpake_init( &handshake->ecjpake_ctx );
-#if defined(MBEDTLS_SSL_CLI_C)
- handshake->ecjpake_cache = NULL;
- handshake->ecjpake_cache_len = 0;
-#endif
-#endif
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
handshake->sni_authmode = MBEDTLS_SSL_VERIFY_UNSET;
@@ -5507,17 +5327,17 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl )
*/
if( ssl->transform_negotiate == NULL )
{
- ssl->transform_negotiate = (mbedtls_ssl_transform*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_transform) );
+ ssl->transform_negotiate = (mbedtls_ssl_transform*)calloc( 1, sizeof(mbedtls_ssl_transform) );
}
if( ssl->session_negotiate == NULL )
{
- ssl->session_negotiate = (mbedtls_ssl_session*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_session) );
+ ssl->session_negotiate = (mbedtls_ssl_session*)calloc( 1, sizeof(mbedtls_ssl_session) );
}
if( ssl->handshake == NULL )
{
- ssl->handshake = (mbedtls_ssl_handshake_params*)mbedtls_calloc( 1, sizeof(mbedtls_ssl_handshake_params) );
+ ssl->handshake = (mbedtls_ssl_handshake_params*)calloc( 1, sizeof(mbedtls_ssl_handshake_params) );
}
/* All pointers should exist and can be directly freed without issue */
@@ -5527,9 +5347,9 @@ static int ssl_handshake_init( mbedtls_ssl_context *ssl )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc() of ssl sub-contexts failed" ) );
- mbedtls_free( ssl->handshake );
- mbedtls_free( ssl->transform_negotiate );
- mbedtls_free( ssl->session_negotiate );
+ free( ssl->handshake );
+ free( ssl->transform_negotiate );
+ free( ssl->session_negotiate );
ssl->handshake = NULL;
ssl->transform_negotiate = NULL;
@@ -5611,11 +5431,11 @@ int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
/*
* Prepare base structures
*/
- if( ( ssl-> in_buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL ||
- ( ssl->out_buf = (unsigned char*)mbedtls_calloc( 1, len ) ) == NULL )
+ if( ( ssl-> in_buf = (unsigned char*)calloc( 1, len ) ) == NULL ||
+ ( ssl->out_buf = (unsigned char*)calloc( 1, len ) ) == NULL )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "alloc(%d bytes) failed", len ) );
- mbedtls_free( ssl->in_buf );
+ free( ssl->in_buf );
ssl->in_buf = NULL;
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
}
@@ -5734,14 +5554,14 @@ static int ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial )
if( ssl->transform )
{
mbedtls_ssl_transform_free( ssl->transform );
- mbedtls_free( ssl->transform );
+ free( ssl->transform );
ssl->transform = NULL;
}
if( ssl->session )
{
mbedtls_ssl_session_free( ssl->session );
- mbedtls_free( ssl->session );
+ free( ssl->session );
ssl->session = NULL;
}
@@ -5752,7 +5572,7 @@ static int ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial )
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
if( partial == 0 )
{
- mbedtls_free( ssl->cli_id );
+ free( ssl->cli_id );
ssl->cli_id = NULL;
ssl->cli_id_len = 0;
}
@@ -5938,7 +5758,7 @@ static int ssl_append_key_cert( mbedtls_ssl_key_cert **head,
mbedtls_pk_context *key )
{
mbedtls_ssl_key_cert *keycert = (mbedtls_ssl_key_cert*)
- mbedtls_calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
+ calloc( 1, sizeof( mbedtls_ssl_key_cert ) );
if( keycert == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -6002,32 +5822,6 @@ void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
}
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
-/*
- * Set EC J-PAKE password for current handshake
- */
-int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
- const unsigned char *pw,
- size_t pw_len )
-{
- mbedtls_ecjpake_role role;
-
- if( ssl->handshake == NULL || ssl->conf == NULL )
- return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
-
- if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER )
- role = MBEDTLS_ECJPAKE_SERVER;
- else
- role = MBEDTLS_ECJPAKE_CLIENT;
-
- return( mbedtls_ecjpake_setup( &ssl->handshake->ecjpake_ctx,
- role,
- MBEDTLS_MD_SHA256,
- MBEDTLS_ECP_DP_SECP256R1,
- pw, pw_len ) );
-}
-#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
-
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
const unsigned char *psk, size_t psk_len,
@@ -6048,17 +5842,17 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
if( conf->psk != NULL || conf->psk_identity != NULL )
{
- mbedtls_free( conf->psk );
- mbedtls_free( conf->psk_identity );
+ free( conf->psk );
+ free( conf->psk_identity );
conf->psk = NULL;
conf->psk_identity = NULL;
}
- if( ( conf->psk = (unsigned char*)mbedtls_calloc( 1, psk_len ) ) == NULL ||
- ( conf->psk_identity = (unsigned char*)mbedtls_calloc( 1, psk_identity_len ) ) == NULL )
+ if( ( conf->psk = (unsigned char*)calloc( 1, psk_len ) ) == NULL ||
+ ( conf->psk_identity = (unsigned char*)calloc( 1, psk_identity_len ) ) == NULL )
{
- mbedtls_free( conf->psk );
- mbedtls_free( conf->psk_identity );
+ free( conf->psk );
+ free( conf->psk_identity );
conf->psk = NULL;
conf->psk_identity = NULL;
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -6083,10 +5877,10 @@ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
if( ssl->handshake->psk != NULL )
- mbedtls_free( ssl->handshake->psk );
+ free( ssl->handshake->psk );
if( ( ssl->handshake->psk = (unsigned char*)
- mbedtls_calloc( 1, psk_len ) ) == NULL )
+ calloc( 1, psk_len ) ) == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
ssl->handshake->psk_len = psk_len;
@@ -6186,7 +5980,7 @@ int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname )
if( hostname_len > MBEDTLS_SSL_MAX_HOST_NAME_LEN )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
- ssl->hostname = (char*)mbedtls_calloc( 1, hostname_len + 1 );
+ ssl->hostname = (char*)calloc( 1, hostname_len + 1 );
if( ssl->hostname == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
@@ -6443,11 +6237,6 @@ int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl )
size_t transform_expansion;
const mbedtls_ssl_transform *transform = ssl->transform_out;
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- if( ssl->session_out->compression != MBEDTLS_SSL_COMPRESS_NULL )
- return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
-#endif
-
if( transform == NULL )
return( (int) mbedtls_ssl_hdr_len( ssl ) );
@@ -7207,11 +6996,6 @@ void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform )
if( transform == NULL )
return;
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- deflateEnd( &transform->ctx_deflate );
- inflateEnd( &transform->ctx_inflate );
-#endif
-
mbedtls_cipher_free( &transform->cipher_ctx_enc );
mbedtls_cipher_free( &transform->cipher_ctx_dec );
@@ -7229,7 +7013,7 @@ static void ssl_key_cert_free( mbedtls_ssl_key_cert *key_cert )
while( cur != NULL )
{
next = cur->next;
- mbedtls_free( cur );
+ free( cur );
cur = next;
}
}
@@ -7260,26 +7044,17 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake )
#if defined(MBEDTLS_ECDH_C)
mbedtls_ecdh_free( &handshake->ecdh_ctx );
#endif
-#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- mbedtls_ecjpake_free( &handshake->ecjpake_ctx );
-#if defined(MBEDTLS_SSL_CLI_C)
- mbedtls_free( handshake->ecjpake_cache );
- handshake->ecjpake_cache = NULL;
- handshake->ecjpake_cache_len = 0;
-#endif
-#endif
-#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C)
/* explicit void pointer cast for buggy MS compiler */
- mbedtls_free( (void *) handshake->curves );
+ free( (void *) handshake->curves );
#endif
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
if( handshake->psk != NULL )
{
mbedtls_zeroize( handshake->psk, handshake->psk_len );
- mbedtls_free( handshake->psk );
+ free( handshake->psk );
}
#endif
@@ -7296,15 +7071,15 @@ void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake )
while( cur != NULL )
{
next = cur->next;
- mbedtls_free( cur );
+ free( cur );
cur = next;
}
}
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_SERVER_NAME_INDICATION */
#if defined(MBEDTLS_SSL_PROTO_DTLS)
- mbedtls_free( handshake->verify_cookie );
- mbedtls_free( handshake->hs_msg );
+ free( handshake->verify_cookie );
+ free( handshake->hs_msg );
ssl_flight_free( handshake->flight );
#endif
@@ -7320,12 +7095,12 @@ void mbedtls_ssl_session_free( mbedtls_ssl_session *session )
if( session->peer_cert != NULL )
{
mbedtls_x509_crt_free( session->peer_cert );
- mbedtls_free( session->peer_cert );
+ free( session->peer_cert );
}
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- mbedtls_free( session->ticket );
+ free( session->ticket );
#endif
mbedtls_zeroize( session, sizeof( mbedtls_ssl_session ) );
@@ -7344,27 +7119,19 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
if( ssl->out_buf != NULL )
{
mbedtls_zeroize( ssl->out_buf, MBEDTLS_SSL_BUFFER_LEN );
- mbedtls_free( ssl->out_buf );
+ free( ssl->out_buf );
}
if( ssl->in_buf != NULL )
{
mbedtls_zeroize( ssl->in_buf, MBEDTLS_SSL_BUFFER_LEN );
- mbedtls_free( ssl->in_buf );
+ free( ssl->in_buf );
}
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- if( ssl->compress_buf != NULL )
- {
- mbedtls_zeroize( ssl->compress_buf, MBEDTLS_SSL_BUFFER_LEN );
- mbedtls_free( ssl->compress_buf );
- }
-#endif
-
if( ssl->transform )
{
mbedtls_ssl_transform_free( ssl->transform );
- mbedtls_free( ssl->transform );
+ free( ssl->transform );
}
if( ssl->handshake )
@@ -7373,22 +7140,22 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
mbedtls_ssl_transform_free( ssl->transform_negotiate );
mbedtls_ssl_session_free( ssl->session_negotiate );
- mbedtls_free( ssl->handshake );
- mbedtls_free( ssl->transform_negotiate );
- mbedtls_free( ssl->session_negotiate );
+ free( ssl->handshake );
+ free( ssl->transform_negotiate );
+ free( ssl->session_negotiate );
}
if( ssl->session )
{
mbedtls_ssl_session_free( ssl->session );
- mbedtls_free( ssl->session );
+ free( ssl->session );
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
if( ssl->hostname != NULL )
{
mbedtls_zeroize( ssl->hostname, strlen( ssl->hostname ) );
- mbedtls_free( ssl->hostname );
+ free( ssl->hostname );
}
#endif
@@ -7401,7 +7168,7 @@ void mbedtls_ssl_free( mbedtls_ssl_context *ssl )
#endif
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
- mbedtls_free( ssl->cli_id );
+ free( ssl->cli_id );
#endif
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= free" ) );
@@ -7625,8 +7392,8 @@ void mbedtls_ssl_config_free( mbedtls_ssl_config *conf )
{
mbedtls_zeroize( conf->psk, conf->psk_len );
mbedtls_zeroize( conf->psk_identity, conf->psk_identity_len );
- mbedtls_free( conf->psk );
- mbedtls_free( conf->psk_identity );
+ free( conf->psk );
+ free( conf->psk_identity );
conf->psk_len = 0;
conf->psk_identity_len = 0;
}
diff --git a/deps/mbedtls/timing.c b/deps/mbedtls/timing.c
index f620d09ee4..2ca0f75ecc 100644
--- a/deps/mbedtls/timing.c
+++ b/deps/mbedtls/timing.c
@@ -25,19 +25,10 @@
#include MBEDTLS_CONFIG_FILE
#endif
-#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif
-
#if defined(MBEDTLS_TIMING_C)
#include "mbedtls/timing.h"
-#if !defined(MBEDTLS_TIMING_ALT)
-
#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) && !defined(__HAIKU__)
#error "This module only works on Unix and Windows, see MBEDTLS_TIMING_C in config.h"
@@ -355,171 +346,4 @@ int mbedtls_timing_get_delay( void *data )
return( 0 );
}
-#endif /* !MBEDTLS_TIMING_ALT */
-
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * Busy-waits for the given number of milliseconds.
- * Used for testing mbedtls_timing_hardclock.
- */
-static void busy_msleep( unsigned long msec )
-{
- struct mbedtls_timing_hr_time hires;
- unsigned long i = 0; /* for busy-waiting */
- volatile unsigned long j; /* to prevent optimisation */
-
- (void) mbedtls_timing_get_timer( &hires, 1 );
-
- while( mbedtls_timing_get_timer( &hires, 0 ) < msec )
- i++;
-
- j = i;
- (void) j;
-}
-
-#define FAIL do \
-{ \
- if( verbose != 0 ) \
- mbedtls_printf( "failed\n" ); \
- \
- return( 1 ); \
-} while( 0 )
-
-/*
- * Checkup routine
- *
- * Warning: this is work in progress, some tests may not be reliable enough
- * yet! False positives may happen.
- */
-int mbedtls_timing_self_test( int verbose )
-{
- unsigned long cycles, ratio;
- unsigned long millisecs, secs;
- int hardfail;
- struct mbedtls_timing_hr_time hires;
- uint32_t a, b;
- mbedtls_timing_delay_context ctx;
-
- if( verbose != 0 )
- mbedtls_printf( " TIMING tests note: will take some time!\n" );
-
-
- if( verbose != 0 )
- mbedtls_printf( " TIMING test #1 (set_alarm / get_timer): " );
-
- for( secs = 1; secs <= 3; secs++ )
- {
- (void) mbedtls_timing_get_timer( &hires, 1 );
-
- mbedtls_set_alarm( (int) secs );
- while( !mbedtls_timing_alarmed )
- ;
-
- millisecs = mbedtls_timing_get_timer( &hires, 0 );
-
- /* For some reason on Windows it looks like alarm has an extra delay
- * (maybe related to creating a new thread). Allow some room here. */
- if( millisecs < 800 * secs || millisecs > 1200 * secs + 300 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( 1 );
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " TIMING test #2 (set/get_delay ): " );
-
- for( a = 200; a <= 400; a += 200 )
- {
- for( b = 200; b <= 400; b += 200 )
- {
- mbedtls_timing_set_delay( &ctx, a, a + b );
-
- busy_msleep( a - a / 8 );
- if( mbedtls_timing_get_delay( &ctx ) != 0 )
- FAIL;
-
- busy_msleep( a / 4 );
- if( mbedtls_timing_get_delay( &ctx ) != 1 )
- FAIL;
-
- busy_msleep( b - a / 8 - b / 8 );
- if( mbedtls_timing_get_delay( &ctx ) != 1 )
- FAIL;
-
- busy_msleep( b / 4 );
- if( mbedtls_timing_get_delay( &ctx ) != 2 )
- FAIL;
- }
- }
-
- mbedtls_timing_set_delay( &ctx, 0, 0 );
- busy_msleep( 200 );
- if( mbedtls_timing_get_delay( &ctx ) != -1 )
- FAIL;
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
- if( verbose != 0 )
- mbedtls_printf( " TIMING test #3 (hardclock / get_timer): " );
-
- /*
- * Allow one failure for possible counter wrapping.
- * On a 4Ghz 32-bit machine the cycle counter wraps about once per second;
- * since the whole test is about 10ms, it shouldn't happen twice in a row.
- */
- hardfail = 0;
-
-hard_test:
- if( hardfail > 1 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed (ignored)\n" );
-
- goto hard_test_done;
- }
-
- /* Get a reference ratio cycles/ms */
- millisecs = 1;
- cycles = mbedtls_timing_hardclock();
- busy_msleep( millisecs );
- cycles = mbedtls_timing_hardclock() - cycles;
- ratio = cycles / millisecs;
-
- /* Check that the ratio is mostly constant */
- for( millisecs = 2; millisecs <= 4; millisecs++ )
- {
- cycles = mbedtls_timing_hardclock();
- busy_msleep( millisecs );
- cycles = mbedtls_timing_hardclock() - cycles;
-
- /* Allow variation up to 20% */
- if( cycles / millisecs < ratio - ratio / 5 ||
- cycles / millisecs > ratio + ratio / 5 )
- {
- hardfail++;
- goto hard_test;
- }
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
-
-hard_test_done:
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
- return( 0 );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_TIMING_C */
diff --git a/deps/mbedtls/version.c b/deps/mbedtls/version.c
deleted file mode 100644
index 6ca80d4695..0000000000
--- a/deps/mbedtls/version.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Version information
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_VERSION_C)
-
-#include "mbedtls/version.h"
-#include
-
-unsigned int mbedtls_version_get_number()
-{
- return( MBEDTLS_VERSION_NUMBER );
-}
-
-void mbedtls_version_get_string( char *string )
-{
- memcpy( string, MBEDTLS_VERSION_STRING,
- sizeof( MBEDTLS_VERSION_STRING ) );
-}
-
-void mbedtls_version_get_string_full( char *string )
-{
- memcpy( string, MBEDTLS_VERSION_STRING_FULL,
- sizeof( MBEDTLS_VERSION_STRING_FULL ) );
-}
-
-#endif /* MBEDTLS_VERSION_C */
diff --git a/deps/mbedtls/version_features.c b/deps/mbedtls/version_features.c
deleted file mode 100644
index 5cbe8aca37..0000000000
--- a/deps/mbedtls/version_features.c
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * Version feature information
- *
- * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This file is part of mbed TLS (https://tls.mbed.org)
- */
-
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#if defined(MBEDTLS_VERSION_C)
-
-#include "mbedtls/version.h"
-
-#include
-
-static const char *features[] = {
-#if defined(MBEDTLS_VERSION_FEATURES)
-#if defined(MBEDTLS_HAVE_ASM)
- "MBEDTLS_HAVE_ASM",
-#endif /* MBEDTLS_HAVE_ASM */
-#if defined(MBEDTLS_NO_UDBL_DIVISION)
- "MBEDTLS_NO_UDBL_DIVISION",
-#endif /* MBEDTLS_NO_UDBL_DIVISION */
-#if defined(MBEDTLS_HAVE_SSE2)
- "MBEDTLS_HAVE_SSE2",
-#endif /* MBEDTLS_HAVE_SSE2 */
-#if defined(MBEDTLS_HAVE_TIME)
- "MBEDTLS_HAVE_TIME",
-#endif /* MBEDTLS_HAVE_TIME */
-#if defined(MBEDTLS_HAVE_TIME_DATE)
- "MBEDTLS_HAVE_TIME_DATE",
-#endif /* MBEDTLS_HAVE_TIME_DATE */
-#if defined(MBEDTLS_PLATFORM_MEMORY)
- "MBEDTLS_PLATFORM_MEMORY",
-#endif /* MBEDTLS_PLATFORM_MEMORY */
-#if defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
- "MBEDTLS_PLATFORM_NO_STD_FUNCTIONS",
-#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
-#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
- "MBEDTLS_PLATFORM_EXIT_ALT",
-#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
-#if defined(MBEDTLS_PLATFORM_TIME_ALT)
- "MBEDTLS_PLATFORM_TIME_ALT",
-#endif /* MBEDTLS_PLATFORM_TIME_ALT */
-#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
- "MBEDTLS_PLATFORM_FPRINTF_ALT",
-#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
-#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
- "MBEDTLS_PLATFORM_PRINTF_ALT",
-#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
-#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
- "MBEDTLS_PLATFORM_SNPRINTF_ALT",
-#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
-#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
- "MBEDTLS_PLATFORM_NV_SEED_ALT",
-#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
-#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
- "MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT",
-#endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
-#if defined(MBEDTLS_DEPRECATED_WARNING)
- "MBEDTLS_DEPRECATED_WARNING",
-#endif /* MBEDTLS_DEPRECATED_WARNING */
-#if defined(MBEDTLS_DEPRECATED_REMOVED)
- "MBEDTLS_DEPRECATED_REMOVED",
-#endif /* MBEDTLS_DEPRECATED_REMOVED */
-#if defined(MBEDTLS_TIMING_ALT)
- "MBEDTLS_TIMING_ALT",
-#endif /* MBEDTLS_TIMING_ALT */
-#if defined(MBEDTLS_AES_ALT)
- "MBEDTLS_AES_ALT",
-#endif /* MBEDTLS_AES_ALT */
-#if defined(MBEDTLS_ARC4_ALT)
- "MBEDTLS_ARC4_ALT",
-#endif /* MBEDTLS_ARC4_ALT */
-#if defined(MBEDTLS_BLOWFISH_ALT)
- "MBEDTLS_BLOWFISH_ALT",
-#endif /* MBEDTLS_BLOWFISH_ALT */
-#if defined(MBEDTLS_CAMELLIA_ALT)
- "MBEDTLS_CAMELLIA_ALT",
-#endif /* MBEDTLS_CAMELLIA_ALT */
-#if defined(MBEDTLS_DES_ALT)
- "MBEDTLS_DES_ALT",
-#endif /* MBEDTLS_DES_ALT */
-#if defined(MBEDTLS_XTEA_ALT)
- "MBEDTLS_XTEA_ALT",
-#endif /* MBEDTLS_XTEA_ALT */
-#if defined(MBEDTLS_MD2_ALT)
- "MBEDTLS_MD2_ALT",
-#endif /* MBEDTLS_MD2_ALT */
-#if defined(MBEDTLS_MD4_ALT)
- "MBEDTLS_MD4_ALT",
-#endif /* MBEDTLS_MD4_ALT */
-#if defined(MBEDTLS_MD5_ALT)
- "MBEDTLS_MD5_ALT",
-#endif /* MBEDTLS_MD5_ALT */
-#if defined(MBEDTLS_RIPEMD160_ALT)
- "MBEDTLS_RIPEMD160_ALT",
-#endif /* MBEDTLS_RIPEMD160_ALT */
-#if defined(MBEDTLS_SHA1_ALT)
- "MBEDTLS_SHA1_ALT",
-#endif /* MBEDTLS_SHA1_ALT */
-#if defined(MBEDTLS_SHA256_ALT)
- "MBEDTLS_SHA256_ALT",
-#endif /* MBEDTLS_SHA256_ALT */
-#if defined(MBEDTLS_SHA512_ALT)
- "MBEDTLS_SHA512_ALT",
-#endif /* MBEDTLS_SHA512_ALT */
-#if defined(MBEDTLS_ECP_ALT)
- "MBEDTLS_ECP_ALT",
-#endif /* MBEDTLS_ECP_ALT */
-#if defined(MBEDTLS_MD2_PROCESS_ALT)
- "MBEDTLS_MD2_PROCESS_ALT",
-#endif /* MBEDTLS_MD2_PROCESS_ALT */
-#if defined(MBEDTLS_MD4_PROCESS_ALT)
- "MBEDTLS_MD4_PROCESS_ALT",
-#endif /* MBEDTLS_MD4_PROCESS_ALT */
-#if defined(MBEDTLS_MD5_PROCESS_ALT)
- "MBEDTLS_MD5_PROCESS_ALT",
-#endif /* MBEDTLS_MD5_PROCESS_ALT */
-#if defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
- "MBEDTLS_RIPEMD160_PROCESS_ALT",
-#endif /* MBEDTLS_RIPEMD160_PROCESS_ALT */
-#if defined(MBEDTLS_SHA1_PROCESS_ALT)
- "MBEDTLS_SHA1_PROCESS_ALT",
-#endif /* MBEDTLS_SHA1_PROCESS_ALT */
-#if defined(MBEDTLS_SHA256_PROCESS_ALT)
- "MBEDTLS_SHA256_PROCESS_ALT",
-#endif /* MBEDTLS_SHA256_PROCESS_ALT */
-#if defined(MBEDTLS_SHA512_PROCESS_ALT)
- "MBEDTLS_SHA512_PROCESS_ALT",
-#endif /* MBEDTLS_SHA512_PROCESS_ALT */
-#if defined(MBEDTLS_DES_SETKEY_ALT)
- "MBEDTLS_DES_SETKEY_ALT",
-#endif /* MBEDTLS_DES_SETKEY_ALT */
-#if defined(MBEDTLS_DES_CRYPT_ECB_ALT)
- "MBEDTLS_DES_CRYPT_ECB_ALT",
-#endif /* MBEDTLS_DES_CRYPT_ECB_ALT */
-#if defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
- "MBEDTLS_DES3_CRYPT_ECB_ALT",
-#endif /* MBEDTLS_DES3_CRYPT_ECB_ALT */
-#if defined(MBEDTLS_AES_SETKEY_ENC_ALT)
- "MBEDTLS_AES_SETKEY_ENC_ALT",
-#endif /* MBEDTLS_AES_SETKEY_ENC_ALT */
-#if defined(MBEDTLS_AES_SETKEY_DEC_ALT)
- "MBEDTLS_AES_SETKEY_DEC_ALT",
-#endif /* MBEDTLS_AES_SETKEY_DEC_ALT */
-#if defined(MBEDTLS_AES_ENCRYPT_ALT)
- "MBEDTLS_AES_ENCRYPT_ALT",
-#endif /* MBEDTLS_AES_ENCRYPT_ALT */
-#if defined(MBEDTLS_AES_DECRYPT_ALT)
- "MBEDTLS_AES_DECRYPT_ALT",
-#endif /* MBEDTLS_AES_DECRYPT_ALT */
-#if defined(MBEDTLS_ECP_INTERNAL_ALT)
- "MBEDTLS_ECP_INTERNAL_ALT",
-#endif /* MBEDTLS_ECP_INTERNAL_ALT */
-#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
- "MBEDTLS_ECP_RANDOMIZE_JAC_ALT",
-#endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
-#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
- "MBEDTLS_ECP_ADD_MIXED_ALT",
-#endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
-#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
- "MBEDTLS_ECP_DOUBLE_JAC_ALT",
-#endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
-#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
- "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT",
-#endif /* MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT */
-#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
- "MBEDTLS_ECP_NORMALIZE_JAC_ALT",
-#endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
-#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
- "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT",
-#endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */
-#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
- "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT",
-#endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
-#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
- "MBEDTLS_ECP_NORMALIZE_MXZ_ALT",
-#endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */
-#if defined(MBEDTLS_TEST_NULL_ENTROPY)
- "MBEDTLS_TEST_NULL_ENTROPY",
-#endif /* MBEDTLS_TEST_NULL_ENTROPY */
-#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- "MBEDTLS_ENTROPY_HARDWARE_ALT",
-#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
-#if defined(MBEDTLS_AES_ROM_TABLES)
- "MBEDTLS_AES_ROM_TABLES",
-#endif /* MBEDTLS_AES_ROM_TABLES */
-#if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY)
- "MBEDTLS_CAMELLIA_SMALL_MEMORY",
-#endif /* MBEDTLS_CAMELLIA_SMALL_MEMORY */
-#if defined(MBEDTLS_CIPHER_MODE_CBC)
- "MBEDTLS_CIPHER_MODE_CBC",
-#endif /* MBEDTLS_CIPHER_MODE_CBC */
-#if defined(MBEDTLS_CIPHER_MODE_CFB)
- "MBEDTLS_CIPHER_MODE_CFB",
-#endif /* MBEDTLS_CIPHER_MODE_CFB */
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- "MBEDTLS_CIPHER_MODE_CTR",
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
- "MBEDTLS_CIPHER_NULL_CIPHER",
-#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
-#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
- "MBEDTLS_CIPHER_PADDING_PKCS7",
-#endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */
-#if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
- "MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS",
-#endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */
-#if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
- "MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN",
-#endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */
-#if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
- "MBEDTLS_CIPHER_PADDING_ZEROS",
-#endif /* MBEDTLS_CIPHER_PADDING_ZEROS */
-#if defined(MBEDTLS_ENABLE_WEAK_CIPHERSUITES)
- "MBEDTLS_ENABLE_WEAK_CIPHERSUITES",
-#endif /* MBEDTLS_ENABLE_WEAK_CIPHERSUITES */
-#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES)
- "MBEDTLS_REMOVE_ARC4_CIPHERSUITES",
-#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */
-#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
- "MBEDTLS_ECP_DP_SECP192R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
- "MBEDTLS_ECP_DP_SECP224R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
- "MBEDTLS_ECP_DP_SECP256R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
- "MBEDTLS_ECP_DP_SECP384R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
- "MBEDTLS_ECP_DP_SECP521R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
- "MBEDTLS_ECP_DP_SECP192K1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
- "MBEDTLS_ECP_DP_SECP224K1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
- "MBEDTLS_ECP_DP_SECP256K1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
- "MBEDTLS_ECP_DP_BP256R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
- "MBEDTLS_ECP_DP_BP384R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
- "MBEDTLS_ECP_DP_BP512R1_ENABLED",
-#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
-#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
- "MBEDTLS_ECP_DP_CURVE25519_ENABLED",
-#endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
-#if defined(MBEDTLS_ECP_NIST_OPTIM)
- "MBEDTLS_ECP_NIST_OPTIM",
-#endif /* MBEDTLS_ECP_NIST_OPTIM */
-#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- "MBEDTLS_ECDSA_DETERMINISTIC",
-#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
-#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_PSK_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */
-#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED",
-#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
-#if defined(MBEDTLS_PK_PARSE_EC_EXTENDED)
- "MBEDTLS_PK_PARSE_EC_EXTENDED",
-#endif /* MBEDTLS_PK_PARSE_EC_EXTENDED */
-#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
- "MBEDTLS_ERROR_STRERROR_DUMMY",
-#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
-#if defined(MBEDTLS_GENPRIME)
- "MBEDTLS_GENPRIME",
-#endif /* MBEDTLS_GENPRIME */
-#if defined(MBEDTLS_FS_IO)
- "MBEDTLS_FS_IO",
-#endif /* MBEDTLS_FS_IO */
-#if defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
- "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
-#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
-#if defined(MBEDTLS_NO_PLATFORM_ENTROPY)
- "MBEDTLS_NO_PLATFORM_ENTROPY",
-#endif /* MBEDTLS_NO_PLATFORM_ENTROPY */
-#if defined(MBEDTLS_ENTROPY_FORCE_SHA256)
- "MBEDTLS_ENTROPY_FORCE_SHA256",
-#endif /* MBEDTLS_ENTROPY_FORCE_SHA256 */
-#if defined(MBEDTLS_ENTROPY_NV_SEED)
- "MBEDTLS_ENTROPY_NV_SEED",
-#endif /* MBEDTLS_ENTROPY_NV_SEED */
-#if defined(MBEDTLS_MEMORY_DEBUG)
- "MBEDTLS_MEMORY_DEBUG",
-#endif /* MBEDTLS_MEMORY_DEBUG */
-#if defined(MBEDTLS_MEMORY_BACKTRACE)
- "MBEDTLS_MEMORY_BACKTRACE",
-#endif /* MBEDTLS_MEMORY_BACKTRACE */
-#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- "MBEDTLS_PK_RSA_ALT_SUPPORT",
-#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
-#if defined(MBEDTLS_PKCS1_V15)
- "MBEDTLS_PKCS1_V15",
-#endif /* MBEDTLS_PKCS1_V15 */
-#if defined(MBEDTLS_PKCS1_V21)
- "MBEDTLS_PKCS1_V21",
-#endif /* MBEDTLS_PKCS1_V21 */
-#if defined(MBEDTLS_RSA_NO_CRT)
- "MBEDTLS_RSA_NO_CRT",
-#endif /* MBEDTLS_RSA_NO_CRT */
-#if defined(MBEDTLS_SELF_TEST)
- "MBEDTLS_SELF_TEST",
-#endif /* MBEDTLS_SELF_TEST */
-#if defined(MBEDTLS_SHA256_SMALLER)
- "MBEDTLS_SHA256_SMALLER",
-#endif /* MBEDTLS_SHA256_SMALLER */
-#if defined(MBEDTLS_SSL_ALL_ALERT_MESSAGES)
- "MBEDTLS_SSL_ALL_ALERT_MESSAGES",
-#endif /* MBEDTLS_SSL_ALL_ALERT_MESSAGES */
-#if defined(MBEDTLS_SSL_DEBUG_ALL)
- "MBEDTLS_SSL_DEBUG_ALL",
-#endif /* MBEDTLS_SSL_DEBUG_ALL */
-#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- "MBEDTLS_SSL_ENCRYPT_THEN_MAC",
-#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
-#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
- "MBEDTLS_SSL_EXTENDED_MASTER_SECRET",
-#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
-#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
- "MBEDTLS_SSL_FALLBACK_SCSV",
-#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
-#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
- "MBEDTLS_SSL_HW_RECORD_ACCEL",
-#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
-#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
- "MBEDTLS_SSL_CBC_RECORD_SPLITTING",
-#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
-#if defined(MBEDTLS_SSL_RENEGOTIATION)
- "MBEDTLS_SSL_RENEGOTIATION",
-#endif /* MBEDTLS_SSL_RENEGOTIATION */
-#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
- "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO",
-#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
-#if defined(MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
- "MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE",
-#endif /* MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE */
-#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- "MBEDTLS_SSL_MAX_FRAGMENT_LENGTH",
-#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
-#if defined(MBEDTLS_SSL_PROTO_SSL3)
- "MBEDTLS_SSL_PROTO_SSL3",
-#endif /* MBEDTLS_SSL_PROTO_SSL3 */
-#if defined(MBEDTLS_SSL_PROTO_TLS1)
- "MBEDTLS_SSL_PROTO_TLS1",
-#endif /* MBEDTLS_SSL_PROTO_TLS1 */
-#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
- "MBEDTLS_SSL_PROTO_TLS1_1",
-#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
-#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- "MBEDTLS_SSL_PROTO_TLS1_2",
-#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
-#if defined(MBEDTLS_SSL_PROTO_DTLS)
- "MBEDTLS_SSL_PROTO_DTLS",
-#endif /* MBEDTLS_SSL_PROTO_DTLS */
-#if defined(MBEDTLS_SSL_ALPN)
- "MBEDTLS_SSL_ALPN",
-#endif /* MBEDTLS_SSL_ALPN */
-#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- "MBEDTLS_SSL_DTLS_ANTI_REPLAY",
-#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
-#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
- "MBEDTLS_SSL_DTLS_HELLO_VERIFY",
-#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY */
-#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE)
- "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE",
-#endif /* MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE */
-#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
- "MBEDTLS_SSL_DTLS_BADMAC_LIMIT",
-#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
-#if defined(MBEDTLS_SSL_SESSION_TICKETS)
- "MBEDTLS_SSL_SESSION_TICKETS",
-#endif /* MBEDTLS_SSL_SESSION_TICKETS */
-#if defined(MBEDTLS_SSL_EXPORT_KEYS)
- "MBEDTLS_SSL_EXPORT_KEYS",
-#endif /* MBEDTLS_SSL_EXPORT_KEYS */
-#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
- "MBEDTLS_SSL_SERVER_NAME_INDICATION",
-#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
-#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
- "MBEDTLS_SSL_TRUNCATED_HMAC",
-#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
-#if defined(MBEDTLS_THREADING_ALT)
- "MBEDTLS_THREADING_ALT",
-#endif /* MBEDTLS_THREADING_ALT */
-#if defined(MBEDTLS_THREADING_PTHREAD)
- "MBEDTLS_THREADING_PTHREAD",
-#endif /* MBEDTLS_THREADING_PTHREAD */
-#if defined(MBEDTLS_VERSION_FEATURES)
- "MBEDTLS_VERSION_FEATURES",
-#endif /* MBEDTLS_VERSION_FEATURES */
-#if defined(MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3)
- "MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3",
-#endif /* MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 */
-#if defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
- "MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION",
-#endif /* MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION */
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
- "MBEDTLS_X509_CHECK_KEY_USAGE",
-#endif /* MBEDTLS_X509_CHECK_KEY_USAGE */
-#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
- "MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE",
-#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
-#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
- "MBEDTLS_X509_RSASSA_PSS_SUPPORT",
-#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
-#if defined(MBEDTLS_ZLIB_SUPPORT)
- "MBEDTLS_ZLIB_SUPPORT",
-#endif /* MBEDTLS_ZLIB_SUPPORT */
-#if defined(MBEDTLS_AESNI_C)
- "MBEDTLS_AESNI_C",
-#endif /* MBEDTLS_AESNI_C */
-#if defined(MBEDTLS_AES_C)
- "MBEDTLS_AES_C",
-#endif /* MBEDTLS_AES_C */
-#if defined(MBEDTLS_ARC4_C)
- "MBEDTLS_ARC4_C",
-#endif /* MBEDTLS_ARC4_C */
-#if defined(MBEDTLS_ASN1_PARSE_C)
- "MBEDTLS_ASN1_PARSE_C",
-#endif /* MBEDTLS_ASN1_PARSE_C */
-#if defined(MBEDTLS_ASN1_WRITE_C)
- "MBEDTLS_ASN1_WRITE_C",
-#endif /* MBEDTLS_ASN1_WRITE_C */
-#if defined(MBEDTLS_BASE64_C)
- "MBEDTLS_BASE64_C",
-#endif /* MBEDTLS_BASE64_C */
-#if defined(MBEDTLS_BIGNUM_C)
- "MBEDTLS_BIGNUM_C",
-#endif /* MBEDTLS_BIGNUM_C */
-#if defined(MBEDTLS_BLOWFISH_C)
- "MBEDTLS_BLOWFISH_C",
-#endif /* MBEDTLS_BLOWFISH_C */
-#if defined(MBEDTLS_CAMELLIA_C)
- "MBEDTLS_CAMELLIA_C",
-#endif /* MBEDTLS_CAMELLIA_C */
-#if defined(MBEDTLS_CCM_C)
- "MBEDTLS_CCM_C",
-#endif /* MBEDTLS_CCM_C */
-#if defined(MBEDTLS_CERTS_C)
- "MBEDTLS_CERTS_C",
-#endif /* MBEDTLS_CERTS_C */
-#if defined(MBEDTLS_CIPHER_C)
- "MBEDTLS_CIPHER_C",
-#endif /* MBEDTLS_CIPHER_C */
-#if defined(MBEDTLS_CMAC_C)
- "MBEDTLS_CMAC_C",
-#endif /* MBEDTLS_CMAC_C */
-#if defined(MBEDTLS_CTR_DRBG_C)
- "MBEDTLS_CTR_DRBG_C",
-#endif /* MBEDTLS_CTR_DRBG_C */
-#if defined(MBEDTLS_DEBUG_C)
- "MBEDTLS_DEBUG_C",
-#endif /* MBEDTLS_DEBUG_C */
-#if defined(MBEDTLS_DES_C)
- "MBEDTLS_DES_C",
-#endif /* MBEDTLS_DES_C */
-#if defined(MBEDTLS_DHM_C)
- "MBEDTLS_DHM_C",
-#endif /* MBEDTLS_DHM_C */
-#if defined(MBEDTLS_ECDH_C)
- "MBEDTLS_ECDH_C",
-#endif /* MBEDTLS_ECDH_C */
-#if defined(MBEDTLS_ECDSA_C)
- "MBEDTLS_ECDSA_C",
-#endif /* MBEDTLS_ECDSA_C */
-#if defined(MBEDTLS_ECJPAKE_C)
- "MBEDTLS_ECJPAKE_C",
-#endif /* MBEDTLS_ECJPAKE_C */
-#if defined(MBEDTLS_ECP_C)
- "MBEDTLS_ECP_C",
-#endif /* MBEDTLS_ECP_C */
-#if defined(MBEDTLS_ENTROPY_C)
- "MBEDTLS_ENTROPY_C",
-#endif /* MBEDTLS_ENTROPY_C */
-#if defined(MBEDTLS_ERROR_C)
- "MBEDTLS_ERROR_C",
-#endif /* MBEDTLS_ERROR_C */
-#if defined(MBEDTLS_GCM_C)
- "MBEDTLS_GCM_C",
-#endif /* MBEDTLS_GCM_C */
-#if defined(MBEDTLS_HAVEGE_C)
- "MBEDTLS_HAVEGE_C",
-#endif /* MBEDTLS_HAVEGE_C */
-#if defined(MBEDTLS_HMAC_DRBG_C)
- "MBEDTLS_HMAC_DRBG_C",
-#endif /* MBEDTLS_HMAC_DRBG_C */
-#if defined(MBEDTLS_MD_C)
- "MBEDTLS_MD_C",
-#endif /* MBEDTLS_MD_C */
-#if defined(MBEDTLS_MD2_C)
- "MBEDTLS_MD2_C",
-#endif /* MBEDTLS_MD2_C */
-#if defined(MBEDTLS_MD4_C)
- "MBEDTLS_MD4_C",
-#endif /* MBEDTLS_MD4_C */
-#if defined(MBEDTLS_MD5_C)
- "MBEDTLS_MD5_C",
-#endif /* MBEDTLS_MD5_C */
-#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
- "MBEDTLS_MEMORY_BUFFER_ALLOC_C",
-#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
-#if defined(MBEDTLS_NET_C)
- "MBEDTLS_NET_C",
-#endif /* MBEDTLS_NET_C */
-#if defined(MBEDTLS_OID_C)
- "MBEDTLS_OID_C",
-#endif /* MBEDTLS_OID_C */
-#if defined(MBEDTLS_PADLOCK_C)
- "MBEDTLS_PADLOCK_C",
-#endif /* MBEDTLS_PADLOCK_C */
-#if defined(MBEDTLS_PEM_PARSE_C)
- "MBEDTLS_PEM_PARSE_C",
-#endif /* MBEDTLS_PEM_PARSE_C */
-#if defined(MBEDTLS_PEM_WRITE_C)
- "MBEDTLS_PEM_WRITE_C",
-#endif /* MBEDTLS_PEM_WRITE_C */
-#if defined(MBEDTLS_PK_C)
- "MBEDTLS_PK_C",
-#endif /* MBEDTLS_PK_C */
-#if defined(MBEDTLS_PK_PARSE_C)
- "MBEDTLS_PK_PARSE_C",
-#endif /* MBEDTLS_PK_PARSE_C */
-#if defined(MBEDTLS_PK_WRITE_C)
- "MBEDTLS_PK_WRITE_C",
-#endif /* MBEDTLS_PK_WRITE_C */
-#if defined(MBEDTLS_PKCS5_C)
- "MBEDTLS_PKCS5_C",
-#endif /* MBEDTLS_PKCS5_C */
-#if defined(MBEDTLS_PKCS11_C)
- "MBEDTLS_PKCS11_C",
-#endif /* MBEDTLS_PKCS11_C */
-#if defined(MBEDTLS_PKCS12_C)
- "MBEDTLS_PKCS12_C",
-#endif /* MBEDTLS_PKCS12_C */
-#if defined(MBEDTLS_PLATFORM_C)
- "MBEDTLS_PLATFORM_C",
-#endif /* MBEDTLS_PLATFORM_C */
-#if defined(MBEDTLS_RIPEMD160_C)
- "MBEDTLS_RIPEMD160_C",
-#endif /* MBEDTLS_RIPEMD160_C */
-#if defined(MBEDTLS_RSA_C)
- "MBEDTLS_RSA_C",
-#endif /* MBEDTLS_RSA_C */
-#if defined(MBEDTLS_SHA1_C)
- "MBEDTLS_SHA1_C",
-#endif /* MBEDTLS_SHA1_C */
-#if defined(MBEDTLS_SHA256_C)
- "MBEDTLS_SHA256_C",
-#endif /* MBEDTLS_SHA256_C */
-#if defined(MBEDTLS_SHA512_C)
- "MBEDTLS_SHA512_C",
-#endif /* MBEDTLS_SHA512_C */
-#if defined(MBEDTLS_SSL_CACHE_C)
- "MBEDTLS_SSL_CACHE_C",
-#endif /* MBEDTLS_SSL_CACHE_C */
-#if defined(MBEDTLS_SSL_COOKIE_C)
- "MBEDTLS_SSL_COOKIE_C",
-#endif /* MBEDTLS_SSL_COOKIE_C */
-#if defined(MBEDTLS_SSL_TICKET_C)
- "MBEDTLS_SSL_TICKET_C",
-#endif /* MBEDTLS_SSL_TICKET_C */
-#if defined(MBEDTLS_SSL_CLI_C)
- "MBEDTLS_SSL_CLI_C",
-#endif /* MBEDTLS_SSL_CLI_C */
-#if defined(MBEDTLS_SSL_SRV_C)
- "MBEDTLS_SSL_SRV_C",
-#endif /* MBEDTLS_SSL_SRV_C */
-#if defined(MBEDTLS_SSL_TLS_C)
- "MBEDTLS_SSL_TLS_C",
-#endif /* MBEDTLS_SSL_TLS_C */
-#if defined(MBEDTLS_THREADING_C)
- "MBEDTLS_THREADING_C",
-#endif /* MBEDTLS_THREADING_C */
-#if defined(MBEDTLS_TIMING_C)
- "MBEDTLS_TIMING_C",
-#endif /* MBEDTLS_TIMING_C */
-#if defined(MBEDTLS_VERSION_C)
- "MBEDTLS_VERSION_C",
-#endif /* MBEDTLS_VERSION_C */
-#if defined(MBEDTLS_X509_USE_C)
- "MBEDTLS_X509_USE_C",
-#endif /* MBEDTLS_X509_USE_C */
-#if defined(MBEDTLS_X509_CRT_PARSE_C)
- "MBEDTLS_X509_CRT_PARSE_C",
-#endif /* MBEDTLS_X509_CRT_PARSE_C */
-#if defined(MBEDTLS_X509_CRL_PARSE_C)
- "MBEDTLS_X509_CRL_PARSE_C",
-#endif /* MBEDTLS_X509_CRL_PARSE_C */
-#if defined(MBEDTLS_X509_CSR_PARSE_C)
- "MBEDTLS_X509_CSR_PARSE_C",
-#endif /* MBEDTLS_X509_CSR_PARSE_C */
-#if defined(MBEDTLS_X509_CREATE_C)
- "MBEDTLS_X509_CREATE_C",
-#endif /* MBEDTLS_X509_CREATE_C */
-#if defined(MBEDTLS_X509_CRT_WRITE_C)
- "MBEDTLS_X509_CRT_WRITE_C",
-#endif /* MBEDTLS_X509_CRT_WRITE_C */
-#if defined(MBEDTLS_X509_CSR_WRITE_C)
- "MBEDTLS_X509_CSR_WRITE_C",
-#endif /* MBEDTLS_X509_CSR_WRITE_C */
-#if defined(MBEDTLS_XTEA_C)
- "MBEDTLS_XTEA_C",
-#endif /* MBEDTLS_XTEA_C */
-#endif /* MBEDTLS_VERSION_FEATURES */
- NULL
-};
-
-int mbedtls_version_check_feature( const char *feature )
-{
- const char **idx = features;
-
- if( *idx == NULL )
- return( -2 );
-
- if( feature == NULL )
- return( -1 );
-
- while( *idx != NULL )
- {
- if( !strcmp( *idx, feature ) )
- return( 0 );
- idx++;
- }
- return( -1 );
-}
-
-#endif /* MBEDTLS_VERSION_C */
diff --git a/deps/mbedtls/x509.c b/deps/mbedtls/x509.c
index 88e32b067e..255f046402 100644
--- a/deps/mbedtls/x509.c
+++ b/deps/mbedtls/x509.c
@@ -48,21 +48,10 @@
#include "mbedtls/pem.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_free free
-#define mbedtls_calloc calloc
-#define mbedtls_printf printf
-#define mbedtls_snprintf snprintf
-#endif
-
-#if defined(MBEDTLS_HAVE_TIME)
-#include "mbedtls/platform_time.h"
-#endif
+#include
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include
@@ -457,7 +446,8 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
/* Mark this item as being no the only one in a set */
cur->next_merged = 1;
- cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
+ cur->next = (mbedtls_asn1_named_data*)
+ calloc( 1, sizeof( mbedtls_x509_name ) );
if( cur->next == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
@@ -471,7 +461,8 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
if( *p == end )
return( 0 );
- cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
+ cur->next = (mbedtls_asn1_named_data*)
+ calloc( 1, sizeof( mbedtls_x509_name ) );
if( cur->next == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
@@ -664,10 +655,10 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
if( *pk_alg == MBEDTLS_PK_RSASSA_PSS )
{
- mbedtls_pk_rsassa_pss_options *pss_opts;
-
- pss_opts = mbedtls_calloc( 1, sizeof( mbedtls_pk_rsassa_pss_options ) );
- if( pss_opts == NULL )
+ mbedtls_pk_rsassa_pss_options *pss_opts =
+ (mbedtls_pk_rsassa_pss_options *)
+ calloc( 1, sizeof( mbedtls_pk_rsassa_pss_options ) );
+ if (!pss_opts)
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
ret = mbedtls_x509_get_rsassa_pss_params( sig_params,
@@ -676,7 +667,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
&pss_opts->expected_salt_len );
if( ret != 0 )
{
- mbedtls_free( pss_opts );
+ free( pss_opts );
return( ret );
}
@@ -764,16 +755,16 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
if( name != dn )
{
- ret = mbedtls_snprintf( p, n, merge ? " + " : ", " );
+ ret = snprintf( p, n, merge ? " + " : ", " );
MBEDTLS_X509_SAFE_SNPRINTF;
}
ret = mbedtls_oid_get_attr_short_name( &name->oid, &short_name );
if( ret == 0 )
- ret = mbedtls_snprintf( p, n, "%s=", short_name );
+ ret = snprintf( p, n, "%s=", short_name );
else
- ret = mbedtls_snprintf( p, n, "\?\?=" );
+ ret = snprintf( p, n, "\?\?=" );
MBEDTLS_X509_SAFE_SNPRINTF;
for( i = 0; i < name->val.len; i++ )
@@ -787,7 +778,7 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
else s[i] = c;
}
s[i] = '\0';
- ret = mbedtls_snprintf( p, n, "%s", s );
+ ret = snprintf( p, n, "%s", s );
MBEDTLS_X509_SAFE_SNPRINTF;
merge = name->next_merged;
@@ -818,14 +809,14 @@ int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *se
if( i == 0 && nr > 1 && serial->p[i] == 0x0 )
continue;
- ret = mbedtls_snprintf( p, n, "%02X%s",
+ ret = snprintf( p, n, "%02X%s",
serial->p[i], ( i < nr - 1 ) ? ":" : "" );
MBEDTLS_X509_SAFE_SNPRINTF;
}
if( nr != serial->len )
{
- ret = mbedtls_snprintf( p, n, "...." );
+ ret = snprintf( p, n, "...." );
MBEDTLS_X509_SAFE_SNPRINTF;
}
@@ -846,9 +837,9 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
ret = mbedtls_oid_get_sig_alg_desc( sig_oid, &desc );
if( ret != 0 )
- ret = mbedtls_snprintf( p, n, "???" );
+ ret = snprintf( p, n, "???" );
else
- ret = mbedtls_snprintf( p, n, "%s", desc );
+ ret = snprintf( p, n, "%s", desc );
MBEDTLS_X509_SAFE_SNPRINTF;
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
@@ -862,7 +853,7 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
md_info = mbedtls_md_info_from_type( md_alg );
mgf_md_info = mbedtls_md_info_from_type( pss_opts->mgf1_hash_id );
- ret = mbedtls_snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
+ ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
md_info ? mbedtls_md_get_name( md_info ) : "???",
mgf_md_info ? mbedtls_md_get_name( mgf_md_info ) : "???",
pss_opts->expected_salt_len );
@@ -882,11 +873,9 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
*/
int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name )
{
- char *p = buf;
+ char *p = buf;
size_t n = buf_size;
- int ret;
-
- ret = mbedtls_snprintf( p, n, "%s key size", name );
+ int ret = snprintf( p, n, "%s key size", name );
MBEDTLS_X509_SAFE_SNPRINTF;
return( 0 );
@@ -917,7 +906,7 @@ static int x509_get_current_time( mbedtls_x509_time *now )
static int x509_get_current_time( mbedtls_x509_time *now )
{
struct tm *lt;
- mbedtls_time_t tt;
+ time_t tt;
int ret = 0;
#if defined(MBEDTLS_THREADING_C)
@@ -925,7 +914,7 @@ static int x509_get_current_time( mbedtls_x509_time *now )
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
- tt = mbedtls_time( NULL );
+ tt = time( NULL );
lt = gmtime( &tt );
if( lt == NULL )
@@ -1025,74 +1014,4 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from )
}
#endif /* MBEDTLS_HAVE_TIME_DATE */
-#if defined(MBEDTLS_SELF_TEST)
-
-#include "mbedtls/x509_crt.h"
-#include "mbedtls/certs.h"
-
-/*
- * Checkup routine
- */
-int mbedtls_x509_self_test( int verbose )
-{
-#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_SHA256_C)
- int ret;
- uint32_t flags;
- mbedtls_x509_crt cacert;
- mbedtls_x509_crt clicert;
-
- if( verbose != 0 )
- mbedtls_printf( " X.509 certificate load: " );
-
- mbedtls_x509_crt_init( &clicert );
-
- ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt,
- mbedtls_test_cli_crt_len );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( ret );
- }
-
- mbedtls_x509_crt_init( &cacert );
-
- ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_ca_crt,
- mbedtls_test_ca_crt_len );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( ret );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n X.509 signature verify: ");
-
- ret = mbedtls_x509_crt_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
- if( ret != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- return( ret );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n\n");
-
- mbedtls_x509_crt_free( &cacert );
- mbedtls_x509_crt_free( &clicert );
-
- return( 0 );
-#else
- ((void) verbose);
- return( 0 );
-#endif /* MBEDTLS_CERTS_C && MBEDTLS_SHA1_C */
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_X509_USE_C */
diff --git a/deps/mbedtls/x509_crl.c b/deps/mbedtls/x509_crl.c
index 83e1c2b2d4..0eae7b2b20 100644
--- a/deps/mbedtls/x509_crl.c
+++ b/deps/mbedtls/x509_crl.c
@@ -46,15 +46,8 @@
#include "mbedtls/pem.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_free free
-#define mbedtls_calloc calloc
-#define mbedtls_snprintf snprintf
-#endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include
@@ -234,7 +227,7 @@ static int x509_get_entries( unsigned char **p,
if( *p < end )
{
- cur_entry->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl_entry ) );
+ cur_entry->next = (mbedtls_x509_crl_entry*)calloc( 1, sizeof( mbedtls_x509_crl_entry ) );
if( cur_entry->next == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
@@ -276,7 +269,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
if( crl->version != 0 && crl->next == NULL )
{
- crl->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl ) );
+ crl->next = (mbedtls_x509_crl*)calloc( 1, sizeof( mbedtls_x509_crl ) );
if( crl->next == NULL )
{
@@ -291,7 +284,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
/*
* Copy raw DER-encoded CRL
*/
- if( ( p = mbedtls_calloc( 1, buflen ) ) == NULL )
+ if( ( p = (unsigned char*)calloc( 1, buflen ) ) == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
memcpy( p, buf, buflen );
@@ -561,7 +554,7 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
ret = mbedtls_x509_crl_parse( chain, buf, n );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
@@ -588,23 +581,23 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
p = buf;
n = size;
- ret = mbedtls_snprintf( p, n, "%sCRL version : %d",
+ ret = snprintf( p, n, "%sCRL version : %d",
prefix, crl->version );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
+ ret = snprintf( p, n, "\n%sissuer name : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_dn_gets( p, n, &crl->issuer );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%sthis update : " \
+ ret = snprintf( p, n, "\n%sthis update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->this_update.year, crl->this_update.mon,
crl->this_update.day, crl->this_update.hour,
crl->this_update.min, crl->this_update.sec );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%snext update : " \
+ ret = snprintf( p, n, "\n%snext update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->next_update.year, crl->next_update.mon,
crl->next_update.day, crl->next_update.hour,
@@ -613,20 +606,20 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
entry = &crl->entry;
- ret = mbedtls_snprintf( p, n, "\n%sRevoked certificates:",
+ ret = snprintf( p, n, "\n%sRevoked certificates:",
prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
while( entry != NULL && entry->raw.len != 0 )
{
- ret = mbedtls_snprintf( p, n, "\n%sserial number: ",
+ ret = snprintf( p, n, "\n%sserial number: ",
prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_serial_gets( p, n, &entry->serial );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, " revocation date: " \
+ ret = snprintf( p, n, " revocation date: " \
"%04d-%02d-%02d %02d:%02d:%02d",
entry->revocation_date.year, entry->revocation_date.mon,
entry->revocation_date.day, entry->revocation_date.hour,
@@ -636,14 +629,14 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
entry = entry->next;
}
- ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = snprintf( p, n, "\n%ssigned using : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_sig_alg_gets( p, n, &crl->sig_oid, crl->sig_pk, crl->sig_md,
crl->sig_opts );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n" );
+ ret = snprintf( p, n, "\n" );
MBEDTLS_X509_SAFE_SNPRINTF;
return( (int) ( size - n ) );
@@ -675,7 +668,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
do
{
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
- mbedtls_free( crl_cur->sig_opts );
+ free( crl_cur->sig_opts );
#endif
name_cur = crl_cur->issuer.next;
@@ -684,7 +677,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
name_prv = name_cur;
name_cur = name_cur->next;
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
- mbedtls_free( name_prv );
+ free( name_prv );
}
entry_cur = crl_cur->entry.next;
@@ -693,13 +686,13 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
entry_prv = entry_cur;
entry_cur = entry_cur->next;
mbedtls_zeroize( entry_prv, sizeof( mbedtls_x509_crl_entry ) );
- mbedtls_free( entry_prv );
+ free( entry_prv );
}
if( crl_cur->raw.p != NULL )
{
mbedtls_zeroize( crl_cur->raw.p, crl_cur->raw.len );
- mbedtls_free( crl_cur->raw.p );
+ free( crl_cur->raw.p );
}
crl_cur = crl_cur->next;
@@ -714,7 +707,7 @@ void mbedtls_x509_crl_free( mbedtls_x509_crl *crl )
mbedtls_zeroize( crl_prv, sizeof( mbedtls_x509_crl ) );
if( crl_prv != crl )
- mbedtls_free( crl_prv );
+ free( crl_prv );
}
while( crl_cur != NULL );
}
diff --git a/deps/mbedtls/x509_crt.c b/deps/mbedtls/x509_crt.c
index 8a49031ace..5fa3a8e1ab 100644
--- a/deps/mbedtls/x509_crt.c
+++ b/deps/mbedtls/x509_crt.c
@@ -42,19 +42,13 @@
#include
#include
+#include
#if defined(MBEDTLS_PEM_PARSE_C)
#include "mbedtls/pem.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
-#define mbedtls_free free
-#define mbedtls_calloc calloc
-#define mbedtls_snprintf snprintf
-#endif
#if defined(MBEDTLS_THREADING_C)
#include "mbedtls/threading.h"
@@ -486,7 +480,8 @@ static int x509_get_subject_alt_name( unsigned char **p,
if( cur->next != NULL )
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS );
- cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
+ cur->next = (mbedtls_asn1_sequence*)
+ calloc( 1, sizeof( mbedtls_asn1_sequence ) );
if( cur->next == NULL )
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
@@ -704,7 +699,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, const unsigned char *
/* Create and populate a new buffer for the raw field */
crt->raw.len = crt_end - buf;
- crt->raw.p = p = mbedtls_calloc( 1, crt->raw.len );
+ crt->raw.p = p = (unsigned char*)calloc( 1, crt->raw.len );
if( p == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
@@ -936,9 +931,9 @@ int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *bu
/*
* Add new certificate on the end of the chain if needed.
*/
- if( crt->version != 0 && crt->next == NULL )
+ if( crt->version != 0 && !crt->next)
{
- crt->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
+ crt->next = (mbedtls_x509_crt*)calloc( 1, sizeof( mbedtls_x509_crt ) );
if( crt->next == NULL )
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
@@ -954,7 +949,7 @@ int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *bu
prev->next = NULL;
if( crt != chain )
- mbedtls_free( crt );
+ free( crt );
return( ret );
}
@@ -1093,7 +1088,7 @@ int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path )
ret = mbedtls_x509_crt_parse( chain, buf, n );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
@@ -1182,7 +1177,7 @@ cleanup:
while( ( entry = readdir( dir ) ) != NULL )
{
- snp_ret = mbedtls_snprintf( entry_name, sizeof entry_name,
+ snp_ret = snprintf( entry_name, sizeof entry_name,
"%s/%s", path, entry->d_name );
if( snp_ret < 0 || (size_t)snp_ret >= sizeof entry_name )
@@ -1261,7 +1256,7 @@ static int x509_info_subject_alt_name( char **buf, size_t *size,
#define PRINT_ITEM(i) \
{ \
- ret = mbedtls_snprintf( p, n, "%s" i, sep ); \
+ ret = snprintf( p, n, "%s" i, sep ); \
MBEDTLS_X509_SAFE_SNPRINTF; \
sep = ", "; \
}
@@ -1336,7 +1331,7 @@ static int x509_info_ext_key_usage( char **buf, size_t *size,
if( mbedtls_oid_get_extended_key_usage( &cur->buf, &desc ) != 0 )
desc = "???";
- ret = mbedtls_snprintf( p, n, "%s%s", sep, desc );
+ ret = snprintf( p, n, "%s%s", sep, desc );
MBEDTLS_X509_SAFE_SNPRINTF;
sep = ", ";
@@ -1370,47 +1365,47 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
if( NULL == crt )
{
- ret = mbedtls_snprintf( p, n, "\nCertificate is uninitialised!\n" );
+ ret = snprintf( p, n, "\nCertificate is uninitialised!\n" );
MBEDTLS_X509_SAFE_SNPRINTF;
return( (int) ( size - n ) );
}
- ret = mbedtls_snprintf( p, n, "%scert. version : %d\n",
+ ret = snprintf( p, n, "%scert. version : %d\n",
prefix, crt->version );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "%sserial number : ",
+ ret = snprintf( p, n, "%sserial number : ",
prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_serial_gets( p, n, &crt->serial );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%sissuer name : ", prefix );
+ ret = snprintf( p, n, "\n%sissuer name : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_dn_gets( p, n, &crt->issuer );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%ssubject name : ", prefix );
+ ret = snprintf( p, n, "\n%ssubject name : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_dn_gets( p, n, &crt->subject );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%sissued on : " \
+ ret = snprintf( p, n, "\n%sissued on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_from.year, crt->valid_from.mon,
crt->valid_from.day, crt->valid_from.hour,
crt->valid_from.min, crt->valid_from.sec );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%sexpires on : " \
+ ret = snprintf( p, n, "\n%sexpires on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_to.year, crt->valid_to.mon,
crt->valid_to.day, crt->valid_to.hour,
crt->valid_to.min, crt->valid_to.sec );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = snprintf( p, n, "\n%ssigned using : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_sig_alg_gets( p, n, &crt->sig_oid, crt->sig_pk,
@@ -1420,11 +1415,9 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
/* Key size */
if( ( ret = mbedtls_x509_key_size_helper( key_size_str, BEFORE_COLON,
mbedtls_pk_get_name( &crt->pk ) ) ) != 0 )
- {
return( ret );
- }
- ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
+ ret = snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
(int) mbedtls_pk_get_bitlen( &crt->pk ) );
MBEDTLS_X509_SAFE_SNPRINTF;
@@ -1434,20 +1427,20 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & MBEDTLS_X509_EXT_BASIC_CONSTRAINTS )
{
- ret = mbedtls_snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
+ ret = snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
crt->ca_istrue ? "true" : "false" );
MBEDTLS_X509_SAFE_SNPRINTF;
if( crt->max_pathlen > 0 )
{
- ret = mbedtls_snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
+ ret = snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
MBEDTLS_X509_SAFE_SNPRINTF;
}
}
if( crt->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME )
{
- ret = mbedtls_snprintf( p, n, "\n%ssubject alt name : ", prefix );
+ ret = snprintf( p, n, "\n%ssubject alt name : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
if( ( ret = x509_info_subject_alt_name( &p, &n,
@@ -1457,7 +1450,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & MBEDTLS_X509_EXT_NS_CERT_TYPE )
{
- ret = mbedtls_snprintf( p, n, "\n%scert. type : ", prefix );
+ ret = snprintf( p, n, "\n%scert. type : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
if( ( ret = x509_info_cert_type( &p, &n, crt->ns_cert_type ) ) != 0 )
@@ -1466,7 +1459,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE )
{
- ret = mbedtls_snprintf( p, n, "\n%skey usage : ", prefix );
+ ret = snprintf( p, n, "\n%skey usage : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
if( ( ret = x509_info_key_usage( &p, &n, crt->key_usage ) ) != 0 )
@@ -1475,7 +1468,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
if( crt->ext_types & MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE )
{
- ret = mbedtls_snprintf( p, n, "\n%sext key usage : ", prefix );
+ ret = snprintf( p, n, "\n%sext key usage : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
if( ( ret = x509_info_ext_key_usage( &p, &n,
@@ -1483,7 +1476,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
return( ret );
}
- ret = mbedtls_snprintf( p, n, "\n" );
+ ret = snprintf( p, n, "\n" );
MBEDTLS_X509_SAFE_SNPRINTF;
return( (int) ( size - n ) );
@@ -1531,14 +1524,14 @@ int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
if( ( flags & cur->code ) == 0 )
continue;
- ret = mbedtls_snprintf( p, n, "%s%s\n", prefix, cur->string );
+ ret = snprintf( p, n, "%s%s\n", prefix, cur->string );
MBEDTLS_X509_SAFE_SNPRINTF;
flags ^= cur->code;
}
if( flags != 0 )
{
- ret = mbedtls_snprintf( p, n, "%sUnknown reason "
+ ret = snprintf( p, n, "%sUnknown reason "
"(this should not happen)\n", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
}
@@ -1727,7 +1720,7 @@ static int x509_memcasecmp( const void *s1, const void *s2, size_t len )
{
size_t i;
unsigned char diff;
- const unsigned char *n1 = s1, *n2 = s2;
+ const unsigned char *n1 = (const unsigned char*)s1, *n2 = (const unsigned char*)s2;
for( i = 0; i < len; i++ )
{
@@ -2342,7 +2335,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
mbedtls_pk_free( &cert_cur->pk );
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
- mbedtls_free( cert_cur->sig_opts );
+ free( cert_cur->sig_opts );
#endif
name_cur = cert_cur->issuer.next;
@@ -2351,7 +2344,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
name_prv = name_cur;
name_cur = name_cur->next;
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
- mbedtls_free( name_prv );
+ free( name_prv );
}
name_cur = cert_cur->subject.next;
@@ -2360,7 +2353,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
name_prv = name_cur;
name_cur = name_cur->next;
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
- mbedtls_free( name_prv );
+ free( name_prv );
}
seq_cur = cert_cur->ext_key_usage.next;
@@ -2369,7 +2362,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
seq_prv = seq_cur;
seq_cur = seq_cur->next;
mbedtls_zeroize( seq_prv, sizeof( mbedtls_x509_sequence ) );
- mbedtls_free( seq_prv );
+ free( seq_prv );
}
seq_cur = cert_cur->subject_alt_names.next;
@@ -2378,13 +2371,13 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
seq_prv = seq_cur;
seq_cur = seq_cur->next;
mbedtls_zeroize( seq_prv, sizeof( mbedtls_x509_sequence ) );
- mbedtls_free( seq_prv );
+ free( seq_prv );
}
if( cert_cur->raw.p != NULL )
{
mbedtls_zeroize( cert_cur->raw.p, cert_cur->raw.len );
- mbedtls_free( cert_cur->raw.p );
+ free( cert_cur->raw.p );
}
cert_cur = cert_cur->next;
@@ -2399,7 +2392,7 @@ void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
mbedtls_zeroize( cert_prv, sizeof( mbedtls_x509_crt ) );
if( cert_prv != crt )
- mbedtls_free( cert_prv );
+ free( cert_prv );
}
while( cert_cur != NULL );
}
diff --git a/deps/mbedtls/x509_csr.c b/deps/mbedtls/x509_csr.c
index a67b672462..c82b1c89a2 100644
--- a/deps/mbedtls/x509_csr.c
+++ b/deps/mbedtls/x509_csr.c
@@ -46,15 +46,8 @@
#include "mbedtls/pem.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
#include
#include
-#define mbedtls_free free
-#define mbedtls_calloc calloc
-#define mbedtls_snprintf snprintf
-#endif
#if defined(MBEDTLS_FS_IO) || defined(EFIX64) || defined(EFI32)
#include
@@ -109,9 +102,9 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
/*
* first copy the raw DER data
*/
- p = mbedtls_calloc( 1, len = buflen );
+ p = (unsigned char*)calloc( 1, len = buflen );
- if( p == NULL )
+ if (!p)
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
memcpy( p, buf, buflen );
@@ -323,7 +316,7 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path )
ret = mbedtls_x509_csr_parse( csr, buf, n );
mbedtls_zeroize( buf, n );
- mbedtls_free( buf );
+ free( buf );
return( ret );
}
@@ -338,24 +331,19 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path )
int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
const mbedtls_x509_csr *csr )
{
- int ret;
- size_t n;
- char *p;
char key_size_str[BEFORE_COLON];
-
- p = buf;
- n = size;
-
- ret = mbedtls_snprintf( p, n, "%sCSR version : %d",
+ char *p = buf;
+ size_t n = size;
+ int ret = snprintf( p, n, "%sCSR version : %d",
prefix, csr->version );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%ssubject name : ", prefix );
+ ret = snprintf( p, n, "\n%ssubject name : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_dn_gets( p, n, &csr->subject );
MBEDTLS_X509_SAFE_SNPRINTF;
- ret = mbedtls_snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = snprintf( p, n, "\n%ssigned using : ", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
ret = mbedtls_x509_sig_alg_gets( p, n, &csr->sig_oid, csr->sig_pk, csr->sig_md,
@@ -368,7 +356,7 @@ int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
return( ret );
}
- ret = mbedtls_snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
+ ret = snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
(int) mbedtls_pk_get_bitlen( &csr->pk ) );
MBEDTLS_X509_SAFE_SNPRINTF;
@@ -397,7 +385,7 @@ void mbedtls_x509_csr_free( mbedtls_x509_csr *csr )
mbedtls_pk_free( &csr->pk );
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
- mbedtls_free( csr->sig_opts );
+ free( csr->sig_opts );
#endif
name_cur = csr->subject.next;
@@ -406,13 +394,13 @@ void mbedtls_x509_csr_free( mbedtls_x509_csr *csr )
name_prv = name_cur;
name_cur = name_cur->next;
mbedtls_zeroize( name_prv, sizeof( mbedtls_x509_name ) );
- mbedtls_free( name_prv );
+ free( name_prv );
}
if( csr->raw.p != NULL )
{
mbedtls_zeroize( csr->raw.p, csr->raw.len );
- mbedtls_free( csr->raw.p );
+ free( csr->raw.p );
}
mbedtls_zeroize( csr, sizeof( mbedtls_x509_csr ) );
diff --git a/deps/mbedtls/xtea.c b/deps/mbedtls/xtea.c
index fb2d6dce23..8e64dfef3b 100644
--- a/deps/mbedtls/xtea.c
+++ b/deps/mbedtls/xtea.c
@@ -31,15 +31,6 @@
#include
-#if defined(MBEDTLS_SELF_TEST)
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include
-#define mbedtls_printf printf
-#endif /* MBEDTLS_PLATFORM_C */
-#endif /* MBEDTLS_SELF_TEST */
-
#if !defined(MBEDTLS_XTEA_ALT)
#include "arc4_alt.h"
@@ -189,90 +180,4 @@ int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx, int mode, size_t length,
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#endif /* !MBEDTLS_XTEA_ALT */
-#if defined(MBEDTLS_SELF_TEST)
-
-/*
- * XTEA tests vectors (non-official)
- */
-
-static const unsigned char xtea_test_key[6][16] =
-{
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
- 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
- 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
- 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00 }
-};
-
-static const unsigned char xtea_test_pt[6][8] =
-{
- { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
- { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
-};
-
-static const unsigned char xtea_test_ct[6][8] =
-{
- { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
- { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
- { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
-};
-
-/*
- * Checkup routine
- */
-int mbedtls_xtea_self_test( int verbose )
-{
- int i, ret = 0;
- unsigned char buf[8];
- mbedtls_xtea_context ctx;
-
- mbedtls_xtea_init( &ctx );
- for( i = 0; i < 6; i++ )
- {
- if( verbose != 0 )
- mbedtls_printf( " XTEA test #%d: ", i + 1 );
-
- memcpy( buf, xtea_test_pt[i], 8 );
-
- mbedtls_xtea_setup( &ctx, xtea_test_key[i] );
- mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, buf, buf );
-
- if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )
- {
- if( verbose != 0 )
- mbedtls_printf( "failed\n" );
-
- ret = 1;
- goto exit;
- }
-
- if( verbose != 0 )
- mbedtls_printf( "passed\n" );
- }
-
- if( verbose != 0 )
- mbedtls_printf( "\n" );
-
-exit:
- mbedtls_xtea_free( &ctx );
-
- return( ret );
-}
-
-#endif /* MBEDTLS_SELF_TEST */
-
#endif /* MBEDTLS_XTEA_C */
diff --git a/deps/rcheevos/src/rcheevos/compat.c b/deps/rcheevos/src/rcheevos/compat.c
index 6d6402503f..53eeb3292d 100644
--- a/deps/rcheevos/src/rcheevos/compat.c
+++ b/deps/rcheevos/src/rcheevos/compat.c
@@ -22,6 +22,24 @@ int rc_strncasecmp(const char* left, const char* right, size_t length)
return 0;
}
+int rc_strcasecmp(const char* left, const char* right)
+{
+ while (*left || *right)
+ {
+ if (*left != *right)
+ {
+ const int diff = tolower(*left) - tolower(*right);
+ if (diff != 0)
+ return diff;
+ }
+
+ ++left;
+ ++right;
+ }
+
+ return 0;
+}
+
char* rc_strdup(const char* str)
{
const size_t length = strlen(str);
diff --git a/deps/rcheevos/src/rcheevos/compat.h b/deps/rcheevos/src/rcheevos/compat.h
index 3bc648ab0f..62c362f47e 100644
--- a/deps/rcheevos/src/rcheevos/compat.h
+++ b/deps/rcheevos/src/rcheevos/compat.h
@@ -41,6 +41,11 @@ extern "C" {
#define strncasecmp rc_strncasecmp
#endif
+#ifndef strcasecmp
+ extern int rc_strcasecmp(const char* left, const char* right);
+ #define strcasecmp rc_strcasecmp
+#endif
+
#ifndef strdup
extern char* rc_strdup(const char* str);
#define strdup rc_strdup
diff --git a/deps/rcheevos/src/rcheevos/condition.c b/deps/rcheevos/src/rcheevos/condition.c
index 1afb8bbbd2..29046aae99 100644
--- a/deps/rcheevos/src/rcheevos/condition.c
+++ b/deps/rcheevos/src/rcheevos/condition.c
@@ -213,9 +213,20 @@ int rc_evaluate_condition_value(rc_condition_t* self, rc_eval_state_t* eval_stat
case RC_OPERATOR_DIV:
if (self->operand2.type == RC_OPERAND_FP)
- value = (int)((double)value / self->operand2.value.dbl);
+ {
+ if (self->operand2.value.dbl == 0.0)
+ value = 0;
+ else
+ value = (int)((double)value / self->operand2.value.dbl);
+ }
else
- value /= rc_evaluate_operand(&self->operand2, eval_state);
+ {
+ unsigned value2 = rc_evaluate_operand(&self->operand2, eval_state);
+ if (value2 == 0)
+ value = 0;
+ else
+ value /= value2;
+ }
break;
case RC_OPERATOR_AND:
diff --git a/deps/rcheevos/src/rcheevos/condset.c b/deps/rcheevos/src/rcheevos/condset.c
index 9e142a61d3..345b1c142f 100644
--- a/deps/rcheevos/src/rcheevos/condset.c
+++ b/deps/rcheevos/src/rcheevos/condset.c
@@ -114,6 +114,7 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, rc
rc_condition_t* condition;
int set_valid, cond_valid, and_next, or_next;
unsigned measured_value = 0;
+ unsigned total_hits = 0;
int can_measure = 1, measured_from_hits = 0;
eval_state->primed = 1;
@@ -207,12 +208,14 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, rc
break;
}
+ /* STEP 4: calculate total hits */
+ total_hits = condition->current_hits;
+
if (eval_state->add_hits) {
if (condition->required_hits != 0) {
/* if the condition has a target hit count, we have to recalculate cond_valid including the AddHits counter */
- measured_from_hits = 1;
- measured_value = condition->current_hits + eval_state->add_hits;
- cond_valid = (measured_value >= condition->required_hits);
+ total_hits = condition->current_hits + eval_state->add_hits;
+ cond_valid = (total_hits >= condition->required_hits);
}
else {
/* no target hit count. we can't tell if the add_hits value is from this frame or not, so ignore it.
@@ -221,13 +224,8 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, rc
eval_state->add_hits = 0;
}
- else if (condition->required_hits != 0) {
- /* if there's a hit target, capture the current hits for recording Measured value later */
- measured_from_hits = 1;
- measured_value = condition->current_hits;
- }
- /* STEP 4: handle special flags */
+ /* STEP 5: handle special flags */
switch (condition->type) {
case RC_CONDITION_PAUSE_IF:
/* as soon as we find a PauseIf that evaluates to true, stop processing the rest of the group */
@@ -256,6 +254,14 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, rc
}
continue;
+ case RC_CONDITION_MEASURED:
+ if (condition->required_hits != 0) {
+ /* if there's a hit target, capture the current hits for recording Measured value later */
+ measured_from_hits = 1;
+ measured_value = total_hits;
+ }
+ break;
+
case RC_CONDITION_MEASURED_IF:
if (!cond_valid)
can_measure = 0;
diff --git a/deps/rcheevos/src/rcheevos/consoleinfo.c b/deps/rcheevos/src/rcheevos/consoleinfo.c
index 7507791b44..063e3a8209 100644
--- a/deps/rcheevos/src/rcheevos/consoleinfo.c
+++ b/deps/rcheevos/src/rcheevos/consoleinfo.c
@@ -113,7 +113,7 @@ const char* rc_console_name(int console_id)
return "PC-9800";
case RC_CONSOLE_PCFX:
- return "PCFX";
+ return "PC-FX";
case RC_CONSOLE_PC_ENGINE:
return "PCEngine";
@@ -394,6 +394,15 @@ static const rc_memory_region_t _rc_memory_regions_pcengine[] = {
};
static const rc_memory_regions_t rc_memory_regions_pcengine = { _rc_memory_regions_pcengine, 4 };
+/* ===== PC-FX ===== */
+/* http://daifukkat.su/pcfx/data/memmap.html */
+static const rc_memory_region_t _rc_memory_regions_pcfx[] = {
+ { 0x000000U, 0x1FFFFFU, 0x00000000U, RC_MEMORY_TYPE_SYSTEM_RAM, "System RAM" },
+ { 0x200000U, 0x207FFFU, 0xE0000000U, RC_MEMORY_TYPE_SAVE_RAM, "Internal Backup Memory" },
+ { 0x208000U, 0x20FFFFU, 0xE8000000U, RC_MEMORY_TYPE_SAVE_RAM, "External Backup Memory" },
+};
+static const rc_memory_regions_t rc_memory_regions_pcfx = { _rc_memory_regions_pcfx, 3 };
+
/* ===== PlayStation ===== */
/* http://www.raphnet.net/electronique/psx_adaptor/Playstation.txt */
static const rc_memory_region_t _rc_memory_regions_playstation[] = {
@@ -421,7 +430,7 @@ static const rc_memory_regions_t rc_memory_regions_segacd = { _rc_memory_regions
/* https://segaretro.org/Sega_Saturn_hardware_notes_(2004-04-27) */
static const rc_memory_region_t _rc_memory_regions_saturn[] = {
{ 0x000000U, 0x0FFFFFU, 0x00200000U, RC_MEMORY_TYPE_SYSTEM_RAM, "Work RAM Low" },
- { 0x100000U, 0x1FFFFFU, 0x06000000U, RC_MEMORY_TYPE_SAVE_RAM, "Work RAM High" }
+ { 0x100000U, 0x1FFFFFU, 0x06000000U, RC_MEMORY_TYPE_SYSTEM_RAM, "Work RAM High" }
};
static const rc_memory_regions_t rc_memory_regions_saturn = { _rc_memory_regions_saturn, 2 };
@@ -455,15 +464,6 @@ static const rc_memory_region_t _rc_memory_regions_snes[] = {
};
static const rc_memory_regions_t rc_memory_regions_snes = { _rc_memory_regions_snes, 2 };
-/* ===== WonderSwan ===== */
-/* http://daifukkat.su/docs/wsman/#ovr_memmap */
-static const rc_memory_region_t _rc_memory_regions_wonderswan[] = {
- /* RAM ends at 0x3FFF for WonderSwan, WonderSwan color uses all 64KB */
- { 0x000000U, 0x00FFFFU, 0x000000U, RC_MEMORY_TYPE_SYSTEM_RAM, "System RAM" },
- { 0x010000U, 0x01FFFFU, 0x000000U, RC_MEMORY_TYPE_SAVE_RAM, "Cartridge RAM" }
-};
-static const rc_memory_regions_t rc_memory_regions_wonderswan = { _rc_memory_regions_wonderswan, 2 };
-
/* ===== Vectrex ===== */
/* https://roadsidethoughts.com/vectrex/vectrex-memory-map.htm */
static const rc_memory_region_t _rc_memory_regions_vectrex[] = {
@@ -478,6 +478,23 @@ static const rc_memory_region_t _rc_memory_regions_virtualboy[] = {
};
static const rc_memory_regions_t rc_memory_regions_virtualboy = { _rc_memory_regions_virtualboy, 2 };
+/* ===== WonderSwan ===== */
+/* http://daifukkat.su/docs/wsman/#ovr_memmap */
+static const rc_memory_region_t _rc_memory_regions_wonderswan[] = {
+ /* RAM ends at 0x3FFF for WonderSwan, WonderSwan color uses all 64KB */
+ { 0x000000U, 0x00FFFFU, 0x000000U, RC_MEMORY_TYPE_SYSTEM_RAM, "System RAM" },
+ /* Only 64KB of SRAM is accessible via the addressing scheme, but the cartridge
+ * may have up to 512KB of SRAM. http://daifukkat.su/docs/wsman/#cart_meta
+ * Since beetle_wswan exposes it as a contiguous block, assume its contiguous
+ * even though the documentation says $20000-$FFFFF is ROM data. If this causes
+ * a conflict in the future, we can revisit. A new region with a virtual address
+ * could be added to pick up the additional SRAM data. As long as it immediately
+ * follows the 64KB at $10000, all existing achievements should be unaffected.
+ */
+ { 0x010000U, 0x08FFFFU, 0x010000U, RC_MEMORY_TYPE_SAVE_RAM, "Cartridge RAM" }
+};
+static const rc_memory_regions_t rc_memory_regions_wonderswan = { _rc_memory_regions_wonderswan, 2 };
+
/* ===== default ===== */
static const rc_memory_regions_t rc_memory_regions_none = { 0, 0 };
@@ -554,6 +571,9 @@ const rc_memory_regions_t* rc_console_memory_regions(int console_id)
case RC_CONSOLE_PC_ENGINE:
return &rc_memory_regions_pcengine;
+ case RC_CONSOLE_PCFX:
+ return &rc_memory_regions_pcfx;
+
case RC_CONSOLE_PLAYSTATION:
return &rc_memory_regions_playstation;
@@ -575,15 +595,15 @@ const rc_memory_regions_t* rc_console_memory_regions(int console_id)
case RC_CONSOLE_SUPER_NINTENDO:
return &rc_memory_regions_snes;
- case RC_CONSOLE_WONDERSWAN:
- return &rc_memory_regions_wonderswan;
-
case RC_CONSOLE_VECTREX:
return &rc_memory_regions_vectrex;
case RC_CONSOLE_VIRTUAL_BOY:
return &rc_memory_regions_virtualboy;
+ case RC_CONSOLE_WONDERSWAN:
+ return &rc_memory_regions_wonderswan;
+
default:
return &rc_memory_regions_none;
}
diff --git a/deps/rcheevos/src/rhash/hash.c b/deps/rcheevos/src/rhash/hash.c
index e461e1320e..0a10ee4a8e 100644
--- a/deps/rcheevos/src/rhash/hash.c
+++ b/deps/rcheevos/src/rhash/hash.c
@@ -399,7 +399,7 @@ static int rc_hash_3do(char hash[33], const char* path)
{
if (buffer[offset + 0x03] == 0x02) /* file */
{
- if (strcasecmp((char*)&buffer[offset + 0x20], "LaunchMe") == 0)
+ if (strcasecmp((const char*)&buffer[offset + 0x20], "LaunchMe") == 0)
{
/* the block size is at offset 0x0C (assume 0x0C is always 0) */
block_size = buffer[offset + 0x0D] * 65536 + buffer[offset + 0x0E] * 256 + buffer[offset + 0x0F];
@@ -710,7 +710,7 @@ static int rc_hash_pce_cd(char hash[33], const char* path)
rc_cd_read_sector(track_handle, 1, buffer, 128);
/* normal PC Engine CD will have a header block in sector 1 */
- if (strncmp("PC Engine CD-ROM SYSTEM", (const char*)&buffer[32], 23) == 0)
+ if (memcmp("PC Engine CD-ROM SYSTEM", &buffer[32], 23) == 0)
{
/* the title of the disc is the last 22 bytes of the header */
md5_init(&md5);
@@ -727,7 +727,7 @@ static int rc_hash_pce_cd(char hash[33], const char* path)
/* the first three bytes specify the sector of the program data, and the fourth byte
* is the number of sectors.
*/
- sector = buffer[0] * 65536 + buffer[1] * 256 + buffer[2];
+ sector = (buffer[0] << 16) + (buffer[1] << 8) + buffer[2];
num_sectors = buffer[3];
if (verbose_message_callback)
@@ -776,6 +776,78 @@ static int rc_hash_pce_cd(char hash[33], const char* path)
return rc_hash_finalize(&md5, hash);
}
+static int rc_hash_pcfx_cd(char hash[33], const char* path)
+{
+ uint8_t buffer[2048];
+ void* track_handle;
+ md5_state_t md5;
+ int sector, num_sectors;
+
+ track_handle = rc_cd_open_track(path, 0);
+ if (!track_handle)
+ return rc_hash_error("Could not open track");
+
+ /* PC-FX boot header fills the first two sectors of the disc
+ * https://bitbucket.org/trap15/pcfxtools/src/master/pcfx-cdlink.c
+ */
+
+ /* PC-FX CD will have a header marker in sector 0 */
+ rc_cd_read_sector(track_handle, 0, buffer, 32);
+ if (memcmp("PC-FX:Hu_CD-ROM", &buffer[0], 15) == 0)
+ {
+ /* the important stuff is the first 128 bytes of the second sector (title being the first 32) */
+ rc_cd_read_sector(track_handle, 1, buffer, 128);
+
+ md5_init(&md5);
+ md5_append(&md5, buffer, 128);
+
+ if (verbose_message_callback)
+ {
+ char message[128];
+ buffer[128] = '\0';
+ snprintf(message, sizeof(message), "Found PC-FX CD, title=%.32s", &buffer[0]);
+ verbose_message_callback(message);
+ }
+
+ /* the program sector is in bytes 33-36 (assume byte 36 is 0) */
+ sector = (buffer[34] << 16) + (buffer[33] << 8) + buffer[32];
+
+ /* the number of sectors the program occupies is in bytes 37-40 (assume byte 40 is 0) */
+ num_sectors = (buffer[38] << 16) + (buffer[37] << 8) + buffer[36];
+
+ if (verbose_message_callback)
+ {
+ char message[128];
+ snprintf(message, sizeof(message), "Hashing %d sectors starting at sector %d", num_sectors, sector);
+ verbose_message_callback(message);
+ }
+
+ while (num_sectors > 0)
+ {
+ rc_cd_read_sector(track_handle, sector, buffer, sizeof(buffer));
+ md5_append(&md5, buffer, sizeof(buffer));
+
+ ++sector;
+ --num_sectors;
+ }
+ }
+ else
+ {
+ rc_cd_read_sector(track_handle, 1, buffer, 128);
+ rc_cd_close_track(track_handle);
+
+ /* some PC-FX CDs still identify as PCE CDs */
+ if (memcmp("PC Engine CD-ROM SYSTEM", &buffer[32], 23) == 0)
+ return rc_hash_pce_cd(hash, path);
+
+ return rc_hash_error("Not a PC-FX CD");
+ }
+
+ rc_cd_close_track(track_handle);
+
+ return rc_hash_finalize(&md5, hash);
+}
+
static int rc_hash_psx(char hash[33], const char* path)
{
uint8_t buffer[2048];
@@ -1297,6 +1369,12 @@ int rc_hash_generate_from_file(char hash[33], int console_id, const char* path)
return rc_hash_whole_file(hash, console_id, path);
+ case RC_CONSOLE_PCFX:
+ if (rc_path_compare_extension(path, "m3u"))
+ return rc_hash_generate_from_playlist(hash, console_id, path);
+
+ return rc_hash_pcfx_cd(hash, path);
+
case RC_CONSOLE_PLAYSTATION:
if (rc_path_compare_extension(path, "m3u"))
return rc_hash_generate_from_playlist(hash, console_id, path);
@@ -1452,8 +1530,9 @@ void rc_hash_initialize_iterator(struct rc_hash_iterator* iterator, const char*
iterator->consoles[0] = RC_CONSOLE_PLAYSTATION;
iterator->consoles[1] = RC_CONSOLE_PC_ENGINE;
iterator->consoles[2] = RC_CONSOLE_3DO;
+ iterator->consoles[3] = RC_CONSOLE_PCFX;
/* SEGA CD hash doesn't have any logic to ensure it's being used against a SEGA CD, so it should always be last */
- iterator->consoles[3] = RC_CONSOLE_SEGA_CD;
+ iterator->consoles[4] = RC_CONSOLE_SEGA_CD;
need_path = 1;
}
else if (rc_path_compare_extension(ext, "col"))
diff --git a/deps/vitaGL/.github/FUNDING.yml b/deps/vitaGL/.github/FUNDING.yml
new file mode 100644
index 0000000000..dbd470e946
--- /dev/null
+++ b/deps/vitaGL/.github/FUNDING.yml
@@ -0,0 +1 @@
+patreon: Rinnegatamante
diff --git a/deps/vitaGL/Makefile b/deps/vitaGL/Makefile
index e4b82ce5fa..e508bbc4b3 100644
--- a/deps/vitaGL/Makefile
+++ b/deps/vitaGL/Makefile
@@ -7,20 +7,25 @@ SOURCES += source/hacks
endif
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
+ASMFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S))
CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg))
HEADERS := $(CGFILES:.cg=.h)
-OBJS := $(CFILES:.c=.o)
+OBJS := $(CFILES:.c=.o) $(ASMFILES:.S=.o)
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
AR = $(PREFIX)-gcc-ar
-CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -flto -ftree-vectorize -DSTB_DXT_IMPLEMENTATION
+CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -ftree-vectorize -DSTB_DXT_IMPLEMENTATION
ASFLAGS = $(CFLAGS)
ifeq ($(NO_DEBUG),1)
CFLAGS += -DSKIP_ERROR_HANDLING
endif
+ifeq ($(HAVE_SHARK),1)
+CFLAGS += -DHAVE_SHARK
+endif
+
all: $(TARGET).a
$(TARGET).a: $(OBJS)
@@ -47,6 +52,7 @@ clean:
@make -C samples/sample5 clean
@make -C samples/sample6 clean
@make -C samples/sample7 clean
+ @make -C samples/sample8 clean
install: $(TARGET).a
@mkdir -p $(VITASDK)/$(PREFIX)/lib/
@@ -69,3 +75,5 @@ samples: $(TARGET).a
cp "samples/sample6/vitaGL-Sample006.vpk" .
@make -C samples/sample7
cp "samples/sample7/vitaGL-Sample007.vpk" .
+ @make -C samples/sample8
+ cp "samples/sample8/vitaGL-Sample008.vpk" .
diff --git a/deps/vitaGL/README.md b/deps/vitaGL/README.md
index 5accb88b97..a4b3d9597f 100644
--- a/deps/vitaGL/README.md
+++ b/deps/vitaGL/README.md
@@ -20,7 +20,7 @@ Here you can find a list of projects using vitaGL:
Direct OpenGL Usage:
[vitaQuake](https://vitadb.rinnegatamante.it/#/info/10) - Port of Quake I and mission packs
[vitaQuakeII](https://vitadb.rinnegatamante.it/#/info/278) -Port of Quake II and mission packs
-[vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena)
+[vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena, Urban Terror)
[vitaRTCW](https://vitadb.rinnegatamante.it/#/info/459) - Port of iortcw (Return to Castle Wolfenstein)
[vitaHexenII](https://vitadb.rinnegatamante.it/#/info/196) - Port of Hexen II
[vitaXash3D](https://vitadb.rinnegatamante.it/#/info/365) - Port of Xash3D (Half Life, Counter Strike 1.6)
diff --git a/deps/vitaGL/samples/sample2/Makefile b/deps/vitaGL/samples/sample2/Makefile
index bdbdbd8e39..9a385a0fda 100644
--- a/deps/vitaGL/samples/sample2/Makefile
+++ b/deps/vitaGL/samples/sample2/Makefile
@@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include
-LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon
+LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
diff --git a/deps/vitaGL/samples/sample4/Makefile b/deps/vitaGL/samples/sample4/Makefile
index 5a2d34a73b..16fdc27ac7 100644
--- a/deps/vitaGL/samples/sample4/Makefile
+++ b/deps/vitaGL/samples/sample4/Makefile
@@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include
-LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon
+LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
diff --git a/deps/vitaGL/samples/sample5/Makefile b/deps/vitaGL/samples/sample5/Makefile
index 32f94c96c5..964bd24cce 100644
--- a/deps/vitaGL/samples/sample5/Makefile
+++ b/deps/vitaGL/samples/sample5/Makefile
@@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include
-LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon
+LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lSceAppMgr_stub -lmathneon
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
diff --git a/deps/vitaGL/samples/sample5/main.c b/deps/vitaGL/samples/sample5/main.c
index 5d8f35edc3..6b4389c403 100644
--- a/deps/vitaGL/samples/sample5/main.c
+++ b/deps/vitaGL/samples/sample5/main.c
@@ -21,13 +21,6 @@ uint16_t indices[] = {
20,21,22,21,22,23 // Bottom
};
-void init_perspective(float fov, float aspect, float near, float far){
- float half_height = near * tanf(((fov * M_PI) / 180.0f) * 0.5f);
- float half_width = half_height * aspect;
-
- glFrustum(-half_width, half_width, -half_height, half_height, near, far);
-}
-
int main(){
// Initializing graphics device
@@ -53,7 +46,7 @@ int main(){
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- init_perspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
+ gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube
diff --git a/deps/vitaGL/samples/sample6/Makefile b/deps/vitaGL/samples/sample6/Makefile
index bc0a5fe656..eaf8e9f488 100644
--- a/deps/vitaGL/samples/sample6/Makefile
+++ b/deps/vitaGL/samples/sample6/Makefile
@@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include
-LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon
+LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
diff --git a/deps/vitaGL/samples/sample6/main.c b/deps/vitaGL/samples/sample6/main.c
index 464c0be430..817eeecf05 100644
--- a/deps/vitaGL/samples/sample6/main.c
+++ b/deps/vitaGL/samples/sample6/main.c
@@ -25,13 +25,6 @@ uint16_t indices[] = {
20,21,22,21,22,23 // Bottom
};
-void init_perspective(float fov, float aspect, float near, float far){
- float half_height = near * tanf(((fov * M_PI) / 180.0f) * 0.5f);
- float half_width = half_height * aspect;
-
- glFrustum(-half_width, half_width, -half_height, half_height, near, far);
-}
-
int main(){
// Initializing graphics device
@@ -67,7 +60,7 @@ int main(){
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- init_perspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
+ gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube
diff --git a/deps/vitaGL/samples/sample8/Makefile b/deps/vitaGL/samples/sample8/Makefile
new file mode 100644
index 0000000000..68a1481bd6
--- /dev/null
+++ b/deps/vitaGL/samples/sample8/Makefile
@@ -0,0 +1,37 @@
+SAMPLE_NUM := 008
+TARGET := vitaGL-Sample$(SAMPLE_NUM)
+SOURCES := .
+
+INCLUDES := include
+
+LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lSceAppMgr_stub -lmathneon
+
+CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
+CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
+BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
+OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
+
+PREFIX = arm-vita-eabi
+CC = $(PREFIX)-gcc
+CXX = $(PREFIX)-g++
+CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
+CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
+ASFLAGS = $(CFLAGS)
+
+all: $(TARGET).vpk
+
+$(TARGET).vpk: eboot.bin
+ vita-mksfoex -s TITLE_ID=VITAGL$(SAMPLE_NUM) "$(TARGET)" param.sfo
+ vita-pack-vpk -s param.sfo -b eboot.bin $@
+
+eboot.bin: $(TARGET).velf
+ vita-make-fself -at 0x0E -m 0x10000 $< eboot.bin
+
+%.velf: %.elf
+ vita-elf-create $< $@
+
+$(TARGET).elf: $(OBJS)
+ $(CC) $(CFLAGS) $^ $(LIBS) -o $@
+
+clean:
+ @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin
diff --git a/deps/vitaGL/samples/sample8/main.c b/deps/vitaGL/samples/sample8/main.c
new file mode 100644
index 0000000000..9a7feee685
--- /dev/null
+++ b/deps/vitaGL/samples/sample8/main.c
@@ -0,0 +1,76 @@
+// Drawing a rotating cube
+
+#include
+#include
+
+float colors[] = {1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}; // Colors for a face
+
+float vertices_front[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f}; // Front Face
+float vertices_back[] = {-0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Back Face
+float vertices_left[] = {-0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f}; // Left Face
+float vertices_right[] = {0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Right Face
+float vertices_top[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f}; // Top Face
+float vertices_bottom[] = {-0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Bottom Face
+
+uint16_t indices[] = {
+ 0, 1, 2, 1, 2, 3, // Front
+ 4, 5, 6, 5, 6, 7, // Back
+ 8, 9,10, 9,10,11, // Left
+ 12,13,14,13,14,15, // Right
+ 16,17,18,17,18,19, // Top
+ 20,21,22,21,22,23 // Bottom
+};
+
+int main(){
+
+ // Initializing graphics device
+ vglSetParamBufferSize(2 * 1024 * 1024);
+ vglInitWithCustomSizes(0x1000, 960, 544, 16 * 1024 * 1024, 0, 0, SCE_GXM_MULTISAMPLE_4X);
+ vglWaitVblankStart(GL_TRUE);
+
+ // Creating colors array
+ float color_array[12*6];
+ int i;
+ for (i=0;i<12*6;i++){
+ color_array[i] = colors[i % 12];
+ }
+
+ // Creating vertices array
+ float vertex_array[12*6];
+ memcpy(&vertex_array[12*0], &vertices_front[0], sizeof(float) * 12);
+ memcpy(&vertex_array[12*1], &vertices_back[0], sizeof(float) * 12);
+ memcpy(&vertex_array[12*2], &vertices_left[0], sizeof(float) * 12);
+ memcpy(&vertex_array[12*3], &vertices_right[0], sizeof(float) * 12);
+ memcpy(&vertex_array[12*4], &vertices_top[0], sizeof(float) * 12);
+ memcpy(&vertex_array[12*5], &vertices_bottom[0], sizeof(float) * 12);
+
+ glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+
+ for (;;){
+ vglStartRendering();
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glVertexPointer(3, GL_FLOAT, 0, vertex_array);
+ glColorPointer(3, GL_FLOAT, 0, color_array);
+ glRotatef(1.0f, 0.0f, 0.0f, 1.0f);
+ glRotatef(0.5f, 0.0f, 1.0f, 0.0f);
+ glDrawElements(GL_TRIANGLES, 6*6, GL_UNSIGNED_SHORT, indices);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ vglStopRendering();
+ }
+
+ vglEnd();
+
+}
\ No newline at end of file
diff --git a/deps/vitaGL/source/custom_shaders.c b/deps/vitaGL/source/custom_shaders.c
index f199a70c20..e3cd811435 100644
--- a/deps/vitaGL/source/custom_shaders.c
+++ b/deps/vitaGL/source/custom_shaders.c
@@ -23,12 +23,14 @@
#include "shared.h"
-#define MAX_CUSTOM_SHADERS 32 // Maximum number of linkable custom shaders
-#define MAX_SHADER_PARAMS 16 // Maximum number of parameters per custom shader
+#define MAX_CUSTOM_SHADERS 64 // Maximum number of linkable custom shaders
+#define MAX_SHADER_PARAMS 8 // Maximum number of parameters per custom shader
// Internal stuffs
void *frag_uniforms = NULL;
void *vert_uniforms = NULL;
+uint8_t use_shark = 1; // Flag to check if vitaShaRK should be initialized at vitaGL boot
+uint8_t is_shark_online = 0; // Current vitaShaRK status
GLuint cur_program = 0; // Current in use custom program (0 = No custom program)
@@ -45,6 +47,7 @@ typedef struct shader {
GLboolean valid;
SceGxmShaderPatcherId id;
const SceGxmProgram *prog;
+ uint32_t size;
} shader;
// Program struct holding vertex/fragment shader info
@@ -52,8 +55,8 @@ typedef struct program {
shader *vshader;
shader *fshader;
GLboolean valid;
- SceGxmVertexAttribute attr[16];
- SceGxmVertexStream stream[16];
+ SceGxmVertexAttribute attr[MAX_SHADER_PARAMS];
+ SceGxmVertexStream stream[MAX_SHADER_PARAMS];
SceGxmVertexProgram *vprog;
SceGxmFragmentProgram *fprog;
GLuint attr_num;
@@ -102,8 +105,8 @@ void reloadCustomShader(void) {
}
void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
- program *p = &progs[cur_program - 1];
if (implicit_wvp) {
+ program *p = &progs[cur_program - 1];
if (mvp_modified) {
matrix4x4_multiply(mvp_matrix, projection_matrix, modelview_matrix);
mvp_modified = GL_FALSE;
@@ -121,6 +124,10 @@ void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean imp
* - IMPLEMENTATION STARTS HERE -
* ------------------------------
*/
+
+void vglEnableRuntimeShaderCompiler(GLboolean usage) {
+ use_shark = usage;
+}
GLuint glCreateShader(GLenum shaderType) {
// Looking for a free shader slot
@@ -146,6 +153,7 @@ GLuint glCreateShader(GLenum shaderType) {
break;
default:
vgl_error = GL_INVALID_ENUM;
+ return 0;
break;
}
shaders[res - 1].valid = GL_TRUE;
@@ -153,17 +161,74 @@ GLuint glCreateShader(GLenum shaderType) {
return res;
}
+void glGetShaderiv(GLuint handle, GLenum pname, GLint *params) {
+ // Grabbing passed shader
+ shader *s = &shaders[handle - 1];
+
+ switch (pname) {
+ case GL_SHADER_TYPE:
+ *params = s->type;
+ break;
+ case GL_COMPILE_STATUS:
+ *params = s->prog ? GL_TRUE : GL_FALSE;
+ break;
+ default:
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ break;
+ }
+}
+
+void glShaderSource(GLuint handle, GLsizei count, const GLchar * const *string, const GLint *length) {
+#ifndef SKIP_ERROR_HANDLING
+ if (count < 0) {
+ SET_GL_ERROR(GL_INVALID_VALUE)
+ }
+#endif
+ if (!is_shark_online) {
+ SET_GL_ERROR(GL_INVALID_OPERATION)
+ }
+
+ // Grabbing passed shader
+ shader *s = &shaders[handle - 1];
+
+ // Temporarily setting prog to point to the shader source
+ s->prog = (SceGxmProgram *)string;
+ s->size = *length;
+}
+
void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length) {
// Grabbing passed shader
shader *s = &shaders[handles[0] - 1];
// Allocating compiled shader on RAM and registering it into sceGxmShaderPatcher
s->prog = (SceGxmProgram *)malloc(length);
- memcpy((void *)s->prog, binary, length);
+ memcpy_neon((void *)s->prog, binary, length);
sceGxmShaderPatcherRegisterProgram(gxm_shader_patcher, s->prog, &s->id);
s->prog = sceGxmShaderPatcherGetProgramFromId(s->id);
}
+void glCompileShader(GLuint handle) {
+ // If vitaShaRK is not enabled, we just error out
+ if (!is_shark_online) {
+ SET_GL_ERROR(GL_INVALID_OPERATION)
+ }
+#ifdef HAVE_SHARK
+ // Grabbing passed shader
+ shader *s = &shaders[handle - 1];
+
+ // Compiling shader source
+ s->prog = shark_compile_shader((const char*)s->prog, &s->size, s->type == GL_FRAGMENT_SHADER ? SHARK_FRAGMENT_SHADER : SHARK_VERTEX_SHADER);
+ if (s->prog) {
+ SceGxmProgram *res = (SceGxmProgram *)malloc(s->size);
+ memcpy_neon((void *)res, (void *)s->prog, s->size);
+ s->prog = res;
+ sceGxmShaderPatcherRegisterProgram(gxm_shader_patcher, s->prog, &s->id);
+ s->prog = sceGxmShaderPatcherGetProgramFromId(s->id);
+ }
+ shark_clear_output();
+#endif
+}
+
void glDeleteShader(GLuint shad) {
// Grabbing passed shader
shader *s = &shaders[shad - 1];
@@ -193,8 +258,9 @@ void glAttachShader(GLuint prog, GLuint shad) {
default:
break;
}
- } else
- vgl_error = GL_INVALID_VALUE;
+ } else {
+ SET_GL_ERROR(GL_INVALID_VALUE)
+ }
}
GLuint glCreateProgram(void) {
@@ -335,6 +401,43 @@ void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {
}
}
+void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {
+ // Grabbing passed uniform
+ uniform *u = (uniform *)location;
+ if (u->ptr == NULL)
+ return;
+
+ // Setting passed value to desired uniform
+ if (u->isVertex) {
+ if (vert_uniforms == NULL)
+ sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vert_uniforms);
+ sceGxmSetUniformDataF(vert_uniforms, u->ptr, 0, 3 * count, value);
+ } else {
+ if (frag_uniforms == NULL)
+ sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &frag_uniforms);
+ sceGxmSetUniformDataF(frag_uniforms, u->ptr, 0, 3 * count, value);
+ }
+}
+
+void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
+ // Grabbing passed uniform
+ uniform *u = (uniform *)location;
+ if (u->ptr == NULL)
+ return;
+
+ // Setting passed value to desired uniform
+ float v[4] = {v0, v1, v2, v3};
+ if (u->isVertex) {
+ if (vert_uniforms == NULL)
+ sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vert_uniforms);
+ sceGxmSetUniformDataF(vert_uniforms, u->ptr, 0, 4, v);
+ } else {
+ if (frag_uniforms == NULL)
+ sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &frag_uniforms);
+ sceGxmSetUniformDataF(frag_uniforms, u->ptr, 0, 4, v);
+ }
+}
+
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {
// Grabbing passed uniform
uniform *u = (uniform *)location;
@@ -402,7 +505,7 @@ void vglBindPackedAttribLocation(GLuint prog, GLuint index, const GLchar *name,
bpe = sizeof(uint8_t);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -425,8 +528,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (stride < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -440,7 +542,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
bpe = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -449,13 +551,13 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
// Copying passed data to vitaGL mempool
if (stride == 0)
- memcpy(ptr, pointer, count * bpe * size); // Faster if stride == 0
+ memcpy_neon(ptr, pointer, count * bpe * size); // Faster if stride == 0
else {
int i;
uint8_t *dst = (uint8_t *)ptr;
uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) {
- memcpy(dst, src, bpe * size);
+ memcpy_neon(dst, src, bpe * size);
dst += (bpe * size);
src += stride;
}
diff --git a/deps/vitaGL/source/framebuffers.c b/deps/vitaGL/source/framebuffers.c
index bf6258b60e..3e67e28df1 100644
--- a/deps/vitaGL/source/framebuffers.c
+++ b/deps/vitaGL/source/framebuffers.c
@@ -66,8 +66,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) {
int i = 0, j = 0;
#ifndef SKIP_ERROR_HANDLING
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
for (i = 0; i < BUFFERS_NUM; i++) {
@@ -85,8 +84,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) {
void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) {
#ifndef SKIP_ERROR_HANDLING
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
while (n > 0) {
@@ -117,7 +115,7 @@ void glBindFramebuffer(GLenum target, GLuint fb) {
active_write_fb = active_read_fb = (framebuffer *)fb;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -134,7 +132,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint
fb = active_read_fb;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -178,7 +176,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint
sceGxmCreateRenderTarget(&renderTargetParams, &fb->target);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
diff --git a/deps/vitaGL/source/get_info.c b/deps/vitaGL/source/get_info.c
index 314d0aa5aa..36bb0f8db5 100644
--- a/deps/vitaGL/source/get_info.c
+++ b/deps/vitaGL/source/get_info.c
@@ -80,7 +80,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params) {
*params = GL_FALSE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -98,7 +98,7 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
// Since we use column-major matrices internally, wee need to transpose it before returning it to the application
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
- data[i*4+j] = modelview_matrix[j][i];
+ data[i * 4 + j] = modelview_matrix[j][i];
}
}
break;
@@ -106,7 +106,7 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
// Since we use column-major matrices internally, wee need to transpose it before returning it to the application
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
- data[i*4+j] = projection_matrix[j][i];
+ data[i * 4 + j] = projection_matrix[j][i];
}
}
break;
@@ -122,8 +122,14 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
case GL_MAX_TEXTURE_STACK_DEPTH: // Max texture stack depth
*data = GENERIC_STACK_DEPTH;
break;
+ case GL_DEPTH_BITS:
+ *data = 32;
+ break;
+ case GL_STENCIL_BITS:
+ *data = 8;
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -155,8 +161,14 @@ void glGetIntegerv(GLenum pname, GLint *data) {
data[2] = gl_viewport.w;
data[3] = gl_viewport.h;
break;
+ case GL_DEPTH_BITS:
+ data[0] = 32;
+ break;
+ case GL_STENCIL_BITS:
+ data[0] = 8;
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
diff --git a/deps/vitaGL/source/gxm.c b/deps/vitaGL/source/gxm.c
index 66b58f371d..53bd49b4c6 100644
--- a/deps/vitaGL/source/gxm.c
+++ b/deps/vitaGL/source/gxm.c
@@ -23,6 +23,8 @@
#include "shared.h"
+static uint32_t gxm_param_buf_size = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE; // Param buffer size for sceGxm
+
static void *vdm_ring_buffer_addr; // VDM ring buffer memblock starting address
static void *vertex_ring_buffer_addr; // vertex ring buffer memblock starting address
static void *fragment_ring_buffer_addr; // fragment ring buffer memblock starting address
@@ -44,6 +46,9 @@ static void *gxm_depth_surface_addr; // Depth surface memblock starting address
static void *gxm_stencil_surface_addr; // Stencil surface memblock starting address
static SceGxmDepthStencilSurface gxm_depth_stencil_surface; // Depth/Stencil surfaces setup for sceGxm
+static SceUID shared_fb; // In-use hared framebuffer identifier
+static SceSharedFbInfo shared_fb_info; // In-use shared framebuffer info struct
+
SceGxmContext *gxm_context; // sceGxm context instance
GLenum vgl_error = GL_NO_ERROR; // Error returned by glGetError
SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance
@@ -58,6 +63,9 @@ int DISPLAY_STRIDE; // Display stride in pixels
float DISPLAY_WIDTH_FLOAT; // Display width in pixels (float)
float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float)
+uint8_t system_app_mode = 0; // Flag for system app mode usage
+static uint8_t gxm_initialized = 0; // Current sceGxm state
+
// sceDisplay callback data
struct display_queue_callback_data {
void *addr;
@@ -95,17 +103,40 @@ static void display_queue_callback(const void *callbackData) {
}
void initGxm(void) {
+ if (gxm_initialized)
+ return;
+
+ // Initializing runtime shader compiler
+ if (use_shark) {
+#ifdef HAVE_SHARK
+ if (shark_init(NULL) >= 0)
+ is_shark_online = 1;
+ else
+#endif
+ is_shark_online = 0;
+ }
+
+ // Checking if the running application is a system one
+ SceAppMgrBudgetInfo info;
+ info.size = sizeof(SceAppMgrBudgetInfo);
+ if (!sceAppMgrGetBudgetInfo(&info))
+ system_app_mode = 1;
+
// Initializing sceGxm init parameters
SceGxmInitializeParams gxm_init_params;
memset(&gxm_init_params, 0, sizeof(SceGxmInitializeParams));
- gxm_init_params.flags = 0;
+ gxm_init_params.flags = system_app_mode ? 0x0A : 0;
gxm_init_params.displayQueueMaxPendingCount = DISPLAY_BUFFER_COUNT - 1;
gxm_init_params.displayQueueCallback = display_queue_callback;
gxm_init_params.displayQueueCallbackDataSize = sizeof(struct display_queue_callback_data);
- gxm_init_params.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
+ gxm_init_params.parameterBufferSize = gxm_param_buf_size;
// Initializing sceGxm
- sceGxmInitialize(&gxm_init_params);
+ if (system_app_mode)
+ sceGxmVshInitialize(&gxm_init_params);
+ else
+ sceGxmInitialize(&gxm_init_params);
+ gxm_initialized = 1;
}
void initGxmContext(void) {
@@ -153,6 +184,17 @@ void termGxmContext(void) {
// Destroying sceGxm context
sceGxmDestroyContext(gxm_context);
+
+ if (system_app_mode) {
+ sceSharedFbBegin(shared_fb, &shared_fb_info);
+ sceGxmUnmapMemory(shared_fb_info.fb_base);
+ sceSharedFbEnd(shared_fb);
+ sceSharedFbClose(shared_fb);
+ }
+#ifdef HAVE_SHARK
+ // Shutting down runtime shader compiler
+ if (is_shark_online) shark_end();
+#endif
}
void createDisplayRenderTarget(void) {
@@ -177,16 +219,34 @@ void destroyDisplayRenderTarget(void) {
}
void initDisplayColorSurfaces(void) {
+ // Getting access to the shared framebuffer on system app mode
+ while (system_app_mode) {
+ shared_fb = sceSharedFbOpen(1);
+ memset(&shared_fb_info, 0, sizeof(SceSharedFbInfo));
+ sceSharedFbGetInfo(shared_fb, &shared_fb_info);
+ if (shared_fb_info.index == 1)
+ sceSharedFbClose(shared_fb);
+ else {
+ sceGxmMapMemory(shared_fb_info.fb_base, shared_fb_info.fb_size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
+ gxm_color_surfaces_addr[0] = shared_fb_info.fb_base;
+ gxm_color_surfaces_addr[1] = shared_fb_info.fb_base2;
+ memset(&shared_fb_info, 0, sizeof(SceSharedFbInfo));
+ break;
+ }
+ }
+
vglMemType type = VGL_MEM_VRAM;
int i;
for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) {
// Allocating color surface memblock
- gxm_color_surfaces_addr[i] = gpu_alloc_mapped(
- ALIGN(4 * DISPLAY_STRIDE * DISPLAY_HEIGHT, 1 * 1024 * 1024),
- &type);
+ if (!system_app_mode) {
+ gxm_color_surfaces_addr[i] = gpu_alloc_mapped(
+ ALIGN(4 * DISPLAY_STRIDE * DISPLAY_HEIGHT, 1 * 1024 * 1024),
+ &type);
+ memset(gxm_color_surfaces_addr[i], 0, DISPLAY_STRIDE * DISPLAY_HEIGHT);
+ }
// Initializing allocated color surface
- memset(gxm_color_surfaces_addr[i], 0, DISPLAY_STRIDE * DISPLAY_HEIGHT);
sceGxmColorSurfaceInit(&gxm_color_surfaces[i],
SCE_GXM_COLOR_FORMAT_A8B8G8R8,
SCE_GXM_COLOR_SURFACE_LINEAR,
@@ -206,7 +266,8 @@ void termDisplayColorSurfaces(void) {
// Deallocating display's color surfaces and destroying sync objects
int i;
for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) {
- vgl_mem_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM);
+ if (!system_app_mode)
+ vgl_mem_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM);
sceGxmSyncObjectDestroy(gxm_sync_objects[i]);
}
}
@@ -317,9 +378,18 @@ void waitRenderingDone(void) {
* ------------------------------
*/
+void vglSetParamBufferSize(uint32_t size) {
+ gxm_param_buf_size = size;
+}
+
void vglStartRendering(void) {
// Starting drawing scene
if (active_write_fb == NULL) { // Default framebuffer is used
+ if (system_app_mode) {
+ sceSharedFbBegin(shared_fb, &shared_fb_info);
+ shared_fb_info.vsync = vblank;
+ gxm_back_buffer_index = (shared_fb_info.index + 1) % 2;
+ }
sceGxmBeginScene(gxm_context, gxm_scene_flags, gxm_render_target,
NULL, NULL,
gxm_sync_objects[gxm_back_buffer_index],
@@ -338,7 +408,7 @@ void vglStartRendering(void) {
// Setting back current viewport if enabled cause sceGxm will reset it at sceGxmEndScene call
sceGxmSetViewport(gxm_context, x_port, x_scale, y_port, y_scale, z_port, z_scale);
-
+
if (scissor_test_state)
sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, region.x, region.y, region.x + region.w - 1, region.y + region.h - 1);
else
@@ -348,18 +418,23 @@ void vglStartRendering(void) {
void vglStopRenderingInit(void) {
// Ending drawing scene
sceGxmEndScene(gxm_context, NULL, NULL);
+ if (system_app_mode && vblank)
+ sceDisplayWaitVblankStart();
}
void vglStopRenderingTerm(void) {
if (active_write_fb == NULL) { // Default framebuffer is used
-
// Properly requesting a display update
- struct display_queue_callback_data queue_cb_data;
- queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index];
- sceGxmDisplayQueueAddEntry(gxm_sync_objects[gxm_front_buffer_index],
- gxm_sync_objects[gxm_back_buffer_index], &queue_cb_data);
- gxm_front_buffer_index = gxm_back_buffer_index;
- gxm_back_buffer_index = (gxm_back_buffer_index + 1) % DISPLAY_BUFFER_COUNT;
+ if (system_app_mode)
+ sceSharedFbEnd(shared_fb);
+ else {
+ struct display_queue_callback_data queue_cb_data;
+ queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index];
+ sceGxmDisplayQueueAddEntry(gxm_sync_objects[gxm_front_buffer_index],
+ gxm_sync_objects[gxm_back_buffer_index], &queue_cb_data);
+ gxm_front_buffer_index = gxm_back_buffer_index;
+ gxm_back_buffer_index = (gxm_back_buffer_index + 1) % DISPLAY_BUFFER_COUNT;
+ }
}
// Resetting vitaGL mempool
diff --git a/deps/vitaGL/source/hacks/memcpy_neon.S b/deps/vitaGL/source/hacks/memcpy_neon.S
new file mode 100644
index 0000000000..2f1d33ebb7
--- /dev/null
+++ b/deps/vitaGL/source/hacks/memcpy_neon.S
@@ -0,0 +1,140 @@
+/*
+ * NEON code contributed by Siarhei Siamashka .
+ * Origin: http://sourceware.org/ml/libc-ports/2009-07/msg00003.html
+ *
+ * The GNU C Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License.
+ *
+ * Tweaked for Android by Jim Huang
+ */
+
+.arm
+.fpu neon
+
+@ void* memcpy_n(void *destination, const void *source, size_t num)
+.global memcpy_neon
+.type memcpy_neon, %function
+/*
+ * ENABLE_UNALIGNED_MEM_ACCESSES macro can be defined to permit the use
+ * of unaligned load/store memory accesses supported since ARMv6. This
+ * will further improve performance, but can purely theoretically cause
+ * problems if somebody decides to set SCTLR.A bit in the OS kernel
+ * (to trap each unaligned memory access) or somehow mess with strongly
+ * ordered/device memory.
+ */
+#define ENABLE_UNALIGNED_MEM_ACCESSES 1
+
+#define NEON_MAX_PREFETCH_DISTANCE 320
+
+.align 4
+memcpy_neon:
+ .fnstart
+ mov ip, r0
+ cmp r2, #16
+ blt 4f @ Have less than 16 bytes to copy
+
+ @ First ensure 16 byte alignment for the destination buffer
+ tst r0, #0xF
+ beq 2f
+ tst r0, #1
+ ldrneb r3, [r1], #1
+ strneb r3, [ip], #1
+ subne r2, r2, #1
+ tst ip, #2
+#ifdef ENABLE_UNALIGNED_MEM_ACCESSES
+ ldrneh r3, [r1], #2
+ strneh r3, [ip], #2
+#else
+ ldrneb r3, [r1], #1
+ strneb r3, [ip], #1
+ ldrneb r3, [r1], #1
+ strneb r3, [ip], #1
+#endif
+ subne r2, r2, #2
+
+ tst ip, #4
+ beq 1f
+ vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
+ vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [ip, :32]!
+ sub r2, r2, #4
+1:
+ tst ip, #8
+ beq 2f
+ vld1.8 {d0}, [r1]!
+ vst1.8 {d0}, [ip, :64]!
+ sub r2, r2, #8
+2:
+ subs r2, r2, #32
+ blt 3f
+ mov r3, #32
+
+ @ Main copy loop, 32 bytes are processed per iteration.
+ @ ARM instructions are used for doing fine-grained prefetch,
+ @ increasing prefetch distance progressively up to
+ @ NEON_MAX_PREFETCH_DISTANCE at runtime
+1:
+ vld1.8 {d0-d3}, [r1]!
+ cmp r3, #(NEON_MAX_PREFETCH_DISTANCE - 32)
+ pld [r1, r3]
+ addle r3, r3, #32
+ vst1.8 {d0-d3}, [ip, :128]!
+ sub r2, r2, #32
+ cmp r2, r3
+ bge 1b
+ cmp r2, #0
+ blt 3f
+1: @ Copy the remaining part of the buffer (already prefetched)
+ vld1.8 {d0-d3}, [r1]!
+ subs r2, r2, #32
+ vst1.8 {d0-d3}, [ip, :128]!
+ bge 1b
+3: @ Copy up to 31 remaining bytes
+ tst r2, #16
+ beq 4f
+ vld1.8 {d0, d1}, [r1]!
+ vst1.8 {d0, d1}, [ip, :128]!
+4:
+ @ Use ARM instructions exclusively for the final trailing part
+ @ not fully fitting into full 16 byte aligned block in order
+ @ to avoid "ARM store after NEON store" hazard. Also NEON
+ @ pipeline will be (mostly) flushed by the time when the
+ @ control returns to the caller, making the use of NEON mostly
+ @ transparent (and avoiding hazards in the caller code)
+
+#ifdef ENABLE_UNALIGNED_MEM_ACCESSES
+ movs r3, r2, lsl #29
+ ldrcs r3, [r1], #4
+ strcs r3, [ip], #4
+ ldrcs r3, [r1], #4
+ strcs r3, [ip], #4
+ ldrmi r3, [r1], #4
+ strmi r3, [ip], #4
+ movs r2, r2, lsl #31
+ ldrcsh r3, [r1], #2
+ strcsh r3, [ip], #2
+ ldrmib r3, [r1], #1
+ strmib r3, [ip], #1
+#else
+ movs r3, r2, lsl #29
+ bcc 1f
+ .rept 8
+ ldrcsb r3, [r1], #1
+ strcsb r3, [ip], #1
+ .endr
+1:
+ bpl 1f
+ .rept 4
+ ldrmib r3, [r1], #1
+ strmib r3, [ip], #1
+ .endr
+1:
+ movs r2, r2, lsl #31
+ ldrcsb r3, [r1], #1
+ strcsb r3, [ip], #1
+ ldrcsb r3, [r1], #1
+ strcsb r3, [ip], #1
+ ldrmib r3, [r1], #1
+ strmib r3, [ip], #1
+#endif
+ bx lr
+ .fnend
diff --git a/deps/vitaGL/source/legacy.c b/deps/vitaGL/source/legacy.c
index 1b14001e1c..1b7340c402 100644
--- a/deps/vitaGL/source/legacy.c
+++ b/deps/vitaGL/source/legacy.c
@@ -87,8 +87,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -107,7 +106,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
last_vert->v.x = x;
last_vert->v.y = y;
last_vert->v.z = z;
- memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f));
last_clr->next = last_vert->next = NULL;
// Increasing vertex counter
@@ -118,8 +117,7 @@ void glVertex3fv(const GLfloat *v) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -135,8 +133,8 @@ void glVertex3fv(const GLfloat *v) {
}
// Properly populating the new element
- memcpy(&last_vert->v, v, sizeof(vector3f));
- memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&last_vert->v, v, sizeof(vector3f));
+ memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f));
last_clr->next = last_vert->next = NULL;
// Increasing vertex counter
@@ -157,7 +155,7 @@ void glColor3f(GLfloat red, GLfloat green, GLfloat blue) {
void glColor3fv(const GLfloat *v) {
// Setting current color value
- memcpy(¤t_color.r, v, sizeof(vector3f));
+ memcpy_neon(¤t_color.r, v, sizeof(vector3f));
current_color.a = 1.0f;
}
@@ -187,7 +185,7 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
void glColor4fv(const GLfloat *v) {
// Setting current color value
- memcpy(¤t_color.r, v, sizeof(vector4f));
+ memcpy_neon(¤t_color.r, v, sizeof(vector4f));
}
void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {
@@ -209,8 +207,7 @@ void glTexCoord2fv(GLfloat *f) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -232,8 +229,7 @@ void glTexCoord2f(GLfloat s, GLfloat t) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -255,8 +251,7 @@ void glTexCoord2i(GLint s, GLint t) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -278,8 +273,7 @@ void glArrayElement(GLint i) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (i < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -309,7 +303,7 @@ void glArrayElement(GLint i) {
last_clr->next = NULL;
// Populating new vertex element
- memcpy(&last_vert->v, ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&last_vert->v, ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
// Checking if current texture unit has GL_COLOR_ARRAY enabled
if (tex_unit->color_array_state) {
@@ -322,11 +316,11 @@ void glArrayElement(GLint i) {
// Populating new color element
last_clr->v.a = 1.0f;
- memcpy(&last_clr->v, ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
+ memcpy_neon(&last_clr->v, ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
} else {
// Populating new color element with current color
- memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f));
}
// Checking if current texture unit has GL_TEXTURE_COORD_ARRAY enabled
@@ -347,7 +341,7 @@ void glArrayElement(GLint i) {
}
// Populating new texcoord element
- memcpy(&last_uv->v, ptr_tex, tex_unit->vertex_array.size * 2);
+ memcpy_neon(&last_uv->v, ptr_tex, tex_unit->vertex_array.size * 2);
last_uv->next = NULL;
}
}
@@ -357,8 +351,7 @@ void glBegin(GLenum mode) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -394,7 +387,7 @@ void glBegin(GLenum mode) {
np = 4;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -410,7 +403,7 @@ void glEnd(void) {
// Error handling
if (phase != MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
return;
}
#endif
@@ -498,8 +491,8 @@ void glEnd(void) {
memset(vertices, 0, (vertex_count * sizeof(vector3f)));
indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t));
for (i = 0; i < vertex_count; i++) {
- memcpy(&vertices[n], &object->v, sizeof(vector3f));
- memcpy(&uv_map[n], &object_uv->v, sizeof(vector2f));
+ memcpy_neon(&vertices[n], &object->v, sizeof(vector3f));
+ memcpy_neon(&uv_map[n], &object_uv->v, sizeof(vector2f));
indices[n] = n;
object = object->next;
object_uv = object_uv->next;
@@ -522,8 +515,8 @@ void glEnd(void) {
indices[i * 6 + 5] = i * 4 + 3;
}
for (j = 0; j < vertex_count; j++) {
- memcpy(&vertices[j], &object->v, sizeof(vector3f));
- memcpy(&uv_map[j], &object_uv->v, sizeof(vector2f));
+ memcpy_neon(&vertices[j], &object->v, sizeof(vector3f));
+ memcpy_neon(&uv_map[j], &object_uv->v, sizeof(vector2f));
object = object->next;
object_uv = object_uv->next;
}
@@ -554,8 +547,8 @@ void glEnd(void) {
memset(vertices, 0, (vertex_count * sizeof(vector3f)));
indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t));
for (i = 0; i < vertex_count; i++) {
- memcpy(&vertices[n], &object->v, sizeof(vector3f));
- memcpy(&colors[n], &object_clr->v, sizeof(vector4f));
+ memcpy_neon(&vertices[n], &object->v, sizeof(vector3f));
+ memcpy_neon(&colors[n], &object_clr->v, sizeof(vector4f));
indices[n] = n;
object = object->next;
object_clr = object_clr->next;
@@ -579,8 +572,8 @@ void glEnd(void) {
indices[i * 6 + 5] = i * 4 + 3;
}
for (j = 0; j < vertex_count; j++) {
- memcpy(&vertices[j], &object->v, sizeof(vector3f));
- memcpy(&colors[j], &object_clr->v, sizeof(vector4f));
+ memcpy_neon(&vertices[j], &object->v, sizeof(vector3f));
+ memcpy_neon(&colors[j], &object_clr->v, sizeof(vector4f));
object = object->next;
object_clr = object_clr->next;
}
diff --git a/deps/vitaGL/source/matrices.c b/deps/vitaGL/source/matrices.c
index 26c40226fa..50a65e536f 100644
--- a/deps/vitaGL/source/matrices.c
+++ b/deps/vitaGL/source/matrices.c
@@ -46,7 +46,7 @@ void glMatrixMode(GLenum mode) {
matrix = &projection_matrix;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -55,11 +55,9 @@ void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdou
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
} else if ((left == right) || (bottom == top) || (nearVal == farVal)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -72,11 +70,9 @@ void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLd
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
} else if ((left == right) || (bottom == top) || (nearVal < 0) || (farVal < 0)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -102,7 +98,7 @@ void glMultMatrixf(const GLfloat *m) {
tmp[i][j] = m[j * 4 + i];
}
}
-
+
// Multiplicating passed matrix with in use one
matrix4x4_multiply(res, *matrix, tmp);
@@ -139,8 +135,7 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -162,8 +157,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -171,7 +165,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (modelview_stack_counter >= MODELVIEW_STACK_DEPTH) {
- vgl_error = GL_STACK_OVERFLOW;
+ SET_GL_ERROR(GL_STACK_OVERFLOW)
} else
#endif
// Copying current matrix into the matrix stack and increasing stack counter
@@ -181,7 +175,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (projection_stack_counter >= GENERIC_STACK_DEPTH) {
- vgl_error = GL_STACK_OVERFLOW;
+ SET_GL_ERROR(GL_STACK_OVERFLOW)
} else
#endif
// Copying current matrix into the matrix stack and increasing stack counter
@@ -193,17 +187,16 @@ void glPopMatrix(void) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
if (matrix == &modelview_matrix) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
- if (modelview_stack_counter == 0)
- vgl_error = GL_STACK_UNDERFLOW;
- else
+ if (modelview_stack_counter == 0) {
+ SET_GL_ERROR(GL_STACK_UNDERFLOW)
+ } else
#endif
// Copying last matrix on stack into current matrix and decreasing stack counter
matrix4x4_copy(*matrix, modelview_matrix_stack[--modelview_stack_counter]);
@@ -211,12 +204,25 @@ void glPopMatrix(void) {
} else if (matrix == &projection_matrix) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
- if (projection_stack_counter == 0)
- vgl_error = GL_STACK_UNDERFLOW;
- else
+ if (projection_stack_counter == 0) {
+ SET_GL_ERROR(GL_STACK_UNDERFLOW)
+ } else
#endif
// Copying last matrix on stack into current matrix and decreasing stack counter
matrix4x4_copy(*matrix, projection_matrix_stack[--projection_stack_counter]);
}
mvp_modified = GL_TRUE;
}
+
+void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
+#ifndef SKIP_ERROR_HANDLING
+ // Error handling
+ if (phase == MODEL_CREATION) {
+ SET_GL_ERROR(GL_INVALID_OPERATION)
+ }
+#endif
+
+ // Initializing frustum matrix with requested parameters
+ matrix4x4_init_perspective(*matrix, fovy, aspect, zNear, zFar);
+ mvp_modified = GL_TRUE;
+}
diff --git a/deps/vitaGL/source/misc.c b/deps/vitaGL/source/misc.c
index 69116f437e..b5e71277c2 100644
--- a/deps/vitaGL/source/misc.c
+++ b/deps/vitaGL/source/misc.c
@@ -119,7 +119,7 @@ void glPolygonMode(GLenum face, GLenum mode) {
new_mode = SCE_GXM_POLYGON_MODE_TRIANGLE_FILL;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (face) {
@@ -140,7 +140,7 @@ void glPolygonMode(GLenum face, GLenum mode) {
sceGxmSetBackPolygonMode(gxm_context, new_mode);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
return;
}
update_polygon_offset();
@@ -167,8 +167,7 @@ void glFrontFace(GLenum mode) {
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
#ifndef SKIP_ERROR_HANDLING
if ((width < 0) || (height < 0)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
x_scale = width >> 1;
@@ -197,8 +196,7 @@ void glDepthRangef(GLfloat nearVal, GLfloat farVal) {
void glEnable(GLenum cap) {
#ifndef SKIP_ERROR_HANDLING
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
switch (cap) {
@@ -250,7 +248,7 @@ void glEnable(GLenum cap) {
clip_plane0 = GL_TRUE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -258,8 +256,7 @@ void glEnable(GLenum cap) {
void glDisable(GLenum cap) {
#ifndef SKIP_ERROR_HANDLING
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
switch (cap) {
@@ -311,7 +308,7 @@ void glDisable(GLenum cap) {
clip_plane0 = GL_FALSE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -411,7 +408,7 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -429,12 +426,12 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -443,8 +440,7 @@ void glLineWidth(GLfloat width) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (width <= 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -457,8 +453,7 @@ void glPointSize(GLfloat size) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (size <= 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -483,7 +478,7 @@ void glFogf(GLenum pname, GLfloat param) {
fog_far = param;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -504,10 +499,10 @@ void glFogfv(GLenum pname, const GLfloat *params) {
fog_far = params[0];
break;
case GL_FOG_COLOR:
- memcpy(&fog_color.r, params, sizeof(vector4f));
+ memcpy_neon(&fog_color.r, params, sizeof(vector4f));
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -528,7 +523,7 @@ void glFogi(GLenum pname, const GLint param) {
fog_far = param;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -545,10 +540,10 @@ void glClipPlane(GLenum plane, const GLdouble *equation) {
matrix4x4_transpose(inverted_transposed, inverted);
vector4f temp;
vector4f_matrix4x4_mult(&temp, inverted_transposed, &clip_plane0_eq);
- memcpy(&clip_plane0_eq.x, &temp.x, sizeof(vector4f));
+ memcpy_neon(&clip_plane0_eq.x, &temp.x, sizeof(vector4f));
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
diff --git a/deps/vitaGL/source/shaders.h b/deps/vitaGL/source/shaders.h
index 24a9db1c13..705ec6f04d 100644
--- a/deps/vitaGL/source/shaders.h
+++ b/deps/vitaGL/source/shaders.h
@@ -25,81 +25,81 @@
#define _SHADERS_H_
// Disable color buffer shader
-SceGxmShaderPatcherId disable_color_buffer_fragment_id;
-const SceGxmProgramParameter *disable_color_buffer_position;
-SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
-const SceGxmProgramParameter *clear_depth;
+extern SceGxmShaderPatcherId disable_color_buffer_fragment_id;
+extern const SceGxmProgramParameter *disable_color_buffer_position;
+extern SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
+extern const SceGxmProgramParameter *clear_depth;
// Clear shader
-SceGxmShaderPatcherId clear_vertex_id;
-SceGxmShaderPatcherId clear_fragment_id;
-const SceGxmProgramParameter *clear_position;
-const SceGxmProgramParameter *clear_color;
-SceGxmVertexProgram *clear_vertex_program_patched;
-SceGxmFragmentProgram *clear_fragment_program_patched;
+extern SceGxmShaderPatcherId clear_vertex_id;
+extern SceGxmShaderPatcherId clear_fragment_id;
+extern const SceGxmProgramParameter *clear_position;
+extern const SceGxmProgramParameter *clear_color;
+extern SceGxmVertexProgram *clear_vertex_program_patched;
+extern SceGxmFragmentProgram *clear_fragment_program_patched;
// Color (RGBA/RGB) shader
-SceGxmShaderPatcherId rgba_vertex_id;
-SceGxmShaderPatcherId rgb_vertex_id;
-SceGxmShaderPatcherId rgba_fragment_id;
-const SceGxmProgramParameter *rgba_position;
-const SceGxmProgramParameter *rgba_color;
-const SceGxmProgramParameter *rgba_wvp;
-const SceGxmProgramParameter *rgb_position;
-const SceGxmProgramParameter *rgb_color;
-const SceGxmProgramParameter *rgb_wvp;
-SceGxmVertexProgram *rgba_vertex_program_patched;
-SceGxmVertexProgram *rgba_u8n_vertex_program_patched;
-SceGxmVertexProgram *rgb_vertex_program_patched;
-SceGxmVertexProgram *rgb_u8n_vertex_program_patched;
-SceGxmFragmentProgram *rgba_fragment_program_patched;
-const SceGxmProgram *rgba_fragment_program;
+extern SceGxmShaderPatcherId rgba_vertex_id;
+extern SceGxmShaderPatcherId rgb_vertex_id;
+extern SceGxmShaderPatcherId rgba_fragment_id;
+extern const SceGxmProgramParameter *rgba_position;
+extern const SceGxmProgramParameter *rgba_color;
+extern const SceGxmProgramParameter *rgba_wvp;
+extern const SceGxmProgramParameter *rgb_position;
+extern const SceGxmProgramParameter *rgb_color;
+extern const SceGxmProgramParameter *rgb_wvp;
+extern SceGxmVertexProgram *rgba_vertex_program_patched;
+extern SceGxmVertexProgram *rgba_u8n_vertex_program_patched;
+extern SceGxmVertexProgram *rgb_vertex_program_patched;
+extern SceGxmVertexProgram *rgb_u8n_vertex_program_patched;
+extern SceGxmFragmentProgram *rgba_fragment_program_patched;
+extern const SceGxmProgram *rgba_fragment_program;
// Texture2D shader
-SceGxmShaderPatcherId texture2d_vertex_id;
-SceGxmShaderPatcherId texture2d_fragment_id;
-const SceGxmProgramParameter *texture2d_position;
-const SceGxmProgramParameter *texture2d_texcoord;
-const SceGxmProgramParameter *texture2d_wvp;
-const SceGxmProgramParameter *texture2d_alpha_cut;
-const SceGxmProgramParameter *texture2d_alpha_op;
-const SceGxmProgramParameter *texture2d_tint_color;
-const SceGxmProgramParameter *texture2d_tex_env;
-const SceGxmProgramParameter *texture2d_clip_plane0;
-const SceGxmProgramParameter *texture2d_clip_plane0_eq;
-const SceGxmProgramParameter *texture2d_mv;
-const SceGxmProgramParameter *texture2d_fog_mode;
-const SceGxmProgramParameter *texture2d_fog_near;
-const SceGxmProgramParameter *texture2d_fog_far;
-const SceGxmProgramParameter *texture2d_fog_density;
-const SceGxmProgramParameter *texture2d_fog_color;
-const SceGxmProgramParameter *texture2d_tex_env_color;
-SceGxmVertexProgram *texture2d_vertex_program_patched;
-SceGxmFragmentProgram *texture2d_fragment_program_patched;
-const SceGxmProgram *texture2d_fragment_program;
+extern SceGxmShaderPatcherId texture2d_vertex_id;
+extern SceGxmShaderPatcherId texture2d_fragment_id;
+extern const SceGxmProgramParameter *texture2d_position;
+extern const SceGxmProgramParameter *texture2d_texcoord;
+extern const SceGxmProgramParameter *texture2d_wvp;
+extern const SceGxmProgramParameter *texture2d_alpha_cut;
+extern const SceGxmProgramParameter *texture2d_alpha_op;
+extern const SceGxmProgramParameter *texture2d_tint_color;
+extern const SceGxmProgramParameter *texture2d_tex_env;
+extern const SceGxmProgramParameter *texture2d_clip_plane0;
+extern const SceGxmProgramParameter *texture2d_clip_plane0_eq;
+extern const SceGxmProgramParameter *texture2d_mv;
+extern const SceGxmProgramParameter *texture2d_fog_mode;
+extern const SceGxmProgramParameter *texture2d_fog_near;
+extern const SceGxmProgramParameter *texture2d_fog_far;
+extern const SceGxmProgramParameter *texture2d_fog_density;
+extern const SceGxmProgramParameter *texture2d_fog_color;
+extern const SceGxmProgramParameter *texture2d_tex_env_color;
+extern SceGxmVertexProgram *texture2d_vertex_program_patched;
+extern SceGxmFragmentProgram *texture2d_fragment_program_patched;
+extern const SceGxmProgram *texture2d_fragment_program;
// Texture2D+RGBA shader
-SceGxmShaderPatcherId texture2d_rgba_vertex_id;
-SceGxmShaderPatcherId texture2d_rgba_fragment_id;
-const SceGxmProgramParameter *texture2d_rgba_position;
-const SceGxmProgramParameter *texture2d_rgba_texcoord;
-const SceGxmProgramParameter *texture2d_rgba_wvp;
-const SceGxmProgramParameter *texture2d_rgba_alpha_cut;
-const SceGxmProgramParameter *texture2d_rgba_alpha_op;
-const SceGxmProgramParameter *texture2d_rgba_color;
-const SceGxmProgramParameter *texture2d_rgba_tex_env;
-const SceGxmProgramParameter *texture2d_rgba_clip_plane0;
-const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq;
-const SceGxmProgramParameter *texture2d_rgba_mv;
-const SceGxmProgramParameter *texture2d_rgba_fog_mode;
-const SceGxmProgramParameter *texture2d_rgba_fog_near;
-const SceGxmProgramParameter *texture2d_rgba_fog_far;
-const SceGxmProgramParameter *texture2d_rgba_fog_density;
-const SceGxmProgramParameter *texture2d_rgba_fog_color;
-const SceGxmProgramParameter *texture2d_rgba_tex_env_color;
-SceGxmVertexProgram *texture2d_rgba_vertex_program_patched;
-SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched;
-SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched;
-const SceGxmProgram *texture2d_rgba_fragment_program;
+extern SceGxmShaderPatcherId texture2d_rgba_vertex_id;
+extern SceGxmShaderPatcherId texture2d_rgba_fragment_id;
+extern const SceGxmProgramParameter *texture2d_rgba_position;
+extern const SceGxmProgramParameter *texture2d_rgba_texcoord;
+extern const SceGxmProgramParameter *texture2d_rgba_wvp;
+extern const SceGxmProgramParameter *texture2d_rgba_alpha_cut;
+extern const SceGxmProgramParameter *texture2d_rgba_alpha_op;
+extern const SceGxmProgramParameter *texture2d_rgba_color;
+extern const SceGxmProgramParameter *texture2d_rgba_tex_env;
+extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0;
+extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq;
+extern const SceGxmProgramParameter *texture2d_rgba_mv;
+extern const SceGxmProgramParameter *texture2d_rgba_fog_mode;
+extern const SceGxmProgramParameter *texture2d_rgba_fog_near;
+extern const SceGxmProgramParameter *texture2d_rgba_fog_far;
+extern const SceGxmProgramParameter *texture2d_rgba_fog_density;
+extern const SceGxmProgramParameter *texture2d_rgba_fog_color;
+extern const SceGxmProgramParameter *texture2d_rgba_tex_env_color;
+extern SceGxmVertexProgram *texture2d_rgba_vertex_program_patched;
+extern SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched;
+extern SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched;
+extern const SceGxmProgram *texture2d_rgba_fragment_program;
#endif
diff --git a/deps/vitaGL/source/shared.h b/deps/vitaGL/source/shared.h
index 6be0eb7723..021434883e 100644
--- a/deps/vitaGL/source/shared.h
+++ b/deps/vitaGL/source/shared.h
@@ -56,6 +56,8 @@ extern float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float)
#include "state.h"
#include "texture_callbacks.h"
+#define SET_GL_ERROR(x) vgl_error = x; return;
+
// Texture environment mode
typedef enum texEnvMode {
MODULATE = 0,
@@ -107,6 +109,9 @@ void LOG(const char *format, ...);
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
+extern uint8_t use_shark; // Flag to check if vitaShaRK should be initialized at vitaGL boot
+extern uint8_t is_shark_online; // Current vitaShaRK status
+
// sceGxm viewport setup (NOTE: origin is on center screen)
extern float x_port;
extern float y_port;
@@ -126,10 +131,11 @@ extern float fullscreen_z_scale;
extern SceGxmContext *gxm_context; // sceGxm context instance
extern GLenum vgl_error; // Error returned by glGetError
extern SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance
+extern uint8_t system_app_mode; // Flag for system app mode usage
-matrix4x4 mvp_matrix; // ModelViewProjection Matrix
-matrix4x4 projection_matrix; // Projection Matrix
-matrix4x4 modelview_matrix; // ModelView Matrix
+extern matrix4x4 mvp_matrix; // ModelViewProjection Matrix
+extern matrix4x4 projection_matrix; // Projection Matrix
+extern matrix4x4 modelview_matrix; // ModelView Matrix
extern GLboolean mvp_modified; // Check if ModelViewProjection matrix needs to be recreated
extern GLuint cur_program; // Current in use custom program (0 = No custom program)
diff --git a/deps/vitaGL/source/state.h b/deps/vitaGL/source/state.h
index fea6184987..3b9f21c0e5 100644
--- a/deps/vitaGL/source/state.h
+++ b/deps/vitaGL/source/state.h
@@ -96,6 +96,7 @@ typedef struct texture_unit {
SceGxmTextureFilter mag_filter;
SceGxmTextureAddrMode u_mode;
SceGxmTextureAddrMode v_mode;
+ uint32_t lod_bias;
} texture_unit;
// Framebuffer struct
diff --git a/deps/vitaGL/source/tests.c b/deps/vitaGL/source/tests.c
index cce5dd5800..8e0251412a 100644
--- a/deps/vitaGL/source/tests.c
+++ b/deps/vitaGL/source/tests.c
@@ -246,21 +246,21 @@ void update_scissor_test() {
// Setting current vertex program to clear screen one and fragment program to scissor test one
sceGxmSetVertexProgram(gxm_context, clear_vertex_program_patched);
sceGxmSetFragmentProgram(gxm_context, scissor_test_fragment_program);
-
+
// Invalidating viewport
invalidate_viewport();
-
+
// Invalidating internal tile based region clip
sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
-
+
if (scissor_test_state) {
// Calculating scissor test region vertices
vector4f_convert_to_local_space(scissor_test_vertices, region.x, region.y, region.w, region.h);
-
+
void *vertex_buffer;
sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vertex_buffer);
sceGxmSetUniformDataF(vertex_buffer, clear_position, 0, 4, &clear_vertices->x);
-
+
// Cleaning stencil surface mask update bit on the whole screen
sceGxmSetFrontStencilFunc(gxm_context,
SCE_GXM_STENCIL_FUNC_NEVER,
@@ -290,7 +290,7 @@ void update_scissor_test() {
SCE_GXM_STENCIL_OP_KEEP,
SCE_GXM_STENCIL_OP_KEEP,
0, 0);
-
+
void *vertex_buffer;
sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vertex_buffer);
if (scissor_test_state)
@@ -298,14 +298,14 @@ void update_scissor_test() {
else
sceGxmSetUniformDataF(vertex_buffer, clear_position, 0, 4, &clear_vertices->x);
sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_FAN, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4);
-
+
// Restoring viewport
validate_viewport();
-
+
// Reducing GPU workload by performing tile granularity clipping
if (scissor_test_state)
sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, region.x, region.y, region.x + region.w - 1, region.y + region.h - 1);
-
+
// Restoring original stencil test settings
change_stencil_settings();
}
@@ -327,8 +327,7 @@ void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if ((width < 0) || (height < 0)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -385,8 +384,7 @@ void glDepthMask(GLboolean flag) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
- vgl_error = GL_INVALID_OPERATION;
- return;
+ SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
@@ -407,36 +405,36 @@ void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass
switch (face) {
case GL_FRONT:
if (!change_stencil_config(&stencil_fail_front, sfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_front, dpfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
case GL_BACK:
if (!change_stencil_config(&stencil_fail_back, sfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_back, dpfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
case GL_FRONT_AND_BACK:
if (!change_stencil_config(&stencil_fail_front, sfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&stencil_fail_back, sfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_front, dpfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_back, dpfail))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_back, dppass))
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
change_stencil_settings();
@@ -450,27 +448,31 @@ void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) {
// Properly updating stencil test function settings
switch (face) {
case GL_FRONT:
- if (!change_stencil_func_config(&stencil_func_front, func))
- vgl_error = GL_INVALID_ENUM;
+ if (!change_stencil_func_config(&stencil_func_front, func)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ }
stencil_mask_front = mask;
stencil_ref_front = ref;
break;
case GL_BACK:
- if (!change_stencil_func_config(&stencil_func_back, func))
- vgl_error = GL_INVALID_ENUM;
+ if (!change_stencil_func_config(&stencil_func_back, func)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ }
stencil_mask_back = mask;
stencil_ref_back = ref;
break;
case GL_FRONT_AND_BACK:
- if (!change_stencil_func_config(&stencil_func_front, func))
- vgl_error = GL_INVALID_ENUM;
- if (!change_stencil_func_config(&stencil_func_back, func))
- vgl_error = GL_INVALID_ENUM;
+ if (!change_stencil_func_config(&stencil_func_front, func)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ }
+ if (!change_stencil_func_config(&stencil_func_back, func)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ }
stencil_mask_front = stencil_mask_back = mask;
stencil_ref_front = stencil_ref_back = ref;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
change_stencil_settings();
@@ -493,7 +495,7 @@ void glStencilMaskSeparate(GLenum face, GLuint mask) {
stencil_mask_front_write = stencil_mask_back_write = mask;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
return;
}
change_stencil_settings();
diff --git a/deps/vitaGL/source/texture_callbacks.c b/deps/vitaGL/source/texture_callbacks.c
index 08039147e4..48f42cbafd 100644
--- a/deps/vitaGL/source/texture_callbacks.c
+++ b/deps/vitaGL/source/texture_callbacks.c
@@ -24,12 +24,15 @@
#include
#include
+#include "vitaGL.h"
#include "texture_callbacks.h"
+#define convert_u16_to_u32_cspace(color, lshift, rshift, mask) ((((color << lshift) >> rshift) & mask) * 0xFF) / mask
+
// Read callback for 32bpp unsigned RGBA format
uint32_t readRGBA(void *data) {
uint32_t res;
- memcpy(&res, data, 4);
+ memcpy_neon(&res, data, 4);
return res;
}
@@ -37,48 +40,71 @@ uint32_t readRGBA(void *data) {
uint32_t readRGBA5551(void *data) {
uint16_t clr;
uint32_t r, g, b, a;
- memcpy(&clr, data, 2);
- r = (((clr >> 11) & 0x1F) * 0xFF) / 0x1F;
- g = ((((clr << 5) >> 11) & 0x1F) * 0xFF) / 0x1F;
- b = ((((clr << 10) >> 11) & 0x1F) * 0xFF) / 0x1F;
- a = (((clr << 15) >> 15) & 0x1) == 1 ? 0xFF : 0x00;
+ memcpy_neon(&clr, data, 2);
+ r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
+ g = convert_u16_to_u32_cspace(clr, 5, 11, 0x1F);
+ b = convert_u16_to_u32_cspace(clr, 10, 11, 0x1F);
+ a = convert_u16_to_u32_cspace(clr, 15, 15, 0x01);
return ((a << 24) | (b << 16) | (g << 8) | r);
}
+// Read callback for 16bpp unsigned RGBA4444 format
+uint32_t readRGBA4444(void *data) {
+ uint16_t clr;
+ uint32_t r, g, b, a;
+ memcpy_neon(&clr, data, 2);
+ r = convert_u16_to_u32_cspace(clr, 0, 12, 0x0F);
+ g = convert_u16_to_u32_cspace(clr, 4, 12, 0x0F);
+ b = convert_u16_to_u32_cspace(clr, 8, 12, 0x0F);
+ a = convert_u16_to_u32_cspace(clr, 12, 12, 0x0F);
+ return ((a << 24) | (b << 16) | (g << 8) | r);
+}
+
+// Read callback for 16bpp unsigned RGB565 format
+uint32_t readRGB565(void *data) {
+ uint16_t clr;
+ uint32_t r, g, b;
+ memcpy_neon(&clr, data, 2);
+ r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
+ g = convert_u16_to_u32_cspace(clr, 5, 11, 0x3F);
+ b = convert_u16_to_u32_cspace(clr, 11, 11, 0x1F);
+ return ((0xFF << 24) | (b << 16) | (g << 8) | r);
+}
+
// Read callback for 24bpp unsigned RGB format
uint32_t readRGB(void *data) {
uint32_t res = 0xFFFFFFFF;
- memcpy(&res, data, 3);
+ memcpy_neon(&res, data, 3);
return res;
}
// Read callback for 16bpp unsigned RG format
uint32_t readRG(void *data) {
uint32_t res = 0xFFFFFFFF;
- memcpy(&res, data, 2);
+ memcpy_neon(&res, data, 2);
return res;
}
// Read callback for 8bpp unsigned R format
uint32_t readR(void *data) {
uint32_t res = 0xFFFFFFFF;
- memcpy(&res, data, 1);
+ memcpy_neon(&res, data, 1);
return res;
}
// Write callback for 32bpp unsigned RGBA format
void writeRGBA(void *data, uint32_t color) {
- memcpy(data, &color, 4);
+ memcpy_neon(data, &color, 4);
}
// Write callback for 24bpp unsigned RGB format
void writeRGB(void *data, uint32_t color) {
- memcpy(data, &color, 3);
+ memcpy_neon(data, &color, 3);
}
// Write callback for 16bpp unsigned RG format
void writeRG(void *data, uint32_t color) {
- memcpy(data, &color, 2);
+ memcpy_neon(data, &color, 2);
}
// Write callback for 16bpp unsigned RA format
@@ -91,5 +117,5 @@ void writeRA(void *data, uint32_t color) {
// Write callback for 8bpp unsigned R format
void writeR(void *data, uint32_t color) {
- memcpy(data, &color, 1);
+ memcpy_neon(data, &color, 1);
}
\ No newline at end of file
diff --git a/deps/vitaGL/source/texture_callbacks.h b/deps/vitaGL/source/texture_callbacks.h
index e9177ac78c..dd038b5bc2 100644
--- a/deps/vitaGL/source/texture_callbacks.h
+++ b/deps/vitaGL/source/texture_callbacks.h
@@ -28,8 +28,10 @@
uint32_t readR(void *data);
uint32_t readRG(void *data);
uint32_t readRGB(void *data);
+uint32_t readRGB565(void *data);
uint32_t readRGBA(void *data);
uint32_t readRGBA5551(void *data);
+uint32_t readRGBA4444(void *data);
// Write callbacks
void writeR(void *data, uint32_t color);
diff --git a/deps/vitaGL/source/textures.c b/deps/vitaGL/source/textures.c
index 8d7295926c..2a74bc6231 100644
--- a/deps/vitaGL/source/textures.c
+++ b/deps/vitaGL/source/textures.c
@@ -37,8 +37,7 @@ void glGenTextures(GLsizei n, GLuint *res) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -67,7 +66,7 @@ void glBindTexture(GLenum target, GLuint texture) {
tex_unit->tex_id = texture;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -76,8 +75,7 @@ void glDeleteTextures(GLsizei n, const GLuint *gl_textures) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
@@ -138,7 +136,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
data_bpp = 1;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -150,7 +148,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
data_bpp = 2;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -158,11 +156,17 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
switch (type) {
case GL_UNSIGNED_BYTE:
data_bpp = 3;
- if (internalFormat == GL_RGB) fast_store = GL_TRUE;
- else read_cb = readRGB;
+ if (internalFormat == GL_RGB)
+ fast_store = GL_TRUE;
+ else
+ read_cb = readRGB;
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ data_bpp = 2;
+ read_cb = readRGB565;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -170,15 +174,21 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
switch (type) {
case GL_UNSIGNED_BYTE:
data_bpp = 4;
- if (internalFormat == GL_RGBA) fast_store = GL_TRUE;
- else read_cb = readRGBA;
+ if (internalFormat == GL_RGBA)
+ fast_store = GL_TRUE;
+ else
+ read_cb = readRGBA;
break;
case GL_UNSIGNED_SHORT_5_5_5_1:
data_bpp = 2;
read_cb = readRGBA5551;
break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ data_bpp = 2;
+ read_cb = readRGBA4444;
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -225,22 +235,23 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
tex_format = SCE_GXM_TEXTURE_FORMAT_P8_ABGR;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
// Checking if texture is too big for sceGxm
if (width > GXM_TEX_MAX_SIZE || height > GXM_TEX_MAX_SIZE) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
// Allocating texture/mipmaps depending on user call
tex->type = internalFormat;
tex->write_cb = write_cb;
if (level == 0)
- if (tex->write_cb) gpu_alloc_texture(width, height, tex_format, data, tex, data_bpp, read_cb, write_cb, fast_store);
- else gpu_alloc_compressed_texture(width, height, tex_format, data, tex, data_bpp, read_cb);
+ if (tex->write_cb)
+ gpu_alloc_texture(width, height, tex_format, data, tex, data_bpp, read_cb, write_cb, fast_store);
+ else
+ gpu_alloc_compressed_texture(width, height, tex_format, data, tex, data_bpp, read_cb);
else {
gpu_alloc_mipmaps(level, tex);
sceGxmTextureSetMipFilter(&tex->gxm_tex, SCE_GXM_TEXTURE_MIP_FILTER_ENABLED);
@@ -251,6 +262,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter);
sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter);
+ sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
// Setting palette if the format requests one
if (tex->valid && tex->palette_UID)
@@ -258,7 +270,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -281,13 +293,11 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
int i, j;
if (xoffset + width > orig_w) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
} else if (yoffset + height > orig_h) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
-
+
// Support for legacy GL1.0 format
switch (format) {
case 1:
@@ -303,7 +313,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
format = GL_RGBA;
break;
}
-
+
/*
* Callbacks are actually used to just perform down/up-sampling
* between U8 texture formats. Reads are expected to give as result
@@ -323,8 +333,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 1;
break;
default:
- vgl_error = GL_INVALID_ENUM;
- return;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -335,8 +344,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 2;
break;
default:
- vgl_error = GL_INVALID_ENUM;
- return;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -346,9 +354,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 3;
read_cb = readRGB;
break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ data_bpp = 2;
+ read_cb = readRGB565;
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
- return;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -362,9 +373,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 2;
read_cb = readRGBA5551;
break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ data_bpp = 2;
+ read_cb = readRGBA4444;
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
- return;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
@@ -410,7 +424,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -431,12 +445,12 @@ void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum fo
bpp = 4;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -470,7 +484,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter);
@@ -492,7 +506,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter);
@@ -512,7 +526,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
sceGxmTextureSetUAddrMode(&tex->gxm_tex, tex_unit->u_mode);
@@ -532,18 +546,22 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
break;
+ case GL_TEXTURE_LOD_BIAS: // Distant LOD bias
+ tex_unit->lod_bias = (uint32_t)(param + GL_MAX_TEXTURE_LOD_BIAS);
+ sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -593,13 +611,17 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP; // Mirror Clamp
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
break;
+ case GL_TEXTURE_LOD_BIAS: // Distant LOD bias
+ tex_unit->lod_bias = (uint32_t)(param + GL_MAX_TEXTURE_LOD_BIAS);
+ sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
+ break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -607,9 +629,9 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {
void glActiveTexture(GLenum texture) {
// Changing current in use server texture unit
#ifndef SKIP_ERROR_HANDLING
- if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31))
- vgl_error = GL_INVALID_ENUM;
- else
+ if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ } else
#endif
server_texture_unit = texture - GL_TEXTURE0;
}
@@ -641,7 +663,7 @@ void glGenerateMipmap(GLenum target) {
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -667,12 +689,13 @@ void glTexEnvf(GLenum target, GLenum pname, GLfloat param) {
tex_unit->env_mode = ADD;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ break;
}
}
@@ -682,15 +705,16 @@ void glTexEnvfv(GLenum target, GLenum pname, GLfloat *param) {
case GL_TEXTURE_ENV:
switch (pname) {
case GL_TEXTURE_ENV_COLOR:
- memcpy(&texenv_color.r, param, sizeof(GLfloat) * 4);
+ memcpy_neon(&texenv_color.r, param, sizeof(GLfloat) * 4);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ break;
}
}
@@ -722,12 +746,12 @@ void glTexEnvi(GLenum target, GLenum pname, GLint param) {
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
diff --git a/deps/vitaGL/source/utils/gpu_utils.c b/deps/vitaGL/source/utils/gpu_utils.c
index cdda870475..6097b1deb3 100644
--- a/deps/vitaGL/source/utils/gpu_utils.c
+++ b/deps/vitaGL/source/utils/gpu_utils.c
@@ -25,8 +25,8 @@
#include "stb_dxt.h"
#ifndef MIN
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#define MAX(a,b) (((a)<(b))?(b):(a))
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#endif
// VRAM usage setting
@@ -45,29 +45,27 @@ static unsigned int pool_size = 0;
vglMemType frag_usse_type;
vglMemType vert_usse_type;
-uint64_t morton_1(uint64_t x)
-{
- x = x & 0x5555555555555555;
- x = (x | (x >> 1)) & 0x3333333333333333;
- x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F;
- x = (x | (x >> 4)) & 0x00FF00FF00FF00FF;
- x = (x | (x >> 8)) & 0x0000FFFF0000FFFF;
- x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF;
- return x;
+uint64_t morton_1(uint64_t x) {
+ x = x & 0x5555555555555555;
+ x = (x | (x >> 1)) & 0x3333333333333333;
+ x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F;
+ x = (x | (x >> 4)) & 0x00FF00FF00FF00FF;
+ x = (x | (x >> 8)) & 0x0000FFFF0000FFFF;
+ x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF;
+ return x;
}
-void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y)
-{
- *x = morton_1(d);
- *y = morton_1(d >> 1);
+void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) {
+ *x = morton_1(d);
+ *y = morton_1(d >> 1);
}
void extract_block(const uint8_t *src, int width, uint8_t *block) {
int j;
for (j = 0; j < 4; j++) {
- memcpy(&block[j * 4 * 4], src, 16);
+ memcpy_neon(&block[j * 4 * 4], src, 16);
src += width * 4;
- }
+ }
}
void dxt_compress(uint8_t *dst, uint8_t *src, int w, int h, int isdxt5) {
@@ -77,8 +75,10 @@ void dxt_compress(uint8_t *dst, uint8_t *src, int w, int h, int isdxt5) {
uint64_t d, offs_x, offs_y;
for (d = 0; d < num_blocks; d++) {
d2xy_morton(d, &offs_x, &offs_y);
- if (offs_x * 4 >= h) continue;
- if (offs_y * 4 >= w) continue;
+ if (offs_x * 4 >= h)
+ continue;
+ if (offs_y * 4 >= w)
+ continue;
extract_block(src + offs_y * 16 + offs_x * w * 16, w, block);
stb_compress_dxt_block(dst, block, isdxt5, STB_DXT_HIGHQUAL);
dst += isdxt5 ? 16 : 8;
@@ -239,7 +239,7 @@ palette *gpu_alloc_palette(const void *data, uint32_t w, uint32_t bpe) {
if (data == NULL)
memset(texture_palette, 0, 256 * sizeof(uint32_t));
else if (bpe == 4)
- memcpy(texture_palette, data, w * sizeof(uint32_t));
+ memcpy_neon(texture_palette, data, w * sizeof(uint32_t));
res->data = texture_palette;
// Returning palette
@@ -274,11 +274,11 @@ void gpu_alloc_texture(uint32_t w, uint32_t h, SceGxmTextureFormat format, const
int i, j;
uint8_t *src = (uint8_t *)data;
uint8_t *dst;
- if (fast_store) { // Internal Format and Data Format are the same, we can just use memcpy for better performance
+ if (fast_store) { // Internal Format and Data Format are the same, we can just use memcpy_neon for better performance
uint32_t line_size = w * bpp;
for (i = 0; i < h; i++) {
dst = ((uint8_t *)texture_data) + (ALIGN(w, 8) * bpp) * i;
- memcpy(dst, src, line_size);
+ memcpy_neon(dst, src, line_size);
src += line_size;
}
} else { // Different internal and data formats, we need to go with slower callbacks system
@@ -310,20 +310,21 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo
// If there's already a texture in passed texture object we first dealloc it
if (tex->valid)
gpu_free_texture(tex);
-
+
// Getting texture format alignment
uint8_t alignment = tex_format_to_alignment(format);
-
+
// Calculating swizzled compressed texture size on memory
tex->mtype = use_vram ? VGL_MEM_VRAM : VGL_MEM_RAM;
int tex_size = w * h;
- if (alignment == 8) tex_size /= 2;
-
+ if (alignment == 8)
+ tex_size /= 2;
+
// Allocating texture data buffer
void *texture_data = gpu_alloc_mapped(tex_size, &tex->mtype);
-
+
// NOTE: Supports only GL_RGBA source format for now
-
+
// Initializing texture data buffer
if (texture_data != NULL) {
// Initializing texture data buffer
@@ -338,11 +339,10 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo
writeRGBA(dst++, src);
src += src_bpp;
}*/
-
+
// Performing swizzling and DXT compression
- dxt_compress(texture_data, (void*)data, w, h, alignment == 16);
-
-
+ dxt_compress(texture_data, (void *)data, w, h, alignment == 16);
+
//swizzle(texture_data, tmp2, w, h, alignment << 3);
//free(tmp);
//free(tmp2);
@@ -418,7 +418,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) {
has_temp_buffer = GL_FALSE;
temp = sceGxmTextureGetData(&tex->gxm_tex);
} else {
- memcpy(temp, sceGxmTextureGetData(&tex->gxm_tex), stride * orig_h * bpp);
+ memcpy_neon(temp, sceGxmTextureGetData(&tex->gxm_tex), stride * orig_h * bpp);
gpu_free_texture(tex);
}
@@ -427,7 +427,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) {
void *texture_data = gpu_alloc_mapped(size, &tex->mtype);
// Moving back old texture data from heap to texture memblock
- memcpy(texture_data, temp, stride * orig_h * bpp);
+ memcpy_neon(texture_data, temp, stride * orig_h * bpp);
if (has_temp_buffer)
free(temp);
else
diff --git a/deps/vitaGL/source/utils/math_utils.c b/deps/vitaGL/source/utils/math_utils.c
index 3b2ab113c8..ef9390781e 100644
--- a/deps/vitaGL/source/utils/math_utils.c
+++ b/deps/vitaGL/source/utils/math_utils.c
@@ -36,7 +36,7 @@ void matrix4x4_identity(matrix4x4 m) {
}
void matrix4x4_copy(matrix4x4 dst, const matrix4x4 src) {
- memcpy(dst, src, sizeof(matrix4x4));
+ memcpy_neon(dst, src, sizeof(matrix4x4));
}
void matrix4x4_multiply(matrix4x4 dst, const matrix4x4 src1, const matrix4x4 src2) {
diff --git a/deps/vitaGL/source/utils/mem_utils.c b/deps/vitaGL/source/utils/mem_utils.c
index 0a46a312eb..3d23d96871 100644
--- a/deps/vitaGL/source/utils/mem_utils.c
+++ b/deps/vitaGL/source/utils/mem_utils.c
@@ -272,25 +272,31 @@ int vgl_mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont) {
if (mempool_addr[0] != NULL)
vgl_mem_term();
- mempool_size[0] = ALIGN(size_cdram, 256 * 1024);
- mempool_size[1] = ALIGN(size_ram, 4 * 1024);
- mempool_size[2] = ALIGN(size_phycont, 256 * 1024);
- mempool_id[0] = sceKernelAllocMemBlock("cdram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, mempool_size[0], NULL);
- mempool_id[1] = sceKernelAllocMemBlock("ram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, mempool_size[1], NULL);
- mempool_id[2] = sceKernelAllocMemBlock("phycont_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW, mempool_size[2], NULL);
+ mempool_size[VGL_MEM_VRAM - 1] = ALIGN(size_cdram, 256 * 1024);
+ mempool_size[VGL_MEM_RAM - 1] = ALIGN(size_ram, 4 * 1024);
+ mempool_size[VGL_MEM_SLOW - 1] = ALIGN(size_phycont, 256 * 1024);
+ if (size_cdram)
+ mempool_id[VGL_MEM_VRAM - 1] = sceKernelAllocMemBlock("cdram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, mempool_size[VGL_MEM_VRAM - 1], NULL);
+ mempool_id[VGL_MEM_RAM - 1] = sceKernelAllocMemBlock("ram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, mempool_size[VGL_MEM_RAM - 1], NULL);
+ if (size_phycont)
+ mempool_id[VGL_MEM_SLOW - 1] = sceKernelAllocMemBlock("phycont_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW, mempool_size[VGL_MEM_SLOW - 1], NULL);
for (int i = 0; i < VGL_MEM_TYPE_COUNT - 2; i++) {
- sceKernelGetMemBlockBase(mempool_id[i], &mempool_addr[i]);
- sceGxmMapMemory(mempool_addr[i], mempool_size[i], SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
+ if (mempool_size[i]) {
+ sceKernelGetMemBlockBase(mempool_id[i], &mempool_addr[i]);
+ sceGxmMapMemory(mempool_addr[i], mempool_size[i], SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
+ }
}
// Initialize heap
heap_init();
// Add memblocks to heap
- heap_extend(VGL_MEM_VRAM, mempool_addr[0], mempool_size[0]);
+ if (size_cdram)
+ heap_extend(VGL_MEM_VRAM, mempool_addr[0], mempool_size[0]);
heap_extend(VGL_MEM_RAM, mempool_addr[1], mempool_size[1]);
- heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]);
+ if (size_phycont)
+ heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]);
return 1;
}
diff --git a/deps/vitaGL/source/utils/stb_dxt.h b/deps/vitaGL/source/utils/stb_dxt.h
index 9f7a4295a8..7441bede63 100644
--- a/deps/vitaGL/source/utils/stb_dxt.h
+++ b/deps/vitaGL/source/utils/stb_dxt.h
@@ -684,7 +684,7 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a
dest += 8;
// make a new copy of the data in which alpha is opaque,
// because code uses a fast test for color constancy
- memcpy(data, src, 4*16);
+ memcpy_neon(data, src, 4*16);
for (i=0; i < 16; ++i)
data[i][3] = 255;
src = &data[0][0];
diff --git a/deps/vitaGL/source/vitaGL.c b/deps/vitaGL/source/vitaGL.c
index 925cd12948..47bb02d623 100644
--- a/deps/vitaGL/source/vitaGL.c
+++ b/deps/vitaGL/source/vitaGL.c
@@ -36,6 +36,84 @@
#include "shaders/texture2d_rgba_v.h"
#include "shaders/texture2d_v.h"
+// Disable color buffer shader
+SceGxmShaderPatcherId disable_color_buffer_fragment_id;
+const SceGxmProgramParameter *disable_color_buffer_position;
+SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
+const SceGxmProgramParameter *clear_depth;
+
+// Clear shader
+SceGxmShaderPatcherId clear_vertex_id;
+SceGxmShaderPatcherId clear_fragment_id;
+const SceGxmProgramParameter *clear_position;
+const SceGxmProgramParameter *clear_color;
+SceGxmVertexProgram *clear_vertex_program_patched;
+SceGxmFragmentProgram *clear_fragment_program_patched;
+
+// Color (RGBA/RGB) shader
+SceGxmShaderPatcherId rgba_vertex_id;
+SceGxmShaderPatcherId rgb_vertex_id;
+SceGxmShaderPatcherId rgba_fragment_id;
+const SceGxmProgramParameter *rgba_position;
+const SceGxmProgramParameter *rgba_color;
+const SceGxmProgramParameter *rgba_wvp;
+const SceGxmProgramParameter *rgb_position;
+const SceGxmProgramParameter *rgb_color;
+const SceGxmProgramParameter *rgb_wvp;
+SceGxmVertexProgram *rgba_vertex_program_patched;
+SceGxmVertexProgram *rgba_u8n_vertex_program_patched;
+SceGxmVertexProgram *rgb_vertex_program_patched;
+SceGxmVertexProgram *rgb_u8n_vertex_program_patched;
+SceGxmFragmentProgram *rgba_fragment_program_patched;
+const SceGxmProgram *rgba_fragment_program;
+
+// Texture2D shader
+SceGxmShaderPatcherId texture2d_vertex_id;
+SceGxmShaderPatcherId texture2d_fragment_id;
+const SceGxmProgramParameter *texture2d_position;
+const SceGxmProgramParameter *texture2d_texcoord;
+const SceGxmProgramParameter *texture2d_wvp;
+const SceGxmProgramParameter *texture2d_alpha_cut;
+const SceGxmProgramParameter *texture2d_alpha_op;
+const SceGxmProgramParameter *texture2d_tint_color;
+const SceGxmProgramParameter *texture2d_tex_env;
+const SceGxmProgramParameter *texture2d_clip_plane0;
+const SceGxmProgramParameter *texture2d_clip_plane0_eq;
+const SceGxmProgramParameter *texture2d_mv;
+const SceGxmProgramParameter *texture2d_fog_mode;
+const SceGxmProgramParameter *texture2d_fog_near;
+const SceGxmProgramParameter *texture2d_fog_far;
+const SceGxmProgramParameter *texture2d_fog_density;
+const SceGxmProgramParameter *texture2d_fog_color;
+const SceGxmProgramParameter *texture2d_tex_env_color;
+SceGxmVertexProgram *texture2d_vertex_program_patched;
+SceGxmFragmentProgram *texture2d_fragment_program_patched;
+const SceGxmProgram *texture2d_fragment_program;
+
+// Texture2D+RGBA shader
+SceGxmShaderPatcherId texture2d_rgba_vertex_id;
+SceGxmShaderPatcherId texture2d_rgba_fragment_id;
+const SceGxmProgramParameter *texture2d_rgba_position;
+const SceGxmProgramParameter *texture2d_rgba_texcoord;
+const SceGxmProgramParameter *texture2d_rgba_wvp;
+const SceGxmProgramParameter *texture2d_rgba_alpha_cut;
+const SceGxmProgramParameter *texture2d_rgba_alpha_op;
+const SceGxmProgramParameter *texture2d_rgba_color;
+const SceGxmProgramParameter *texture2d_rgba_tex_env;
+const SceGxmProgramParameter *texture2d_rgba_clip_plane0;
+const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq;
+const SceGxmProgramParameter *texture2d_rgba_mv;
+const SceGxmProgramParameter *texture2d_rgba_fog_mode;
+const SceGxmProgramParameter *texture2d_rgba_fog_near;
+const SceGxmProgramParameter *texture2d_rgba_fog_far;
+const SceGxmProgramParameter *texture2d_rgba_fog_density;
+const SceGxmProgramParameter *texture2d_rgba_fog_color;
+const SceGxmProgramParameter *texture2d_rgba_tex_env_color;
+SceGxmVertexProgram *texture2d_rgba_vertex_program_patched;
+SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched;
+SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched;
+const SceGxmProgram *texture2d_rgba_fragment_program;
+
typedef struct gpubuffer {
void *ptr;
} gpubuffer;
@@ -203,7 +281,7 @@ void vglUseVramForUSSE(GLboolean usage) {
use_vram_for_usse = usage;
}
-void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa) {
+void vglInitWithCustomSizes(uint32_t gpu_pool_size, int width, int height, int ram_pool_size, int cdram_pool_size, int phycont_pool_size, SceGxmMultisampleMode msaa) {
// Setting our display size
msaa_mode = msaa;
DISPLAY_WIDTH = width;
@@ -231,13 +309,8 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
// Initializing sceGxm
initGxm();
- // Getting max allocatable CDRAM and RAM memory
- SceKernelFreeMemorySizeInfo info;
- info.size = sizeof(SceKernelFreeMemorySizeInfo);
- sceKernelGetFreeMemorySize(&info);
-
// Initializing memory heap for CDRAM and RAM memory
- vgl_mem_init(info.size_user > ram_threshold ? info.size_user - ram_threshold : info.size_user, info.size_cdram - 256 * 1024, info.size_phycont - 1 * 1024 * 1024); // leave some just in case
+ vgl_mem_init(ram_pool_size, cdram_pool_size, phycont_pool_size);
// Initializing sceGxm context
initGxmContext();
@@ -608,11 +681,12 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
}
texture_units[i].env_mode = MODULATE;
texture_units[i].tex_id = 0;
- texture_units[i].enabled = 0;
+ texture_units[i].enabled = GL_FALSE;
texture_units[i].min_filter = SCE_GXM_TEXTURE_FILTER_LINEAR;
texture_units[i].mag_filter = SCE_GXM_TEXTURE_FILTER_LINEAR;
texture_units[i].u_mode = SCE_GXM_TEXTURE_ADDR_REPEAT;
texture_units[i].v_mode = SCE_GXM_TEXTURE_ADDR_REPEAT;
+ texture_units[i].lod_bias = GL_MAX_TEXTURE_LOD_BIAS; // sceGxm range is 0 - (GL_MAX_TEXTURE_LOD_BIAS*2 + 1)
}
// Init custom shaders
@@ -635,6 +709,24 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
sceGxmMapMemory(addr, _newlib_heap_size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
}
+void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa) {
+ // Initializing sceGxm
+ initGxm();
+
+ // Getting max allocatable CDRAM and RAM memory
+ if (system_app_mode) {
+ SceAppMgrBudgetInfo info;
+ info.size = sizeof(SceAppMgrBudgetInfo);
+ sceAppMgrGetBudgetInfo(&info);
+ vglInitWithCustomSizes(gpu_pool_size, width, height, info.free_user_rw > ram_threshold ? info.free_user_rw - ram_threshold : info.free_user_rw, 0, 0, msaa);
+ } else {
+ SceKernelFreeMemorySizeInfo info;
+ info.size = sizeof(SceKernelFreeMemorySizeInfo);
+ sceKernelGetFreeMemorySize(&info);
+ vglInitWithCustomSizes(gpu_pool_size, width, height, info.size_user > ram_threshold ? info.size_user - ram_threshold : info.size_user, info.size_cdram - 256 * 1024, info.size_phycont - 1 * 1024 * 1024, msaa);
+ }
+}
+
void vglInit(uint32_t gpu_pool_size) {
vglInitExtended(gpu_pool_size, DISPLAY_WIDTH_DEF, DISPLAY_HEIGHT_DEF, 0x1000000, SCE_GXM_MULTISAMPLE_NONE);
}
@@ -699,8 +791,7 @@ void glGenBuffers(GLsizei n, GLuint *res) {
int i = 0, j = 0;
#ifndef SKIP_ERROR_HANDLING
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
for (i = 0; i < BUFFERS_NUM; i++) {
@@ -716,8 +807,7 @@ void glGenBuffers(GLsizei n, GLuint *res) {
void glBindBuffer(GLenum target, GLuint buffer) {
#ifndef SKIP_ERROR_HANDLING
if ((buffer != 0x0000) && ((buffer >= BUFFERS_ADDR + BUFFERS_NUM) || (buffer < BUFFERS_ADDR))) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
switch (target) {
@@ -728,7 +818,7 @@ void glBindBuffer(GLenum target, GLuint buffer) {
index_array_unit = buffer - BUFFERS_ADDR;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -736,7 +826,7 @@ void glBindBuffer(GLenum target, GLuint buffer) {
void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) {
#ifndef SKIP_ERROR_HANDLING
if (n < 0) {
- vgl_error = GL_INVALID_VALUE;
+ SET_GL_ERROR(GL_INVALID_VALUE)
return;
}
#endif
@@ -756,8 +846,7 @@ void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) {
void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage) {
#ifndef SKIP_ERROR_HANDLING
if (size < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
int idx = 0;
@@ -769,12 +858,12 @@ void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage)
idx = index_array_unit;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
vglMemType type = VGL_MEM_VRAM;
gpu_buffers[idx].ptr = gpu_alloc_mapped(size, &type);
- memcpy(gpu_buffers[idx].ptr, data, size);
+ memcpy_neon(gpu_buffers[idx].ptr, data, size);
}
void glBlendFunc(GLenum sfactor, GLenum dfactor) {
@@ -813,7 +902,7 @@ void glBlendFunc(GLenum sfactor, GLenum dfactor) {
blend_sfactor_rgb = blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (dfactor) {
@@ -851,7 +940,7 @@ void glBlendFunc(GLenum sfactor, GLenum dfactor) {
blend_dfactor_rgb = blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (blend_state)
@@ -894,7 +983,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_sfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (dstRGB) {
@@ -932,7 +1021,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_dfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (srcAlpha) {
@@ -970,7 +1059,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (dstAlpha) {
@@ -1008,7 +1097,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (blend_state)
@@ -1033,7 +1122,7 @@ void glBlendEquation(GLenum mode) {
blend_func_rgb = blend_func_a = SCE_GXM_BLEND_FUNC_MAX;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (blend_state)
@@ -1058,7 +1147,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
blend_func_rgb = SCE_GXM_BLEND_FUNC_MAX;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
switch (modeAlpha) {
@@ -1078,7 +1167,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
blend_func_a = SCE_GXM_BLEND_FUNC_MAX;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (blend_state)
@@ -1104,8 +1193,7 @@ void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1117,7 +1205,7 @@ void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *poin
tex_unit->vertex_array.size = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -1129,8 +1217,7 @@ void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *poin
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 3) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1142,7 +1229,7 @@ void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *point
tex_unit->color_array.size = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -1154,8 +1241,7 @@ void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *point
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1167,7 +1253,7 @@ void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *po
tex_unit->texture_array.size = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
@@ -1209,7 +1295,7 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
skip_draw = GL_TRUE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (!skip_draw) {
@@ -1319,20 +1405,20 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0, tex_set = 0, clr_set = 0;
if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.num * tex_unit->vertex_array.size));
- memcpy(&vertices[0], ptr, count * sizeof(vector3f));
+ memcpy_neon(&vertices[0], ptr, count * sizeof(vector3f));
vec_set = 1;
} else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * tex_unit->vertex_array.stride);
if (tex_unit->texture_array.stride == 0) {
ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * (tex_unit->texture_array.num * tex_unit->texture_array.size));
- memcpy(&uv_map[0], ptr_tex, count * sizeof(vector2f));
+ memcpy_neon(&uv_map[0], ptr_tex, count * sizeof(vector2f));
tex_set = 1;
} else
ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * tex_unit->texture_array.stride);
if (tex_unit->color_array_state) {
if (tex_unit->color_array.stride == 0) {
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * sizeof(vector4f));
- memcpy(&colors[0], ptr_clr, count * sizeof(vector4f));
+ memcpy_neon(&colors[0], ptr_clr, count * sizeof(vector4f));
clr_set = 1;
} else
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.stride);
@@ -1340,15 +1426,15 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) {
if (!vec_set) {
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride;
}
if (!tex_set) {
- memcpy(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
+ memcpy_neon(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
ptr_tex += tex_unit->texture_array.stride;
}
if (tex_unit->color_array_state && (!clr_set)) {
- memcpy(&colors[n], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
+ memcpy_neon(&colors[n], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr_clr += tex_unit->color_array.stride;
}
indices[n] = n;
@@ -1390,24 +1476,24 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0, clr_set = 0;
if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size)));
- memcpy(&vertices[n], ptr, count * sizeof(vector3f));
+ memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f));
vec_set = 1;
} else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride));
if (tex_unit->color_array.stride == 0) {
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * ((tex_unit->color_array.num * tex_unit->color_array.size)));
- memcpy(&colors[n], ptr_clr, count * tex_unit->color_array.num * tex_unit->color_array.size);
+ memcpy_neon(&colors[n], ptr_clr, count * tex_unit->color_array.num * tex_unit->color_array.size);
clr_set = 1;
} else
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.size);
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) {
if (!vec_set) {
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride;
}
if (!clr_set) {
- memcpy(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
+ memcpy_neon(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr_clr += tex_unit->color_array.stride;
}
indices[n] = n;
@@ -1430,7 +1516,7 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f));
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) {
- memcpy(&colors[n], ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f));
indices[n] = n;
}
} else {
@@ -1441,17 +1527,17 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0;
if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size)));
- memcpy(&vertices[n], ptr, count * sizeof(vector3f));
+ memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f));
vec_set = 1;
} else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride));
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) {
if (!vec_set) {
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride;
}
- memcpy(&colors[n], ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f));
indices[n] = n;
}
}
@@ -1470,12 +1556,13 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
if (tex_unit->vertex_array_state) {
GLboolean skip_draw = GL_FALSE;
#ifndef SKIP_ERROR_HANDLING
- if (type != GL_UNSIGNED_SHORT)
- vgl_error = GL_INVALID_ENUM;
- else if (phase == MODEL_CREATION)
- vgl_error = GL_INVALID_OPERATION;
- else if (count < 0)
- vgl_error = GL_INVALID_VALUE;
+ if (type != GL_UNSIGNED_SHORT) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ } else if (phase == MODEL_CREATION) {
+ SET_GL_ERROR(GL_INVALID_OPERATION)
+ } else if (count < 0) {
+ SET_GL_ERROR(GL_INVALID_VALUE)
+ }
#endif
switch (mode) {
case GL_POINTS:
@@ -1500,7 +1587,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
skip_draw = GL_TRUE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (!skip_draw) {
@@ -1582,7 +1669,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
- memcpy(indices, gl_indices, sizeof(uint16_t) * count);
+ memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
}
if (vertex_array_unit >= 0) {
vertices = (vector3f *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->vertex_array.pointer);
@@ -1602,11 +1689,11 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uv_map = (vector2f *)gpu_pool_memalign(vertex_count_int * sizeof(vector2f), sizeof(vector2f));
colors = (vector4f *)gpu_pool_memalign(vertex_count_int * sizeof(vector4f), sizeof(vector4f));
if (tex_unit->vertex_array.stride == 0)
- memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
+ memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if (tex_unit->texture_array.stride == 0)
- memcpy(uv_map, tex_unit->texture_array.pointer, vertex_count_int * (tex_unit->texture_array.size * tex_unit->texture_array.num));
+ memcpy_neon(uv_map, tex_unit->texture_array.pointer, vertex_count_int * (tex_unit->texture_array.size * tex_unit->texture_array.num));
if (tex_unit->color_array_state && (tex_unit->color_array.stride == 0))
- memcpy(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
+ memcpy_neon(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
if ((tex_unit->vertex_array.stride != 0) || (tex_unit->texture_array.stride != 0)) {
if (tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
@@ -1614,9 +1701,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uint8_t *ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer);
for (n = 0; n < vertex_count_int; n++) {
if (tex_unit->vertex_array.stride != 0)
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
if (tex_unit->texture_array.stride != 0)
- memcpy(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
+ memcpy_neon(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
ptr += tex_unit->vertex_array.stride;
ptr_tex += tex_unit->texture_array.stride;
}
@@ -1639,7 +1726,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
- memcpy(indices, gl_indices, sizeof(uint16_t) * count);
+ memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
}
if (vertex_array_unit >= 0) {
colors = (uint8_t *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->color_array.pointer);
@@ -1656,9 +1743,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f));
colors = (uint8_t *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size);
if (tex_unit->vertex_array.stride == 0)
- memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
+ memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if (tex_unit->color_array.stride == 0)
- memcpy(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
+ memcpy_neon(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
if ((tex_unit->vertex_array.stride != 0) || (tex_unit->color_array.stride != 0)) {
if (tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
@@ -1666,9 +1753,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uint8_t *ptr_clr = ((uint8_t *)tex_unit->color_array.pointer);
for (n = 0; n < vertex_count_int; n++) {
if (tex_unit->vertex_array.stride != 0)
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
if (tex_unit->color_array.stride != 0)
- memcpy(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
+ memcpy_neon(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr += tex_unit->vertex_array.stride;
ptr_clr += tex_unit->color_array.stride;
}
@@ -1686,7 +1773,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
- memcpy(indices, gl_indices, sizeof(uint16_t) * count);
+ memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
}
int n = 0, j = 0;
uint64_t vertex_count_int = 0;
@@ -1702,14 +1789,14 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f));
colors = (vector4f *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size);
if ((!vertex_array_unit) && tex_unit->vertex_array.stride == 0)
- memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
+ memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
uint8_t *ptr = ((uint8_t *)tex_unit->vertex_array.pointer);
for (n = 0; n < vertex_count_int; n++) {
if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0)
- memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
- memcpy(&colors[n], ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
+ memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f));
if (!vertex_array_unit)
ptr += tex_unit->vertex_array.stride;
}
@@ -1734,7 +1821,7 @@ void glEnableClientState(GLenum array) {
tex_unit->texture_array_state = GL_TRUE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
@@ -1752,16 +1839,16 @@ void glDisableClientState(GLenum array) {
tex_unit->texture_array_state = GL_FALSE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
void glClientActiveTexture(GLenum texture) {
#ifndef SKIP_ERROR_HANDLING
- if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31))
- vgl_error = GL_INVALID_ENUM;
- else
+ if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) {
+ SET_GL_ERROR(GL_INVALID_ENUM)
+ } else
#endif
client_texture_unit = texture - GL_TEXTURE0;
}
@@ -1771,8 +1858,7 @@ void glClientActiveTexture(GLenum texture) {
void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1785,18 +1871,18 @@ void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, con
bpe = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
tex_unit->vertex_object = gpu_pool_memalign(count * bpe * size, bpe * size);
if (stride == 0)
- memcpy(tex_unit->vertex_object, pointer, count * bpe * size);
+ memcpy_neon(tex_unit->vertex_object, pointer, count * bpe * size);
else {
int i;
uint8_t *dst = (uint8_t *)tex_unit->vertex_object;
uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) {
- memcpy(dst, src, bpe * size);
+ memcpy_neon(dst, src, bpe * size);
dst += (bpe * size);
src += stride;
}
@@ -1806,8 +1892,7 @@ void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, con
void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 3) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1823,19 +1908,19 @@ void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, cons
bpe = sizeof(uint8_t);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
tex_unit->color_object = gpu_pool_memalign(count * bpe * size, bpe * size);
tex_unit->color_object_type = type;
if (stride == 0)
- memcpy(tex_unit->color_object, pointer, count * bpe * size);
+ memcpy_neon(tex_unit->color_object, pointer, count * bpe * size);
else {
int i;
uint8_t *dst = (uint8_t *)tex_unit->color_object;
uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) {
- memcpy(dst, src, bpe * size);
+ memcpy_neon(dst, src, bpe * size);
dst += (bpe * size);
src += stride;
}
@@ -1845,8 +1930,7 @@ void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, cons
void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1859,18 +1943,18 @@ void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, c
bpe = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
tex_unit->texture_object = gpu_pool_memalign(count * bpe * size, bpe * size);
if (stride == 0)
- memcpy(tex_unit->texture_object, pointer, count * bpe * size);
+ memcpy_neon(tex_unit->texture_object, pointer, count * bpe * size);
else {
int i;
uint8_t *dst = (uint8_t *)tex_unit->texture_object;
uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) {
- memcpy(dst, src, bpe * size);
+ memcpy_neon(dst, src, bpe * size);
dst += (bpe * size);
src += stride;
}
@@ -1880,8 +1964,7 @@ void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, c
void vglIndexPointer(GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING
if (stride < 0) {
- vgl_error = GL_INVALID_VALUE;
- return;
+ SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
texture_unit *tex_unit = &texture_units[client_texture_unit];
@@ -1894,18 +1977,18 @@ void vglIndexPointer(GLenum type, GLsizei stride, GLuint count, const GLvoid *po
bpe = sizeof(GLshort);
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
tex_unit->index_object = gpu_pool_memalign(count * bpe, bpe);
if (stride == 0)
- memcpy(tex_unit->index_object, pointer, count * bpe);
+ memcpy_neon(tex_unit->index_object, pointer, count * bpe);
else {
int i;
uint8_t *dst = (uint8_t *)tex_unit->index_object;
uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) {
- memcpy(dst, src, bpe);
+ memcpy_neon(dst, src, bpe);
dst += bpe;
src += stride;
}
@@ -1938,10 +2021,11 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
texture_unit *tex_unit = &texture_units[client_texture_unit];
int texture2d_idx = tex_unit->tex_id;
#ifndef SKIP_ERROR_HANDLING
- if (phase == MODEL_CREATION)
- vgl_error = GL_INVALID_OPERATION;
- else if (count < 0)
- vgl_error = GL_INVALID_VALUE;
+ if (phase == MODEL_CREATION) {
+ SET_GL_ERROR(GL_INVALID_OPERATION)
+ } else if (count < 0) {
+ SET_GL_ERROR(GL_INVALID_VALUE)
+ }
#endif
GLboolean skip_draw = GL_FALSE;
switch (mode) {
@@ -1967,7 +2051,7 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
skip_draw = GL_TRUE;
break;
default:
- vgl_error = GL_INVALID_ENUM;
+ SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
if (!skip_draw) {
@@ -2074,7 +2158,7 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
vector4f *colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f));
int n;
for (n = 0; n < count; n++) {
- memcpy(&colors[n], ¤t_color.r, sizeof(vector4f));
+ memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f));
}
sceGxmSetVertexStream(gxm_context, 0, tex_unit->vertex_object);
sceGxmSetVertexStream(gxm_context, 1, colors);
diff --git a/deps/vitaGL/source/vitaGL.h b/deps/vitaGL/source/vitaGL.h
index fd252b844d..4072661241 100644
--- a/deps/vitaGL/source/vitaGL.h
+++ b/deps/vitaGL/source/vitaGL.h
@@ -24,20 +24,32 @@ extern "C" {
#endif
#include
+#ifdef HAVE_SHARK
+#include
+#endif
// clang-format off
-#define GLfloat float
-#define GLint int32_t
-#define GLdouble double
-#define GLshort int16_t
-#define GLuint uint32_t
-#define GLsizei int32_t
-#define GLenum uint16_t
-#define GLubyte uint8_t
-#define GLvoid void
-#define GLbyte int8_t
#define GLboolean uint8_t
+#define GLbyte int8_t
+#define GLubyte uint8_t
#define GLchar char
+#define GLshort int16_t
+#define GLushort uint16_t
+#define GLint int32_t
+#define GLuint uint32_t
+#define GLfixed int32_t
+#define GLint64 int64_t
+#define GLuint64 uint64_t
+#define GLsizei int32_t
+#define GLenum uint32_t
+#define GLintptr int32_t
+#define GLsizeiptr uint32_t
+#define GLsync int32_t
+#define GLfloat float
+#define GLclampf float
+#define GLdouble double
+#define GLclampd double
+#define GLvoid void
#define GL_FALSE 0
#define GL_TRUE 1
@@ -47,6 +59,8 @@ extern "C" {
#define GL_ZERO 0
#define GL_ONE 1
+#define GL_NONE 0
+
#define GL_POINTS 0x0000
#define GL_LINES 0x0001
#define GL_LINE_LOOP 0x0002
@@ -108,6 +122,8 @@ extern "C" {
#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
+#define GL_DEPTH_BITS 0x0D56
+#define GL_STENCIL_BITS 0x0D57
#define GL_TEXTURE_2D 0x0DE1
#define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401
@@ -218,6 +234,7 @@ extern "C" {
#define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF
#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_TEXTURE_LOD_BIAS 0x8501
#define GL_INCR_WRAP 0x8507
#define GL_MIRROR_CLAMP_EXT 0x8742
#define GL_DECR_WRAP 0x8508
@@ -234,12 +251,15 @@ extern "C" {
#define GL_DYNAMIC_COPY 0x88EA
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_COMPILE_STATUS 0x8B81
#define GL_READ_FRAMEBUFFER 0x8CA8
#define GL_DRAW_FRAMEBUFFER 0x8CA9
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_FRAMEBUFFER 0x8D40
-#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 32
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 32
+#define GL_MAX_TEXTURE_LOD_BIAS 31
// Aliases
#define GL_CLAMP GL_CLAMP_TO_EDGE
@@ -282,6 +302,7 @@ void glColor4ubv(const GLubyte *v);
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *data);
+void glCompileShader(GLuint shader);
GLuint glCreateProgram(void);
GLuint glCreateShader(GLenum shaderType);
void glCullFace(GLenum mode);
@@ -316,6 +337,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params);
void glGetFloatv(GLenum pname, GLfloat *data);
GLenum glGetError(void);
void glGetIntegerv(GLenum pname, GLint *data);
+void glGetShaderiv(GLuint handle, GLenum pname, GLint *params);
const GLubyte *glGetString(GLenum name);
GLint glGetUniformLocation(GLuint prog, const GLchar *name);
GLboolean glIsEnabled(GLenum cap);
@@ -336,6 +358,7 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
void glScalef(GLfloat x, GLfloat y, GLfloat z);
void glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length); // NOTE: Uses GXP shaders
+void glShaderSource(GLuint handle, GLsizei count, const GLchar * const *string, const GLint *length); // NOTE: Uses CG shader sources
void glStencilFunc(GLenum func, GLint ref, GLuint mask);
void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
void glStencilMask(GLuint mask);
@@ -357,6 +380,8 @@ void glTranslatef(GLfloat x, GLfloat y, GLfloat z);
void glUniform1f(GLint location, GLfloat v0);
void glUniform1i(GLint location, GLint v0);
void glUniform2fv(GLint location, GLsizei count, const GLfloat *value);
+void glUniform3fv(GLint location, GLsizei count, const GLfloat *value);
+void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value);
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void glUseProgram(GLuint program);
@@ -366,6 +391,9 @@ void glVertex3fv(const GLfloat *v);
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
+// glu*
+void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
+
// VGL_EXT_gpu_objects_array extension
void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer);
void vglColorPointerMapped(GLenum type, const GLvoid *pointer);
@@ -394,12 +422,15 @@ typedef enum {
// vgl*
void *vglAlloc(uint32_t size, vglMemType type);
+void vglEnableRuntimeShaderCompiler(GLboolean usage);
void vglEnd(void);
void vglFree(void *addr);
void *vglGetTexDataPointer(GLenum target);
void vglInit(uint32_t gpu_pool_size);
void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa);
+void vglInitWithCustomSizes(uint32_t gpu_pool_size, int width, int height, int ram_pool_size, int cdram_pool_size, int phycont_pool_size, SceGxmMultisampleMode msaa);
size_t vglMemFree(vglMemType type);
+void vglSetParamBufferSize(uint32_t size);
void vglStartRendering();
void vglStopRendering();
void vglStopRenderingInit();
@@ -410,6 +441,9 @@ void vglUseVramForUSSE(GLboolean usage);
void vglUseExtraMem(GLboolean usage);
void vglWaitVblankStart(GLboolean enable);
+// NEON optimized memcpy
+void *memcpy_neon(void *destination, const void *source, size_t num);
+
#ifdef __cplusplus
}
#endif
diff --git a/deps/vitaShaRK/.gitattributes b/deps/vitaShaRK/.gitattributes
new file mode 100644
index 0000000000..dfe0770424
--- /dev/null
+++ b/deps/vitaShaRK/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/deps/vitaShaRK/.github/FUNDING.yml b/deps/vitaShaRK/.github/FUNDING.yml
new file mode 100644
index 0000000000..dbd470e946
--- /dev/null
+++ b/deps/vitaShaRK/.github/FUNDING.yml
@@ -0,0 +1 @@
+patreon: Rinnegatamante
diff --git a/deps/vitaShaRK/.gitignore b/deps/vitaShaRK/.gitignore
new file mode 100644
index 0000000000..4a072bdd8b
--- /dev/null
+++ b/deps/vitaShaRK/.gitignore
@@ -0,0 +1,59 @@
+*.vpk
+*.elf
+*.velf
+*.bin
+*.sfo
+*.S
+*.wo
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+# =========================
+# Operating System Files
+# =========================
+
+# OSX
+# =========================
+
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+# Vita build stuffs
+*.a
+*.o
diff --git a/deps/vitaShaRK/LICENSE b/deps/vitaShaRK/LICENSE
new file mode 100644
index 0000000000..8805d0dfad
--- /dev/null
+++ b/deps/vitaShaRK/LICENSE
@@ -0,0 +1,165 @@
+GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/deps/vitaShaRK/Makefile b/deps/vitaShaRK/Makefile
new file mode 100644
index 0000000000..58ce7401e2
--- /dev/null
+++ b/deps/vitaShaRK/Makefile
@@ -0,0 +1,37 @@
+TARGET := libvitashark
+SOURCES := source
+SHADERS := shaders
+
+CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
+ASMFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S))
+CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg))
+HEADERS := $(CGFILES:.cg=.h)
+OBJS := $(CFILES:.c=.o) $(ASMFILES:.S=.o)
+
+PREFIX = arm-vita-eabi
+CC = $(PREFIX)-gcc
+AR = $(PREFIX)-gcc-ar
+CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -ftree-vectorize
+ASFLAGS = $(CFLAGS)
+
+all: $(TARGET).a
+
+$(TARGET).a: $(OBJS)
+ $(AR) -rc $@ $^
+
+clean:
+ @rm -rf $(TARGET).a $(TARGET).elf $(OBJS)
+ @make -C samples/sample1 clean
+ @make -C samples/sample2 clean
+
+install: $(TARGET).a
+ @mkdir -p $(VITASDK)/$(PREFIX)/lib/
+ cp $(TARGET).a $(VITASDK)/$(PREFIX)/lib/
+ @mkdir -p $(VITASDK)/$(PREFIX)/include/
+ cp source/vitashark.h $(VITASDK)/$(PREFIX)/include/
+
+samples: $(TARGET).a
+ @make -C samples/sample1
+ cp "samples/sample1/vitaShaRK-Sample001.vpk" .
+ @make -C samples/sample2
+ cp "samples/sample1/vitaShaRK-Sample002.vpk" .
diff --git a/deps/vitaShaRK/README.md b/deps/vitaShaRK/README.md
new file mode 100644
index 0000000000..53d4cd9d4b
--- /dev/null
+++ b/deps/vitaShaRK/README.md
@@ -0,0 +1,18 @@
+# vitaShaRK
+**vita** **Sha**ders **R**untime **K**ompiler is a runtime shader compiler library for PSVITA/PSTV using the SceShaccCg module contained inside the PSM runtime.
+
+# Build Instructions
+In order to build vitaShaRK, you'll first need to build SceShaccCg stubs. This is a full list of commands you can use to install this library and the required stubs:
+```
+vita-libs-gen SceShaccCg.yml build
+cd build
+make install
+cd ..
+cp shacccg.h $VITASDK/arm-vita-eabi/psp2/shacccg.h
+make install
+```
+
+
+# Credits
+
+**frangarcj** for the original vita2d shader compiler source used as base to build up this library.
diff --git a/deps/vitaShaRK/SceShaccCg.yml b/deps/vitaShaRK/SceShaccCg.yml
new file mode 100644
index 0000000000..d20eae44a5
--- /dev/null
+++ b/deps/vitaShaRK/SceShaccCg.yml
@@ -0,0 +1,43 @@
+version: 2
+firmware: 3.60
+modules:
+ SceShaccCg:
+ nid: 0xB3B90A35
+ libraries:
+ SceShaccCg:
+ kernel: false
+ nid: 0xA05BBEBB
+ functions:
+ SceShaccCg_0205DE96: 0x0205DE96
+ SceShaccCg_07DDFC78: 0x07DDFC78
+ SceShaccCg_0E1285A6: 0x0E1285A6
+ SceShaccCg_152971B1: 0x152971B1
+ SceShaccCg_17223BEB: 0x17223BEB
+ SceShaccCg_2654E73A: 0x2654E73A
+ SceShaccCg_268FAEE9: 0x268FAEE9
+ sceShaccCgInitializeCompileOptions: 0x3B58AFA0
+ SceShaccCg_4595A388: 0x4595A388
+ SceShaccCg_46FA0303: 0x46FA0303
+ SceShaccCg_56BFA825: 0x56BFA825
+ SceShaccCg_648739F3: 0x648739F3
+ sceShaccCgCompileProgram: 0x66814F35
+ SceShaccCg_6BB58825: 0x6BB58825
+ sceShaccCgSetDefaultAllocator: 0x6F01D573
+ SceShaccCg_6FB40CA9: 0x6FB40CA9
+ SceShaccCg_7B2CF324: 0x7B2CF324
+ SceShaccCg_7BC25091: 0x7BC25091
+ SceShaccCg_7F430CCD: 0x7F430CCD
+ SceShaccCg_95F57A23: 0x95F57A23
+ SceShaccCg_A067C481: 0xA067C481
+ SceShaccCg_A13A8A1E: 0xA13A8A1E
+ SceShaccCg_A56B1A5B: 0xA56B1A5B
+ SceShaccCg_A7930FF6: 0xA7930FF6
+ sceShaccCgInitializeCallbackList: 0xA8C2C1C8
+ sceShaccCgDestroyCompileOutput: 0xAA82EF0C
+ SceShaccCg_B4AC9943: 0xB4AC9943
+ SceShaccCg_BB703EE1: 0xBB703EE1
+ SceShaccCg_D4378DB1: 0xD4378DB1
+ SceShaccCg_DAD4AAE4: 0xDAD4AAE4
+ SceShaccCg_DF3DDCFD: 0xDF3DDCFD
+ SceShaccCg_EF8D59D6: 0xEF8D59D6
+ SceShaccCg_F4BAB902: 0xF4BAB902
diff --git a/deps/vitaShaRK/SceShaccCg/Makefile b/deps/vitaShaRK/SceShaccCg/Makefile
new file mode 100644
index 0000000000..495b32a861
--- /dev/null
+++ b/deps/vitaShaRK/SceShaccCg/Makefile
@@ -0,0 +1,47 @@
+ifdef VITASDK
+PREFIX = $(VITASDK)/bin/
+endif
+
+ARCH ?= $(PREFIX)arm-vita-eabi
+AS = $(ARCH)-as
+AR = $(ARCH)-ar
+RANLIB = $(ARCH)-ranlib
+
+TARGETS = libSceShaccCg_stub.a
+TARGETS_WEAK = libSceShaccCg_stub_weak.a
+
+SceShaccCg_OBJS = SceShaccCg_SceShaccCg_SceShaccCg_0205DE96.o SceShaccCg_SceShaccCg_SceShaccCg_07DDFC78.o SceShaccCg_SceShaccCg_SceShaccCg_0E1285A6.o SceShaccCg_SceShaccCg_SceShaccCg_152971B1.o SceShaccCg_SceShaccCg_SceShaccCg_17223BEB.o SceShaccCg_SceShaccCg_SceShaccCg_2654E73A.o SceShaccCg_SceShaccCg_SceShaccCg_268FAEE9.o SceShaccCg_SceShaccCg_sceShaccCgInitializeCompileOptions.o SceShaccCg_SceShaccCg_SceShaccCg_4595A388.o SceShaccCg_SceShaccCg_SceShaccCg_46FA0303.o SceShaccCg_SceShaccCg_SceShaccCg_56BFA825.o SceShaccCg_SceShaccCg_SceShaccCg_648739F3.o SceShaccCg_SceShaccCg_sceShaccCgCompileProgram.o SceShaccCg_SceShaccCg_SceShaccCg_6BB58825.o SceShaccCg_SceShaccCg_sceShaccCgSetDefaultAllocator.o SceShaccCg_SceShaccCg_SceShaccCg_6FB40CA9.o SceShaccCg_SceShaccCg_SceShaccCg_7B2CF324.o SceShaccCg_SceShaccCg_SceShaccCg_7BC25091.o SceShaccCg_SceShaccCg_SceShaccCg_7F430CCD.o SceShaccCg_SceShaccCg_SceShaccCg_95F57A23.o SceShaccCg_SceShaccCg_SceShaccCg_A067C481.o SceShaccCg_SceShaccCg_SceShaccCg_A13A8A1E.o SceShaccCg_SceShaccCg_SceShaccCg_A56B1A5B.o SceShaccCg_SceShaccCg_SceShaccCg_A7930FF6.o SceShaccCg_SceShaccCg_sceShaccCgInitializeCallbackList.o SceShaccCg_SceShaccCg_sceShaccCgDestroyCompileOutput.o SceShaccCg_SceShaccCg_SceShaccCg_B4AC9943.o SceShaccCg_SceShaccCg_SceShaccCg_BB703EE1.o SceShaccCg_SceShaccCg_SceShaccCg_D4378DB1.o SceShaccCg_SceShaccCg_SceShaccCg_DAD4AAE4.o SceShaccCg_SceShaccCg_SceShaccCg_DF3DDCFD.o SceShaccCg_SceShaccCg_SceShaccCg_EF8D59D6.o SceShaccCg_SceShaccCg_SceShaccCg_F4BAB902.o
+SceShaccCg_weak_OBJS = SceShaccCg_SceShaccCg_SceShaccCg_0205DE96.wo SceShaccCg_SceShaccCg_SceShaccCg_07DDFC78.wo SceShaccCg_SceShaccCg_SceShaccCg_0E1285A6.wo SceShaccCg_SceShaccCg_SceShaccCg_152971B1.wo SceShaccCg_SceShaccCg_SceShaccCg_17223BEB.wo SceShaccCg_SceShaccCg_SceShaccCg_2654E73A.wo SceShaccCg_SceShaccCg_SceShaccCg_268FAEE9.wo SceShaccCg_SceShaccCg_sceShaccCgInitializeCompileOptions.wo SceShaccCg_SceShaccCg_SceShaccCg_4595A388.wo SceShaccCg_SceShaccCg_SceShaccCg_46FA0303.wo SceShaccCg_SceShaccCg_SceShaccCg_56BFA825.wo SceShaccCg_SceShaccCg_SceShaccCg_648739F3.wo SceShaccCg_SceShaccCg_sceShaccCgCompileProgram.wo SceShaccCg_SceShaccCg_SceShaccCg_6BB58825.wo SceShaccCg_SceShaccCg_sceShaccCgSetDefaultAllocator.wo SceShaccCg_SceShaccCg_SceShaccCg_6FB40CA9.wo SceShaccCg_SceShaccCg_SceShaccCg_7B2CF324.wo SceShaccCg_SceShaccCg_SceShaccCg_7BC25091.wo SceShaccCg_SceShaccCg_SceShaccCg_7F430CCD.wo SceShaccCg_SceShaccCg_SceShaccCg_95F57A23.wo SceShaccCg_SceShaccCg_SceShaccCg_A067C481.wo SceShaccCg_SceShaccCg_SceShaccCg_A13A8A1E.wo SceShaccCg_SceShaccCg_SceShaccCg_A56B1A5B.wo SceShaccCg_SceShaccCg_SceShaccCg_A7930FF6.wo SceShaccCg_SceShaccCg_sceShaccCgInitializeCallbackList.wo SceShaccCg_SceShaccCg_sceShaccCgDestroyCompileOutput.wo SceShaccCg_SceShaccCg_SceShaccCg_B4AC9943.wo SceShaccCg_SceShaccCg_SceShaccCg_BB703EE1.wo SceShaccCg_SceShaccCg_SceShaccCg_D4378DB1.wo SceShaccCg_SceShaccCg_SceShaccCg_DAD4AAE4.wo SceShaccCg_SceShaccCg_SceShaccCg_DF3DDCFD.wo SceShaccCg_SceShaccCg_SceShaccCg_EF8D59D6.wo SceShaccCg_SceShaccCg_SceShaccCg_F4BAB902.wo
+SceKernel_OBJS =
+ALL_OBJS=
+
+all: $(TARGETS) $(TARGETS_WEAK)
+
+define LIBRARY_template
+ $(1): $$($(1:lib%_stub.a=%)_OBJS)
+ ALL_OBJS += $$($(1:lib%_stub.a=%)_OBJS)
+endef
+define LIBRARY_WEAK_template
+ $(1): $$($(1:lib%_stub_weak.a=%)_weak_OBJS)
+ ALL_OBJS += $$($(1:lib%_stub_weak.a=%)_weak_OBJS)
+endef
+
+$(foreach library,$(TARGETS),$(eval $(call LIBRARY_template,$(library))))
+$(foreach library,$(TARGETS_WEAK),$(eval $(call LIBRARY_WEAK_template,$(library))))
+
+install: $(TARGETS) $(TARGETS_WEAK)
+ cp $(TARGETS) $(VITASDK)/arm-vita-eabi/lib
+ cp $(TARGETS_WEAK) $(VITASDK)/arm-vita-eabi/lib
+
+clean:
+ rm -f $(TARGETS) $(TARGETS_WEAK) $(ALL_OBJS)
+
+$(TARGETS) $(TARGETS_WEAK):
+ $(AR) cru $@ $?
+ $(RANLIB) $@
+
+%.o: %.S
+ $(AS) --defsym GEN_WEAK_EXPORTS=0 $< -o $@
+
+%.wo: %.S
+ $(AS) --defsym GEN_WEAK_EXPORTS=1 $< -o $@
diff --git a/deps/vitaShaRK/include/shacccg.h b/deps/vitaShaRK/include/shacccg.h
new file mode 100644
index 0000000000..aa9f6f06eb
--- /dev/null
+++ b/deps/vitaShaRK/include/shacccg.h
@@ -0,0 +1,185 @@
+#ifndef _PSP2_SHACCCG_H
+#define _PSP2_SHACCCG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif // def __cplusplus
+
+typedef struct SceShaccCgCompileOptions SceShaccCgCompileOptions;
+typedef struct SceShaccCgSourceFile SceShaccCgSourceFile;
+typedef struct SceShaccCgSourceLocation SceShaccCgSourceLocation;
+typedef void const *SceShaccCgParameter;
+
+typedef SceShaccCgSourceFile* (*SceShaccCgCallbackOpenFile)(
+ const char *fileName,
+ const SceShaccCgSourceLocation *includedFrom,
+ const SceShaccCgCompileOptions *compileOptions,
+ const char **errorString);
+
+typedef void (*SceShaccCgCallbackReleaseFile)(
+ const SceShaccCgSourceFile *file,
+ const SceShaccCgCompileOptions *compileOptions);
+
+typedef const char* (*SceShaccCgCallbackLocateFile)(
+ const char *fileName,
+ const SceShaccCgSourceLocation *includedFrom,
+ uint32_t searchPathCount,
+ const char *const*searchPaths,
+ const SceShaccCgCompileOptions *compileOptions,
+ const char **errorString);
+
+typedef const char* (*SceShaccCgCallbackAbsolutePath)(
+ const char *fileName,
+ const SceShaccCgSourceLocation *includedFrom,
+ const SceShaccCgCompileOptions *compileOptions);
+
+typedef void (*SceShaccCgCallbackReleaseFileName)(
+ const char *fileName,
+ const SceShaccCgCompileOptions *compileOptions);
+
+typedef int32_t (*SceShaccCgCallbackFileDate)(
+ const SceShaccCgSourceFile *file,
+ const SceShaccCgSourceLocation *includedFrom,
+ const SceShaccCgCompileOptions *compileOptions,
+ int64_t *timeLastStatusChange,
+ int64_t *timeLastModified);
+
+typedef enum SceShaccCgDiagnosticLevel {
+ SCE_SHACCCG_DIAGNOSTIC_LEVEL_INFO,
+ SCE_SHACCCG_DIAGNOSTIC_LEVEL_WARNING,
+ SCE_SHACCCG_DIAGNOSTIC_LEVEL_ERROR
+} SceShaccCgDiagnosticLevel;
+
+typedef enum SceShaccCgTargetProfile {
+ SCE_SHACCCG_PROFILE_VP,
+ SCE_SHACCCG_PROFILE_FP
+} SceShaccCgTargetProfile;
+
+typedef enum SceShaccCgCallbackDefaults {
+ SCE_SHACCCG_SYSTEM_FILES,
+ SCE_SHACCCG_TRIVIAL
+} SceShaccCgCallbackDefaults;
+
+typedef enum SceShaccCgLocale {
+ SCE_SHACCCG_ENGLISH,
+ SCE_SHACCCG_JAPANESE
+} SceShaccCgLocale;
+
+typedef struct SceShaccCgSourceFile {
+ const char *fileName;
+ const char *text;
+ uint32_t size;
+} SceShaccCgSourceFile;
+
+typedef struct SceShaccCgSourceLocation {
+ const SceShaccCgSourceFile *file;
+ uint32_t lineNumber;
+ uint32_t columnNumber;
+} SceShaccCgSourceLocation;
+
+typedef struct SceShaccCgCallbackList {
+ SceShaccCgCallbackOpenFile openFile;
+ SceShaccCgCallbackReleaseFile releaseFile;
+ SceShaccCgCallbackLocateFile locateFile;
+ SceShaccCgCallbackAbsolutePath absolutePath;
+ SceShaccCgCallbackReleaseFileName releaseFileName;
+ SceShaccCgCallbackFileDate fileDate;
+} SceShaccCgCallbackList;
+
+typedef struct SceShaccCgCompileOptions {
+ const char *mainSourceFile;
+ SceShaccCgTargetProfile targetProfile;
+ const char *entryFunctionName;
+ uint32_t searchPathCount;
+ const char* const *searchPaths;
+ uint32_t macroDefinitionCount;
+ const char* const *macroDefinitions;
+ uint32_t includeFileCount;
+ const char* const *includeFiles;
+ uint32_t suppressedWarningsCount;
+ const uint32_t *suppressedWarnings;
+ SceShaccCgLocale locale;
+ int32_t useFx;
+ int32_t noStdlib;
+ int32_t optimizationLevel;
+ int32_t useFastmath;
+ int32_t useFastprecision;
+ int32_t useFastint;
+ int32_t warningsAsErrors;
+ int32_t performanceWarnings;
+ int32_t warningLevel;
+ int32_t pedantic;
+ int32_t pedanticError;
+ int field_5C;
+ int field_60;
+ int field_64;
+} SceShaccCgCompileOptions;
+
+typedef struct SceShaccCgDiagnosticMessage {
+ SceShaccCgDiagnosticLevel level;
+ uint32_t code;
+ const SceShaccCgSourceLocation *location;
+ const char *message;
+} SceShaccCgDiagnosticMessage;
+
+typedef struct SceShaccCgCompileOutput {
+ const uint8_t *programData;
+ uint32_t programSize;
+ int32_t diagnosticCount;
+ const SceShaccCgDiagnosticMessage *diagnostics;
+} SceShaccCgCompileOutput;
+
+
+int SceShaccCg_0205DE96(int);
+int SceShaccCg_07DDFC78(int);
+int SceShaccCg_0E1285A6(int);
+int SceShaccCg_152971B1(int);
+int SceShaccCg_17223BEB(int);
+int SceShaccCg_2654E73A(int);
+int SceShaccCg_268FAEE9(int);
+
+int sceShaccCgInitializeCompileOptions(
+ SceShaccCgCompileOptions *options);
+
+int SceShaccCg_4595A388(int);
+int SceShaccCg_46FA0303(int);
+int SceShaccCg_56BFA825(int);
+int SceShaccCg_648739F3(int);
+
+SceShaccCgCompileOutput const *sceShaccCgCompileProgram(
+ const SceShaccCgCompileOptions *options,
+ const SceShaccCgCallbackList *callbacks,
+ int unk);
+
+int SceShaccCg_6BB58825(int);
+int sceShaccCgSetDefaultAllocator(void *(*malloc_cb)(unsigned int), void (*free_cb)(void *));
+int SceShaccCg_6FB40CA9(int);
+int SceShaccCg_7B2CF324(int);
+int SceShaccCg_7BC25091(int);
+int SceShaccCg_7F430CCD(int);
+int SceShaccCg_95F57A23(int);
+int SceShaccCg_A067C481(int);
+int SceShaccCg_A13A8A1E(int);
+int SceShaccCg_A56B1A5B(int);
+int SceShaccCg_A7930FF6(int);
+
+void sceShaccCgInitializeCallbackList(
+ SceShaccCgCallbackList *callbacks,
+ SceShaccCgCallbackDefaults defaults);
+
+void sceShaccCgDestroyCompileOutput(
+ SceShaccCgCompileOutput const *output);
+
+int SceShaccCg_B4AC9943(int);
+int SceShaccCg_BB703EE1(int);
+int SceShaccCg_D4378DB1(int);
+int SceShaccCg_DAD4AAE4(int);
+int SceShaccCg_DF3DDCFD(int);
+int SceShaccCg_EF8D59D6(int);
+int SceShaccCg_F4BAB902(int);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _PSP2_SHACCCG_H */
diff --git a/deps/vitaShaRK/samples/sample1/Makefile b/deps/vitaShaRK/samples/sample1/Makefile
new file mode 100644
index 0000000000..0202cf37cc
--- /dev/null
+++ b/deps/vitaShaRK/samples/sample1/Makefile
@@ -0,0 +1,37 @@
+SAMPLE_NUM := 001
+TARGET := vitaShaRK-Sample$(SAMPLE_NUM)
+SOURCES := .
+
+INCLUDES := include
+
+LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub
+
+CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
+CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
+BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
+OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
+
+PREFIX = arm-vita-eabi
+CC = $(PREFIX)-gcc
+CXX = $(PREFIX)-g++
+CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
+CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
+ASFLAGS = $(CFLAGS)
+
+all: $(TARGET).vpk
+
+$(TARGET).vpk: eboot.bin
+ vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo
+ vita-pack-vpk -s param.sfo -b eboot.bin $@
+
+eboot.bin: $(TARGET).velf
+ vita-make-fself -s $< eboot.bin
+
+%.velf: %.elf
+ vita-elf-create $< $@
+
+$(TARGET).elf: $(OBJS)
+ $(CC) $(CFLAGS) $^ $(LIBS) -o $@
+
+clean:
+ @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin
diff --git a/deps/vitaShaRK/samples/sample1/main.c b/deps/vitaShaRK/samples/sample1/main.c
new file mode 100644
index 0000000000..1e312c51a7
--- /dev/null
+++ b/deps/vitaShaRK/samples/sample1/main.c
@@ -0,0 +1,59 @@
+// Simple compiler with no logging
+
+#include
+#include
+#include
+
+const char fragment_shader[] =
+ "float4 main(uniform float4 u_clear_color) : COLOR\n"
+ "{\n"
+ " return u_clear_color;\n"
+ "}"
+ ;
+
+const char vertex_shader[] =
+ "void main(\n"
+ "float3 aPosition,\n"
+ "float3 aColor,\n"
+ "uniform float4x4 wvp,\n"
+ "float4 out vPosition: POSITION,\n"
+ "float4 out vColor: COLOR)\n"
+ "{\n"
+ " vPosition = mul(float4(aPosition, 1.f), wvp);\n"
+ " vColor = float4(aColor, 1.f);\n"
+ "}"
+ ;
+
+void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) {
+ FILE *f = fopen(fname, "wb");
+ fwrite(p, 1, size, f);
+ fclose(f);
+}
+
+int main() {
+ // Initializing vitaShaRK
+ if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data
+ return -1;
+
+ // Compiling fragment shader
+ uint32_t size = sizeof(fragment_shader) - 1;
+ SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER);
+
+ // Saving compiled GXP file on SD
+ if (p) saveGXP(p, size, "ux0:data/clear_f.gxp");
+
+ shark_clear_output();
+
+ // Compiling vertex shader
+ size = sizeof(vertex_shader) - 1;
+ p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER);
+
+ // Saving compiled GXP file on SD
+ if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp");
+
+ shark_clear_output();
+
+ shark_end();
+
+ return 0;
+}
diff --git a/deps/vitaShaRK/samples/sample2/Makefile b/deps/vitaShaRK/samples/sample2/Makefile
new file mode 100644
index 0000000000..e41643545a
--- /dev/null
+++ b/deps/vitaShaRK/samples/sample2/Makefile
@@ -0,0 +1,37 @@
+SAMPLE_NUM := 002
+TARGET := vitaShaRK-Sample$(SAMPLE_NUM)
+SOURCES := .
+
+INCLUDES := include
+
+LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub
+
+CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
+CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
+BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
+OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
+
+PREFIX = arm-vita-eabi
+CC = $(PREFIX)-gcc
+CXX = $(PREFIX)-g++
+CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
+CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
+ASFLAGS = $(CFLAGS)
+
+all: $(TARGET).vpk
+
+$(TARGET).vpk: eboot.bin
+ vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo
+ vita-pack-vpk -s param.sfo -b eboot.bin $@
+
+eboot.bin: $(TARGET).velf
+ vita-make-fself -s $< eboot.bin
+
+%.velf: %.elf
+ vita-elf-create $< $@
+
+$(TARGET).elf: $(OBJS)
+ $(CC) $(CFLAGS) $^ $(LIBS) -o $@
+
+clean:
+ @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin
diff --git a/deps/vitaShaRK/samples/sample2/main.c b/deps/vitaShaRK/samples/sample2/main.c
new file mode 100644
index 0000000000..0d585e0201
--- /dev/null
+++ b/deps/vitaShaRK/samples/sample2/main.c
@@ -0,0 +1,85 @@
+// Simple compiler with file logging
+
+#include
+#include
+#include
+
+const char fragment_shader[] =
+ "float4 main(uniform float4 u_clear_color) : COLOR\n"
+ "{\n"
+ " return u_clear_color;\n"
+ "}"
+ ;
+
+const char vertex_shader[] =
+ "void main(\n"
+ "float3 aPosition,\n"
+ "float3 aColor,\n"
+ "uniform float4x4 wvp,\n"
+ "float4 out vPosition: POSITION,\n"
+ "float4 out vColor: COLOR)\n"
+ "{\n"
+ " vPosition = mul(float4(aPosition, 1.f), wvp);\n"
+ " vColor = float4(aColor, 1.f);\n"
+ "}"
+ ;
+
+char curr_compilation[256];
+
+void log_cb(const char *msg, shark_log_level msg_level, int line) {
+ FILE *f = fopen("ux0:/data/shark.log", "a+");
+ switch (msg_level) {
+ case SHARK_LOG_INFO:
+ fprintf(f, "%s) INFO: %s at line %d\n", curr_compilation, msg, line);
+ break;
+ case SHARK_LOG_WARNING:
+ fprintf(f, "%s) WARNING: %s at line %d\n", curr_compilation, msg, line);
+ break;
+ case SHARK_LOG_ERROR:
+ fprintf(f, "%s) ERROR: %s at line %d\n", curr_compilation, msg, line);
+ break;
+ default:
+ break;
+ }
+ fclose(f);
+}
+
+void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) {
+ FILE *f = fopen(fname, "wb");
+ fwrite(p, 1, size, f);
+ fclose(f);
+}
+
+int main() {
+ // Initializing vitaShaRK
+ if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data
+ return -1;
+
+ // Setting up logger
+ shark_install_log_cb(log_cb);
+ shark_set_warnings_level(SHARK_WARN_MAX);
+
+ // Compiling fragment shader
+ sprintf(curr_compilation, "clear_f.gxp");
+ uint32_t size = sizeof(fragment_shader) - 1;
+ SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER);
+
+ // Saving compiled GXP file on SD
+ if (p) saveGXP(p, size, "ux0:data/clear_f.gxp");
+
+ shark_clear_output();
+
+ // Compiling vertex shader
+ sprintf(curr_compilation, "rgb_v.gxp");
+ size = sizeof(vertex_shader) - 1;
+ p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER);
+
+ // Saving compiled GXP file on SD
+ if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp");
+
+ shark_clear_output();
+
+ shark_end();
+
+ return 0;
+}
diff --git a/deps/vitaShaRK/source/vitashark.c b/deps/vitaShaRK/source/vitashark.c
new file mode 100644
index 0000000000..96a6c719aa
--- /dev/null
+++ b/deps/vitaShaRK/source/vitashark.c
@@ -0,0 +1,124 @@
+/*
+ * This file is part of vitaGL
+ * Copyright 2017, 2018, 2019, 2020 Rinnegatamante
+ * Copyright 2020 Asakura Reiko
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "vitashark.h"
+#include
+#include "shacccg.h"
+
+// Default path for SceShaccCg module location
+#define DEFAULT_SHACCCG_PATH "ur0:/data/libshacccg.suprx"
+
+static void (*shark_log_cb)(const char *msg, shark_log_level msg_level, int line) = NULL;
+static shark_warn_level shark_warnings_level = SHARK_WARN_SILENT;
+
+static SceUID shark_module_id = 0;
+static uint8_t shark_initialized = 0;
+static SceShaccCgCompileOutput *shark_output = NULL;
+static SceShaccCgSourceFile shark_input;
+
+// Dummy Open File callback
+static SceShaccCgSourceFile *shark_open_file_cb(const char *fileName,
+ const SceShaccCgSourceLocation *includedFrom,
+ const SceShaccCgCompileOptions *compileOptions,
+ const char **errorString)
+{
+ return &shark_input;
+}
+
+int shark_init(const char *path) {
+ // Initializing sceShaccCg module
+ if (!shark_initialized) {
+ shark_module_id = sceKernelLoadStartModule(path ? path : DEFAULT_SHACCCG_PATH, 0, NULL, 0, NULL, NULL);
+ if (shark_module_id < 0) return -1;
+ sceShaccCgSetDefaultAllocator(malloc, free);
+ shark_initialized = 1;
+ }
+ return 0;
+}
+
+void shark_end() {
+ if (!shark_initialized) return;
+
+ // Terminating sceShaccCg module
+ sceKernelStopUnloadModule(shark_module_id, 0, NULL, 0, NULL, NULL);
+ shark_initialized = 0;
+}
+
+void shark_install_log_cb(void (*cb)(const char *msg, shark_log_level msg_level, int line)) {
+ shark_log_cb = cb;
+}
+
+void shark_set_warnings_level(shark_warn_level level) {
+ // Changing current warnings level
+ shark_warnings_level = level;
+}
+
+void shark_clear_output() {
+ // Clearing sceShaccCg output
+ if (shark_output) {
+ sceShaccCgDestroyCompileOutput(shark_output);
+ shark_output = NULL;
+ }
+}
+
+SceGxmProgram *shark_compile_shader_extended(const char *src, uint32_t *size, shark_type type, shark_opt opt, int32_t use_fastmath, int32_t use_fastprecision, int32_t use_fastint) {
+ if (!shark_initialized) return NULL;
+
+ // Forcing usage for memory source for the shader to compile
+ shark_input.fileName = "";
+ shark_input.text = src;
+ shark_input.size = *size;
+
+ // Properly configuring SceShaccCg with requqested settings
+ SceShaccCgCompileOptions options = {0};
+ options.mainSourceFile = shark_input.fileName;
+ options.targetProfile = type;
+ options.entryFunctionName = "main";
+ options.macroDefinitions = NULL;
+ options.useFx = 1;
+ options.warningLevel = shark_warnings_level;
+ options.optimizationLevel = opt;
+ options.useFastmath = use_fastmath;
+ options.useFastint = use_fastint;
+ options.useFastprecision = use_fastprecision;
+ options.pedantic = shark_warnings_level > SHARK_WARN_MEDIUM ? SHARK_ENABLE : SHARK_DISABLE;
+ options.performanceWarnings = shark_warnings_level > SHARK_WARN_SILENT ? SHARK_ENABLE : SHARK_DISABLE;
+
+ // Executing shader compilation
+ SceShaccCgCallbackList callbacks = {0};
+ sceShaccCgInitializeCallbackList(&callbacks, SCE_SHACCCG_TRIVIAL);
+ callbacks.openFile = shark_open_file_cb;
+ const SceShaccCgCompileOutput *shark_output = sceShaccCgCompileProgram(&options, &callbacks, 0);
+
+ // Executing logging
+ if (shark_log_cb) {
+ for (int i = 0; i < shark_output->diagnosticCount; ++i) {
+ const SceShaccCgDiagnosticMessage *log = &shark_output->diagnostics[i];
+ shark_log_cb(log->message, log->level, log->location->lineNumber);
+ }
+ }
+
+ // Returning output
+ if (shark_output->programData) *size = shark_output->programSize;
+ return (SceGxmProgram *)shark_output->programData;
+}
+
+SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type) {
+ return shark_compile_shader_extended(src, size, type, SHARK_OPT_DEFAULT, SHARK_DISABLE, SHARK_DISABLE, SHARK_DISABLE);
+}
diff --git a/deps/vitaShaRK/source/vitashark.h b/deps/vitaShaRK/source/vitashark.h
new file mode 100644
index 0000000000..61d1966084
--- /dev/null
+++ b/deps/vitaShaRK/source/vitashark.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of vitaShaRK
+ * Copyright 2017, 2018, 2019, 2020 Rinnegatamante
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _VITASHARK_H_
+#define _VITASHARK_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+
+typedef enum shark_opt {
+ SHARK_OPT_SLOW, //!< Equivalent to O0
+ SHARK_OPT_SAFE, //!< Equivalent to O1
+ SHARK_OPT_DEFAULT, //!< Equivalent to O2
+ SHARK_OPT_FAST, //!< Equivalent to O3
+ SHARK_OPT_UNSAFE //!< Equivalent to Ofast
+} shark_opt;
+
+typedef enum shark_type {
+ SHARK_VERTEX_SHADER,
+ SHARK_FRAGMENT_SHADER
+} shark_type;
+
+typedef enum shark_log_level {
+ SHARK_LOG_INFO,
+ SHARK_LOG_WARNING,
+ SHARK_LOG_ERROR
+} shark_log_level;
+
+typedef enum shark_warn_level {
+ SHARK_WARN_SILENT,
+ SHARK_WARN_LOW,
+ SHARK_WARN_MEDIUM,
+ SHARK_WARN_HIGH,
+ SHARK_WARN_MAX
+} shark_warn_level;
+
+#define SHARK_DISABLE 0
+#define SHARK_ENABLE 1
+
+// Init/term routines
+int shark_init(const char *path); //!< Initializes runtime shader compiler
+void shark_end(); //!< Terminates runtime shader compiler and frees used memory
+
+// Compiling routines
+SceGxmProgram *shark_compile_shader_extended(const char *src, uint32_t *size, shark_type type, shark_opt opt, int32_t use_fastmath, int32_t use_fastprecision, int32_t use_fastint); //!< Compiles a shader with extended settings
+SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type); //!< Compiles a shader
+void shark_clear_output(); //!< Clears output of a compilation attempt
+
+// Logging routines
+void shark_install_log_cb(void (*cb)(const char *msg, shark_log_level msg_level, int line)); //!< Installs a log function for info, warnings and errors
+void shark_set_warnings_level(shark_warn_level level); //!< Sets warnings level for logging
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/disk_control_interface.c b/disk_control_interface.c
index 2c1d93d5dc..d9b708d2f6 100644
--- a/disk_control_interface.c
+++ b/disk_control_interface.c
@@ -665,7 +665,9 @@ error:
* if functionality is supported by core
* NOTE: Must be called immediately after
* loading content */
-bool disk_control_verify_initial_index(disk_control_interface_t *disk_control)
+bool disk_control_verify_initial_index(
+ disk_control_interface_t *disk_control,
+ bool verbosity)
{
bool success = false;
unsigned image_index = 0;
@@ -723,6 +725,8 @@ bool disk_control_verify_initial_index(disk_control_interface_t *disk_control)
image_index + 1,
image_path);
+ /* Ignore 'verbosity' setting - errors should
+ * always be displayed */
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_SET_INITIAL_DISK),
0, 60,
@@ -765,11 +769,12 @@ bool disk_control_verify_initial_index(disk_control_interface_t *disk_control)
* it is likely other notifications will be
* generated before setting the disk index, and
* we do not want to 'overwrite' them */
- runloop_msg_queue_push(
- msg,
- 0, msg_duration,
- false, NULL,
- MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
+ if (verbosity)
+ runloop_msg_queue_push(
+ msg,
+ 0, msg_duration,
+ false, NULL,
+ MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
return success;
@@ -777,7 +782,8 @@ bool disk_control_verify_initial_index(disk_control_interface_t *disk_control)
/* Saves current disk index to file, if supported
* by current core */
-bool disk_control_save_image_index(disk_control_interface_t *disk_control)
+bool disk_control_save_image_index(
+ disk_control_interface_t *disk_control)
{
if (!disk_control)
return false;
diff --git a/disk_control_interface.h b/disk_control_interface.h
index 1991b47300..695dad8fa8 100644
--- a/disk_control_interface.h
+++ b/disk_control_interface.h
@@ -167,11 +167,14 @@ bool disk_control_set_initial_index(
* if functionality is supported by core
* NOTE: Must be called immediately after
* loading content */
-bool disk_control_verify_initial_index(disk_control_interface_t *disk_control);
+bool disk_control_verify_initial_index(
+ disk_control_interface_t *disk_control,
+ bool verbosity);
/* Saves current disk index to file, if supported
* by current core */
-bool disk_control_save_image_index(disk_control_interface_t *disk_control);
+bool disk_control_save_image_index(
+ disk_control_interface_t *disk_control);
RETRO_END_DECLS
diff --git a/disk_index_file.c b/disk_index_file.c
index b65e8e75bc..dcd827f079 100644
--- a/disk_index_file.c
+++ b/disk_index_file.c
@@ -313,7 +313,7 @@ bool disk_index_file_init(
{
/* Use content directory */
strlcpy(disk_index_file_dir, content_path, sizeof(disk_index_file_dir));
- path_basedir(disk_index_file_dir);
+ path_basedir_size(disk_index_file_dir, STRLEN_CONST(disk_index_file_dir));
}
/* > Create directory, if required */
diff --git a/dist-scripts/dist-cores.sh b/dist-scripts/dist-cores.sh
index 974df83229..5746fd7b3b 100755
--- a/dist-scripts/dist-cores.sh
+++ b/dist-scripts/dist-cores.sh
@@ -20,8 +20,9 @@ cd dist-scripts
elif [ $PLATFORM = "ps2" ] ; then
platform=ps2
-SALAMANDER=NO
+SALAMANDER=yes
EXT=a
+OPTS=release
mkdir -p ../pkg/${platform}/cores/
@@ -151,6 +152,9 @@ fi
# Compile Salamander core
if [ $SALAMANDER = "yes" ]; then
make -C ../ -f Makefile.${platform}.salamander $OPTS || exit 1
+ if [ $PLATFORM = "ps2" ] ; then
+ mv -f ../raboot.elf ../pkg/${platform}/raboot.elf
+ fi
if [ $PLATFORM = "psp1" ] ; then
mv -f ../EBOOT.PBP ../pkg/${platform}/EBOOT.PBP
fi
@@ -249,15 +253,13 @@ for f in `ls -v *_${platform}.${EXT}`; do
make -C ../ -f Makefile.${platform} $OPTS APP_TITLE="$name" LIBRETRO=$name $whole_archive $big_stack -j3 || exit 1
elif [ $PLATFORM = "ps2" ]; then
# TODO PS2 should be able to compile in parallel
- make -C ../ -f Makefile.${platform} $OPTS $whole_archive $big_stack || exit 1
+ make -C ../ -f Makefile.${platform} $OPTS || exit 1
else
make -C ../ -f Makefile.${platform} $OPTS $whole_archive $big_stack -j3 || exit 1
fi
# Do manual executable step
- if [ $PLATFORM = "ps2" ] ; then
- make -C ../ -f Makefile.${platform} package -j3
- elif [ $PLATFORM = "dex-ps3" ] ; then
+ if [ $PLATFORM = "dex-ps3" ] ; then
$MAKE_FSELF_NPDRM -c ../retroarch_${platform}.elf ../CORE.SELF
elif [ $PLATFORM = "cex-ps3" ] ; then
$SCETOOL_PATH $SCETOOL_FLAGS_CORE ../retroarch_${platform}.elf ../CORE.SELF
@@ -287,7 +289,7 @@ for f in `ls -v *_${platform}.${EXT}`; do
fi
fi
elif [ $PLATFORM = "ps2" ] ; then
- mv -f ../retroarchps2-release.elf ../pkg/${platform}/cores/retroarchps2_${name}.elf
+ mv -f ../retroarchps2.elf ../pkg/${platform}/cores/${name}_libretro_${platform}.elf
elif [ $PLATFORM = "psp1" ] ; then
mv -f ../EBOOT.PBP ../pkg/${platform}/cores/${name}_libretro.PBP
elif [ $PLATFORM = "vita" ] ; then
@@ -330,6 +332,7 @@ for f in `ls -v *_${platform}.${EXT}`; do
rm -f ../retroarch_${platform}.elf ../retroarch_${platform}.self ../CORE.SELF
elif [ $PLATFORM = "ps2" ] ; then
rm -f ../retroarchps2.elf
+ rm -f ../retroarchps2-debug.elf
elif [ $PLATFORM = "psp1" ] ; then
rm -f ../retroarchpsp.elf
elif [ $PLATFORM = "vita" ] ; then
diff --git a/driver.h b/driver.h
index dd116ab142..18abf3078e 100644
--- a/driver.h
+++ b/driver.h
@@ -35,6 +35,7 @@ enum
DRIVER_LOCATION,
DRIVER_MENU,
DRIVERS_VIDEO_INPUT,
+ DRIVER_BLUETOOTH,
DRIVER_WIFI,
DRIVER_LED,
DRIVER_MIDI
@@ -49,6 +50,7 @@ enum
DRIVER_LOCATION_MASK = 1 << DRIVER_LOCATION,
DRIVER_MENU_MASK = 1 << DRIVER_MENU,
DRIVERS_VIDEO_INPUT_MASK = 1 << DRIVERS_VIDEO_INPUT,
+ DRIVER_BLUETOOTH_MASK = 1 << DRIVER_BLUETOOTH,
DRIVER_WIFI_MASK = 1 << DRIVER_WIFI,
DRIVER_LED_MASK = 1 << DRIVER_LED,
DRIVER_MIDI_MASK = 1 << DRIVER_MIDI
diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c
index 1890205207..f9f2dad817 100644
--- a/frontend/drivers/platform_emscripten.c
+++ b/frontend/drivers/platform_emscripten.c
@@ -46,48 +46,8 @@
#include "../../tasks/tasks_internal.h"
#include "../../file_path_special.h"
-void RWebAudioRecalibrateTime(void);
void dummyErrnoCodes(void);
-
-static unsigned emscripten_frame_count = 0;
-
-static void emscripten_mainloop(void)
-{
- int ret;
- video_frame_info_t video_info;
-
- RWebAudioRecalibrateTime();
-
- emscripten_frame_count++;
-
- video_driver_build_info(&video_info);
-
- /* Disable BFI during fast forward, slow-motion,
- * and pause to prevent flicker. */
- if (
- video_info.black_frame_insertion
- && !video_info.input_driver_nonblock_state
- && !video_info.runloop_is_slowmotion
- && !video_info.runloop_is_paused)
- {
- if ((emscripten_frame_count & 1) == 0)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- video_info.cb_swap_buffers(video_info.context_data);
- return;
- }
- }
-
- ret = runloop_iterate();
-
- task_queue_check();
-
- if (ret != -1)
- return;
-
- main_exit(NULL);
- emscripten_force_exit(0);
-}
+void emscripten_mainloop(void);
void cmd_savefiles(void)
{
diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c
index a59d289946..2096bcaf43 100644
--- a/frontend/drivers/platform_ps2.c
+++ b/frontend/drivers/platform_ps2.c
@@ -13,50 +13,46 @@
*/
#include
-
-#include "../frontend_driver.h"
-
-#include
+#include
+#include
#include
+#include
+
#include
#include
#include
#include
-#include
-#include
-#include
#include
#include
+#include
+
+#include
+#include
+
+#include "../frontend_driver.h"
+#include "../../defaults.h"
+#include "../../file_path_special.h"
+#include "../../verbosity.h"
+#include
-static char eboot_path[512];
-static char user_path[512];
static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE;
+static int bootDeviceID;
+char cwd[FILENAME_MAX];
static void create_path_names(void)
{
- char cwd[FILENAME_MAX];
- int bootDeviceID;
+ char user_path[FILENAME_MAX];
-#if defined(BUILD_FOR_PCSX2)
- strlcpy(cwd, rootDevicePath(BOOT_DEVICE_MC0), sizeof(cwd));
-#else
- getcwd(cwd, sizeof(cwd));
- bootDeviceID=getBootDeviceID(cwd);
- strlcpy(cwd, rootDevicePath(bootDeviceID), sizeof(cwd));
-#endif
- strcat(cwd, "RETROARCH");
+ strlcpy(user_path, rootDevicePath(bootDeviceID), rootDevicePath(bootDeviceID));
+ strcat(user_path, "RETROARCH");
+
+ // Content in the same folder
+ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], cwd,
+ "cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
+ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], cwd,
+ "info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
- strlcpy(eboot_path, cwd, sizeof(eboot_path));
- strlcpy(g_defaults.dirs[DEFAULT_DIR_PORT], eboot_path, sizeof(g_defaults.dirs[DEFAULT_DIR_PORT]));
- strlcpy(user_path, eboot_path, sizeof(user_path));
-
- fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], g_defaults.dirs[DEFAULT_DIR_PORT],
- "CORES", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
- fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], g_defaults.dirs[DEFAULT_DIR_PORT],
- "INFO", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
-
- /* user data */
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CHEATS], user_path,
"CHEATS", sizeof(g_defaults.dirs[DEFAULT_DIR_CHEATS]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG], user_path,
@@ -95,6 +91,20 @@ static void poweroffCallback(void *arg)
poweroffShutdown();
}
+static void reset_IOP()
+{
+ SifInitRpc(0);
+#if !defined(DEBUG) || defined(BUILD_FOR_PCSX2)
+ /* Comment this line if you don't wanna debug the output */
+ while(!SifIopReset(NULL, 0)){};
+#endif
+
+ while(!SifIopSync()){};
+ SifInitRpc(0);
+ sbv_patch_enable_lmb();
+ sbv_patch_disable_prefix_check();
+}
+
static void frontend_ps2_get_environment_settings(int *argc, char *argv[],
void *args, void *params_data)
{
@@ -103,7 +113,7 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[],
#ifndef IS_SALAMANDER
if (!string_is_empty(argv[1]))
{
- static char path[PATH_MAX_LENGTH] = {0};
+ static char path[FILENAME_MAX] = {0};
struct rarch_main_wrap *args =
(struct rarch_main_wrap*)params_data;
@@ -122,7 +132,6 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[],
RARCH_LOG("argv[0]: %s\n", argv[0]);
RARCH_LOG("argv[1]: %s\n", argv[1]);
- RARCH_LOG("argv[2]: %s\n", argv[2]);
RARCH_LOG("Auto-start game %s.\n", argv[1]);
}
@@ -139,18 +148,7 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[],
static void frontend_ps2_init(void *data)
{
- char cwd[FILENAME_MAX];
- int bootDeviceID;
-
- SifInitRpc(0);
-#if !defined(DEBUG) || defined(BUILD_FOR_PCSX2)
- /* Comment this line if you don't wanna debug the output */
- while(!SifIopReset(NULL, 0)){};
-#endif
-
- while(!SifIopSync()){};
- SifInitRpc(0);
- sbv_patch_enable_lmb();
+ reset_IOP();
/* I/O Files */
SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL);
@@ -161,21 +159,22 @@ static void frontend_ps2_init(void *data)
SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL);
SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL);
- /* Controllers */
- SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL);
- SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL);
-
/* USB */
SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL);
SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL);
+ /* CDFS */
+ SifExecModuleBuffer(&cdfs_irx, size_cdfs_irx, 0, NULL, NULL);
+
+#ifndef IS_SALAMANDER
+ /* Controllers */
+ SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL);
+ SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL);
+
/* Audio */
SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL);
SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL);
- /* CDVD */
- SifExecModuleBuffer(&cdfs_irx, size_cdfs_irx, 0, NULL, NULL);
-
/* Initializes audsrv library */
if (audsrv_init()) {
RARCH_ERR("audsrv library not initalizated\n");
@@ -192,48 +191,52 @@ static void frontend_ps2_init(void *data)
if (mtapPortOpen(0) != 1) {
RARCH_ERR("mtapPortOpen library not initalizated\n");
}
+#endif
+
+#if defined(BUILD_FOR_PCSX2)
+ bootDeviceID = BOOT_DEVICE_MC0;
+ strlcpy(cwd, rootDevicePath(bootDeviceID), sizeof(rootDevicePath(bootDeviceID)));
+#else
+ getcwd(cwd, sizeof(cwd));
+ bootDeviceID = getBootDeviceID(cwd);
+#if !defined(IS_SALAMANDER) && !defined(DEBUG)
+ // If it is not salamander we need to go one level up for set the CWD.
+ path_parent_dir(cwd);
+#endif
+#endif
#if defined(HAVE_FILE_LOGGER)
- retro_main_log_file_init("retroarch.log", false);
+ char fileLog[FILENAME_MAX];
+ strlcpy(fileLog, rootDevicePath(bootDeviceID), sizeof(fileLog));
+ strcat(fileLog, "retroarch.log");
+ retro_main_log_file_init(fileLog, false);
verbosity_enable();
#endif
+
+ waitUntilDeviceIsReady(bootDeviceID);
}
static void frontend_ps2_deinit(void *data)
{
- (void)data;
#if defined(HAVE_FILE_LOGGER)
verbosity_disable();
- command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL);
+ retro_main_log_file_deinit();
#endif
- padEnd();
- audsrv_quit();
- Exit(0);
}
static void frontend_ps2_exec(const char *path, bool should_load_game)
{
-#if defined(IS_SALAMANDER)
- char argp[512] = {0};
- SceSize args = 0;
-
- strlcpy(argp, eboot_path, sizeof(argp));
- args = strlen(argp) + 1;
-
+ int args = 0;
+ static char *argv[1];
+ RARCH_LOG("Attempt to load executable: [%s].\n", path);
#ifndef IS_SALAMANDER
if (should_load_game && !path_is_empty(RARCH_PATH_CONTENT))
{
- argp[args] = '\0';
- strlcat(argp + args, path_get(RARCH_PATH_CONTENT), sizeof(argp) - args);
- args += strlen(argp + args) + 1;
+ args++;
+ argv[0] = path_get(RARCH_PATH_CONTENT);
}
#endif
-
- RARCH_LOG("Attempt to load executable: [%s].\n", path);
-#if 0
- exitspawn_kernel(path, args, argp); /* I don't know what this is doing */
-#endif
-#endif
+ LoadELFFromFile(path, args, argv);
}
#ifndef IS_SALAMANDER
@@ -353,7 +356,7 @@ frontend_ctx_driver_t frontend_ctx_ps2 = {
frontend_ps2_exitspawn, /* exitspawn */
NULL, /* process_args */
frontend_ps2_exec, /* exec */
- #ifdef IS_SALAMANDER
+#ifdef IS_SALAMANDER
NULL, /* set_fork */
#else
frontend_ps2_set_fork, /* set_fork */
diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c
index 988f8cbe38..341fce4e87 100644
--- a/frontend/drivers/platform_unix.c
+++ b/frontend/drivers/platform_unix.c
@@ -190,6 +190,33 @@ error:
/* forward declaration */
bool android_run_events(void *data);
+void android_dpi_get_density(char *s, size_t len)
+{
+ static bool inited_once = false;
+ static bool inited2_once = false;
+ static char string[PROP_VALUE_MAX] = {0};
+ static char string2[PROP_VALUE_MAX] = {0};
+ if (!inited_once)
+ {
+ system_property_get("getprop", "ro.sf.lcd_density", string);
+ inited_once = true;
+ }
+
+ if (!string_is_empty(string))
+ {
+ strlcpy(s, string, len);
+ return;
+ }
+
+ if (!inited2_once)
+ {
+ system_property_get("wm", "density", string2);
+ inited2_once = true;
+ }
+
+ strlcpy(s, string2, len);
+}
+
void android_app_write_cmd(struct android_app *android_app, int8_t cmd)
{
if (!android_app)
diff --git a/frontend/drivers/platform_unix.h b/frontend/drivers/platform_unix.h
index 8a0485e6bc..13d6007b1c 100644
--- a/frontend/drivers/platform_unix.h
+++ b/frontend/drivers/platform_unix.h
@@ -346,6 +346,8 @@ extern JNIEnv *jni_thread_getenv(void);
void android_app_write_cmd(struct android_app *android_app, int8_t cmd);
+void android_dpi_get_density(char *s, size_t len);
+
extern struct android_app *g_android;
#endif
diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c
index efa677e130..dde19827bd 100644
--- a/frontend/drivers/platform_wiiu.c
+++ b/frontend/drivers/platform_wiiu.c
@@ -606,28 +606,32 @@ void net_print_exp(const char *str)
sendto(wiiu_log_socket, str, strlen(str), 0, (struct sockaddr *)&broadcast, sizeof(broadcast));
}
-/* RFC 791 specifies that any IP host must be able to receive a datagram of 576 bytes.
- * Since we're generally never logging more than a line or two's worth of data (~100 bytes)
+/* RFC 791 specifies that any IP host must be able
+ * to receive a datagram of 576 bytes.
+ * Since we're generally never logging more than a
+ * line or two's worth of data (~100 bytes)
* this is a reasonable size for our use. */
#define DGRAM_SIZE 576
-static ssize_t wiiu_log_write(struct _reent *r, void *fd, const char *ptr, size_t len)
+static ssize_t wiiu_log_write(struct _reent *r,
+ void *fd, const char *ptr, size_t len)
{
+ int remaining;
if (wiiu_log_socket < 0)
return len;
- while(wiiu_log_lock)
+ while (wiiu_log_lock)
OSSleepTicks(((248625000 / 4)) / 1000);
wiiu_log_lock = 1;
- int sent;
- int remaining = len;
+ remaining = len;
- while(remaining > 0)
+ while (remaining > 0)
{
int block = remaining < DGRAM_SIZE ? remaining : DGRAM_SIZE;
- sent = sendto(wiiu_log_socket, ptr, block, 0, (struct sockaddr *)&broadcast, sizeof(broadcast));
+ int sent = sendto(wiiu_log_socket, ptr, block, 0,
+ (struct sockaddr *)&broadcast, sizeof(broadcast));
if (sent < 0)
break;
diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c
index f40c7cec40..a233f5f996 100644
--- a/frontend/drivers/platform_win32.c
+++ b/frontend/drivers/platform_win32.c
@@ -32,6 +32,7 @@
#include
#include
#include
+#include
#include
#ifdef HAVE_CONFIG_H
@@ -176,6 +177,16 @@ enum retro_language win32_get_retro_lang_from_langid(unsigned short langid)
return RETRO_LANGUAGE_ENGLISH;
}
#endif
+#else
+unsigned short win32_get_langid_from_retro_lang(enum retro_language lang)
+{
+ return 0x409; /* fallback to US English */
+}
+
+enum retro_language win32_get_retro_lang_from_langid(unsigned short langid)
+{
+ return RETRO_LANGUAGE_ENGLISH;
+}
#endif
static void gfx_dwm_shutdown(void)
@@ -613,7 +624,7 @@ static void frontend_win32_environment_get(int *argc, char *argv[],
":\\logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS]));
}
-static uint64_t frontend_win32_get_mem_total(void)
+static uint64_t frontend_win32_get_total_mem(void)
{
/* OSes below 2000 don't have the Ex version,
* and non-Ex cannot work with >4GB RAM */
@@ -630,7 +641,7 @@ static uint64_t frontend_win32_get_mem_total(void)
#endif
}
-static uint64_t frontend_win32_get_mem_used(void)
+static uint64_t frontend_win32_get_free_mem(void)
{
/* OSes below 2000 don't have the Ex version,
* and non-Ex cannot work with >4GB RAM */
@@ -638,12 +649,12 @@ static uint64_t frontend_win32_get_mem_used(void)
MEMORYSTATUSEX mem_info;
mem_info.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mem_info);
- return ((frontend_win32_get_mem_total() - mem_info.ullAvailPhys));
+ return mem_info.ullAvailPhys;
#else
MEMORYSTATUS mem_info;
mem_info.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&mem_info);
- return ((frontend_win32_get_mem_total() - mem_info.dwAvailPhys));
+ return mem_info.dwAvailPhys;
#endif
}
@@ -1034,16 +1045,14 @@ static bool accessibility_speak_windows(int speed,
#ifdef HAVE_NVDA
else if (USE_NVDA)
{
- long res;
- const size_t cSize = strlen(speak_text)+1;
- wchar_t *wc;
- res = nvdaController_testIfRunning_func();
- wc = malloc(sizeof(wchar_t) * cSize);
- mbstowcs(wc, speak_text, cSize);
+ wchar_t *wc = utf8_to_utf16_string_alloc(speak_text);
+ long res = nvdaController_testIfRunning_func();
- if (res != 0)
+ if (!wc || res != 0)
{
RARCH_LOG("Error communicating with NVDA\n");
+ if (wc)
+ free(wc);
return false;
}
@@ -1053,6 +1062,7 @@ static bool accessibility_speak_windows(int speed,
nvdaController_brailleMessage_func(wc);
else
nvdaController_speakText_func(wc);
+ free(wc);
}
#endif
#ifdef HAVE_SAPI
@@ -1076,12 +1086,16 @@ static bool accessibility_speak_windows(int speed,
if (SUCCEEDED(hr))
{
- wchar_t wtext[1200];
+ wchar_t *wc = utf8_to_utf16_string_alloc(speak_text);
+
snprintf(cmd, sizeof(cmd),
"%s", speeds[speed], langid, speak_text);
- mbstowcs(wtext, speak_text, sizeof(wtext));
- hr = ISpVoice_Speak(pVoice, wtext, SPF_ASYNC /*SVSFlagsAsync*/, NULL);
+ if (!wc)
+ return false;
+
+ hr = ISpVoice_Speak(pVoice, wc, SPF_ASYNC /*SVSFlagsAsync*/, NULL);
+ free(wc);
}
}
#endif
@@ -1114,8 +1128,8 @@ frontend_ctx_driver_t frontend_ctx_win32 = {
frontend_win32_get_architecture,
frontend_win32_get_powerstate,
frontend_win32_parse_drive_list,
- frontend_win32_get_mem_total,
- frontend_win32_get_mem_used,
+ frontend_win32_get_total_mem,
+ frontend_win32_get_free_mem,
NULL, /* install_signal_handler */
NULL, /* get_sighandler_state */
NULL, /* set_sighandler_state */
diff --git a/frontend/drivers/platform_win32.h b/frontend/drivers/platform_win32.h
index de8de6c321..8843d7ce63 100644
--- a/frontend/drivers/platform_win32.h
+++ b/frontend/drivers/platform_win32.h
@@ -19,12 +19,8 @@
#ifndef _PLATFORM_WIN32_H
#define _PLATFORM_WIN32_H
-#if defined(HAVE_LANGEXTRA) && !defined(_XBOX)
-#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500) || !defined(_MSC_VER)
unsigned short win32_get_langid_from_retro_lang(enum retro_language lang);
enum retro_language win32_get_retro_lang_from_langid(unsigned short langid);
-#endif
-#endif
#endif
diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c
index 9577718e52..619316ffe5 100644
--- a/frontend/frontend_driver.c
+++ b/frontend/frontend_driver.c
@@ -134,11 +134,6 @@ static frontend_ctx_driver_t *frontend_ctx_drivers[] = {
NULL
};
-#ifndef IS_SALAMANDER
-/* TODO/FIXME - static public global variable */
-static frontend_ctx_driver_t *current_frontend_ctx;
-#endif
-
/**
* frontend_ctx_find_driver:
* @ident : Identifier name of driver to find.
@@ -280,294 +275,3 @@ bool frontend_driver_get_salamander_basename(char *s, size_t len)
#endif
}
-
-#ifndef IS_SALAMANDER
-frontend_ctx_driver_t *frontend_get_ptr(void)
-{
- return current_frontend_ctx;
-}
-
-int frontend_driver_parse_drive_list(void *data, bool load_content)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
-
- if (!frontend || !frontend->parse_drive_list)
- return -1;
- return frontend->parse_drive_list(data, load_content);
-}
-
-void frontend_driver_content_loaded(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
-
- if (!frontend || !frontend->content_loaded)
- return;
- frontend->content_loaded();
-}
-
-bool frontend_driver_has_fork(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
-
- if (!frontend || !frontend->set_fork)
- return false;
- return true;
-}
-
-bool frontend_driver_set_fork(enum frontend_fork fork_mode)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
-
- if (!frontend_driver_has_fork())
- return false;
- return frontend->set_fork(fork_mode);
-}
-
-void frontend_driver_process_args(int *argc, char *argv[])
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
-
- if (!frontend || !frontend->process_args)
- return;
- frontend->process_args(argc, argv);
-}
-
-bool frontend_driver_is_inited(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend)
- return false;
- return true;
-}
-
-void frontend_driver_init_first(void *args)
-{
- current_frontend_ctx = (frontend_ctx_driver_t*)frontend_ctx_init_first();
-
- if (current_frontend_ctx && current_frontend_ctx->init)
- current_frontend_ctx->init(args);
-}
-
-void frontend_driver_free(void)
-{
- current_frontend_ctx = NULL;
-}
-
-environment_get_t frontend_driver_environment_get_ptr(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend)
- return NULL;
- return frontend->environment_get;
-}
-
-bool frontend_driver_has_get_video_driver_func(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_video_driver)
- return false;
- return true;
-}
-
-const struct video_driver *frontend_driver_get_video_driver(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_video_driver)
- return NULL;
- return frontend->get_video_driver();
-}
-
-void frontend_driver_exitspawn(char *s, size_t len, char *args)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->exitspawn)
- return;
- frontend->exitspawn(s, len, args);
-}
-
-void frontend_driver_deinit(void *args)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->deinit)
- return;
- frontend->deinit(args);
-}
-
-void frontend_driver_shutdown(bool a)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->shutdown)
- return;
- frontend->shutdown(a);
-}
-
-enum frontend_architecture frontend_driver_get_cpu_architecture(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_architecture)
- return FRONTEND_ARCH_NONE;
- return frontend->get_architecture();
-}
-
-const void *frontend_driver_get_cpu_architecture_str(
- char *architecture, size_t size)
-{
- const frontend_ctx_driver_t
- *frontend = frontend_get_ptr();
- enum frontend_architecture arch = frontend_driver_get_cpu_architecture();
-
- switch (arch)
- {
- case FRONTEND_ARCH_X86:
- strlcpy(architecture, "x86", size);
- break;
- case FRONTEND_ARCH_X86_64:
- strlcpy(architecture, "x64", size);
- break;
- case FRONTEND_ARCH_PPC:
- strlcpy(architecture, "PPC", size);
- break;
- case FRONTEND_ARCH_ARM:
- strlcpy(architecture, "ARM", size);
- break;
- case FRONTEND_ARCH_ARMV7:
- strlcpy(architecture, "ARMv7", size);
- break;
- case FRONTEND_ARCH_ARMV8:
- strlcpy(architecture, "ARMv8", size);
- break;
- case FRONTEND_ARCH_MIPS:
- strlcpy(architecture, "MIPS", size);
- break;
- case FRONTEND_ARCH_TILE:
- strlcpy(architecture, "Tilera", size);
- break;
- case FRONTEND_ARCH_NONE:
- default:
- strlcpy(architecture, "N/A", size);
- break;
- }
-
- return frontend;
-}
-
-uint64_t frontend_driver_get_total_memory(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_total_mem)
- return 0;
- return frontend->get_total_mem();
-}
-
-uint64_t frontend_driver_get_free_memory(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_free_mem)
- return 0;
- return frontend->get_free_mem();
-}
-
-void frontend_driver_install_signal_handler(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->install_signal_handler)
- return;
- frontend->install_signal_handler();
-}
-
-int frontend_driver_get_signal_handler_state(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_signal_handler_state)
- return -1;
- return frontend->get_signal_handler_state();
-}
-
-void frontend_driver_set_signal_handler_state(int value)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->set_signal_handler_state)
- return;
- frontend->set_signal_handler_state(value);
-}
-
-void frontend_driver_attach_console(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->attach_console)
- return;
- frontend->attach_console();
-}
-
-void frontend_driver_detach_console(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->detach_console)
- return;
- frontend->detach_console();
-}
-
-void frontend_driver_destroy_signal_handler_state(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->destroy_signal_handler_state)
- return;
- frontend->destroy_signal_handler_state();
-}
-
-bool frontend_driver_can_watch_for_changes(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->watch_path_for_changes)
- return false;
- return true;
-}
-
-void frontend_driver_watch_path_for_changes(struct string_list *list, int flags, path_change_data_t **change_data)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->watch_path_for_changes)
- return;
- frontend->watch_path_for_changes(list, flags, change_data);
-}
-
-bool frontend_driver_check_for_path_changes(path_change_data_t *change_data)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->check_for_path_changes)
- return false;
- return frontend->check_for_path_changes(change_data);
-}
-
-void frontend_driver_set_sustained_performance_mode(bool on)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->set_sustained_performance_mode)
- return;
- frontend->set_sustained_performance_mode(on);
-}
-
-const char* frontend_driver_get_cpu_model_name(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_cpu_model_name)
- return NULL;
- return frontend->get_cpu_model_name();
-}
-
-enum retro_language frontend_driver_get_user_language(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->get_user_language)
- return RETRO_LANGUAGE_ENGLISH;
- return frontend->get_user_language();
-}
-
-bool frontend_driver_is_narrator_running(void)
-{
- frontend_ctx_driver_t *frontend = frontend_get_ptr();
- if (!frontend || !frontend->is_narrator_running)
- return false;
- return frontend->is_narrator_running();
-}
-#endif
diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c
index 1522fe8853..8b0b292852 100644
--- a/gfx/common/d3d_common.c
+++ b/gfx/common/d3d_common.c
@@ -156,6 +156,7 @@ void d3d_input_driver(const char* input_name, const char* joypad_name,
*input_data = xinput;
#else
#if _WIN32_WINNT >= 0x0501
+#ifdef HAVE_WINRAWINPUT
/* winraw only available since XP */
if (string_is_equal(input_name, "raw"))
{
@@ -167,6 +168,7 @@ void d3d_input_driver(const char* input_name, const char* joypad_name,
}
}
#endif
+#endif
#ifdef HAVE_DINPUT
*input_data = input_dinput.init(joypad_name);
diff --git a/gfx/common/d3dcompiler_common.c b/gfx/common/d3dcompiler_common.c
index 9cf9e3aa96..a408ac7b4f 100644
--- a/gfx/common/d3dcompiler_common.c
+++ b/gfx/common/d3dcompiler_common.c
@@ -27,6 +27,7 @@
#if defined(HAVE_DYNAMIC) && !defined(__WINRT__)
#include
+/* TODO/FIXME - static globals */
static dylib_t d3dcompiler_dll;
static const char* d3dcompiler_dll_list[] = {
"D3DCompiler_47.dll", "D3DCompiler_46.dll", "D3DCompiler_45.dll", "D3DCompiler_44.dll",
diff --git a/gfx/common/dbus_common.c b/gfx/common/dbus_common.c
index 68c4838187..abbce177c7 100644
--- a/gfx/common/dbus_common.c
+++ b/gfx/common/dbus_common.c
@@ -19,6 +19,7 @@
#ifdef HAVE_DBUS
#include
+/* TODO/FIXME - static globals */
static DBusConnection* dbus_connection = NULL;
static unsigned int dbus_screensaver_cookie = 0;
#endif
diff --git a/gfx/common/drm_common.c b/gfx/common/drm_common.c
index a1bede5eac..15af377eb2 100644
--- a/gfx/common/drm_common.c
+++ b/gfx/common/drm_common.c
@@ -21,6 +21,7 @@
#include "drm_common.h"
+/* TODO/FIXME - globals */
struct pollfd g_drm_fds;
uint32_t g_connector_id = 0;
diff --git a/gfx/common/egl_common.c b/gfx/common/egl_common.c
index 791f1b86e2..cf20ada661 100644
--- a/gfx/common/egl_common.c
+++ b/gfx/common/egl_common.c
@@ -33,6 +33,7 @@
#include "../../verbosity.h"
#include "../../frontend/frontend_driver.h"
+/* TODO/FIXME - globals */
bool g_egl_inited = false;
unsigned g_egl_major = 0;
diff --git a/gfx/common/gdi_common.h b/gfx/common/gdi_common.h
index 4ed7cd8e86..3b234abcc2 100644
--- a/gfx/common/gdi_common.h
+++ b/gfx/common/gdi_common.h
@@ -34,8 +34,6 @@ typedef struct gdi
unsigned video_height;
unsigned screen_width;
unsigned screen_height;
- void *ctx_data;
- const gfx_ctx_driver_t *ctx_driver;
unsigned menu_width;
unsigned menu_height;
@@ -50,6 +48,9 @@ typedef struct gdi
bool lte_win98;
unsigned short *temp_buf;
unsigned char *menu_frame;
+
+ bool menu_enable;
+ bool menu_full_screen;
} gdi_t;
typedef struct gdi_texture
diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m
index 9846c944b5..0b94dd2b77 100644
--- a/gfx/common/metal_common.m
+++ b/gfx/common/metal_common.m
@@ -23,18 +23,20 @@
#include
#import
-#include "../../managers/state_manager.h"
#import "metal_common.h"
-#import "../../ui/drivers/cocoa/cocoa_common.h"
-//#import "Context.h"
#include "metal/Context.h"
+#include "../../ui/drivers/cocoa/cocoa_common.h"
+
+#ifdef HAVE_REWIND
+#include "../../managers/state_manager.h"
+#endif
#ifdef HAVE_MENU
-#import "../../menu/menu_driver.h"
+#include "../../menu/menu_driver.h"
#endif
#ifdef HAVE_GFX_WIDGETS
-#import "../gfx_widgets.h"
+#include "../gfx_widgets.h"
#endif
#define STRUCT_ASSIGN(x, y) \
@@ -1002,7 +1004,17 @@ typedef struct MTLALIGN(16)
if (_shader->pass[i].frame_count_mod)
_engine.pass[i].frame_count %= _shader->pass[i].frame_count_mod;
- _engine.pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
+#ifdef HAVE_REWIND
+ if (state_manager_frame_is_reversed())
+ {
+ _engine.pass[i].frame_direction = -1;
+ }
+ else
+#else
+ {
+ _engine.pass[i].frame_direction = 1;
+ }
+#endif
for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++)
{
diff --git a/gfx/common/network_common.h b/gfx/common/network_common.h
index 80a1825603..4de779287d 100644
--- a/gfx/common/network_common.h
+++ b/gfx/common/network_common.h
@@ -24,8 +24,6 @@ typedef struct network
unsigned video_height;
unsigned screen_width;
unsigned screen_height;
- void *ctx_data;
- const gfx_ctx_driver_t *ctx_driver;
char address[256];
uint16_t port;
int fd;
diff --git a/gfx/common/sixel_common.h b/gfx/common/sixel_common.h
index 0ec5b5519b..1c7dd6195e 100644
--- a/gfx/common/sixel_common.h
+++ b/gfx/common/sixel_common.h
@@ -29,8 +29,6 @@ typedef struct sixel
unsigned video_height;
unsigned screen_width;
unsigned screen_height;
- void *ctx_data;
- const gfx_ctx_driver_t *ctx_driver;
} sixel_t;
#endif
diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c
index 9ea17d0db2..0097dc3e77 100644
--- a/gfx/common/vulkan_common.c
+++ b/gfx/common/vulkan_common.c
@@ -46,6 +46,7 @@
#define VULKAN_EMULATE_MAILBOX
#endif
+/* TODO/FIXME - static globals */
static dylib_t vulkan_library;
static VkInstance cached_instance_vk;
static VkDevice cached_device_vk;
@@ -207,12 +208,17 @@ VkResult vulkan_emulated_mailbox_acquire_next_image_blocking(
static void vulkan_emulated_mailbox_loop(void *userdata)
{
VkFence fence;
- VkFenceCreateInfo info = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
- struct vulkan_emulated_mailbox *mailbox = (struct vulkan_emulated_mailbox*)userdata;
+ VkFenceCreateInfo info;
+ struct vulkan_emulated_mailbox *mailbox =
+ (struct vulkan_emulated_mailbox*)userdata;
if (!mailbox)
return;
+ info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ info.pNext = NULL;
+ info.flags = 0;
+
vkCreateFence(mailbox->device, &info, NULL, &fence);
for (;;)
@@ -230,16 +236,20 @@ static void vulkan_emulated_mailbox_loop(void *userdata)
mailbox->request_acquire = false;
slock_unlock(mailbox->lock);
- mailbox->result = vkAcquireNextImageKHR(mailbox->device, mailbox->swapchain, UINT64_MAX,
+ mailbox->result = vkAcquireNextImageKHR(
+ mailbox->device, mailbox->swapchain, UINT64_MAX,
VK_NULL_HANDLE, fence, &mailbox->index);
- /* VK_SUBOPTIMAL_KHR can be returned on Android 10 when prerotate is not dealt with.
- * This is not an error we need to care about, and we'll treat it as SUCCESS. */
+ /* VK_SUBOPTIMAL_KHR can be returned on Android 10
+ * when prerotate is not dealt with.
+ * This is not an error we need to care about,
+ * and we'll treat it as SUCCESS. */
if (mailbox->result == VK_SUBOPTIMAL_KHR)
mailbox->result = VK_SUCCESS;
if (mailbox->result == VK_SUCCESS)
- vkWaitForFences(mailbox->device, 1, &fence, true, UINT64_MAX);
+ vkWaitForFences(mailbox->device, 1,
+ &fence, true, UINT64_MAX);
vkResetFences(mailbox->device, 1, &fence);
if (mailbox->result == VK_SUCCESS)
@@ -314,31 +324,6 @@ uint32_t vulkan_find_memory_type_fallback(
device_reqs, host_reqs_second, 0);
}
-void vulkan_transfer_image_ownership(VkCommandBuffer cmd,
- VkImage image, VkImageLayout layout,
- VkPipelineStageFlags src_stages,
- VkPipelineStageFlags dst_stages,
- uint32_t src_queue_family,
- uint32_t dst_queue_family)
-{
- VkImageMemoryBarrier barrier =
- { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
-
- barrier.srcAccessMask = 0;
- barrier.dstAccessMask = 0;
- barrier.oldLayout = layout;
- barrier.newLayout = layout;
- barrier.srcQueueFamilyIndex = src_queue_family;
- barrier.dstQueueFamilyIndex = dst_queue_family;
- barrier.image = image;
- barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
- barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- vkCmdPipelineBarrier(cmd, src_stages, dst_stages,
- false, 0, NULL, 0, NULL, 1, &barrier);
-}
-
void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
struct vk_texture *dynamic,
struct vk_texture *staging)
@@ -348,7 +333,9 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
retro_assert(dynamic->type == VULKAN_TEXTURE_DYNAMIC);
retro_assert(staging->type == VULKAN_TEXTURE_STAGING);
- vulkan_sync_texture_to_gpu(vk, staging);
+ if ( staging->need_manual_cache_management &&
+ staging->memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, staging->memory);
/* We don't have to sync against previous TRANSFER,
* since we observed the completion by fences.
@@ -359,25 +346,32 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
* We would also need to optionally maintain extra textures due to
* changes in resolution, so this seems like the sanest and
* simplest solution. */
- vulkan_image_layout_transition(vk, cmd, dynamic->image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(cmd, dynamic->image,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
- memset(®ion, 0, sizeof(region));
- region.imageExtent.width = dynamic->width;
- region.imageExtent.height = dynamic->height;
- region.imageExtent.depth = 1;
- region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.imageSubresource.layerCount = 1;
+ region.bufferOffset = 0;
+ region.bufferRowLength = 0;
+ region.bufferImageHeight = 0;
+ region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ region.imageSubresource.mipLevel = 0;
+ region.imageSubresource.baseArrayLayer = 0;
+ region.imageSubresource.layerCount = 1;
+ region.imageOffset.x = 0;
+ region.imageOffset.y = 0;
+ region.imageOffset.z = 0;
+ region.imageExtent.width = dynamic->width;
+ region.imageExtent.height = dynamic->height;
+ region.imageExtent.depth = 1;
vkCmdCopyBufferToImage(cmd,
staging->buffer,
dynamic->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, ®ion);
- vulkan_image_layout_transition(vk, cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(cmd,
dynamic->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
@@ -392,6 +386,7 @@ void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
#ifdef VULKAN_DEBUG_TEXTURE_ALLOC
static VkImage vk_images[4 * 1024];
static unsigned vk_count;
+static unsigned track_seq;
void vulkan_log_textures(void)
{
@@ -404,7 +399,6 @@ void vulkan_log_textures(void)
vk_count = 0;
}
-static unsigned track_seq;
static void vulkan_track_alloc(VkImage image)
{
vk_images[vk_count++] = image;
@@ -430,30 +424,6 @@ static void vulkan_track_dealloc(VkImage image)
}
#endif
-void vulkan_sync_texture_to_gpu(vk_t *vk, const struct vk_texture *tex)
-{
- VkMappedMemoryRange range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
- if (!tex || !tex->need_manual_cache_management || tex->memory == VK_NULL_HANDLE)
- return;
-
- range.memory = tex->memory;
- range.offset = 0;
- range.size = VK_WHOLE_SIZE;
- vkFlushMappedMemoryRanges(vk->context->device, 1, &range);
-}
-
-void vulkan_sync_texture_to_cpu(vk_t *vk, const struct vk_texture *tex)
-{
- VkMappedMemoryRange range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
- if (!tex || !tex->need_manual_cache_management || tex->memory == VK_NULL_HANDLE)
- return;
-
- range.memory = tex->memory;
- range.offset = 0;
- range.size = VK_WHOLE_SIZE;
- vkInvalidateMappedMemoryRanges(vk->context->device, 1, &range);
-}
-
static unsigned vulkan_num_miplevels(unsigned width, unsigned height)
{
unsigned size = MAX(width, height);
@@ -747,7 +717,9 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
for (y = 0; y < tex.height; y++, dst += tex.stride, src += stride)
memcpy(dst, src, width * bpp);
- vulkan_sync_texture_to_gpu(vk, &tex);
+ if ( tex.need_manual_cache_management &&
+ tex.memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, tex.memory);
vkUnmapMemory(device, tex.memory);
}
else if (initial && type == VULKAN_TEXTURE_STATIC)
@@ -771,7 +743,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
* and transfers from the images without having to
* mess around with lots of extra transitions at per-level granularity.
*/
- vulkan_image_layout_transition(vk,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(
staging,
tex.image,
VK_IMAGE_LAYOUT_UNDEFINED,
@@ -819,7 +791,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
/* Only injects execution and memory barriers,
* not actual transition. */
- vulkan_image_layout_transition(vk, staging, tex.image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(
+ staging, tex.image,
VK_IMAGE_LAYOUT_GENERAL,
VK_IMAGE_LAYOUT_GENERAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@@ -834,7 +807,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
}
/* Complete our texture. */
- vulkan_image_layout_transition(vk, staging, tex.image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(
+ staging, tex.image,
VK_IMAGE_LAYOUT_GENERAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@@ -844,7 +818,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
}
else
{
- vulkan_image_layout_transition(vk, staging, tex.image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(
+ staging, tex.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT,
@@ -899,7 +874,24 @@ void vulkan_destroy_texture(
if (tex->image)
vulkan_track_dealloc(tex->image);
#endif
- memset(tex, 0, sizeof(*tex));
+ tex->type = VULKAN_TEXTURE_STREAMED;
+ tex->default_smooth = false;
+ tex->need_manual_cache_management = false;
+ tex->mipmap = false;
+ tex->memory_type = 0;
+ tex->width = 0;
+ tex->height = 0;
+ tex->offset = 0;
+ tex->stride = 0;
+ tex->size = 0;
+ tex->mapped = NULL;
+ tex->image = VK_NULL_HANDLE;
+ tex->view = VK_NULL_HANDLE;
+ tex->memory = VK_NULL_HANDLE;
+ tex->buffer = VK_NULL_HANDLE;
+ tex->format = VK_FORMAT_UNDEFINED;
+ tex->memory_size = 0;
+ tex->layout = VK_IMAGE_LAYOUT_UNDEFINED;
}
static void vulkan_write_quad_descriptors(
@@ -911,18 +903,23 @@ static void vulkan_write_quad_descriptors(
const struct vk_texture *texture,
VkSampler sampler)
{
+ VkWriteDescriptorSet write;
VkDescriptorBufferInfo buffer_info;
- VkWriteDescriptorSet write = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET };
buffer_info.buffer = buffer;
buffer_info.offset = offset;
buffer_info.range = range;
+ write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ write.pNext = NULL;
write.dstSet = set;
write.dstBinding = 0;
+ write.dstArrayElement = 0;
write.descriptorCount = 1;
write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ write.pImageInfo = NULL;
write.pBufferInfo = &buffer_info;
+ write.pTexelBufferView = NULL;
vkUpdateDescriptorSets(device, 1, &write, 0, NULL);
if (texture)
@@ -960,7 +957,7 @@ void vulkan_transition_texture(vk_t *vk, VkCommandBuffer cmd, struct vk_texture
switch (texture->type)
{
case VULKAN_TEXTURE_STREAMED:
- vulkan_image_layout_transition(vk, cmd, texture->image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(cmd, texture->image,
texture->layout, VK_IMAGE_LAYOUT_GENERAL,
VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_HOST_BIT,
@@ -1015,10 +1012,11 @@ void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
/* Upload descriptors */
{
+ unsigned i;
VkDescriptorSet set;
-
/* Upload UBO */
struct vk_buffer_range range;
+
if (!vulkan_buffer_chain_alloc(vk->context, &vk->chain->ubo,
call->uniform_size, &range))
return;
@@ -1038,13 +1036,15 @@ void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call)
call->texture,
call->sampler);
- vkCmdBindDescriptorSets(vk->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
+ vkCmdBindDescriptorSets(vk->cmd,
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
vk->pipelines.layout, 0,
1, &set, 0, NULL);
- vk->tracker.view = VK_NULL_HANDLE;
+ vk->tracker.view = VK_NULL_HANDLE;
vk->tracker.sampler = VK_NULL_HANDLE;
- memset(&vk->tracker.mvp, 0, sizeof(vk->tracker.mvp));
+ for (i = 0; i < 16; i++)
+ vk->tracker.mvp.data[i] = 0.0f;
}
/* VBO is already uploaded. */
@@ -1139,83 +1139,29 @@ void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad)
vkCmdDraw(vk->cmd, 6, 1, 0, 0);
}
-void vulkan_image_layout_transition(
- vk_t *vk,
- VkCommandBuffer cmd, VkImage image,
- VkImageLayout old_layout,
- VkImageLayout new_layout,
- VkAccessFlags srcAccess,
- VkAccessFlags dstAccess,
- VkPipelineStageFlags srcStages,
- VkPipelineStageFlags dstStages)
-{
- VkImageMemoryBarrier barrier =
- { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
-
- barrier.srcAccessMask = srcAccess;
- barrier.dstAccessMask = dstAccess;
- barrier.oldLayout = old_layout;
- barrier.newLayout = new_layout;
- barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- barrier.image = image;
- barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
- barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- vkCmdPipelineBarrier(cmd,
- srcStages,
- dstStages,
- 0,
- 0, NULL,
- 0, NULL,
- 1, &barrier);
-}
-
-void vulkan_image_layout_transition_levels(
- VkCommandBuffer cmd, VkImage image, uint32_t levels,
- VkImageLayout old_layout, VkImageLayout new_layout,
- VkAccessFlags src_access, VkAccessFlags dst_access,
- VkPipelineStageFlags src_stages, VkPipelineStageFlags dst_stages)
-{
- VkImageMemoryBarrier barrier = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
-
- barrier.srcAccessMask = src_access;
- barrier.dstAccessMask = dst_access;
- barrier.oldLayout = old_layout;
- barrier.newLayout = new_layout;
- barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- barrier.image = image;
- barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- barrier.subresourceRange.levelCount = levels;
- barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
-
- vkCmdPipelineBarrier(cmd,
- src_stages,
- dst_stages,
- false,
- 0, NULL,
- 0, NULL,
- 1, &barrier);
-}
-
struct vk_buffer vulkan_create_buffer(
const struct vulkan_context *context,
size_t size, VkBufferUsageFlags usage)
{
struct vk_buffer buffer;
VkMemoryRequirements mem_reqs;
- VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
- VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ VkBufferCreateInfo info;
+ VkMemoryAllocateInfo alloc;
+ info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
+ info.pNext = NULL;
+ info.flags = 0;
info.size = size;
info.usage = usage;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+ info.queueFamilyIndexCount = 0;
+ info.pQueueFamilyIndices = NULL;
vkCreateBuffer(context->device, &info, NULL, &buffer.buffer);
vkGetBufferMemoryRequirements(context->device, buffer.buffer, &mem_reqs);
+ alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ alloc.pNext = NULL;
alloc.allocationSize = mem_reqs.size;
alloc.memoryTypeIndex = vulkan_find_memory_type(
&context->memory_properties,
@@ -1225,7 +1171,7 @@ struct vk_buffer vulkan_create_buffer(
vkAllocateMemory(context->device, &alloc, NULL, &buffer.memory);
vkBindBufferMemory(context->device, buffer.buffer, buffer.memory, 0);
- buffer.size = size;
+ buffer.size = size;
vkMapMemory(context->device,
buffer.memory, 0, buffer.size, 0, &buffer.mapped);
@@ -1249,24 +1195,30 @@ static struct vk_descriptor_pool *vulkan_alloc_descriptor_pool(
const struct vk_descriptor_manager *manager)
{
unsigned i;
- VkDescriptorPoolCreateInfo pool_info = {
- VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
- VkDescriptorSetAllocateInfo alloc_info = {
- VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO };
-
+ VkDescriptorPoolCreateInfo pool_info;
+ VkDescriptorSetAllocateInfo alloc_info;
struct vk_descriptor_pool *pool =
- (struct vk_descriptor_pool*)calloc(1, sizeof(*pool));
+ (struct vk_descriptor_pool*)malloc(sizeof(*pool));
if (!pool)
return NULL;
+ pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ pool_info.pNext = NULL;
+ pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
pool_info.maxSets = VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS;
pool_info.poolSizeCount = manager->num_sizes;
pool_info.pPoolSizes = manager->sizes;
- pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
+
+ pool->pool = VK_NULL_HANDLE;
+ for (i = 0; i < VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS; i++)
+ pool->sets[i] = VK_NULL_HANDLE;
+ pool->next = NULL;
vkCreateDescriptorPool(device, &pool_info, NULL, &pool->pool);
/* Just allocate all descriptor sets up front. */
+ alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ alloc_info.pNext = NULL;
alloc_info.descriptorPool = pool->pool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &manager->set_layout;
@@ -1304,12 +1256,22 @@ struct vk_descriptor_manager vulkan_create_descriptor_manager(
unsigned num_sizes,
VkDescriptorSetLayout set_layout)
{
+ unsigned i;
struct vk_descriptor_manager manager;
- memset(&manager, 0, sizeof(manager));
+
retro_assert(num_sizes <= VULKAN_MAX_DESCRIPTOR_POOL_SIZES);
+
+ manager.current = NULL;
+ manager.count = 0;
+
+ for (i = 0; i < VULKAN_MAX_DESCRIPTOR_POOL_SIZES; i++)
+ {
+ manager.sizes[i].type = VK_DESCRIPTOR_TYPE_SAMPLER;
+ manager.sizes[i].descriptorCount = 0;
+ }
memcpy(manager.sizes, sizes, num_sizes * sizeof(*sizes));
- manager.num_sizes = num_sizes;
manager.set_layout = set_layout;
+ manager.num_sizes = num_sizes;
manager.head = vulkan_alloc_descriptor_pool(device, &manager);
retro_assert(manager.head);
@@ -1366,12 +1328,13 @@ static struct vk_buffer_node *vulkan_buffer_chain_alloc_node(
size_t size, VkBufferUsageFlags usage)
{
struct vk_buffer_node *node = (struct vk_buffer_node*)
- calloc(1, sizeof(*node));
+ malloc(sizeof(*node));
if (!node)
return NULL;
node->buffer = vulkan_create_buffer(
context, size, usage);
+ node->next = NULL;
return node;
}
@@ -2559,7 +2522,7 @@ static void vulkan_destroy_swapchain(gfx_ctx_vulkan_data_t *vk)
vkDeviceWaitIdle(vk->context.device);
vkDestroySwapchainKHR(vk->context.device, vk->swapchain, NULL);
memset(vk->context.swapchain_images, 0, sizeof(vk->context.swapchain_images));
- vk->swapchain = VK_NULL_HANDLE;
+ vk->swapchain = VK_NULL_HANDLE;
vk->context.has_acquired_swapchain = false;
}
@@ -2597,7 +2560,7 @@ static void vulkan_destroy_swapchain(gfx_ctx_vulkan_data_t *vk)
void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index)
{
- VkPresentInfoKHR present = { VK_STRUCTURE_TYPE_PRESENT_INFO_KHR };
+ VkPresentInfoKHR present;
VkResult result = VK_SUCCESS;
VkResult err = VK_SUCCESS;
@@ -2612,12 +2575,14 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index)
return;
}
+ present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
+ present.pNext = NULL;
+ present.waitSemaphoreCount = 1;
+ present.pWaitSemaphores = &vk->context.swapchain_semaphores[index];
present.swapchainCount = 1;
present.pSwapchains = &vk->swapchain;
present.pImageIndices = &index;
present.pResults = &result;
- present.waitSemaphoreCount = 1;
- present.pWaitSemaphores = &vk->context.swapchain_semaphores[index];
/* Better hope QueuePresent doesn't block D: */
#ifdef HAVE_THREADS
@@ -2736,14 +2701,20 @@ static void vulkan_acquire_clear_fences(gfx_ctx_vulkan_data_t *vk)
static VkSemaphore vulkan_get_wsi_acquire_semaphore(struct vulkan_context *ctx)
{
+ VkSemaphore sem;
+
if (ctx->num_recycled_acquire_semaphores == 0)
{
- VkSemaphoreCreateInfo sem_info = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
+ VkSemaphoreCreateInfo sem_info;
+
+ sem_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ sem_info.pNext = NULL;
+ sem_info.flags = 0;
vkCreateSemaphore(ctx->device, &sem_info, NULL,
&ctx->swapchain_recycled_semaphores[ctx->num_recycled_acquire_semaphores++]);
}
- VkSemaphore sem =
+ sem =
ctx->swapchain_recycled_semaphores[--ctx->num_recycled_acquire_semaphores];
ctx->swapchain_recycled_semaphores[ctx->num_recycled_acquire_semaphores] =
VK_NULL_HANDLE;
@@ -2752,16 +2723,21 @@ static VkSemaphore vulkan_get_wsi_acquire_semaphore(struct vulkan_context *ctx)
static void vulkan_acquire_wait_fences(gfx_ctx_vulkan_data_t *vk)
{
- VkFenceCreateInfo fence_info =
- { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
+ unsigned index;
+ VkFenceCreateInfo fence_info;
+ VkFence *next_fence = NULL;
+
+ fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ fence_info.pNext = NULL;
+ fence_info.flags = 0;
/* Decouples the frame fence index from swapchain index. */
vk->context.current_frame_index =
(vk->context.current_frame_index + 1) %
vk->context.num_swapchain_images;
- unsigned index = vk->context.current_frame_index;
- VkFence *next_fence = &vk->context.swapchain_fences[index];
+ index = vk->context.current_frame_index;
+ next_fence = &vk->context.swapchain_fences[index];
if (*next_fence != VK_NULL_HANDLE)
{
@@ -2798,14 +2774,20 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)
{
unsigned index;
VkResult err;
- VkFence fence = VK_NULL_HANDLE;
- VkSemaphore semaphore = VK_NULL_HANDLE;
- VkFenceCreateInfo fence_info =
- { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
- VkSemaphoreCreateInfo sem_info =
- { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
+ VkFenceCreateInfo fence_info;
+ VkSemaphoreCreateInfo sem_info;
+ VkFence fence = VK_NULL_HANDLE;
+ VkSemaphore semaphore = VK_NULL_HANDLE;
bool is_retrying = false;
+ fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ fence_info.pNext = NULL;
+ fence_info.flags = 0;
+
+ sem_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ sem_info.pNext = NULL;
+ sem_info.flags = 0;
+
retry:
if (vk->swapchain == VK_NULL_HANDLE)
{
@@ -2821,10 +2803,10 @@ retry:
{
/* We still don't have a swapchain, so just fake it ... */
vk->context.current_swapchain_index = 0;
- vk->context.current_frame_index = 0;
+ vk->context.current_frame_index = 0;
vulkan_acquire_clear_fences(vk);
vulkan_acquire_wait_fences(vk);
- vk->context.invalid_swapchain = true;
+ vk->context.invalid_swapchain = true;
return;
}
}
@@ -2930,10 +2912,8 @@ retry:
index = vk->context.current_swapchain_index;
if (vk->context.swapchain_semaphores[index] == VK_NULL_HANDLE)
- {
vkCreateSemaphore(vk->context.device, &sem_info,
NULL, &vk->context.swapchain_semaphores[index]);
- }
vulkan_acquire_wait_fences(vk);
}
@@ -2945,6 +2925,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
uint32_t format_count;
uint32_t present_mode_count;
uint32_t desired_swapchain_images;
+ VkResult res;
VkSurfaceCapabilitiesKHR surface_properties;
VkSurfaceFormatKHR formats[256];
VkPresentModeKHR present_modes[16];
@@ -2957,7 +2938,6 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
settings_t *settings = config_get_ptr();
VkCompositeAlphaFlagBitsKHR composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
- VkResult res;
vkDeviceWaitIdle(vk->context.device);
vulkan_acquire_clear_fences(vk);
@@ -3264,22 +3244,33 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
void vulkan_initialize_render_pass(VkDevice device, VkFormat format,
VkRenderPass *render_pass)
{
- VkRenderPassCreateInfo rp_info = {
- VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO };
- VkAttachmentReference color_ref = { 0,
- VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
- VkAttachmentDescription attachment = {0};
+ VkAttachmentReference color_ref;
+ VkRenderPassCreateInfo rp_info;
+ VkAttachmentDescription attachment;
VkSubpassDescription subpass = {0};
+ rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ rp_info.pNext = NULL;
+ rp_info.flags = 0;
+ rp_info.attachmentCount = 1;
+ rp_info.pAttachments = &attachment;
+ rp_info.subpassCount = 1;
+ rp_info.pSubpasses = &subpass;
+ rp_info.dependencyCount = 0;
+ rp_info.pDependencies = NULL;
+
+ color_ref.attachment = 0;
+ color_ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
/* We will always write to the entire framebuffer,
* so we don't really need to clear. */
+ attachment.flags = 0;
attachment.format = format;
attachment.samples = VK_SAMPLE_COUNT_1_BIT;
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
-
attachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@@ -3287,11 +3278,6 @@ void vulkan_initialize_render_pass(VkDevice device, VkFormat format,
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &color_ref;
- rp_info.attachmentCount = 1;
- rp_info.pAttachments = &attachment;
- rp_info.subpassCount = 1;
- rp_info.pSubpasses = &subpass;
-
vkCreateRenderPass(device, &rp_info, NULL, render_pass);
}
@@ -3303,18 +3289,23 @@ void vulkan_set_uniform_buffer(
VkDeviceSize offset,
VkDeviceSize range)
{
+ VkWriteDescriptorSet write;
VkDescriptorBufferInfo buffer_info;
- VkWriteDescriptorSet write = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET };
buffer_info.buffer = buffer;
buffer_info.offset = offset;
buffer_info.range = range;
+ write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ write.pNext = NULL;
write.dstSet = set;
write.dstBinding = binding;
+ write.dstArrayElement = 0;
write.descriptorCount = 1;
write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ write.pImageInfo = NULL;
write.pBufferInfo = &buffer_info;
+ write.pTexelBufferView = NULL;
vkUpdateDescriptorSets(device, 1, &write, 0, NULL);
}
@@ -3478,27 +3469,35 @@ void vulkan_framebuffer_copy(VkImage image,
{
VkImageCopy region;
- vulkan_image_layout_transition_levels(cmd, image,VK_REMAINING_MIP_LEVELS,
+ VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, image,VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
- VK_PIPELINE_STAGE_TRANSFER_BIT);
+ VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_QUEUE_FAMILY_IGNORED,
+ VK_QUEUE_FAMILY_IGNORED);
- memset(®ion, 0, sizeof(region));
-
- region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.srcSubresource.layerCount = 1;
- region.dstSubresource = region.srcSubresource;
- region.extent.width = size.width;
- region.extent.height = size.height;
- region.extent.depth = 1;
+ region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ region.srcSubresource.mipLevel = 0;
+ region.srcSubresource.baseArrayLayer = 0;
+ region.srcSubresource.layerCount = 1;
+ region.srcOffset.x = 0;
+ region.srcOffset.y = 0;
+ region.srcOffset.z = 0;
+ region.dstSubresource = region.srcSubresource;
+ region.dstOffset.x = 0;
+ region.dstOffset.y = 0;
+ region.dstOffset.z = 0;
+ region.extent.width = size.width;
+ region.extent.height = size.height;
+ region.extent.depth = 1;
vkCmdCopyImage(cmd,
src_image, src_layout,
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, ®ion);
- vulkan_image_layout_transition_levels(cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -3506,7 +3505,9 @@ void vulkan_framebuffer_copy(VkImage image,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
- VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+ VK_QUEUE_FAMILY_IGNORED,
+ VK_QUEUE_FAMILY_IGNORED);
}
void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
@@ -3514,7 +3515,7 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
VkClearColorValue color;
VkImageSubresourceRange range;
- vulkan_image_layout_transition_levels(cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_UNDEFINED,
@@ -3522,14 +3523,19 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
- VK_PIPELINE_STAGE_TRANSFER_BIT);
+ VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_QUEUE_FAMILY_IGNORED,
+ VK_QUEUE_FAMILY_IGNORED);
- memset(&color, 0, sizeof(color));
- memset(&range, 0, sizeof(range));
-
- range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- range.levelCount = 1;
- range.layerCount = 1;
+ color.float32[0] = 0.0f;
+ color.float32[1] = 0.0f;
+ color.float32[2] = 0.0f;
+ color.float32[3] = 0.0f;
+ range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ range.baseMipLevel = 0;
+ range.levelCount = 1;
+ range.baseArrayLayer = 0;
+ range.layerCount = 1;
vkCmdClearColorImage(cmd,
image,
@@ -3538,7 +3544,7 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
1,
&range);
- vulkan_image_layout_transition_levels(cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@@ -3546,27 +3552,7 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
- VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
-}
-
-void vulkan_pass_set_texture(
- VkDevice device,
- VkDescriptorSet set, VkSampler sampler,
- unsigned binding,
- VkImageView imageView, VkImageLayout imageLayout)
-{
- VkDescriptorImageInfo image_info;
- VkWriteDescriptorSet write = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET };
-
- image_info.sampler = sampler;
- image_info.imageView = imageView;
- image_info.imageLayout = imageLayout;
-
- write.dstSet = set;
- write.dstBinding = binding;
- write.descriptorCount = 1;
- write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- write.pImageInfo = &image_info;
-
- vkUpdateDescriptorSets(device, 1, &write, 0, NULL);
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+ VK_QUEUE_FAMILY_IGNORED,
+ VK_QUEUE_FAMILY_IGNORED);
}
diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h
index 475d6afb7a..70362a1dcc 100644
--- a/gfx/common/vulkan_common.h
+++ b/gfx/common/vulkan_common.h
@@ -261,12 +261,6 @@ struct vk_buffer_chain vulkan_buffer_chain_init(
VkDeviceSize alignment,
VkBufferUsageFlags usage);
-#define VK_BUFFER_CHAIN_DISCARD(chain) \
-{ \
- chain->current = chain->head; \
- chain->offset = 0; \
-}
-
bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
struct vk_buffer_chain *chain, size_t size,
struct vk_buffer_range *range);
@@ -450,6 +444,89 @@ typedef struct vk
void *filter_chain;
} vk_t;
+#define VK_BUFFER_CHAIN_DISCARD(chain) \
+{ \
+ chain->current = chain->head; \
+ chain->offset = 0; \
+}
+
+#define VULKAN_SYNC_TEXTURE_TO_GPU(device, tex_memory) \
+{ \
+ VkMappedMemoryRange range; \
+ range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
+ range.pNext = NULL; \
+ range.memory = tex_memory; \
+ range.offset = 0; \
+ range.size = VK_WHOLE_SIZE; \
+ vkFlushMappedMemoryRanges(device, 1, &range); \
+}
+
+#define VULKAN_SYNC_TEXTURE_TO_CPU(device, tex_memory) \
+{ \
+ VkMappedMemoryRange range; \
+ range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
+ range.pNext = NULL; \
+ range.memory = tex_memory; \
+ range.offset = 0; \
+ range.size = VK_WHOLE_SIZE; \
+ vkInvalidateMappedMemoryRanges(device, 1, &range); \
+}
+
+#define VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, levels, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages, src_queue_family_idx, dst_queue_family_idx) \
+{ \
+ VkImageMemoryBarrier barrier; \
+ barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; \
+ barrier.pNext = NULL; \
+ barrier.srcAccessMask = src_access; \
+ barrier.dstAccessMask = dst_access; \
+ barrier.oldLayout = old_layout; \
+ barrier.newLayout = new_layout; \
+ barrier.srcQueueFamilyIndex = src_queue_family_idx; \
+ barrier.dstQueueFamilyIndex = dst_queue_family_idx; \
+ barrier.image = img; \
+ barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; \
+ barrier.subresourceRange.baseMipLevel = 0; \
+ barrier.subresourceRange.levelCount = levels; \
+ barrier.subresourceRange.baseArrayLayer = 0; \
+ barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; \
+ vkCmdPipelineBarrier(cmd, src_stages, dst_stages, 0, 0, NULL, 0, NULL, 1, &barrier); \
+}
+
+#define VULKAN_TRANSFER_IMAGE_OWNERSHIP(cmd, img, layout, src_stages, dst_stages, src_queue_family, dst_queue_family) VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, VK_REMAINING_MIP_LEVELS, layout, layout, 0, 0, src_stages, dst_stages, src_queue_family, dst_queue_family)
+
+#define VULKAN_IMAGE_LAYOUT_TRANSITION(cmd, img, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages) VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, VK_REMAINING_MIP_LEVELS, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED)
+
+#define VK_DESCRIPTOR_MANAGER_RESTART(manager) \
+{ \
+ manager->current = manager->head; \
+ manager->count = 0; \
+}
+
+#define VK_MAP_PERSISTENT_TEXTURE(device, texture) \
+{ \
+ vkMapMemory(device, texture->memory, texture->offset, texture->size, 0, &texture->mapped); \
+}
+
+#define VULKAN_PASS_SET_TEXTURE(device, set, _sampler, binding, image_view, image_layout) \
+{ \
+ VkDescriptorImageInfo image_info; \
+ VkWriteDescriptorSet write; \
+ image_info.sampler = _sampler; \
+ image_info.imageView = image_view; \
+ image_info.imageLayout = image_layout; \
+ write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; \
+ write.pNext = NULL; \
+ write.dstSet = set; \
+ write.dstBinding = binding; \
+ write.dstArrayElement = 0; \
+ write.descriptorCount = 1; \
+ write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; \
+ write.pImageInfo = &image_info; \
+ write.pBufferInfo = NULL; \
+ write.pTexelBufferView = NULL; \
+ vkUpdateDescriptorSets(device, 1, &write, 0, NULL); \
+}
+
uint32_t vulkan_find_memory_type(
const VkPhysicalDeviceMemoryProperties *mem_props,
uint32_t device_reqs, uint32_t host_reqs);
@@ -466,18 +543,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk,
const void *initial, const VkComponentMapping *swizzle,
enum vk_texture_type type);
-void vulkan_sync_texture_to_gpu(vk_t *vk, const struct vk_texture *tex);
-void vulkan_sync_texture_to_cpu(vk_t *vk, const struct vk_texture *tex);
-
void vulkan_transition_texture(vk_t *vk, VkCommandBuffer cmd, struct vk_texture *texture);
-void vulkan_transfer_image_ownership(VkCommandBuffer cmd,
- VkImage image, VkImageLayout layout,
- VkPipelineStageFlags src_stages,
- VkPipelineStageFlags dst_stages,
- uint32_t src_queue_family,
- uint32_t dst_queue_family);
-
void vulkan_destroy_texture(
VkDevice device,
struct vk_texture *tex);
@@ -494,18 +561,6 @@ void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad);
*/
void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call);
-void vulkan_image_layout_transition(vk_t *vk,
- VkCommandBuffer cmd, VkImage image,
- VkImageLayout old_layout, VkImageLayout new_layout,
- VkAccessFlags srcAccess, VkAccessFlags dstAccess,
- VkPipelineStageFlags srcStages, VkPipelineStageFlags dstStages);
-
-void vulkan_image_layout_transition_levels(
- VkCommandBuffer cmd, VkImage image, uint32_t levels,
- VkImageLayout old_layout, VkImageLayout new_layout,
- VkAccessFlags src_access, VkAccessFlags dst_access,
- VkPipelineStageFlags src_stages, VkPipelineStageFlags dst_stages);
-
static INLINE unsigned vulkan_format_to_bpp(VkFormat format)
{
switch (format)
@@ -564,17 +619,6 @@ VkDescriptorSet vulkan_descriptor_manager_alloc(
VkDevice device,
struct vk_descriptor_manager *manager);
-#define VK_DESCRIPTOR_MANAGER_RESTART(manager) \
-{ \
- manager->current = manager->head; \
- manager->count = 0; \
-}
-
-#define VK_MAP_PERSISTENT_TEXTURE(device, texture) \
-{ \
- vkMapMemory(device, texture->memory, texture->offset, texture->size, 0, &texture->mapped); \
-}
-
struct vk_descriptor_manager vulkan_create_descriptor_manager(
VkDevice device,
const VkDescriptorPoolSize *sizes, unsigned num_sizes,
@@ -630,12 +674,6 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd);
void vulkan_initialize_render_pass(VkDevice device,
VkFormat format, VkRenderPass *render_pass);
-void vulkan_pass_set_texture(
- VkDevice device,
- VkDescriptorSet set, VkSampler sampler,
- unsigned binding,
- VkImageView imageView, VkImageLayout imageLayout);
-
RETRO_END_DECLS
#endif
diff --git a/gfx/common/wayland_common.h b/gfx/common/wayland_common.h
deleted file mode 100644
index 941da1defa..0000000000
--- a/gfx/common/wayland_common.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* RetroArch - A frontend for libretro.
- * Copyright (C) 2011-2017 - Daniel De Matteis
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
- */
-
-#ifndef WAYLAND_COMMON_H__
-#define WAYLAND_COMMON_H__
-
-#include
-#include
-
-#include
-#include
-#include
-
-#include "../../input/input_driver.h"
-
-#define UDEV_KEY_MAX 0x2ff
-#define UDEV_MAX_KEYS (UDEV_KEY_MAX + 7) / 8
-
-#define MAX_TOUCHES 16
-
-typedef struct
-{
- bool active;
- int16_t x;
- int16_t y;
-} wayland_touch_data_t;
-
-typedef struct input_ctx_wayland_data
-{
- /* Wayland uses Linux keysyms. */
- uint8_t key_state[UDEV_MAX_KEYS];
- bool keyboard_focus;
-
- struct
- {
- int last_x, last_y;
- int x, y;
- int delta_x, delta_y;
- bool last_valid;
- bool focus;
- bool left, right, middle;
- } mouse;
-
- struct wl_display *dpy;
- int fd;
-
- const input_device_driver_t *joypad;
- bool blocked;
-
- wayland_touch_data_t touches[MAX_TOUCHES];
-
-} input_ctx_wayland_data_t;
-
-#endif
diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c
index f9c4fb8235..b4d8469c11 100644
--- a/gfx/common/win32_common.c
+++ b/gfx/common/win32_common.c
@@ -230,39 +230,6 @@ typedef struct DISPLAYCONFIG_PATH_INFO_CUSTOM
typedef LONG (WINAPI *QUERYDISPLAYCONFIG)(UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO_CUSTOM*, UINT32*, DISPLAYCONFIG_MODE_INFO_CUSTOM*, UINT32*);
typedef LONG (WINAPI *GETDISPLAYCONFIGBUFFERSIZES)(UINT32, UINT32*, UINT32*);
-bool g_win32_restore_desktop = false;
-static bool taskbar_is_created = false;
-bool g_win32_inited = false;
-
-typedef struct win32_common_state
-{
- int pos_x;
- int pos_y;
- unsigned pos_width;
- unsigned pos_height;
- unsigned taskbar_message;
- bool quit;
- unsigned monitor_count;
- bool resized;
-} win32_common_state_t;
-
-static win32_common_state_t win32_st =
-{
- CW_USEDEFAULT, /* pos_x */
- CW_USEDEFAULT, /* pos_y */
- 0, /* pos_width */
- 0, /* pos_height */
- 0, /* taskbar_message */
- false, /* quit */
- 0, /* monitor_count */
- false /* resized */
-};
-
-unsigned g_win32_resize_width = 0;
-unsigned g_win32_resize_height = 0;
-
-ui_window_win32_t main_window;
-
/* Power Request APIs */
#if !defined(_XBOX) && (_MSC_VER == 1310)
@@ -310,9 +277,45 @@ typedef REASON_CONTEXT POWER_REQUEST_CONTEXT, *PPOWER_REQUEST_CONTEXT, *LPPOWER_
#define INT_PTR_COMPAT INT_PTR
#endif
+
+/* TODO/FIXME - globals */
+bool g_win32_restore_desktop = false;
+static bool taskbar_is_created = false;
+bool g_win32_inited = false;
+
+unsigned g_win32_resize_width = 0;
+unsigned g_win32_resize_height = 0;
+
+ui_window_win32_t main_window;
+
static HMONITOR win32_monitor_last;
static HMONITOR win32_monitor_all[MAX_MONITORS];
+typedef struct win32_common_state
+{
+ int pos_x;
+ int pos_y;
+ unsigned pos_width;
+ unsigned pos_height;
+ unsigned taskbar_message;
+ bool quit;
+ unsigned monitor_count;
+ bool resized;
+} win32_common_state_t;
+
+static win32_common_state_t win32_st =
+{
+ CW_USEDEFAULT, /* pos_x */
+ CW_USEDEFAULT, /* pos_y */
+ 0, /* pos_width */
+ 0, /* pos_height */
+ 0, /* taskbar_message */
+ false, /* quit */
+ 0, /* monitor_count */
+ false /* resized */
+};
+
+
bool win32_taskbar_is_created(void)
{
return taskbar_is_created;
@@ -915,9 +918,6 @@ static LRESULT CALLBACK wnd_proc_common(
uint16_t mod = 0;
unsigned keycode = 0;
unsigned keysym = (lparam >> 16) & 0xff;
-#if _WIN32_WINNT >= 0x0501 /* XP */
- settings_t *settings = config_get_ptr();
-#endif
if (GetKeyState(VK_SHIFT) & 0x80)
mod |= RETROKMOD_SHIFT;
@@ -932,17 +932,20 @@ static LRESULT CALLBACK wnd_proc_common(
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80)
mod |= RETROKMOD_META;
-#if _WIN32_WINNT >= 0x0501 /* XP */
- if (settings &&
- string_is_equal(settings->arrays.input_driver, "raw"))
- keysym = (unsigned)wparam;
- else
-#endif
{
+ input_driver_t *driver = input_get_ptr();
+
+#if _WIN32_WINNT >= 0x0501 /* XP */
+#ifdef HAVE_WINRAWINPUT
+ if (driver == &input_winraw)
+ keysym = (unsigned)wparam;
+ else
+#endif
+#endif
#ifdef HAVE_DINPUT
- /* extended keys will map to dinput if the high bit is set */
- if (input_get_ptr() == &input_dinput && (lparam >> 24 & 0x1))
- keysym |= 0x80;
+ /* extended keys will map to dinput if the high bit is set */
+ if (driver == &input_dinput && (lparam >> 24 & 0x1))
+ keysym |= 0x80;
#else
/* fix key binding issues on winraw when DirectInput is not available */
#endif
@@ -1066,7 +1069,7 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
}
#endif
-#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) || defined(HAVE_VULKAN)
+#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
@@ -1089,6 +1092,7 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
taskbar_is_created = true;
#endif
#ifdef HAVE_DINPUT
+ if (input_get_ptr() == &input_dinput)
{
void* input_data = input_get_data();
if (input_data && dinput_handle_message(input_data,
@@ -1129,6 +1133,70 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
}
#endif
+#ifdef HAVE_VULKAN
+LRESULT CALLBACK WndProcVK(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam)
+{
+ LRESULT ret;
+ bool quit = false;
+ win32_common_state_t *g_win32 = (win32_common_state_t*)&win32_st;
+
+ switch (message)
+ {
+ case WM_MOUSEMOVE:
+ case WM_POINTERDOWN:
+ case WM_POINTERUP:
+ case WM_POINTERUPDATE:
+ case WM_DEVICECHANGE:
+ case WM_MOUSEWHEEL:
+ case WM_MOUSEHWHEEL:
+ case WM_NCLBUTTONDBLCLK:
+#if _WIN32_WINNT >= 0x0500 /* 2K */
+ if (g_win32->taskbar_message && message == g_win32->taskbar_message)
+ taskbar_is_created = true;
+#endif
+#ifdef HAVE_DINPUT
+ if (input_get_ptr() == &input_dinput)
+ {
+ void* input_data = input_get_data();
+ if (input_data && dinput_handle_message(input_data,
+ message, wparam, lparam))
+ return 0;
+ }
+#endif
+ break;
+ case WM_DROPFILES:
+ case WM_SYSCOMMAND:
+ case WM_CHAR:
+ case WM_KEYDOWN:
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ case WM_SYSKEYDOWN:
+ case WM_CLOSE:
+ case WM_DESTROY:
+ case WM_QUIT:
+ case WM_MOVE:
+ case WM_SIZE:
+ case WM_COMMAND:
+ ret = wnd_proc_common(&quit, hwnd, message, wparam, lparam);
+ if (quit)
+ return ret;
+#if _WIN32_WINNT >= 0x0500 /* 2K */
+ if (g_win32->taskbar_message && message == g_win32->taskbar_message)
+ taskbar_is_created = true;
+#endif
+ break;
+ case WM_CREATE:
+ create_vk_context(hwnd, &g_win32->quit);
+ if (DragAcceptFiles_func)
+ DragAcceptFiles_func(hwnd, true);
+ return 0;
+ }
+
+ return DefWindowProc(hwnd, message, wparam, lparam);
+}
+#endif
+
#ifdef HAVE_GDI
LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
@@ -1152,6 +1220,7 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
taskbar_is_created = true;
#endif
#ifdef HAVE_DINPUT
+ if (input_get_ptr() == &input_dinput)
{
void* input_data = input_get_data();
if (input_data && dinput_handle_message(input_data,
@@ -1381,7 +1450,8 @@ void win32_show_cursor(void *data, bool state)
#endif
}
-void win32_check_window(bool *quit, bool *resize,
+void win32_check_window(void *data,
+ bool *quit, bool *resize,
unsigned *width, unsigned *height)
{
#if !defined(_XBOX)
diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h
index 4f8b700228..d8b7fc43b8 100644
--- a/gfx/common/win32_common.h
+++ b/gfx/common/win32_common.h
@@ -60,6 +60,8 @@ int win32_change_display_settings(const char *str, void *devmode_data,
void create_graphics_context(HWND hwnd, bool *quit);
+void create_vk_context(HWND hwnd, bool *quit);
+
void create_gdi_context(HWND hwnd, bool *quit);
bool win32_get_video_output(DEVMODE *dm, int mode, size_t len);
@@ -96,7 +98,8 @@ HWND win32_get_window(void);
bool win32_has_focus(void *data);
-void win32_check_window(bool *quit,
+void win32_check_window(void *data,
+ bool *quit,
bool *resize, unsigned *width, unsigned *height);
void win32_set_window(unsigned *width, unsigned *height,
@@ -124,11 +127,16 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam);
#endif
-#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) || defined(HAVE_VULKAN)
+#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam);
#endif
+#if defined(HAVE_VULKAN)
+LRESULT CALLBACK WndProcVK(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam);
+#endif
+
LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam);
diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c
index 5f5b302e6f..93c6e60c9a 100644
--- a/gfx/common/x11_common.c
+++ b/gfx/common/x11_common.c
@@ -59,6 +59,7 @@
#define V_DBLSCAN 0x20
+/* TODO/FIXME - globals */
static XF86VidModeModeInfo desktop_mode;
static bool xdg_screensaver_available = true;
bool g_x11_entered = false;
@@ -81,11 +82,11 @@ static XIC g_x11_xic;
static void x11_hide_mouse(Display *dpy, Window win)
{
- static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
Cursor no_ptr;
Pixmap bm_no;
XColor black, dummy;
- Colormap colormap = DefaultColormap(dpy, DefaultScreen(dpy));
+ static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
+ Colormap colormap = DefaultColormap(dpy, DefaultScreen(dpy));
if (!XAllocNamedColor(dpy, colormap, "black", &black, &dummy))
return;
diff --git a/gfx/common/xinerama_common.c b/gfx/common/xinerama_common.c
index 34879e8275..3db4d765de 100644
--- a/gfx/common/xinerama_common.c
+++ b/gfx/common/xinerama_common.c
@@ -30,7 +30,8 @@
#include "../../verbosity.h"
-static XineramaScreenInfo *xinerama_query_screens(Display *dpy, int *num_screens)
+static XineramaScreenInfo *xinerama_query_screens(
+ Display *dpy, int *num_screens)
{
int major, minor;
diff --git a/gfx/display_servers/dispserv_win32.c b/gfx/display_servers/dispserv_win32.c
index 6ba2c662a2..29416312ed 100644
--- a/gfx/display_servers/dispserv_win32.c
+++ b/gfx/display_servers/dispserv_win32.c
@@ -222,64 +222,70 @@ static bool win32_display_server_set_window_decorations(void *data, bool on)
static bool win32_display_server_set_resolution(void *data,
unsigned width, unsigned height, int int_hz, float hz, int center, int monitor_index, int xoffset)
{
- DEVMODE curDevmode;
- int iModeNum;
- int freq = int_hz;
- int depth = 0;
- dispserv_win32_t *serv = (dispserv_win32_t*)data;
+ DEVMODE dm = {0};
+ LONG res = 0;
+ unsigned i = 0;
+ unsigned curr_bpp = 0;
+#if _WIN32_WINNT >= 0x0500
+ unsigned curr_orientation = 0;
+#endif
+ dispserv_win32_t *serv = (dispserv_win32_t*)data;
if (!serv)
return false;
- win32_get_video_output(&curDevmode, -1, sizeof(curDevmode));
+ win32_get_video_output(&dm, -1, sizeof(dm));
if (serv->orig_width == 0)
- serv->orig_width = GetSystemMetrics(SM_CXSCREEN);
- serv->orig_refresh = curDevmode.dmDisplayFrequency;
+ serv->orig_width = GetSystemMetrics(SM_CXSCREEN);
if (serv->orig_height == 0)
- serv->orig_height = GetSystemMetrics(SM_CYSCREEN);
+ serv->orig_height = GetSystemMetrics(SM_CYSCREEN);
+ serv->orig_refresh = dm.dmDisplayFrequency;
/* Used to stop super resolution bug */
- if (width == curDevmode.dmPelsWidth)
- width = 0;
+ if (width == dm.dmPelsWidth)
+ width = 0;
if (width == 0)
- width = curDevmode.dmPelsWidth;
+ width = dm.dmPelsWidth;
if (height == 0)
- height = curDevmode.dmPelsHeight;
- if (depth == 0)
- depth = curDevmode.dmBitsPerPel;
- if (freq == 0)
- freq = curDevmode.dmDisplayFrequency;
+ height = dm.dmPelsHeight;
+ if (curr_bpp == 0)
+ curr_bpp = dm.dmBitsPerPel;
+ if (int_hz == 0)
+ int_hz = dm.dmDisplayFrequency;
+#if _WIN32_WINNT >= 0x0500
+ if (curr_orientation == 0)
+ curr_orientation = dm.dmDisplayOrientation;
+#endif
- for (iModeNum = 0;; iModeNum++)
+ for (i = 0; win32_get_video_output(&dm, i, sizeof(dm)); i++)
{
- LONG res;
- DEVMODE devmode;
-
- if (!win32_get_video_output(&devmode, iModeNum, sizeof(devmode)))
- break;
-
- if (devmode.dmPelsWidth != width)
+ if (dm.dmPelsWidth != width)
continue;
-
- if (devmode.dmPelsHeight != height)
+ if (dm.dmPelsHeight != height)
continue;
-
- if (devmode.dmBitsPerPel != depth)
+ if (dm.dmBitsPerPel != curr_bpp)
continue;
-
- if (devmode.dmDisplayFrequency != freq)
+ if (dm.dmDisplayFrequency != int_hz)
continue;
+#if _WIN32_WINNT >= 0x0500
+ if (dm.dmDisplayOrientation != curr_orientation)
+ continue;
+ if (dm.dmDisplayFixedOutput != DMDFO_DEFAULT)
+ continue;
+#endif
- devmode.dmFields |=
- DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
- res =
- win32_change_display_settings(NULL, &devmode, CDS_TEST);
+ dm.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
+#if _WIN32_WINNT >= 0x0500
+ dm.dmFields |= DM_DISPLAYORIENTATION;
+#endif
+
+ res = win32_change_display_settings(NULL, &dm, CDS_TEST);
switch (res)
{
case DISP_CHANGE_SUCCESSFUL:
- res = win32_change_display_settings(NULL, &devmode, 0);
+ res = win32_change_display_settings(NULL, &dm, 0);
switch (res)
{
case DISP_CHANGE_SUCCESSFUL:
@@ -300,31 +306,42 @@ static bool win32_display_server_set_resolution(void *data,
return true;
}
-void *win32_display_server_get_resolution_list(void *data,
- unsigned *len)
+static void *win32_display_server_get_resolution_list(
+ void *data, unsigned *len)
{
- DEVMODE dm;
- unsigned i, count = 0;
+ DEVMODE dm = {0};
+ unsigned i, j, count = 0;
unsigned curr_width = 0;
unsigned curr_height = 0;
unsigned curr_bpp = 0;
unsigned curr_refreshrate = 0;
+#if _WIN32_WINNT >= 0x0500
+ unsigned curr_orientation = 0;
+#endif
struct video_display_config *conf = NULL;
- for (i = 0;; i++)
- {
- if (!win32_get_video_output(&dm, i, sizeof(dm)))
- break;
-
- count++;
- }
-
- if (win32_get_video_output(&dm, -1, sizeof(dm)))
- {
+ if (win32_get_video_output(&dm, -1, sizeof(dm))) {
curr_width = dm.dmPelsWidth;
curr_height = dm.dmPelsHeight;
curr_bpp = dm.dmBitsPerPel;
curr_refreshrate = dm.dmDisplayFrequency;
+#if _WIN32_WINNT >= 0x0500
+ curr_orientation = dm.dmDisplayOrientation;
+#endif
+ }
+
+ for (i = 0; win32_get_video_output(&dm, i, sizeof(dm)); i++)
+ {
+ if (dm.dmBitsPerPel != curr_bpp)
+ continue;
+#if _WIN32_WINNT >= 0x0500
+ if (dm.dmDisplayOrientation != curr_orientation)
+ continue;
+ if (dm.dmDisplayFixedOutput != DMDFO_DEFAULT)
+ continue;
+#endif
+
+ count++;
}
*len = count;
@@ -333,24 +350,32 @@ void *win32_display_server_get_resolution_list(void *data,
if (!conf)
return NULL;
- for (i = 0;; i++)
+ for (i = 0, j = 0; win32_get_video_output(&dm, i, sizeof(dm)); i++)
{
- if (!win32_get_video_output(&dm, i, sizeof(dm)))
- break;
+ if (dm.dmBitsPerPel != curr_bpp)
+ continue;
+#if _WIN32_WINNT >= 0x0500
+ if (dm.dmDisplayOrientation != curr_orientation)
+ continue;
+ if (dm.dmDisplayFixedOutput != DMDFO_DEFAULT)
+ continue;
+#endif
- conf[i].width = dm.dmPelsWidth;
- conf[i].height = dm.dmPelsHeight;
- conf[i].bpp = dm.dmBitsPerPel;
- conf[i].refreshrate = dm.dmDisplayFrequency;
- conf[i].idx = i;
- conf[i].current = false;
+ conf[j].width = dm.dmPelsWidth;
+ conf[j].height = dm.dmPelsHeight;
+ conf[j].bpp = dm.dmBitsPerPel;
+ conf[j].refreshrate = dm.dmDisplayFrequency;
+ conf[j].idx = j;
+ conf[j].current = false;
- if ( (conf[i].width == curr_width)
- && (conf[i].height == curr_height)
- && (conf[i].refreshrate == curr_refreshrate)
- && (conf[i].bpp == curr_bpp)
+ if ( (conf[j].width == curr_width)
+ && (conf[j].height == curr_height)
+ && (conf[j].bpp == curr_bpp)
+ && (conf[j].refreshrate == curr_refreshrate)
)
- conf[i].current = true;
+ conf[j].current = true;
+
+ j++;
}
return conf;
diff --git a/gfx/display_servers/dispserv_x11.c b/gfx/display_servers/dispserv_x11.c
index c37b84fb13..15f94ef8e3 100644
--- a/gfx/display_servers/dispserv_x11.c
+++ b/gfx/display_servers/dispserv_x11.c
@@ -40,6 +40,7 @@
#include "../video_crt_switch.h" /* needed to set aspect for low res in linux */
#ifdef HAVE_XRANDR
+/* TODO/FIXME - static globals */
static char xrandr[1024] = {0};
static char crt_name[16] = {0};
static int crt_name_id = 0;
diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c
index aa374ce82d..1a77643e94 100644
--- a/gfx/drivers/ctr_gfx.c
+++ b/gfx/drivers/ctr_gfx.c
@@ -582,7 +582,7 @@ static bool ctr_frame(void* data, const void* frame,
#if 0
ctr->vsync_event_pending = true;
#endif
- while(ctr->vsync_event_pending)
+ while (ctr->vsync_event_pending)
{
task_queue_check();
svcSleepThread(0);
diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c
index e29aa60872..7279135a3e 100644
--- a/gfx/drivers/d3d10.c
+++ b/gfx/drivers/d3d10.c
@@ -31,7 +31,9 @@
#include "../../verbosity.h"
#include "../../configuration.h"
#include "../../retroarch.h"
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#include "../font_driver.h"
#include "../common/d3d_common.h"
@@ -1339,7 +1341,11 @@ static bool d3d10_gfx_frame(
else
d3d10->pass[i].frame_count = frame_count;
+#ifdef HAVE_REWIND
d3d10->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
+#else
+ d3d10->pass[i].frame_direction = 1;
+#endif
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
{
@@ -1546,7 +1552,9 @@ static bool d3d10_gfx_alive(void* data)
bool quit;
d3d10_video_t* d3d10 = (d3d10_video_t*)data;
- win32_check_window(&quit, &d3d10->resize_chain, &d3d10->vp.full_width, &d3d10->vp.full_height);
+ win32_check_window(NULL,
+ &quit, &d3d10->resize_chain, &d3d10->vp.full_width,
+ &d3d10->vp.full_height);
if ( d3d10->resize_chain
&& d3d10->vp.full_width != 0
diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c
index afa10d162a..84e1381dd7 100644
--- a/gfx/drivers/d3d11.c
+++ b/gfx/drivers/d3d11.c
@@ -46,7 +46,9 @@
#include "../../menu/menu_driver.h"
#include "../video_shader_parse.h"
#include "../drivers_shader/slang_process.h"
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#include "../common/d3d_common.h"
#include "../common/d3d11_common.h"
@@ -1419,7 +1421,11 @@ static bool d3d11_gfx_frame(
else
d3d11->pass[i].frame_count = frame_count;
+#ifdef HAVE_REWIND
d3d11->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
+#else
+ d3d11->pass[i].frame_direction = 1;
+#endif
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
{
@@ -1620,9 +1626,15 @@ static bool d3d11_gfx_alive(void* data)
bool quit;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
- win32_check_window(&quit, &d3d11->resize_chain, &d3d11->vp.full_width, &d3d11->vp.full_height);
+ win32_check_window(NULL,
+ &quit,
+ &d3d11->resize_chain,
+ &d3d11->vp.full_width,
+ &d3d11->vp.full_height);
- if (d3d11->resize_chain && d3d11->vp.full_width != 0 && d3d11->vp.full_height != 0)
+ if ( d3d11->resize_chain
+ && d3d11->vp.full_width != 0
+ && d3d11->vp.full_height != 0)
video_driver_set_size(d3d11->vp.full_width, d3d11->vp.full_height);
return !quit;
diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c
index 1b51818d7b..5a4989ff7b 100644
--- a/gfx/drivers/d3d12.c
+++ b/gfx/drivers/d3d12.c
@@ -33,7 +33,9 @@
#include "../../verbosity.h"
#include "../../configuration.h"
#include "../../retroarch.h"
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#ifdef HAVE_MENU
#include "../../menu/menu_driver.h"
@@ -1316,7 +1318,11 @@ static bool d3d12_gfx_frame(
else
d3d12->pass[i].frame_count = frame_count;
+#ifdef HAVE_REWIND
d3d12->pass[i].frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
+#else
+ d3d12->pass[i].frame_direction = 1;
+#endif
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
{
@@ -1613,7 +1619,11 @@ static bool d3d12_gfx_alive(void* data)
bool quit;
d3d12_video_t* d3d12 = (d3d12_video_t*)data;
- win32_check_window(&quit, &d3d12->resize_chain, &d3d12->vp.full_width, &d3d12->vp.full_height);
+ win32_check_window(NULL,
+ &quit,
+ &d3d12->resize_chain,
+ &d3d12->vp.full_width,
+ &d3d12->vp.full_height);
if ( d3d12->resize_chain
&& d3d12->vp.full_width != 0
diff --git a/gfx/drivers/d3d8.c b/gfx/drivers/d3d8.c
index 1e3ca02e73..f384539215 100644
--- a/gfx/drivers/d3d8.c
+++ b/gfx/drivers/d3d8.c
@@ -1046,9 +1046,7 @@ static bool d3d8_alive(void *data)
/* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height);
-#ifndef _XBOX
- win32_check_window(&quit, &resize, &temp_width, &temp_height);
-#endif
+ win32_check_window(NULL, &quit, &resize, &temp_width, &temp_height);
if (quit)
d3d->quitting = quit;
diff --git a/gfx/drivers/d3d9.c b/gfx/drivers/d3d9.c
index 50117403ac..27da553843 100644
--- a/gfx/drivers/d3d9.c
+++ b/gfx/drivers/d3d9.c
@@ -1057,9 +1057,7 @@ static bool d3d9_alive(void *data)
/* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height);
-#ifndef _XBOX
- win32_check_window(&quit, &resize, &temp_width, &temp_height);
-#endif
+ win32_check_window(NULL, &quit, &resize, &temp_width, &temp_height);
if (quit)
d3d->quitting = quit;
diff --git a/gfx/drivers/fpga_gfx.c b/gfx/drivers/fpga_gfx.c
index 2e6ebd7c58..123a968a7a 100644
--- a/gfx/drivers/fpga_gfx.c
+++ b/gfx/drivers/fpga_gfx.c
@@ -103,13 +103,7 @@ static void fpga_gfx_create(fpga_t *fpga)
static void *fpga_gfx_init(const video_info_t *video,
const input_driver_t **input, void **input_data)
{
- unsigned full_x, full_y;
- gfx_ctx_input_t inp;
- gfx_ctx_mode_t mode;
const gfx_ctx_driver_t *ctx_driver = NULL;
- unsigned win_width = 0, win_height = 0;
- unsigned temp_width = 0, temp_height = 0;
- settings_t *settings = config_get_ptr();
fpga_t *fpga = (fpga_t*)calloc(1, sizeof(*fpga));
*input = NULL;
@@ -128,71 +122,11 @@ static void *fpga_gfx_init(const video_info_t *video,
fpga_gfx_create(fpga);
- ctx_driver = video_context_driver_init_first(fpga,
- settings->arrays.video_context_driver,
- GFX_CTX_FPGA_API, 1, 0, false);
- if (!ctx_driver)
- goto error;
-
- video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver);
-
- RARCH_LOG("[FPGA]: Found FPGA context: %s\n", ctx_driver->ident);
-
- video_context_driver_get_video_size(&mode);
-
- full_x = mode.width;
- full_y = mode.height;
- mode.width = 0;
- mode.height = 0;
-
- RARCH_LOG("[FPGA]: Detecting screen resolution %ux%u.\n", full_x, full_y);
-
- win_width = video->width;
- win_height = video->height;
-
- if (video->fullscreen && (win_width == 0) && (win_height == 0))
- {
- win_width = full_x;
- win_height = full_y;
- }
-
- mode.width = win_width;
- mode.height = win_height;
- mode.fullscreen = video->fullscreen;
-
- if (!video_context_driver_set_video_mode(&mode))
- goto error;
-
- mode.width = 0;
- mode.height = 0;
-
- video_context_driver_get_video_size(&mode);
-
- temp_width = mode.width;
- temp_height = mode.height;
- mode.width = 0;
- mode.height = 0;
-
- /* Get real known video size, which might have been altered by context. */
-
- if (temp_width != 0 && temp_height != 0)
- video_driver_set_size(temp_width, temp_height);
-
- video_driver_get_size(&temp_width, &temp_height);
-
- RARCH_LOG("[FPGA]: Using resolution %ux%u\n", temp_width, temp_height);
-
- inp.input = input;
- inp.input_data = input_data;
-
- video_context_driver_input_driver(&inp);
-
RARCH_LOG("[FPGA]: Init complete.\n");
return fpga;
error:
- video_context_driver_destroy();
if (fpga)
free(fpga);
return NULL;
@@ -202,7 +136,6 @@ static bool fpga_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
- gfx_ctx_mode_t mode;
const void *frame_to_copy = frame;
unsigned width = 0;
unsigned height = 0;
@@ -251,8 +184,6 @@ static bool fpga_gfx_frame(void *data, const void *frame,
draw = false;
}
- video_context_driver_get_video_size(&mode);
-
if (draw)
{
if (bits == 16)
@@ -317,25 +248,6 @@ static void fpga_gfx_set_nonblock_state(void *a, bool b, bool c, unsigned d) { }
static bool fpga_gfx_alive(void *data)
{
- gfx_ctx_size_t size_data;
- unsigned temp_width = 0;
- unsigned temp_height = 0;
- bool quit = false;
- bool resize = false;
-
- /* Needed because some context drivers don't track their sizes */
- video_driver_get_size(&temp_width, &temp_height);
-
- size_data.quit = &quit;
- size_data.resize = &resize;
- size_data.width = &temp_width;
- size_data.height = &temp_height;
-
- video_context_driver_check_window(&size_data);
-
- if (temp_width != 0 && temp_height != 0)
- video_driver_set_size(temp_width, temp_height);
-
return true;
}
@@ -369,8 +281,6 @@ static void fpga_gfx_free(void *data)
free(fpga->menu_frame);
fpga->menu_frame = NULL;
- video_context_driver_free();
-
free(fpga);
fpga->regOp.only_mmap = 0;
@@ -449,34 +359,13 @@ static void fpga_set_osd_msg(void *data,
}
static void fpga_get_video_output_size(void *data,
- unsigned *width, unsigned *height)
-{
- gfx_ctx_size_t size_data;
- size_data.width = width;
- size_data.height = height;
- video_context_driver_get_video_output_size(&size_data);
-}
-
-static void fpga_get_video_output_prev(void *data)
-{
- video_context_driver_get_video_output_prev();
-}
-
-static void fpga_get_video_output_next(void *data)
-{
- video_context_driver_get_video_output_next();
-}
+ unsigned *width, unsigned *height) { }
+static void fpga_get_video_output_prev(void *data) { }
+static void fpga_get_video_output_next(void *data) { }
static void fpga_set_video_mode(void *data, unsigned width, unsigned height,
bool fullscreen)
{
- gfx_ctx_mode_t mode;
-
- mode.width = width;
- mode.height = height;
- mode.fullscreen = fullscreen;
-
- video_context_driver_set_video_mode(&mode);
}
static const video_poke_interface_t fpga_poke_interface = {
diff --git a/gfx/drivers/gcm_gfx.c b/gfx/drivers/gcm_gfx.c
index 6b58243dc9..d53f5d177c 100644
--- a/gfx/drivers/gcm_gfx.c
+++ b/gfx/drivers/gcm_gfx.c
@@ -261,7 +261,7 @@ waitFinish(gcmContextData *context, u32 sLabelVal)
rsxFlushBuffer (context);
- while(*(vu32 *) gcmGetLabelAddress (GCM_LABEL_INDEX) != sLabelVal)
+ while (*(vu32 *) gcmGetLabelAddress (GCM_LABEL_INDEX) != sLabelVal)
usleep(30);
sLabelVal++;
diff --git a/gfx/drivers/gdi_gfx.c b/gfx/drivers/gdi_gfx.c
index 2996ade4f4..d7d5e13afb 100644
--- a/gfx/drivers/gdi_gfx.c
+++ b/gfx/drivers/gdi_gfx.c
@@ -39,6 +39,139 @@
#include "../common/win32_common.h"
#endif
+static HDC win32_gdi_hdc;
+static void *dinput_gdi;
+
+static void gfx_ctx_gdi_update_title(void)
+{
+ char title[128];
+ const ui_window_t *window = ui_companion_driver_get_window_ptr();
+
+ title[0] = '\0';
+
+ video_driver_get_window_title(title, sizeof(title));
+
+ if (window && title[0])
+ window->set_title(&main_window, title);
+}
+
+static void gfx_ctx_gdi_get_video_size(
+ unsigned *width, unsigned *height)
+{
+ HWND window = win32_get_window();
+
+ if (window)
+ {
+ *width = g_win32_resize_width;
+ *height = g_win32_resize_height;
+ }
+ else
+ {
+ RECT mon_rect;
+ MONITORINFOEX current_mon;
+ unsigned mon_id = 0;
+ HMONITOR hm_to_use = NULL;
+
+ win32_monitor_info(¤t_mon, &hm_to_use, &mon_id);
+ mon_rect = current_mon.rcMonitor;
+ *width = mon_rect.right - mon_rect.left;
+ *height = mon_rect.bottom - mon_rect.top;
+ }
+}
+
+static bool gfx_ctx_gdi_init(void)
+{
+ WNDCLASSEX wndclass = {0};
+
+ if (g_win32_inited)
+ return true;
+
+ win32_window_reset();
+ win32_monitor_init();
+
+ wndclass.lpfnWndProc = WndProcGDI;
+ if (!win32_window_init(&wndclass, true, NULL))
+ return false;
+ return true;
+}
+
+static void gfx_ctx_gdi_destroy(void)
+{
+ HWND window = win32_get_window();
+
+ if (window && win32_gdi_hdc)
+ {
+ ReleaseDC(window, win32_gdi_hdc);
+ win32_gdi_hdc = NULL;
+ }
+
+ if (window)
+ {
+ win32_monitor_from_window();
+ win32_destroy_window();
+ }
+
+ if (g_win32_restore_desktop)
+ {
+ win32_monitor_get_info();
+ g_win32_restore_desktop = false;
+ }
+
+ g_win32_inited = false;
+}
+
+static bool gfx_ctx_gdi_set_video_mode(
+ unsigned width, unsigned height,
+ bool fullscreen)
+{
+ if (!win32_set_video_mode(NULL, width, height, fullscreen))
+ {
+ gfx_ctx_gdi_destroy();
+ return false;
+ }
+
+ return true;
+}
+
+static void gfx_ctx_gdi_input_driver(
+ input_driver_t **input, void **input_data)
+{
+ settings_t *settings = config_get_ptr();
+#if _WIN32_WINNT >= 0x0501
+#ifdef HAVE_WINRAWINPUT
+ /* winraw only available since XP */
+ if (string_is_equal(settings->arrays.input_driver, "raw"))
+ {
+ *input_data = input_winraw.init(settings->arrays.input_driver);
+ if (*input_data)
+ {
+ *input = &input_winraw;
+ dinput_gdi = NULL;
+ return;
+ }
+ }
+#endif
+#endif
+
+#ifdef HAVE_DINPUT
+ dinput_gdi = input_dinput.init(settings->arrays.input_driver);
+ *input = dinput_gdi ? &input_dinput : NULL;
+#else
+ dinput_gdi = NULL;
+ *input = NULL;
+#endif
+ *input_data = dinput_gdi;
+}
+
+void create_gdi_context(HWND hwnd, bool *quit)
+{
+ win32_gdi_hdc = GetDC(hwnd);
+
+ win32_setup_pixel_format(win32_gdi_hdc, false);
+
+ g_win32_inited = true;
+}
+
static void gdi_gfx_create(gdi_t *gdi)
{
char os[64] = {0};
@@ -65,11 +198,10 @@ static void *gdi_gfx_init(const video_info_t *video,
input_driver_t **input, void **input_data)
{
unsigned full_x, full_y;
- gfx_ctx_input_t inp;
- gfx_ctx_mode_t mode;
void *ctx_data = NULL;
const gfx_ctx_driver_t *ctx_driver = NULL;
- unsigned win_width = 0, win_height = 0;
+ unsigned mode_width = 0, mode_height = 0;
+ unsigned win_width = 0, win_height = 0;
unsigned temp_width = 0, temp_height = 0;
settings_t *settings = config_get_ptr();
bool video_font_enable = settings->bools.video_font_enable;
@@ -93,28 +225,15 @@ static void *gdi_gfx_init(const video_info_t *video,
gdi->video_pitch = video->width * 2;
gdi_gfx_create(gdi);
-
- ctx_driver = video_context_driver_init_first(gdi,
- settings->arrays.video_context_driver,
- GFX_CTX_GDI_API, 1, 0, false, &ctx_data);
- if (!ctx_driver)
+ if (!gfx_ctx_gdi_init())
goto error;
- if (ctx_data)
- gdi->ctx_data = ctx_data;
+ gfx_ctx_gdi_get_video_size(&mode_width, &mode_height);
- gdi->ctx_driver = ctx_driver;
-
- video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver);
-
- RARCH_LOG("[GDI]: Found GDI context: %s\n", ctx_driver->ident);
-
- video_context_driver_get_video_size(&mode);
-
- full_x = mode.width;
- full_y = mode.height;
- mode.width = 0;
- mode.height = 0;
+ full_x = mode_width;
+ full_y = mode_height;
+ mode_width = 0;
+ mode_height = 0;
RARCH_LOG("[GDI]: Detecting screen resolution %ux%u.\n", full_x, full_y);
@@ -127,22 +246,22 @@ static void *gdi_gfx_init(const video_info_t *video,
win_height = full_y;
}
- mode.width = win_width;
- mode.height = win_height;
- mode.fullscreen = video->fullscreen;
+ mode_width = win_width;
+ mode_height = win_height;
- if (!video_context_driver_set_video_mode(&mode))
+ if (!gfx_ctx_gdi_set_video_mode(mode_width,
+ mode_height, video->fullscreen))
goto error;
- mode.width = 0;
- mode.height = 0;
+ mode_width = 0;
+ mode_height = 0;
- video_context_driver_get_video_size(&mode);
+ gfx_ctx_gdi_get_video_size(&mode_width, &mode_height);
- temp_width = mode.width;
- temp_height = mode.height;
- mode.width = 0;
- mode.height = 0;
+ temp_width = mode_width;
+ temp_height = mode_height;
+ mode_width = 0;
+ mode_height = 0;
/* Get real known video size, which might have been altered by context. */
@@ -153,10 +272,7 @@ static void *gdi_gfx_init(const video_info_t *video,
RARCH_LOG("[GDI]: Using resolution %ux%u\n", temp_width, temp_height);
- inp.input = input;
- inp.input_data = input_data;
-
- video_context_driver_input_driver(&inp);
+ gfx_ctx_gdi_input_driver(input, input_data);
if (video_font_enable)
font_driver_init_osd(gdi,
@@ -170,7 +286,7 @@ static void *gdi_gfx_init(const video_info_t *video,
return gdi;
error:
- video_context_driver_destroy();
+ gfx_ctx_gdi_destroy();
if (gdi)
free(gdi);
return NULL;
@@ -180,8 +296,9 @@ static bool gdi_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
- BITMAPINFO *info;
- gfx_ctx_mode_t mode;
+ BITMAPINFO info;
+ unsigned mode_width = 0;
+ unsigned mode_height = 0;
const void *frame_to_copy = frame;
unsigned width = 0;
unsigned height = 0;
@@ -199,7 +316,8 @@ static bool gdi_gfx_frame(void *data, const void *frame,
return true;
#ifdef HAVE_MENU
- menu_driver_frame(menu_is_alive, video_info);
+ if (gdi->menu_enable)
+ menu_driver_frame(menu_is_alive, video_info);
#endif
if ( gdi->video_width != frame_width ||
@@ -276,20 +394,27 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
}
- video_context_driver_get_video_size(&mode);
+ gfx_ctx_gdi_get_video_size(&mode_width, &mode_height);
- gdi->screen_width = mode.width;
- gdi->screen_height = mode.height;
+ gdi->screen_width = mode_width;
+ gdi->screen_height = mode_height;
- info = (BITMAPINFO*)
- calloc(1, sizeof(*info) + (3 * sizeof(RGBQUAD)));
+ info.bmiColors[0].rgbBlue = 0;
+ info.bmiColors[0].rgbGreen = 0;
+ info.bmiColors[0].rgbRed = 0;
+ info.bmiColors[0].rgbReserved = 0;
- info->bmiHeader.biBitCount = bits;
- info->bmiHeader.biWidth = pitch / (bits / 8);
- info->bmiHeader.biHeight = -height;
- info->bmiHeader.biPlanes = 1;
- info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- info->bmiHeader.biSizeImage = 0;
+ info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ info.bmiHeader.biWidth = pitch / (bits / 8);
+ info.bmiHeader.biHeight = -height;
+ info.bmiHeader.biPlanes = 1;
+ info.bmiHeader.biBitCount = bits;
+ info.bmiHeader.biCompression = 0;
+ info.bmiHeader.biSizeImage = 0;
+ info.bmiHeader.biXPelsPerMeter= 0;
+ info.bmiHeader.biYPelsPerMeter= 0;
+ info.bmiHeader.biClrUsed = 0;
+ info.bmiHeader.biClrImportant = 0;
if (bits == 16)
{
@@ -309,13 +434,13 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
frame_to_copy = gdi->temp_buf;
- info->bmiHeader.biCompression = BI_RGB;
+ info.bmiHeader.biCompression = BI_RGB;
}
else
{
- unsigned *masks = (unsigned*)info->bmiColors;
+ unsigned *masks = (unsigned*)info.bmiColors;
- info->bmiHeader.biCompression = BI_BITFIELDS;
+ info.bmiHeader.biCompression = BI_BITFIELDS;
/* default 16-bit format on Windows is XRGB1555 */
if (frame_to_copy == gdi->menu_frame)
@@ -335,24 +460,20 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
}
else
- info->bmiHeader.biCompression = BI_RGB;
+ info.bmiHeader.biCompression = BI_RGB;
if (draw)
StretchDIBits(gdi->memDC, 0, 0, width, height, 0, 0, width, height,
- frame_to_copy, info, DIB_RGB_COLORS, SRCCOPY);
+ frame_to_copy, &info, DIB_RGB_COLORS, SRCCOPY);
SelectObject(gdi->memDC, gdi->bmp_old);
- free(info);
-
if (msg)
font_driver_render_msg(gdi, msg, NULL, NULL);
InvalidateRect(hwnd, NULL, false);
- if (gdi->ctx_driver->update_window_title)
- gdi->ctx_driver->update_window_title(
- video_info->context_data);
+ gfx_ctx_gdi_update_title();
return true;
}
@@ -368,12 +489,11 @@ static bool gdi_gfx_alive(void *data)
bool quit = false;
bool resize = false;
bool ret = false;
- gdi_t *gdi = (gdi_t*)data;
/* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height);
- gdi->ctx_driver->check_window(gdi->ctx_data,
+ win32_check_window(NULL,
&quit, &resize, &temp_width, &temp_height);
ret = !quit;
@@ -440,7 +560,7 @@ static void gdi_gfx_free(void *data)
}
font_driver_free_osd();
- video_context_driver_free();
+ gfx_ctx_gdi_destroy();
free(gdi);
}
@@ -454,6 +574,17 @@ static bool gdi_gfx_set_shader(void *data,
return false;
}
+static void gdi_set_texture_enable(
+ void *data, bool state, bool full_screen)
+{
+ gdi_t *gdi = (gdi_t*)data;
+ if (!gdi)
+ return;
+
+ gdi->menu_enable = state;
+ gdi->menu_full_screen = full_screen;
+}
+
static void gdi_set_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height,
float alpha)
@@ -495,13 +626,7 @@ static void gdi_set_texture_frame(void *data,
static void gdi_set_video_mode(void *data, unsigned width, unsigned height,
bool fullscreen)
{
- gfx_ctx_mode_t mode;
-
- mode.width = width;
- mode.height = height;
- mode.fullscreen = fullscreen;
-
- video_context_driver_set_video_mode(&mode);
+ gfx_ctx_gdi_set_video_mode(width, height, fullscreen);
}
static uintptr_t gdi_load_texture(void *video_data, void *data,
@@ -580,7 +705,7 @@ static const video_poke_interface_t gdi_poke_interface = {
NULL,
NULL,
gdi_set_texture_frame,
- NULL,
+ gdi_set_texture_enable,
font_driver_render_msg,
NULL,
NULL, /* grab_mouse_toggle */
diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c
index 16d37c1b5a..02db144cfe 100644
--- a/gfx/drivers/gl.c
+++ b/gfx/drivers/gl.c
@@ -2064,6 +2064,7 @@ static bool gl2_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver,
init_data.gl.core_context_enabled = gl->core_context_in_use;
init_data.shader_type = type;
init_data.shader = NULL;
+ init_data.shader_data = NULL;
init_data.data = gl;
init_data.path = shader_path;
@@ -2076,13 +2077,14 @@ static bool gl2_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver,
RARCH_ERR("[GL]: Failed to initialize shader, falling back to stock.\n");
- init_data.shader = NULL;
- init_data.path = NULL;
+ init_data.shader = NULL;
+ init_data.shader_data = NULL;
+ init_data.path = NULL;
- ret = gl_shader_driver_init(&init_data);
+ ret = gl_shader_driver_init(&init_data);
- gl->shader = init_data.shader;
- gl->shader_data = init_data.shader_data;
+ gl->shader = init_data.shader;
+ gl->shader_data = init_data.shader_data;
return ret;
}
@@ -2666,7 +2668,9 @@ static void gl2_video_layout_layer_begin(const video_layout_render_info_t *info)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
-static void gl2_video_layout_image(const video_layout_render_info_t *info, void *image_handle, void *alpha_handle)
+static void gl2_video_layout_image(
+ const video_layout_render_info_t *info,
+ void *image_handle, void *alpha_handle)
{
/* TODO alpha_handle */
int i;
@@ -2690,7 +2694,7 @@ static void gl2_video_layout_image(const video_layout_render_info_t *info, void
coord[7] = 1.f - (b.y + b.h);
i = 0;
- while(i < 16)
+ while (i < 16)
{
color[i++] = info->color.r;
color[i++] = info->color.g;
@@ -2698,10 +2702,10 @@ static void gl2_video_layout_image(const video_layout_render_info_t *info, void
color[i++] = info->color.a;
}
- gl->coords.vertex = coord;
+ gl->coords.vertex = coord;
gl->coords.tex_coord = tex_coords;
- gl->coords.color = color;
- gl->coords.vertices = 4;
+ gl->coords.color = color;
+ gl->coords.vertices = 4;
gl->shader->set_coords(gl->shader_data, &gl->coords);
gl->shader->set_mvp(gl->shader_data, &gl->mvp_no_rot);
@@ -2825,7 +2829,6 @@ static bool gl2_frame(void *data, const void *frame,
bool runloop_is_paused = video_info->runloop_is_paused;
bool hard_sync = video_info->hard_sync;
unsigned hard_sync_frames = video_info->hard_sync_frames;
- void *context_data = video_info->context_data;
struct font_params *osd_params = (struct font_params*)
&video_info->osd_stat_params;
const char *stat_text = video_info->stat_text;
@@ -2861,7 +2864,8 @@ static bool gl2_frame(void *data, const void *frame,
if (gl->should_resize)
{
- video_info->cb_set_resize(context_data,
+ if (gl->ctx_driver->set_resize)
+ gl->ctx_driver->set_resize(gl->ctx_data,
width, height);
gl->should_resize = false;
@@ -3068,7 +3072,7 @@ static bool gl2_frame(void *data, const void *frame,
}
if (gl->ctx_driver->update_window_title)
- gl->ctx_driver->update_window_title(context_data);
+ gl->ctx_driver->update_window_title(gl->ctx_data);
/* Reset state which could easily mess up libretro core. */
if (gl->hw_render_fbo_init)
@@ -3103,12 +3107,13 @@ static bool gl2_frame(void *data, const void *frame,
&& !runloop_is_paused)
{
if (gl->ctx_driver->swap_buffers)
- gl->ctx_driver->swap_buffers(context_data);
+ gl->ctx_driver->swap_buffers(gl->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}
#endif
- gl->ctx_driver->swap_buffers(context_data);
+ if (gl->ctx_driver->swap_buffers)
+ gl->ctx_driver->swap_buffers(gl->ctx_data);
/* check if we are fast forwarding or in menu, if we are ignore hard sync */
if ( gl->have_sync
@@ -4080,14 +4085,16 @@ static bool gl2_set_shader(void *data,
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
}
- init_data.shader_type = fallback;
- init_data.shader = NULL;
- init_data.data = gl;
- init_data.path = path;
+ init_data.shader_type = fallback;
+ init_data.path = path;
+ init_data.shader = NULL;
+ init_data.data = gl;
+ init_data.shader_data = NULL;
+ init_data.gl.core_context_enabled = false;
if (!gl_shader_driver_init(&init_data))
{
- init_data.path = NULL;
+ init_data.path = NULL;
gl_shader_driver_init(&init_data);
diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c
index a91e22d2d4..06c4ec9bdb 100644
--- a/gfx/drivers/gl1.c
+++ b/gfx/drivers/gl1.c
@@ -708,9 +708,6 @@ static bool gl1_gfx_frame(void *data, const void *frame,
video_info->xmb_shadows_enable = false;
video_info->menu_shader_pipeline = 0;
- if (!frame || !frame_width || !frame_height)
- return true;
-
if (gl1->should_resize)
{
gfx_ctx_mode_t mode;
@@ -720,8 +717,9 @@ static bool gl1_gfx_frame(void *data, const void *frame,
mode.width = width;
mode.height = height;
- video_info->cb_set_resize(video_info->context_data,
- mode.width, mode.height);
+ if (gl1->ctx_driver->set_resize)
+ gl1->ctx_driver->set_resize(gl1->ctx_data,
+ mode.width, mode.height);
gl1_gfx_set_viewport(gl1,
video_width, video_height, false, true);
@@ -756,7 +754,7 @@ static bool gl1_gfx_frame(void *data, const void *frame,
pot_width = get_pot(width);
pot_height = get_pot(height);
- if ( frame == RETRO_HW_FRAME_BUFFER_VALID || (
+ if ( !frame || frame == RETRO_HW_FRAME_BUFFER_VALID || (
frame_width == 4 &&
frame_height == 4 &&
(frame_width < width && frame_height < height))
@@ -791,9 +789,6 @@ static bool gl1_gfx_frame(void *data, const void *frame,
if (draw)
{
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -880,7 +875,7 @@ static bool gl1_gfx_frame(void *data, const void *frame,
if (gl1->ctx_driver->update_window_title)
gl1->ctx_driver->update_window_title(
- video_info->context_data);
+ gl1->ctx_data);
/* Screenshots. */
if (gl1->readback_buffer_screenshot)
@@ -898,12 +893,12 @@ static bool gl1_gfx_frame(void *data, const void *frame,
&& !video_info->runloop_is_slowmotion
&& !video_info->runloop_is_paused)
{
- gl1->ctx_driver->swap_buffers(video_info->context_data);
+ gl1->ctx_driver->swap_buffers(gl1->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}
#endif
- gl1->ctx_driver->swap_buffers(video_info->context_data);
+ gl1->ctx_driver->swap_buffers(gl1->ctx_data);
/* check if we are fast forwarding or in menu, if we are ignore hard sync */
if (video_info->hard_sync
@@ -913,6 +908,9 @@ static bool gl1_gfx_frame(void *data, const void *frame,
glClear(GL_COLOR_BUFFER_BIT);
glFinish();
}
+
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
gl1_context_bind_hw_render(gl1, true);
diff --git a/gfx/drivers/gl_core.c b/gfx/drivers/gl_core.c
index 3ba5e36539..e288472aa2 100644
--- a/gfx/drivers/gl_core.c
+++ b/gfx/drivers/gl_core.c
@@ -33,7 +33,9 @@
#include "../../configuration.h"
#include "../../dynamic.h"
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#include "../../retroarch.h"
#include "../../verbosity.h"
@@ -1845,7 +1847,6 @@ static bool gl_core_frame(void *data, const void *frame,
bool statistics_show = video_info->statistics_show;
bool msg_bgcolor_enable = video_info->msg_bgcolor_enable;
bool black_frame_insertion = video_info->black_frame_insertion;
- void *context_data = video_info->context_data;
unsigned hard_sync_frames = video_info->hard_sync_frames;
bool runloop_is_paused = video_info->runloop_is_paused;
bool runloop_is_slowmotion = video_info->runloop_is_slowmotion;
@@ -1875,7 +1876,9 @@ static bool gl_core_frame(void *data, const void *frame,
if (gl->should_resize)
{
- video_info->cb_set_resize(context_data, width, height);
+ if (gl->ctx_driver->set_resize)
+ gl->ctx_driver->set_resize(gl->ctx_data,
+ width, height);
gl->should_resize = false;
}
@@ -1907,7 +1910,11 @@ static bool gl_core_frame(void *data, const void *frame,
texture.padded_height = streamed->height;
}
gl_core_filter_chain_set_frame_count(gl->filter_chain, frame_count);
+#ifdef HAVE_REWIND
gl_core_filter_chain_set_frame_direction(gl->filter_chain, state_manager_frame_is_reversed() ? -1 : 1);
+#else
+ gl_core_filter_chain_set_frame_direction(gl->filter_chain, 1);
+#endif
gl_core_filter_chain_set_input_texture(gl->filter_chain, &texture);
gl_core_filter_chain_build_offscreen_passes(gl->filter_chain, &gl->filter_chain_vp);
@@ -1953,7 +1960,7 @@ static bool gl_core_frame(void *data, const void *frame,
}
if (gl->ctx_driver->update_window_title)
- gl->ctx_driver->update_window_title(context_data);
+ gl->ctx_driver->update_window_title(gl->ctx_data);
if (gl->readback_buffer_screenshot)
{
@@ -1977,11 +1984,11 @@ static bool gl_core_frame(void *data, const void *frame,
&& !runloop_is_slowmotion
&& !runloop_is_paused)
{
- gl->ctx_driver->swap_buffers(context_data);
+ gl->ctx_driver->swap_buffers(gl->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}
- gl->ctx_driver->swap_buffers(context_data);
+ gl->ctx_driver->swap_buffers(gl->ctx_data);
if (video_info->hard_sync &&
!input_driver_nonblock_state &&
diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c
index 0ce56bc6a1..136a213d4f 100644
--- a/gfx/drivers/gx2_gfx.c
+++ b/gfx/drivers/gx2_gfx.c
@@ -25,7 +25,10 @@
#include "../../configuration.h"
#include "../../verbosity.h"
#include "../../retroarch.h"
+
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#ifdef HAVE_CONFIG_H
#include "../../config.h"
@@ -1142,7 +1145,11 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
if (wiiu->shader_preset)
{
unsigned i;
+#ifdef HAVE_REWIND
int32_t frame_direction = state_manager_frame_is_reversed() ? -1 : 1;
+#else
+ int32_t frame_direction = 1;
+#endif
for (i = 0; i < wiiu->shader_preset->passes; i++)
{
diff --git a/gfx/drivers/network_gfx.c b/gfx/drivers/network_gfx.c
index 7b6feb6c1c..905f398f8a 100644
--- a/gfx/drivers/network_gfx.c
+++ b/gfx/drivers/network_gfx.c
@@ -64,17 +64,32 @@ static bool network_rgb32 = false;
static bool network_menu_rgb32 = false;
static unsigned *network_video_temp_buf = NULL;
+static void gfx_ctx_network_input_driver(
+ const char *joypad_driver,
+ input_driver_t **input, void **input_data)
+{
+#ifdef HAVE_UDEV
+ *input_data = input_udev.init(joypad_driver);
+
+ if (*input_data)
+ {
+ *input = &input_udev;
+ return;
+ }
+#endif
+ *input = NULL;
+ *input_data = NULL;
+}
+
static void *network_gfx_init(const video_info_t *video,
input_driver_t **input, void **input_data)
{
int fd;
- gfx_ctx_input_t inp;
- void *ctx_data = NULL;
- const gfx_ctx_driver_t *ctx_driver = NULL;
struct addrinfo *addr = NULL, *next_addr = NULL;
settings_t *settings = config_get_ptr();
network_video_t *network = (network_video_t*)calloc(1, sizeof(*network));
bool video_font_enable = settings->bools.video_font_enable;
+ const char *joypad_driver = settings->arrays.joypad_driver;
*input = NULL;
*input_data = NULL;
@@ -87,25 +102,8 @@ static void *network_gfx_init(const video_info_t *video,
else
network_video_pitch = video->width * 2;
- ctx_driver = video_context_driver_init_first(network,
- "network",
- GFX_CTX_NETWORK_VIDEO_API, 1, 0, false, &ctx_data);
-
- if (!ctx_driver)
- goto error;
-
- if (ctx_data)
- network->ctx_data = ctx_data;
-
- network->ctx_driver = ctx_driver;
- video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver);
-
- RARCH_LOG("[network]: Found network video context: %s\n", ctx_driver->ident);
-
- inp.input = input;
- inp.input_data = input_data;
-
- video_context_driver_input_driver(&inp);
+ gfx_ctx_network_input_driver(joypad_driver,
+ input, input_data);
if (font_enable)
font_driver_init_osd(network,
@@ -160,7 +158,6 @@ try_connect:
return network;
error:
- video_context_driver_destroy();
if (network)
free(network);
return NULL;
@@ -170,7 +167,6 @@ static bool network_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
- gfx_ctx_mode_t mode;
const void *frame_to_copy = frame;
unsigned width = 0;
unsigned height = 0;
@@ -339,59 +335,36 @@ static void network_gfx_set_nonblock_state(void *a, bool b, bool c, unsigned d)
static bool network_gfx_alive(void *data)
{
- gfx_ctx_size_t size_data;
- unsigned temp_width = 0;
- unsigned temp_height = 0;
- bool quit = false;
- bool resize = false;
- network_video_t *network = (network_video_t*)data;
+ unsigned temp_width = 0;
+ unsigned temp_height = 0;
+ bool quit = false;
+ bool resize = false;
+ network_video_t *network = (network_video_t*)data;
- /* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height);
- network->ctx_driver->check_window(network->ctx_data,
- &quit, &resize, &temp_width, &temp_height);
-
if (temp_width != 0 && temp_height != 0)
video_driver_set_size(temp_width, temp_height);
return true;
}
-static bool network_gfx_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool network_gfx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-static bool network_gfx_has_windowed(void *data)
-{
- (void)data;
- return true;
-}
+static bool network_gfx_focus(void *data) { return true; }
+static bool network_gfx_suppress_screensaver(void *data, bool enable) { return false; }
+static bool network_gfx_has_windowed(void *data) { return true; }
static void network_gfx_free(void *data)
{
network_video_t *network = (network_video_t*)data;
if (network_menu_frame)
- {
free(network_menu_frame);
- network_menu_frame = NULL;
- }
if (network_video_temp_buf)
- {
free(network_video_temp_buf);
- network_video_temp_buf = NULL;
- }
+
+ network_menu_frame = NULL;
+ network_video_temp_buf = NULL;
font_driver_free_osd();
@@ -403,21 +376,9 @@ static void network_gfx_free(void *data)
}
static bool network_gfx_set_shader(void *data,
- enum rarch_shader_type type, const char *path)
-{
- (void)data;
- (void)type;
- (void)path;
-
- return false;
-}
-
+ enum rarch_shader_type type, const char *path) { return false; }
static void network_gfx_set_rotation(void *data,
- unsigned rotation)
-{
- (void)data;
- (void)rotation;
-}
+ unsigned rotation) { }
static void network_set_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height,
@@ -434,7 +395,10 @@ static void network_set_texture_frame(void *data,
network_menu_frame = NULL;
}
- if (!network_menu_frame || network_menu_width != width || network_menu_height != height || network_menu_pitch != pitch)
+ if ( !network_menu_frame ||
+ network_menu_width != width ||
+ network_menu_height != height ||
+ network_menu_pitch != pitch)
if (pitch && height)
network_menu_frame = (unsigned char*)malloc(pitch * height);
@@ -449,35 +413,12 @@ static void network_set_texture_frame(void *data,
}
static void network_get_video_output_size(void *data,
- unsigned *width, unsigned *height)
-{
- gfx_ctx_size_t size_data;
- size_data.width = width;
- size_data.height = height;
- video_context_driver_get_video_output_size(&size_data);
-}
-
-static void network_get_video_output_prev(void *data)
-{
- video_context_driver_get_video_output_prev();
-}
-
-static void network_get_video_output_next(void *data)
-{
- video_context_driver_get_video_output_next();
-}
+ unsigned *width, unsigned *height) { }
+static void network_get_video_output_prev(void *data) { }
+static void network_get_video_output_next(void *data) { }
static void network_set_video_mode(void *data, unsigned width, unsigned height,
- bool fullscreen)
-{
- gfx_ctx_mode_t mode;
-
- mode.width = width;
- mode.height = height;
- mode.fullscreen = fullscreen;
-
- video_context_driver_set_video_mode(&mode);
-}
+ bool fullscreen) { }
static const video_poke_interface_t network_poke_interface = {
NULL,
diff --git a/gfx/drivers/oga_gfx.c b/gfx/drivers/oga_gfx.c
index 256817d8af..44955adc52 100644
--- a/gfx/drivers/oga_gfx.c
+++ b/gfx/drivers/oga_gfx.c
@@ -41,7 +41,6 @@
#include "../../retroarch.h"
#include
-#include
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
@@ -133,6 +132,9 @@ static void *oga_gfx_init(const video_info_t *video,
vid = (oga_video_t*)calloc(1, sizeof(*vid));
vid->menu_frame = NULL;
+ vid->menu_width = 0;
+ vid->menu_height = 0;
+ vid->menu_pitch = 0;
vid->display = go2_display_create();
vid->presenter = go2_presenter_create(vid->display, DRM_FORMAT_RGB565, 0xff000000, false);
vid->menu_surface = go2_surface_create(vid->display, NATIVE_WIDTH, NATIVE_HEIGHT, DRM_FORMAT_XRGB8888);
@@ -188,7 +190,7 @@ static void render_msg(oga_video_t* vid,
{
const struct font_atlas* atlas = vid->font_driver->get_atlas(vid->font);
int msg_width = get_message_width(vid, msg);
- int dest_x = MAX(0, width - get_message_width(vid, msg));
+ int dest_x = MAX(0, width - msg_width);
int dest_stride = go2_surface_stride_get(surface);
const char *c = msg;
@@ -197,7 +199,7 @@ static void render_msg(oga_video_t* vid,
const struct font_glyph* g = vid->font_driver->get_glyph(vid->font, *c);
if (!g)
continue;
- if (dest_x + g->advance_x >= width)
+ if (dest_x >= width)
break;
const uint8_t* source = atlas->buffer + g->atlas_offset_y * atlas->width + g->atlas_offset_x;
@@ -249,9 +251,20 @@ static bool oga_gfx_frame(void *data, const void *frame, unsigned width,
go2_surface_format_get(dst_surface)) / 8;
bool menu_is_alive = video_info->menu_is_alive;
+ if (unlikely(!frame || width == 0 || height == 0))
+ return true;
+
+ if (unlikely(video_info->input_driver_nonblock_state) && !vid->threaded)
+ {
+ if (frame_count % 4 != 0)
+ return true;
+ }
+
#ifdef HAVE_MENU
if (unlikely(menu_is_alive))
{
+ if (unlikely(vid->menu_width == 0))
+ return true;
menu_driver_frame(menu_is_alive, video_info);
dst_surface = vid->menu_surface;
src = (uint8_t*)vid->menu_frame;
@@ -262,15 +275,6 @@ static bool oga_gfx_frame(void *data, const void *frame, unsigned width,
}
#endif
- if (unlikely(!frame || width == 0 || height == 0))
- return true;
-
- if (unlikely(video_info->input_driver_nonblock_state) && !vid->threaded)
- {
- if (frame_count % 4 != 0)
- return true;
- }
-
/* copy buffer to surface */
dst = (uint8_t*)go2_surface_map(dst_surface);
yy = height;
diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c
index 6b7a977b2f..9ac2d02476 100644
--- a/gfx/drivers/ps2_gfx.c
+++ b/gfx/drivers/ps2_gfx.c
@@ -165,7 +165,6 @@ static void refreshScreen(ps2_video_t *ps2)
gsKit_sync_flip(ps2->gsGlobal);
gsKit_queue_exec(ps2->gsGlobal);
gsKit_TexManager_nextFrame(ps2->gsGlobal);
-
}
static void *ps2_gfx_init(const video_info_t *video,
diff --git a/gfx/drivers/sixel_gfx.c b/gfx/drivers/sixel_gfx.c
index 10c42b139d..7e9f27f160 100644
--- a/gfx/drivers/sixel_gfx.c
+++ b/gfx/drivers/sixel_gfx.c
@@ -189,13 +189,14 @@ static void scroll_on_demand(int pixelheight)
static void *sixel_gfx_init(const video_info_t *video,
input_driver_t **input, void **input_data)
{
- gfx_ctx_input_t inp;
void *ctx_data = NULL;
+ const char *scale_str = NULL;
settings_t *settings = config_get_ptr();
bool video_font_enable = settings->bools.video_font_enable;
sixel_t *sixel = (sixel_t*)calloc(1, sizeof(*sixel));
- const gfx_ctx_driver_t *ctx_driver = NULL;
- const char *scale_str = NULL;
+
+ if (!sixel)
+ return NULL;
*input = NULL;
*input_data = NULL;
@@ -219,25 +220,17 @@ static void *sixel_gfx_init(const video_info_t *video,
sixel_video_scale = 1.0;
}
- ctx_driver = video_context_driver_init_first(sixel,
- settings->arrays.video_context_driver,
- GFX_CTX_SIXEL_API, 1, 0, false, &ctx_data);
+#ifdef HAVE_UDEV
+ *input_data = input_udev.init(settings->arrays.input_driver);
- if (!ctx_driver)
- goto error;
-
- if (ctx_data)
- sixel->ctx_data = ctx_data;
-
- sixel->ctx_driver = ctx_driver;
- video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver);
-
- RARCH_LOG("[SIXEL]: Found SIXEL context: %s\n", ctx_driver->ident);
-
- inp.input = input;
- inp.input_data = input_data;
-
- video_context_driver_input_driver(&inp);
+ if (*input_data)
+ *input = &input_udev;
+ else
+#endif
+ {
+ *input = NULL;
+ *input_data = NULL;
+ }
if (video_font_enable)
font_driver_init_osd(sixel,
@@ -246,15 +239,7 @@ static void *sixel_gfx_init(const video_info_t *video,
video->is_threaded,
FONT_DRIVER_RENDER_SIXEL);
- RARCH_LOG("[SIXEL]: Init complete.\n");
-
return sixel;
-
-error:
- video_context_driver_destroy();
- if (sixel)
- free(sixel);
- return NULL;
}
static bool sixel_gfx_frame(void *data, const void *frame,
@@ -435,7 +420,6 @@ static void sixel_gfx_set_nonblock_state(void *a, bool b, bool c, unsigned d) {
static bool sixel_gfx_alive(void *data)
{
- gfx_ctx_size_t size_data;
unsigned temp_width = 0;
unsigned temp_height = 0;
bool quit = false;
@@ -445,9 +429,6 @@ static bool sixel_gfx_alive(void *data)
/* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height);
- sixel->ctx_driver->check_window(sixel->ctx_data,
- &quit, &resize, &temp_width, &temp_height);
-
if (temp_width != 0 && temp_height != 0)
video_driver_set_size(temp_width, temp_height);
@@ -544,35 +525,11 @@ static void sixel_set_texture_frame(void *data,
}
static void sixel_get_video_output_size(void *data,
- unsigned *width, unsigned *height)
-{
- gfx_ctx_size_t size_data;
- size_data.width = width;
- size_data.height = height;
- video_context_driver_get_video_output_size(&size_data);
-}
-
-static void sixel_get_video_output_prev(void *data)
-{
- video_context_driver_get_video_output_prev();
-}
-
-static void sixel_get_video_output_next(void *data)
-{
- video_context_driver_get_video_output_next();
-}
-
+ unsigned *width, unsigned *height) { }
+static void sixel_get_video_output_prev(void *data) { }
+static void sixel_get_video_output_next(void *data) { }
static void sixel_set_video_mode(void *data, unsigned width, unsigned height,
- bool fullscreen)
-{
- gfx_ctx_mode_t mode;
-
- mode.width = width;
- mode.height = height;
- mode.fullscreen = fullscreen;
-
- video_context_driver_set_video_mode(&mode);
-}
+ bool fullscreen) { }
static const video_poke_interface_t sixel_poke_interface = {
NULL,
diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c
index dd3aa6906d..c4d0e4289b 100644
--- a/gfx/drivers/vg.c
+++ b/gfx/drivers/vg.c
@@ -456,9 +456,9 @@ static bool vg_frame(void *data, const void *frame,
#endif
if (vg->ctx_driver->update_window_title)
- vg->ctx_driver->update_window_title(video_info->context_data);
+ vg->ctx_driver->update_window_title(vg->ctx_data);
- vg->ctx_driver->swap_buffers(video_info->context_data);
+ vg->ctx_driver->swap_buffers(vg->ctx_data);
return true;
}
diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c
index db07f7e311..73459197c4 100644
--- a/gfx/drivers/vulkan.c
+++ b/gfx/drivers/vulkan.c
@@ -46,7 +46,9 @@
#include "../../driver.h"
#include "../../configuration.h"
+#ifdef HAVE_REWIND
#include "../../managers/state_manager.h"
+#endif
#include "../../retroarch.h"
#include "../../verbosity.h"
@@ -759,8 +761,6 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
{
struct vulkan_filter_chain_create_info info;
- memset(&info, 0, sizeof(info));
-
if (!vk->context)
return false;
@@ -770,13 +770,14 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
info.pipeline_cache = vk->pipelines.cache;
info.queue = vk->context->queue;
info.command_pool = vk->swapchain[vk->context->current_frame_index].cmd_pool;
+ info.num_passes = 0;
+ info.original_format = vk->tex_fmt;
info.max_input_size.width = vk->tex_w;
info.max_input_size.height = vk->tex_h;
info.swapchain.viewport = vk->vk_vp;
info.swapchain.format = vk->context->swapchain_format;
info.swapchain.render_pass = vk->render_pass;
info.swapchain.num_indices = vk->context->num_swapchain_images;
- info.original_format = vk->tex_fmt;
vk->filter_chain = vulkan_filter_chain_create_default(
&info,
@@ -796,21 +797,20 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
{
struct vulkan_filter_chain_create_info info;
- memset(&info, 0, sizeof(info));
-
info.device = vk->context->device;
info.gpu = vk->context->gpu;
info.memory_properties = &vk->context->memory_properties;
info.pipeline_cache = vk->pipelines.cache;
info.queue = vk->context->queue;
info.command_pool = vk->swapchain[vk->context->current_frame_index].cmd_pool;
+ info.num_passes = 0;
+ info.original_format = vk->tex_fmt;
info.max_input_size.width = vk->tex_w;
info.max_input_size.height = vk->tex_h;
info.swapchain.viewport = vk->vk_vp;
info.swapchain.format = vk->context->swapchain_format;
info.swapchain.render_pass = vk->render_pass;
info.swapchain.num_indices = vk->context->num_swapchain_images;
- info.original_format = vk->tex_fmt;
vk->filter_chain = vulkan_filter_chain_create_from_preset(
&info, shader_path,
@@ -1239,6 +1239,12 @@ static void *vulkan_init(const video_info_t *video,
RARCH_LOG("[Vulkan]: Using resolution %ux%u\n", temp_width, temp_height);
+ if (!vk->ctx_driver || !vk->ctx_driver->get_context_data)
+ {
+ RARCH_ERR("[Vulkan]: Failed to get context data.\n");
+ goto error;
+ }
+
*(void**)&vk->context = vk->ctx_driver->get_context_data(vk->ctx_data);
vk->vsync = video->vsync;
@@ -1580,17 +1586,23 @@ static void vulkan_readback(vk_t *vk)
VkBufferImageCopy region;
struct vk_texture *staging;
struct video_viewport vp;
- VkMemoryBarrier barrier = { VK_STRUCTURE_TYPE_MEMORY_BARRIER };
+ VkMemoryBarrier barrier;
vulkan_viewport_info(vk, &vp);
- memset(®ion, 0, sizeof(region));
- region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.imageSubresource.layerCount = 1;
- region.imageOffset.x = vp.x;
- region.imageOffset.y = vp.y;
- region.imageExtent.width = vp.width;
- region.imageExtent.height = vp.height;
- region.imageExtent.depth = 1;
+
+ region.bufferOffset = 0;
+ region.bufferRowLength = 0;
+ region.bufferImageHeight = 0;
+ region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ region.imageSubresource.mipLevel = 0;
+ region.imageSubresource.baseArrayLayer = 0;
+ region.imageSubresource.layerCount = 1;
+ region.imageOffset.x = vp.x;
+ region.imageOffset.y = vp.y;
+ region.imageOffset.z = 0;
+ region.imageExtent.width = vp.width;
+ region.imageExtent.height = vp.height;
+ region.imageExtent.depth = 1;
staging = &vk->readback.staging[vk->context->current_frame_index];
*staging = vulkan_create_texture(vk,
@@ -1605,6 +1617,8 @@ static void vulkan_readback(vk_t *vk)
1, ®ion);
/* Make the data visible to host. */
+ barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
+ barrier.pNext = NULL;
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
vkCmdPipelineBarrier(vk->cmd,
@@ -1633,7 +1647,7 @@ static void vulkan_inject_black_frame(vk_t *vk, video_frame_info_t *video_info,
vkResetCommandBuffer(vk->cmd, 0);
vkBeginCommandBuffer(vk->cmd, &begin_info);
- vulkan_image_layout_transition(vk, vk->cmd, backbuffer->image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(vk->cmd, backbuffer->image,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
@@ -1642,7 +1656,7 @@ static void vulkan_inject_black_frame(vk_t *vk, video_frame_info_t *video_info,
vkCmdClearColorImage(vk->cmd, backbuffer->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
&clear_color, 1, &range);
- vulkan_image_layout_transition(vk, vk->cmd, backbuffer->image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(vk->cmd, backbuffer->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
@@ -1692,15 +1706,16 @@ static bool vulkan_frame(void *data, const void *frame,
uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
+ unsigned i;
+ VkSubmitInfo submit_info;
VkClearValue clear_color;
+ VkRenderPassBeginInfo rp_info;
+ VkCommandBufferBeginInfo begin_info;
VkSemaphore signal_semaphores[2];
vk_t *vk = (vk_t*)data;
- struct vk_per_frame *chain = NULL;
- struct vk_image *backbuffer = NULL;
bool waits_for_semaphores = false;
unsigned width = video_info->width;
unsigned height = video_info->height;
- void *context_data = video_info->context_data;
bool statistics_show = video_info->statistics_show;
const char *stat_text = video_info->stat_text;
bool black_frame_insertion = video_info->black_frame_insertion;
@@ -1713,22 +1728,17 @@ static bool vulkan_frame(void *data, const void *frame,
&video_info->osd_stat_params;
bool menu_is_alive = video_info->menu_is_alive;
- VkCommandBufferBeginInfo begin_info = {
- VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
- VkRenderPassBeginInfo rp_info = {
- VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO };
- VkSubmitInfo submit_info = {
- VK_STRUCTURE_TYPE_SUBMIT_INFO };
unsigned frame_index =
vk->context->current_frame_index;
unsigned swapchain_index =
vk->context->current_swapchain_index;
/* Bookkeeping on start of frame. */
- chain = &vk->swapchain[frame_index];
- backbuffer = &vk->backbuffers[swapchain_index];
- vk->chain = chain;
- vk->backbuffer = backbuffer;
+ struct vk_per_frame *chain = &vk->swapchain[frame_index];
+ struct vk_image *backbuffer = &vk->backbuffers[swapchain_index];
+
+ vk->chain = chain;
+ vk->backbuffer = backbuffer;
{
struct vk_descriptor_manager *manager = &chain->descriptor_manager;
@@ -1745,15 +1755,30 @@ static bool vulkan_frame(void *data, const void *frame,
}
/* Start recording the command buffer. */
- vk->cmd = chain->cmd;
- begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+ vk->cmd = chain->cmd;
+
+ begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ begin_info.pNext = NULL;
+ begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+ begin_info.pInheritanceInfo = NULL;
+
vkResetCommandBuffer(vk->cmd, 0);
vkBeginCommandBuffer(vk->cmd, &begin_info);
- memset(&vk->tracker, 0, sizeof(vk->tracker));
+ vk->tracker.dirty = 0;
+ vk->tracker.scissor.offset.x = 0;
+ vk->tracker.scissor.offset.y = 0;
+ vk->tracker.scissor.extent.width = 0;
+ vk->tracker.scissor.extent.height = 0;
+ vk->tracker.use_scissor = false;
+ vk->tracker.pipeline = VK_NULL_HANDLE;
+ vk->tracker.view = VK_NULL_HANDLE;
+ vk->tracker.sampler = VK_NULL_HANDLE;
+ for (i = 0; i < 16; i++)
+ vk->tracker.mvp.data[i] = 0.0f;
- waits_for_semaphores = vk->hw.enable && frame &&
+ waits_for_semaphores = vk->hw.enable && frame &&
!vk->hw.num_cmd && vk->hw.valid_semaphore;
if (waits_for_semaphores &&
@@ -1763,7 +1788,7 @@ static bool vulkan_frame(void *data, const void *frame,
retro_assert(vk->hw.image);
/* Acquire ownership of image from other queue family. */
- vulkan_transfer_image_ownership(vk->cmd,
+ VULKAN_TRANSFER_IMAGE_OWNERSHIP(vk->cmd,
vk->hw.image->create_info.image,
vk->hw.image->image_layout,
/* Create a dependency chain from semaphore wait. */
@@ -1781,7 +1806,7 @@ static bool vulkan_frame(void *data, const void *frame,
const uint8_t *src = (const uint8_t*)frame;
unsigned bpp = vk->video.rgb32 ? 4 : 2;
- if ( chain->texture.width != frame_width
+ if ( chain->texture.width != frame_width
|| chain->texture.height != frame_height)
{
chain->texture = vulkan_create_texture(vk, &chain->texture,
@@ -1795,19 +1820,19 @@ static bool vulkan_frame(void *data, const void *frame,
}
if (chain->texture.type == VULKAN_TEXTURE_STAGING)
- {
chain->texture_optimal = vulkan_create_texture(
vk,
&chain->texture_optimal,
- frame_width, frame_height, chain->texture_optimal.format,
+ frame_width, frame_height,
+ chain->texture_optimal.format,
NULL, NULL, VULKAN_TEXTURE_DYNAMIC);
- }
}
if (frame != chain->texture.mapped)
{
dst = (uint8_t*)chain->texture.mapped;
- if (chain->texture.stride == pitch && pitch == frame_width * bpp)
+ if ( (chain->texture.stride == pitch )
+ && pitch == frame_width * bpp)
memcpy(dst, src, frame_width * frame_height * bpp);
else
for (y = 0; y < frame_height; y++,
@@ -1821,16 +1846,28 @@ static bool vulkan_frame(void *data, const void *frame,
vulkan_copy_staging_to_dynamic(vk, vk->cmd,
&chain->texture_optimal, &chain->texture);
}
- else
- vulkan_sync_texture_to_gpu(vk, &chain->texture);
+ else if (chain->texture.need_manual_cache_management
+ && chain->texture.memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device,
+ chain->texture.memory);
vk->last_valid_index = frame_index;
}
/* Notify filter chain about the new sync index. */
- vulkan_filter_chain_notify_sync_index((vulkan_filter_chain_t*)vk->filter_chain, frame_index);
- vulkan_filter_chain_set_frame_count((vulkan_filter_chain_t*)vk->filter_chain, frame_count);
- vulkan_filter_chain_set_frame_direction((vulkan_filter_chain_t*)vk->filter_chain, state_manager_frame_is_reversed() ? -1 : 1);
+ vulkan_filter_chain_notify_sync_index(
+ (vulkan_filter_chain_t*)vk->filter_chain, frame_index);
+ vulkan_filter_chain_set_frame_count(
+ (vulkan_filter_chain_t*)vk->filter_chain, frame_count);
+#ifdef HAVE_REWIND
+ vulkan_filter_chain_set_frame_direction(
+ (vulkan_filter_chain_t*)vk->filter_chain,
+ state_manager_frame_is_reversed() ? -1 : 1);
+#else
+ vulkan_filter_chain_set_frame_direction(
+ (vulkan_filter_chain_t*)vk->filter_chain,
+ 1);
+#endif
/* Render offscreen filter chain passes. */
{
@@ -1870,22 +1907,24 @@ static bool vulkan_frame(void *data, const void *frame,
else
{
/* Fall back to the default, black texture.
- * This can happen if we restart the video driver while in the menu. */
- input.image = vk->default_texture.image;
- input.view = vk->default_texture.view;
- input.layout = vk->default_texture.layout;
- input.format = vk->default_texture.format;
- input.width = vk->default_texture.width;
- input.height = vk->default_texture.height;
+ * This can happen if we restart the video
+ * driver while in the menu. */
+ input.image = vk->default_texture.image;
+ input.view = vk->default_texture.view;
+ input.layout = vk->default_texture.layout;
+ input.format = vk->default_texture.format;
+ input.width = vk->default_texture.width;
+ input.height = vk->default_texture.height;
}
- vk->hw.last_width = input.width;
- vk->hw.last_height = input.height;
+ vk->hw.last_width = input.width;
+ vk->hw.last_height = input.height;
}
else
{
struct vk_texture *tex = &vk->swapchain[vk->last_valid_index].texture;
- if (vk->swapchain[vk->last_valid_index].texture_optimal.memory != VK_NULL_HANDLE)
+ if (vk->swapchain[vk->last_valid_index].texture_optimal.memory
+ != VK_NULL_HANDLE)
tex = &vk->swapchain[vk->last_valid_index].texture_optimal;
else
vulkan_transition_texture(vk, vk->cmd, tex);
@@ -1898,7 +1937,8 @@ static bool vulkan_frame(void *data, const void *frame,
input.format = VK_FORMAT_UNDEFINED; /* It's already configured. */
}
- vulkan_filter_chain_set_input_texture((vulkan_filter_chain_t*)vk->filter_chain, &input);
+ vulkan_filter_chain_set_input_texture((vulkan_filter_chain_t*)
+ vk->filter_chain, &input);
}
vulkan_set_viewport(vk, width, height, false, true);
@@ -1931,22 +1971,27 @@ static bool vulkan_frame(void *data, const void *frame,
#endif
/* Render to backbuffer. */
- if (backbuffer->image != VK_NULL_HANDLE && vk->context->has_acquired_swapchain)
+ if ( (backbuffer->image != VK_NULL_HANDLE)
+ && vk->context->has_acquired_swapchain)
{
+ rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+ rp_info.pNext = NULL;
rp_info.renderPass = vk->render_pass;
rp_info.framebuffer = backbuffer->framebuffer;
+ rp_info.renderArea.offset.x = 0;
+ rp_info.renderArea.offset.y = 0;
rp_info.renderArea.extent.width = vk->context->swapchain_width;
rp_info.renderArea.extent.height = vk->context->swapchain_height;
rp_info.clearValueCount = 1;
rp_info.pClearValues = &clear_color;
- clear_color.color.float32[0] = 0.0f;
- clear_color.color.float32[1] = 0.0f;
- clear_color.color.float32[2] = 0.0f;
- clear_color.color.float32[3] = 0.0f;
+ clear_color.color.float32[0] = 0.0f;
+ clear_color.color.float32[1] = 0.0f;
+ clear_color.color.float32[2] = 0.0f;
+ clear_color.color.float32[3] = 0.0f;
/* Prepare backbuffer for rendering. */
- vulkan_image_layout_transition(vk, vk->cmd, backbuffer->image,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(vk->cmd, backbuffer->image,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
@@ -2040,7 +2085,7 @@ static bool vulkan_frame(void *data, const void *frame,
*
* If we're reading back, perform the readback before presenting.
*/
- vulkan_image_layout_transition(vk,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(
vk->cmd, backbuffer->image,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
@@ -2052,7 +2097,7 @@ static bool vulkan_frame(void *data, const void *frame,
vulkan_readback(vk);
/* Prepare for presentation after transfers are complete. */
- vulkan_image_layout_transition(vk, vk->cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(vk->cmd,
backbuffer->image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
@@ -2067,7 +2112,7 @@ static bool vulkan_frame(void *data, const void *frame,
vk->context->has_acquired_swapchain)
{
/* Prepare backbuffer for presentation. */
- vulkan_image_layout_transition(vk, vk->cmd,
+ VULKAN_IMAGE_LAYOUT_TRANSITION(vk->cmd,
backbuffer->image,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
@@ -2084,7 +2129,7 @@ static bool vulkan_frame(void *data, const void *frame,
retro_assert(vk->hw.image);
/* Release ownership of image back to other queue family. */
- vulkan_transfer_image_ownership(vk->cmd,
+ VULKAN_TRANSFER_IMAGE_OWNERSHIP(vk->cmd,
vk->hw.image->create_info.image,
vk->hw.image->image_layout,
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
@@ -2095,6 +2140,15 @@ static bool vulkan_frame(void *data, const void *frame,
vkEndCommandBuffer(vk->cmd);
/* Submit command buffers to GPU. */
+ submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+ submit_info.pNext = NULL;
+ submit_info.waitSemaphoreCount = 0;
+ submit_info.pWaitSemaphores = NULL;
+ submit_info.pWaitDstStageMask = NULL;
+ submit_info.commandBufferCount = 1;
+ submit_info.pCommandBuffers = &vk->cmd;
+ submit_info.signalSemaphoreCount = 0;
+ submit_info.pSignalSemaphores = NULL;
if (vk->hw.num_cmd)
{
@@ -2106,11 +2160,6 @@ static bool vulkan_frame(void *data, const void *frame,
vk->hw.num_cmd = 0;
}
- else
- {
- submit_info.commandBufferCount = 1;
- submit_info.pCommandBuffers = &vk->cmd;
- }
if (waits_for_semaphores)
{
@@ -2119,7 +2168,7 @@ static bool vulkan_frame(void *data, const void *frame,
submit_info.pWaitDstStageMask = vk->hw.wait_dst_stages;
/* Consume the semaphores. */
- vk->hw.valid_semaphore = false;
+ vk->hw.valid_semaphore = false;
/* We allocated space for this. */
if (vk->context->has_acquired_swapchain &&
@@ -2151,9 +2200,8 @@ static bool vulkan_frame(void *data, const void *frame,
submit_info.pWaitDstStageMask = &wait_stage;
}
- submit_info.signalSemaphoreCount = 0;
-
- if (vk->context->swapchain_semaphores[swapchain_index] != VK_NULL_HANDLE &&
+ if (vk->context->swapchain_semaphores[swapchain_index]
+ != VK_NULL_HANDLE &&
vk->context->has_acquired_swapchain)
{
signal_semaphores[submit_info.signalSemaphoreCount++] = vk->context->swapchain_semaphores[swapchain_index];
@@ -2176,12 +2224,12 @@ static bool vulkan_frame(void *data, const void *frame,
slock_unlock(vk->context->queue_lock);
#endif
- vk->ctx_driver->swap_buffers(context_data);
+ vk->ctx_driver->swap_buffers(vk->ctx_data);
if (!vk->context->swap_interval_emulation_lock)
{
if (vk->ctx_driver->update_window_title)
- vk->ctx_driver->update_window_title(context_data);
+ vk->ctx_driver->update_window_title(vk->ctx_data);
}
/* Handle spurious swapchain invalidations as soon as we can,
@@ -2192,10 +2240,12 @@ static bool vulkan_frame(void *data, const void *frame,
mode.width = width;
mode.height = height;
- video_info->cb_set_resize(context_data, mode.width, mode.height);
+ if (vk->ctx_driver->set_resize)
+ vk->ctx_driver->set_resize(vk->ctx_data, mode.width, mode.height);
vk->should_resize = false;
}
+
vulkan_check_swapchain(vk);
/* Disable BFI during fast forward, slow-motion,
@@ -2207,9 +2257,10 @@ static bool vulkan_frame(void *data, const void *frame,
&& !input_driver_nonblock_state
&& !runloop_is_slowmotion
&& !runloop_is_paused)
- vulkan_inject_black_frame(vk, video_info, context_data);
+ vulkan_inject_black_frame(vk, video_info, vk->ctx_data);
- /* Vulkan doesn't directly support swap_interval > 1, so we fake it by duping out more frames. */
+ /* Vulkan doesn't directly support swap_interval > 1,
+ * so we fake it by duping out more frames. */
if ( vk->context->swap_interval > 1
&& !vk->context->swap_interval_emulation_lock)
{
@@ -2324,13 +2375,13 @@ static void vulkan_set_texture_frame(void *data,
float alpha)
{
unsigned y, stride;
- uint8_t *ptr = NULL;
- uint8_t *dst = NULL;
- const uint8_t *src = NULL;
- vk_t *vk = (vk_t*)data;
- unsigned index = 0;
- struct vk_texture *texture = NULL;
- struct vk_texture *texture_optimal = NULL;
+ uint8_t *ptr = NULL;
+ uint8_t *dst = NULL;
+ const uint8_t *src = NULL;
+ vk_t *vk = (vk_t*)data;
+ unsigned index = 0;
+ struct vk_texture *texture = NULL;
+ struct vk_texture *texture_optimal = NULL;
const VkComponentMapping br_swizzle = {
VK_COMPONENT_SWIZZLE_B,
VK_COMPONENT_SWIZZLE_G,
@@ -2376,8 +2427,9 @@ static void vulkan_set_texture_frame(void *data,
NULL, rgb32 ? NULL : &br_swizzle,
VULKAN_TEXTURE_DYNAMIC);
}
- else
- vulkan_sync_texture_to_gpu(vk, texture);
+ else if (texture->need_manual_cache_management
+ && texture->memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, texture->memory);
vkUnmapMemory(vk->context->device, texture->memory);
vk->menu.dirty[index] = true;
@@ -2577,7 +2629,9 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle)
vkMapMemory(vk->context->device, staging->memory,
staging->offset, staging->size, 0, (void**)&src);
- vulkan_sync_texture_to_cpu(vk, staging);
+ if (staging->need_manual_cache_management
+ && staging->memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_CPU(vk->context->device, staging->memory);
ctx->in_stride = staging->stride;
ctx->out_stride = -(int)vk->vp.width * 3;
@@ -2611,7 +2665,9 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle)
VK_MAP_PERSISTENT_TEXTURE(vk->context->device, staging);
}
- vulkan_sync_texture_to_cpu(vk, staging);
+ if (staging->need_manual_cache_management
+ && staging->memory != VK_NULL_HANDLE)
+ VULKAN_SYNC_TEXTURE_TO_CPU(vk->context->device, staging->memory);
{
unsigned x, y;
@@ -2731,6 +2787,7 @@ static void vulkan_render_overlay(vk_t *vk, unsigned width,
{
struct vk_draw_triangles call;
struct vk_buffer_range range;
+
if (!vulkan_buffer_chain_alloc(vk->context, &vk->chain->vbo,
4 * sizeof(struct vk_vertex), &range))
break;
@@ -2738,15 +2795,14 @@ static void vulkan_render_overlay(vk_t *vk, unsigned width,
memcpy(range.data, &vk->overlay.vertex[i * 4],
4 * sizeof(struct vk_vertex));
- memset(&call, 0, sizeof(call));
- call.pipeline = vk->display.pipelines[3]; /* Strip with blend */
+ call.vertices = 4;
+ call.uniform_size = sizeof(vk->mvp);
+ call.uniform = &vk->mvp;
+ call.vbo = ⦥
call.texture = &vk->overlay.images[i];
+ call.pipeline = vk->display.pipelines[3]; /* Strip with blend */
call.sampler = call.texture->mipmap ?
vk->samplers.mipmap_linear : vk->samplers.linear;
- call.uniform = &vk->mvp;
- call.uniform_size = sizeof(vk->mvp);
- call.vbo = ⦥
- call.vertices = 4;
vulkan_draw_triangles(vk, &call);
}
diff --git a/gfx/drivers_context/android_ctx.c b/gfx/drivers_context/android_ctx.c
index 7198b974e1..e4b4bdd57f 100644
--- a/gfx/drivers_context/android_ctx.c
+++ b/gfx/drivers_context/android_ctx.c
@@ -33,23 +33,12 @@
#include "../common/gl_common.h"
#endif
-#ifdef HAVE_VULKAN
-#include "../common/vulkan_common.h"
-#endif
-
#include "../../frontend/frontend_driver.h"
#include "../../frontend/drivers/platform_unix.h"
#include "../../verbosity.h"
#include "../../configuration.h"
-static enum gfx_ctx_api android_api = GFX_CTX_NONE;
-
-/* forward declaration */
-int system_property_get(const char *cmd, const char *args, char *value);
-
#ifdef HAVE_OPENGLES
-static bool g_es3 = false;
-
#ifndef EGL_OPENGL_ES3_BIT_KHR
#define EGL_OPENGL_ES3_BIT_KHR 0x0040
#endif
@@ -60,44 +49,24 @@ typedef struct
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
-#ifdef HAVE_VULKAN
- gfx_ctx_vulkan_data_t vk;
- unsigned width;
- unsigned height;
- int swap_interval;
-#endif
} android_ctx_data_t;
+/* TODO/FIXME - static globals */
+static enum gfx_ctx_api android_api = GFX_CTX_NONE;
+#ifdef HAVE_OPENGLES
+static bool g_es3 = false;
+#endif
+
static void android_gfx_ctx_destroy(void *data)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
-#ifdef HAVE_VULKAN
- struct android_app *android_app = (struct android_app*)g_android;
-#endif
if (!and)
return;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- egl_destroy(&and->egl);
+ egl_destroy(&and->egl);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- vulkan_context_destroy(&and->vk, android_app->window);
-
- if (and->vk.context.queue_lock)
- slock_free(and->vk.context.queue_lock);
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
free(data);
}
@@ -123,7 +92,8 @@ static void *android_gfx_ctx_init(void *video_driver)
};
#endif
struct android_app *android_app = (struct android_app*)g_android;
- android_ctx_data_t *and = (android_ctx_data_t*)calloc(1, sizeof(*and));
+ android_ctx_data_t *and = (android_ctx_data_t*)
+ calloc(1, sizeof(*and));
if (!android_app || !and)
return false;
@@ -133,56 +103,33 @@ static void *android_gfx_ctx_init(void *video_driver)
attribs[1] = EGL_OPENGL_ES3_BIT_KHR;
#endif
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
+ RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
- if (!egl_init_context(&and->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
- &major, &minor, &n, attribs, NULL))
- {
- egl_report_error();
- goto error;
- }
-
- if (!egl_get_native_visual_id(&and->egl, &format))
- goto error;
-#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- if (!vulkan_context_init(&and->vk, VULKAN_WSI_ANDROID))
- goto error;
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
+ if (!egl_init_context(&and->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
+ &major, &minor, &n, attribs, NULL))
+ {
+ egl_report_error();
+ goto error;
}
+ if (!egl_get_native_visual_id(&and->egl, &format))
+ goto error;
+#endif
+
slock_lock(android_app->mutex);
if (!android_app->window)
- goto unlock_error;
-
- switch (android_api)
{
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format);
-
- break;
- case GFX_CTX_NONE:
- default:
- break;
+ slock_unlock(android_app->mutex);
+ android_gfx_ctx_destroy(and);
+ return NULL;
}
+ ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format);
+
slock_unlock(android_app->mutex);
return and;
-unlock_error:
- slock_unlock(android_app->mutex);
error:
android_gfx_ctx_destroy(and);
@@ -194,66 +141,23 @@ static void android_gfx_ctx_get_video_size(void *data,
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- egl_get_video_size(&and->egl, width, height);
+ egl_get_video_size(&and->egl, width, height);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- *width = and->width;
- *height = and->height;
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
}
static void android_gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
-#ifdef HAVE_VULKAN
- struct android_app *android_app = (struct android_app*)g_android;
-#endif
-
unsigned new_width = 0;
unsigned new_height = 0;
android_ctx_data_t *and = (android_ctx_data_t*)data;
- *quit = false;
+ *quit = false;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- egl_get_video_size(&and->egl, &new_width, &new_height);
+ egl_get_video_size(&and->egl, &new_width, &new_height);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- if (android_app->content_rect.changed)
- {
- and->vk.need_new_swapchain = true;
- android_app->content_rect.changed = false;
- }
-
- /* Swapchains are recreated in set_resize as a
- * central place, so use that to trigger swapchain reinit. */
- *resize = and->vk.need_new_swapchain;
- new_width = android_app->content_rect.width;
- new_height = android_app->content_rect.height;
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
if (new_width != *width || new_height != *height)
{
@@ -267,54 +171,17 @@ static void android_gfx_ctx_check_window(void *data, bool *quit,
}
static bool android_gfx_ctx_set_resize(void *data,
- unsigned width, unsigned height)
-{
-#ifdef HAVE_VULKAN
- android_ctx_data_t *and = (android_ctx_data_t*)data;
- struct android_app *android_app = (struct android_app*)g_android;
-#endif
- (void)data;
- (void)width;
- (void)height;
-
- switch (android_api)
- {
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- and->width = android_app->content_rect.width;
- and->height = android_app->content_rect.height;
- RARCH_LOG("[Android]: Native window size: %u x %u.\n", and->width, and->height);
- if (!vulkan_create_swapchain(&and->vk, and->width, and->height, and->swap_interval))
- {
- RARCH_ERR("[Android]: Failed to update swapchain.\n");
- return false;
- }
-
- if (and->vk.created_new_swapchain)
- vulkan_acquire_next_image(&and->vk);
- and->vk.context.invalid_swapchain = true;
- and->vk.need_new_swapchain = false;
-#endif
- break;
-
- case GFX_CTX_NONE:
- default:
- break;
- }
-
- return false;
-}
+ unsigned width, unsigned height) { return false; }
static bool android_gfx_ctx_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
-#if defined(HAVE_OPENGLES) || defined(HAVE_VULKAN)
+#if defined(HAVE_OPENGLES)
struct android_app *android_app = (struct android_app*)g_android;
- android_ctx_data_t *and = (android_ctx_data_t*)data;
-#endif
-#if defined(HAVE_OPENGLES) && defined(HAVE_EGL)
- EGLint context_attributes[] = {
+ android_ctx_data_t *and = (android_ctx_data_t*)data;
+#if defined(HAVE_EGL)
+ EGLint context_attributes[] = {
EGL_CONTEXT_CLIENT_VERSION, g_es3 ? 3 : 2,
#if 0
EGL_CONTEXT_FLAGS_KHR, debug ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0,
@@ -322,10 +189,7 @@ static bool android_gfx_ctx_set_video_mode(void *data,
EGL_NONE
};
#endif
-
- (void)width;
- (void)height;
- (void)fullscreen;
+#endif
switch (android_api)
{
@@ -341,19 +205,6 @@ static bool android_gfx_ctx_set_video_mode(void *data,
if (!egl_create_surface(&and->egl, android_app->window))
return false;
-#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- and->width = ANativeWindow_getWidth(android_app->window);
- and->height = ANativeWindow_getHeight(android_app->window);
- RARCH_LOG("[Android]: Native window size: %u x %u.\n", and->width, and->height);
- if (!vulkan_surface_create(&and->vk, VULKAN_WSI_ANDROID, NULL, android_app->window,
- and->width, and->height, and->swap_interval))
- {
- RARCH_ERR("[Android]: Failed to create surface.\n");
- return false;
- }
#endif
break;
@@ -384,36 +235,20 @@ static bool android_gfx_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
unsigned version;
-
android_api = api;
- switch (api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGLES
- version = major * 100 + minor;
- if (version > 300)
- return false;
- if (version < 300)
- g_es3 = false;
- else if (version == 300)
- g_es3 = true;
+ version = major * 100 + minor;
+ if (version > 300)
+ return false;
+ if (version < 300)
+ g_es3 = false;
+ else if (version == 300)
+ g_es3 = true;
- if (api == GFX_CTX_OPENGL_ES_API)
- return true;
+ if (api == GFX_CTX_OPENGL_ES_API)
+ return true;
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- return true;
-#else
- break;
-#endif
- case GFX_CTX_NONE:
- default:
- break;
- }
return false;
}
@@ -432,39 +267,7 @@ static bool android_gfx_ctx_has_focus(void *data)
return focused;
}
-static bool android_gfx_ctx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-static void dpi_get_density(char *s, size_t len)
-{
- static bool inited_once = false;
- static bool inited2_once = false;
- static char string[PROP_VALUE_MAX] = {0};
- static char string2[PROP_VALUE_MAX] = {0};
- if (!inited_once)
- {
- system_property_get("getprop", "ro.sf.lcd_density", string);
- inited_once = true;
- }
-
- if (!string_is_empty(string))
- {
- strlcpy(s, string, len);
- return;
- }
-
- if (!inited2_once)
- {
- system_property_get("wm", "density", string2);
- inited2_once = true;
- }
-
- strlcpy(s, string2, len);
-}
+static bool android_gfx_ctx_suppress_screensaver(void *data, bool enable) { return false; }
static bool android_gfx_ctx_get_metrics(void *data,
enum display_metric_types type, float *value)
@@ -474,7 +277,6 @@ static bool android_gfx_ctx_get_metrics(void *data,
switch (type)
{
case DISPLAY_METRIC_MM_WIDTH:
- return false;
case DISPLAY_METRIC_MM_HEIGHT:
return false;
case DISPLAY_METRIC_DPI:
@@ -483,7 +285,7 @@ static bool android_gfx_ctx_get_metrics(void *data,
char density[PROP_VALUE_MAX];
density[0] = '\0';
- dpi_get_density(density, sizeof(density));
+ android_dpi_get_density(density, sizeof(density));
if (string_is_empty(density))
goto dpi_fallback;
dpi = atoi(density);
@@ -513,130 +315,40 @@ static void android_gfx_ctx_swap_buffers(void *data)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- egl_swap_buffers(&and->egl);
+ egl_swap_buffers(&and->egl);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- vulkan_present(&and->vk, and->vk.context.current_swapchain_index);
- vulkan_acquire_next_image(&and->vk);
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
}
static void android_gfx_ctx_set_swap_interval(void *data, int swap_interval)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- egl_set_swap_interval(&and->egl, swap_interval);
+ egl_set_swap_interval(&and->egl, swap_interval);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#ifdef HAVE_VULKAN
- if (and->swap_interval != swap_interval)
- {
- RARCH_LOG("[Vulkan]: Setting swap interval: %u.\n", swap_interval);
- and->swap_interval = swap_interval;
- if (and->vk.swapchain)
- and->vk.need_new_swapchain = true;
- }
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
-}
-
-static gfx_ctx_proc_t android_gfx_ctx_get_proc_address(const char *symbol)
-{
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#else
- break;
-#endif
- case GFX_CTX_NONE:
- default:
- break;
- }
-
- return NULL;
}
static void android_gfx_ctx_bind_hw_render(void *data, bool enable)
{
android_ctx_data_t *and = (android_ctx_data_t*)data;
-
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_EGL
- egl_bind_hw_render(&and->egl, enable);
+ egl_bind_hw_render(&and->egl, enable);
#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
}
-#ifdef HAVE_VULKAN
-static void *android_gfx_ctx_get_context_data(void *data)
-{
- android_ctx_data_t *and = (android_ctx_data_t*)data;
- return &and->vk.context;
-}
-#endif
-
static uint32_t android_gfx_ctx_get_flags(void *data)
{
uint32_t flags = 0;
- switch (android_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_GLSL
- BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
+ BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
- break;
- case GFX_CTX_VULKAN_API:
-#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
- BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
-#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
return flags;
}
-static void android_gfx_ctx_set_flags(void *data, uint32_t flags)
-{
- (void)flags;
-}
+static void android_gfx_ctx_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_android = {
android_gfx_ctx_init,
@@ -660,7 +372,11 @@ const gfx_ctx_driver_t gfx_ctx_android = {
false, /* has_windowed */
android_gfx_ctx_swap_buffers,
android_gfx_ctx_input_driver,
- android_gfx_ctx_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
@@ -668,10 +384,6 @@ const gfx_ctx_driver_t gfx_ctx_android = {
android_gfx_ctx_get_flags,
android_gfx_ctx_set_flags,
android_gfx_ctx_bind_hw_render,
-#ifdef HAVE_VULKAN
- android_gfx_ctx_get_context_data,
-#else
NULL,
-#endif
NULL
};
diff --git a/gfx/drivers_context/android_vk_ctx.c b/gfx/drivers_context/android_vk_ctx.c
new file mode 100644
index 0000000000..91b66127e2
--- /dev/null
+++ b/gfx/drivers_context/android_vk_ctx.c
@@ -0,0 +1,331 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2017 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+#include
+
+#include
+
+#include
+#include
+#include
+
+#ifdef HAVE_CONFIG_H
+#include "../../config.h"
+#endif
+
+#include "../common/vulkan_common.h"
+
+#include "../../frontend/frontend_driver.h"
+#include "../../frontend/drivers/platform_unix.h"
+#include "../../verbosity.h"
+#include "../../configuration.h"
+
+typedef struct
+{
+ gfx_ctx_vulkan_data_t vk;
+ unsigned width;
+ unsigned height;
+ int swap_interval;
+} android_ctx_data_vk_t;
+
+static void android_gfx_ctx_vk_destroy(void *data)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+ struct android_app *android_app = (struct android_app*)g_android;
+
+ if (!and)
+ return;
+
+ vulkan_context_destroy(&and->vk, android_app->window);
+
+ if (and->vk.context.queue_lock)
+ slock_free(and->vk.context.queue_lock);
+
+ free(data);
+}
+
+static void *android_gfx_ctx_vk_init(void *video_driver)
+{
+ struct android_app *android_app = (struct android_app*)g_android;
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)calloc(1, sizeof(*and));
+
+ if (!android_app || !and)
+ return false;
+
+ if (!vulkan_context_init(&and->vk, VULKAN_WSI_ANDROID))
+ goto error;
+
+ slock_lock(android_app->mutex);
+ if (!android_app->window)
+ {
+ slock_unlock(android_app->mutex);
+ android_gfx_ctx_vk_destroy(and);
+ return NULL;
+ }
+
+ slock_unlock(android_app->mutex);
+ return and;
+
+error:
+ android_gfx_ctx_vk_destroy(and);
+
+ return NULL;
+}
+
+static void android_gfx_ctx_vk_get_video_size(void *data,
+ unsigned *width, unsigned *height)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+
+ *width = and->width;
+ *height = and->height;
+}
+
+static void android_gfx_ctx_vk_check_window(void *data, bool *quit,
+ bool *resize, unsigned *width, unsigned *height)
+{
+ struct android_app *android_app = (struct android_app*)g_android;
+
+ unsigned new_width = 0;
+ unsigned new_height = 0;
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+
+ *quit = false;
+
+ if (android_app->content_rect.changed)
+ {
+ and->vk.need_new_swapchain = true;
+ android_app->content_rect.changed = false;
+ }
+
+ /* Swapchains are recreated in set_resize as a
+ * central place, so use that to trigger swapchain reinit. */
+ *resize = and->vk.need_new_swapchain;
+ new_width = android_app->content_rect.width;
+ new_height = android_app->content_rect.height;
+
+ if (new_width != *width || new_height != *height)
+ {
+ RARCH_LOG("[Android]: Resizing (%u x %u) -> (%u x %u).\n",
+ *width, *height, new_width, new_height);
+
+ *width = new_width;
+ *height = new_height;
+ *resize = true;
+ }
+}
+
+static bool android_gfx_ctx_vk_set_resize(void *data,
+ unsigned width, unsigned height)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+ struct android_app *android_app = (struct android_app*)g_android;
+
+ and->width = android_app->content_rect.width;
+ and->height = android_app->content_rect.height;
+ RARCH_LOG("[Android]: Native window size: %u x %u.\n", and->width, and->height);
+ if (!vulkan_create_swapchain(&and->vk, and->width, and->height, and->swap_interval))
+ {
+ RARCH_ERR("[Android]: Failed to update swapchain.\n");
+ return false;
+ }
+
+ if (and->vk.created_new_swapchain)
+ vulkan_acquire_next_image(&and->vk);
+ and->vk.context.invalid_swapchain = true;
+ and->vk.need_new_swapchain = false;
+
+ return true;
+}
+
+static bool android_gfx_ctx_vk_set_video_mode(void *data,
+ unsigned width, unsigned height,
+ bool fullscreen)
+{
+ struct android_app *android_app = (struct android_app*)g_android;
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+
+ and->width = ANativeWindow_getWidth(android_app->window);
+ and->height = ANativeWindow_getHeight(android_app->window);
+ RARCH_LOG("[Android]: Native window size: %u x %u.\n",
+ and->width, and->height);
+ if (!vulkan_surface_create(&and->vk, VULKAN_WSI_ANDROID,
+ NULL, android_app->window,
+ and->width, and->height, and->swap_interval))
+ {
+ RARCH_ERR("[Android]: Failed to create surface.\n");
+ return false;
+ }
+
+ return true;
+}
+
+static void android_gfx_ctx_vk_input_driver(void *data,
+ const char *joypad_name,
+ input_driver_t **input, void **input_data)
+{
+ void *androidinput = input_android.init(joypad_name);
+
+ *input = androidinput ? &input_android : NULL;
+ *input_data = androidinput;
+}
+
+static enum gfx_ctx_api android_gfx_ctx_vk_get_api(void *data)
+{
+ return GFX_CTX_VULKAN_API;
+}
+
+static bool android_gfx_ctx_vk_bind_api(void *data,
+ enum gfx_ctx_api api, unsigned major, unsigned minor)
+{
+ if (api == GFX_CTX_VULKAN_API)
+ return true;
+ return false;
+}
+
+static bool android_gfx_ctx_vk_has_focus(void *data)
+{
+ bool focused = false;
+ struct android_app *android_app = (struct android_app*)g_android;
+ if (!android_app)
+ return true;
+
+ slock_lock(android_app->mutex);
+ focused = !android_app->unfocused;
+ slock_unlock(android_app->mutex);
+
+ return focused;
+}
+
+static bool android_gfx_ctx_vk_suppress_screensaver(void *data, bool enable) { return false; }
+
+static bool android_gfx_ctx_vk_get_metrics(void *data,
+ enum display_metric_types type, float *value)
+{
+ static int dpi = -1;
+
+ switch (type)
+ {
+ case DISPLAY_METRIC_MM_WIDTH:
+ case DISPLAY_METRIC_MM_HEIGHT:
+ return false;
+ case DISPLAY_METRIC_DPI:
+ if (dpi == -1)
+ {
+ char density[PROP_VALUE_MAX];
+ density[0] = '\0';
+
+ android_dpi_get_density(density, sizeof(density));
+ if (string_is_empty(density))
+ goto dpi_fallback;
+ dpi = atoi(density);
+
+ if (dpi <= 0)
+ goto dpi_fallback;
+ }
+ *value = (float)dpi;
+ break;
+ case DISPLAY_METRIC_NONE:
+ default:
+ *value = 0;
+ return false;
+ }
+
+ return true;
+
+dpi_fallback:
+ /* add a fallback in case the device doesn't report DPI.
+ * Hopefully fixes issues with the moto G2. */
+ dpi = 90;
+ *value = (float)dpi;
+ return true;
+}
+
+static void android_gfx_ctx_vk_swap_buffers(void *data)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+
+ vulkan_present(&and->vk, and->vk.context.current_swapchain_index);
+ vulkan_acquire_next_image(&and->vk);
+}
+
+static void android_gfx_ctx_vk_set_swap_interval(void *data, int swap_interval)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+
+ if (and->swap_interval != swap_interval)
+ {
+ RARCH_LOG("[Vulkan]: Setting swap interval: %u.\n", swap_interval);
+ and->swap_interval = swap_interval;
+ if (and->vk.swapchain)
+ and->vk.need_new_swapchain = true;
+ }
+}
+
+static gfx_ctx_proc_t android_gfx_ctx_vk_get_proc_address(const char *symbol) { return NULL; }
+static void android_gfx_ctx_vk_bind_hw_render(void *data, bool enable) { }
+
+static void *android_gfx_ctx_vk_get_context_data(void *data)
+{
+ android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)data;
+ return &and->vk.context;
+}
+
+static uint32_t android_gfx_ctx_vk_get_flags(void *data)
+{
+ uint32_t flags = 0;
+
+#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
+ BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
+#endif
+
+ return flags;
+}
+
+static void android_gfx_ctx_vk_set_flags(void *data, uint32_t flags) { }
+
+const gfx_ctx_driver_t gfx_ctx_vk_android = {
+ android_gfx_ctx_vk_init,
+ android_gfx_ctx_vk_destroy,
+ android_gfx_ctx_vk_get_api,
+ android_gfx_ctx_vk_bind_api,
+ android_gfx_ctx_vk_set_swap_interval,
+ android_gfx_ctx_vk_set_video_mode,
+ android_gfx_ctx_vk_get_video_size,
+ NULL, /* get_refresh_rate */
+ NULL, /* get_video_output_size */
+ NULL, /* get_video_output_prev */
+ NULL, /* get_video_output_next */
+ android_gfx_ctx_vk_get_metrics,
+ NULL,
+ NULL, /* update_title */
+ android_gfx_ctx_vk_check_window,
+ android_gfx_ctx_vk_set_resize,
+ android_gfx_ctx_vk_has_focus,
+ android_gfx_ctx_vk_suppress_screensaver,
+ false, /* has_windowed */
+ android_gfx_ctx_vk_swap_buffers,
+ android_gfx_ctx_vk_input_driver,
+ android_gfx_ctx_vk_get_proc_address,
+ NULL,
+ NULL,
+ NULL,
+ "android_vk",
+ android_gfx_ctx_vk_get_flags,
+ android_gfx_ctx_vk_set_flags,
+ android_gfx_ctx_vk_bind_hw_render,
+ android_gfx_ctx_vk_get_context_data,
+ NULL
+};
diff --git a/gfx/drivers_context/cgl_ctx.c b/gfx/drivers_context/cgl_ctx.c
index a427031117..04eab3409f 100644
--- a/gfx/drivers_context/cgl_ctx.c
+++ b/gfx/drivers_context/cgl_ctx.c
@@ -56,8 +56,6 @@ extern CGLError CGLSetSurface(CGLContextObj gl, CGSConnectionID cid, CGSWindowID
}
#endif
-static enum gfx_ctx_api cgl_api = GFX_CTX_NONE;
-
typedef struct gfx_ctx_cgl_data
{
CGLContextObj glCtx;
@@ -106,15 +104,7 @@ static void gfx_ctx_cgl_swap_buffers(void *data)
static bool gfx_ctx_cgl_set_video_mode(void *data,
unsigned width, unsigned height,
- bool fullscreen)
-{
- (void)data;
- (void)width;
- (void)height;
- (void)fullscreen;
-
- return true;
-}
+ bool fullscreen) { return true; }
static void gfx_ctx_cgl_destroy(void *data)
{
@@ -135,12 +125,7 @@ static void gfx_ctx_cgl_destroy(void *data)
static void gfx_ctx_cgl_input_driver(void *data,
const char *name,
- input_driver_t **input, void **input_data)
-{
- (void)data;
- (void)input;
- (void)input_data;
-}
+ input_driver_t **input, void **input_data) { }
static gfx_ctx_proc_t gfx_ctx_cgl_get_proc_address(const char *symbol_name)
{
@@ -161,53 +146,25 @@ static gfx_ctx_proc_t gfx_ctx_cgl_get_proc_address(const char *symbol_name)
return ret;
}
-static bool gfx_ctx_cgl_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_cgl_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-static enum gfx_ctx_api gfx_ctx_cgl_get_api(void *data)
-{
- return cgl_api;
-}
+static bool gfx_ctx_cgl_has_focus(void *data) { return true; }
+static bool gfx_ctx_cgl_suppress_screensaver(void *data, bool enable) { return false; }
+static enum gfx_ctx_api gfx_ctx_cgl_get_api(void *data) { return GFX_CTX_OPENGL_API; }
static bool gfx_ctx_cgl_bind_api(void *data, enum gfx_ctx_api api,
unsigned major, unsigned minor)
{
- (void)data;
- (void)api;
- (void)major;
- (void)minor;
-
if (api == GFX_CTX_OPENGL_API)
- {
- cgl_api = api;
return true;
- }
return false;
}
-static void gfx_ctx_cgl_show_mouse(void *data, bool state)
-{
- (void)data;
- (void)state;
-}
+static void gfx_ctx_cgl_show_mouse(void *data, bool state) { }
static void gfx_ctx_cgl_bind_hw_render(void *data, bool enable)
{
gfx_ctx_cgl_data_t *cgl = (gfx_ctx_cgl_data_t*)data;
- (void)enable;
-
CGLSetCurrentContext(cgl->glCtx);
/* TODO - needs to handle HW render context too */
@@ -342,10 +299,7 @@ static uint32_t gfx_ctx_cgl_get_flags(void *data)
return flags;
}
-static void gfx_ctx_cgl_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void gfx_ctx_cgl_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_cgl = {
gfx_ctx_cgl_init,
diff --git a/gfx/drivers_context/drm_ctx.c b/gfx/drivers_context/drm_ctx.c
index e1c8db1d78..ad65db7b44 100644
--- a/gfx/drivers_context/drm_ctx.c
+++ b/gfx/drivers_context/drm_ctx.c
@@ -66,15 +66,6 @@
#define EGL_PLATFORM_GBM_KHR 0x31D7
#endif
-static enum gfx_ctx_api drm_api = GFX_CTX_NONE;
-
-static struct gbm_bo *g_bo = NULL;
-static struct gbm_bo *g_next_bo = NULL;
-static struct gbm_surface *g_gbm_surface = NULL;
-static struct gbm_device *g_gbm_dev = NULL;
-
-static bool waiting_for_flip = false;
-
typedef struct gfx_ctx_drm_data
{
#ifdef HAVE_EGL
@@ -86,6 +77,11 @@ typedef struct gfx_ctx_drm_data
unsigned fb_height;
bool core_hw_context_enable;
+ bool waiting_for_flip;
+ struct gbm_bo *bo;
+ struct gbm_bo *next_bo;
+ struct gbm_surface *gbm_surface;
+ struct gbm_device *gbm_dev;
} gfx_ctx_drm_data_t;
struct drm_fb
@@ -94,6 +90,8 @@ struct drm_fb
uint32_t fb_id;
};
+static enum gfx_ctx_api drm_api = GFX_CTX_NONE;
+
static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
{
struct drm_fb *fb = (struct drm_fb*)data;
@@ -146,10 +144,6 @@ static void gfx_ctx_drm_swap_interval(void *data, int interval)
static void gfx_ctx_drm_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
- (void)data;
- (void)width;
- (void)height;
-
*resize = false;
*quit = (bool)frontend_driver_get_signal_handler_state();
}
@@ -157,10 +151,6 @@ static void gfx_ctx_drm_check_window(void *data, bool *quit,
static void drm_flip_handler(int fd, unsigned frame,
unsigned sec, unsigned usec, void *data)
{
- (void)fd;
- (void)sec;
- (void)usec;
-
#if 0
static unsigned first_page_flip;
static unsigned last_page_flip;
@@ -182,47 +172,47 @@ static void drm_flip_handler(int fd, unsigned frame,
*(bool*)data = false;
}
-static bool gfx_ctx_drm_wait_flip(bool block)
+static bool gfx_ctx_drm_wait_flip(gfx_ctx_drm_data_t *drm, bool block)
{
int timeout = 0;
- if (!waiting_for_flip)
+ if (!drm->waiting_for_flip)
return false;
if (block)
timeout = -1;
- while (waiting_for_flip)
+ while (drm->waiting_for_flip)
{
if (!drm_wait_flip(timeout))
break;
}
- if (waiting_for_flip)
+ if (drm->waiting_for_flip)
return true;
/* Page flip has taken place. */
/* This buffer is not on-screen anymore. Release it to GBM. */
- gbm_surface_release_buffer(g_gbm_surface, g_bo);
+ gbm_surface_release_buffer(drm->gbm_surface, drm->bo);
/* This buffer is being shown now. */
- g_bo = g_next_bo;
+ drm->bo = drm->next_bo;
return false;
}
-static bool gfx_ctx_drm_queue_flip(void)
+static bool gfx_ctx_drm_queue_flip(gfx_ctx_drm_data_t *drm)
{
struct drm_fb *fb = NULL;
- g_next_bo = gbm_surface_lock_front_buffer(g_gbm_surface);
- fb = (struct drm_fb*)gbm_bo_get_user_data(g_next_bo);
+ drm->next_bo = gbm_surface_lock_front_buffer(drm->gbm_surface);
+ fb = (struct drm_fb*)gbm_bo_get_user_data(drm->next_bo);
if (!fb)
- fb = (struct drm_fb*)drm_fb_get_from_bo(g_next_bo);
+ fb = (struct drm_fb*)drm_fb_get_from_bo(drm->next_bo);
if (drmModePageFlip(g_drm_fd, g_crtc_id, fb->fb_id,
- DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip) == 0)
+ DRM_MODE_PAGE_FLIP_EVENT, &drm->waiting_for_flip) == 0)
return true;
/* Failed to queue page flip. */
@@ -235,35 +225,26 @@ static void gfx_ctx_drm_swap_buffers(void *data)
settings_t *settings = config_get_ptr();
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- egl_swap_buffers(&drm->egl);
+ egl_swap_buffers(&drm->egl);
#endif
- break;
- default:
- break;
- }
/* I guess we have to wait for flip to have taken
* place before another flip can be queued up.
*
* If true, we are still waiting for a flip
* (nonblocking mode, so just drop the frame). */
- if (gfx_ctx_drm_wait_flip(drm->interval))
+ if (gfx_ctx_drm_wait_flip(drm, drm->interval))
return;
- waiting_for_flip = gfx_ctx_drm_queue_flip();
+ drm->waiting_for_flip = gfx_ctx_drm_queue_flip(drm);
/* Triple-buffered page flips */
if (max_swapchain_images >= 3 &&
- gbm_surface_has_free_buffers(g_gbm_surface))
+ gbm_surface_has_free_buffers(drm->gbm_surface))
return;
- gfx_ctx_drm_wait_flip(true);
+ gfx_ctx_drm_wait_flip(drm, true);
}
static void gfx_ctx_drm_get_video_size(void *data,
@@ -286,11 +267,11 @@ static void free_drm_resources(gfx_ctx_drm_data_t *drm)
/* Restore original CRTC. */
drm_restore_crtc();
- if (g_gbm_surface)
- gbm_surface_destroy(g_gbm_surface);
+ if (drm->gbm_surface)
+ gbm_surface_destroy(drm->gbm_surface);
- if (g_gbm_dev)
- gbm_device_destroy(g_gbm_dev);
+ if (drm->gbm_dev)
+ gbm_device_destroy(drm->gbm_dev);
drm_free();
@@ -303,8 +284,8 @@ static void free_drm_resources(gfx_ctx_drm_data_t *drm)
}
}
- g_gbm_surface = NULL;
- g_gbm_dev = NULL;
+ drm->gbm_surface = NULL;
+ drm->gbm_dev = NULL;
g_drm_fd = -1;
}
@@ -314,21 +295,11 @@ static void gfx_ctx_drm_destroy_resources(gfx_ctx_drm_data_t *drm)
return;
/* Make sure we acknowledge all page-flips. */
- gfx_ctx_drm_wait_flip(true);
+ gfx_ctx_drm_wait_flip(drm, true);
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- egl_destroy(&drm->egl);
+ egl_destroy(&drm->egl);
#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
free_drm_resources(drm);
@@ -339,8 +310,8 @@ static void gfx_ctx_drm_destroy_resources(gfx_ctx_drm_data_t *drm)
drm->fb_width = 0;
drm->fb_height = 0;
- g_bo = NULL;
- g_next_bo = NULL;
+ drm->bo = NULL;
+ drm->next_bo = NULL;
}
static void *gfx_ctx_drm_init(void *video_driver)
@@ -407,9 +378,9 @@ nextgpu:
drmSetMaster(g_drm_fd);
- g_gbm_dev = gbm_create_device(fd);
+ drm->gbm_dev = gbm_create_device(fd);
- if (!g_gbm_dev)
+ if (!drm->gbm_dev)
{
RARCH_WARN("[KMS]: Couldn't create GBM device.\n");
goto nextgpu;
@@ -600,35 +571,35 @@ static bool gfx_ctx_drm_egl_set_video_mode(gfx_ctx_drm_data_t *drm)
break;
}
+#ifdef HAVE_EGL
+ if (!egl_init_context(&drm->egl, EGL_PLATFORM_GBM_KHR,
+ (EGLNativeDisplayType)drm->gbm_dev, &major,
+ &minor, &n, attrib_ptr, gbm_choose_xrgb8888_cb))
+ goto error;
+
+ attr = gfx_ctx_drm_egl_fill_attribs(drm, egl_attribs);
+ egl_attribs_ptr = &egl_attribs[0];
+
+ if (!egl_create_context(&drm->egl, (attr != egl_attribs_ptr)
+ ? egl_attribs_ptr : NULL))
+ goto error;
+
+ if (!egl_create_surface(&drm->egl, (EGLNativeWindowType)drm->gbm_surface))
+ return false;
+
switch (drm_api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
-#ifdef HAVE_EGL
- if (!egl_init_context(&drm->egl, EGL_PLATFORM_GBM_KHR,
- (EGLNativeDisplayType)g_gbm_dev, &major,
- &minor, &n, attrib_ptr, gbm_choose_xrgb8888_cb))
- goto error;
-
- attr = gfx_ctx_drm_egl_fill_attribs(drm, egl_attribs);
- egl_attribs_ptr = &egl_attribs[0];
-
- if (!egl_create_context(&drm->egl, (attr != egl_attribs_ptr)
- ? egl_attribs_ptr : NULL))
- goto error;
-
- if (!egl_create_surface(&drm->egl, (EGLNativeWindowType)g_gbm_surface))
- return false;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glClear(GL_COLOR_BUFFER_BIT);
-#endif
#endif
break;
case GFX_CTX_NONE:
default:
break;
}
+#endif
egl_swap_buffers(drm);
@@ -707,40 +678,30 @@ static bool gfx_ctx_drm_set_video_mode(void *data,
drm->fb_height = g_drm_mode->vdisplay;
/* Create GBM surface. */
- g_gbm_surface = gbm_surface_create(
- g_gbm_dev,
+ drm->gbm_surface = gbm_surface_create(
+ drm->gbm_dev,
drm->fb_width,
drm->fb_height,
GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!g_gbm_surface)
+ if (!drm->gbm_surface)
{
RARCH_ERR("[KMS/EGL]: Couldn't create GBM surface.\n");
goto error;
}
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- if (!gfx_ctx_drm_egl_set_video_mode(drm))
- goto error;
+ if (!gfx_ctx_drm_egl_set_video_mode(drm))
+ goto error;
#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
- g_bo = gbm_surface_lock_front_buffer(g_gbm_surface);
+ drm->bo = gbm_surface_lock_front_buffer(drm->gbm_surface);
- fb = (struct drm_fb*)gbm_bo_get_user_data(g_bo);
+ fb = (struct drm_fb*)gbm_bo_get_user_data(drm->bo);
if (!fb)
- fb = drm_fb_get_from_bo(g_bo);
+ fb = drm_fb_get_from_bo(drm->bo);
ret = drmModeSetCrtc(g_drm_fd,
g_crtc_id, fb->fb_id, 0, 0, &g_connector_id, 1, g_drm_mode);
@@ -810,28 +771,15 @@ static void gfx_ctx_drm_input_driver(void *data,
*input_data = NULL;
}
-static bool gfx_ctx_drm_has_focus(void *data)
-{
- return true;
-}
+static bool gfx_ctx_drm_has_focus(void *data) { return true; }
-static bool gfx_ctx_drm_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool gfx_ctx_drm_suppress_screensaver(void *data, bool enable) { return false; }
-static enum gfx_ctx_api gfx_ctx_drm_get_api(void *data)
-{
- return drm_api;
-}
+static enum gfx_ctx_api gfx_ctx_drm_get_api(void *data) { return drm_api; }
static bool gfx_ctx_drm_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)video_driver;
-
drm_api = api;
#ifdef HAVE_EGL
g_egl_major = major;
@@ -874,41 +822,13 @@ static bool gfx_ctx_drm_bind_api(void *video_driver,
return false;
}
-static gfx_ctx_proc_t gfx_ctx_drm_get_proc_address(const char *symbol)
-{
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#endif
- case GFX_CTX_NONE:
- default:
- break;
- }
-
- return NULL;
-}
-
static void gfx_ctx_drm_bind_hw_render(void *data, bool enable)
{
gfx_ctx_drm_data_t *drm = (gfx_ctx_drm_data_t*)data;
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- egl_bind_hw_render(&drm->egl, enable);
+ egl_bind_hw_render(&drm->egl, enable);
#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
}
static uint32_t gfx_ctx_drm_get_flags(void *data)
@@ -962,7 +882,11 @@ const gfx_ctx_driver_t gfx_ctx_drm = {
false, /* has_windowed */
gfx_ctx_drm_swap_buffers,
gfx_ctx_drm_input_driver,
- gfx_ctx_drm_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/drm_go2_ctx.c b/gfx/drivers_context/drm_go2_ctx.c
index 40b060c69d..36d0c78644 100644
--- a/gfx/drivers_context/drm_go2_ctx.c
+++ b/gfx/drivers_context/drm_go2_ctx.c
@@ -68,8 +68,6 @@
#define EGL_PLATFORM_GBM_KHR 0x31D7
#endif
-static enum gfx_ctx_api drm_api = GFX_CTX_NONE;
-
typedef struct gfx_ctx_go2_drm_data
{
#ifdef HAVE_EGL
@@ -82,11 +80,16 @@ typedef struct gfx_ctx_go2_drm_data
unsigned fb_height;
unsigned ctx_w;
unsigned ctx_h;
+ unsigned native_width;
+ unsigned native_height;
bool core_hw_context_enable;
} gfx_ctx_go2_drm_data_t;
-static unsigned native_width = 480;
-static unsigned native_height = 320;
+/* TODO/FIXME - static global */
+static enum gfx_ctx_api drm_api = GFX_CTX_NONE;
+
+/* Function callback */
+void (*swap_buffers)(void*);
static void gfx_ctx_go2_drm_input_driver(void *data,
const char *joypad_name,
@@ -107,24 +110,6 @@ static void gfx_ctx_go2_drm_input_driver(void *data,
*input_data = NULL;
}
-static gfx_ctx_proc_t gfx_ctx_go2_drm_get_proc_address(const char *symbol)
-{
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#endif
- case GFX_CTX_NONE:
- default:
- break;
- }
-
- return NULL;
-}
-
static void *gfx_ctx_go2_drm_init(void *video_driver)
{
gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)
@@ -133,8 +118,12 @@ static void *gfx_ctx_go2_drm_init(void *video_driver)
if (!drm)
return NULL;
- drm->display = go2_display_create();
- drm->presenter = go2_presenter_create(drm->display, DRM_FORMAT_RGB565, 0xff000000, true);
+ drm->native_width = 480;
+ drm->native_height = 320;
+
+ drm->display = go2_display_create();
+ drm->presenter = go2_presenter_create(drm->display,
+ DRM_FORMAT_RGB565, 0xff000000, true);
return drm;
}
@@ -157,10 +146,7 @@ static void gfx_ctx_go2_drm_destroy(void *data)
drm->display = NULL;
}
-static enum gfx_ctx_api gfx_ctx_go2_drm_get_api(void *data)
-{
- return drm_api;
-}
+static enum gfx_ctx_api gfx_ctx_go2_drm_get_api(void *data) { return drm_api; }
static bool gfx_ctx_go2_drm_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)
@@ -222,8 +208,10 @@ static bool gfx_ctx_go2_drm_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
- struct retro_system_av_info *av_info = NULL;
- gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)data;
+ settings_t *settings = config_get_ptr();
+ struct retro_system_av_info *av_info = NULL;
+ gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)data;
+ bool use_ctx_scaling = settings->bools.video_ctx_scaling;
if (!drm)
return false;
@@ -232,36 +220,34 @@ static bool gfx_ctx_go2_drm_set_video_mode(void *data,
frontend_driver_install_signal_handler();
- settings_t *settings = config_get_ptr();
- bool use_ctx_scaling = settings->bools.video_ctx_scaling;
-
if (use_ctx_scaling && !menu_driver_is_alive())
{
- drm->fb_width = av_info->geometry.base_width;
+ drm->fb_width = av_info->geometry.base_width;
drm->fb_height = av_info->geometry.base_height;
}
else
{
- drm->fb_width = native_width;
- drm->fb_height = native_height;
+ drm->fb_width = drm->native_width;
+ drm->fb_height = drm->native_height;
}
if (!drm->context)
{
go2_context_attributes_t attr;
- attr.major = 3;
- attr.minor = 2;
- attr.red_bits = 8;
- attr.green_bits = 8;
- attr.blue_bits = 8;
- attr.alpha_bits = 8;
- attr.depth_bits = 0;
+ attr.major = 3;
+ attr.minor = 2;
+ attr.red_bits = 8;
+ attr.green_bits = 8;
+ attr.blue_bits = 8;
+ attr.alpha_bits = 8;
+ attr.depth_bits = 0;
attr.stencil_bits = 0;
- drm->ctx_w = MAX(av_info->geometry.max_width, native_width);
- drm->ctx_h = MAX(av_info->geometry.max_height, native_height);
+ drm->ctx_w = MAX(av_info->geometry.max_width, drm->native_width);
+ drm->ctx_h = MAX(av_info->geometry.max_height, drm->native_height);
- drm->context = go2_context_create(drm->display, drm->ctx_w, drm->ctx_h, &attr);
+ drm->context = go2_context_create(
+ drm->display, drm->ctx_w, drm->ctx_h, &attr);
}
go2_context_make_current(drm->context);
@@ -274,56 +260,46 @@ static bool gfx_ctx_go2_drm_set_video_mode(void *data,
static void gfx_ctx_go2_drm_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
- gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)data;
- struct retro_system_av_info* av_info = video_viewport_get_system_av_info();
+ unsigned w;
+ unsigned h;
+ gfx_ctx_go2_drm_data_t
+ *drm = (gfx_ctx_go2_drm_data_t*)data;
settings_t *settings = config_get_ptr();
bool use_ctx_scaling = settings->bools.video_ctx_scaling;
- unsigned w;
- unsigned h;
-
if (use_ctx_scaling && !menu_driver_is_alive())
{
- w = av_info->geometry.base_width;
- h = av_info->geometry.base_height;
+ struct retro_system_av_info*
+ av_info = video_viewport_get_system_av_info();
+ w = av_info->geometry.base_width;
+ h = av_info->geometry.base_height;
}
else
{
- w = native_width;
- h = native_height;
+ w = drm->native_width;
+ h = drm->native_height;
}
if (*width != w || *height != h)
{
- *width = drm->fb_width = w;
- *height = drm->fb_height = h;
- *resize = false;
+ *width = drm->fb_width = w;
+ *height = drm->fb_height = h;
+ *resize = false;
}
*quit = (bool)frontend_driver_get_signal_handler_state();
}
-static bool gfx_ctx_go2_drm_has_focus(void *data)
-{
- return true;
-}
+static bool gfx_ctx_go2_drm_has_focus(void *data) { return true; }
+static bool gfx_ctx_go2_drm_suppress_screensaver(void *data, bool enable) { return false; }
-static bool gfx_ctx_go2_drm_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-int ss = 0;
-
-void (*swap_buffers)(void*);
static void gfx_ctx_go2_drm_swap_buffers(void *data)
{
- gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)data;
+ gfx_ctx_go2_drm_data_t
+ *drm = (gfx_ctx_go2_drm_data_t*)data;
- int out_w = native_width;
- int out_h = native_height;
+ int out_w = drm->native_width;
+ int out_h = drm->native_height;
int out_x = 0;
int out_y = 0;
@@ -341,27 +317,17 @@ static void gfx_ctx_go2_drm_swap_buffers(void *data)
out_x = 0;
}
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- go2_context_swap_buffers(drm->context);
+ go2_context_swap_buffers(drm->context);
- go2_surface_t* surface = go2_context_surface_lock(drm->context);
- go2_presenter_post(drm->presenter,
- surface,
- src_x, src_y, src_w, src_h,
- out_y, out_x, out_h, out_w,
- GO2_ROTATION_DEGREES_270, 2);
- go2_context_surface_unlock(drm->context, surface);
+ go2_surface_t* surface = go2_context_surface_lock(drm->context);
+ go2_presenter_post(drm->presenter,
+ surface,
+ src_x, src_y, src_w, src_h,
+ out_y, out_x, out_h, out_w,
+ GO2_ROTATION_DEGREES_270, 2);
+ go2_context_surface_unlock(drm->context, surface);
#endif
- break;
- default:
- printf("unhandled gfx_ctx_go2_drm_swap_buffers\n");
- break;
- }
}
static uint32_t gfx_ctx_go2_drm_get_flags(void *data)
@@ -397,19 +363,9 @@ static void gfx_ctx_go2_drm_bind_hw_render(void *data, bool enable)
{
gfx_ctx_go2_drm_data_t *drm = (gfx_ctx_go2_drm_data_t*)data;
- switch (drm_api)
- {
- case GFX_CTX_OPENGL_API:
- case GFX_CTX_OPENGL_ES_API:
- case GFX_CTX_OPENVG_API:
#ifdef HAVE_EGL
- egl_bind_hw_render(&drm->egl, enable);
+ egl_bind_hw_render(&drm->egl, enable);
#endif
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
}
const gfx_ctx_driver_t gfx_ctx_go2_drm = {
@@ -434,7 +390,11 @@ const gfx_ctx_driver_t gfx_ctx_go2_drm = {
false, /* has_windowed */
gfx_ctx_go2_drm_swap_buffers,
gfx_ctx_go2_drm_input_driver,
- gfx_ctx_go2_drm_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c
index 85fb7eeeb6..853a065607 100644
--- a/gfx/drivers_context/emscriptenegl_ctx.c
+++ b/gfx/drivers_context/emscriptenegl_ctx.c
@@ -42,21 +42,14 @@ typedef struct
#ifdef HAVE_EGL
egl_ctx_data_t egl;
#endif
+ int initial_width;
+ int initial_height;
unsigned fb_width;
unsigned fb_height;
} emscripten_ctx_data_t;
-/* TODO/FIXME - would like to move these to emscripten_ctx_data_t -
- * see the TODO/FIXME note down below */
-static int emscripten_initial_width;
-static int emscripten_initial_height;
-
-static enum gfx_ctx_api emscripten_api = GFX_CTX_NONE;
-
static void gfx_ctx_emscripten_swap_interval(void *data, int interval)
{
- (void)data;
-
if (interval == 0)
emscripten_set_main_loop_timing(EM_TIMING_SETIMMEDIATE, 0);
else
@@ -105,8 +98,8 @@ static void gfx_ctx_emscripten_check_window(void *data, bool *quit,
if (input_width == 0 || input_height == 0)
{
- input_width = emscripten_initial_width;
- input_height = emscripten_initial_height;
+ input_width = emscripten->initial_width;
+ input_height = emscripten->initial_height;
emscripten->fb_width = emscripten->fb_height = 0;
}
@@ -207,9 +200,11 @@ static void *gfx_ctx_emscripten_init(void *video_driver)
/* TODO/FIXME - why is this conditional here - shouldn't these always
* be grabbed? */
- if (emscripten_initial_width == 0 || emscripten_initial_height == 0)
+ if ( emscripten->initial_width == 0 ||
+ emscripten->initial_height == 0)
emscripten_get_canvas_element_size("#canvas",
- &emscripten_initial_width, &emscripten_initial_height);
+ &emscripten->initial_width,
+ &emscripten->initial_height);
#ifdef HAVE_EGL
if (g_egl_inited)
@@ -259,29 +254,15 @@ static bool gfx_ctx_emscripten_set_video_mode(void *data,
return true;
}
-static enum gfx_ctx_api gfx_ctx_emscripten_get_api(void *data)
-{
- return emscripten_api;
-}
+static enum gfx_ctx_api gfx_ctx_emscripten_get_api(void *data) { return GFX_CTX_OPENGL_ES_API; }
static bool gfx_ctx_emscripten_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
- (void)major;
- (void)minor;
-
- emscripten_api = api;
-
- switch (api)
- {
#ifdef HAVE_EGL
- case GFX_CTX_OPENGL_ES_API:
- return egl_bind_api(EGL_OPENGL_ES_API);
+ if (api == GFX_CTX_OPENGL_ES_API)
+ return egl_bind_api(EGL_OPENGL_ES_API);
#endif
- default:
- break;
- }
return false;
}
@@ -296,53 +277,19 @@ static void gfx_ctx_emscripten_input_driver(void *data,
*input_data = rwebinput;
}
-static bool gfx_ctx_emscripten_has_focus(void *data)
-{
- (void)data;
+static bool gfx_ctx_emscripten_has_focus(void *data) { return g_egl_inited; }
- return g_egl_inited;
-}
-
-static bool gfx_ctx_emscripten_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
-
- return false;
-}
+static bool gfx_ctx_emscripten_suppress_screensaver(void *data, bool enable) { return false; }
static float gfx_ctx_emscripten_translate_aspect(void *data,
- unsigned width, unsigned height)
-{
- (void)data;
-
- return (float)width / height;
-}
+ unsigned width, unsigned height) { return (float)width / height; }
static bool gfx_ctx_emscripten_init_egl_image_buffer(void *data,
- const video_info_t *video)
-{
- (void)data;
-
- return false;
-}
+ const video_info_t *video) { return false; }
static bool gfx_ctx_emscripten_write_egl_image(void *data,
const void *frame, unsigned width, unsigned height, unsigned pitch,
- bool rgb32, unsigned index, void **image_handle)
-{
- (void)data;
- return false;
-}
-
-static gfx_ctx_proc_t gfx_ctx_emscripten_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#else
- return NULL;
-#endif
-}
+ bool rgb32, unsigned index, void **image_handle) { return false; }
static void gfx_ctx_emscripten_bind_hw_render(void *data, bool enable)
{
@@ -360,10 +307,7 @@ static uint32_t gfx_ctx_emscripten_get_flags(void *data)
return flags;
}
-static void gfx_ctx_emscripten_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void gfx_ctx_emscripten_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_emscripten = {
gfx_ctx_emscripten_init,
@@ -387,7 +331,11 @@ const gfx_ctx_driver_t gfx_ctx_emscripten = {
false,
gfx_ctx_emscripten_swap_buffers,
gfx_ctx_emscripten_input_driver,
- gfx_ctx_emscripten_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
gfx_ctx_emscripten_init_egl_image_buffer,
gfx_ctx_emscripten_write_egl_image,
NULL,
diff --git a/gfx/drivers_context/fpga_ctx.c b/gfx/drivers_context/fpga_ctx.c
deleted file mode 100644
index 66b1c030dc..0000000000
--- a/gfx/drivers_context/fpga_ctx.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/* RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- * Copyright (C) 2016-2017 - Brad Parker
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
- */
-
-/* FPGA context. */
-
-#include
-#include
-
-#include
-
-#ifdef HAVE_CONFIG_H
-#include "../../config.h"
-#endif
-
-#include "../../configuration.h"
-#include "../../dynamic.h"
-#include "../../verbosity.h"
-#include "../video_driver.h"
-#include "../common/fpga_common.h"
-
-static unsigned g_resize_width = FB_WIDTH;
-static unsigned g_resize_height = FB_HEIGHT;
-
-static void gfx_ctx_fpga_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
-}
-
-static bool gfx_ctx_fpga_set_resize(void *data,
- unsigned width, unsigned height)
-{
- (void)data;
- (void)width;
- (void)height;
-
- return false;
-}
-
-static void gfx_ctx_fpga_update_title(void *data)
-{
- char title[128];
-
- title[0] = '\0';
-
- video_driver_get_window_title(title, sizeof(title));
-}
-
-static void gfx_ctx_fpga_get_video_size(void *data,
- unsigned *width, unsigned *height)
-{
- (void)data;
-
- *width = g_resize_width;
- *height = g_resize_height;
-}
-
-static void *gfx_ctx_fpga_init(void *video_driver)
-{
- (void)video_driver;
-
- return (void*)"fpga";
-}
-
-static void gfx_ctx_fpga_destroy(void *data)
-{
- (void)data;
-}
-
-static bool gfx_ctx_fpga_set_video_mode(void *data,
- unsigned width, unsigned height,
- bool fullscreen)
-{
- if (false)
- goto error;
-
- return true;
-
-error:
- gfx_ctx_fpga_destroy(data);
- return false;
-}
-
-
-static void gfx_ctx_fpga_input_driver(void *data,
- const char *joypad_name,
- const input_driver_t **input, void **input_data)
-{
-}
-
-static bool gfx_ctx_fpga_has_focus(void *data)
-{
- return true;
-}
-
-static bool gfx_ctx_fpga_suppress_screensaver(void *data, bool enable)
-{
- return true;
-}
-
-static bool gfx_ctx_fpga_has_windowed(void *data)
-{
- (void)data;
-
- return true;
-}
-
-static bool gfx_ctx_fpga_get_metrics(void *data,
- enum display_metric_types type, float *value)
-{
- return true;
-}
-
-static bool gfx_ctx_fpga_bind_api(void *data,
- enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
-
- return true;
-}
-
-static void gfx_ctx_fpga_show_mouse(void *data, bool state)
-{
- (void)data;
-}
-
-static void gfx_ctx_fpga_swap_interval(void *data, unsigned interval)
-{
- (void)data;
- (void)interval;
-}
-
-static void gfx_ctx_fpga_set_flags(void *data, uint32_t flags)
-{
- (void)data;
- (void)flags;
-}
-
-static uint32_t gfx_ctx_fpga_get_flags(void *data)
-{
- uint32_t flags = 0;
- BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
- return flags;
-}
-
-const gfx_ctx_driver_t gfx_ctx_fpga = {
- gfx_ctx_fpga_init,
- gfx_ctx_fpga_destroy,
- gfx_ctx_fpga_bind_api,
- gfx_ctx_fpga_swap_interval,
- gfx_ctx_fpga_set_video_mode,
- gfx_ctx_fpga_get_video_size,
- NULL, /* get_video_output_size */
- NULL, /* get_video_output_prev */
- NULL, /* get_video_output_next */
- gfx_ctx_fpga_get_metrics,
- NULL,
- gfx_ctx_fpga_update_title,
- gfx_ctx_fpga_check_window,
- gfx_ctx_fpga_set_resize,
- gfx_ctx_fpga_has_focus,
- gfx_ctx_fpga_suppress_screensaver,
- gfx_ctx_fpga_has_windowed,
- NULL, /* swap_buffers */
- gfx_ctx_fpga_input_driver,
- NULL,
- NULL,
- NULL,
- gfx_ctx_fpga_show_mouse,
- "fpga",
- gfx_ctx_fpga_get_flags,
- gfx_ctx_fpga_set_flags,
- NULL,
- NULL,
- NULL
-};
-
diff --git a/gfx/drivers_context/gdi_ctx.c b/gfx/drivers_context/gdi_ctx.c
deleted file mode 100644
index 0025b38c89..0000000000
--- a/gfx/drivers_context/gdi_ctx.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/* RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- * Copyright (C) 2016-2019 - Brad Parker
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
- */
-
-/* Win32/GDI context. */
-
-/* necessary for mingw32 multimon defines: */
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0500 /*_WIN32_WINNT_WIN2K */
-#endif
-
-#include
-#include
-
-#include
-#include
-
-#include
-
-#ifdef HAVE_CONFIG_H
-#include "../../config.h"
-#endif
-
-#include "../../dynamic.h"
-#include "../../configuration.h"
-#include "../../retroarch.h"
-#include "../../verbosity.h"
-#include "../../frontend/frontend_driver.h"
-
-#include "../common/win32_common.h"
-
-static HDC win32_gdi_hdc;
-
-static unsigned win32_gdi_major = 0;
-static unsigned win32_gdi_minor = 0;
-static int win32_gdi_interval = 0;
-static enum gfx_ctx_api win32_gdi_api = GFX_CTX_NONE;
-
-typedef struct gfx_ctx_gdi_data
-{
- void *empty;
-} gfx_ctx_gdi_data_t;
-
-static void *dinput_gdi;
-
-static void gfx_ctx_gdi_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
- win32_check_window(quit, resize, width, height);
-}
-
-static bool gfx_ctx_gdi_set_resize(void *data,
- unsigned width, unsigned height)
-{
- return false;
-}
-
-static void gfx_ctx_gdi_update_title(void *data)
-{
- const ui_window_t *window = ui_companion_driver_get_window_ptr();
- char title[128];
-
- title[0] = '\0';
-
- video_driver_get_window_title(title, sizeof(title));
-
- if (window && title[0])
- window->set_title(&main_window, title);
-}
-
-static void gfx_ctx_gdi_get_video_size(void *data,
- unsigned *width, unsigned *height)
-{
- HWND window = win32_get_window();
-
- (void)data;
-
- if (!window)
- {
- RECT mon_rect;
- MONITORINFOEX current_mon;
- unsigned mon_id = 0;
- HMONITOR hm_to_use = NULL;
-
- win32_monitor_info(¤t_mon, &hm_to_use, &mon_id);
- mon_rect = current_mon.rcMonitor;
- *width = mon_rect.right - mon_rect.left;
- *height = mon_rect.bottom - mon_rect.top;
- }
- else
- {
- *width = g_win32_resize_width;
- *height = g_win32_resize_height;
- }
-}
-
-static void *gfx_ctx_gdi_init(void *video_driver)
-{
- WNDCLASSEX wndclass = {0};
- gfx_ctx_gdi_data_t *gdi = (gfx_ctx_gdi_data_t*)calloc(1, sizeof(*gdi));
-
- if (!gdi)
- return NULL;
-
- if (g_win32_inited)
- goto error;
-
- win32_window_reset();
- win32_monitor_init();
-
- wndclass.lpfnWndProc = WndProcGDI;
- if (!win32_window_init(&wndclass, true, NULL))
- goto error;
-
- return gdi;
-
-error:
- if (gdi)
- free(gdi);
- return NULL;
-}
-
-static void gfx_ctx_gdi_destroy(void *data)
-{
- gfx_ctx_gdi_data_t *gdi = (gfx_ctx_gdi_data_t*)data;
- HWND window = win32_get_window();
-
- if (window && win32_gdi_hdc)
- {
- ReleaseDC(window, win32_gdi_hdc);
- win32_gdi_hdc = NULL;
- }
-
- if (window)
- {
- win32_monitor_from_window();
- win32_destroy_window();
- }
-
- if (g_win32_restore_desktop)
- {
- win32_monitor_get_info();
- g_win32_restore_desktop = false;
- }
-
- if (gdi)
- free(gdi);
-
- g_win32_inited = false;
- win32_gdi_major = 0;
- win32_gdi_minor = 0;
-}
-
-static bool gfx_ctx_gdi_set_video_mode(void *data,
- unsigned width, unsigned height,
- bool fullscreen)
-{
- if (!win32_set_video_mode(NULL, width, height, fullscreen))
- {
- RARCH_ERR("[GDI]: win32_set_video_mode failed.\n");
- gfx_ctx_gdi_destroy(data);
- return false;
- }
-
- return true;
-}
-
-static void gfx_ctx_gdi_input_driver(void *data,
- const char *joypad_name,
- input_driver_t **input, void **input_data)
-{
-#if _WIN32_WINNT >= 0x0501
- settings_t *settings = config_get_ptr();
-
- /* winraw only available since XP */
- if (string_is_equal(settings->arrays.input_driver, "raw"))
- {
- *input_data = input_winraw.init(joypad_name);
- if (*input_data)
- {
- *input = &input_winraw;
- dinput_gdi = NULL;
- return;
- }
- }
-#endif
-
-#ifdef HAVE_DINPUT
- dinput_gdi = input_dinput.init(joypad_name);
- *input = dinput_gdi ? &input_dinput : NULL;
-#else
- dinput_gdi = NULL;
- *input = NULL;
-#endif
- *input_data = dinput_gdi;
-}
-
-static enum gfx_ctx_api gfx_ctx_gdi_get_api(void *data)
-{
- return win32_gdi_api;
-}
-
-static bool gfx_ctx_gdi_bind_api(void *data,
- enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
-
- win32_gdi_major = major;
- win32_gdi_minor = minor;
- win32_gdi_api = api;
-
- return true;
-}
-
-static void gfx_ctx_gdi_swap_interval(void *data, int interval)
-{
- (void)data;
- (void)interval;
-}
-
-static void gfx_ctx_gdi_set_flags(void *data, uint32_t flags)
-{
- (void)data;
- (void)flags;
-}
-
-static uint32_t gfx_ctx_gdi_get_flags(void *data)
-{
- uint32_t flags = 0;
-
- return flags;
-}
-
-static void gfx_ctx_gdi_swap_buffers(void *data)
-{
- SwapBuffers(win32_gdi_hdc);
-}
-
-void create_gdi_context(HWND hwnd, bool *quit)
-{
- win32_gdi_hdc = GetDC(hwnd);
-
- win32_setup_pixel_format(win32_gdi_hdc, false);
-
- g_win32_inited = true;
-}
-
-const gfx_ctx_driver_t gfx_ctx_gdi = {
- gfx_ctx_gdi_init,
- gfx_ctx_gdi_destroy,
- gfx_ctx_gdi_get_api,
- gfx_ctx_gdi_bind_api,
- gfx_ctx_gdi_swap_interval,
- gfx_ctx_gdi_set_video_mode,
- gfx_ctx_gdi_get_video_size,
- NULL, /* get_refresh_rate */
- NULL, /* get_video_output_size */
- NULL, /* get_video_output_prev */
- NULL, /* get_video_output_next */
- win32_get_metrics,
- NULL,
- gfx_ctx_gdi_update_title,
- gfx_ctx_gdi_check_window,
- gfx_ctx_gdi_set_resize,
- win32_has_focus,
- win32_suppress_screensaver,
- true, /* has_windowed */
- gfx_ctx_gdi_swap_buffers,
- gfx_ctx_gdi_input_driver,
- NULL,
- NULL,
- NULL,
- win32_show_cursor,
- "gdi",
- gfx_ctx_gdi_get_flags,
- gfx_ctx_gdi_set_flags,
- NULL,
- NULL,
- NULL
-};
diff --git a/gfx/drivers_context/gfx_null_ctx.c b/gfx/drivers_context/gfx_null_ctx.c
index 698de8ce0e..c888c8297e 100644
--- a/gfx/drivers_context/gfx_null_ctx.c
+++ b/gfx/drivers_context/gfx_null_ctx.c
@@ -18,23 +18,8 @@
#include "../../retroarch.h"
-static void gfx_ctx_null_swap_interval(void *data, int interval)
-{
- (void)data;
- (void)interval;
-}
-
-static void gfx_ctx_null_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
- (void)data;
- (void)quit;
- (void)width;
- (void)height;
- (void)resize;
-}
-
-static void gfx_ctx_null_get_video_size(void *data, unsigned *width, unsigned *height)
+static void gfx_ctx_null_get_video_size(
+ void *data, unsigned *width, unsigned *height)
{
(void)data;
#ifdef VITA
@@ -46,90 +31,25 @@ static void gfx_ctx_null_get_video_size(void *data, unsigned *width, unsigned *h
#endif
}
+static void gfx_ctx_null_swap_interval(void *data, int interval) { }
+static void gfx_ctx_null_check_window(void *data, bool *quit,
+ bool *resize, unsigned *width, unsigned *height) { }
static bool gfx_ctx_null_set_video_mode(void *data,
unsigned width, unsigned height,
- bool fullscreen)
-{
- (void)data;
- (void)width;
- (void)height;
- (void)fullscreen;
-
- return true;
-}
-
-static void gfx_ctx_null_destroy(void *data)
-{
- (void)data;
-}
-
+ bool fullscreen) { return true; }
+static void gfx_ctx_null_destroy(void *data) { }
static void gfx_ctx_null_input_driver(void *data,
const char *name,
- input_driver_t **input, void **input_data)
-{
- (void)data;
- (void)input;
- (void)input_data;
-}
-
-static bool gfx_ctx_null_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_null_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-static enum gfx_ctx_api gfx_ctx_null_get_api(void *data)
-{
- return GFX_CTX_NONE;
-}
-
-static bool gfx_ctx_null_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
- (void)api;
- (void)major;
- (void)minor;
-
- return true;
-}
-
-static void gfx_ctx_null_show_mouse(void *data, bool state)
-{
- (void)data;
- (void)state;
-}
-
-static void gfx_ctx_null_bind_hw_render(void *data, bool enable)
-{
- (void)data;
- (void)enable;
-}
-
-static void *gfx_ctx_null_init(void *video_driver)
-{
- (void)video_driver;
-
- return (void*)"null";
-}
-
-static uint32_t gfx_ctx_null_get_flags(void *data)
-{
- uint32_t flags = 0;
-
- return flags;
-}
-
-static void gfx_ctx_null_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+ input_driver_t **input, void **input_data) { }
+static bool gfx_ctx_null_has_focus(void *data) { return true; }
+static bool gfx_ctx_null_suppress_screensaver(void *data, bool enable) { return false; }
+static enum gfx_ctx_api gfx_ctx_null_get_api(void *data) { return GFX_CTX_NONE; }
+static bool gfx_ctx_null_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor) { return true; }
+static void gfx_ctx_null_show_mouse(void *data, bool state) { }
+static void gfx_ctx_null_bind_hw_render(void *data, bool enable) { }
+static void *gfx_ctx_null_init(void *video_driver) { return (void*)"null"; }
+static uint32_t gfx_ctx_null_get_flags(void *data) { return 0; }
+static void gfx_ctx_null_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_null = {
gfx_ctx_null_init,
diff --git a/gfx/drivers_context/khr_display_ctx.c b/gfx/drivers_context/khr_display_ctx.c
index 42f377c29a..9b06cfa942 100644
--- a/gfx/drivers_context/khr_display_ctx.c
+++ b/gfx/drivers_context/khr_display_ctx.c
@@ -33,8 +33,6 @@ typedef struct
unsigned height;
} khr_display_ctx_data_t;
-static enum gfx_ctx_api khr_api = GFX_CTX_NONE;
-
static void gfx_ctx_khr_display_destroy(void *data)
{
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
@@ -60,7 +58,8 @@ static void gfx_ctx_khr_display_get_video_size(void *data,
static void *gfx_ctx_khr_display_init(void *video_driver)
{
- khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)calloc(1, sizeof(*khr));
+ khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)
+ calloc(1, sizeof(*khr));
if (!khr)
return NULL;
@@ -102,8 +101,9 @@ static bool gfx_ctx_khr_display_set_resize(void *data,
{
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
- khr->width = width;
- khr->height = height;
+ khr->width = width;
+ khr->height = height;
+
if (!vulkan_create_swapchain(&khr->vk, khr->width, khr->height,
khr->swap_interval))
{
@@ -115,8 +115,8 @@ static bool gfx_ctx_khr_display_set_resize(void *data,
vulkan_acquire_next_image(&khr->vk);
khr->vk.context.invalid_swapchain = true;
- khr->vk.need_new_swapchain = false;
- return false;
+ khr->vk.need_new_swapchain = false;
+ return true;
}
static bool gfx_ctx_khr_display_set_video_mode(void *data,
@@ -130,13 +130,13 @@ static bool gfx_ctx_khr_display_set_video_mode(void *data,
if (!fullscreen)
{
- width = 0;
- height = 0;
+ width = 0;
+ height = 0;
}
- info.width = width;
- info.height = height;
- info.monitor_index = video_monitor_index;
+ info.width = width;
+ info.height = height;
+ info.monitor_index = video_monitor_index;
if (!vulkan_surface_create(&khr->vk, VULKAN_WSI_DISPLAY, &info, NULL,
0, 0, khr->swap_interval))
@@ -145,8 +145,8 @@ static bool gfx_ctx_khr_display_set_video_mode(void *data,
goto error;
}
- khr->width = khr->vk.context.swapchain_width;
- khr->height = khr->vk.context.swapchain_height;
+ khr->width = khr->vk.context.swapchain_width;
+ khr->height = khr->vk.context.swapchain_height;
return true;
@@ -198,36 +198,21 @@ static void gfx_ctx_khr_display_input_driver(void *data,
static enum gfx_ctx_api gfx_ctx_khr_display_get_api(void *data)
{
- return khr_api;
+ return GFX_CTX_VULKAN_API;
}
static bool gfx_ctx_khr_display_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
- (void)major;
- (void)minor;
-
- khr_api = api;
-
if (api == GFX_CTX_VULKAN_API)
return true;
-
return false;
}
-static bool gfx_ctx_khr_display_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_khr_display_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static void gfx_ctx_khr_display_set_flags(void *data, uint32_t flags) { }
+static bool gfx_ctx_khr_display_has_focus(void *data) { return true; }
+static bool gfx_ctx_khr_display_suppress_screensaver(void *data, bool enable) { return false; }
+static gfx_ctx_proc_t gfx_ctx_khr_display_get_proc_address(const char *symbol) { return NULL; }
static void gfx_ctx_khr_display_set_swap_interval(void *data,
int swap_interval)
@@ -249,11 +234,6 @@ static void gfx_ctx_khr_display_swap_buffers(void *data)
vulkan_acquire_next_image(&khr->vk);
}
-static gfx_ctx_proc_t gfx_ctx_khr_display_get_proc_address(const char *symbol)
-{
- return NULL;
-}
-
static uint32_t gfx_ctx_khr_display_get_flags(void *data)
{
uint32_t flags = 0;
@@ -265,11 +245,6 @@ static uint32_t gfx_ctx_khr_display_get_flags(void *data)
return flags;
}
-static void gfx_ctx_khr_display_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
-
static void *gfx_ctx_khr_display_get_context_data(void *data)
{
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;
diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c
index 034a8445d2..415068da27 100644
--- a/gfx/drivers_context/mali_fbdev_ctx.c
+++ b/gfx/drivers_context/mali_fbdev_ctx.c
@@ -57,8 +57,6 @@ typedef struct
float refresh_rate;
} mali_ctx_data_t;
-static enum gfx_ctx_api mali_api = GFX_CTX_NONE;
-
static void gfx_ctx_mali_fbdev_destroy(void *data)
{
int fd;
@@ -213,18 +211,14 @@ static void gfx_ctx_mali_fbdev_input_driver(void *data,
static enum gfx_ctx_api gfx_ctx_mali_fbdev_get_api(void *data)
{
- return mali_api;
+ return GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_mali_fbdev_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
- mali_api = api;
-
if (api == GFX_CTX_OPENGL_ES_API)
return true;
-
return false;
}
@@ -260,13 +254,6 @@ static void gfx_ctx_mali_fbdev_swap_buffers(void *data)
#endif
}
-static gfx_ctx_proc_t gfx_ctx_mali_fbdev_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#endif
-}
-
static void gfx_ctx_mali_fbdev_bind_hw_render(void *data, bool enable)
{
mali_ctx_data_t *mali = (mali_ctx_data_t*)data;
@@ -319,7 +306,11 @@ const gfx_ctx_driver_t gfx_ctx_mali_fbdev = {
false, /* has_windowed */
gfx_ctx_mali_fbdev_swap_buffers,
gfx_ctx_mali_fbdev_input_driver,
- gfx_ctx_mali_fbdev_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/network_ctx.c b/gfx/drivers_context/network_ctx.c
deleted file mode 100644
index c7a4ca7469..0000000000
--- a/gfx/drivers_context/network_ctx.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/* RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- * Copyright (C) 2016-2019 - Brad Parker
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
- */
-
-/* network video context. */
-
-#ifdef HAVE_CONFIG_H
-#include "../../config.h"
-#endif
-
-#include "../../configuration.h"
-#include "../../dynamic.h"
-#include "../../retroarch.h"
-#include "../../verbosity.h"
-#include "../../ui/ui_companion_driver.h"
-
-#if defined(_WIN32) && !defined(_XBOX)
-#include "../common/win32_common.h"
-#endif
-
-static enum gfx_ctx_api network_ctx_api = GFX_CTX_NONE;
-
-static void gfx_ctx_network_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
-}
-
-static bool gfx_ctx_network_set_resize(void *data,
- unsigned width, unsigned height)
-{
- (void)data;
- (void)width;
- (void)height;
-
- return false;
-}
-
-static void gfx_ctx_network_get_video_size(void *data,
- unsigned *width, unsigned *height)
-{
- (void)data;
-}
-
-static void *gfx_ctx_network_init(void *video_driver)
-{
- (void)video_driver;
-
- return (void*)"network";
-}
-
-static void gfx_ctx_network_destroy(void *data)
-{
- (void)data;
-}
-
-static bool gfx_ctx_network_set_video_mode(void *data,
- unsigned width, unsigned height,
- bool fullscreen)
-{
- return true;
-}
-
-static void gfx_ctx_network_input_driver(void *data,
- const char *joypad_name,
- input_driver_t **input, void **input_data)
-{
- (void)data;
-
-#ifdef HAVE_UDEV
- *input_data = input_udev.init(joypad_name);
-
- if (*input_data)
- {
- *input = &input_udev;
- return;
- }
-#endif
- *input = NULL;
- *input_data = NULL;
-}
-
-static bool gfx_ctx_network_has_focus(void *data)
-{
- return true;
-}
-
-static bool gfx_ctx_network_suppress_screensaver(void *data, bool enable)
-{
- return true;
-}
-
-static bool gfx_ctx_network_get_metrics(void *data,
- enum display_metric_types type, float *value)
-{
- return false;
-}
-
-static enum gfx_ctx_api gfx_ctx_network_get_api(void *data)
-{
- return network_ctx_api;
-}
-
-static bool gfx_ctx_network_bind_api(void *data,
- enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
-
- return true;
-}
-
-static void gfx_ctx_network_show_mouse(void *data, bool state)
-{
- (void)data;
-}
-
-static void gfx_ctx_network_swap_interval(void *data, int interval)
-{
- (void)data;
- (void)interval;
-}
-
-static void gfx_ctx_network_set_flags(void *data, uint32_t flags)
-{
- (void)data;
- (void)flags;
-}
-
-static uint32_t gfx_ctx_network_get_flags(void *data)
-{
- uint32_t flags = 0;
-
- return flags;
-}
-
-static void gfx_ctx_network_swap_buffers(void *data)
-{
- (void)data;
-}
-
-const gfx_ctx_driver_t gfx_ctx_network = {
- gfx_ctx_network_init,
- gfx_ctx_network_destroy,
- gfx_ctx_network_get_api,
- gfx_ctx_network_bind_api,
- gfx_ctx_network_swap_interval,
- gfx_ctx_network_set_video_mode,
- gfx_ctx_network_get_video_size,
- NULL, /* get_refresh_rate */
- NULL, /* get_video_output_size */
- NULL, /* get_video_output_prev */
- NULL, /* get_video_output_next */
- gfx_ctx_network_get_metrics,
- NULL,
- NULL, /* update_title */
- gfx_ctx_network_check_window,
- gfx_ctx_network_set_resize,
- gfx_ctx_network_has_focus,
- gfx_ctx_network_suppress_screensaver,
- true, /* has_windowed */
- gfx_ctx_network_swap_buffers,
- gfx_ctx_network_input_driver,
- NULL,
- NULL,
- NULL,
- gfx_ctx_network_show_mouse,
- "network",
- gfx_ctx_network_get_flags,
- gfx_ctx_network_set_flags,
- NULL,
- NULL,
- NULL
-};
diff --git a/gfx/drivers_context/opendingux_fbdev_ctx.c b/gfx/drivers_context/opendingux_fbdev_ctx.c
index cdfb0ee923..fdb9e5257b 100644
--- a/gfx/drivers_context/opendingux_fbdev_ctx.c
+++ b/gfx/drivers_context/opendingux_fbdev_ctx.c
@@ -42,8 +42,6 @@ typedef struct
unsigned width, height;
} opendingux_ctx_data_t;
-static enum gfx_ctx_api opendingux_api = GFX_CTX_NONE;
-
static void gfx_ctx_opendingux_destroy(void *data)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
@@ -182,33 +180,20 @@ static void gfx_ctx_opendingux_input_driver(void *data,
static enum gfx_ctx_api gfx_ctx_opendingux_get_api(void *data)
{
- return opendingux_api;
+ return GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_opendingux_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
-
- opendingux_api = api;
-
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
-static bool gfx_ctx_opendingux_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_opendingux_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static void gfx_ctx_opendingux_set_flags(void *data, uint32_t flags) { }
+static bool gfx_ctx_opendingux_has_focus(void *data) { return true; }
+static bool gfx_ctx_opendingux_suppress_screensaver(void *data, bool enable) { return false; }
static void gfx_ctx_opendingux_swap_buffers(void *data)
{
@@ -229,13 +214,6 @@ static void gfx_ctx_opendingux_set_swap_interval(
#endif
}
-#ifdef HAVE_EGL
-static gfx_ctx_proc_t gfx_ctx_opendingux_get_proc_address(const char *symbol)
-{
- return egl_get_proc_address(symbol);
-}
-#endif
-
static void gfx_ctx_opendingux_bind_hw_render(void *data, bool enable)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
@@ -254,11 +232,6 @@ static uint32_t gfx_ctx_opendingux_get_flags(void *data)
return flags;
}
-static void gfx_ctx_opendingux_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
-
const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev = {
gfx_ctx_opendingux_init,
gfx_ctx_opendingux_destroy,
@@ -282,7 +255,7 @@ const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev = {
gfx_ctx_opendingux_swap_buffers,
gfx_ctx_opendingux_input_driver,
#ifdef HAVE_EGL
- gfx_ctx_opendingux_get_proc_address,
+ egl_get_proc_address,
#else
NULL,
#endif
diff --git a/gfx/drivers_context/orbis_ctx.c b/gfx/drivers_context/orbis_ctx.c
index a56f96ba5e..0656049cf5 100644
--- a/gfx/drivers_context/orbis_ctx.c
+++ b/gfx/drivers_context/orbis_ctx.c
@@ -26,31 +26,34 @@
#include "../../frontend/frontend_driver.h"
#include "../../configuration.h"
+/* TODO/FIXME - static globals */
static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API;
+/* TODO/FIXME - global reference */
extern bool platform_orbis_has_focus;
void orbis_ctx_destroy(void *data)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
- if (ctx_orbis)
- {
+ if (ctx_orbis)
+ {
#ifdef HAVE_EGL
- egl_destroy(&ctx_orbis->egl);
+ egl_destroy(&ctx_orbis->egl);
#endif
- ctx_orbis->resize = false;
- free(ctx_orbis);
- }
+ ctx_orbis->resize = false;
+ free(ctx_orbis);
+ }
}
static void orbis_ctx_get_video_size(void *data,
- unsigned *width, unsigned *height)
+ unsigned *width, unsigned *height)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ orbis_ctx_data_t
+ *ctx_orbis = (orbis_ctx_data_t *)data;
- *width = ATTR_ORBISGL_WIDTH;
- *height = ATTR_ORBISGL_HEIGHT;
+ *width = ATTR_ORBISGL_WIDTH;
+ *height = ATTR_ORBISGL_HEIGHT;
}
static void *orbis_ctx_init(void *video_driver)
@@ -73,7 +76,8 @@ static void *orbis_ctx_init(void *video_driver)
EGL_NONE};
#endif
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)calloc(1, sizeof(*ctx_orbis));
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)
+ calloc(1, sizeof(*ctx_orbis));
if (!ctx_orbis)
return NULL;
@@ -81,20 +85,25 @@ static void *orbis_ctx_init(void *video_driver)
#ifdef HAVE_EGL
memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config));
+
{
- ctx_orbis->pgl_config.size=sizeof(ctx_orbis->pgl_config);
- ctx_orbis->pgl_config.flags=SCE_PGL_FLAGS_USE_COMPOSITE_EXT | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY | 0x60;
- ctx_orbis->pgl_config.processOrder=1;
- ctx_orbis->pgl_config.systemSharedMemorySize=0x200000;
- ctx_orbis->pgl_config.videoSharedMemorySize=0x2400000;
- ctx_orbis->pgl_config.maxMappedFlexibleMemory=0xAA00000;
- ctx_orbis->pgl_config.drawCommandBufferSize=0xC0000;
- ctx_orbis->pgl_config.lcueResourceBufferSize=0x10000;
- ctx_orbis->pgl_config.dbgPosCmd_0x40=ATTR_ORBISGL_WIDTH;
- ctx_orbis->pgl_config.dbgPosCmd_0x44=ATTR_ORBISGL_HEIGHT;
- ctx_orbis->pgl_config.dbgPosCmd_0x48=0;
- ctx_orbis->pgl_config.dbgPosCmd_0x4C=0;
- ctx_orbis->pgl_config.unk_0x5C=2;
+ ctx_orbis->pgl_config.size =
+ sizeof(ctx_orbis->pgl_config);
+ ctx_orbis->pgl_config.flags =
+ SCE_PGL_FLAGS_USE_COMPOSITE_EXT
+ | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY
+ | 0x60;
+ ctx_orbis->pgl_config.processOrder = 1;
+ ctx_orbis->pgl_config.systemSharedMemorySize = 0x200000;
+ ctx_orbis->pgl_config.videoSharedMemorySize = 0x2400000;
+ ctx_orbis->pgl_config.maxMappedFlexibleMemory = 0xAA00000;
+ ctx_orbis->pgl_config.drawCommandBufferSize = 0xC0000;
+ ctx_orbis->pgl_config.lcueResourceBufferSize = 0x10000;
+ ctx_orbis->pgl_config.dbgPosCmd_0x40 = ATTR_ORBISGL_WIDTH;
+ ctx_orbis->pgl_config.dbgPosCmd_0x44 = ATTR_ORBISGL_HEIGHT;
+ ctx_orbis->pgl_config.dbgPosCmd_0x48 = 0;
+ ctx_orbis->pgl_config.dbgPosCmd_0x4C = 0;
+ ctx_orbis->pgl_config.unk_0x5C = 2;
}
ret = scePigletSetConfigurationVSH(&ctx_orbis->pgl_config);
if (!ret)
@@ -128,7 +137,7 @@ static void orbis_ctx_check_window(void *data, bool *quit,
if (new_width != *width || new_height != *height)
{
- *width = new_width;
+ *width = new_width;
*height = new_height;
*resize = true;
}
@@ -141,17 +150,18 @@ static bool orbis_ctx_set_video_mode(void *data,
bool fullscreen)
{
/* Create an EGL rendering context */
- static const EGLint contextAttributeList[] =
+ static const EGLint
+ contextAttributeList[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE};
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
- ctx_orbis->width = ATTR_ORBISGL_WIDTH;
- ctx_orbis->height = ATTR_ORBISGL_HEIGHT;
+ ctx_orbis->width = ATTR_ORBISGL_WIDTH;
+ ctx_orbis->height = ATTR_ORBISGL_HEIGHT;
- ctx_orbis->native_window.width = ctx_orbis->width;
+ ctx_orbis->native_window.width = ctx_orbis->width;
ctx_orbis->native_window.height = ctx_orbis->height;
ctx_orbis->refresh_rate = 60;
@@ -193,7 +203,6 @@ static enum gfx_ctx_api orbis_ctx_get_api(void *data)
static bool orbis_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
ctx_orbis_api = api;
#ifdef HAVE_EGL
@@ -205,51 +214,33 @@ static bool orbis_ctx_bind_api(void *data,
return false;
}
-static bool orbis_ctx_has_focus(void *data)
-{
- (void)data;
- return true;
-}
+static bool orbis_ctx_has_focus(void *data) { return true; }
-static bool orbis_ctx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool orbis_ctx_suppress_screensaver(void *data, bool enable) { return false; }
static void orbis_ctx_set_swap_interval(void *data,
- int swap_interval)
+ int swap_interval)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
-
#ifdef HAVE_EGL
- egl_set_swap_interval(&ctx_orbis->egl, 0);
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ egl_set_swap_interval(&ctx_orbis->egl, 0);
#endif
}
static void orbis_ctx_swap_buffers(void *data)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
-
#ifdef HAVE_EGL
- egl_swap_buffers(&ctx_orbis->egl);
-#endif
-}
-
-static gfx_ctx_proc_t orbis_ctx_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ egl_swap_buffers(&ctx_orbis->egl);
#endif
}
static void orbis_ctx_bind_hw_render(void *data, bool enable)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
#ifdef HAVE_EGL
- egl_bind_hw_render(&ctx_orbis->egl, enable);
+ egl_bind_hw_render(&ctx_orbis->egl, enable);
#endif
}
@@ -271,16 +262,13 @@ static uint32_t orbis_ctx_get_flags(void *data)
return flags;
}
-static void orbis_ctx_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void orbis_ctx_set_flags(void *data, uint32_t flags) { }
static float orbis_ctx_get_refresh_rate(void *data)
{
- orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
+ orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
- return ctx_orbis->refresh_rate;
+ return ctx_orbis->refresh_rate;
}
const gfx_ctx_driver_t orbis_ctx = {
@@ -305,7 +293,11 @@ const gfx_ctx_driver_t orbis_ctx = {
false, /* has_windowed */
orbis_ctx_swap_buffers,
orbis_ctx_input_driver,
- orbis_ctx_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/osmesa_ctx.c b/gfx/drivers_context/osmesa_ctx.c
index cfc3daecab..cf32ac2053 100644
--- a/gfx/drivers_context/osmesa_ctx.c
+++ b/gfx/drivers_context/osmesa_ctx.c
@@ -41,14 +41,14 @@
#define HAVE_OSMESA_CREATE_CONTEXT_EXT 1
#endif
+#define OSMESA_DEFAULT_FORMAT OSMESA_RGBA
+#define OSMESA_BPP 4
+#define OSMESA_FIFO_PATH "/tmp/osmesa-retroarch.sock"
+
+/* TODO/FIXME - static globals */
static bool g_osmesa_profile = OSMESA_COMPAT_PROFILE;
static int g_osmesa_major = 2;
static int g_osmesa_minor = 1;
-static const int g_osmesa_format = OSMESA_RGBA;
-static const int g_osmesa_bpp = 4;
-static const char *g_osmesa_fifo = "/tmp/osmesa-retroarch.sock";
-
-static enum gfx_ctx_api osmesa_api = GFX_CTX_NONE;
typedef struct gfx_osmesa_ctx_data
{
@@ -77,11 +77,12 @@ static void osmesa_fifo_open(gfx_ctx_osmesa_data_t *osmesa)
saun.sun_family = AF_UNIX;
- strlcpy(saun.sun_path, g_osmesa_fifo, sizeof(saun.sun_path));
+ strlcpy(saun.sun_path, OSMESA_FIFO_PATH, sizeof(saun.sun_path));
- unlink(g_osmesa_fifo);
+ unlink(OSMESA_FIFO_PATH);
- if (bind(osmesa->socket, &saun, sizeof(saun.sun_family) + sizeof(saun.sun_path)) < 0)
+ if (bind(osmesa->socket,
+ &saun, sizeof(saun.sun_family) + sizeof(saun.sun_path)) < 0)
{
perror("[osmesa] bind()");
close(osmesa->socket);
@@ -95,8 +96,10 @@ static void osmesa_fifo_open(gfx_ctx_osmesa_data_t *osmesa)
return;
}
- RARCH_ERR("[osmesa] Frame size is %ix%ix%i\n", osmesa->width, osmesa->height, osmesa->pixsize);
- RARCH_ERR("[osmesa] Please connect to unix:%s\n", g_osmesa_fifo);
+ RARCH_ERR("[osmesa] Frame size is %ix%ix%i\n",
+ osmesa->width, osmesa->height, osmesa->pixsize);
+ RARCH_ERR("[osmesa] Please connect to unix:%s\n",
+ OSMESA_FIFO_PATH);
}
static void osmesa_fifo_accept(gfx_ctx_osmesa_data_t *osmesa)
@@ -146,7 +149,7 @@ static void *osmesa_ctx_init(void *video_driver)
{
#ifdef HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS
const int attribs[] = {
- OSMESA_FORMAT, g_osmesa_format,
+ OSMESA_FORMAT, OSMESA_DEFAULT_FORMAT,
OSMESA_DEPTH_BITS, 0,
OSMESA_STENCIL_BITS, 0,
OSMESA_ACCUM_BITS, 0,
@@ -168,7 +171,7 @@ static void *osmesa_ctx_init(void *video_driver)
#ifdef HAVE_OSMESA_CREATE_CONTEXT_EXT
if (!osmesa->ctx)
- osmesa->ctx = OSMesaCreateContextExt(g_osmesa_format, 0, 0, 0, NULL);
+ osmesa->ctx = OSMesaCreateContextExt(OSMESA_DEFAULT_FORMAT, 0, 0, 0, NULL);
#endif
if (!osmesa->ctx)
@@ -176,13 +179,13 @@ static void *osmesa_ctx_init(void *video_driver)
#if defined(HAVE_OSMESA_CREATE_CONTEXT_ATTRIBS) || defined(HAVE_OSMESA_CREATE_CONTEXT_EXT)
RARCH_WARN("[osmesa]: Falling back to standard context creation.\n");
#endif
- osmesa->ctx = OSMesaCreateContext(g_osmesa_format, NULL);
+ osmesa->ctx = OSMesaCreateContext(OSMESA_DEFAULT_FORMAT, NULL);
}
if (!osmesa->ctx)
goto error;
- osmesa->pixsize = g_osmesa_bpp;
+ osmesa->pixsize = OSMESA_BPP;
return osmesa;
@@ -213,7 +216,7 @@ static void osmesa_ctx_destroy(void *data)
static enum gfx_ctx_api osmesa_ctx_get_api(void *data)
{
- return osmesa_api;
+ return GFX_CTX_OPENGL_API;
}
static bool osmesa_ctx_bind_api(void *data,
@@ -223,19 +226,16 @@ static bool osmesa_ctx_bind_api(void *data,
if (api != GFX_CTX_OPENGL_API)
return false;
- osmesa_api = api;
- g_osmesa_profile = OSMESA_COMPAT_PROFILE;
+ /* Use version 2.1 by default */
+ g_osmesa_major = 2;
+ g_osmesa_minor = 1;
+ g_osmesa_profile = OSMESA_COMPAT_PROFILE;
if (major)
{
g_osmesa_major = major;
g_osmesa_minor = minor;
}
- else
- {
- g_osmesa_major = 2;
- g_osmesa_minor = 1;
- }
return true;
}
@@ -277,27 +277,7 @@ static bool osmesa_ctx_set_video_mode(void *data,
osmesa->screen = screen;
if (!osmesa->socket)
- {
-#if 0
- unlink(g_osmesa_fifo);
- if (mkfifo(g_osmesa_fifo, 0666) == 0)
- {
- RARCH_WARN("[osmesa]: Please connect the sink to the fifo...\n");
- RARCH_WARN("[osmesa]: Picture size is %ux%u\n", width, height);
- osmesa->socket = open(g_osmesa_fifo, O_WRONLY);
-
- if (osmesa->socket)
- RARCH_WARN("[osmesa]: Initialized fifo at %s\n", g_osmesa_fifo);
- }
-
- if (!osmesa->socket || osmesa->socket < 0)
- {
- unlink(g_osmesa_fifo);
- RARCH_WARN("[osmesa]: Failed to initialize fifo: %s\n", strerror(errno));
- }
-#endif
osmesa_fifo_open(osmesa);
- }
return true;
}
@@ -326,18 +306,9 @@ static void osmesa_ctx_check_window(void *data, bool *quit,
*quit = false;
}
-static bool osmesa_ctx_has_focus(void *data)
-{
- (void)data;
- return true;
-}
+static bool osmesa_ctx_has_focus(void *data) { return true; }
-static bool osmesa_ctx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool osmesa_ctx_suppress_screensaver(void *data, bool enable) { return false; }
static void osmesa_ctx_swap_buffers(void *data)
{
@@ -363,12 +334,6 @@ static gfx_ctx_proc_t osmesa_ctx_get_proc_address(const char *name)
return (gfx_ctx_proc_t)OSMesaGetProcAddress(name);
}
-static void osmesa_ctx_show_mouse(void *data, bool state)
-{
- (void)data;
- (void)state;
-}
-
static uint32_t osmesa_ctx_get_flags(void *data)
{
uint32_t flags = 0;
@@ -378,10 +343,8 @@ static uint32_t osmesa_ctx_get_flags(void *data)
return flags;
}
-static void osmesa_ctx_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void osmesa_ctx_show_mouse(void *data, bool state) { }
+static void osmesa_ctx_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_osmesa =
{
diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c
index 88f03dc719..e870e5307f 100644
--- a/gfx/drivers_context/ps3_ctx.c
+++ b/gfx/drivers_context/ps3_ctx.c
@@ -41,6 +41,7 @@ typedef struct gfx_ctx_ps3_data
#endif
} gfx_ctx_ps3_data_t;
+/* TODO/FIXME - static global */
static enum gfx_ctx_api ps3_api = GFX_CTX_NONE;
static void gfx_ctx_ps3_get_resolution(unsigned idx,
@@ -158,22 +159,11 @@ static void gfx_ctx_ps3_check_window(void *data, bool *quit,
*resize = true;
}
-static bool gfx_ctx_ps3_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_ps3_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool gfx_ctx_ps3_has_focus(void *data) { return true; }
+static bool gfx_ctx_ps3_suppress_screensaver(void *data, bool enable) { return false; }
static void gfx_ctx_ps3_swap_buffers(void *data)
{
- (void)data;
#ifdef HAVE_PSGL
psglSwap();
#endif
@@ -203,9 +193,6 @@ static void *gfx_ctx_ps3_init(void *video_driver)
gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)
calloc(1, sizeof(gfx_ctx_ps3_data_t));
- (void)video_driver;
- (void)global;
-
if (!ps3)
return NULL;
@@ -271,10 +258,7 @@ static void *gfx_ctx_ps3_init(void *video_driver)
static bool gfx_ctx_ps3_set_video_mode(void *data,
unsigned width, unsigned height,
- bool fullscreen)
-{
- return true;
-}
+ bool fullscreen) { return true; }
static void gfx_ctx_ps3_destroy_resources(gfx_ctx_ps3_data_t *ps3)
{
@@ -310,18 +294,11 @@ static void gfx_ctx_ps3_input_driver(void *data,
*input_data = ps3input;
}
-static enum gfx_ctx_api gfx_ctx_ps3_get_api(void *data)
-{
- return ps3_api;
-}
+static enum gfx_ctx_api gfx_ctx_ps3_get_api(void *data) { return ps3_api; }
static bool gfx_ctx_ps3_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
- (void)major;
- (void)minor;
-
ps3_api = api;
if (
@@ -400,10 +377,7 @@ static uint32_t gfx_ctx_ps3_get_flags(void *data)
return flags;
}
-static void gfx_ctx_ps3_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void gfx_ctx_ps3_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_ps3 = {
gfx_ctx_ps3_init,
diff --git a/gfx/drivers_context/qnx_ctx.c b/gfx/drivers_context/qnx_ctx.c
index 9ad55430d3..f4ba0d7cf0 100644
--- a/gfx/drivers_context/qnx_ctx.c
+++ b/gfx/drivers_context/qnx_ctx.c
@@ -49,9 +49,6 @@
#define WINDOW_BUFFERS 2
-screen_context_t screen_ctx;
-screen_window_t screen_win;
-
typedef struct
{
#ifdef HAVE_EGL
@@ -61,7 +58,10 @@ typedef struct
bool resize;
} qnx_ctx_data_t;
-static enum gfx_ctx_api qnx_api = GFX_CTX_NONE;
+/* TODO/FIXME - globals with public scope */
+screen_context_t screen_ctx;
+screen_window_t screen_win;
+
static void gfx_ctx_qnx_destroy(void *data)
{
@@ -78,6 +78,11 @@ static void *gfx_ctx_qnx_init(void *video_driver)
{
EGLint n;
EGLint major, minor;
+ int usage, format;
+#ifndef HAVE_BB10
+ int angle, size[2];
+ screen_display_mode_t screen_mode;
+#endif
EGLint context_attributes[] = {
#ifdef HAVE_OPENGLES2
EGL_CONTEXT_CLIENT_VERSION, 2,
@@ -150,7 +155,7 @@ static void *gfx_ctx_qnx_init(void *video_driver)
}
}
- int format = SCREEN_FORMAT_RGBX8888;
+ format = SCREEN_FORMAT_RGBX8888;
if (screen_set_window_property_iv(screen_win,
SCREEN_PROPERTY_FORMAT, &format))
{
@@ -158,7 +163,6 @@ static void *gfx_ctx_qnx_init(void *video_driver)
goto error;
}
- int usage;
#ifdef HAVE_OPENGLES2
usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
#elif HAVE_OPENGLES3
@@ -188,11 +192,8 @@ static void *gfx_ctx_qnx_init(void *video_driver)
}
#ifndef HAVE_BB10
- int angle, size[2];
-
angle = atoi(getenv("ORIENTATION"));
- screen_display_mode_t screen_mode;
if (screen_get_display_property_pv(qnx->screen_disp,
SCREEN_PROPERTY_MODE, (void**)&screen_mode))
{
@@ -299,14 +300,7 @@ static void gfx_ctx_qnx_check_window(void *data, bool *quit,
static bool gfx_ctx_qnx_set_video_mode(void *data,
unsigned width, unsigned height,
- bool fullscreen)
-{
- (void)data;
- (void)width;
- (void)height;
- (void)fullscreen;
- return true;
-}
+ bool fullscreen) { return true; }
static void gfx_ctx_qnx_input_driver(void *data,
const char *joypad_name,
@@ -318,36 +312,19 @@ static void gfx_ctx_qnx_input_driver(void *data,
*input_data = qnxinput;
}
-static enum gfx_ctx_api gfx_ctx_qnx_get_api(void *data)
-{
- return qnx_api;
-}
+static enum gfx_ctx_api gfx_ctx_qnx_get_api(void *data) { return GFX_CTX_OPENGL_ES_API; }
static bool gfx_ctx_qnx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
-
- qnx_api = api;
-
if (api == GFX_CTX_OPENGL_ES_API)
return true;
-
return false;
}
-static bool gfx_ctx_qnx_has_focus(void *data)
-{
- (void)data;
- return true;
-}
+static bool gfx_ctx_qnx_has_focus(void *data) { return true; }
-static bool gfx_ctx_qnx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool gfx_ctx_qnx_suppress_screensaver(void *data, bool enable) { return false; }
static int dpi_get_density(qnx_ctx_data_t *qnx)
{
@@ -430,13 +407,6 @@ static void gfx_ctx_qnx_bind_hw_render(void *data, bool enable)
#endif
}
-static gfx_ctx_proc_t gfx_ctx_qnx_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#endif
-}
-
static uint32_t gfx_ctx_qnx_get_flags(void *data)
{
uint32_t flags = 0;
@@ -446,10 +416,7 @@ static uint32_t gfx_ctx_qnx_get_flags(void *data)
return flags;
}
-static void gfx_ctx_qnx_set_flags(void *data, uint32_t flags)
-{
- (void)flags;
-}
+static void gfx_ctx_qnx_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_qnx = {
gfx_ctx_qnx_init,
@@ -473,7 +440,11 @@ const gfx_ctx_driver_t gfx_ctx_qnx = {
false, /* has_windowed */
gfx_ctx_qnx_swap_buffers,
gfx_ctx_qnx_input_driver,
- gfx_ctx_qnx_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c
index 3709172894..7a368f8f8c 100644
--- a/gfx/drivers_context/sdl_gl_ctx.c
+++ b/gfx/drivers_context/sdl_gl_ctx.c
@@ -32,44 +32,45 @@
#include "../common/sdl2_common.h"
#endif
-static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API;
-
typedef struct gfx_ctx_sdl_data
{
- int g_width;
- int g_height;
- int g_new_width;
- int g_new_height;
+ int width;
+ int height;
+ int new_width;
+ int new_height;
- bool g_full;
- bool g_resized;
+ bool full;
+ bool resized;
#ifdef HAVE_SDL2
- SDL_Window *g_win;
- SDL_GLContext g_ctx;
+ SDL_Window *win;
+ SDL_GLContext ctx;
#else
- SDL_Surface *g_win;
+ SDL_Surface *win;
#endif
} gfx_ctx_sdl_data_t;
+/* TODO/FIXME - static global */
+static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API;
+
static void sdl_ctx_destroy_resources(gfx_ctx_sdl_data_t *sdl)
{
if (!sdl)
return;
#ifdef HAVE_SDL2
- if (sdl->g_ctx)
- SDL_GL_DeleteContext(sdl->g_ctx);
+ if (sdl->ctx)
+ SDL_GL_DeleteContext(sdl->ctx);
- if (sdl->g_win)
- SDL_DestroyWindow(sdl->g_win);
+ if (sdl->win)
+ SDL_DestroyWindow(sdl->win);
- sdl->g_ctx = NULL;
+ sdl->ctx = NULL;
#else
- if (sdl->g_win)
- SDL_FreeSurface(sdl->g_win);
+ if (sdl->win)
+ SDL_FreeSurface(sdl->win);
#endif
- sdl->g_win = NULL;
+ sdl->win = NULL;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
@@ -95,13 +96,13 @@ static void *sdl_ctx_init(void *video_driver)
goto error;
RARCH_LOG("[SDL_GL] SDL %i.%i.%i gfx context driver initialized.\n",
- SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
return sdl;
error:
RARCH_WARN("[SDL_GL]: Failed to initialize SDL gfx context driver: %s\n",
- SDL_GetError());
+ SDL_GetError());
sdl_ctx_destroy_resources(sdl);
@@ -122,10 +123,7 @@ static void sdl_ctx_destroy(void *data)
free(sdl);
}
-static enum gfx_ctx_api sdl_ctx_get_api(void *data)
-{
- return sdl_api;
-}
+static enum gfx_ctx_api sdl_ctx_get_api(void *data) { return sdl_api; }
static bool sdl_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major,
@@ -159,7 +157,6 @@ static bool sdl_ctx_bind_api(void *data,
static void sdl_ctx_swap_interval(void *data, int interval)
{
- (void)data;
#ifdef HAVE_SDL2
SDL_GL_SetSwapInterval(interval);
#else
@@ -171,14 +168,14 @@ static bool sdl_ctx_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
- unsigned fsflag = 0;
- gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
- settings_t *settings = config_get_ptr();
- bool windowed_fullscreen= settings->bools.video_windowed_fullscreen;
+ unsigned fsflag = 0;
+ gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
+ settings_t *settings = config_get_ptr();
+ bool windowed_fullscreen = settings->bools.video_windowed_fullscreen;
unsigned video_monitor_index = settings->uints.video_monitor_index;
- sdl->g_new_width = width;
- sdl->g_new_height = height;
+ sdl->new_width = width;
+ sdl->new_height = height;
#ifdef HAVE_SDL2
@@ -190,18 +187,18 @@ static bool sdl_ctx_set_video_mode(void *data,
fsflag = SDL_WINDOW_FULLSCREEN;
}
- if (sdl->g_win)
+ if (sdl->win)
{
- SDL_SetWindowSize(sdl->g_win, width, height);
+ SDL_SetWindowSize(sdl->win, width, height);
if (fullscreen)
- SDL_SetWindowFullscreen(sdl->g_win, fsflag);
+ SDL_SetWindowFullscreen(sdl->win, fsflag);
}
else
{
unsigned display = video_monitor_index;
- sdl->g_win = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED_DISPLAY(display),
+ sdl->win = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED_DISPLAY(display),
SDL_WINDOWPOS_UNDEFINED_DISPLAY(display),
width, height, SDL_WINDOW_OPENGL | fsflag);
}
@@ -209,35 +206,35 @@ static bool sdl_ctx_set_video_mode(void *data,
if (fullscreen)
fsflag = SDL_FULLSCREEN;
- sdl->g_win = SDL_SetVideoMode(width, height, 0, SDL_OPENGL | fsflag);
+ sdl->win = SDL_SetVideoMode(width, height, 0, SDL_OPENGL | fsflag);
#endif
- if (!sdl->g_win)
+ if (!sdl->win)
goto error;
#ifdef HAVE_SDL2
#if defined(_WIN32)
- sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_WIN32);
+ sdl2_set_handles(sdl->win, RARCH_DISPLAY_WIN32);
#elif defined(HAVE_X11)
- sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_X11);
+ sdl2_set_handles(sdl->win, RARCH_DISPLAY_X11);
#elif defined(HAVE_COCOA)
- sdl2_set_handles(sdl->g_win, RARCH_DISPLAY_OSX);
+ sdl2_set_handles(sdl->win, RARCH_DISPLAY_OSX);
#endif
- if (sdl->g_ctx)
+ if (sdl->ctx)
video_driver_set_video_cache_context_ack();
else
{
- sdl->g_ctx = SDL_GL_CreateContext(sdl->g_win);
+ sdl->ctx = SDL_GL_CreateContext(sdl->win);
- if (!sdl->g_ctx)
+ if (!sdl->ctx)
goto error;
}
#endif
- sdl->g_full = fullscreen;
- sdl->g_width = width;
- sdl->g_height = height;
+ sdl->full = fullscreen;
+ sdl->width = width;
+ sdl->height = height;
return true;
@@ -255,10 +252,10 @@ static void sdl_ctx_get_video_size(void *data,
if (!sdl)
return;
- *width = sdl->g_width;
- *height = sdl->g_height;
+ *width = sdl->width;
+ *height = sdl->height;
- if (!sdl->g_win)
+ if (!sdl->win)
{
#ifdef HAVE_SDL2
SDL_DisplayMode mode = {0};
@@ -293,7 +290,8 @@ static void sdl_ctx_update_title(void *data)
if (title[0])
{
#ifdef HAVE_SDL2
- SDL_SetWindowTitle((SDL_Window*)video_driver_display_userdata_get(), title);
+ SDL_SetWindowTitle((SDL_Window*)
+ video_driver_display_userdata_get(), title);
#else
SDL_WM_SetCaption(title, NULL);
#endif
@@ -310,9 +308,11 @@ static void sdl_ctx_check_window(void *data, bool *quit,
SDL_PumpEvents();
#ifdef HAVE_SDL2
- while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUIT, SDL_WINDOWEVENT) > 0)
+ while (SDL_PeepEvents(&event, 1,
+ SDL_GETEVENT, SDL_QUIT, SDL_WINDOWEVENT) > 0)
#else
- while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_QUITMASK|SDL_VIDEORESIZEMASK) > 0)
+ while (SDL_PeepEvents(&event, 1,
+ SDL_GETEVENT, SDL_QUITMASK|SDL_VIDEORESIZEMASK) > 0)
#endif
{
switch (event.type)
@@ -327,15 +327,15 @@ static void sdl_ctx_check_window(void *data, bool *quit,
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
{
- sdl->g_resized = true;
- sdl->g_new_width = event.window.data1;
- sdl->g_new_height = event.window.data2;
+ sdl->resized = true;
+ sdl->new_width = event.window.data1;
+ sdl->new_height = event.window.data2;
}
#else
case SDL_VIDEORESIZE:
- sdl->g_resized = true;
- sdl->g_new_width = event.resize.w;
- sdl->g_new_height = event.resize.h;
+ sdl->resized = true;
+ sdl->new_width = event.resize.w;
+ sdl->new_height = event.resize.h;
#endif
break;
default:
@@ -343,12 +343,12 @@ static void sdl_ctx_check_window(void *data, bool *quit,
}
}
- if (sdl->g_resized)
+ if (sdl->resized)
{
- *width = sdl->g_new_width;
- *height = sdl->g_new_height;
- *resize = true;
- sdl->g_resized = false;
+ *width = sdl->new_width;
+ *height = sdl->new_height;
+ *resize = true;
+ sdl->resized = false;
}
}
@@ -359,26 +359,19 @@ static bool sdl_ctx_has_focus(void *data)
#ifdef HAVE_SDL2
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
- return (SDL_GetWindowFlags(sdl->g_win) & flags) == flags;
+ return (SDL_GetWindowFlags(sdl->win) & flags) == flags;
#else
flags = (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
return (SDL_GetAppState() & flags) == flags;
#endif
}
-static bool sdl_ctx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
static void sdl_ctx_swap_buffers(void *data)
{
#ifdef HAVE_SDL2
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
if (sdl)
- SDL_GL_SwapWindow(sdl->g_win);
+ SDL_GL_SwapWindow(sdl->win);
#else
SDL_GL_SwapBuffers();
#endif
@@ -397,11 +390,7 @@ static gfx_ctx_proc_t sdl_ctx_get_proc_address(const char *name)
return (gfx_ctx_proc_t)SDL_GL_GetProcAddress(name);
}
-static void sdl_ctx_show_mouse(void *data, bool state)
-{
- (void)data;
- SDL_ShowCursor(state);
-}
+static void sdl_ctx_show_mouse(void *data, bool state) { SDL_ShowCursor(state); }
static uint32_t sdl_ctx_get_flags(void *data)
{
@@ -412,10 +401,8 @@ static uint32_t sdl_ctx_get_flags(void *data)
return flags;
}
-static void sdl_ctx_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static bool sdl_ctx_suppress_screensaver(void *data, bool enable) { return false; }
+static void sdl_ctx_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_sdl_gl =
{
diff --git a/gfx/drivers_context/sixel_ctx.c b/gfx/drivers_context/sixel_ctx.c
deleted file mode 100644
index 7b6ca0e226..0000000000
--- a/gfx/drivers_context/sixel_ctx.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/* RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2017 - Daniel De Matteis
- * Copyright (C) 2016-2019 - Brad Parker
- *
- * RetroArch is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Found-
- * ation, either version 3 of the License, or (at your option) any later version.
- *
- * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with RetroArch.
- * If not, see .
- */
-
-/* SIXEL context. */
-
-#ifdef HAVE_CONFIG_H
-#include "../../config.h"
-#endif
-
-#include "../../configuration.h"
-#include "../../dynamic.h"
-#include "../../retroarch.h"
-#include "../../verbosity.h"
-#include "../../ui/ui_companion_driver.h"
-
-#if defined(_WIN32) && !defined(_XBOX)
-#include "../common/win32_common.h"
-#endif
-
-static enum gfx_ctx_api sixel_ctx_api = GFX_CTX_NONE;
-
-static void gfx_ctx_sixel_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
-}
-
-static bool gfx_ctx_sixel_set_resize(void *data,
- unsigned width, unsigned height)
-{
- (void)data;
- (void)width;
- (void)height;
-
- return false;
-}
-
-static void gfx_ctx_sixel_get_video_size(void *data,
- unsigned *width, unsigned *height)
-{
- (void)data;
-}
-
-static void *gfx_ctx_sixel_init(void *video_driver)
-{
- (void)video_driver;
-
- return (void*)"sixel";
-}
-
-static void gfx_ctx_sixel_destroy(void *data)
-{
- (void)data;
-}
-
-static bool gfx_ctx_sixel_set_video_mode(void *data,
- unsigned width, unsigned height,
- bool fullscreen)
-{
- return true;
-}
-
-static void gfx_ctx_sixel_input_driver(void *data,
- const char *joypad_name,
- input_driver_t **input, void **input_data)
-{
- (void)data;
-
-#ifdef HAVE_UDEV
- *input_data = input_udev.init(joypad_name);
-
- if (*input_data)
- {
- *input = &input_udev;
- return;
- }
-#endif
- *input = NULL;
- *input_data = NULL;
-}
-
-static bool gfx_ctx_sixel_has_focus(void *data)
-{
- return true;
-}
-
-static bool gfx_ctx_sixel_suppress_screensaver(void *data, bool enable)
-{
- return true;
-}
-
-static bool gfx_ctx_sixel_get_metrics(void *data,
- enum display_metric_types type, float *value)
-{
- return false;
-}
-
-static enum gfx_ctx_api gfx_ctx_sixel_get_api(void *data)
-{
- return sixel_ctx_api;
-}
-
-static bool gfx_ctx_sixel_bind_api(void *data,
- enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
-
- return true;
-}
-
-static void gfx_ctx_sixel_show_mouse(void *data, bool state)
-{
- (void)data;
-}
-
-static void gfx_ctx_sixel_swap_interval(void *data, int interval)
-{
- (void)data;
- (void)interval;
-}
-
-static void gfx_ctx_sixel_set_flags(void *data, uint32_t flags)
-{
- (void)data;
- (void)flags;
-}
-
-static uint32_t gfx_ctx_sixel_get_flags(void *data)
-{
- uint32_t flags = 0;
-
- return flags;
-}
-
-const gfx_ctx_driver_t gfx_ctx_sixel = {
- gfx_ctx_sixel_init,
- gfx_ctx_sixel_destroy,
- gfx_ctx_sixel_get_api,
- gfx_ctx_sixel_bind_api,
- gfx_ctx_sixel_swap_interval,
- gfx_ctx_sixel_set_video_mode,
- gfx_ctx_sixel_get_video_size,
- NULL, /* get_refresh_rate */
- NULL, /* get_video_output_size */
- NULL, /* get_video_output_prev */
- NULL, /* get_video_output_next */
- gfx_ctx_sixel_get_metrics,
- NULL,
- NULL, /* update_title */
- gfx_ctx_sixel_check_window,
- gfx_ctx_sixel_set_resize,
- gfx_ctx_sixel_has_focus,
- gfx_ctx_sixel_suppress_screensaver,
- true, /* has_windowed */
- NULL, /* swap_buffers */
- gfx_ctx_sixel_input_driver,
- NULL,
- NULL,
- NULL,
- gfx_ctx_sixel_show_mouse,
- "sixel",
- gfx_ctx_sixel_get_flags,
- gfx_ctx_sixel_set_flags,
- NULL,
- NULL,
- NULL
-};
diff --git a/gfx/drivers_context/switch_ctx.c b/gfx/drivers_context/switch_ctx.c
index a6cf2dc278..4633c864ac 100644
--- a/gfx/drivers_context/switch_ctx.c
+++ b/gfx/drivers_context/switch_ctx.c
@@ -27,8 +27,7 @@
#include "../common/switch_common.h"
#include "../../frontend/frontend_driver.h"
-static enum gfx_ctx_api ctx_nx_api = GFX_CTX_OPENGL_API;
-
+/* TODO/FIXME - global referenced */
extern bool platform_switch_has_focus;
void switch_ctx_destroy(void *data)
@@ -197,15 +196,12 @@ static void switch_ctx_input_driver(void *data,
static enum gfx_ctx_api switch_ctx_get_api(void *data)
{
- return ctx_nx_api;
+ return GFX_CTX_OPENGL_API;
}
static bool switch_ctx_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
- ctx_nx_api = api;
-
if (api == GFX_CTX_OPENGL_API)
if (egl_bind_api(EGL_OPENGL_API))
return true;
@@ -213,18 +209,8 @@ static bool switch_ctx_bind_api(void *data,
return false;
}
-static bool switch_ctx_has_focus(void *data)
-{
- (void)data;
- return platform_switch_has_focus;
-}
-
-static bool switch_ctx_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool switch_ctx_has_focus(void *data) { return platform_switch_has_focus; }
+static bool switch_ctx_suppress_screensaver(void *data, bool enable) { return false; }
static void switch_ctx_set_swap_interval(void *data,
int swap_interval)
@@ -245,13 +231,6 @@ static void switch_ctx_swap_buffers(void *data)
#endif
}
-static gfx_ctx_proc_t switch_ctx_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#endif
-}
-
static void switch_ctx_bind_hw_render(void *data, bool enable)
{
switch_ctx_data_t *ctx_nx = (switch_ctx_data_t *)data;
@@ -281,10 +260,7 @@ static uint32_t switch_ctx_get_flags(void *data)
return flags;
}
-static void switch_ctx_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void switch_ctx_set_flags(void *data, uint32_t flags) { }
static float switch_ctx_get_refresh_rate(void *data)
{
@@ -365,7 +341,11 @@ const gfx_ctx_driver_t switch_ctx = {
false, /* has_windowed */
switch_ctx_swap_buffers,
switch_ctx_input_driver,
- switch_ctx_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/uwp_egl_ctx.c b/gfx/drivers_context/uwp_egl_ctx.c
index 7367311ecc..3d0eb0ad5a 100644
--- a/gfx/drivers_context/uwp_egl_ctx.c
+++ b/gfx/drivers_context/uwp_egl_ctx.c
@@ -52,19 +52,15 @@
#include "../common/angle_common.h"
#endif
+/* TODO/FIXME - static globals */
+static egl_ctx_data_t uwp_egl;
#ifdef HAVE_DYNAMIC
static dylib_t dll_handle = NULL; /* Handle to libGLESv2.dll */
#endif
-static void gfx_ctx_uwp_destroy(void *data);
-
-static egl_ctx_data_t uwp_egl;
-static int uwp_interval = 0;
-static enum gfx_ctx_api uwp_api = GFX_CTX_OPENGL_ES_API;
-
typedef struct gfx_ctx_cgl_data
{
- void *empty;
+ int interval;
} gfx_ctx_uwp_data_t;
bool create_gles_context(void* corewindow)
@@ -119,31 +115,15 @@ error:
static void gfx_ctx_uwp_swap_interval(void *data, int interval)
{
- (void)data;
+ gfx_ctx_uwp_data_t *uwp = (gfx_ctx_uwp_data_t*)data;
- switch (uwp_api)
+ if (uwp->interval != interval)
{
- case GFX_CTX_OPENGL_ES_API:
- if (uwp_interval != interval)
- {
- uwp_interval = interval;
- egl_set_swap_interval(&uwp_egl, uwp_interval);
- }
- break;
-
- case GFX_CTX_NONE:
- default:
- break;
+ uwp->interval = interval;
+ egl_set_swap_interval(&uwp_egl, uwp->interval);
}
}
-static void gfx_ctx_uwp_check_window(void *data, bool *quit,
- bool *resize, unsigned *width, unsigned *height)
-{
- win32_check_window(quit, resize, width, height);
-}
-
-
static gfx_ctx_proc_t gfx_ctx_uwp_get_proc_address(const char* symbol)
{
#ifdef HAVE_DYNAMIC
@@ -154,36 +134,17 @@ static gfx_ctx_proc_t gfx_ctx_uwp_get_proc_address(const char* symbol)
}
-static void gfx_ctx_uwp_swap_buffers(void *data)
-{
- switch (uwp_api)
- {
- case GFX_CTX_OPENGL_ES_API:
- egl_swap_buffers(&uwp_egl);
- break;
- case GFX_CTX_NONE:
- default:
- break;
- }
-}
+static void gfx_ctx_uwp_swap_buffers(void *data) { egl_swap_buffers(&uwp_egl); }
static bool gfx_ctx_uwp_set_resize(void *data,
- unsigned width, unsigned height)
-{
- (void)data;
- (void)width;
- (void)height;
-
- return false;
-}
-
+ unsigned width, unsigned height) { return false; }
static void gfx_ctx_uwp_get_video_size(void *data,
unsigned *width, unsigned *height)
{
bool quit;
bool resize;
- win32_check_window(&quit, &resize, width, height);
+ win32_check_window(NULL, &quit, &resize, width, height);
}
static void *gfx_ctx_uwp_init(void *video_driver)
@@ -193,7 +154,6 @@ static void *gfx_ctx_uwp_init(void *video_driver)
if (!uwp)
return NULL;
-
#ifdef HAVE_DYNAMIC
dll_handle = dylib_load("libGLESv2.dll");
#endif
@@ -204,39 +164,35 @@ static void *gfx_ctx_uwp_init(void *video_driver)
static void gfx_ctx_uwp_destroy(void *data)
{
gfx_ctx_uwp_data_t *wgl = (gfx_ctx_uwp_data_t*)data;
+
+ if (!wgl)
+ return;
- switch (uwp_api)
- {
- case GFX_CTX_OPENGL_ES_API:
- egl_destroy(&uwp_egl);
- break;
-
- case GFX_CTX_NONE:
- default:
- break;
- }
+ egl_destroy(&uwp_egl);
#ifdef HAVE_DYNAMIC
dylib_close(dll_handle);
#endif
-
}
static bool gfx_ctx_uwp_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
+ gfx_ctx_uwp_data_t *uwp = (gfx_ctx_uwp_data_t*)data;
+
if (!win32_set_video_mode(NULL, width, height, fullscreen))
{
RARCH_ERR("[UWP EGL]: win32_set_video_mode failed.\n");
}
- if (!create_gles_context(uwp_get_corewindow())) {
+ if (!create_gles_context(uwp_get_corewindow()))
+ {
RARCH_ERR("[UWP EGL]: create_gles_context failed.\n");
goto error;
}
- gfx_ctx_uwp_swap_interval(data, uwp_interval);
+ gfx_ctx_uwp_swap_interval(data, uwp->interval);
return true;
error:
@@ -255,66 +211,45 @@ static void gfx_ctx_uwp_input_driver(void *data,
if (string_is_equal(settings->arrays.input_driver, "xinput"))
{
void* xinput = input_xinput.init(joypad_name);
- *input = xinput ? (input_driver_t*)&input_xinput : NULL;
- *input_data = xinput;
+ *input = xinput ? (input_driver_t*)&input_xinput : NULL;
+ *input_data = xinput;
}
else
{
- void* uwp = input_uwp.init(joypad_name);
- *input = uwp ? (input_driver_t*)&input_uwp : NULL;
+ void* uwp = input_uwp.init(joypad_name);
+ *input = uwp ? (input_driver_t*)&input_uwp : NULL;
*input_data = uwp;
}
}
static enum gfx_ctx_api gfx_ctx_uwp_get_api(void *data)
{
- return uwp_api;
+ return GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_uwp_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
- (void)data;
-
if (api == GFX_CTX_OPENGL_ES_API)
return true;
- else
- return false;
+ return false;
}
static void gfx_ctx_uwp_bind_hw_render(void *data, bool enable)
{
- switch (uwp_api)
- {
- case GFX_CTX_OPENGL_ES_API:
- egl_bind_hw_render(&uwp_egl, enable);
- break;
-
- case GFX_CTX_NONE:
- default:
- break;
- }
+ egl_bind_hw_render(&uwp_egl, enable);
}
static uint32_t gfx_ctx_uwp_get_flags(void *data)
{
uint32_t flags = 0;
- switch (uwp_api)
- {
- case GFX_CTX_OPENGL_ES_API:
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
- BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
+ BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
#ifdef HAVE_GLSL
- BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
+ BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
#endif
- break;
-
- case GFX_CTX_NONE:
- default:
- break;
- }
return flags;
}
@@ -334,7 +269,7 @@ const gfx_ctx_driver_t gfx_ctx_uwp = {
win32_get_metrics,
NULL,
NULL, /* update title */
- gfx_ctx_uwp_check_window,
+ win32_check_window,
gfx_ctx_uwp_set_resize,
win32_has_focus,
NULL, /* suppress screensaver */
diff --git a/gfx/drivers_context/vc_egl_ctx.c b/gfx/drivers_context/vc_egl_ctx.c
index 9eceb5da57..5ea4070472 100644
--- a/gfx/drivers_context/vc_egl_ctx.c
+++ b/gfx/drivers_context/vc_egl_ctx.c
@@ -74,11 +74,12 @@ typedef struct
EGLContext eglimage_ctx;
EGLSurface pbuff_surf;
VGImage vgimage[MAX_EGLIMAGE_TEXTURES];
+ PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR;
+ PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR;
} vc_ctx_data_t;
+/* TODO/FIXME - static globals */
static enum gfx_ctx_api vc_api = GFX_CTX_NONE;
-static PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR;
-static PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR;
static INLINE bool gfx_ctx_vc_egl_query_extension(vc_ctx_data_t *vc, const char *ext)
{
@@ -146,7 +147,102 @@ static void dispmanx_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
slock_unlock(vc->vsync_condition_mutex);
}
-static void gfx_ctx_vc_destroy(void *data);
+static void gfx_ctx_vc_destroy(void *data)
+{
+ vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
+ unsigned i;
+
+ if (!vc)
+ {
+ g_egl_inited = false;
+ return;
+ }
+
+ if (vc->egl.dpy)
+ {
+ for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
+ {
+ if (vc->eglBuffer[i] && vc->peglDestroyImageKHR)
+ {
+ egl_bind_api(EGL_OPENVG_API);
+ eglMakeCurrent(vc->egl.dpy,
+ vc->pbuff_surf, vc->pbuff_surf, vc->eglimage_ctx);
+ vc->peglDestroyImageKHR(vc->egl.dpy, vc->eglBuffer[i]);
+ }
+
+ if (vc->vgimage[i])
+ {
+ egl_bind_api(EGL_OPENVG_API);
+ eglMakeCurrent(vc->egl.dpy,
+ vc->pbuff_surf, vc->pbuff_surf, vc->eglimage_ctx);
+ vgDestroyImage(vc->vgimage[i]);
+ }
+ }
+
+ if (vc->egl.ctx)
+ {
+ gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
+ eglMakeCurrent(vc->egl.dpy,
+ EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroyContext(vc->egl.dpy, vc->egl.ctx);
+ }
+
+ if (vc->egl.hw_ctx)
+ eglDestroyContext(vc->egl.dpy, vc->egl.hw_ctx);
+
+ if (vc->eglimage_ctx)
+ {
+ egl_bind_api(EGL_OPENVG_API);
+ eglMakeCurrent(vc->egl.dpy,
+ EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroyContext(vc->egl.dpy, vc->eglimage_ctx);
+ }
+
+ if (vc->egl.surf)
+ {
+ gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
+ eglDestroySurface(vc->egl.dpy, vc->egl.surf);
+ }
+
+ if (vc->pbuff_surf)
+ {
+ egl_bind_api(EGL_OPENVG_API);
+ eglDestroySurface(vc->egl.dpy, vc->pbuff_surf);
+ }
+
+ egl_bind_api(EGL_OPENVG_API);
+ eglMakeCurrent(vc->egl.dpy,
+ EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
+ eglMakeCurrent(vc->egl.dpy,
+ EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ egl_terminate(vc->egl.dpy);
+ }
+
+ vc->egl.ctx = NULL;
+ vc->egl.hw_ctx = NULL;
+ vc->eglimage_ctx = NULL;
+ vc->egl.surf = NULL;
+ vc->pbuff_surf = NULL;
+ vc->egl.dpy = NULL;
+ vc->egl.config = 0;
+ g_egl_inited = false;
+
+ for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
+ {
+ vc->eglBuffer[i] = NULL;
+ vc->vgimage[i] = 0;
+ }
+
+ /* Stop generating vsync callbacks if we are doing so.
+ * Don't destroy the context while cbs are being generated! */
+ if (vc->vsync_callback_set)
+ vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
+
+ /* Destroy mutexes and conditions. */
+ slock_free(vc->vsync_condition_mutex);
+ scond_free(vc->vsync_condition);
+}
static void *gfx_ctx_vc_init(void *video_driver)
{
@@ -382,103 +478,6 @@ static bool gfx_ctx_vc_bind_api(void *data,
return false;
}
-static void gfx_ctx_vc_destroy(void *data)
-{
- vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
- unsigned i;
-
- if (!vc)
- {
- g_egl_inited = false;
- return;
- }
-
- if (vc->egl.dpy)
- {
- for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
- {
- if (vc->eglBuffer[i] && peglDestroyImageKHR)
- {
- egl_bind_api(EGL_OPENVG_API);
- eglMakeCurrent(vc->egl.dpy,
- vc->pbuff_surf, vc->pbuff_surf, vc->eglimage_ctx);
- peglDestroyImageKHR(vc->egl.dpy, vc->eglBuffer[i]);
- }
-
- if (vc->vgimage[i])
- {
- egl_bind_api(EGL_OPENVG_API);
- eglMakeCurrent(vc->egl.dpy,
- vc->pbuff_surf, vc->pbuff_surf, vc->eglimage_ctx);
- vgDestroyImage(vc->vgimage[i]);
- }
- }
-
- if (vc->egl.ctx)
- {
- gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
- eglMakeCurrent(vc->egl.dpy,
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglDestroyContext(vc->egl.dpy, vc->egl.ctx);
- }
-
- if (vc->egl.hw_ctx)
- eglDestroyContext(vc->egl.dpy, vc->egl.hw_ctx);
-
- if (vc->eglimage_ctx)
- {
- egl_bind_api(EGL_OPENVG_API);
- eglMakeCurrent(vc->egl.dpy,
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglDestroyContext(vc->egl.dpy, vc->eglimage_ctx);
- }
-
- if (vc->egl.surf)
- {
- gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
- eglDestroySurface(vc->egl.dpy, vc->egl.surf);
- }
-
- if (vc->pbuff_surf)
- {
- egl_bind_api(EGL_OPENVG_API);
- eglDestroySurface(vc->egl.dpy, vc->pbuff_surf);
- }
-
- egl_bind_api(EGL_OPENVG_API);
- eglMakeCurrent(vc->egl.dpy,
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- gfx_ctx_vc_bind_api(data, vc_api, 0, 0);
- eglMakeCurrent(vc->egl.dpy,
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- egl_terminate(vc->egl.dpy);
- }
-
- vc->egl.ctx = NULL;
- vc->egl.hw_ctx = NULL;
- vc->eglimage_ctx = NULL;
- vc->egl.surf = NULL;
- vc->pbuff_surf = NULL;
- vc->egl.dpy = NULL;
- vc->egl.config = 0;
- g_egl_inited = false;
-
- for (i = 0; i < MAX_EGLIMAGE_TEXTURES; i++)
- {
- vc->eglBuffer[i] = NULL;
- vc->vgimage[i] = 0;
- }
-
- /* Stop generating vsync callbacks if we are doing so.
- * Don't destroy the context while cbs are being generated! */
- if (vc->vsync_callback_set)
- vc_dispmanx_vsync_callback(vc->dispman_display, NULL, NULL);
-
- /* Destroy mutexes and conditions. */
- slock_free(vc->vsync_condition_mutex);
- scond_free(vc->vsync_condition);
-}
-
static void gfx_ctx_vc_input_driver(void *data,
const char *name,
input_driver_t **input, void **input_data)
@@ -487,23 +486,12 @@ static void gfx_ctx_vc_input_driver(void *data,
*input_data = NULL;
}
-static bool gfx_ctx_vc_has_focus(void *data)
-{
- (void)data;
- return g_egl_inited;
-}
-
-static bool gfx_ctx_vc_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static bool gfx_ctx_vc_has_focus(void *data) { return g_egl_inited; }
+static bool gfx_ctx_vc_suppress_screensaver(void *data, bool enable) { return false; }
static float gfx_ctx_vc_translate_aspect(void *data,
unsigned width, unsigned height)
{
- (void)data;
/* Check for SD televisions: they should always be 4:3. */
if ((width == 640 || width == 720) && (height == 480 || height == 576))
return 4.0f / 3.0f;
@@ -526,11 +514,11 @@ static bool gfx_ctx_vc_image_buffer_init(void *data,
if (vc_api == GFX_CTX_OPENVG_API)
return false;
- peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)egl_get_proc_address("eglCreateImageKHR");
- peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)egl_get_proc_address("eglDestroyImageKHR");
+ vc->peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)egl_get_proc_address("eglCreateImageKHR");
+ vc->peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)egl_get_proc_address("eglDestroyImageKHR");
- if ( !peglCreateImageKHR ||
- !peglDestroyImageKHR ||
+ if ( !vc->peglCreateImageKHR ||
+ !vc->peglDestroyImageKHR ||
!gfx_ctx_vc_egl_query_extension(vc, "KHR_image")
)
return false;
@@ -587,8 +575,9 @@ fail:
return false;
}
-static bool gfx_ctx_vc_image_buffer_write(void *data, const void *frame, unsigned width,
- unsigned height, unsigned pitch, bool rgb32, unsigned index, void **image_handle)
+static bool gfx_ctx_vc_image_buffer_write(void *data, const void *frame,
+ unsigned width, unsigned height,
+ unsigned pitch, bool rgb32, unsigned index, void **image_handle)
{
bool ret = false;
vc_ctx_data_t *vc = (vc_ctx_data_t*)data;
@@ -602,12 +591,12 @@ static bool gfx_ctx_vc_image_buffer_write(void *data, const void *frame, unsigne
if (!vc->eglBuffer[index] || !vc->vgimage[index])
{
- vc->vgimage[index] = vgCreateImage(
+ vc->vgimage[index] = vgCreateImage(
rgb32 ? VG_sXRGB_8888 : VG_sRGB_565,
vc->res,
vc->res,
VG_IMAGE_QUALITY_NONANTIALIASED);
- vc->eglBuffer[index] = peglCreateImageKHR(
+ vc->eglBuffer[index] = vc->peglCreateImageKHR(
vc->egl.dpy,
vc->eglimage_ctx,
EGL_VG_PARENT_IMAGE_KHR,
@@ -681,15 +670,6 @@ static void gfx_ctx_vc_bind_hw_render(void *data, bool enable)
#endif
}
-static gfx_ctx_proc_t gfx_ctx_vc_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#else
- return NULL;
-#endif
-}
-
static uint32_t gfx_ctx_vc_get_flags(void *data)
{
uint32_t flags = 0;
@@ -698,10 +678,7 @@ static uint32_t gfx_ctx_vc_get_flags(void *data)
return flags;
}
-static void gfx_ctx_vc_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+static void gfx_ctx_vc_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t gfx_ctx_videocore = {
gfx_ctx_vc_init,
@@ -725,7 +702,11 @@ const gfx_ctx_driver_t gfx_ctx_videocore = {
false, /* has_windowed */
gfx_ctx_vc_swap_buffers,
gfx_ctx_vc_input_driver,
- gfx_ctx_vc_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
gfx_ctx_vc_image_buffer_init,
gfx_ctx_vc_image_buffer_write,
NULL,
diff --git a/gfx/drivers_context/vita_ctx.c b/gfx/drivers_context/vita_ctx.c
index 6cecfeb308..3d95a3c142 100644
--- a/gfx/drivers_context/vita_ctx.c
+++ b/gfx/drivers_context/vita_ctx.c
@@ -18,15 +18,10 @@
#include "../../retroarch.h"
-static void vita_swap_interval(void *data, int interval)
-{
- (void)data;
- vglWaitVblankStart(interval);
-}
+static void vita_swap_interval(void *data, int interval) { vglWaitVblankStart(interval); }
static void vita_get_video_size(void *data, unsigned *width, unsigned *height)
{
- (void)data;
*width = 960;
*height = 544;
}
@@ -50,95 +45,26 @@ static void vita_check_window(void *data, bool *quit,
static void vita_swap_buffers(void *data)
{
- (void)data;
vglStopRendering();
vglStartRendering();
}
static bool vita_set_video_mode(void *data,
unsigned width, unsigned height,
- bool fullscreen)
-{
- (void)data;
- (void)width;
- (void)height;
- (void)fullscreen;
-
- return true;
-}
-
-static void vita_destroy(void *data)
-{
- (void)data;
-}
-
+ bool fullscreen) { return true; }
+static void vita_destroy(void *data) { }
static void vita_input_driver(void *data,
const char *name,
- input_driver_t **input, void **input_data)
-{
- (void)data;
- (void)input;
- (void)input_data;
-}
-
-static bool vita_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool vita_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
-
-static enum gfx_ctx_api vita_get_api(void *data)
-{
- return GFX_CTX_NONE;
-}
-
-static bool vita_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor)
-{
- (void)data;
- (void)api;
- (void)major;
- (void)minor;
-
- return true;
-}
-
-static void vita_show_mouse(void *data, bool state)
-{
- (void)data;
- (void)state;
-}
-
-static void vita_bind_hw_render(void *data, bool enable)
-{
- (void)data;
- (void)enable;
-}
-
-static void *vita_init(void *video_driver)
-{
- (void)video_driver;
-
- return (void*)"vita";
-}
-
-static uint32_t vita_get_flags(void *data)
-{
- uint32_t flags = 0;
-
- return flags;
-}
-
-static void vita_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
+ input_driver_t **input, void **input_data) { }
+static bool vita_has_focus(void *data) { return true; }
+static bool vita_suppress_screensaver(void *data, bool enable) { return false; }
+static enum gfx_ctx_api vita_get_api(void *data) { return GFX_CTX_OPENGL_ES_API; }
+static bool vita_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor) { return true; }
+static void vita_show_mouse(void *data, bool state) { }
+static void vita_bind_hw_render(void *data, bool enable) { }
+static void *vita_init(void *video_driver) { return (void*)"vita"; }
+static uint32_t vita_get_flags(void *data) { return 0; }
+static void vita_set_flags(void *data, uint32_t flags) { }
const gfx_ctx_driver_t vita_ctx = {
vita_init,
diff --git a/gfx/drivers_context/vivante_fbdev_ctx.c b/gfx/drivers_context/vivante_fbdev_ctx.c
index da89fdcf32..16911fa554 100644
--- a/gfx/drivers_context/vivante_fbdev_ctx.c
+++ b/gfx/drivers_context/vivante_fbdev_ctx.c
@@ -43,8 +43,6 @@ typedef struct
unsigned width, height;
} vivante_ctx_data_t;
-static enum gfx_ctx_api viv_api = GFX_CTX_NONE;
-
static void gfx_ctx_vivante_destroy(void *data)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
@@ -188,32 +186,20 @@ static void gfx_ctx_vivante_input_driver(void *data,
static enum gfx_ctx_api gfx_ctx_vivante_get_api(void *data)
{
- return viv_api;
+ return GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_vivante_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
-
- viv_api = api;
-
if (api == GFX_CTX_OPENGL_ES_API)
return true;
return false;
}
-static bool gfx_ctx_vivante_has_focus(void *data)
-{
- (void)data;
- return true;
-}
-
-static bool gfx_ctx_vivante_suppress_screensaver(void *data, bool enable)
-{
- (void)data;
- (void)enable;
- return false;
-}
+static void gfx_ctx_vivante_set_flags(void *data, uint32_t flags) { }
+static bool gfx_ctx_vivante_has_focus(void *data) { return true; }
+static bool gfx_ctx_vivante_suppress_screensaver(void *data, bool enable) { return false; }
static void gfx_ctx_vivante_set_swap_interval(void *data, int swap_interval)
{
@@ -233,15 +219,6 @@ static void gfx_ctx_vivante_swap_buffers(void *data)
#endif
}
-static gfx_ctx_proc_t gfx_ctx_vivante_get_proc_address(const char *symbol)
-{
-#ifdef HAVE_EGL
- return egl_get_proc_address(symbol);
-#else
- return NULL;
-#endif
-}
-
static void gfx_ctx_vivante_bind_hw_render(void *data, bool enable)
{
vivante_ctx_data_t *viv = (vivante_ctx_data_t*)data;
@@ -260,11 +237,6 @@ static uint32_t gfx_ctx_vivante_get_flags(void *data)
return flags;
}
-static void gfx_ctx_vivante_set_flags(void *data, uint32_t flags)
-{
- (void)data;
-}
-
const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
gfx_ctx_vivante_init,
gfx_ctx_vivante_destroy,
@@ -287,7 +259,11 @@ const gfx_ctx_driver_t gfx_ctx_vivante_fbdev = {
false, /* has_windowed */
gfx_ctx_vivante_swap_buffers,
gfx_ctx_vivante_input_driver,
- gfx_ctx_vivante_get_proc_address,
+#ifdef HAVE_EGL
+ egl_get_proc_address,
+#else
+ NULL,
+#endif
NULL,
NULL,
NULL,
diff --git a/gfx/drivers_context/w_vk_ctx.c b/gfx/drivers_context/w_vk_ctx.c
new file mode 100644
index 0000000000..ea0901701a
--- /dev/null
+++ b/gfx/drivers_context/w_vk_ctx.c
@@ -0,0 +1,343 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2017 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include
+
+/* Win32/WGL context. */
+
+/* necessary for mingw32 multimon defines: */
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K
+#endif
+
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+
+#include
+#include