Skip to content

Commit

Permalink
Added all contents of liballoc
Browse files Browse the repository at this point in the history
  • Loading branch information
blanham committed Dec 13, 2013
0 parents commit 78f44b7
Show file tree
Hide file tree
Showing 11 changed files with 1,109 additions and 0 deletions.
26 changes: 26 additions & 0 deletions HOWTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

This is a step-by-step instruction guide detailing how to
implement the library on your own system.


1. Copy the "liballoc.c" and "liballoc.h" files into
your working directory. (Whatever project you want
to use it in).

2. Create the hooks that the library needs:

Make a new file called "liballoc_hooks.c" (or
whatever) and implement the functions detailed
in the README and explained in "liballoc.h"

Look at "linux.c" for an example. It implements
the hooks for a Linux system.

3. Be sure to include the "liballoc.h" header
into your C/C++ files that are using the
malloc/free/memory operations. (So that
malloc/free/etc are declared.. obviously.)

4. Compile as per your normal method and test.


10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

This code is released into the public domain. Use this code at your own
risk. Feel free to use it for whatever purpose you want. I take no responsibilty or
whatever if anything goes wrong. Use it at your own risk.

If you have any fixes or patches, please email me.

Durand Miller <[email protected]>


54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Please see LICENSE for licensing information.


# --------- FLAGS AND VARIABLES --------------------

CFLAGS=-O2 -nostdlib -nodefaultlibs -fno-builtin -fPIC -Wall
HEADERPATH=-I./



# --------- GENERIC MAKE RULES --------------------

all:
@echo "Makefile for the liballoc library."
@echo "Please see LICENSE for licensing information."
@echo
@echo "Output should be: liballoc.a "
@echo " liballoc.so"
@echo
@echo "Usage: make [ compile | clean | <platform> ] "
@echo
@echo "Currently supported platforms:"
@echo
@echo " linux"
@echo " linux_debug"
@echo
@echo
@echo "Please see the README for example usage"


clean:
rm -f ./*.o
rm -f ./*.a
rm -f ./*.so

compile:
gcc $(HEADERPATH) $(CFLAGS) -static -c liballoc.c
ar -rcv liballoc.a *.o
gcc $(HEADERPATH) $(CFLAGS) -shared liballoc.c -o liballoc.so


linux:
gcc $(HEADERPATH) $(CFLAGS) -static -c liballoc.c linux.c
ar -rcv liballoc.a *.o
gcc $(HEADERPATH) $(CFLAGS) -shared liballoc.c linux.c -o liballoc.so


linux_debug:
gcc -DDEBUG $(HEADERPATH) $(CFLAGS) -static -c liballoc.c linux.c
ar -rcv liballoc.a *.o
gcc -DDEBUG $(HEADERPATH) $(CFLAGS) -shared liballoc.c linux.c -o liballoc.so



58 changes: 58 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@



There are 4 functions which you need to implement on your system:

int liballoc_lock();
int liballoc_unlock();
void* liballoc_alloc(int);
int liballoc_free(void*,int);

1) Have a look at liballoc.h for information about what each function is
supposed to do.


2) Have a look at linux.c for an example of how to implement the library
on linux.


NOTE: There are two ways to build the library.

1) Compile the library with a new system file. For example, I've
left linux.c with the default distribution. It gets compiled
directly into the liballoc_linux.so file.

2) Implement the functions in your application and then just
link against the default liballoc.so library when you compile
your app.


QUICK START
-------------

You can simply type: "make linux" to build the linux shared
library. Thereafter, you can link it directly into your applications
during build or afterwards by export the LD_PRELOAD environment
variable.


To run bash with the library, for example:

LD_PRELOAD=/full/path/to/liballoc.so bash


The above command will pre-link the library into the application,
essentially replacing the default malloc/free calls at runtime. It's
quite cool.



Durand Miller

[email protected]






Loading

0 comments on commit 78f44b7

Please sign in to comment.