mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-26 19:11:00 +00:00
[loader] atmosphere zbic + code tweaks (#4483)
- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- just some adjustments for #4482 as instructed by lizzie. -replace static zstd content with atmosphere's repo version; -replace void pointer types with spans -remove unused overload Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4483
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
"repo": "lioncash/biscuit",
|
||||
"version": "v0.19.0"
|
||||
},
|
||||
"atmosphere_zstd_bic": {
|
||||
"hash": "204f7573ea40de2878759c7ff5b2c016111fc29ae8574df50a3a0db9018c3b012f9040ea7466559130424d4335f2dfd6d7abfdc4d4d67e8a34531b8284f0cc6a",
|
||||
"repo": "Atmosphere-NX/Atmosphere",
|
||||
"version": "3ace80cc7b87e1837fccca1522801bbf6fddc6aa"
|
||||
},
|
||||
"boost": {
|
||||
"artifact": "boost-%VERSION%.tar.zst",
|
||||
"find_args": "CONFIG OPTIONAL_COMPONENTS headers context system fiber filesystem",
|
||||
|
||||
Vendored
+5
@@ -48,6 +48,11 @@ if (NOT TARGET stb::headers)
|
||||
add_library(stb::headers ALIAS stb)
|
||||
endif()
|
||||
|
||||
AddJsonPackage(NAME atmosphere_zstd_bic DOWNLOAD_ONLY)
|
||||
set(ATMOSPHERE_ZSTD_BIC_INCLUDE_DIR
|
||||
"${atmosphere_zstd_bic_SOURCE_DIR}/libraries/libstratosphere/source/util"
|
||||
PARENT_SCOPE)
|
||||
|
||||
# ItaniumDemangle (Windows only)
|
||||
if (WIN32 AND NOT TARGET LLVM::Demangle)
|
||||
add_library(demangle demangle/ItaniumDemangle.cpp)
|
||||
|
||||
@@ -139,9 +139,6 @@ add_library(
|
||||
vector_math.h
|
||||
zbic_compression.cpp
|
||||
zbic_compression.h
|
||||
zstd.c
|
||||
zstd.h
|
||||
zstd_errors.h
|
||||
zstd_compression.cpp
|
||||
zstd_compression.h
|
||||
fs/ryujinx_compat.h fs/ryujinx_compat.cpp
|
||||
@@ -152,6 +149,10 @@ add_library(
|
||||
net/net.h net/net.cpp
|
||||
container/unordered_map.h container/unordered_set.h)
|
||||
|
||||
set_source_files_properties(zbic_compression.cpp PROPERTIES
|
||||
INCLUDE_DIRECTORIES "${ATMOSPHERE_ZSTD_BIC_INCLUDE_DIR}"
|
||||
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:Clang,GNU>:-Wno-unused-function>")
|
||||
|
||||
if(WIN32)
|
||||
target_sources(common PRIVATE windows/timer_resolution.cpp
|
||||
windows/timer_resolution.h)
|
||||
@@ -246,7 +247,6 @@ endif()
|
||||
|
||||
target_link_libraries(common PUBLIC fmt::fmt stb::headers Threads::Threads)
|
||||
target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd)
|
||||
target_compile_definitions(common PRIVATE ZSTD_ZBIC_SUPPORT=1)
|
||||
|
||||
# Please refer to src/common/demangle.cpp
|
||||
if (WIN32)
|
||||
|
||||
@@ -4,40 +4,37 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "common/zbic_compression.h"
|
||||
#include "common/zstd.h"
|
||||
|
||||
#define ZSTD_ZBIC_SUPPORT 1
|
||||
#define ZSTDLIB_VISIBLE static
|
||||
#define ZSTDLIB_HIDDEN static
|
||||
#define ZSTDERRORLIB_VISIBLE static
|
||||
#define ZSTDERRORLIB_HIDDEN static
|
||||
#undef ZSTD_MULTITHREAD
|
||||
|
||||
#include "zstd.h"
|
||||
#include "zstd.inc"
|
||||
|
||||
namespace Common::Compression {
|
||||
|
||||
bool IsZBIC(const void* src, size_t src_size) {
|
||||
if (!src || src_size < 4) {
|
||||
bool IsZBIC(std::span<const u8> src) {
|
||||
if (src.size() < sizeof(u32)) {
|
||||
return false;
|
||||
}
|
||||
u32 magic = 0;
|
||||
std::memcpy(&magic, src, sizeof(u32));
|
||||
std::memcpy(&magic, src.data(), sizeof(u32));
|
||||
return magic == ZSTD_MAGICNUMBER; // 0x4349425A ("ZBIC")
|
||||
}
|
||||
|
||||
int DecompressDataZBIC(void* dst, size_t dst_size, const void* src, size_t src_size) {
|
||||
if (!dst || !src || dst_size == 0 || src_size == 0) {
|
||||
int DecompressDataZBIC(std::span<u8> dst, std::span<const u8> src) {
|
||||
if (dst.empty() || src.empty()) {
|
||||
return -1;
|
||||
}
|
||||
const size_t res = ZSTD_decompress(dst, dst_size, src, src_size);
|
||||
const size_t res = ZSTD_decompress(dst.data(), dst.size(), src.data(), src.size());
|
||||
if (ZSTD_isError(res)) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<int>(res);
|
||||
}
|
||||
|
||||
std::vector<u8> DecompressDataZBIC(std::span<const u8> compressed, std::size_t uncompressed_size) {
|
||||
std::vector<u8> uncompressed(uncompressed_size);
|
||||
const int r = DecompressDataZBIC(uncompressed.data(), uncompressed_size, compressed.data(), compressed.size());
|
||||
if (r <= 0) {
|
||||
return {};
|
||||
}
|
||||
if (static_cast<size_t>(r) < uncompressed_size) {
|
||||
uncompressed.resize(static_cast<size_t>(r));
|
||||
}
|
||||
return uncompressed;
|
||||
}
|
||||
|
||||
} // namespace Common::Compression
|
||||
|
||||
@@ -4,15 +4,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Common::Compression {
|
||||
|
||||
[[nodiscard]] bool IsZBIC(const void* src, size_t src_size);
|
||||
[[nodiscard]] bool IsZBIC(std::span<const u8> src);
|
||||
|
||||
[[nodiscard]] std::vector<u8> DecompressDataZBIC(std::span<const u8> compressed, std::size_t uncompressed_size);
|
||||
|
||||
[[nodiscard]] int DecompressDataZBIC(void* dst, size_t dst_size, const void* src, size_t src_size);
|
||||
[[nodiscard]] int DecompressDataZBIC(std::span<u8> dst, std::span<const u8> src);
|
||||
|
||||
} // namespace Common::Compression
|
||||
|
||||
-52650
File diff suppressed because it is too large
Load Diff
-3209
File diff suppressed because it is too large
Load Diff
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under both the BSD-style license (found in the
|
||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||
* in the COPYING file in the root directory of this source tree).
|
||||
* You may select, at your option, one of the above-listed licenses.
|
||||
*/
|
||||
|
||||
#ifndef ZSTD_ERRORS_H_398273423
|
||||
#define ZSTD_ERRORS_H_398273423
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
|
||||
#ifndef ZSTDERRORLIB_VISIBLE
|
||||
/* Backwards compatibility with old macro name */
|
||||
# ifdef ZSTDERRORLIB_VISIBILITY
|
||||
# define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
|
||||
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||
# define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
|
||||
# else
|
||||
# define ZSTDERRORLIB_VISIBLE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZSTDERRORLIB_HIDDEN
|
||||
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
||||
# else
|
||||
# define ZSTDERRORLIB_HIDDEN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
||||
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
|
||||
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
||||
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||
#else
|
||||
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
|
||||
#endif
|
||||
|
||||
/*-*********************************************
|
||||
* Error codes list
|
||||
*-*********************************************
|
||||
* Error codes _values_ are pinned down since v1.3.1 only.
|
||||
* Therefore, don't rely on values if you may link to any version < v1.3.1.
|
||||
*
|
||||
* Only values < 100 are considered stable.
|
||||
*
|
||||
* note 1 : this API shall be used with static linking only.
|
||||
* dynamic linking is not yet officially supported.
|
||||
* note 2 : Prefer relying on the enum than on its value whenever possible
|
||||
* This is the only supported way to use the error list < v1.3.1
|
||||
* note 3 : ZSTD_isError() is always correct, whatever the library version.
|
||||
**********************************************/
|
||||
typedef enum {
|
||||
ZSTD_error_no_error = 0,
|
||||
ZSTD_error_GENERIC = 1,
|
||||
ZSTD_error_prefix_unknown = 10,
|
||||
ZSTD_error_version_unsupported = 12,
|
||||
ZSTD_error_frameParameter_unsupported = 14,
|
||||
ZSTD_error_frameParameter_windowTooLarge = 16,
|
||||
ZSTD_error_corruption_detected = 20,
|
||||
ZSTD_error_checksum_wrong = 22,
|
||||
ZSTD_error_literals_headerWrong = 24,
|
||||
ZSTD_error_dictionary_corrupted = 30,
|
||||
ZSTD_error_dictionary_wrong = 32,
|
||||
ZSTD_error_dictionaryCreation_failed = 34,
|
||||
ZSTD_error_parameter_unsupported = 40,
|
||||
ZSTD_error_parameter_combination_unsupported = 41,
|
||||
ZSTD_error_parameter_outOfBound = 42,
|
||||
ZSTD_error_tableLog_tooLarge = 44,
|
||||
ZSTD_error_maxSymbolValue_tooLarge = 46,
|
||||
ZSTD_error_maxSymbolValue_tooSmall = 48,
|
||||
ZSTD_error_cannotProduce_uncompressedBlock = 49,
|
||||
ZSTD_error_stabilityCondition_notRespected = 50,
|
||||
ZSTD_error_stage_wrong = 60,
|
||||
ZSTD_error_init_missing = 62,
|
||||
ZSTD_error_memory_allocation = 64,
|
||||
ZSTD_error_workSpace_tooSmall= 66,
|
||||
ZSTD_error_dstSize_tooSmall = 70,
|
||||
ZSTD_error_srcSize_wrong = 72,
|
||||
ZSTD_error_dstBuffer_null = 74,
|
||||
ZSTD_error_noForwardProgress_destFull = 80,
|
||||
ZSTD_error_noForwardProgress_inputEmpty = 82,
|
||||
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
||||
ZSTD_error_frameIndex_tooLarge = 100,
|
||||
ZSTD_error_seekableIO = 102,
|
||||
ZSTD_error_dstBuffer_wrong = 104,
|
||||
ZSTD_error_srcBuffer_wrong = 105,
|
||||
ZSTD_error_sequenceProducer_failed = 106,
|
||||
ZSTD_error_externalSequences_invalid = 107,
|
||||
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
||||
} ZSTD_ErrorCode;
|
||||
|
||||
ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZSTD_ERRORS_H_398273423 */
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
@@ -108,10 +109,8 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core::
|
||||
if (nso_header.IsZBICCompressed()) {
|
||||
// ZBIC compression
|
||||
const int r = Common::Compression::DecompressDataZBIC(
|
||||
decompressed_size.data(),
|
||||
nso_header.segments[i].size,
|
||||
compressed_data.data(),
|
||||
nso_header.segments_compressed_size[i]
|
||||
std::span<u8>{decompressed_size}.first(nso_header.segments[i].size),
|
||||
std::span<const u8>{compressed_data}.first(nso_header.segments_compressed_size[i])
|
||||
);
|
||||
ASSERT(r > 0);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user