triv_malloc.g 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. fun malloc 1 {
  15. $size
  16. @size 0 param = ;
  17. $alloc_size
  18. # Add space for the length
  19. @alloc_size size 4 + = ;
  20. # Make it a multiple of 4
  21. @alloc_size alloc_size 1 - 0x3 | 1 + = ;
  22. $ptr
  23. @ptr alloc_size platform_allocate = ;
  24. ptr 1024 1024 * 100 * < "too much alloc" assert_msg ;
  25. ptr size = ;
  26. ptr 4 + ret ;
  27. }
  28. fun free 1 {
  29. }
  30. fun _malloc_get_size 1 {
  31. $ptr
  32. @ptr 0 param = ;
  33. $size
  34. @size ptr 4 - ** = ;
  35. size ret ;
  36. }
  37. fun malloc_stats 0 {
  38. }