mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
add cyassl runtime alloc routines override, move to ctaocrypt so both can use, submitted by eof
This commit is contained in:
52
ctaocrypt/include/cyassl_memory.h
Normal file
52
ctaocrypt/include/cyassl_memory.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* cyassl_memory.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
|
||||||
|
*
|
||||||
|
* This file is part of CyaSSL.
|
||||||
|
*
|
||||||
|
* CyaSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* CyaSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CYASSL_MEMORY_H
|
||||||
|
#define CYASSL_MEMORY_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef void *(*CyaSSL_Malloc_cb)(size_t size);
|
||||||
|
typedef void (*CyaSSL_Free_cb)(void *ptr);
|
||||||
|
typedef void *(*CyaSSL_Realloc_cb)(void *ptr, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
int CyaSSL_SetAllocators(CyaSSL_Malloc_cb malloc_function,
|
||||||
|
CyaSSL_Free_cb free_function,
|
||||||
|
CyaSSL_Realloc_cb realloc_function);
|
||||||
|
|
||||||
|
void* CyaSSL_Malloc(size_t size);
|
||||||
|
void CyaSSL_Free(void *ptr);
|
||||||
|
void* CyaSSL_Realloc(void *ptr, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CYASSL_MEMORY_H */
|
@@ -1,3 +1,24 @@
|
|||||||
|
/* logging.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
|
||||||
|
*
|
||||||
|
* This file is part of CyaSSL.
|
||||||
|
*
|
||||||
|
* CyaSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* CyaSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef CYASSL_LOGGING_H
|
#ifndef CYASSL_LOGGING_H
|
||||||
#define CYASSL_LOGGING_H
|
#define CYASSL_LOGGING_H
|
||||||
|
|
||||||
@@ -10,9 +31,9 @@
|
|||||||
enum CYA_Log_Levels {
|
enum CYA_Log_Levels {
|
||||||
ERROR_LOG = 0,
|
ERROR_LOG = 0,
|
||||||
INFO_LOG,
|
INFO_LOG,
|
||||||
ENTER_LOG,
|
ENTER_LOG,
|
||||||
LEAVE_LOG,
|
LEAVE_LOG,
|
||||||
OTHER_LOG
|
OTHER_LOG
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*CyaSSL_Logging_cb)(const int logLevel,
|
typedef void (*CyaSSL_Logging_cb)(const int logLevel,
|
||||||
|
@@ -260,6 +260,11 @@
|
|||||||
|
|
||||||
#endif /* MICRIUM */
|
#endif /* MICRIUM */
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(XMALLOC_USER) && !defined(MICRIUM_MALLOC)
|
||||||
|
#define USE_CYASSL_MEMORY
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Place any other flags or defines here */
|
/* Place any other flags or defines here */
|
||||||
|
|
||||||
|
|
||||||
|
@@ -134,11 +134,12 @@ enum {
|
|||||||
extern void *XREALLOC(void *p, size_t n, void* heap, int type);
|
extern void *XREALLOC(void *p, size_t n, void* heap, int type);
|
||||||
extern void XFREE(void *p, void* heap, int type);
|
extern void XFREE(void *p, void* heap, int type);
|
||||||
#elif !defined(MICRIUM_MALLOC)
|
#elif !defined(MICRIUM_MALLOC)
|
||||||
/* defaults to C runtime if user doesn't override and not Micrium */
|
/* default C runtime, can install different routines at runtime */
|
||||||
#include <stdlib.h>
|
#define USE_CYASSL_MEMORY
|
||||||
#define XMALLOC(s, h, t) malloc((s))
|
#include <cyassl_memory.h>
|
||||||
#define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
|
#define XMALLOC(s, h, t) CyaSSL_Malloc((s))
|
||||||
#define XREALLOC(p, n, h, t) realloc((p), (n))
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) CyaSSL_Free((xp));}
|
||||||
|
#define XREALLOC(p, n, h, t) CyaSSL_Realloc((p), (n))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STRING_USER
|
#ifndef STRING_USER
|
||||||
|
92
ctaocrypt/src/cyassl_memory.c
Normal file
92
ctaocrypt/src/cyassl_memory.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/* cyassl_memory.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
|
||||||
|
*
|
||||||
|
* This file is part of CyaSSL.
|
||||||
|
*
|
||||||
|
* CyaSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* CyaSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "os_settings.h"
|
||||||
|
|
||||||
|
#ifdef USE_CYASSL_MEMORY
|
||||||
|
|
||||||
|
#include "cyassl_memory.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Set these to default values initially. */
|
||||||
|
static CyaSSL_Malloc_cb malloc_function = 0;
|
||||||
|
static CyaSSL_Free_cb free_function = 0;
|
||||||
|
static CyaSSL_Realloc_cb realloc_function = 0;
|
||||||
|
|
||||||
|
int CyaSSL_SetAllocators(CyaSSL_Malloc_cb mf,
|
||||||
|
CyaSSL_Free_cb ff,
|
||||||
|
CyaSSL_Realloc_cb rf)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
if (mf)
|
||||||
|
malloc_function = mf;
|
||||||
|
else
|
||||||
|
res = -1;
|
||||||
|
|
||||||
|
if (ff)
|
||||||
|
free_function = ff;
|
||||||
|
else
|
||||||
|
res = -1;
|
||||||
|
|
||||||
|
if (rf)
|
||||||
|
realloc_function = rf;
|
||||||
|
else
|
||||||
|
res = -1;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* CyaSSL_Malloc(size_t size)
|
||||||
|
{
|
||||||
|
void* res = 0;
|
||||||
|
|
||||||
|
if (malloc_function)
|
||||||
|
res = malloc_function(size);
|
||||||
|
else
|
||||||
|
res = malloc(size);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CyaSSL_Free(void *ptr)
|
||||||
|
{
|
||||||
|
if (free_function)
|
||||||
|
free_function(ptr);
|
||||||
|
else
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* CyaSSL_Realloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
void* res = 0;
|
||||||
|
|
||||||
|
if (realloc_function)
|
||||||
|
res = realloc_function(ptr, size);
|
||||||
|
else
|
||||||
|
res = realloc(ptr, size);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_CYASSL_MEMORY */
|
@@ -1,8 +1,26 @@
|
|||||||
#include "logging.h"
|
/* logging.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
|
||||||
|
*
|
||||||
|
* This file is part of CyaSSL.
|
||||||
|
*
|
||||||
|
* CyaSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* CyaSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include "os_settings.h"
|
||||||
#include "config.h"
|
#include "logging.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Set these to default values initially. */
|
/* Set these to default values initially. */
|
||||||
@@ -12,15 +30,14 @@ static int loggingEnabled = 0;
|
|||||||
|
|
||||||
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
|
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if (f)
|
if (f)
|
||||||
log_function = f;
|
log_function = f;
|
||||||
else
|
else
|
||||||
res = -1;
|
res = -1;
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,9 +68,9 @@ void CyaSSL_Debugging_OFF(void)
|
|||||||
|
|
||||||
static void log(const int logLevel, const char *const logMessage)
|
static void log(const int logLevel, const char *const logMessage)
|
||||||
{
|
{
|
||||||
if (log_function)
|
if (log_function)
|
||||||
log_function(logLevel, logMessage);
|
log_function(logLevel, logMessage);
|
||||||
else {
|
else {
|
||||||
if (loggingEnabled) {
|
if (loggingEnabled) {
|
||||||
#ifdef THREADX
|
#ifdef THREADX
|
||||||
dc_log_printf("%s\n", logMessage);
|
dc_log_printf("%s\n", logMessage);
|
||||||
@@ -64,44 +81,44 @@ static void log(const int logLevel, const char *const logMessage)
|
|||||||
#else
|
#else
|
||||||
fprintf(stderr, "%s\n", logMessage);
|
fprintf(stderr, "%s\n", logMessage);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CYASSL_MSG(const char* msg)
|
void CYASSL_MSG(const char* msg)
|
||||||
{
|
{
|
||||||
log(INFO_LOG , msg);
|
log(INFO_LOG , msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CYASSL_ENTER(const char* msg)
|
void CYASSL_ENTER(const char* msg)
|
||||||
{
|
{
|
||||||
if (loggingEnabled) {
|
if (loggingEnabled) {
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
sprintf(buffer, "CyaSSL Entering %s", msg);
|
sprintf(buffer, "CyaSSL Entering %s", msg);
|
||||||
log(ENTER_LOG , buffer);
|
log(ENTER_LOG , buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CYASSL_LEAVE(const char* msg, int ret)
|
void CYASSL_LEAVE(const char* msg, int ret)
|
||||||
{
|
{
|
||||||
if (loggingEnabled) {
|
if (loggingEnabled) {
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
||||||
log(LEAVE_LOG , buffer);
|
log(LEAVE_LOG , buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CYASSL_ERROR(int error)
|
void CYASSL_ERROR(int error)
|
||||||
{
|
{
|
||||||
if (loggingEnabled) {
|
if (loggingEnabled) {
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
||||||
log(ERROR_LOG , buffer);
|
log(ERROR_LOG , buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* DEBUG_CYASSL */
|
#endif /* DEBUG_CYASSL */
|
||||||
|
@@ -8,7 +8,8 @@ libcyassl_la_SOURCES = \
|
|||||||
../ctaocrypt/src/random.c ../ctaocrypt/src/rsa.c ../ctaocrypt/src/sha.c \
|
../ctaocrypt/src/random.c ../ctaocrypt/src/rsa.c ../ctaocrypt/src/sha.c \
|
||||||
../ctaocrypt/src/aes.c ../ctaocrypt/src/sha256.c ../ctaocrypt/src/dh.c \
|
../ctaocrypt/src/aes.c ../ctaocrypt/src/sha256.c ../ctaocrypt/src/dh.c \
|
||||||
../ctaocrypt/src/dsa.c ../ctaocrypt/src/arc4.c ../ctaocrypt/src/rabbit.c \
|
../ctaocrypt/src/dsa.c ../ctaocrypt/src/arc4.c ../ctaocrypt/src/rabbit.c \
|
||||||
../ctaocrypt/src/pwdbased.c ../ctaocrypt/src/logging.c
|
../ctaocrypt/src/pwdbased.c ../ctaocrypt/src/logging.c \
|
||||||
|
../ctaocrypt/src/cyassl_memory.c
|
||||||
libcyassl_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
libcyassl_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||||
EXTRA_DIST = ../include/*.h ../include/openssl/*.h ../include/*.rc
|
EXTRA_DIST = ../include/*.h ../include/openssl/*.h ../include/*.rc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user