/js/src/yarr/OSAllocatorOS2.cpp

http://github.com/zpao/v8monkey · C++ · 89 lines · 46 code · 15 blank · 28 comment · 6 complexity · c60cdc96b94124c515081bdc561f02aa MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=8 sw=4 et tw=99 ft=cpp:
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Copyright (C) 2010 Apple Inc. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  26. * THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * ***** END LICENSE BLOCK ***** */
  29. #include "assembler/wtf/Platform.h"
  30. #if ENABLE_ASSEMBLER && WTF_OS_OS2
  31. #define INCL_DOS
  32. #include <os2.h>
  33. #include "wtf/Assertions.h"
  34. #include "OSAllocator.h"
  35. namespace WTF {
  36. static inline ULONG protection(bool writable, bool executable)
  37. {
  38. return (PAG_READ | (writable ? PAG_WRITE : 0) | (executable ? PAG_EXECUTE : 0));
  39. }
  40. void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
  41. {
  42. void* result = NULL;
  43. if (DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) &&
  44. DosAllocMem(&result, bytes, protection(writable, executable)))
  45. { CRASH();
  46. }
  47. return result;
  48. }
  49. void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable)
  50. {
  51. void* result = NULL;
  52. if (DosAllocMem(&result, bytes, OBJ_ANY | PAG_COMMIT | protection(writable, executable)) &&
  53. DosAllocMem(&result, bytes, PAG_COMMIT | protection(writable, executable)))
  54. { CRASH();
  55. }
  56. return result;
  57. }
  58. void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
  59. {
  60. if (DosSetMem(address, bytes, PAG_COMMIT | protection(writable, executable)))
  61. CRASH();
  62. }
  63. void OSAllocator::decommit(void* address, size_t bytes)
  64. {
  65. if (DosSetMem(address, bytes, PAG_DECOMMIT))
  66. CRASH();
  67. }
  68. void OSAllocator::releaseDecommitted(void* address, size_t bytes)
  69. {
  70. if (DosFreeMem(address))
  71. CRASH();
  72. }
  73. } // namespace WTF
  74. #endif