From owner-svn-src-head@freebsd.org Thu Sep 24 06:40:36 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5E3BC3EE2E2; Thu, 24 Sep 2020 06:40:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BxlmN1vP2z40TB; Thu, 24 Sep 2020 06:40:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2514C1DC92; Thu, 24 Sep 2020 06:40:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08O6eaWX066257; Thu, 24 Sep 2020 06:40:36 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08O6ea8L066256; Thu, 24 Sep 2020 06:40:36 GMT (envelope-from imp@FreeBSD.org) Message-Id: <202009240640.08O6ea8L066256@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 24 Sep 2020 06:40:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366101 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 366101 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Sep 2020 06:40:36 -0000 Author: imp Date: Thu Sep 24 06:40:35 2020 New Revision: 366101 URL: https://svnweb.freebsd.org/changeset/base/366101 Log: Create a standalone version of sys/malloc.h The ZSTD support for the boot loader will need to include files that use the kernel's malloc interface. Create a standalone stub version that's functional enough to allow this to work. There's some limitations in this interface, and it's not quite a perfect match. Specifically, M_WAITOK allocations can fail because there's nothing that can be done we no memory is available. Modified: head/sys/sys/malloc.h Modified: head/sys/sys/malloc.h ============================================================================== --- head/sys/sys/malloc.h Thu Sep 24 06:12:57 2020 (r366100) +++ head/sys/sys/malloc.h Thu Sep 24 06:40:35 2020 (r366101) @@ -37,6 +37,7 @@ #ifndef _SYS_MALLOC_H_ #define _SYS_MALLOC_H_ +#ifndef _STANDALONE #include #ifdef _KERNEL #include @@ -267,4 +268,34 @@ WOULD_OVERFLOW(size_t nmemb, size_t size) #undef MUL_NO_OVERFLOW #endif /* _KERNEL */ +#else +/* + * The native stand malloc / free interface we're mapping to + */ +extern void Free(void *p, const char *file, int line); +extern void *Malloc(size_t bytes, const char *file, int line); + +/* + * Minimal standalone malloc implementation / environment. None of the + * flags mean anything and there's no need declare malloc types. + * Define the simple alloc / free routines in terms of Malloc and + * Free. None of the kernel features that this stuff disables are needed. + * + * XXX we are setting ourselves up for a potential crash if we can't allocate + * memory for a M_WAITOK call. + */ +#define M_WAITOK 0 +#define M_ZERO 0 +#define M_NOWAIT 0 +#define MALLOC_DECLARE(x) + +#define kmem_zalloc(size, flags) Malloc((size), __FILE__, __LINE__) +#define kmem_free(p, size) Free(p, __FILE__, __LINE__) + +/* + * ZFS mem.h define that's the OpenZFS porting layer way of saying + * M_WAITOK. Given the above, it will also be a nop. + */ +#define KM_SLEEP M_WAITOK +#endif /* _STANDALONE */ #endif /* !_SYS_MALLOC_H_ */