mirror of
https://github.com/urbit/shrub.git
synced 2024-12-23 19:05:48 +03:00
u3: refactors custom allocator init for libraries
This commit is contained in:
parent
f996844950
commit
7c9167b6ae
@ -1,8 +1,6 @@
|
|||||||
#ifndef U3_ALLOCATE_H
|
#ifndef U3_ALLOCATE_H
|
||||||
#define U3_ALLOCATE_H
|
#define U3_ALLOCATE_H
|
||||||
|
|
||||||
#include <openssl/opensslv.h>
|
|
||||||
|
|
||||||
#include "manage.h"
|
#include "manage.h"
|
||||||
|
|
||||||
/** Constants.
|
/** Constants.
|
||||||
@ -477,15 +475,6 @@
|
|||||||
void*
|
void*
|
||||||
u3a_malloc(size_t len_i);
|
u3a_malloc(size_t len_i);
|
||||||
|
|
||||||
/* u3a_malloc_ssl(): openssl-shaped malloc
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_malloc_ssl(size_t len_i
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
/* u3a_calloc(): aligned storage measured in bytes.
|
/* u3a_calloc(): aligned storage measured in bytes.
|
||||||
*/
|
*/
|
||||||
void*
|
void*
|
||||||
@ -496,39 +485,11 @@
|
|||||||
void*
|
void*
|
||||||
u3a_realloc(void* lag_v, size_t len_i);
|
u3a_realloc(void* lag_v, size_t len_i);
|
||||||
|
|
||||||
/* u3a_realloc2(): gmp-shaped realloc.
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_realloc2(void* lag_v, size_t old_i, size_t new_i);
|
|
||||||
|
|
||||||
/* u3a_realloc_ssl(): openssl-shaped realloc.
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_realloc_ssl(void* lag_v, size_t len_i
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
/* u3a_free(): free for aligned malloc.
|
/* u3a_free(): free for aligned malloc.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
u3a_free(void* tox_v);
|
u3a_free(void* tox_v);
|
||||||
|
|
||||||
/* u3a_free2(): gmp-shaped free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
u3a_free2(void* tox_v, size_t siz_i);
|
|
||||||
|
|
||||||
/* u3a_free_ssl(): openssl-shaped free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
u3a_free_ssl(void* tox_v
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Reference and arena control.
|
/* Reference and arena control.
|
||||||
*/
|
*/
|
||||||
/* u3a_gain(): gain a reference count in normal space.
|
/* u3a_gain(): gain a reference count in normal space.
|
||||||
|
@ -692,18 +692,6 @@ u3a_malloc(size_t len_i)
|
|||||||
return out_w;
|
return out_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* u3a_malloc_ssl(): openssl-shaped malloc
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_malloc_ssl(size_t len_i
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return u3a_malloc(len_i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* u3a_cellblock(): allocate a block of cells on the hat.
|
/* u3a_cellblock(): allocate a block of cells on the hat.
|
||||||
*/
|
*/
|
||||||
static c3_o
|
static c3_o
|
||||||
@ -885,26 +873,6 @@ u3a_realloc(void* lag_v, size_t len_i)
|
|||||||
return u3a_wealloc(lag_v, (len_w + 3) >> 2);
|
return u3a_wealloc(lag_v, (len_w + 3) >> 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* u3a_realloc2(): gmp-shaped realloc.
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_realloc2(void* lag_v, size_t old_i, size_t new_i)
|
|
||||||
{
|
|
||||||
return u3a_realloc(lag_v, new_i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* u3a_realloc_ssl(): openssl-shaped realloc.
|
|
||||||
*/
|
|
||||||
void*
|
|
||||||
u3a_realloc_ssl(void* lag_v, size_t len_i
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return u3a_realloc(lag_v, len_i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* u3a_free(): free for aligned malloc.
|
/* u3a_free(): free for aligned malloc.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -921,26 +889,6 @@ u3a_free(void* tox_v)
|
|||||||
u3a_wfree(org_w);
|
u3a_wfree(org_w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* u3a_free2(): gmp-shaped free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
u3a_free2(void* tox_v, size_t siz_i)
|
|
||||||
{
|
|
||||||
return u3a_free(tox_v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* u3a_free_ssl(): openssl-shaped free.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
u3a_free_ssl(void* tox_v
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
||||||
, const char* file, int line
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return u3a_free(tox_v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* _me_wash_north(): clean up mug slots after copy.
|
/* _me_wash_north(): clean up mug slots after copy.
|
||||||
*/
|
*/
|
||||||
static void _me_wash_north(u3_noun dog);
|
static void _me_wash_north(u3_noun dog);
|
||||||
|
@ -1718,16 +1718,53 @@ _cm_signals(void)
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void u3je_secp_init(void);
|
/* _cm_malloc_ssl(): openssl-shaped malloc
|
||||||
extern void u3je_secp_stop(void);
|
*/
|
||||||
|
static void*
|
||||||
|
_cm_malloc_ssl(size_t len_i
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||||
|
, const char* file, int line
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return u3a_malloc(len_i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* _cm_realloc_ssl(): openssl-shaped realloc.
|
||||||
|
*/
|
||||||
|
static void*
|
||||||
|
_cm_realloc_ssl(void* lag_v, size_t len_i
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||||
|
, const char* file, int line
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return u3a_realloc(lag_v, len_i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* _cm_free_ssl(): openssl-shaped free.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
_cm_free_ssl(void* tox_v
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||||
|
, const char* file, int line
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return u3a_free(tox_v);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void u3je_secp_init(void);
|
||||||
|
|
||||||
|
/* _cm_crypto(): initialize openssl and crypto jets.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
_cm_crypto()
|
_cm_crypto()
|
||||||
{
|
{
|
||||||
/* Initialize OpenSSL with loom allocation functions. */
|
/* Initialize OpenSSL with loom allocation functions. */
|
||||||
if ( 0 == CRYPTO_set_mem_functions(&u3a_malloc_ssl,
|
if ( 0 == CRYPTO_set_mem_functions(&_cm_malloc_ssl,
|
||||||
&u3a_realloc_ssl,
|
&_cm_realloc_ssl,
|
||||||
&u3a_free_ssl) ) {
|
&_cm_free_ssl) ) {
|
||||||
u3l_log("%s\r\n", "openssl initialization failed");
|
u3l_log("%s\r\n", "openssl initialization failed");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -1735,6 +1772,22 @@ _cm_crypto()
|
|||||||
u3je_secp_init();
|
u3je_secp_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* _cm_realloc2(): gmp-shaped realloc.
|
||||||
|
*/
|
||||||
|
static void*
|
||||||
|
_cm_realloc2(void* lag_v, size_t old_i, size_t new_i)
|
||||||
|
{
|
||||||
|
return u3a_realloc(lag_v, new_i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* _cm_free2(): gmp-shaped free.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
_cm_free2(void* tox_v, size_t siz_i)
|
||||||
|
{
|
||||||
|
return u3a_free(tox_v);
|
||||||
|
}
|
||||||
|
|
||||||
/* u3m_init(): start the environment.
|
/* u3m_init(): start the environment.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -1746,7 +1799,7 @@ u3m_init(void)
|
|||||||
|
|
||||||
/* Make sure GMP uses our malloc.
|
/* Make sure GMP uses our malloc.
|
||||||
*/
|
*/
|
||||||
mp_set_memory_functions(u3a_malloc, u3a_realloc2, u3a_free2);
|
mp_set_memory_functions(u3a_malloc, _cm_realloc2, _cm_free2);
|
||||||
|
|
||||||
/* Map at fixed address.
|
/* Map at fixed address.
|
||||||
*/
|
*/
|
||||||
@ -1781,7 +1834,10 @@ u3m_init(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* u3m_stop(): graceful shutdown cleanup. */
|
extern void u3je_secp_stop(void);
|
||||||
|
|
||||||
|
/* u3m_stop(): graceful shutdown cleanup.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
u3m_stop()
|
u3m_stop()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user