first commit

This commit is contained in:
murdle
2026-03-01 02:38:58 +02:00
commit 19250b9db4
19111 changed files with 4358159 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
/* SCE CONFIDENTIAL
* Copyright (C) 2014 Sony Computer Entertainment Inc.
* All Rights Reserved.
*/
#ifndef __SCE_NP_CONF_H__
#define __SCE_NP_CONF_H__
#include <np.h>
static const SceNpCommunicationId s_npCommunicationId = {
{'N', 'P', 'W', 'R', '0', '6', '8', '5', '9'},
'\0',
0,
0
};
/***
SceNpCommunicationPassphrase
8129251a703ff265e6d2b777bcf1854d3c6ea7f656626170131163c6e8edcb4110dd6247d40e1d8d06ebdbb610f8046c85332bc4de7946da49635459628a0d13243a6cda7ae3462a4d65d20cb2839b2e311dd7ff5006ec1379c37d3b49f137e2981050601ba4efa2ccc445c1cfc0fbd6b2f075f19490830cb995a6ad779de1d8
***/
static const SceNpCommunicationPassphrase s_npCommunicationPassphrase = {
{
0x81,0x29,0x25,0x1a,0x70,0x3f,0xf2,0x65,
0xe6,0xd2,0xb7,0x77,0xbc,0xf1,0x85,0x4d,
0x3c,0x6e,0xa7,0xf6,0x56,0x62,0x61,0x70,
0x13,0x11,0x63,0xc6,0xe8,0xed,0xcb,0x41,
0x10,0xdd,0x62,0x47,0xd4,0x0e,0x1d,0x8d,
0x06,0xeb,0xdb,0xb6,0x10,0xf8,0x04,0x6c,
0x85,0x33,0x2b,0xc4,0xde,0x79,0x46,0xda,
0x49,0x63,0x54,0x59,0x62,0x8a,0x0d,0x13,
0x24,0x3a,0x6c,0xda,0x7a,0xe3,0x46,0x2a,
0x4d,0x65,0xd2,0x0c,0xb2,0x83,0x9b,0x2e,
0x31,0x1d,0xd7,0xff,0x50,0x06,0xec,0x13,
0x79,0xc3,0x7d,0x3b,0x49,0xf1,0x37,0xe2,
0x98,0x10,0x50,0x60,0x1b,0xa4,0xef,0xa2,
0xcc,0xc4,0x45,0xc1,0xcf,0xc0,0xfb,0xd6,
0xb2,0xf0,0x75,0xf1,0x94,0x90,0x83,0x0c,
0xb9,0x95,0xa6,0xad,0x77,0x9d,0xe1,0xd8
}
};
/***
SceNpCommunicationSignature
b9dde13b01000000000000005c66a0cfc0c22c63dc050021c2e3537360ca40370ff68a60596b1fc84364cebe3459359579ca2ef8c151fc920ee4cf25eb4a926c572891b840eafa35ebfb5d67744b8f8bbd7cd53245ec12a639423a2eb520e8c381c5afa3095727c3ca1612351ed9921940b779dfbcf84b72b5978c5c07fadf11fe8f5a33c41405dea8d59673f1eedbda420cf48618c895c9d4271154d7c9e952
***/
static const SceNpCommunicationSignature s_npCommunicationSignature = {
{
0xb9,0xdd,0xe1,0x3b,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x5c,0x66,0xa0,0xcf,
0xc0,0xc2,0x2c,0x63,0xdc,0x05,0x00,0x21,
0xc2,0xe3,0x53,0x73,0x60,0xca,0x40,0x37,
0x0f,0xf6,0x8a,0x60,0x59,0x6b,0x1f,0xc8,
0x43,0x64,0xce,0xbe,0x34,0x59,0x35,0x95,
0x79,0xca,0x2e,0xf8,0xc1,0x51,0xfc,0x92,
0x0e,0xe4,0xcf,0x25,0xeb,0x4a,0x92,0x6c,
0x57,0x28,0x91,0xb8,0x40,0xea,0xfa,0x35,
0xeb,0xfb,0x5d,0x67,0x74,0x4b,0x8f,0x8b,
0xbd,0x7c,0xd5,0x32,0x45,0xec,0x12,0xa6,
0x39,0x42,0x3a,0x2e,0xb5,0x20,0xe8,0xc3,
0x81,0xc5,0xaf,0xa3,0x09,0x57,0x27,0xc3,
0xca,0x16,0x12,0x35,0x1e,0xd9,0x92,0x19,
0x40,0xb7,0x79,0xdf,0xbc,0xf8,0x4b,0x72,
0xb5,0x97,0x8c,0x5c,0x07,0xfa,0xdf,0x11,
0xfe,0x8f,0x5a,0x33,0xc4,0x14,0x05,0xde,
0xa8,0xd5,0x96,0x73,0xf1,0xee,0xdb,0xda,
0x42,0x0c,0xf4,0x86,0x18,0xc8,0x95,0xc9,
0xd4,0x27,0x11,0x54,0xd7,0xc9,0xe9,0x52
}
};
static const SceNpCommunicationConfig s_npCommunicationConfig =
{
&s_npCommunicationId,
&s_npCommunicationPassphrase,
&s_npCommunicationSignature
};
#endif /* __SCE_NP_CONF_H__ */

View File

@@ -0,0 +1,132 @@
#include "stdafx.h"
#include "CustomMap.h"
CustomMap::CustomMap()
{
m_NodePool = NULL;
m_NodePoolSize = 0;
m_NodePoolIndex = 0;
m_HashSize = 1024;
m_HashTable = (SCustomMapNode**) malloc(m_HashSize * sizeof(SCustomMapNode));
clear();
}
CustomMap::~CustomMap()
{
for( int i = 0;i < m_NodePoolSize; i += 1 )
{
free(m_NodePool[i]);
}
free(m_NodePool);
free(m_HashTable);
}
void CustomMap::clear()
{
// reset the pool index
m_NodePoolIndex = 0;
// clear the hash table
memset(m_HashTable, 0, m_HashSize * sizeof(SCustomMapNode));
}
SCustomMapNode* CustomMap::find(const ChunkPos &Key)
{
unsigned int Hash = (Key.x & 0x00000001f) | (Key.z << 5); // hopefully this will produce a good hash for a 1024 entry table
unsigned int Index = Hash & (m_HashSize-1);
SCustomMapNode* Node = m_HashTable[Index];
while( Node && Node->Hash != Hash )
{
Node = Node->Next;
}
return Node;
}
int CustomMap::end()
{
return m_NodePoolIndex;
}
SCustomMapNode* CustomMap::get(int index)
{
return m_NodePool[index];
}
void CustomMap::insert(const ChunkPos &Key, bool Value)
{
// see if this key already exists
SCustomMapNode* Node = find(Key);
if( !Node )
{
// do we have any space in the pool
if( m_NodePoolIndex >= m_NodePoolSize )
{
resize();
}
// grab the next node from the pool
Node = m_NodePool[m_NodePoolIndex];
m_NodePoolIndex++;
}
else
{
Node->second = Value;
return;
}
// create the new node;
unsigned int Hash = (Key.x & 0x00000001f) | (Key.z << 5); // hopefully this will produce a good hash for a 1024 entry table
unsigned int Index = Hash & (m_HashSize-1);
Node->Hash = Hash;
Node->first = Key;
Node->second = Value;
Node->Next = NULL;
// are any nodes in this hash index
if( !m_HashTable[Index] )
{
m_HashTable[Index] = Node;
}
else
{
// loop to the last node in the hash list
SCustomMapNode* OldNode = m_HashTable[Index];
while( OldNode->Next )
{
OldNode = OldNode->Next;
}
// link the old last node to the new one
OldNode->Next = Node;
}
}
void CustomMap::resize()
{
int OldPoolSize = m_NodePoolSize;
m_NodePoolSize += 512;
SCustomMapNode **NodePool;
if( m_NodePool )
{
NodePool = (SCustomMapNode**) realloc(m_NodePool, m_NodePoolSize * sizeof(SCustomMapNode));
}
else
{
NodePool = (SCustomMapNode**) malloc(m_NodePoolSize * sizeof(SCustomMapNode));
}
for( int i = 0;i < m_NodePoolSize - OldPoolSize;i += 1 )
{
NodePool[i + OldPoolSize] = (SCustomMapNode*) malloc(sizeof(SCustomMapNode));
}
m_NodePool = NodePool;
}

View File

@@ -0,0 +1,43 @@
#ifndef CustomMap_H
#define CustomMap_H
// AP - This replaces the std::unordered_map used in MobSpawner.h
// The problem with the original system is that it calls malloc for every insert it does. Not only is that expensive in itself but it also
// clashes with any other mallocs on other threads (specifically the large amount of mallocing being done in Level.h for the std::unordered_set)
// causing huge stalls.
// This isn't really a univeral replacement for std::unordered_map and is quite specific to MobSpawner.h
#include "../../../Minecraft.World/ChunkPos.h"
typedef struct SCustomMapNode
{
unsigned int Hash;
ChunkPos first;
bool second;
struct SCustomMapNode *Next;
} SCustomMapNode;
class CustomMap
{
private:
SCustomMapNode **m_NodePool;
int m_NodePoolSize;
int m_NodePoolIndex;
int m_HashSize;
SCustomMapNode **m_HashTable;
public:
CustomMap();
~CustomMap();
void clear();
SCustomMapNode* find(const ChunkPos &Key);
int end();
SCustomMapNode* get(int index);
void insert(const ChunkPos &Key, bool Value);
private:
void resize();
};
#endif // CustomMap_H

View File

