PageRenderTime 26ms CodeModel.GetById 9ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/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
30#include "assembler/wtf/Platform.h"
31
32#if ENABLE_ASSEMBLER && WTF_OS_OS2
33
34#define INCL_DOS
35#include <os2.h>
36
37#include "wtf/Assertions.h"
38
39#include "OSAllocator.h"
40
41namespace WTF {
42
43static inline ULONG protection(bool writable, bool executable)
44{
45    return (PAG_READ | (writable ? PAG_WRITE : 0) | (executable ? PAG_EXECUTE : 0));
46}
47
48void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
49{
50    void* result = NULL;
51    if (DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) &&
52        DosAllocMem(&result, bytes, protection(writable, executable)))
53    {   CRASH();
54    }
55    return result;
56}
57
58void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable)
59{
60    void* result = NULL;
61    if (DosAllocMem(&result, bytes, OBJ_ANY | PAG_COMMIT | protection(writable, executable)) &&
62        DosAllocMem(&result, bytes, PAG_COMMIT | protection(writable, executable)))
63    {   CRASH();
64    }
65    return result;
66
67}
68
69void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
70{
71if (DosSetMem(address, bytes, PAG_COMMIT | protection(writable, executable)))
72    CRASH();
73}
74
75void OSAllocator::decommit(void* address, size_t bytes)
76{
77if (DosSetMem(address, bytes, PAG_DECOMMIT))
78    CRASH();
79}
80
81void OSAllocator::releaseDecommitted(void* address, size_t bytes)
82{
83if (DosFreeMem(address))
84    CRASH();
85}
86
87} // namespace WTF
88
89#endif