Merge pull request #46 from dimok789/master

Link fixes for C++ applications and some additional enums and function declarations
This commit is contained in:
James 2016-10-11 21:42:38 +01:00 committed by GitHub
commit 48d2fcc314
10 changed files with 101 additions and 32 deletions

View File

@ -1,6 +1,7 @@
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <coreinit/baseheap.h> #include <coreinit/baseheap.h>
#include <coreinit/memheap.h>
#include <coreinit/expandedheap.h> #include <coreinit/expandedheap.h>
void * void *
@ -30,31 +31,31 @@ __wrap_realloc(void *ptr, size_t size) {
if (!ptr) { if (!ptr) {
return __wrap_malloc(size); return __wrap_malloc(size);
} }
if (__wrap_malloc_usable_size(ptr) >= size) { if (__wrap_malloc_usable_size(ptr) >= size) {
return ptr; return ptr;
} }
void *realloc_ptr = __wrap_malloc(size); void *realloc_ptr = __wrap_malloc(size);
if(!realloc_ptr) { if(!realloc_ptr) {
return NULL; return NULL;
} }
memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr)); memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr));
__wrap_free(ptr); __wrap_free(ptr);
return realloc_ptr; return realloc_ptr;
} }
void * void *
__wrap_calloc(size_t num, size_t size) { __wrap_calloc(size_t num, size_t size) {
void *ptr = __wrap_malloc(num*size); void *ptr = __wrap_malloc(num*size);
if(ptr) { if(ptr) {
memset(ptr, 0, num*size); memset(ptr, 0, num*size);
} }
return ptr; return ptr;
} }

