mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-13 00:26:35 +00:00
os: implement ExpandUnsignedValueToAscii
Nintendo does this as of latest firmware. It's desirable because it removes the only usage of util::SNPrintf() from os library, which means programs which don't otherwise use SNPrintf do not need to link it into .text. This saves ~0xD40 of .text as of time-of-commit when successfully unlinking, and e.g. reduces our sm (and other modules) memory size by a page.
This commit is contained in:
parent
1e7a327a25
commit
15ff64e03a
3 changed files with 69 additions and 1 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "os_waitable_holder_base.hpp"
|
||||
#include "os_waitable_holder_impl.hpp"
|
||||
#include "os_waitable_object_list.hpp"
|
||||
#include "os_utility.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
|
@ -223,7 +224,8 @@ namespace ams::os::impl {
|
|||
constexpr size_t ThreadNamePrefixSize = sizeof(ThreadNamePrefix) - 1;
|
||||
const u64 func = reinterpret_cast<u64>(thread->function);
|
||||
static_assert(ThreadNamePrefixSize + sizeof(func) * 2 + 1 <= sizeof(thread->name_buffer));
|
||||
util::SNPrintf(thread->name_buffer, sizeof(thread->name_buffer), "%s%016lX", ThreadNamePrefix, func);
|
||||
std::memcpy(thread->name_buffer, ThreadNamePrefix, ThreadNamePrefixSize);
|
||||
os::impl::ExpandUnsignedValueToAscii(thread->name_buffer + ThreadNamePrefixSize, func);
|
||||
}
|
||||
|
||||
thread->name_pointer = thread->name_buffer;
|
||||
|
|
42
libraries/libstratosphere/source/os/impl/os_utility.cpp
Normal file
42
libraries/libstratosphere/source/os/impl/os_utility.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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>
|
||||
#include "os_utility.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
void ExpandUnsignedValueToAscii(char *dst, u64 value) {
|
||||
/* Determine size needed. */
|
||||
constexpr size_t SizeNeeded = (BITSIZEOF(value) / 4) * sizeof(char);
|
||||
|
||||
/* Write null-terminator. */
|
||||
dst[SizeNeeded] = '\x00';
|
||||
|
||||
/* Write characters. */
|
||||
for (size_t i = 0; i < SizeNeeded; ++i) {
|
||||
/* Determine current character. */
|
||||
const auto nybble = (value & 0xF);
|
||||
const char cur_c = (nybble < 10) ? ('0' + nybble) : ('A' + nybble - 10);
|
||||
|
||||
/* Write current character. */
|
||||
dst[SizeNeeded - 1 - i] = cur_c;
|
||||
|
||||
/* Shift to next nybble. */
|
||||
value >>= 4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
24
libraries/libstratosphere/source/os/impl/os_utility.hpp
Normal file
24
libraries/libstratosphere/source/os/impl/os_utility.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include "os_waitable_holder_base.hpp"
|
||||
#include "os_waitable_manager_impl.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
void ExpandUnsignedValueToAscii(char *dst, u64 value);
|
||||
|
||||
}
|
Loading…
Reference in a new issue