Git Product home page Git Product logo

litejit's Introduction

LiteJIT

A lightweight jit

LiteJIT uses "cc" to compile the C program into an object file. Then relocate the object file to get the executable code. Since using LLVM OrcJIT in dynamic binary translation is overkill. I start this project.

Basic API

Static member function createLiteJIT is used to create a LiteJIT object. The first argument MemSize is used to specify the code cache size in the created LiteJIT object. The second argument memory is used to specify the external code cache address. The size of the external memory should be larger than the specified MemSize and align to page size.

// MemSize: nKB
static std::unique_ptr<LiteJIT> createLiteJIT(unsigned MemSize = 64,
                                              void *memory = nullptr);

The following four member functions in LiteJIT are used to add C/ELF to code cache:

// The pointer elf points to the loaded ELF file
int addElf(char *elf);
// The file descriptor is an opened ELF file
int addElf(int fd);
// The path is the path of the ELF file
int addElf(const char *Path);
// The string is a C program
int addC(const char *c);

For example, Add a C program to LiteJIT via LiteJIT->addC(prog), LJIT will create a file, then call "cc" to compile the C program (fork and execlp), then call LiteJIT->addElf(fd) to add the compiled ELF file, then call LiteJIT->addElf(elf).

After adding C/ELF, we can use lookup to get the address of the symbol in code cache (if LITEJIT_DISABLE_LOOKUP is disabled).

void *lookup(const std::string &name) const;
void *lookup(const char *name) const;

LITEJIT_DISABLE_LOOKUP is used to reduce the footprint of LiteJIT. Enable LITEJIT_DISABLE_LOOKUP will strip the symbol map (SymbolMap) in LiteJIT. But the lookup functions become unavailable.

Instead, you can register RegisterSymbolEvent and DeleteSymbolEvent. The RegisterSymbolEvent will be called when a symbol is registered. And the DeleteSymbolEvent will be called when a symbol is deleted if the symbol has delete event.

using RegisterSymbolEventTy = bool (*)(const char *, void *); // symbol name, addr
using DeleteSymbolEventTy = void (*)(const char *);           // symbol name

// If the symbol has a delete event, the register symbol event handler must return true
void setRegisterSymbolEvent(RegisterSymbolEventTy handler);
void setDeleteSymbolEvent(DeleteSymbolEventTy handler);

litejit's People

Contributors

lipraxde avatar

Stargazers

HY Chang avatar JasonKao avatar HHsu avatar  avatar zxchen avatar HSZheng avatar

Watchers

James Cloos avatar  avatar

Forkers

fiking fanyi3315

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.