14
include/coreinit/title.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
u64 OSGetTitleID(void);
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -14,6 +14,8 @@ extern "C" {
typedef enum GX2AAMode typedef enum GX2AAMode
{ {
GX2_AA_MODE1X = 0, GX2_AA_MODE1X = 0,
GX2_AA_MODE2X = 1,
GX2_AA_MODE4X = 2
} GX2AAMode; } GX2AAMode;
typedef enum GX2AlphaToMaskMode typedef enum GX2AlphaToMaskMode
@ -117,6 +119,7 @@ typedef enum GX2ClearFlags
{ {
GX2_CLEAR_FLAGS_DEPTH = 1, GX2_CLEAR_FLAGS_DEPTH = 1,
GX2_CLEAR_FLAGS_STENCIL = 2, GX2_CLEAR_FLAGS_STENCIL = 2,
GX2_CLEAR_FLAGS_BOTH = (GX2_CLEAR_FLAGS_DEPTH | GX2_CLEAR_FLAGS_STENCIL),
} GX2ClearFlags; } GX2ClearFlags;
typedef enum GX2CompareFunction typedef enum GX2CompareFunction
@ -185,6 +188,9 @@ typedef enum GX2InvalidateMode
GX2_INVALIDATE_MODE_CPU = 1 << 6, GX2_INVALIDATE_MODE_CPU = 1 << 6,
GX2_INVALIDATE_MODE_STREAM_OUT_BUFFER = 1 << 7, GX2_INVALIDATE_MODE_STREAM_OUT_BUFFER = 1 << 7,
GX2_INVALIDATE_MODE_EXPORT_BUFFER = 1 << 8, 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; } GX2InvalidateMode;
typedef enum GX2InitAttributes typedef enum GX2InitAttributes
@ -218,7 +224,10 @@ typedef enum GX2LogicOp
typedef enum GX2PrimitiveMode typedef enum GX2PrimitiveMode
{ {
GX2_PRIMITIVE_MODE_LINES = 2,
GX2_PRIMITIVE_MODE_LINE_STRIP = 3,
GX2_PRIMITIVE_MODE_TRIANGLES = 4, GX2_PRIMITIVE_MODE_TRIANGLES = 4,
GX2_PRIMITIVE_MODE_TRIANGLE_FAN = 5,
GX2_PRIMITIVE_MODE_TRIANGLE_STRIP = 6, GX2_PRIMITIVE_MODE_TRIANGLE_STRIP = 6,
GX2_PRIMITIVE_MODE_QUADS = 19, GX2_PRIMITIVE_MODE_QUADS = 19,
GX2_PRIMITIVE_MODE_QUAD_STRIP = 20, GX2_PRIMITIVE_MODE_QUAD_STRIP = 20,
@ -384,10 +393,12 @@ typedef enum
typedef enum GX2SurfaceUse typedef enum GX2SurfaceUse
{ {
GX2_SURFACE_USE_TEXTURE = 1 << 0, GX2_SURFACE_USE_TEXTURE = 1 << 0,
GX2_SURFACE_USE_COLOR_BUFFER = 1 << 1, GX2_SURFACE_USE_COLOR_BUFFER = 1 << 1,
GX2_SURFACE_USE_DEPTH_BUFFER = 1 << 2, GX2_SURFACE_USE_DEPTH_BUFFER = 1 << 2,
GX2_SURFACE_USE_SCAN_BUFFER = 1 << 3, 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; } GX2SurfaceUse;
typedef enum GX2TessellationMode typedef enum GX2TessellationMode
@ -428,8 +439,8 @@ typedef enum GX2TexMipPerfMode
typedef enum GX2TexXYFilterMode typedef enum GX2TexXYFilterMode
{ {
GX2_TEX_XY_FILLTER_MODE_POINT = 0, GX2_TEX_XY_FILTER_MODE_POINT = 0,
GX2_TEX_XY_FILLTER_MODE_LINEAR = 1, GX2_TEX_XY_FILTER_MODE_LINEAR = 1,
} GX2TexXYFilterMode; } GX2TexXYFilterMode;
typedef enum GX2TexAnisoRatio typedef enum GX2TexAnisoRatio

View File

@ -12,6 +12,8 @@
#define SOL_SOCKET 0xFFFF #define SOL_SOCKET 0xFFFF
#define INADDR_ANY 0
#define PF_UNSPEC 0 #define PF_UNSPEC 0
#define PF_INET 2 #define PF_INET 2
#define PF_INET6 23 #define PF_INET6 23
@ -35,6 +37,10 @@
#define SHUT_WR 1 #define SHUT_WR 1
#define SHUT_RDWR 2 #define SHUT_RDWR 2
#define IPPROTO_IP 0
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
/* /*
* SOL_SOCKET options * SOL_SOCKET options
*/ */
@ -69,6 +75,16 @@ struct linger
int l_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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -87,7 +103,7 @@ bind(int sockfd,
socklen_t addrlen); socklen_t addrlen);
int int
closesocket(int sockfd); socketclose(int sockfd);
int int
connect(int sockfd, connect(int sockfd,
@ -166,6 +182,12 @@ select(int nfds,
fd_set *exceptfds, fd_set *exceptfds,
struct timeval *timeout); struct timeval *timeout);
char *
inet_ntoa(struct in_addr in);
int
inet_aton(const char *cp, struct in_addr *inp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -54,6 +54,9 @@ CHECK_SIZE(AXInitParams, 0x0C);
void void
AXInit(); AXInit();
void
AXQuit();
void void
AXInitWithParams(AXInitParams *params); AXInitWithParams(AXInitParams *params);

View File

@ -368,5 +368,8 @@ EXPORT(MEMFreeToUnitHeap);
EXPORT(MEMCountFreeBlockForUnitHeap); EXPORT(MEMCountFreeBlockForUnitHeap);
EXPORT(MEMCalcHeapSizeForUnitHeap); EXPORT(MEMCalcHeapSizeForUnitHeap);
// coreinit/title.h
EXPORT(OSGetTitleID);
// coreinit/internal.h // coreinit/internal.h
EXPORT(__os_snprintf); EXPORT(__os_snprintf);

View File

@ -17,23 +17,27 @@ EXPORT(sendto_multi);
EXPORT(sendto_multi_ex); EXPORT(sendto_multi_ex);
EXPORT(shutdown); EXPORT(shutdown);
EXPORT(inet_aton); EXPORT(inet_aton);
EXPORT(inet_ntoa);
EXPORT(inet_ntoa_r); EXPORT(inet_ntoa_r);
EXPORT(inet_ntop); EXPORT(inet_ntop);
EXPORT(inet_pton); EXPORT(inet_pton);
EXPORT(getpeername); EXPORT(getpeername);
EXPORT(getsockname); EXPORT(getsockname);
EXPORT(getsockopt); EXPORT(getsockopt);
EXPORT(setsocketlasterr);
EXPORT(select); EXPORT(select);
EXPORT(setsocklibopt); EXPORT(setsocklibopt);
EXPORT(getsocklibopt); EXPORT(getsocklibopt);
EXPORT(somemopt);
EXPORT(ntohl); EXPORT(ntohl);
EXPORT(htonl); EXPORT(htonl);
EXPORT(ntohs); EXPORT(ntohs);
EXPORT(htons); EXPORT(htons);
/*
// Those are not in nsysnet.rpl - why are they linked o.O?
EXPORT(somemopt);
EXPORT(setsocketlasterr);
EXPORT(icmp_create_handle); EXPORT(icmp_create_handle);
EXPORT(icmp_close_handle); EXPORT(icmp_close_handle);
EXPORT(icmp_ping); EXPORT(icmp_ping);
EXPORT(icmp_cancel); EXPORT(icmp_cancel);
EXPORT(icmp_last_code_type); EXPORT(icmp_last_code_type);
*/

View File

@ -8,6 +8,7 @@ EXPORT(AXSetDefaultMixerSelect);
EXPORT(AXRegisterAppFrameCallback); EXPORT(AXRegisterAppFrameCallback);
EXPORT(AXGetInputSamplesPerFrame); EXPORT(AXGetInputSamplesPerFrame);
EXPORT(AXGetInputSamplesPerSec); EXPORT(AXGetInputSamplesPerSec);
EXPORT(AXQuit);
// sndcore2/device.h // sndcore2/device.h
EXPORT(AXGetDeviceMode); EXPORT(AXGetDeviceMode);

View File

@ -151,14 +151,14 @@ SECTIONS {
/* Reserve space for the TLS segment of the main thread */ /* Reserve space for the TLS segment of the main thread */
__tls_start = .; __tls_start = .;
__tbss_start = .; __tbss_start = .;
*(.tbss) *(.tbss)
*(.tbss.*) *(.tbss.*)
*(.gnu.linkonce.tb.*) *(.gnu.linkonce.tb.*)
*(.tcommon) *(.tcommon)
__tbss_end = .; __tbss_end = .;
. += + SIZEOF(.tdata); . += + SIZEOF(.tdata);
__tls_end = .; __tls_end = .;
. = ALIGN(32); . = ALIGN(32);
@ -193,6 +193,7 @@ SECTIONS {
/* Required compiler trash */ /* Required compiler trash */
.fixup ALIGN(32) : { *(.fixup*) } .fixup ALIGN(32) : { *(.fixup*) }
.got ALIGN(32) : { *(.got*) } .got ALIGN(32) : { *(.got*) }
.gcc_except_table ALIGN(32) : { *(.gcc_except_table*) }
.hash ALIGN(32) : { *(.hash) } .hash ALIGN(32) : { *(.hash) }
.dynsym ALIGN(32) : { *(.dynsym) } .dynsym ALIGN(32) : { *(.dynsym) }

View File

@ -94,7 +94,7 @@ findSymbol(ElfFile &file, uint32_t address)
return symbol.get(); return symbol.get();
} }
} }
for (auto &symbol : file.symbols) { for (auto &symbol : file.symbols) {
if (symbol->address == address) { if (symbol->address == address) {
return symbol.get(); return symbol.get();
@ -238,6 +238,9 @@ read(ElfFile &file, const std::string &filename)
case elf::R_PPC_RELATIVE: case elf::R_PPC_RELATIVE:
*ptr = byte_swap(addr); *ptr = byte_swap(addr);
break; break;
case elf::R_PPC_NONE:
// ignore padding
break;
default: default:
std::cout << "Unexpected relocation type in .rela.dyn section" << std::endl; std::cout << "Unexpected relocation type in .rela.dyn section" << std::endl;
return false; 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 // 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); auto ptr = getLoaderDataPtr<uint32_t>(inSections, rela.offset);
*ptr = addend; *ptr = addend;
std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << ", continuing." << std::endl; std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << ", continuing." << std::endl;
continue; continue;
} }
@ -458,7 +461,7 @@ read(ElfFile &file, const std::string &filename)
file.relocations.emplace_back(relocation); file.relocations.emplace_back(relocation);
} }
} }
// Read dyn relocations // Read dyn relocations
for (auto &section : inSections) { for (auto &section : inSections) {
if (section.header.type != elf::SHT_RELA) { if (section.header.type != elf::SHT_RELA) {
@ -484,6 +487,12 @@ read(ElfFile &file, const std::string &filename)
auto symbol = getSectionSymbol(symSection, index); auto symbol = getSectionSymbol(symSection, index);
auto addr = symbol->value + rela.addend; auto addr = symbol->value + rela.addend;
if(type == elf::R_PPC_NONE)
{
// ignore padding
continue;
}
if(index == 0) if(index == 0)
{ {
auto addend = static_cast<uint32_t>(rela.addend); 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) { if(relocation->type == elf::R_PPC_RELATIVE) {
rela.info = elf::R_PPC_ADDR32 | idx << 8; rela.info = elf::R_PPC_ADDR32 | idx << 8;
} }
rela.addend = relocation->addend; rela.addend = relocation->addend;
rela.offset = relocation->target; rela.offset = relocation->target;
@ -897,7 +906,7 @@ write(ElfFile &file, const std::string &filename)
char *symData = reinterpret_cast<char *>(&sym); char *symData = reinterpret_cast<char *>(&sym);
symTabSection->data.insert(symTabSection->data.end(), symData, symData + sizeof(elf::Symbol)); symTabSection->data.insert(symTabSection->data.end(), symData, symData + sizeof(elf::Symbol));
} }
//Finish SHT_RPL_IMPORTS signatures //Finish SHT_RPL_IMPORTS signatures
Bytef *zero_buffer = reinterpret_cast<Bytef *>(calloc(0x10, 1)); Bytef *zero_buffer = reinterpret_cast<Bytef *>(calloc(0x10, 1));
for (auto &section : outSections) { for (auto &section : 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) { if (section->header.type != elf::SHT_RPL_CRCS && section->header.type != elf::SHT_RPL_FILEINFO) {
continue; continue;
} }
if (section->header.type != elf::SHT_NOBITS) { if (section->header.type != elf::SHT_NOBITS) {
section->header.size = section->data.size(); section->header.size = section->data.size();
} }
@ -1075,17 +1084,17 @@ write(ElfFile &file, const std::string &filename)
section->header.offset = 0; section->header.offset = 0;
} }
} }
// Add data sections next // Add data sections next
for (auto &section : outSections) { for (auto &section : outSections) {
if(section->header.offset != -1) { if(section->header.offset != -1) {
continue; continue;
} }
if (section->header.addr < DataAddress || section->header.addr >= WiiuLoadAddress) { if (section->header.addr < DataAddress || section->header.addr >= WiiuLoadAddress) {
continue; continue;
} }
if (section->header.type != elf::SHT_NOBITS) { if (section->header.type != elf::SHT_NOBITS) {
section->header.size = section->data.size(); section->header.size = section->data.size();
} }
@ -1097,17 +1106,17 @@ write(ElfFile &file, const std::string &filename)
section->header.offset = 0; section->header.offset = 0;
} }
} }
// Add load sections next // Add load sections next
for (auto &section : outSections) { for (auto &section : outSections) {
if(section->header.offset != -1) { if(section->header.offset != -1) {
continue; continue;
} }
if (section->header.addr < WiiuLoadAddress) { if (section->header.addr < WiiuLoadAddress) {
continue; continue;
} }
if (section->header.type != elf::SHT_NOBITS) { if (section->header.type != elf::SHT_NOBITS) {
section->header.size = section->data.size(); section->header.size = section->data.size();
} }
@ -1119,13 +1128,13 @@ write(ElfFile &file, const std::string &filename)
section->header.offset = 0; section->header.offset = 0;
} }
} }
// Everything else // Everything else
for (auto &section : outSections) { for (auto &section : outSections) {
if(section->header.offset != -1) { if(section->header.offset != -1) {
continue; continue;
} }
if (section->header.type != elf::SHT_NOBITS) { if (section->header.type != elf::SHT_NOBITS) {
section->header.size = section->data.size(); section->header.size = section->data.size();
} }