strobjs.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 OBJ_TYPE struct shim_str
  25. #include "memmgr.h"
  26. static MEM_MGR str_mgr = NULL;
  27. int init_str_mgr(void) {
  28. create_lock(&str_mgr_lock);
  29. str_mgr = create_mem_mgr(init_align_up(STR_MGR_ALLOC));
  30. return 0;
  31. }
  32. struct shim_str* get_str_obj(void) {
  33. return get_mem_obj_from_mgr_enlarge(str_mgr, size_align_up(STR_MGR_ALLOC));
  34. }
  35. int free_str_obj(struct shim_str* str) {
  36. if (str == NULL)
  37. return 0;
  38. if (memory_migrated(str)) {
  39. memset(str, 0, sizeof(struct shim_str));
  40. return 0;
  41. }
  42. free_mem_obj_to_mgr(str_mgr, str);
  43. return 0;
  44. }