Photon 1.0.0
Loading...
Searching...
No Matches
ECMAVirtualMachineJIT.hpp
Go to the documentation of this file.
1/*
2 * =====================================================================
3 *
4 * Photon
5 * Copyright Amlal EL Mahrouss, all rights reserved.
6 *
7 * =====================================================================
8 */
9
10#pragma once
11
12#ifndef _WIN32
13
14#include <core/Core.hpp>
15#include <stdarg.h>
16#include <sys/mman.h>
17
18namespace Photon
19{
21 typedef void (*photon_asm_fn_t)(void* arg, size_t arg_cnt);
22
23 inline int photon_delete_chunk(char* fn, size_t size)
24 {
25 if (!fn || !size)
26 return 1;
27
28 return munmap(fn, size);
29 }
30
31 inline photon_asm_fn_t photon_allocate_chunk(char* data, size_t size)
32 {
33 if (!data || !size)
34 {
35 throw Photon::BrowserError("JIT_ARGUMENT_INVALID");
36 }
37
38 char* mem_exec = (char*)mmap(NULL, // address
39 4096, // size
40 PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS,
41 -1, // fd (not used here)
42 0); // offset (not used here)
43
44 if (mem_exec == MAP_FAILED)
45 {
46 throw Photon::BrowserError("JIT_ERROR_OUT_OF_MEMORY");
47 return nullptr;
48 }
49
50 memcpy(mem_exec, data, size);
51
52 return (photon_asm_fn_t)mem_exec;
53 }
54} // namespace Photon
55
56#endif // !_WIN32
Definition Core.hpp:46
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:2506
This file is also about defining core js concepts.
Definition BasePhotonWindow.hpp:22
photon_asm_fn_t photon_allocate_chunk(char *data, size_t size)
Definition ECMAVirtualMachineJIT.hpp:31
void(* photon_asm_fn_t)(void *arg, size_t arg_cnt)
Generic javascript function.
Definition ECMAVirtualMachineJIT.hpp:21
int photon_delete_chunk(char *fn, size_t size)
Definition ECMAVirtualMachineJIT.hpp:23
#define NULL
Definition strtod.cpp:30
Definition format.h:1901