@@ -0,0 +1,130 @@
#include "stdafx.h"
#include "CustomSet.h"
CustomSet::CustomSet()
{
m_NodePool = NULL;
m_NodePoolSize = 0;
m_NodePoolIndex = 0;
m_HashSize = 1024;
m_HashTable = (SCustomSetNode**) malloc(m_HashSize * sizeof(SCustomSetNode));
clear();
}
CustomSet::~CustomSet()
{
for( int i = 0;i < m_NodePoolSize; i += 1 )
{
free(m_NodePool[i]);
}
free(m_NodePool);
free(m_HashTable);
}
void CustomSet::clear()
{
// reset the pool index
m_NodePoolIndex = 0;
// clear the hash table
memset(m_HashTable, 0, m_HashSize * sizeof(SCustomSetNode));
}
SCustomSetNode* CustomSet::find(const ChunkPos &Key)
{
unsigned int Hash = (Key.x & 0x00000001f) | (Key.z << 5); // hopefully this will produce a good hash for a 1024 entry table
unsigned int Index = Hash & (m_HashSize-1);
SCustomSetNode* Node = m_HashTable[Index];
while( Node && Node->Hash != Hash )
{
Node = Node->Next;
}
return Node;
}
int CustomSet::end()
{
return m_NodePoolIndex;
}
ChunkPos CustomSet::get(int index)
{
return m_NodePool[index]->key;
}
void CustomSet::insert(const ChunkPos &Key)
{
// see if this key already exists
SCustomSetNode* Node = find(Key);
if( !Node )
{
// do we have any space in the pool
if( m_NodePoolIndex >= m_NodePoolSize )
{
resize();
}
// grab the next node from the pool
Node = m_NodePool[m_NodePoolIndex];
m_NodePoolIndex++;
}
else
{
return;
}
// create the new node;
unsigned int Hash = (Key.x & 0x00000001f) | (Key.z << 5); // hopefully this will produce a good hash for a 1024 entry table
unsigned int Index = Hash & (m_HashSize-1);
Node->Hash = Hash;
Node->key = Key;
Node->Next = NULL;
// are any nodes in this hash index
if( !m_HashTable[Index] )
{
m_HashTable[Index] = Node;
}
else
{
// loop to the last node in the hash list
SCustomSetNode* OldNode = m_HashTable[Index];
while( OldNode->Next )
{
OldNode = OldNode->Next;
}
// link the old last node to the new one
OldNode->Next = Node;
}
}
void CustomSet::resize()
{
int OldPoolSize = m_NodePoolSize;
m_NodePoolSize += 512;
SCustomSetNode **NodePool;
if( m_NodePool )
{
NodePool = (SCustomSetNode**) realloc(m_NodePool, m_NodePoolSize * sizeof(SCustomSetNode));
}
else
{
NodePool = (SCustomSetNode**) malloc(m_NodePoolSize * sizeof(SCustomSetNode));
}
for( int i = 0;i < m_NodePoolSize - OldPoolSize;i += 1 )
{
NodePool[i + OldPoolSize] = (SCustomSetNode*) malloc(sizeof(SCustomSetNode));
}
m_NodePool = NodePool;
}

View File

@@ -0,0 +1,42 @@
#ifndef CustomSet_H
#define CustomSet_H
// AP - This replaces the std::unordered_set used in Level.h
// The problem with the original system is that it calls malloc for every insert it does. Not only is that expensive in itself but it also
// clashes with any other mallocs on other threads (specifically the large amount of mallocing being done in MobSpawner for the std::unordered_map)
// causing huge stalls.
// This isn't really a univeral replacement for std::unordered_set and is quite specific to Level.h
#include "../../../Minecraft.World/ChunkPos.h"
typedef struct SCustomSetNode
{
unsigned int Hash;
ChunkPos key;
struct SCustomSetNode *Next;
} SCustomSetNode;
class CustomSet
{
private:
SCustomSetNode **m_NodePool;
int m_NodePoolSize;
int m_NodePoolIndex;
int m_HashSize;
SCustomSetNode **m_HashTable;
public:
CustomSet();
~CustomSet();
void clear();
SCustomSetNode* find(const ChunkPos &Key);
int end();
ChunkPos get(int index);
void insert(const ChunkPos &Key);
private:
void resize();
};
#endif // CustomSet_H

View File

@@ -0,0 +1,11 @@
#pragma once
#include <vectormath.h>
using namespace sce::Vectormath::Simd::Aos;
typedef Vector4 XMVECTOR;
typedef Matrix4 XMMATRIX;
typedef Vector4 XMFLOAT4;
XMMATRIX XMMatrixMultiply(XMMATRIX a, XMMATRIX b);
XMVECTOR XMMatrixDeterminant(XMMATRIX a);
XMMATRIX XMMatrixInverse(Vector4 *a, XMMATRIX b);

View File

@@ -0,0 +1,51 @@
#include "stdafx.h"
#include "PSVitaStrings.h"
#include <ces.h>
uint8_t *mallocAndCreateUTF8ArrayFromString(int iID)
{
LPCWSTR wchString=app.GetString(iID);
size_t src_len,dst_len;
int iLen=wcslen(wchString);
src_len=sizeof(WCHAR)*(iLen);
SceCesUcsContext context;
int result = sceCesUcsContextInit( &context );
if( result != S_OK )
{
app.DebugPrintf("sceCesUcsContextInit failed\n");
return NULL;
}
uint32_t utf16Len;
uint32_t utf8Len;
result = sceCesUtf16StrGetUtf8Len( &context,
(uint16_t *)wchString,
iLen,
&utf16Len,
&utf8Len
);
utf8Len += 1;
uint8_t *strUtf8=(uint8_t *)malloc(utf8Len);
memset(strUtf8,0,utf8Len);
result = sceCesUtf16StrToUtf8Str(
&context,
(uint16_t *)wchString,
iLen,
&utf16Len,
strUtf8,
utf8Len,
&utf8Len
);
if( result != SCE_OK )
{
app.DebugPrintf("sceCesUtf16StrToUtf8Str: conversion error : 0x%x\n", result);
return NULL;
}
return strUtf8;
}

View File

@@ -0,0 +1,3 @@
#pragma once
uint8_t *mallocAndCreateUTF8ArrayFromString(int iID);

View File

