GithubHelp home page GithubHelp logo

rust-malloc's Introduction

Rust malloc

A pure-Rust proof-of-concept implementation of malloc/free for x86-64 Linux. It is very, very basic: a linked list of allocations (traversed on every malloc call!), first-fit strategy and all allocations come directly from the brk syscall. As such, it is very slow, not-threadsafe and generally bad. There is little-to-no error checking.

Uses a modified version of zero.rs and a tiny syscall wrapper. Requires a recent rustc from master.

There is an example of a custom version of ~T using this allocator at the bottom of malloc.rs.

Test with:

make
./malloc

To enable the debugging asserts:

make debug
./malloc-debug

Code map:

  • malloc.rs contains malloc, free, etc, as well as main and some tests/examples.
  • types.rs contains the allocation header (Header, surprisingly) as well some newtype structs around raw pointers (Box and Data; in theory these have no runtime cost over using *mut Header and *mut u8 directly) which make the implementation relatively type-safe.
  • util.rs & diag.rs contain utilities and tools for printing diagnostics about the current allocation state.

Only useful for segfaulting and generally making programs incorrect.

TODO

  • Use mmap.
  • Return memory to the OS.
  • Merge adjacent free cells better.

Wishlist

  • Make it fast.
  • Support other platforms/operating systems.

rust-malloc's People

Contributors

glycerine avatar huonw avatar

Watchers

 avatar

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.