dl.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <config.h>
  19. #include <config-util.h>
  20. #include <grub/dl.h>
  21. #include <grub/misc.h>
  22. #include <grub/mm.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <windows.h>
  26. void *
  27. grub_osdep_dl_memalign (grub_size_t align, grub_size_t size)
  28. {
  29. void *ret;
  30. if (align > 4096)
  31. {
  32. grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "too large alignment");
  33. return NULL;
  34. }
  35. size = ALIGN_UP (size, 4096);
  36. ret = VirtualAlloc (NULL, size, MEM_COMMIT | MEM_RESERVE,
  37. PAGE_EXECUTE_READWRITE);
  38. if (!ret)
  39. {
  40. grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
  41. return NULL;
  42. }
  43. return ret;
  44. }
  45. void
  46. grub_dl_osdep_dl_free (void *ptr)
  47. {
  48. if (!ptr)
  49. return;
  50. VirtualFree (ptr, 0, MEM_RELEASE);
  51. }