mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-06-09 23:36:03 +09:00
sandbox: Add a new header for the system malloc()
Some files use U-Boot headers but still need to access the system malloc(). Allow this by creating a new asm/malloc.h which can be used so long as U-Boot's malloc.h has not been included. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
1c8c47ec80
commit
3ff6fe5fab
|
@ -8,10 +8,10 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <os.h>
|
#include <os.h>
|
||||||
#include <cli.h>
|
#include <cli.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <sort.h>
|
#include <sort.h>
|
||||||
#include <asm/getopt.h>
|
#include <asm/getopt.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
#include <asm/malloc.h>
|
||||||
#include <asm/sections.h>
|
#include <asm/sections.h>
|
||||||
#include <asm/state.h>
|
#include <asm/state.h>
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
|
@ -181,7 +181,7 @@ static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state,
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = strlen(state->argv[0]) + strlen(fmt) + 1;
|
len = strlen(state->argv[0]) + strlen(fmt) + 1;
|
||||||
fname = os_malloc(len);
|
fname = malloc(len);
|
||||||
if (!fname)
|
if (!fname)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
snprintf(fname, len, fmt, state->argv[0]);
|
snprintf(fname, len, fmt, state->argv[0]);
|
||||||
|
@ -201,7 +201,7 @@ static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = strlen(state->argv[0]) + strlen(fmt) + 1;
|
len = strlen(state->argv[0]) + strlen(fmt) + 1;
|
||||||
fname = os_malloc(len);
|
fname = malloc(len);
|
||||||
if (!fname)
|
if (!fname)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
strcpy(fname, state->argv[0]);
|
strcpy(fname, state->argv[0]);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fdtdec.h>
|
#include <fdtdec.h>
|
||||||
#include <os.h>
|
#include <os.h>
|
||||||
|
#include <asm/malloc.h>
|
||||||
#include <asm/state.h>
|
#include <asm/state.h>
|
||||||
|
|
||||||
/* Main state record for the sandbox */
|
/* Main state record for the sandbox */
|
||||||
|
@ -27,17 +28,17 @@ static int state_ensure_space(int extra_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size = used + extra_size;
|
size = used + extra_size;
|
||||||
buf = os_malloc(size);
|
buf = malloc(size);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = fdt_open_into(blob, buf, size);
|
ret = fdt_open_into(blob, buf, size);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
os_free(buf);
|
free(buf);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
os_free(blob);
|
free(blob);
|
||||||
state->state_fdt = buf;
|
state->state_fdt = buf;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname)
|
||||||
printf("Cannot find sandbox state file '%s'\n", fname);
|
printf("Cannot find sandbox state file '%s'\n", fname);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
state->state_fdt = os_malloc(size);
|
state->state_fdt = malloc(size);
|
||||||
if (!state->state_fdt) {
|
if (!state->state_fdt) {
|
||||||
puts("No memory to read sandbox state\n");
|
puts("No memory to read sandbox state\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -75,7 +76,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname)
|
||||||
err_read:
|
err_read:
|
||||||
os_close(fd);
|
os_close(fd);
|
||||||
err_open:
|
err_open:
|
||||||
os_free(state->state_fdt);
|
free(state->state_fdt);
|
||||||
state->state_fdt = NULL;
|
state->state_fdt = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -242,7 +243,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname)
|
||||||
/* Create a state FDT if we don't have one */
|
/* Create a state FDT if we don't have one */
|
||||||
if (!state->state_fdt) {
|
if (!state->state_fdt) {
|
||||||
size = 0x4000;
|
size = 0x4000;
|
||||||
state->state_fdt = os_malloc(size);
|
state->state_fdt = malloc(size);
|
||||||
if (!state->state_fdt) {
|
if (!state->state_fdt) {
|
||||||
puts("No memory to create FDT\n");
|
puts("No memory to create FDT\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -300,7 +301,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname)
|
||||||
err_write:
|
err_write:
|
||||||
os_close(fd);
|
os_close(fd);
|
||||||
err_create:
|
err_create:
|
||||||
os_free(state->state_fdt);
|
free(state->state_fdt);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -418,7 +419,7 @@ int state_uninit(void)
|
||||||
os_unlink(state->jumped_fname);
|
os_unlink(state->jumped_fname);
|
||||||
|
|
||||||
if (state->state_fdt)
|
if (state->state_fdt)
|
||||||
os_free(state->state_fdt);
|
free(state->state_fdt);
|
||||||
memset(state, '\0', sizeof(*state));
|
memset(state, '\0', sizeof(*state));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
26
arch/sandbox/include/asm/malloc.h
Normal file
26
arch/sandbox/include/asm/malloc.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||||
|
/*
|
||||||
|
* Sandbox access to system malloc (i.e. not U-Boot's)
|
||||||
|
*
|
||||||
|
* Copyright 2020 Google LLC
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ASM_MALLOC_H
|
||||||
|
|
||||||
|
void *malloc(size_t size);
|
||||||
|
void free(void *ptr);
|
||||||
|
void *calloc(size_t nmemb, size_t size);
|
||||||
|
void *realloc(void *ptr, size_t size);
|
||||||
|
void *reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This header allows calling the system allocation routines. It makes no
|
||||||
|
* sense to also include U-Boot's malloc.h since that redfines malloc to
|
||||||
|
* have a 'dl' prefix. These two implementations cannot be mixed and matched
|
||||||
|
* in the same file.
|
||||||
|
*/
|
||||||
|
#ifdef __MALLOC_H__
|
||||||
|
#error "This sandbox header file cannot be included with malloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user