malloc.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * malloc.h
  3. *
  4. * Copyright (C) 2019 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "mlcrt.h"
  20. #ifndef _MALLOC_H_
  21. #define _MALLOC_H_
  22. #define __CRT_HEAP_FLAG_READY (1 << 0)
  23. #define __CRT_HEAP_FLAG_ZEROFILL (1 << 1)
  24. #define __CRT_HEAP_FLAG_BESTFIT (1 << 2)
  25. enum
  26. {
  27. __CRT_HEAP_CORRUPTED,
  28. __CRT_HEAP_DOUBLE_FREE,
  29. __CRT_HEAP_BAD_POINTER,
  30. __CRT_HEAP_OUT_OF_MEMORY,
  31. };
  32. typedef struct
  33. {
  34. uint32_t magic;
  35. void *base;
  36. size_t size;
  37. uint32_t flags;
  38. uintptr_t next_offset;
  39. void *mutex;
  40. void (*lock_mutex_proc)(void*);
  41. void (*unlock_mutex_proc)(void*);
  42. void (*problem)(int);
  43. } __CRT_PRIVATE(heap_t);
  44. void *__CRT_PUBLIC(malloc)(size_t size);
  45. void __CRT_PUBLIC(free)(void *ptr);
  46. void *__CRT_PUBLIC(calloc)(size_t nmemb, size_t size);
  47. void *__CRT_PUBLIC(realloc)(void *ptr, size_t size);
  48. #endif