malloc.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * malloc.h
  3. *
  4. * Copyright (C) 2017 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. #ifndef _MALLOC_H_
  20. #define _MALLOC_H_
  21. #define __CRT_HEAP_FLAG_READY (1 << 0)
  22. #define __CRT_HEAP_FLAG_ZEROFILL (1 << 1)
  23. #define __CRT_HEAP_FLAG_BESTFIT (1 << 2)
  24. enum
  25. {
  26. __CRT_HEAP_CORRUPTED,
  27. __CRT_HEAP_DOUBLE_FREE,
  28. __CRT_HEAP_BAD_POINTER,
  29. __CRT_HEAP_OUT_OF_MEMORY,
  30. };
  31. typedef struct
  32. {
  33. uint32_t magic;
  34. void *base;
  35. size_t size;
  36. uint32_t flags;
  37. uintptr_t next_offset;
  38. void *mutex;
  39. void (*lock_mutex_proc)(void*);
  40. void (*unlock_mutex_proc)(void*);
  41. void (*problem)(int);
  42. } __crt_heap_t;
  43. void *malloc(size_t size);
  44. void free(void *ptr);
  45. void *calloc(size_t nmemb, size_t size);
  46. void *realloc(void *ptr, size_t size);
  47. #endif