taiHEN  1.0
CFW framework for PS Vita
posix-compat.c
1 /* posix-compat.c -- POSIX functions for libsubstitute to use
2  *
3  * Copyright (C) 2016 Yifan Lu
4  *
5  * This software may be modified and distributed under the terms
6  * of the MIT license. See the LICENSE file for details.
7  */
8 #include <psp2kern/types.h>
9 #include <psp2kern/kernel/sysmem.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
14 extern SceUID g_patch_pool;
15 
23 void *malloc(size_t size) {
24  void *ptr;
25  ptr = sceKernelMemPoolAlloc(g_patch_pool, size + sizeof(size_t));
26  if (ptr) {
27  *(size_t *)ptr = size;
28  ptr = (char *)ptr + sizeof(size_t);
29  }
30  return ptr;
31 }
32 
38 void free(void *ptr) {
39  sceKernelMemPoolFree(g_patch_pool, (char *)ptr - sizeof(size_t));
40 }
41 
50 void *realloc(void *ptr, size_t size) {
51  void *dup;
52  size_t oldsize;
53 
54  dup = malloc(size);
55  if (dup) {
56  oldsize = *(size_t *)((char *)ptr - sizeof(size_t));
57  if (oldsize > size) {
58  oldsize = size;
59  }
60  memcpy(dup, ptr, oldsize);
61  free(ptr);
62  }
63  return dup;
64 }
65 
69 void __attribute__((naked)) abort(void) {
70  asm ("bkpt #0");
71 }