@@ -0,0 +1,468 @@
#pragma once
//#include <libdbg.h>
#include <kernel.h>
// AP recreate Sony's assert macro
/*E Macros for halting of program execution. */
#ifndef SCE_BREAK
/** Breaks program execution. If a debugger is attached, the user can resume execution immediately. */
#define SCE_BREAK() _SCE_BREAK()
#endif /* #ifndef SCE_BREAK */
#ifndef _CONTENT_PACKAGE
#define _SCE_MACRO_BEGIN do {
#define _SCE_MACRO_END } while(0)
#define SCE_DBG_ASSERT(test) _SCE_MACRO_BEGIN { (void)sizeof((test)); } _SCE_MACRO_END
#else
#define SCE_DBG_ASSERT(test)
#endif
//const char* getConsoleHomePath();
char* getUsrDirPath();
void PSVitaInit();
DWORD TlsAlloc(VOID);
LPVOID TlsGetValue(DWORD dwTlsIndex);
BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
typedef struct _RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;
typedef struct _TOUCHSCREENRECT
{
SceInt16 left;
SceInt16 top;
SceInt16 right;
SceInt16 bottom;
}
TOUCHSCREENRECT, *PTOUCHSCREENRECT;
typedef void ID3D11Device;
typedef void ID3D11DeviceContext;
typedef void IDXGISwapChain;
typedef RECT D3D11_RECT;
typedef void ID3D11Buffer;
typedef DWORD (*PTHREAD_START_ROUTINE)( LPVOID lpThreadParameter);
typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
typedef int errno_t;
// typedef struct _RTL_CRITICAL_SECTION {
// //
// // The following field is used for blocking when there is contention for
// // the resource
// //
//
// union {
// ULONG_PTR RawEvent[4];
// } Synchronization;
//
// //
// // The following three fields control entering and exiting the critical
// // section for the resource
// //
//
// LONG LockCount;
// LONG RecursionCount;
// HANDLE OwningThread;
// } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
class PSVitaCriticalSection
{
public:
SceKernelLwMutexWork mutex;
};
class PSVitaCriticalRWSection
{
public:
SceUID RWLock;
};
typedef PSVitaCriticalSection RTL_CRITICAL_SECTION;
typedef PSVitaCriticalSection* PRTL_CRITICAL_SECTION;
typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
typedef PSVitaCriticalRWSection RTL_CRITICAL_RW_SECTION;
typedef PSVitaCriticalRWSection* PRTL_CRITICAL_RW_SECTION;
typedef RTL_CRITICAL_RW_SECTION CRITICAL_RW_SECTION;
typedef PRTL_CRITICAL_RW_SECTION PCRITICAL_RW_SECTION;
typedef PRTL_CRITICAL_RW_SECTION LPCRITICAL_RW_SECTION;
void EnterCriticalSection(CRITICAL_SECTION* _c);
void LeaveCriticalSection(CRITICAL_SECTION* _c);
void InitializeCriticalSection(CRITICAL_SECTION* _c);
void DeleteCriticalSection(CRITICAL_SECTION* _c);
HANDLE CreateEvent(void* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName);
VOID Sleep(DWORD dwMilliseconds);
BOOL SetThreadPriority(HANDLE hThread, int nPriority);
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
LONG InterlockedCompareExchangeRelease(LONG volatile *Destination, LONG Exchange,LONG Comperand );
VOID InitializeCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID InitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION CriticalSection, ULONG SpinCount);
VOID DeleteCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID EnterCriticalSection(PCRITICAL_SECTION CriticalSection);
VOID LeaveCriticalSection(PCRITICAL_SECTION CriticalSection);
ULONG TryEnterCriticalSection(PCRITICAL_SECTION CriticalSection);
DWORD WaitForMultipleObjects(DWORD nCount, CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds);
// AP - RW criticals added to allow simultaneous read but not R/W or W/W
VOID InitializeCriticalRWSection(PCRITICAL_RW_SECTION CriticalSection);
VOID DeleteCriticalRWSection(PCRITICAL_RW_SECTION CriticalSection);
VOID EnterCriticalRWSection(PCRITICAL_RW_SECTION CriticalSection, bool Write);
VOID LeaveCriticalRWSection(PCRITICAL_RW_SECTION CriticalSection, bool Write);
LONG64 InterlockedCompareExchangeRelease64(LONG64 volatile *Destination, LONG64 Exchange, LONG64 Comperand);
BOOL CloseHandle(HANDLE hObject);
BOOL SetEvent(HANDLE hEvent);
HMODULE GetModuleHandle(LPCSTR lpModuleName);
HANDLE CreateThread( void* lpThreadAttributes, DWORD dwStackSize, void* lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
DWORD ResumeThread( HANDLE hThread );
DWORD GetCurrentThreadId(VOID);
DWORD WaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds,BOOL bAlertable );
BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
// AP - all this virtual stuff has been added because Vita doesn't have a virtual memory system so we allocate 1MB real memory chunks instead
// and access memory reads and writes via VirtualCopyTo and VirtualCopyFrom which divides memcpys across multiple 1MB chunks if required
#define VIRTUAL_PAGE_SIZE (1024*1024) // out page size 1MB
#define VIRTUAL_OFFSET 1000000 // we use this just so we don't indicate 'out of memory' to ConsoleSaveFile by returning 0
LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
VOID VirtualCopyTo(LPVOID lpDestOffset, LPVOID lpSrc, SIZE_T dwSize);
VOID VirtualCopyFrom(LPVOID lpDest, LPVOID lpSrcOffset, SIZE_T dwSize);
VOID VirtualMove(LPVOID lpDestOffset, LPVOID lpSrcOffset, SIZE_T dwSize);
BOOL VirtualWriteFile(LPCSTR lpFileName, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped );
VOID VirtualCompress(LPVOID lpDest,LPDWORD lpNewSize, LPVOID lpAddress, SIZE_T dwSize);
VOID VirtualDecompress(LPVOID buf, SIZE_T dwSize);
VOID VirtualMemset(LPVOID lpDestOffset, int val, SIZE_T dwSize);
DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh );
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize );
BOOL WriteFileWithName(LPCSTR lpFileName, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped );
BOOL WriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped );
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped );
#define INVALID_SET_FILE_POINTER false
BOOL SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
#define CreateFile CreateFileA
BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
#define CreateDirectory CreateDirectoryA
BOOL DeleteFileA(LPCSTR lpFileName);
#define DeleteFile DeleteFileA
DWORD GetFileAttributesA(LPCSTR lpFileName);
#define GetFileAttributes GetFileAttributesA
BOOL MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
#define MoveFile MoveFileA
#define MAX_PATH 260
void __debugbreak();
VOID DebugBreak(VOID);
enum D3D11_BLEND
{
D3D11_BLEND_ZERO = 1,
D3D11_BLEND_ONE = 2,
D3D11_BLEND_SRC_COLOR = 3,
D3D11_BLEND_INV_SRC_COLOR = 4,
D3D11_BLEND_SRC_ALPHA = 5,
D3D11_BLEND_INV_SRC_ALPHA = 6,
D3D11_BLEND_DEST_ALPHA = 7,
D3D11_BLEND_INV_DEST_ALPHA = 8,
D3D11_BLEND_DEST_COLOR = 9,
D3D11_BLEND_INV_DEST_COLOR = 10,
D3D11_BLEND_SRC_ALPHA_SAT = 11,
D3D11_BLEND_BLEND_FACTOR = 14,
D3D11_BLEND_INV_BLEND_FACTOR = 15,
D3D11_BLEND_SRC1_COLOR = 16,
D3D11_BLEND_INV_SRC1_COLOR = 17,
D3D11_BLEND_SRC1_ALPHA = 18,
D3D11_BLEND_INV_SRC1_ALPHA = 19
};
enum D3D11_COMPARISON_FUNC
{
D3D11_COMPARISON_NEVER = 1,
D3D11_COMPARISON_LESS = 2,
D3D11_COMPARISON_EQUAL = 3,
D3D11_COMPARISON_LESS_EQUAL = 4,
D3D11_COMPARISON_GREATER = 5,
D3D11_COMPARISON_NOT_EQUAL = 6,
D3D11_COMPARISON_GREATER_EQUAL = 7,
D3D11_COMPARISON_ALWAYS = 8
};
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
VOID GetSystemTime( LPSYSTEMTIME lpSystemTime);
BOOL FileTimeToSystemTime(CONST FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime);
BOOL SystemTimeToFileTime(CONST SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime);
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);
typedef struct _MEMORYSTATUS {
DWORD dwLength;
DWORD dwMemoryLoad;
SIZE_T dwTotalPhys;
SIZE_T dwAvailPhys;
SIZE_T dwTotalPageFile;
SIZE_T dwAvailPageFile;
SIZE_T dwTotalVirtual;
SIZE_T dwAvailVirtual;
} MEMORYSTATUS, *LPMEMORYSTATUS;
#define WINAPI
#define CREATE_SUSPENDED 0x00000004
#define THREAD_BASE_PRIORITY_LOWRT 15 // value that gets a thread to LowRealtime-1
#define THREAD_BASE_PRIORITY_MAX 2 // maximum thread base priority boost
#define THREAD_BASE_PRIORITY_MIN -2 // minimum thread base priority boost
#define THREAD_BASE_PRIORITY_IDLE -15 // value that gets a thread to idle
#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
#define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
#define WAIT_TIMEOUT 258L
#define STATUS_ABANDONED_WAIT_0 ((DWORD )0x00000080L)
#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 )
#define MAXUINT_PTR (~((UINT_PTR)0))
#define MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1))
#define MININT_PTR (~MAXINT_PTR)
#define MAXULONG_PTR (~((ULONG_PTR)0))
#define MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1))
#define MINLONG_PTR (~MAXLONG_PTR)
#define MAXUHALF_PTR ((UHALF_PTR)~0)
#define MAXHALF_PTR ((HALF_PTR)(MAXUHALF_PTR >> 1))
#define MINHALF_PTR (~MAXHALF_PTR)
#define INVALID_HANDLE_VALUE ((HANDLE)0)
//
// Generic test for success on any status value (non-negative numbers
// indicate success).
//
//#define HRESULT_SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
//
// and the inverse
//
#define _HRESULT_TYPEDEF_(_sc) _sc
#define FAILED(Status) ((HRESULT)(Status)<0)
#define MAKE_HRESULT(sev,fac,code) \
((HRESULT) (((unsigned int)(sev)<<31) | ((unsigned int)(fac)<<16) | ((unsigned int)(code))) )
#define MAKE_SCODE(sev,fac,code) \
((SCODE) (((unsigned int)(sev)<<31) | ((unsigned int)(fac)<<16) | ((unsigned int)(code))) )
#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)
#define E_ABORT _HRESULT_TYPEDEF_(0x80004004L)
#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
#define GENERIC_EXECUTE (0x20000000L)
#define GENERIC_ALL (0x10000000L)
#define FILE_SHARE_READ 0x00000001
#define FILE_SHARE_WRITE 0x00000002
#define FILE_SHARE_DELETE 0x00000004
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_DEVICE 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_FLAG_WRITE_THROUGH 0x80000000
#define FILE_FLAG_OVERLAPPED 0x40000000
#define FILE_FLAG_NO_BUFFERING 0x20000000
#define FILE_FLAG_RANDOM_ACCESS 0x10000000
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
#define FILE_BEGIN 0
#define FILE_CURRENT 1
#define FILE_END 2
#define CREATE_NEW 1
#define CREATE_ALWAYS 2
#define OPEN_EXISTING 3
#define OPEN_ALWAYS 4
#define TRUNCATE_EXISTING 5
#define PAGE_NOACCESS 0x01
#define PAGE_READONLY 0x02
#define PAGE_READWRITE 0x04
#define PAGE_WRITECOPY 0x08
#define PAGE_EXECUTE 0x10
#define PAGE_EXECUTE_READ 0x20
#define PAGE_EXECUTE_READWRITE 0x40
#define PAGE_EXECUTE_WRITECOPY 0x80
#define PAGE_GUARD 0x100
#define PAGE_NOCACHE 0x200
#define PAGE_WRITECOMBINE 0x400
#define PAGE_USER_READONLY 0x1000
#define PAGE_USER_READWRITE 0x2000
#define MEM_COMMIT 0x1000
#define MEM_RESERVE 0x2000
#define MEM_DECOMMIT 0x4000
#define MEM_RELEASE 0x8000
#define MEM_FREE 0x10000
#define MEM_PRIVATE 0x20000
#define MEM_RESET 0x80000
#define MEM_TOP_DOWN 0x100000
#define MEM_NOZERO 0x800000
#define MEM_LARGE_PAGES 0x20000000
#define MEM_HEAP 0x40000000
#define MEM_16MB_PAGES 0x80000000
#define IGNORE 0 // Ignore signal
#define INFINITE 0xFFFFFFFF // Infinite timeout
#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
#define STATUS_WAIT_0 ((DWORD )0x00000000L)
#define WAIT_OBJECT_0 ((STATUS_WAIT_0 ) + 0 )
#define STATUS_PENDING ((DWORD )0x00000103L)
#define STILL_ACTIVE STATUS_PENDING
DWORD GetLastError(VOID);
VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer);
DWORD GetTickCount();
BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
#define ERROR_SUCCESS 0L
#define ERROR_IO_PENDING 997L // dderror
#define ERROR_CANCELLED 1223L
#define S_OK ((HRESULT)0x00000000L)
#define S_FALSE ((HRESULT)0x00000001L)
#define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
#define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
#define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
#define MoveMemory RtlMoveMemory
#define CopyMemory RtlCopyMemory
#define FillMemory RtlFillMemory
#define ZeroMemory RtlZeroMemory
#define CDECL
#define APIENTRY
#define VK_ESCAPE 0x1B
#define VK_RETURN 0x0D
VOID OutputDebugStringW(LPCWSTR lpOutputString);
VOID OutputDebugString(LPCSTR lpOutputString);
VOID OutputDebugStringA(LPCSTR lpOutputString);
errno_t _itoa_s(int _Value, char * _DstBuf, size_t _Size, int _Radix);
errno_t _i64toa_s(__int64 _Val, char * _DstBuf, size_t _Size, int _Radix);
#define __declspec(a)
extern "C" int _wcsicmp (const wchar_t * dst, const wchar_t * src);
size_t wcsnlen(const wchar_t *wcs, size_t maxsize);
typedef struct _WIN32_FIND_DATAA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
CHAR cFileName[ MAX_PATH ];
CHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
typedef WIN32_FIND_DATAA WIN32_FIND_DATA;
typedef PWIN32_FIND_DATAA PWIN32_FIND_DATA;
typedef LPWIN32_FIND_DATAA LPWIN32_FIND_DATA;
typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
DWORD GetFileAttributesA(LPCSTR lpFileName);
#define GetFileAttributes GetFileAttributesA
typedef enum _GET_FILEEX_INFO_LEVELS {
GetFileExInfoStandard,
GetFileExMaxInfoLevel
} GET_FILEEX_INFO_LEVELS;
BOOL GetFileAttributesExA(LPCSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation);
#define GetFileAttributesEx GetFileAttributesExA
BOOL DeleteFileA(LPCSTR lpFileName);
#define DeleteFile DeleteFileA
HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
#define FindFirstFile FindFirstFileA
BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
#define FindNextFile FindNextFileA
#define FindClose(hFindFile) CloseHandle(hFindFile)
#ifdef _CONTENT_PACKAGE
#define PSVITA_STUBBED { }
#else
#define PSVITA_STUBBED { static bool bSet = false; if(!bSet){printf("missing function on PSVita : %s\n Tell MarkH about this, then press f5 to continue.\n", __FUNCTION__); bSet = true; SCE_BREAK();} }
#endif
DWORD XGetLanguage();
DWORD XGetLocale();
DWORD XEnableGuestSignin(BOOL fEnable);

View File

@@ -0,0 +1,237 @@
#include "stdafx.h"
#include "PSVitaTLSStorage.h"
#if 1
static PSVitaTLSStorage Singleton;
#define MAX_THREADS 64
typedef struct
{
int ThreadID;
LPVOID Value;
} TLSInfo;
typedef struct
{
TLSInfo *Array;
int Size;
} TLSArray;
static std::vector<TLSArray *> PSVitaTLSStorage_ActiveInfos;
void PSVitaTLSStorage::Init()
{
}
PSVitaTLSStorage *PSVitaTLSStorage::Instance()
{
return &Singleton;
}
DWORD PSVitaTLSStorage::Alloc()
{
TLSArray* Array = new TLSArray;
Array->Array = new TLSInfo[MAX_THREADS];
Array->Size = 0;
for( int i = 0;i < MAX_THREADS;i += 1 )
{
Array->Array[i].ThreadID = -1;
}
// add to the active infos
PSVitaTLSStorage_ActiveInfos.push_back(Array);
return (DWORD) Array;
}
BOOL PSVitaTLSStorage::Free(DWORD dwTlsIndex)
{
// remove from the active infos
std::vector<TLSArray *>::iterator iter = std::find(PSVitaTLSStorage_ActiveInfos.begin(), PSVitaTLSStorage_ActiveInfos.end(), (TLSArray *) dwTlsIndex);
PSVitaTLSStorage_ActiveInfos.erase(iter);
delete []((TLSInfo*)dwTlsIndex);
return 0;
}
void PSVitaTLSStorage::RemoveThread(int threadID)
{
// remove this thread from all the active Infos
std::vector<TLSArray *>::iterator iter = PSVitaTLSStorage_ActiveInfos.begin();
for( ; iter != PSVitaTLSStorage_ActiveInfos.end(); ++iter )
{
TLSArray* Array = ((TLSArray*)*iter);
for( int i = 0;i < Array->Size;i += 1 )
{
if( Array->Array[i].ThreadID == threadID )
{
// shift all the other entries down
for( ;i < MAX_THREADS - 1;i += 1 )
{
Array->Array[i].ThreadID = Array->Array[i+1].ThreadID;
Array->Array[i].Value = Array->Array[i+1].Value;
if( Array->Array[i].ThreadID != -1 )
{
Array->Size = i + 1;
}
}
// mark the top one as unused
Array->Array[i].ThreadID = -1;
break;
}
}
}
}
LPVOID PSVitaTLSStorage::GetValue(DWORD dwTlsIndex)
{
if( !dwTlsIndex )
{
return 0;
}
TLSArray* Array = ((TLSArray*)dwTlsIndex);
SceUID threadID = sceKernelGetThreadId();
for( int i = 0;i < Array->Size;i += 1 )
{
if( Array->Array[i].ThreadID == threadID )
{
return Array->Array[i].Value;
}
}
//assert(0);
return 0;
}
BOOL PSVitaTLSStorage::SetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
if( !dwTlsIndex )
{
return 0;
}
TLSArray* Array = ((TLSArray*)dwTlsIndex);
SceUID threadID = sceKernelGetThreadId();
for( int i = 0;i < Array->Size;i += 1 )
{
if( Array->Array[i].ThreadID == threadID || Array->Array[i].ThreadID == -1 )
{
Array->Array[i].ThreadID = threadID;
Array->Array[i].Value = lpTlsValue;
return 0;
}
}
if( Array->Size < MAX_THREADS )
{
Array->Array[Array->Size].ThreadID = threadID;
Array->Array[Array->Size].Value = lpTlsValue;
Array->Size++;
return 0;
}
assert(0);
return 0;
}
#else
PSVitaTLSStorage* m_pInstance = NULL;
#define sc_maxSlots 64
BOOL m_activeList[sc_maxSlots];
//__thread void* m_values[64];
// AP - Oh my. It seems __thread doesn't like cpp files. I couldn't get it to be thread sensitive as it would always return a shared value.
// For now I've stuck m_values and accessor functions into user_malloc.c. Cheap cheap hack.
extern "C"
{
void user_setValue( unsigned int _index, void* _val );
void* user_getValue( unsigned int _index );
}
void PSVitaTLSStorage::Init()
{
for(int i=0;i<sc_maxSlots; i++)
{
m_activeList[i] = false;
// m_values[i] = NULL;
}
}
PSVitaTLSStorage* PSVitaTLSStorage::Instance()
{
if ( m_pInstance == 0 ) // Is this the first time?
{
m_pInstance = new PSVitaTLSStorage; // Create the singleton instance.
m_pInstance->Init();
}
return m_pInstance;
}
DWORD PSVitaTLSStorage::Alloc()
{
for(int i=0; i<sc_maxSlots; i++)
{
if(m_activeList[i] == false)
{
m_activeList[i] = true;
// m_values[i] = NULL;
return i;
}
}
assert(0); // we've ran out of slots
return -1;
}
BOOL PSVitaTLSStorage::Free( DWORD _index )
{
if(m_activeList[_index] == false)
return false; // not been allocated
m_activeList[_index] = false;
// m_values[_index] = NULL;
return true;
}
BOOL PSVitaTLSStorage::SetValue( DWORD _index, LPVOID _val )
{
if(m_activeList[_index] == false)
return false;
user_setValue(_index, _val);
// m_values[_index] = _val;
return true;
}
LPVOID PSVitaTLSStorage::GetValue( DWORD _index )
{
if(m_activeList[_index] == false)
return NULL;
return user_getValue(_index);
// return m_values[_index];
}
void PSVitaTLSStorage::RemoveThread(int threadID)
{
for(int i=0; i<sc_maxSlots; i++)
{
//m_values[i] = NULL;
user_setValue(i, NULL);
}
}
// AP - Oh my. It seems __thread doesn't like cpp files. I couldn't get it to be thread sensitive as it would always return a shared value.
// For now I've stuck m_values and accessor functions into user_malloc.c. Cheap cheap hack.
__thread void* m_values[64];
void user_setValue( unsigned int _index, void* _val )
{
m_values[_index] = _val;
}
void* user_getValue( unsigned int _index )
{
return m_values[_index];
}
#endif

View File

@@ -0,0 +1,16 @@
#pragma once
class PSVitaTLSStorage
{
private:
public:
static void Init();
static PSVitaTLSStorage *Instance();
static DWORD Alloc();
static BOOL Free(DWORD dwTlsIndex);
static void RemoveThread(int UniqueID);
static LPVOID GetValue(DWORD dwTlsIndex);
static BOOL SetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
};

View File

