From patchwork Sun Jan 12 19:06:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1221851 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=O43P4B8K; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47wmWd6fJrz9s4Y for ; Mon, 13 Jan 2020 06:10:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B4FD481801; Sun, 12 Jan 2020 20:07:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="O43P4B8K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F33CF817EE; Sun, 12 Jan 2020 20:07:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B0328804C1 for ; Sun, 12 Jan 2020 20:07:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x144.google.com with SMTP id p8so6024525iln.12 for ; Sun, 12 Jan 2020 11:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MXCegH5hMGcpyV6+gF4VPQT45m6WqkdFOQH9bvISgeE=; b=O43P4B8KBZTMk6C3rJCWwoozM7iz28cWyPot4iDyV3BoyLMIoNN1ZEdkZiMznT9HxC VmQrHqxbvtKD8j4ReZ4yw2pzcn7bYuNdVy4X1KlPlR31TrAzEL4huHWRmgHkxdH+032l +i0cgrVXiXbrF6LJNCbU+0tyUfvQbO+YntaGw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MXCegH5hMGcpyV6+gF4VPQT45m6WqkdFOQH9bvISgeE=; b=pSRldcdbsLn14qUiQZOWFL9azRpK8sPTk4a9MuT+JhgIawUneafxTHiRX3MBr2j5Ps Fme+vKUwGAYfpzvUiOA/tvGLPsUGCkBZTeU8QR/JSzGbTh7Xkfd26Q8JPz39YtKNVYrR bF0nED+ISnTAflreSqm+QQu/xhpM/WXMGJZ6idvjhSduQTxwacoRp4mM54xcjd885Uc7 kn3338QsqKdoRi9yc3bnE13Ybrxvd34r8rSvuRG41aGraY+ek53sb4jcvYSNT+1l0qLC fCxfb8/0oci4XA6zjbvT5BeJv4VgNvPLrjIfHwJBmR+SLcNTXxSaxXDDErzHomdacwTv fHQA== X-Gm-Message-State: APjAAAXixE3LDI2wRu641v3TcRPo40QPyNhstNQwC1SwBi8mhYIJKdIA aCIRzk7ggEuDzzWS38HXzO7A6bKFhto= X-Google-Smtp-Source: APXvYqxevjh8sf348suO1l8oQ8u8GnOb4XMqaGGgxCvNbUdUkvuOhbPJn3e9tRU36+vGpmfDsDTsJg== X-Received: by 2002:a92:35d0:: with SMTP id c77mr11162450ilf.94.1578856043479; Sun, 12 Jan 2020 11:07:23 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id r22sm3039219ilb.25.2020.01.12.11.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2020 11:07:23 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 19/33] sandbox: Add a new header for the system malloc() Date: Sun, 12 Jan 2020 12:06:10 -0700 Message-Id: <20200112120216.19.Ic9d6fd1bdc56d67194a9e7ea252bb9c81ec59ec4@changeid> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200112190624.79077-1-sjg@chromium.org> References: <20200112190624.79077-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean 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 --- arch/sandbox/cpu/start.c | 6 +++--- arch/sandbox/cpu/state.c | 17 +++++++++-------- arch/sandbox/include/asm/malloc.h | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 arch/sandbox/include/asm/malloc.h diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index d3ce61856e..fa53428436 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -8,10 +8,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -181,7 +181,7 @@ static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state, int len; len = strlen(state->argv[0]) + strlen(fmt) + 1; - fname = os_malloc(len); + fname = malloc(len); if (!fname) return -ENOMEM; snprintf(fname, len, fmt, state->argv[0]); @@ -201,7 +201,7 @@ static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state, int len; len = strlen(state->argv[0]) + strlen(fmt) + 1; - fname = os_malloc(len); + fname = malloc(len); if (!fname) return -ENOMEM; strcpy(fname, state->argv[0]); diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index ef2e63f37a..a347cec528 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -7,6 +7,7 @@ #include #include #include +#include #include /* Main state record for the sandbox */ @@ -27,17 +28,17 @@ static int state_ensure_space(int extra_size) return 0; size = used + extra_size; - buf = os_malloc(size); + buf = malloc(size); if (!buf) return -ENOMEM; ret = fdt_open_into(blob, buf, size); if (ret) { - os_free(buf); + free(buf); return -EIO; } - os_free(blob); + free(blob); state->state_fdt = buf; 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); return -ENOENT; } - state->state_fdt = os_malloc(size); + state->state_fdt = malloc(size); if (!state->state_fdt) { puts("No memory to read sandbox state\n"); return -ENOMEM; @@ -75,7 +76,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname) err_read: os_close(fd); err_open: - os_free(state->state_fdt); + free(state->state_fdt); state->state_fdt = NULL; 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 */ if (!state->state_fdt) { size = 0x4000; - state->state_fdt = os_malloc(size); + state->state_fdt = malloc(size); if (!state->state_fdt) { puts("No memory to create FDT\n"); return -ENOMEM; @@ -300,7 +301,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname) err_write: os_close(fd); err_create: - os_free(state->state_fdt); + free(state->state_fdt); return ret; } @@ -418,7 +419,7 @@ int state_uninit(void) os_unlink(state->jumped_fname); if (state->state_fdt) - os_free(state->state_fdt); + free(state->state_fdt); memset(state, '\0', sizeof(*state)); return 0; diff --git a/arch/sandbox/include/asm/malloc.h b/arch/sandbox/include/asm/malloc.h new file mode 100644 index 0000000000..a1467b5ead --- /dev/null +++ b/arch/sandbox/include/asm/malloc.h @@ -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