diff --git a/aarch64.c b/aarch64.c index 8505b675..a77bb075 100644 --- a/aarch64.c +++ b/aarch64.c @@ -2,8 +2,17 @@ #include "libco.h" #include "settings.h" -#include -#include +#if !defined(LIBCO_ASSERT) + #include + #define LIBCO_ASSERT(...) assert(__VA_ARGS__) +#endif + +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif + #include #ifdef LIBCO_MPROTECT #include @@ -85,13 +94,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void)) } cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { - void* memory = malloc(size); + void* memory = LIBCO_MALLOC(size); if(!memory) return (cothread_t)0; return co_derive(memory, size, entrypoint); } void co_delete(cothread_t handle) { - free(handle); + LIBCO_FREE(handle); } void co_switch(cothread_t handle) { diff --git a/amd64.c b/amd64.c index e96e5247..833b5e2e 100644 --- a/amd64.c +++ b/amd64.c @@ -2,8 +2,16 @@ #include "libco.h" #include "settings.h" -#include -#include +#if !defined(LIBCO_ASSERT) + #include + #define LIBCO_ASSERT(...) assert(__VA_ARGS__) +#endif + +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif #ifdef __cplusplus extern "C" { @@ -114,7 +122,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0; #endif static void crash() { - assert(0); /* called only if cothread_t entrypoint returns */ + LIBCO_ASSERT(0); /* called only if cothread_t entrypoint returns */ } cothread_t co_active() { @@ -142,13 +150,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void)) } cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { - void* memory = malloc(size); + void* memory = LIBCO_MALLOC(size); if(!memory) return (cothread_t)0; return co_derive(memory, size, entrypoint); } void co_delete(cothread_t handle) { - free(handle); + LIBCO_FREE(handle); } void co_switch(cothread_t handle) { diff --git a/arm.c b/arm.c index 1c9dff5c..4a4aef51 100644 --- a/arm.c +++ b/arm.c @@ -2,8 +2,17 @@ #include "libco.h" #include "settings.h" -#include -#include +#if !defined(LIBCO_ASSERT) + #include + #define LIBCO_ASSERT(...) assert(__VA_ARGS__) +#endif + +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif + #ifdef LIBCO_MPROTECT #include #include @@ -61,13 +70,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void)) } cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { - void* memory = malloc(size); + void* memory = LIBCO_MALLOC(size); if(!memory) return (cothread_t)0; return co_derive(memory, size, entrypoint); } void co_delete(cothread_t handle) { - free(handle); + LIBCO_FREE(handle); } void co_switch(cothread_t handle) { diff --git a/ppc.c b/ppc.c index ee6a9a87..bcbdf966 100644 --- a/ppc.c +++ b/ppc.c @@ -4,7 +4,12 @@ #include "libco.h" #include "settings.h" -#include +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif + #include #include @@ -327,7 +332,7 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entry_)(void)) { static uint32_t* co_create_(unsigned size, uintptr_t entry) { (void)entry; - uint32_t* t = (uint32_t*)malloc(size); + uint32_t* t = (uint32_t*)LIBCO_MALLOC(size); #if LIBCO_PPCDESC if(t) { @@ -390,7 +395,7 @@ cothread_t co_create(unsigned int size, void (*entry_)(void)) { } void co_delete(cothread_t t) { - free(t); + LIBCO_FREE(t); } static void co_init_(void) { diff --git a/ppc64v2.c b/ppc64v2.c index 3c296959..1cac8843 100644 --- a/ppc64v2.c +++ b/ppc64v2.c @@ -5,7 +5,12 @@ #include "settings.h" #include -#include + +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif #ifdef __cplusplus extern "C" { @@ -223,7 +228,7 @@ __asm__( cothread_t co_active() { if(!co_active_handle) { - co_active_handle = (struct ppc64_context*)malloc(MIN_STACK + sizeof(struct ppc64_context)); + co_active_handle = (struct ppc64_context*)LIBCO_MALLOC(MIN_STACK + sizeof(struct ppc64_context)); } return (cothread_t)co_active_handle; } @@ -255,13 +260,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*coentry)(void)) { } cothread_t co_create(unsigned int size, void (*coentry)(void)) { - void* memory = malloc(size); + void* memory = LIBCO_MALLOC(size); if(!memory) return (cothread_t)0; return co_derive(memory, size, coentry); } void co_delete(cothread_t handle) { - free(handle); + LIBCO_FREE(handle); } void co_switch(cothread_t to) { diff --git a/x86.c b/x86.c index c539a299..d2c760ad 100644 --- a/x86.c +++ b/x86.c @@ -2,8 +2,16 @@ #include "libco.h" #include "settings.h" -#include -#include +#if !defined(LIBCO_ASSERT) + #include + #define LIBCO_ASSERT(...) assert(__VA_ARGS__) +#endif + +#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE) + #include + #define LIBCO_MALLOC(...) malloc(__VA_ARGS__) + #define LIBCO_FREE(...) free(__VA_ARGS__) +#endif #ifdef __cplusplus extern "C" { @@ -68,7 +76,7 @@ static const unsigned char co_swap_function[4096] = { #endif static void crash() { - assert(0); /* called only if cothread_t entrypoint returns */ + LIBCO_ASSERT(0); /* called only if cothread_t entrypoint returns */ } cothread_t co_active() { @@ -96,13 +104,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void)) } cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { - void* memory = malloc(size); + void* memory = LIBCO_MALLOC(size); if(!memory) return (cothread_t)0; return co_derive(memory, size, entrypoint); } void co_delete(cothread_t handle) { - free(handle); + LIBCO_FREE(handle); } void co_switch(cothread_t handle) {