@@ -0,0 +1,176 @@
#pragma once
//#include "winerror.h"
typedef unsigned int DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
typedef int __int32;
typedef FLOAT *PFLOAT;
typedef BOOL *PBOOL;
typedef BOOL *LPBOOL;
typedef BYTE *PBYTE;
typedef BYTE *LPBYTE;
typedef int *PINT;
typedef int *LPINT;
typedef WORD *PWORD;
typedef WORD *LPWORD;
typedef int *PLONG;
typedef int *LPLONG;
typedef DWORD *PDWORD;
typedef DWORD *LPDWORD;
typedef void *LPVOID;
typedef const void *LPCVOID;
typedef void *PVOID;
typedef unsigned int ULONG;
typedef unsigned char boolean;
typedef int INT;
typedef unsigned int UINT;
typedef unsigned int *PUINT;
typedef unsigned char byte;
typedef long long __int64;
typedef unsigned long long __uint64;
typedef unsigned int DWORD;
typedef int INT;
typedef unsigned long ULONG_PTR, *PULONG_PTR;
typedef ULONG_PTR SIZE_T, *PSIZE_T;
typedef __int64 LONG64, *PLONG64;
#define VOID void
typedef char CHAR;
typedef short SHORT;
typedef int LONG;
typedef long long LONGLONG;
typedef unsigned long long ULONGLONG;
#define CONST const
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
typedef WCHAR *PWCHAR;
typedef WCHAR *LPWCH, *PWCH;
typedef CONST WCHAR *LPCWCH, *PCWCH;
typedef WCHAR *NWPSTR;
typedef WCHAR *LPWSTR, *PWSTR;
typedef CONST WCHAR *LPCWSTR, *PCWSTR;
//
// ANSI (Multi-byte Character) types
//
typedef CHAR *PCHAR;
typedef CHAR *LPCH, *PCH;
typedef CONST CHAR *LPCCH, *PCCH;
typedef CHAR *NPSTR;
typedef CHAR *LPSTR, *PSTR;
typedef CONST CHAR *LPCSTR, *PCSTR;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef struct _FILETIME {
#ifdef _M_PPCBE
DWORD dwHighDateTime;
DWORD dwLowDateTime;
#else
DWORD dwLowDateTime;
DWORD dwHighDateTime;
#endif
} FILETIME, *PFILETIME, *LPFILETIME;
#if defined(MIDL_PASS)
typedef struct _LARGE_INTEGER {
#else // MIDL_PASS
typedef union _LARGE_INTEGER {
struct {
#if defined(_M_PPCBE)
LONG HighPart;
DWORD LowPart;
#else
DWORD LowPart;
LONG HighPart;
#endif
};
struct {
#if defined(_M_PPCBE)
LONG HighPart;
DWORD LowPart;
#else
DWORD LowPart;
LONG HighPart;
#endif
} u;
#endif //MIDL_PASS
LONGLONG QuadPart;
} LARGE_INTEGER;
typedef LARGE_INTEGER *PLARGE_INTEGER;
#if defined(MIDL_PASS)
typedef struct _ULARGE_INTEGER {
#else // MIDL_PASS
typedef union _ULARGE_INTEGER {
struct {
#if defined(_M_PPCBE)
DWORD HighPart;
DWORD LowPart;
#else
DWORD LowPart;
DWORD HighPart;
#endif
};
struct {
#if defined(_M_PPCBE)
DWORD HighPart;
DWORD LowPart;
#else
DWORD LowPart;
DWORD HighPart;
#endif
} u;
#endif //MIDL_PASS
ULONGLONG QuadPart;
} ULARGE_INTEGER;
typedef ULARGE_INTEGER *PULARGE_INTEGER;
// 360 specifics
typedef int HRESULT;
typedef void* HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
DECLARE_HANDLE(HINSTANCE);
typedef HINSTANCE HMODULE; /* HMODULEs can be used in place of HINSTANCEs */
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
DWORD Offset;
DWORD OffsetHigh;
HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;
typedef LPVOID PSECURITY_ATTRIBUTES;
typedef LPVOID LPSECURITY_ATTRIBUTES;
#define __in_ecount(a)
#define __in_bcount(a)
#ifndef AUTO_VAR
#define AUTO_VAR(_var, _val) auto _var = _val
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,204 @@
#include "stdafx.h"
#include "ShutdownManager.h"
#include "..\..\Common\Leaderboards\LeaderboardManager.h"
#include "..\..\MinecraftServer.h"
#ifdef __PS3__
#include "C4JSpursJob.h"
bool ShutdownManager::s_threadShouldRun[ShutdownManager::eThreadIdCount];
int ShutdownManager::s_threadRunning[ShutdownManager::eThreadIdCount];
CRITICAL_SECTION ShutdownManager::s_threadRunningCS;
C4JThread::EventArray *ShutdownManager::s_eventArray[eThreadIdCount];
#endif
// Initialises the shutdown manager - this needs to be called as soon as the game is started so it can respond as quickly as possible to shut down requests
void ShutdownManager::Initialise()
{
#ifdef __PS3__
cellSysutilRegisterCallback( 1, SysUtilCallback, NULL );
for( int i = 0; i < eThreadIdCount; i++ )
{
s_threadShouldRun[i] = true;
s_threadRunning[i] = 0;
s_eventArray[i] = NULL;
}
// Special case for storage manager, which we will manually set now to be considered as running - this will be unset by StorageManager.ExitRequest if required
s_threadRunning[eStorageManagerThreads] = true;
InitializeCriticalSection(&s_threadRunningCS);
#endif
}
// Called in response to a system request to exit the game. This just requests that the main thread should stop, and then the main thread is responsible for calling MainThreadHandleShutdown which
// starts the rest of the shut down process, then waits until it is complete.
void ShutdownManager::StartShutdown()
{
#ifdef __PS3__
s_threadShouldRun[ eMainThread ] = false;
#endif
}
// This should be called from the main thread after it has been requested to shut down (ShouldRun for main thread returns false), and before it returns control to the kernel. This is responsible for
// signalling to all other threads to stop, and wait until their completion before returning.
void ShutdownManager::MainThreadHandleShutdown()
{
#ifdef __PS3__
// Set flags for each thread which will be reset when they are complete
s_threadRunning[ eMainThread ] = false;
// Second wave of things we would like to shut down (after main)
LeaderboardManager::Instance()->CancelOperation();
RequestThreadToStop( eLeaderboardThread );
RequestThreadToStop( eCommerceThread );
RequestThreadToStop( ePostProcessThread );
RequestThreadToStop( eRunUpdateThread );
RequestThreadToStop( eRenderChunkUpdateThread );
RequestThreadToStop( eConnectionReadThreads );
RequestThreadToStop( eConnectionWriteThreads );
RequestThreadToStop( eEventQueueThreads );
app.DebugPrintf("Shutdown manager: waiting on first batch of threads requested to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
// Now shut down the server thread
MinecraftServer::HaltServer();
RequestThreadToStop( eServerThread );
app.DebugPrintf("Shutdown manager: waiting on server to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
//And shut down the storage manager
RequestThreadToStop( eStorageManagerThreads );
StorageManager.ExitRequest(&StorageManagerCompleteFn);
app.DebugPrintf("Shutdown manager: waiting on storage manager to terminate...\n");
WaitForSignalledToComplete();
app.DebugPrintf("Shutdown manager: terminated.\n");
// Audio system shutdown
app.DebugPrintf("Shutdown manager: Audio shutdown.\n");
AIL_shutdown();
// Trophy system shutdown
app.DebugPrintf("Shutdown manager: Trophy system shutdown.\n");
ProfileManager.Terminate();
// Network manager shutdown
app.DebugPrintf("Shutdown manager: Network manager shutdown.\n");
g_NetworkManager.Terminate();
// Finally shut down the spurs job queue - leaving until last so there should be nothing else dependent on this still running
app.DebugPrintf("Shutdown manager: SPURS shutdown.\n");
C4JSpursJobQueue::getMainJobQueue().shutdown();
app.DebugPrintf("Shutdown manager: Complete.\n");
#endif
}
void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]++;
LeaveCriticalSection(&s_threadRunningCS);
#endif
}
void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId, C4JThread::EventArray *eventArray)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]++;
LeaveCriticalSection(&s_threadRunningCS);
s_eventArray[threadId] = eventArray;
#endif
}
bool ShutdownManager::ShouldRun(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
return s_threadShouldRun[threadId];
#else
return true;
#endif
}
void ShutdownManager::HasFinished(ShutdownManager::EThreadId threadId)
{
#ifdef __PS3__
EnterCriticalSection(&s_threadRunningCS);
s_threadRunning[threadId]--;
LeaveCriticalSection(&s_threadRunningCS);
#endif
}
#ifdef __PS3__
void ShutdownManager::SysUtilCallback(uint64_t status, uint64_t param, void *userdata)
{
Minecraft *minecraft = Minecraft::GetInstance();
switch(status)
{
case CELL_SYSUTIL_REQUEST_EXITGAME:
app.DebugPrintf("CELL_SYSUTIL_REQUEST_EXITGAME\n");
StartShutdown();
break;
case CELL_SYSUTIL_SYSTEM_MENU_OPEN:
// Tell the game UI to stop processing
StorageManager.SetSystemUIDisplaying(true);
break;
case CELL_SYSUTIL_DRAWING_END:
StorageManager.SetSystemUIDisplaying(false);
break;
case CELL_SYSUTIL_DRAWING_BEGIN:
case CELL_SYSUTIL_SYSTEM_MENU_CLOSE:
break;
case CELL_SYSUTIL_BGMPLAYBACK_PLAY:
if( minecraft )
{
minecraft->soundEngine->updateSystemMusicPlaying(true);
}
app.DebugPrintf("BGM playing\n");
break;
case CELL_SYSUTIL_BGMPLAYBACK_STOP:
if( minecraft )
{
minecraft->soundEngine->updateSystemMusicPlaying(false);
}
app.DebugPrintf("BGM stopped\n");
break;
}
}
#endif
#ifdef __PS3__
void ShutdownManager::WaitForSignalledToComplete()
{
bool allComplete;
do
{
cellSysutilCheckCallback();
Sleep(10);
allComplete = true;
for( int i = 0; i < eThreadIdCount; i++ )
{
if( !s_threadShouldRun[i] )
{
if( s_threadRunning[i] != 0 ) allComplete = false;
}
}
} while( !allComplete);
}
void ShutdownManager::RequestThreadToStop(int i)
{
s_threadShouldRun[i] = false;
if( s_eventArray[i] )
{
s_eventArray[i]->Cancel();
}
}
void ShutdownManager::StorageManagerCompleteFn()
{
HasFinished(eStorageManagerThreads);
}
#endif

View File

