the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 114 lines 2.8 kB view raw
1/* SCE CONFIDENTIAL 2 PlayStation(R)4 Programmer Tool Runtime Library Release 01.600.051 3 * Copyright (C) 2013 Sony Computer Entertainment Inc. 4 * All Rights Reserved. 5 */ 6extern "C" 7{ 8 9#include <stdlib.h> 10#include <mspace.h> 11#include <kernel.h> 12 13#define HEAP_SIZE (4 * 1024 * 1024) 14 15static SceLibcMspace s_mspace; 16static off_t s_memStart; 17static size_t s_memLength = 4 * 1024 * 1024; 18static size_t s_memAlign = 2 * 1024 * 1024; 19 20int user_malloc_init_for_tls(void); 21int user_malloc_fini_for_tls(void); 22void *user_malloc_for_tls(size_t size); 23void user_free_for_tls(void *ptr); 24int user_posix_memalign_for_tls(void **ptr, size_t boundary, size_t size); 25 26//E Replace _malloc_init_for_tls function. 27//J _malloc_init_for_tls 関数と置き換わる 28int user_malloc_init_for_tls(void) 29{ 30 int res; 31 void *addr; 32 33 //E Allocate direct memory 34 //J ダイレクトメモリを割り当てる 35 res = sceKernelAllocateDirectMemory(0, SCE_KERNEL_MAIN_DMEM_SIZE, s_memLength, s_memAlign, SCE_KERNEL_WB_ONION, &s_memStart); 36 if (res < 0) { 37 //E Error handling 38 //J エラー処理 39 return 1; 40 } 41 42 addr = NULL; 43 //E Map direct memory to the process address space 44 //J ダイレクトメモリをプロセスアドレス空間にマップする 45 res = sceKernelMapDirectMemory(&addr, HEAP_SIZE, SCE_KERNEL_PROT_CPU_READ | SCE_KERNEL_PROT_CPU_WRITE, 0, s_memStart, s_memAlign); 46 if (res < 0) { 47 //E Error handling 48 //J エラー処理 49 return 1; 50 } 51 52 //E Generate mspace 53 //J mspace を生成する 54 s_mspace = sceLibcMspaceCreate("User Malloc For TLS", addr, HEAP_SIZE, 0); 55 if (s_mspace == NULL) { 56 //E Error handling 57 //J エラー処理 58 return 1; 59 } 60 61 return 0; 62} 63 64//E Replace _malloc_fini_for_tls function. 65//J _malloc_fini_for_tls 関数と置き換わる 66int user_malloc_fini_for_tls(void) 67{ 68 int res; 69 70 if (s_mspace != NULL) { 71 //E Free mspace 72 //J mspace を解放する 73 res = sceLibcMspaceDestroy(s_mspace); 74 if (res != 0) { 75 //E Error handling 76 //J エラー処理 77 return 1; 78 } 79 } 80 81 //E Release direct memory 82 //J ダイレクトメモリを解放する 83 res = sceKernelReleaseDirectMemory(s_memStart, s_memLength); 84 if (res < 0) { 85 //E Error handling 86 //J エラー処理 87 return 1; 88 } 89 90 return 0; 91} 92 93//E Replace _malloc_for_tls function. 94//J _malloc_for_tls 関数と置き換わる 95void *user_malloc_for_tls(size_t size) 96{ 97 return sceLibcMspaceMalloc(s_mspace, size); 98} 99 100//E Replace _free_for_tls function. 101//J _free_for_tls 関数と置き換わる 102void user_free_for_tls(void *ptr) 103{ 104 sceLibcMspaceFree(s_mspace, ptr); 105} 106 107//E Replace _posix_memalign_for_tls function. 108//J _posix_memalign_for_tls 関数と置き換わる 109int user_posix_memalign_for_tls(void **ptr, size_t boundary, size_t size) 110{ 111 return sceLibcMspacePosixMemalign(s_mspace, ptr, boundary, size); 112} 113 114} // extern "c"