ro: reduce memory usage by excising (unused) std::malloc

This commit is contained in:
Michael Scire 2021-01-17 22:23:19 -08:00 committed by SciresM
parent 170034aed3
commit 5191f0e305
6 changed files with 47 additions and 7 deletions

View file

@ -122,6 +122,8 @@ $(OFILES) : $(GCH_FILES)
$(OFILES_SRC) : $(HFILES_BIN) $(OFILES_SRC) : $(HFILES_BIN)
ams_environment_weak.o: CXXFLAGS += -fno-lto
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%_bin.h %.bin.o : %.bin %_bin.h %.bin.o : %.bin
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View file

@ -26,4 +26,7 @@ namespace ams {
void InitializeForBoot(); void InitializeForBoot();
void SetInitialRebootPayload(const void *src, size_t src_size); void SetInitialRebootPayload(const void *src, size_t src_size);
void *Malloc(size_t size);
void Free(void *ptr);
} }

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
namespace ams {
WEAK_SYMBOL void *Malloc(size_t size) {
return std::malloc(size);
}
WEAK_SYMBOL void Free(void *ptr) {
return std::free(ptr);
}
}

View file

@ -23,16 +23,16 @@ namespace ams::fs {
void *DefaultAllocate(size_t size) { void *DefaultAllocate(size_t size) {
g_used_default_allocator = true; g_used_default_allocator = true;
return std::malloc(size); return ams::Malloc(size);
} }
void DefaultDeallocate(void *ptr, size_t size) { void DefaultDeallocate(void *ptr, size_t size) {
std::free(ptr); ams::Free(ptr);
} }
os::Mutex g_lock(false); constinit os::SdkMutex g_lock;
AllocateFunction g_allocate_func = DefaultAllocate; constinit AllocateFunction g_allocate_func = DefaultAllocate;
DeallocateFunction g_deallocate_func = DefaultDeallocate; constinit DeallocateFunction g_deallocate_func = DefaultDeallocate;
constexpr size_t RequiredAlignment = alignof(u64); constexpr size_t RequiredAlignment = alignof(u64);

View file

@ -37,7 +37,7 @@ namespace ams::os::impl {
return ResultSuccess(); return ResultSuccess();
} }
Result ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) { Result WaitableManagerHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) {
/* NOTE: Nintendo does not initialize this value, which seems like it can cause incorrect behavior. */ /* NOTE: Nintendo does not initialize this value, which seems like it can cause incorrect behavior. */
s32 index = WaitableManagerImpl::WaitInvalid; s32 index = WaitableManagerImpl::WaitInvalid;
static_assert(WaitableManagerImpl::WaitInvalid != -1); static_assert(WaitableManagerImpl::WaitInvalid != -1);

View file

@ -170,8 +170,15 @@ void __appExit(void) {
setsysExit(); setsysExit();
} }
namespace { namespace ams {
void *Malloc(size_t size) {
AMS_ABORT("ams::Malloc was called");
}
void Free(void *ptr) {
AMS_ABORT("ams::Free was called");
}
} }