@@ -0,0 +1,47 @@
#pragma once
class ShutdownManager
{
public:
typedef enum
{
eMainThread,
eLeaderboardThread,
eCommerceThread,
ePostProcessThread,
eRunUpdateThread,
eRenderChunkUpdateThread,
eServerThread,
eStorageManagerThreads,
eConnectionReadThreads,
eConnectionWriteThreads,
eEventQueueThreads,
eThreadIdCount
} EThreadId;
static void Initialise();
static void StartShutdown();
static void MainThreadHandleShutdown();
#ifdef __PS3__
static void SysUtilCallback(uint64_t status, uint64_t param, void *userdata);
#endif
static void HasStarted(EThreadId threadId);
static void HasStarted(EThreadId threadId, C4JThread::EventArray *eventArray);
static bool ShouldRun(EThreadId threadId);
static void HasFinished(EThreadId threadId);
private:
#ifdef __PS3__
static bool s_threadShouldRun[eThreadIdCount];
static int s_threadRunning[eThreadIdCount];
static CRITICAL_SECTION s_threadRunningCS;
static C4JThread::EventArray *s_eventArray[eThreadIdCount];
static void RequestThreadToStop(int i);
static void WaitForSignalledToComplete();
static void StorageManagerCompleteFn();
#endif
};

View File

@@ -0,0 +1,72 @@
#include "stdafx.h"
TLSStoragePSVita* TLSStoragePSVita::m_pInstance = NULL;
BOOL TLSStoragePSVita::m_activeList[sc_maxSlots];
__thread LPVOID TLSStoragePSVita::m_values[sc_maxSlots];
TLSStoragePSVita::TLSStoragePSVita()
{
for(int i=0;i<sc_maxSlots; i++)
{
m_activeList[i] = false;
m_values[i] = NULL;
}
}
TLSStoragePSVita* TLSStoragePSVita::Instance()
{
if ( m_pInstance == 0 ) // Is this the first time?
{
m_pInstance = new TLSStoragePSVita; // Create the singleton instance.
}
return m_pInstance;
}
int TLSStoragePSVita::Alloc()
{
for(int i=0; i<sc_maxSlots; i++)
{
if(m_activeList[i] == false)
{
m_activeList[i] = true;
m_values[i] = NULL;
return i;
}
}
assert(0); // we've ran out of slots
return -1;
}
BOOL TLSStoragePSVita::Free( DWORD _index )
{
if(m_activeList[_index] == false)
return false; // not been allocated
m_activeList[_index] = false;
m_values[_index] = NULL;
return true;
}
BOOL TLSStoragePSVita::SetValue( DWORD _index, LPVOID _val )
{
if(m_activeList[_index] == false)
return false;
m_values[_index] = _val;
return true;
}
LPVOID TLSStoragePSVita::GetValue( DWORD _index )
{
if(m_activeList[_index] == false)
return NULL;
return m_values[_index];
}

View File

@@ -0,0 +1,25 @@
#pragma once
#pragma once
class TLSStoragePSVita
{
static TLSStoragePSVita* m_pInstance;
static const int sc_maxSlots = 64;
static BOOL m_activeList[sc_maxSlots];
static __thread LPVOID m_values[sc_maxSlots];
public:
TLSStoragePSVita();
// Retrieve singleton instance.
static TLSStoragePSVita* Instance();
int Alloc();
BOOL Free(DWORD _index);
BOOL SetValue(DWORD _index, LPVOID _val);
LPVOID GetValue(DWORD _index);
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,390 @@
/* SCE CONFIDENTIAL
PlayStation(R)Vita Programmer Tool Runtime Library Release 03.000.061
* Copyright (C) 2012 Sony Computer Entertainment Inc.
* All Rights Reserved.
*/
// AP - this is a modified version of the basic sony memory overide functions.
// It was found from profiling that threads were stalling far too much waiting for their turn to malloc/free
// This manager will keep memory bound to a thread once allocated so it can be reused by the same thread later.
// It's only interested in chunks up to 1036 bytes in size, anything greater is not retained
// Todo : I may need to put in a memory flusher if I find threads holding onto memory too much.
#include <stdlib.h>
#include <mspace.h>
#include <kernel.h>
//#include <libdbg.h>
#include <assert.h>
#define HEAP_SIZE (164 * 1024 * 1024)
#define HEAP_ERROR1 1
#define HEAP_ERROR2 2
#define HEAP_ERROR3 3
static SceUID s_heapUid;
static mspace s_mspace;
void user_malloc_init(void);
void user_malloc_finalize(void);
void *user_malloc(size_t size);
void user_free(void *ptr);
void *user_calloc(size_t nelem, size_t size);
void *user_realloc(void *ptr, size_t size);
void *user_memalign(size_t boundary, size_t size);
void *user_reallocalign(void *ptr, size_t size, size_t boundary);
int user_malloc_stats(struct malloc_managed_size *mmsize);
int user_malloc_stats_fast(struct malloc_managed_size *mmsize);
size_t user_malloc_usable_size(void *ptr);
// this is our basic node for managing stacks
typedef struct Block
{
void* Memory;
struct Block *Next;
} Block;
#define MaxRetainedBytes 1036
#define Malloc_BlocksMemorySize 1024
typedef struct
{
Block **Malloc_MemoryPool; // this is an array of available memory allocations up to 1036 bytes in size
Block *Malloc_Blocks; // this is a stack of available block nodes used to store memory chunks
Block *Malloc_BlocksMemory[Malloc_BlocksMemorySize]; // this is a pool of block nodes allocated in large chunks (256 blocks at a time)
int Malloc_BlocksAlloced; // this shows how many block node chunks have been allocated in Malloc_BlocksMemory
} SThreadStorage;
__thread SThreadStorage *Malloc_ThreadStorage = NULL;
/**E Replace _malloc_init function. */
/**J _malloc_init 関数と置き換わる */
void user_malloc_init(void)
{
int res;
void *base = NULL;
/**E Allocate a memory block from the kernel */
/**J カーネルからメモリブロックを確保する */
s_heapUid = sceKernelAllocMemBlock("UserAllocator", SCE_KERNEL_MEMBLOCK_TYPE_USER_RWDATA, HEAP_SIZE, SCE_NULL);
if (s_heapUid < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR1);
} else {
/**E Obtain the address of the allocated memory block */
/**J 確保したメモリブロックのアドレスを取得する */
res = sceKernelGetMemBlockBase(s_heapUid, &base);
if (res < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR2);
} else {
/**E Generate mspace */
/**J mspace を生成する */
s_mspace = mspace_create(base, HEAP_SIZE);
if (s_mspace == NULL) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR3);
}
}
}
}
/**E Replace _malloc_finalize function. */
/**J _malloc_finalize 関数と置き換わる */
void user_malloc_finalize(void)
{
int res;
if (s_mspace != NULL) {
/**E Free mspace */
/**J mspace を解放する */
res = mspace_destroy(s_mspace);
if (res != 0) {
/**E Error handling */
/**J エラー処理 */
__breakpoint(0);
}
s_mspace = NULL;
}
if (SCE_OK <= s_heapUid) {
/**E Free the memory block */
/**J メモリブロックを解放する */
#if 0
res = sceKernelFreeMemBlock(s_heapUid);
if (res < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
__breakpoint(0);
}
#endif
}
}
// before a thread can use the memory system it should register itself
void user_registerthread()
{
Malloc_ThreadStorage = mspace_malloc(s_mspace, sizeof(SThreadStorage));
Malloc_ThreadStorage->Malloc_Blocks = NULL;
Malloc_ThreadStorage->Malloc_BlocksAlloced = 0;
Malloc_ThreadStorage->Malloc_MemoryPool = NULL;
}
// before a thread is destroyed make sure we free any space it might be holding on to
void user_removethread()
{
SThreadStorage *psStorage = Malloc_ThreadStorage;
if( psStorage )
{
if( psStorage->Malloc_MemoryPool )
{
for( int j = 0;j < 1037;j += 1 )
{
Block *OldBlock = psStorage->Malloc_MemoryPool[j];
while( OldBlock )
{
mspace_free(s_mspace, OldBlock->Memory);
OldBlock = OldBlock->Next;
}
}
mspace_free(s_mspace, psStorage->Malloc_MemoryPool);
}
for( int j = 0;j < psStorage->Malloc_BlocksAlloced;j += 1 )
{
free(psStorage->Malloc_BlocksMemory[j]);
}
mspace_free(s_mspace, psStorage);
Malloc_ThreadStorage = NULL;
}
}
/**E Replace malloc function. */
/**J malloc 関数と置き換わる */
void *user_malloc(size_t size)
{
void *p = NULL;
SThreadStorage *psStorage = Malloc_ThreadStorage;
if( psStorage )
{
// is this the first time we've malloced
if( psStorage->Malloc_MemoryPool == NULL )
{
// create an array of pointers to Block nodes, one pointer for each memory bytes size up to 1036
psStorage->Malloc_MemoryPool = mspace_malloc(s_mspace, (MaxRetainedBytes+1) * 4);
for( int i = 0;i < (MaxRetainedBytes+1);i += 1 )
{
psStorage->Malloc_MemoryPool[i] = NULL;
}
}
// are we interested in retaining this size of memory (less 4 bytes to store the associated thread ID)
if( size < (MaxRetainedBytes-4) )
{
// add on space for the thread ID
size += 4;
// round to the nearest malloc boundary. This is what happens internally in the malloc library
if( size <= 12 )
size = 12;
else
size = ((size - 12) & 0xfffffff0) + 16 + 12;
// do we have any memory of this size retained
if( psStorage->Malloc_MemoryPool[size] )
{
// pop it from the retained pool
Block * OldBlock = psStorage->Malloc_MemoryPool[size];
psStorage->Malloc_MemoryPool[size] = OldBlock->Next;
p = OldBlock->Memory;
// push the block storage onto the stack
OldBlock->Next = psStorage->Malloc_Blocks;
psStorage->Malloc_Blocks = OldBlock;
}
else
{
// create some new memory
p = mspace_malloc(s_mspace, size);
// store the thread ID in the last 4 bytes
unsigned int threadID = sceKernelGetThreadId();
unsigned int *ThreadAddr = (unsigned int *) ((unsigned char*) p + (size - 4));
ThreadAddr[0] = threadID;
}
}
else
{
p = mspace_malloc(s_mspace, size);
}
}
else
{
p = mspace_malloc(s_mspace, size);
}
// SCE_DBG_LOG_TRACE("Called malloc(%u)", size);
return p;
}
/**E Replace free function. */
/**J free 関数と置き換わる */
void user_free(void *ptr)
{
if( !ptr || !s_mspace )
{
return;
}
SThreadStorage *psStorage = Malloc_ThreadStorage;
if( psStorage )
{
// calc the size of this chunk rounding to a valid size
unsigned int size = ((unsigned int*)ptr)[-1] - 7;
unsigned int RoundedSize = (size & 0xfffffff0) + 12;
if( RoundedSize < (MaxRetainedBytes+1) )
{
// grab the thread ID from the last 4 bytes
unsigned int *ThreadAddr = (unsigned int *) ((unsigned char*) ptr + (RoundedSize - 4));
// did this thread create this memory
if( sceKernelGetThreadId() != ThreadAddr[0] )
{
// don't worry about retaining memory allocated from a different thread. too much mucking about
mspace_free(s_mspace, ptr);
return;
}
// we need a block node to retain the memory on our stack. do we have any block nodes available
if( psStorage->Malloc_Blocks == NULL )
{
if( psStorage->Malloc_BlocksAlloced == Malloc_BlocksMemorySize )
{
// Max blocks allocated
// The worst case for this running out is when the player has explored a large amount of the map in a single session and then quits. All the allocations
// are suddenly freed up so we need lots of space to store them.
printf("oh nos, max blocks allocated. increase Malloc_BlocksMemorySize");
assert(0);
}
// allocate some more block space in a large chunk
int chunkSize = 256;
psStorage->Malloc_BlocksMemory[psStorage->Malloc_BlocksAlloced] = mspace_malloc(s_mspace, chunkSize * sizeof(Block));
// push all the new blocks onto the pool
for(int i = 0;i < chunkSize;i += 1 )
{
Block *NewBlock = &psStorage->Malloc_BlocksMemory[psStorage->Malloc_BlocksAlloced][i];
NewBlock->Next = psStorage->Malloc_Blocks;
psStorage->Malloc_Blocks = NewBlock;
}
psStorage->Malloc_BlocksAlloced++;
}
// pop a block node off the stack
Block *NewBlock = psStorage->Malloc_Blocks;
psStorage->Malloc_Blocks = NewBlock->Next;
// set up the block data and retain it to the correct slot. We can now reuse this memory on the next malloc
NewBlock->Memory = ptr;
NewBlock->Next = psStorage->Malloc_MemoryPool[RoundedSize];
psStorage->Malloc_MemoryPool[RoundedSize] = NewBlock;
}
else
{
mspace_free(s_mspace, ptr);
}
}
else
{
mspace_free(s_mspace, ptr);
}
}
/**E Replace calloc function. */
/**J calloc 関数と置き換わる */
void *user_calloc(size_t nelem, size_t size)
{
// SCE_DBG_LOG_TRACE("Called calloc(%u, %u)", nelem, size);
return mspace_calloc(s_mspace, nelem, size);
}
/**E Replace realloc function. */
/**J realloc 関数と置き換わる */
void *user_realloc(void *ptr, size_t size)
{
void* p = NULL;
if( Malloc_ThreadStorage )
{
// make sure we use malloc/memcpy/free instead of realloc
p = user_malloc(size);
unsigned int OldSize;
unsigned int OldRoundedSize;
if( ptr )
{
// calc the size of this chunk rounding to a valid size
OldSize = ((unsigned int*)ptr)[-1] - 7;
OldRoundedSize = (OldSize & 0xfffffff0) + 12;
memcpy(p, ptr, OldRoundedSize);
user_free(ptr);
}
}
else
{
p = mspace_realloc(s_mspace, ptr, size);
}
return p;
// SCE_DBG_LOG_TRACE("Called realloc(%p, %u)", ptr, size);
// return mspace_realloc(s_mspace, ptr, size);
}
/**E Replace memalign function. */
/**J memalign 関数と置き換わる */
void *user_memalign(size_t boundary, size_t size)
{
// SCE_DBG_LOG_TRACE("Called memalign(%u, %u)", boundary, size);
return mspace_memalign(s_mspace, boundary, size);
}
/**E Replace reallocalign function. */
/**J reallocalign 関数と置き換わる */
void *user_reallocalign(void *ptr, size_t size, size_t boundary)
{
// SCE_DBG_LOG_TRACE("Called reallocalign(%p, %u, %u)", ptr, size, boundary);
return mspace_reallocalign(s_mspace, ptr, size, boundary);
}
/**E Replace malloc_stats function. */
/**J malloc_stats 関数と置き換わる */
int user_malloc_stats(struct malloc_managed_size *mmsize)
{
// SCE_DBG_LOG_TRACE("Called malloc_stats");
return mspace_malloc_stats(s_mspace, mmsize);
}
/**E Replace malloc_stats_fast function. */
/**J malloc_stata_fast 関数と置き換わる */
int user_malloc_stats_fast(struct malloc_managed_size *mmsize)
{
// SCE_DBG_LOG_TRACE("Called malloc_stats_fast");
return mspace_malloc_stats_fast(s_mspace, mmsize);
}
/**E Replace malloc_usable_size function. */
/**J malloc_usable_size 関数と置き換わる */
size_t user_malloc_usable_size(void *ptr)
{
// SCE_DBG_LOG_TRACE("Called malloc_usable_size");
return mspace_malloc_usable_size(ptr);
}

View File

@@ -0,0 +1,103 @@
/* SCE CONFIDENTIAL
PlayStation(R)Vita Programmer Tool Runtime Library Release 03.000.061
* Copyright (C) 2012 Sony Computer Entertainment Inc.
* All Rights Reserved.
*/
#include <stdlib.h>
#include <mspace.h>
#include <kernel.h>
//#include <libdbg.h>
#define HEAP_SIZE (1024 * 1024)
#define HEAP_ERROR1 1
#define HEAP_ERROR2 2
#define HEAP_ERROR3 3
static SceUID s_heapUid;
static mspace s_mspace;
void user_malloc_for_tls_init(void);
void user_malloc_for_tls_finalize(void);
void *user_malloc_for_tls(size_t size);
void user_free_for_tls(void *ptr);
/**E Replace _malloc_for_tls_init function. */
/**J _malloc_for_tls_init 関数と置き換わる */
void user_malloc_for_tls_init(void)
{
int res;
void *base = NULL;
/**E Allocate a memory block from the kernel */
/**J カーネルからメモリブロックを確保する */
s_heapUid = sceKernelAllocMemBlock("UserAllocatorForTLS", SCE_KERNEL_MEMBLOCK_TYPE_USER_RWDATA, HEAP_SIZE, SCE_NULL);
if (s_heapUid < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR1);
} else {
/**E Obtain the address of the allocated memory block */
/**J 確保したメモリブロックのアドレスを取得する */
res = sceKernelGetMemBlockBase(s_heapUid, &base);
if (res < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR2);
} else {
/**E Generate mspace */
/**J mspace を生成する */
s_mspace = mspace_create(base, HEAP_SIZE);
if (s_mspace == NULL) {
/**E Error handling */
/**J エラー処理 */
sceLibcSetHeapInitError(HEAP_ERROR3);
}
}
}
}
/**E Replace _malloc_for_tls_finalize function. */
/**J _malloc_for_tls_finalize 関数と置き換わる */
void user_malloc_for_tls_finalize(void)
{
int res;
if (s_mspace != NULL) {
/**E Free mspace */
/**J mspace を解放する */
res = mspace_destroy(s_mspace);
if (res != 0) {
/**E Error handling */
/**J エラー処理 */
__breakpoint(0);
}
}
if (SCE_OK <= s_heapUid) {
/**E Free the memory block */
/**J メモリブロックを解放する */
res = sceKernelFreeMemBlock(s_heapUid);
if (res < SCE_OK) {
/**E Error handling */
/**J エラー処理 */
__breakpoint(0);
}
}
}
/**E Replace _malloc_for_tls function. */
/**J _malloc_for_tls 関数と置き換わる */
void *user_malloc_for_tls(size_t size)
{
// SCE_DBG_LOG_TRACE("Called malloc_for_tls(%u)", size);
return mspace_malloc(s_mspace, size);
}
/**E Replace _free_for_tls function. */
/**J _free_for_tls 関数と置き換わる */
void user_free_for_tls(void *ptr)
{
// SCE_DBG_LOG_TRACE("Called free_for_tls(%p)", ptr);
mspace_free(s_mspace, ptr);
}

View File

