Previously the constructor for all of these would run at program
startup, consuming time before the application can enter main().
This is also particularly dangerous, given the logging system wouldn't
have been initialized properly yet, yet the program would use the logs
to signify an error.
To rectify this, we can replace the literals with constexpr functions
that perform the conversion at compile-time, completely eliminating the
runtime cost of initializing these arrays.
- In `SetCurrentThreadName`, when on Linux, truncate to 15 bytes, as (at
least on glibc) `pthread_set_name_np` will otherwise return `ERANGE` and
do nothing.
- Also, add logging in case `pthread_set_name_np` returns an error
anyway. This is Linux-specific, as the Apple and BSD versions of
`pthread_set_name_np return `void`.
- Change the name for CPU threads in multi-core mode from
"yuzu:CoreCPUThread_N" (19 bytes) to "yuzu:CPUCore_N" (14 bytes) so it
fits into the Linux limit. Some other thread names are also cut off,
but I didn't bother addressing them as you can guess them from the
truncated versions. For a CPU thread, truncation means you can't see
which core it is!
We can add a helper function to make creation of these files nicer.
While we're at it, we can eliminate an unnecessary std::array copy in
the constructor. This makes the overhead on some of these functions way
less intensive, given some arrays were quite large.
e.g. The timezone location names are 9633 bytes in size.
In a few places, the data to be set as the IV is already within an array.
We shouldn't require this data to be heap-allocated if it doesn't need
to be. This allows certain callers to reduce heap churn.
The general pattern is to mark mutexes as mutable when it comes to
matters of constness, given the mutex acts as a transient member of a
data structure.
* ipc: Allow all trivially copyable objects to be passed directly into WriteBuffer
With the support of C++20, we can use concepts to deduce if a type is an STL container or not.
* More agressive concept for stl containers
* Add -fconcepts
* Move to common namespace
* Add Common::IsBaseOf
This implements: Socket, Poll, Accept, Bind, Connect, GetPeerName,
GetSockName, Listen, Fcntl, SetSockOpt, Shutdown, Recv, RecvFrom,
Send, SendTo, Write, and Close
The implementation was done referencing: SwIPC, switchbrew, testing
with libnx and inspecting its code, general information about bsd
sockets online, and analysing official software.
Not everything from these service calls is implemented, but everything
that is not implemented will be logged in some way.
This abstraction allows executing blocking functions (like recvfrom on a
socket configured for blocking) without blocking the service thread.
It is intended to be used with SleepClientThread.
Makes the interface future-proofed for supporting other platforms in the event we ever support platforms with differing pointer sizes. This way, we have a type in place that is always guaranteed to be able to represent a pointer exactly.
Not using the return value of these functions are undeniably the source
of a bug. This way we allow compilers to loudly make any future misuses
evident.
src/core/network/network.cpp:112:28: error: use of undeclared identifier 'SHUT_RD'
constexpr int SD_RECEIVE = SHUT_RD;
^
src/core/network/network.cpp:113:25: error: use of undeclared identifier 'SHUT_WR'
constexpr int SD_SEND = SHUT_WR;
^
src/core/network/network.cpp:114:25: error: use of undeclared identifier 'SHUT_RDWR'
constexpr int SD_BOTH = SHUT_RDWR;
^
src/core/network/network.cpp:120:37: error: unknown type name 'in_addr'; did you mean 'in_addr_t'?
constexpr IPv4Address TranslateIPv4(in_addr addr) {
^~~~~~~
in_addr_t
/usr/include/netdb.h:66:20: note: 'in_addr_t' declared here
typedef __uint32_t in_addr_t;
^
src/core/network/network.cpp:121:27: error: member reference base type 'in_addr_t' (aka 'unsigned int') is not a structure or union
const u32 bytes = addr.s_addr;
~~~~^~~~~~~
src/core/network/network.cpp:121:15: error: variables defined in a constexpr function must be initialized
const u32 bytes = addr.s_addr;
^
src/core/network/network.cpp:126:10: error: incomplete result type 'sockaddr' in function definition
sockaddr TranslateFromSockAddrIn(SockAddrIn input) {
^
/usr/include/netdb.h:142:9: note: forward declaration of 'sockaddr'
struct sockaddr *ai_addr; /* binary address */
^
src/core/network/network.cpp:127:5: error: unknown type name 'sockaddr_in'; did you mean 'sockaddr'?
sockaddr_in result;
^~~~~~~~~~~
sockaddr
/usr/include/netdb.h:142:9: note: 'sockaddr' declared here
struct sockaddr *ai_addr; /* binary address */
^
src/core/network/network.cpp:127:17: error: variable has incomplete type 'sockaddr'
sockaddr_in result;
^
/usr/include/netdb.h:142:9: note: forward declaration of 'sockaddr'
struct sockaddr *ai_addr; /* binary address */
^
src/core/network/network.cpp:131:29: error: use of undeclared identifier 'AF_INET'
result.sin_family = AF_INET;
^
src/core/network/network.cpp:135:29: error: use of undeclared identifier 'AF_INET'
result.sin_family = AF_INET;
^
src/core/network/network.cpp:139:23: error: use of undeclared identifier 'htons'
result.sin_port = htons(input.portno);
^
src/core/network/network.cpp:143:14: error: variable has incomplete type 'sockaddr'
sockaddr addr;
^
/usr/include/netdb.h:142:9: note: forward declaration of 'sockaddr'
struct sockaddr *ai_addr; /* binary address */
^
src/core/network/network.cpp:156:1: error: unknown type name 'linger'
linger MakeLinger(bool enable, u32 linger_value) {
^
src/core/network/network.cpp:157:5: error: unknown type name 'linger'
linger value;
^
src/core/network/network.cpp:185:16: error: use of undeclared identifier 'AF_INET'
return AF_INET;
^
src/core/network/network.cpp:195:16: error: use of undeclared identifier 'SOCK_STREAM'
return SOCK_STREAM;
^
src/core/network/network.cpp:197:16: error: use of undeclared identifier 'SOCK_DGRAM'
return SOCK_DGRAM;
^
src/core/network/network.cpp:207:16: error: use of undeclared identifier 'IPPROTO_TCP'
return IPPROTO_TCP;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
This commit adds a network abstraction designed to implement bsd:s but
at the same time work as a generic abstraction to implement any
networking code we have to use from core.
This is implemented on top of BSD sockets on Unix systems and winsock on
Windows. The code is designed around winsocks having compatibility
definitions to support both BSD and Windows sockets.
If subdirectories exist in the given path parameter and don't exist in the real filesystem create them prior to creating the files within.
This fixes the softlocks upon save creation in The Legend of Zelda: Breath of the Wild
These aren't directly important or commonly used within the process, so
we can move these to the bottom to allow everything else to be more
likely to be within a cache line.
In all usages of LogSetting(), string literals are provided.
std::string_view is better suited here, as we won't churn a bunch of
string allocations every time the settings are logged out.
While we're at it, we can fold LogSetting() into LogSettings(), given
it's only ever used there.
- This checks for and removes old updates or dlc based on title id. If a content meta nca exists within the registered cache, it will attempt to remove all the ncas associated with the content meta before installing a new update/dlc
Profiling shows that this is a highly contested mutex, causing dimishing
results compared to a OS lock. std::mutex implementations can spin for a
while before falling back to an OS lock.
This avoids wasting precious CPU cycles in a no-op.
When zero byte files are present, the key (offset) for that file is identical to the file right after. A std::map isn't able to fit key-value pairs with identical keys (offsets), therefore, the solution is to use std::multimap which permits multiple entries with the same key.
This most prominently fixes Pokemon Sword and Shield weather with any RomFS mod applied.
The file wasn't closed prior to being renamed / moved, throwing an error that states "The process cannot access the file because it is being used by another process." Fix this by closing the file prior to a rename / move operation.
Fixes saving in Luigi's Mansion 3 and KATANA KAMI: A Way of the Samurai Story.
We should not be limited by the SDMC's partition size, set this to 1 TiB. Hardware is limited to the max allowed by the MBR partition table which is 2 TiB.
Sets the total space of user and system partitions to their hardware defaults.
Furthermore, return the total space as free space for the user partition to prevent it from reaching zero.
Some games like Bioshock 2 check for the available free space prior to save creation, and we should not be limited by arbitrary limits.