strobjs.c 1.9 KB

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