@@ -0,0 +1,131 @@
/* SCE CONFIDENTIAL
PlayStation(R)Vita Programmer Tool Runtime Library Release 03.000.061
* Copyright (C) 2012 Sony Computer Entertainment Inc.
* All Rights Reserved.
*/
#include <new>
#include <cstdlib>
//#include <libdbg.h>
void *user_new(std::size_t size) throw(std::bad_alloc);
void *user_new(std::size_t size, const std::nothrow_t& x) throw();
void *user_new_array(std::size_t size) throw(std::bad_alloc);
void *user_new_array(std::size_t size, const std::nothrow_t& x) throw();
void user_delete(void *ptr) throw();
void user_delete(void *ptr, const std::nothrow_t& x) throw();
void user_delete_array(void *ptr) throw();
void user_delete_array(void *ptr, const std::nothrow_t& x) throw();
/**E Replace operator new. */
/**J operator new と置き換わる */
void *user_new(std::size_t size) throw(std::bad_alloc)
{
void *ptr;
// SCE_DBG_LOG_TRACE("Called operator new(%u)", size);
if (size == 0)
size = 1;
while ((ptr = (void *)std::malloc(size)) == NULL) {
/**E Obtain new_handler */
/**J new_handler を取得する */
std::new_handler handler = std::_get_new_handler();
/**E When new_handler is a NULL pointer, bad_alloc is send. If not, new_handler is called. */
/**J new_handler が NULL ポインタの場合、bad_alloc を送出する、そうでない場合、new_handler を呼び出す */
if (!handler)
throw std::bad_alloc();
else
(*handler)();
}
return ptr;
}
/**E Replace operator new(std::nothrow). */
/**J operator(std::nothrow) と置き換わる */
void *user_new(std::size_t size, const std::nothrow_t& x) throw()
{
void *ptr;
(void)x;
// SCE_DBG_LOG_TRACE("Called operator new(nothrow)(%u)", size);
if (size == 0)
size = 1;
while ((ptr = (void *)std::malloc(size)) == NULL) {
/**E Obtain new_handler */
/**J new_handler を取得する */
std::new_handler handler = std::_get_new_handler();
/**E When new_handler is a NULL pointer, NULL is returned. */
/**J new_handler が NULL ポインタの場合、NULL を返す */
if (!handler)
return NULL;
/**E Call new_handler. If new_handler sends bad_alloc, NULL is returned. */
/**J new_handler を呼び出す、new_handler が bad_alloc を送出した場合、NULL を返す */
try {
(*handler)();
} catch (std::bad_alloc) {
return NULL;
}
}
return ptr;
}
/**E Replace operator new[]. */
/**J operator new[] と置き換わる */
void *user_new_array(std::size_t size) throw(std::bad_alloc)
{
// SCE_DBG_LOG_TRACE("Called operator new[](%u)", size);
return user_new(size);
}
/**E Replace operator new[](std::nothrow). */
/**J operator new[](std::nothrow) と置き換わる */
void *user_new_array(std::size_t size, const std::nothrow_t& x) throw()
{
// SCE_DBG_LOG_TRACE("Called operator new(nothrow)[](%u)", size);
return user_new(size, x);
}
/**E Replace operator delete. */
/**J operator delete と置き換わる */
void user_delete(void *ptr) throw()
{
// SCE_DBG_LOG_TRACE("Called operator delete(%p)", ptr);
/**E In the case of the NULL pointer, no action will be taken. */
/**J NULL ポインタの場合、何も行わない */
if (ptr != NULL)
std::free(ptr);
}
/**E Replace operator delete(std::nothrow). */
/**J operator delete(std::nothrow) と置き換わる */
void user_delete(void *ptr, const std::nothrow_t& x) throw()
{
(void)x;
// SCE_DBG_LOG_TRACE("Called operator delete(nothrow)(%p)", ptr);
user_delete(ptr);
}
/**E Replace operator delete[]. */
/**J operator delete[] と置き換わる */
void user_delete_array(void *ptr) throw()
{
// SCE_DBG_LOG_TRACE("Called operator delete[](%p)", ptr);
user_delete(ptr);
}
/**E Replace operator delete[](std::nothrow). */
/**J operator delete[](std::nothrow) と置き換わる */
void user_delete_array(void *ptr, const std::nothrow_t& x) throw()
{
// SCE_DBG_LOG_TRACE("Called operator delete(nothrow)[](%p)", ptr);
user_delete(ptr, x);
}

View File

@@ -0,0 +1,511 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2013 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef ZCONF_H
#define ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
* Even better than compiling with -DZ_PREFIX would be to use configure to set
* this permanently in zconf.h using "./configure --zprefix".
*/
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET
/* all linked symbols */
# define _dist_code z__dist_code
# define _length_code z__length_code
# define _tr_align z__tr_align
# define _tr_flush_bits z__tr_flush_bits
# define _tr_flush_block z__tr_flush_block
# define _tr_init z__tr_init
# define _tr_stored_block z__tr_stored_block
# define _tr_tally z__tr_tally
# define adler32 z_adler32
# define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64
# ifndef Z_SOLO
# define compress z_compress
# define compress2 z_compress2
# define compressBound z_compressBound
# endif
# define crc32 z_crc32
# define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64
# define deflate z_deflate
# define deflateBound z_deflateBound
# define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams
# define deflatePending z_deflatePending
# define deflatePrime z_deflatePrime
# define deflateReset z_deflateReset
# define deflateResetKeep z_deflateResetKeep
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO
# define gz_error z_gz_error
# define gz_intmax z_gz_intmax
# define gz_strwinerror z_gz_strwinerror
# define gzbuffer z_gzbuffer
# define gzclearerr z_gzclearerr
# define gzclose z_gzclose
# define gzclose_r z_gzclose_r
# define gzclose_w z_gzclose_w
# define gzdirect z_gzdirect
# define gzdopen z_gzdopen
# define gzeof z_gzeof
# define gzerror z_gzerror
# define gzflush z_gzflush
# define gzgetc z_gzgetc
# define gzgetc_ z_gzgetc_
# define gzgets z_gzgets
# define gzoffset z_gzoffset
# define gzoffset64 z_gzoffset64
# define gzopen z_gzopen
# define gzopen64 z_gzopen64
# ifdef _WIN32
# define gzopen_w z_gzopen_w
# endif
# define gzprintf z_gzprintf
# define gzvprintf z_gzvprintf
# define gzputc z_gzputc
# define gzputs z_gzputs
# define gzread z_gzread
# define gzrewind z_gzrewind
# define gzseek z_gzseek
# define gzseek64 z_gzseek64
# define gzsetparams z_gzsetparams
# define gztell z_gztell
# define gztell64 z_gztell64
# define gzungetc z_gzungetc
# define gzwrite z_gzwrite
# endif
# define inflate z_inflate
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
# define inflateBackInit_ z_inflateBackInit_
# define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd
# define inflateGetHeader z_inflateGetHeader
# define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2
# define inflateSetDictionary z_inflateSetDictionary
# define inflateGetDictionary z_inflateGetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine
# define inflateResetKeep z_inflateResetKeep
# define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
# ifndef Z_SOLO
# define uncompress z_uncompress
# endif
# define zError z_zError
# ifndef Z_SOLO
# define zcalloc z_zcalloc
# define zcfree z_zcfree
# endif
# define zlibCompileFlags z_zlibCompileFlags
# define zlibVersion z_zlibVersion
/* all zlib typedefs in zlib.h and zconf.h */
# define Byte z_Byte
# define Bytef z_Bytef
# define alloc_func z_alloc_func
# define charf z_charf
# define free_func z_free_func
# ifndef Z_SOLO
# define gzFile z_gzFile
# endif
# define gz_header z_gz_header
# define gz_headerp z_gz_headerp
# define in_func z_in_func
# define intf z_intf
# define out_func z_out_func
# define uInt z_uInt
# define uIntf z_uIntf
# define uLong z_uLong
# define uLongf z_uLongf
# define voidp z_voidp
# define voidpc z_voidpc
# define voidpf z_voidpf
/* all zlib structs in zlib.h and zconf.h */
# define gz_header_s z_gz_header_s
# define internal_state z_internal_state
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
# define OS2
#endif
#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
# ifndef WIN32
# define WIN32
# endif
#endif
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
# ifndef SYS16BIT
# define SYS16BIT
# endif
# endif
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#ifdef SYS16BIT
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#ifdef __STDC_VERSION__
# ifndef STDC
# define STDC
# endif
# if __STDC_VERSION__ >= 199901L
# ifndef STDC99
# define STDC99
# endif
# endif
#endif
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
# define STDC
#endif
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# define STDC
#endif
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define STDC
#endif
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC
#endif
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
#if defined(ZLIB_CONST) && !defined(z_const)
# define z_const const
#else
# define z_const
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
#ifndef Z_ARG /* function prototypes for stdarg */
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
# define Z_ARG(args) args
# else
# define Z_ARG(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
# endif
# if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */
# define SMALL_MEDIUM
# ifdef __BORLANDC__
# define FAR _far
# else
# define FAR far
# endif
# endif
#endif
#if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR CDECL
# endif
# endif
#endif
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport)
# else
# define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport)
# endif
# endif
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte const *voidpc;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (UINT_MAX == 0xffffffffUL)
# define Z_U4 unsigned
# elif (ULONG_MAX == 0xffffffffUL)
# define Z_U4 unsigned long
# elif (USHRT_MAX == 0xffffffffUL)
# define Z_U4 unsigned short
# endif
#endif
#ifdef Z_U4
typedef Z_U4 z_crc_t;
#else
typedef unsigned long z_crc_t;
#endif
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H
#endif
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_STDARG_H
#endif
#ifdef STDC
# ifndef Z_SOLO
//# include <sys/types.h> /* for off_t */
# endif
#endif
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifndef Z_SOLO
# include <stdarg.h> /* for va_list */
# endif
#endif
#ifdef _WIN32
# ifndef Z_SOLO
# include <stddef.h> /* for wchar_t */
# endif
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
* though the former does not conform to the LFS document), but considering
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
* equivalently requesting no 64-bit operations
*/
#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
# undef _LARGEFILE64_SOURCE
#endif
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
# define Z_HAVE_UNISTD_H
#endif
#ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# ifndef z_off_t
# define z_off_t off_t
# endif
# endif
#endif
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
# define Z_LFS64
#endif
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
# define Z_LARGE64
#endif
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
# define Z_WANT64
#endif
#if !defined(SEEK_SET) && !defined(Z_SOLO)
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
# define z_off64_t __int64
# else
# define z_off64_t z_off_t
# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
#pragma map(deflateInit_,"DEIN")
#pragma map(deflateInit2_,"DEIN2")
#pragma map(deflateEnd,"DEEND")
#pragma map(deflateBound,"DEBND")
#pragma map(inflateInit_,"ININ")
#pragma map(inflateInit2_,"ININ2")
#pragma map(inflateEnd,"INEND")
#pragma map(inflateSync,"INSY")
#pragma map(inflateSetDictionary,"INSEDI")
#pragma map(compressBound,"CMBND")
#pragma map(inflate_table,"INTABL")
#pragma map(inflate_fast,"INFA")
#pragma map(inflate_copyright,"INCOPY")
#endif
#endif /* ZCONF_H */

File diff suppressed because it is too large Load Diff