Merge pull request #6213 from milescoviello/fix/libc-getifaddrs-guest-heap

fix(libc): allocate the getifaddrs list on the application heap
This commit is contained in:
Dean authored and GitHub committed 2026-10-18 09:47:10 +13:00
commit 430f99a999
2 files changed
+11 -3

No files matched your search

+3 -3
View File
@@ -9,10 +9,10 @@
#include <netinet/in.h>
#include <cerrno>
#endif
#include "prx/libc/include/ApplicationHeap.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <new>
#include <stdexcept>
@@ -213,7 +213,7 @@ int APS5_VABI getifaddrs_nid_postfix(GuestInterfaceAddress** list) {
std::size_t size = entries.size() * sizeof(GuestInterfaceAddress);
for (const auto& entry : entries)
size += Aligned(entry.name.size() + 1) + Aligned(entry.address.size()) + Aligned(entry.netmask.size()) + Aligned(entry.destination.size());
auto* block = static_cast<std::uint8_t*>(std::malloc(size));
auto* block = static_cast<std::uint8_t*>(ApplicationHeapAllocate_nid_no_patch(size));
if (!block) {
*__error_nid_postfix() = 12;
return -1;
@@ -243,7 +243,7 @@ int APS5_VABI getifaddrs_nid_postfix(GuestInterfaceAddress** list) {
}
void APS5_VABI freeifaddrs_nid_postfix(GuestInterfaceAddress* list) {
std::free(list);
ApplicationHeapFree_nid_no_patch(list);
}
}
+8
View File
@@ -7,7 +7,9 @@
#include <ifaddrs.h>
#include <netinet/in.h>
#endif
#include "prx/libc/include/ApplicationHeap.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
@@ -33,6 +35,7 @@ static_assert(offsetof(GuestInterfaceAddress, data) == 48);
extern "C" {
int APS5_VABI getifaddrs_nid_postfix(GuestInterfaceAddress** list);
void APS5_VABI freeifaddrs_nid_postfix(GuestInterfaceAddress* list);
void APS5_VABI free_nid_postfix(void* pointer);
int* APS5_VABI __error_nid_postfix();
}
@@ -106,6 +109,8 @@ static std::vector<HostInterfaceAddress> HostSnapshot() {
}
int main() {
std::array<void*, 10> api{};
ApplicationHeapRegister_nid_no_patch(api.data());
constexpr std::uint32_t knownFlags = 0x1 | 0x2 | 0x8 | 0x10 | 0x40 | 0x80 | 0x100 | 0x200 | 0x8000;
const std::uint8_t loopbackAddress[] = {127, 0, 0, 1};
const std::uint8_t loopbackMask[] = {255, 0, 0, 0};
@@ -167,6 +172,9 @@ int main() {
freeifaddrs_nid_postfix(list);
}
Require(matched);
GuestInterfaceAddress* released = nullptr;
Require(getifaddrs_nid_postfix(&released) == 0 && released != nullptr);
free_nid_postfix(released);
freeifaddrs_nid_postfix(nullptr);
*__error_nid_postfix() = 0;
Require(getifaddrs_nid_postfix(nullptr) == -1);