make the build experience nicer outside of ecelerity.
Add a simple test app. Note: we don't compile the malloc replacement component.
This commit is contained in:
parent
ec9812105b
commit
855e068963
5 changed files with 92 additions and 13 deletions
20
Makefile.am
20
Makefile.am
|
@ -1,4 +1,9 @@
|
||||||
lib_LTLIBRARIES = libumem.la
|
lib_LTLIBRARIES = libumem.la
|
||||||
|
noinst_PROGRAMS = umem_test
|
||||||
|
|
||||||
|
umem_test_SOURCES = umem_test.c
|
||||||
|
umem_test_LDADD = -lumem -lpthread -ldl
|
||||||
|
|
||||||
libumem_la_SOURCES = init_lib.c \
|
libumem_la_SOURCES = init_lib.c \
|
||||||
umem_agent_support.c \
|
umem_agent_support.c \
|
||||||
umem_fail.c \
|
umem_fail.c \
|
||||||
|
@ -6,13 +11,14 @@ libumem_la_SOURCES = init_lib.c \
|
||||||
umem_update_thread.c \
|
umem_update_thread.c \
|
||||||
vmem_mmap.c \
|
vmem_mmap.c \
|
||||||
vmem_sbrk.c \
|
vmem_sbrk.c \
|
||||||
envvar.o \
|
envvar.c \
|
||||||
getpcstack.o \
|
getpcstack.c \
|
||||||
malloc.o \
|
misc.c \
|
||||||
misc.o \
|
vmem_base.c \
|
||||||
vmem_base.o \
|
umem.c \
|
||||||
umem.o \
|
vmem.c
|
||||||
vmem.o
|
|
||||||
|
# malloc.c \
|
||||||
|
|
||||||
# XXX: Standalone version?
|
# XXX: Standalone version?
|
||||||
# See <http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libumem/Makefile.com>
|
# See <http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libumem/Makefile.com>
|
||||||
|
|
5
misc.c
5
misc.c
|
@ -49,7 +49,10 @@
|
||||||
|
|
||||||
#include <umem_impl.h>
|
#include <umem_impl.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
#ifdef ECELERITY
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UMEM_ERRFD 2 /* goes to standard error */
|
#define UMEM_ERRFD 2 /* goes to standard error */
|
||||||
#define UMEM_MAX_ERROR_SIZE 4096 /* error messages are truncated to this */
|
#define UMEM_MAX_ERROR_SIZE 4096 /* error messages are truncated to this */
|
||||||
|
@ -80,7 +83,9 @@ umem_log_enter(const char *error_str, int serious)
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
looped = 0;
|
looped = 0;
|
||||||
|
#ifdef ECELERITY
|
||||||
mem_printf(serious ? DCRITICAL : DINFO, "umem: %s", error_str);
|
mem_printf(serious ? DCRITICAL : DINFO, "umem: %s", error_str);
|
||||||
|
#endif
|
||||||
|
|
||||||
(void) mutex_lock(&umem_error_lock);
|
(void) mutex_lock(&umem_error_lock);
|
||||||
|
|
||||||
|
|
56
sol_compat.h
56
sol_compat.h
|
@ -11,9 +11,15 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#define INLINE inline
|
#ifdef _WIN32
|
||||||
#define THR_RETURN void *
|
# define THR_RETURN DWORD
|
||||||
#define THR_API
|
# define THR_API WINAPI
|
||||||
|
# define INLINE __inline
|
||||||
|
#else
|
||||||
|
# define THR_RETURN void *
|
||||||
|
# define THR_API
|
||||||
|
# define INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__MACH__) || defined(_WIN32)
|
#if defined(__MACH__) || defined(_WIN32)
|
||||||
#define NO_WEAK_SYMBOLS
|
#define NO_WEAK_SYMBOLS
|
||||||
|
@ -98,7 +104,41 @@ static INLINE int thr_create(void *stack_base,
|
||||||
# define RTLD_FIRST 0
|
# define RTLD_FIRST 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*#include "ec_atomic.h"*/
|
#ifdef ECELERITY
|
||||||
|
# include "ec_atomic.h"
|
||||||
|
#else
|
||||||
|
# ifdef _WIN32
|
||||||
|
# define ec_atomic_inc(a) InterlockedIncrement(a)
|
||||||
|
# define ec_atomic_inc64(a) InterlockedIncrement64(a)
|
||||||
|
# elif (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
|
||||||
|
static INLINE uint_t ec_atomic_cas(uint_t *mem, uint_t with, uint_t cmp)
|
||||||
|
{
|
||||||
|
uint_t prev;
|
||||||
|
asm volatile ("lock; cmpxchgl %1, %2"
|
||||||
|
: "=a" (prev)
|
||||||
|
: "r" (with), "m" (*(mem)), "0" (cmp)
|
||||||
|
: "memory");
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef ec_atomic_inc
|
||||||
|
static INLINE uint_t ec_atomic_inc(uint_t *mem)
|
||||||
|
{
|
||||||
|
register uint_t last;
|
||||||
|
do {
|
||||||
|
last = *mem;
|
||||||
|
} while (ec_atomic_cas(mem, last+1, last) != last);
|
||||||
|
return ++last;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
# ifndef ec_atomic_inc64
|
||||||
|
/* yeah, it's not great. It's only used to bump failed allocation
|
||||||
|
* counts, so it is not critical right now. */
|
||||||
|
# define ec_atomic_inc64(a) (*a)++
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define P2PHASE(x, align) ((x) & ((align) - 1))
|
#define P2PHASE(x, align) ((x) & ((align) - 1))
|
||||||
#define P2ALIGN(x, align) ((x) & -(align))
|
#define P2ALIGN(x, align) ((x) & -(align))
|
||||||
|
@ -139,4 +179,12 @@ static INLINE int __nthreads(void)
|
||||||
# define _LP64 1
|
# define _LP64 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
# define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
#ifndef MAX
|
||||||
|
# define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -126,10 +126,11 @@ umem_panic(const char *format, ...)
|
||||||
if (format[strlen(format)-1] != '\n')
|
if (format[strlen(format)-1] != '\n')
|
||||||
umem_error_enter("\n");
|
umem_error_enter("\n");
|
||||||
|
|
||||||
|
#ifdef ECELERITY
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
/*ec_debug_vprintf(DCRITICAL, DMEM, format, va);*/
|
ec_debug_vprintf(DCRITICAL, DMEM, format, va);
|
||||||
fvprintf(stderr, format, va);
|
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
#endif
|
||||||
|
|
||||||
print_stacktrace();
|
print_stacktrace();
|
||||||
|
|
||||||
|
|
19
umem_test.c
Normal file
19
umem_test.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "umem.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *foo;
|
||||||
|
|
||||||
|
umem_startup(NULL, 0, 0, NULL, NULL);
|
||||||
|
|
||||||
|
foo = umem_alloc(32, UMEM_DEFAULT);
|
||||||
|
|
||||||
|
strcpy(foo, "hello there");
|
||||||
|
|
||||||
|
printf("Hello %s\n", foo);
|
||||||
|
|
||||||
|
umem_free(foo, 32);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue