Move PrimitiveType_String to a dedicated string type.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
25 ToProtBits(OS::Protection prot)
28 case OS::Prot_ReadWrite:
29 return PROT_READ | PROT_WRITE;
30 case OS::Prot_ReadWriteExecute:
31 return PROT_READ | PROT_WRITE | PROT_EXEC;
33 assert(prot == OS::Prot_ReadExecute);
34 return PROT_READ | PROT_EXEC;
39 OS::MapMemory(size_t amount, MapMode mode, Protection prot_)
41 int prot = ToProtBits(prot_);
42 void *addr = mmap(NULL, amount, prot, MAP_ANON | MAP_PRIVATE, -1, 0);
43 if (addr == MAP_FAILED)
50 OS::CommitMemory(Address address, size_t amount, Protection prot_)
56 OS::UnmapMemory(Address address, size_t size)
58 munmap(address, size);
62 OS::MapAlignedMemory(size_t amount, size_t alignment, MapMode mode)
64 assert(amount >= alignment);
65 assert(IsPowerOfTwo(alignment));
67 if (alignment == kPageAlignment) {
68 Address address = MapMemory(amount, mode, Prot_ReadWrite);
70 return AlignableMapping();
71 return AlignableMapping(address, alignment, amount);
74 size_t requested = Min(amount * 2, amount + 2 * alignment);
75 Address address = MapMemory(requested, mode, Prot_ReadWrite);
77 return AlignableMapping();
80 Address aligned = AlignedBase(address, alignment);
81 if (!IsAligned(address, alignment)) {
82 // Shave off the first part of the unaligned region.
84 begin = size_t(aligned - address);
85 UnmapAlignedMemory(address, begin);
88 if (requested - begin > amount) {
89 // Shave off the last part of the unaligned region.
90 UnmapAlignedMemory(aligned + amount, requested - amount - begin);
93 return AlignableMapping(aligned, alignment, amount);
97 OS::UnmapAlignedMemory(Address address, size_t size)
99 OS::UnmapMemory(address, size);