strobjs.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * shim_syscalls.c
  15. *
  16. * This file contain functions to allocate / free a fixed-size string object.
  17. */
  18. #include <shim_internal.h>
  19. #include <shim_utils.h>
  20. static struct shim_lock str_mgr_lock;
  21. #define SYSTEM_LOCK() lock(&str_mgr_lock)
  22. #define SYSTEM_UNLOCK() unlock(&str_mgr_lock)
  23. #define STR_MGR_ALLOC 32
  24. #define PAGE_SIZE allocsize
  25. #define OBJ_TYPE struct shim_str
  26. #include "memmgr.h"
  27. static MEM_MGR str_mgr = NULL;
  28. int init_str_mgr(void) {
  29. create_lock(&str_mgr_lock);
  30. str_mgr = create_mem_mgr(init_align_up(STR_MGR_ALLOC));
  31. return 0;
  32. }
  33. struct shim_str* get_str_obj(void) {
  34. return get_mem_obj_from_mgr_enlarge(str_mgr, size_align_up(STR_MGR_ALLOC));
  35. }
  36. int free_str_obj(struct shim_str* str) {
  37. if (str == NULL)
  38. return 0;
  39. if (memory_migrated(str)) {
  40. memset(str, 0, sizeof(struct shim_str));
  41. return 0;
  42. }
  43. free_mem_obj_to_mgr(str_mgr, str);
  44. return 0;
  45. }