#ifndef ExecutableAllocator_h
#define ExecutableAllocator_h
-#if ENABLE(ASSEMBLER)
-
+#include <limits>
#include <wtf/Assertions.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
+#include <wtf/UnusedParam.h>
#include <wtf/Vector.h>
-#include <limits>
+#include <libkern/OSCacheControl.h>
+#include <sys/mman.h>
#define JIT_ALLOCATOR_PAGE_SIZE (ExecutableAllocator::pageSize)
#define JIT_ALLOCATOR_LARGE_ALLOC_SIZE (ExecutableAllocator::pageSize * 4)
+#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
+#define PROTECTION_FLAGS_RW (PROT_READ | PROT_WRITE)
+#define PROTECTION_FLAGS_RX (PROT_READ | PROT_EXEC)
+#define INITIAL_PROTECTION_FLAGS PROTECTION_FLAGS_RX
+#else
+#define INITIAL_PROTECTION_FLAGS (PROT_READ | PROT_WRITE | PROT_EXEC)
+#endif
+
+namespace JSC {
+
+inline size_t roundUpAllocationSize(size_t request, size_t granularity)
+{
+ if ((std::numeric_limits<size_t>::max() - granularity) <= request)
+ CRASH(); // Allocation is too large
+
+ // Round up to next page boundary
+ size_t size = request + (granularity - 1);
+ size = size & ~(granularity - 1);
+ ASSERT(size >= request);
+ return size;
+}
+
+}
+
+#if ENABLE(ASSEMBLER)
+
namespace JSC {
class ExecutablePool : public RefCounted<ExecutablePool> {
static Allocation systemAlloc(size_t n);
static void systemRelease(const Allocation& alloc);
- inline size_t roundUpAllocationSize(size_t request, size_t granularity)
- {
- if ((std::numeric_limits<size_t>::max() - granularity) <= request)
- CRASH(); // Allocation is too large
-
- // Round up to next page boundary
- size_t size = request + (granularity - 1);
- size = size & ~(granularity - 1);
- ASSERT(size >= request);
- return size;
- }
-
ExecutablePool(size_t n);
void* poolAllocate(size_t n);
};
class ExecutableAllocator {
+ enum ProtectionSeting { Writable, Executable };
+
public:
static size_t pageSize;
ExecutableAllocator()
return pool.release();
}
+#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
+ static void makeWritable(void* start, size_t size)
+ {
+ reprotectRegion(start, size, Writable);
+ }
+
+ static void makeExecutable(void* start, size_t size)
+ {
+ reprotectRegion(start, size, Executable);
+ }
+#else
+ static void makeWritable(void*, size_t) {}
+ static void makeExecutable(void*, size_t) {}
+#endif
+
+
+#if PLATFORM(X86) || PLATFORM(X86_64)
+ static void cacheFlush(void*, size_t)
+ {
+ }
+#elif PLATFORM_ARM_ARCH(7) && PLATFORM(IPHONE)
+ static void cacheFlush(void* code, size_t size)
+ {
+ sys_dcache_flush(code, size);
+ sys_icache_invalidate(code, size);
+ }
+#else
+#error "ExecutableAllocator::cacheFlush not implemented on this platform."
+#endif
+
private:
+
+#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
+ static void reprotectRegion(void*, size_t, ProtectionSeting);
+#endif
+
RefPtr<ExecutablePool> m_smallAllocationPool;
static void intializePageSize();
};
}
}
-
#endif // ENABLE(ASSEMBLER)
#endif // !defined(ExecutableAllocator)