mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-06 14:48:17 +01:00
Merge pull request #46 from dimok789/master
Link fixes for C++ applications and some additional enums and function declarations
This commit is contained in:
commit
48d2fcc314
15
crt/memory.c
15
crt/memory.c
@ -1,6 +1,7 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <coreinit/baseheap.h>
|
||||
#include <coreinit/memheap.h>
|
||||
#include <coreinit/expandedheap.h>
|
||||
|
||||
void *
|
||||
@ -30,31 +31,31 @@ __wrap_realloc(void *ptr, size_t size) {
|
||||
if (!ptr) {
|
||||
return __wrap_malloc(size);
|
||||
}
|
||||
|
||||
|
||||
if (__wrap_malloc_usable_size(ptr) >= size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
void *realloc_ptr = __wrap_malloc(size);
|
||||
|
||||
|
||||
if(!realloc_ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr));
|
||||
__wrap_free(ptr);
|
||||
|
||||
|
||||
return realloc_ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
__wrap_calloc(size_t num, size_t size) {
|
||||
void *ptr = __wrap_malloc(num*size);
|
||||
|
||||
|
||||
if(ptr) {
|
||||
memset(ptr, 0, num*size);
|
||||
}
|
||||
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
14
include/coreinit/title.h
Normal file
14
include/coreinit/title.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <wut.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
u64 OSGetTitleID(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
@ -14,6 +14,8 @@ extern "C" {
|
||||
typedef enum GX2AAMode
|
||||
{
|
||||
GX2_AA_MODE1X = 0,
|
||||
GX2_AA_MODE2X = 1,
|
||||
GX2_AA_MODE4X = 2
|
||||
} GX2AAMode;
|
||||
|
||||
typedef enum GX2AlphaToMaskMode
|
||||
@ -117,6 +119,7 @@ typedef enum GX2ClearFlags
|
||||
{
|
||||
GX2_CLEAR_FLAGS_DEPTH = 1,
|
||||
GX2_CLEAR_FLAGS_STENCIL = 2,
|
||||
GX2_CLEAR_FLAGS_BOTH = (GX2_CLEAR_FLAGS_DEPTH | GX2_CLEAR_FLAGS_STENCIL),
|
||||
} GX2ClearFlags;
|
||||
|
||||
typedef enum GX2CompareFunction
|
||||
@ -185,6 +188,9 @@ typedef enum GX2InvalidateMode
|
||||
GX2_INVALIDATE_MODE_CPU = 1 << 6,
|
||||
GX2_INVALIDATE_MODE_STREAM_OUT_BUFFER = 1 << 7,
|
||||
GX2_INVALIDATE_MODE_EXPORT_BUFFER = 1 << 8,
|
||||
GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER= GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_ATTRIBUTE_BUFFER,
|
||||
GX2_INVALIDATE_MODE_CPU_TEXTURE = GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_TEXTURE,
|
||||
GX2_INVALIDATE_MODE_CPU_SHADER = GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_SHADER,
|
||||
} GX2InvalidateMode;
|
||||
|
||||
typedef enum GX2InitAttributes
|
||||
@ -218,7 +224,10 @@ typedef enum GX2LogicOp
|
||||
|
||||
typedef enum GX2PrimitiveMode
|
||||
{
|
||||
GX2_PRIMITIVE_MODE_LINES = 2,
|
||||
GX2_PRIMITIVE_MODE_LINE_STRIP = 3,
|
||||
GX2_PRIMITIVE_MODE_TRIANGLES = 4,
|
||||
GX2_PRIMITIVE_MODE_TRIANGLE_FAN = 5,
|
||||
GX2_PRIMITIVE_MODE_TRIANGLE_STRIP = 6,
|
||||
GX2_PRIMITIVE_MODE_QUADS = 19,
|
||||
GX2_PRIMITIVE_MODE_QUAD_STRIP = 20,
|
||||
@ -384,10 +393,12 @@ typedef enum
|
||||
|
||||
typedef enum GX2SurfaceUse
|
||||
{
|
||||
GX2_SURFACE_USE_TEXTURE = 1 << 0,
|
||||
GX2_SURFACE_USE_COLOR_BUFFER = 1 << 1,
|
||||
GX2_SURFACE_USE_DEPTH_BUFFER = 1 << 2,
|
||||
GX2_SURFACE_USE_SCAN_BUFFER = 1 << 3,
|
||||
GX2_SURFACE_USE_TEXTURE = 1 << 0,
|
||||
GX2_SURFACE_USE_COLOR_BUFFER = 1 << 1,
|
||||
GX2_SURFACE_USE_DEPTH_BUFFER = 1 << 2,
|
||||
GX2_SURFACE_USE_SCAN_BUFFER = 1 << 3,
|
||||
GX2_SURFACE_USE_TV = 1 << 31,
|
||||
GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV = (GX2_SURFACE_USE_TEXTURE | GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_TV)
|
||||
} GX2SurfaceUse;
|
||||
|
||||
typedef enum GX2TessellationMode
|
||||
@ -428,8 +439,8 @@ typedef enum GX2TexMipPerfMode
|
||||
|
||||
typedef enum GX2TexXYFilterMode
|
||||
{
|
||||
GX2_TEX_XY_FILLTER_MODE_POINT = 0,
|
||||
GX2_TEX_XY_FILLTER_MODE_LINEAR = 1,
|
||||
GX2_TEX_XY_FILTER_MODE_POINT = 0,
|
||||
GX2_TEX_XY_FILTER_MODE_LINEAR = 1,
|
||||
} GX2TexXYFilterMode;
|
||||
|
||||
typedef enum GX2TexAnisoRatio
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#define SOL_SOCKET 0xFFFF
|
||||
|
||||
#define INADDR_ANY 0
|
||||
|
||||
#define PF_UNSPEC 0
|
||||
#define PF_INET 2
|
||||
#define PF_INET6 23
|
||||
@ -35,6 +37,10 @@
|
||||
#define SHUT_WR 1
|
||||
#define SHUT_RDWR 2
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
/*
|
||||
* SOL_SOCKET options
|
||||
*/
|
||||
@ -69,6 +75,16 @@ struct linger
|
||||
int l_linger;
|
||||
};
|
||||
|
||||
struct in_addr {
|
||||
unsigned int s_addr;
|
||||
};
|
||||
struct sockaddr_in {
|
||||
short sin_family;
|
||||
unsigned short sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -87,7 +103,7 @@ bind(int sockfd,
|
||||
socklen_t addrlen);
|
||||
|
||||
int
|
||||
closesocket(int sockfd);
|
||||
socketclose(int sockfd);
|
||||
|
||||
int
|
||||
connect(int sockfd,
|
||||
@ -166,6 +182,12 @@ select(int nfds,
|
||||
fd_set *exceptfds,
|
||||
struct timeval *timeout);
|
||||
|
||||
char *
|
||||
inet_ntoa(struct in_addr in);
|
||||
|
||||
int
|
||||
inet_aton(const char *cp, struct in_addr *inp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -54,6 +54,9 @@ CHECK_SIZE(AXInitParams, 0x0C);
|
||||
void
|
||||
AXInit();
|
||||
|
||||
void
|
||||
AXQuit();
|
||||
|
||||
void
|
||||
AXInitWithParams(AXInitParams *params);
|
||||
|
||||
|
@ -368,5 +368,8 @@ EXPORT(MEMFreeToUnitHeap);
|
||||
EXPORT(MEMCountFreeBlockForUnitHeap);
|
||||
EXPORT(MEMCalcHeapSizeForUnitHeap);
|
||||
|
||||
// coreinit/title.h
|
||||
EXPORT(OSGetTitleID);
|
||||
|
||||
// coreinit/internal.h
|
||||
EXPORT(__os_snprintf);
|
||||
|
@ -17,23 +17,27 @@ EXPORT(sendto_multi);
|
||||
EXPORT(sendto_multi_ex);
|
||||
EXPORT(shutdown);
|
||||
EXPORT(inet_aton);
|
||||
EXPORT(inet_ntoa);
|
||||
EXPORT(inet_ntoa_r);
|
||||
EXPORT(inet_ntop);
|
||||
EXPORT(inet_pton);
|
||||
EXPORT(getpeername);
|
||||
EXPORT(getsockname);
|
||||
EXPORT(getsockopt);
|
||||
EXPORT(setsocketlasterr);
|
||||
EXPORT(select);
|
||||
EXPORT(setsocklibopt);
|
||||
EXPORT(getsocklibopt);
|
||||
EXPORT(somemopt);
|
||||
EXPORT(ntohl);
|
||||
EXPORT(htonl);
|
||||
EXPORT(ntohs);
|
||||
EXPORT(htons);
|
||||
/*
|
||||
// Those are not in nsysnet.rpl - why are they linked o.O?
|
||||
EXPORT(somemopt);
|
||||
EXPORT(setsocketlasterr);
|
||||
EXPORT(icmp_create_handle);
|
||||
EXPORT(icmp_close_handle);
|
||||
EXPORT(icmp_ping);
|
||||
EXPORT(icmp_cancel);
|
||||
EXPORT(icmp_last_code_type);
|
||||
*/
|
||||
|
@ -8,6 +8,7 @@ EXPORT(AXSetDefaultMixerSelect);
|
||||
EXPORT(AXRegisterAppFrameCallback);
|
||||
EXPORT(AXGetInputSamplesPerFrame);
|
||||
EXPORT(AXGetInputSamplesPerSec);
|
||||
EXPORT(AXQuit);
|
||||
|
||||
// sndcore2/device.h
|
||||
EXPORT(AXGetDeviceMode);
|
||||
|
@ -151,14 +151,14 @@ SECTIONS {
|
||||
|
||||
/* Reserve space for the TLS segment of the main thread */
|
||||
__tls_start = .;
|
||||
|
||||
|
||||
__tbss_start = .;
|
||||
*(.tbss)
|
||||
*(.tbss.*)
|
||||
*(.gnu.linkonce.tb.*)
|
||||
*(.tcommon)
|
||||
__tbss_end = .;
|
||||
|
||||
|
||||
. += + SIZEOF(.tdata);
|
||||
__tls_end = .;
|
||||
. = ALIGN(32);
|
||||
@ -193,6 +193,7 @@ SECTIONS {
|
||||
/* Required compiler trash */
|
||||
.fixup ALIGN(32) : { *(.fixup*) }
|
||||
.got ALIGN(32) : { *(.got*) }
|
||||
.gcc_except_table ALIGN(32) : { *(.gcc_except_table*) }
|
||||
.hash ALIGN(32) : { *(.hash) }
|
||||
.dynsym ALIGN(32) : { *(.dynsym) }
|
||||
|
||||
|
@ -94,7 +94,7 @@ findSymbol(ElfFile &file, uint32_t address)
|
||||
return symbol.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (auto &symbol : file.symbols) {
|
||||
if (symbol->address == address) {
|
||||
return symbol.get();
|
||||
@ -238,6 +238,9 @@ read(ElfFile &file, const std::string &filename)
|
||||
case elf::R_PPC_RELATIVE:
|
||||
*ptr = byte_swap(addr);
|
||||
break;
|
||||
case elf::R_PPC_NONE:
|
||||
// ignore padding
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unexpected relocation type in .rela.dyn section" << std::endl;
|
||||
return false;
|
||||
@ -448,7 +451,7 @@ read(ElfFile &file, const std::string &filename)
|
||||
// If we can't find a proper symbol, write the addend in and hope for the best
|
||||
auto ptr = getLoaderDataPtr<uint32_t>(inSections, rela.offset);
|
||||
*ptr = addend;
|
||||
|
||||
|
||||
std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << ", continuing." << std::endl;
|
||||
continue;
|
||||
}
|
||||
@ -458,7 +461,7 @@ read(ElfFile &file, const std::string &filename)
|
||||
file.relocations.emplace_back(relocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read dyn relocations
|
||||
for (auto §ion : inSections) {
|
||||
if (section.header.type != elf::SHT_RELA) {
|
||||
@ -484,6 +487,12 @@ read(ElfFile &file, const std::string &filename)
|
||||
auto symbol = getSectionSymbol(symSection, index);
|
||||
auto addr = symbol->value + rela.addend;
|
||||
|
||||
if(type == elf::R_PPC_NONE)
|
||||
{
|
||||
// ignore padding
|
||||
continue;
|
||||
}
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
auto addend = static_cast<uint32_t>(rela.addend);
|
||||
@ -785,7 +794,7 @@ write(ElfFile &file, const std::string &filename)
|
||||
|
||||
if(relocation->type == elf::R_PPC_RELATIVE) {
|
||||
rela.info = elf::R_PPC_ADDR32 | idx << 8;
|
||||
}
|
||||
}
|
||||
|
||||
rela.addend = relocation->addend;
|
||||
rela.offset = relocation->target;
|
||||
@ -897,7 +906,7 @@ write(ElfFile &file, const std::string &filename)
|
||||
char *symData = reinterpret_cast<char *>(&sym);
|
||||
symTabSection->data.insert(symTabSection->data.end(), symData, symData + sizeof(elf::Symbol));
|
||||
}
|
||||
|
||||
|
||||
//Finish SHT_RPL_IMPORTS signatures
|
||||
Bytef *zero_buffer = reinterpret_cast<Bytef *>(calloc(0x10, 1));
|
||||
for (auto §ion : outSections) {
|
||||
@ -1063,7 +1072,7 @@ write(ElfFile &file, const std::string &filename)
|
||||
if (section->header.type != elf::SHT_RPL_CRCS && section->header.type != elf::SHT_RPL_FILEINFO) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.type != elf::SHT_NOBITS) {
|
||||
section->header.size = section->data.size();
|
||||
}
|
||||
@ -1075,17 +1084,17 @@ write(ElfFile &file, const std::string &filename)
|
||||
section->header.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add data sections next
|
||||
for (auto §ion : outSections) {
|
||||
if(section->header.offset != -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.addr < DataAddress || section->header.addr >= WiiuLoadAddress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.type != elf::SHT_NOBITS) {
|
||||
section->header.size = section->data.size();
|
||||
}
|
||||
@ -1097,17 +1106,17 @@ write(ElfFile &file, const std::string &filename)
|
||||
section->header.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add load sections next
|
||||
for (auto §ion : outSections) {
|
||||
if(section->header.offset != -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.addr < WiiuLoadAddress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.type != elf::SHT_NOBITS) {
|
||||
section->header.size = section->data.size();
|
||||
}
|
||||
@ -1119,13 +1128,13 @@ write(ElfFile &file, const std::string &filename)
|
||||
section->header.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Everything else
|
||||
for (auto §ion : outSections) {
|
||||
if(section->header.offset != -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (section->header.type != elf::SHT_NOBITS) {
|
||||
section->header.size = section->data.size();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user