AegisCC

A minimalistic x86-64 JIT compiler demonstrating dynamic machine code generation and execution

AegisCC Demo

A low-level systems project showcasing dynamic x86-64 assembly instruction generation and runtime execution through executable memory allocation in C++.

Key Features

  • Dynamic Code Generation: Generates x86-64 assembly instructions at runtime
  • Executable Memory Management: Allocates and manages executable memory regions safely
  • Function Pointer Casting: Executes dynamically generated code by casting memory to function pointers
  • Global Function Calls: Demonstrates calling global C++ functions from generated machine code
  • Vector Manipulation: Generated code manipulates global integer vectors
  • Assembly Integration: Combines C++ with native assembly language for low-level control
  • Educational Focus: Clear examples of JIT principles and machine code execution

How It Works

  1. Memory Allocation: Allocates executable memory region using mmap or platform-specific APIs
  2. Code Generation: Dynamically generates x86-64 assembly instructions for desired operations
  3. Machine Code Storage: Stores generated bytecode in executable memory
  4. Function Pointer Creation: Casts memory address to function pointer
  5. Execution: Calls generated machine code as native function with full CPU execution

Project Structure

  • Dynamic Machine Code Execution: Part 1 - Direct machine code embedding and execution
  • JIT Compilation: Part 2 - Runtime assembly generation and compilation
  • Output Documentation: read.txt files in both directories with execution results

Technologies Used

  • Language: C++ (94.7% of codebase)
  • Assembly: x86-64 (5.3%)
  • Architecture: 64-bit x86-64 instruction set
  • Operating System: Linux / WSL (Windows Subsystem for Linux)
  • Compiler: g++ for compilation
  • Build Tools: GCC assembler (as), objdump for disassembly analysis

Technical Concepts Demonstrated

  • Machine Code Execution: Running raw CPU instructions from memory
  • JIT Compilation: Just-In-Time compilation of assembly at runtime
  • Memory Safety: Managing executable memory with proper permissions
  • Function Pointers: Type casting memory addresses to callable functions
  • CPU Calling Conventions: x86-64 calling conventions for function calls
  • Assembly Language: Low-level instruction generation and optimization