From nobody Fri Sep 16 15:53:58 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MTdsf5PYtz4cKqw; Fri, 16 Sep 2022 15:53:58 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MTdsf4mQJz3hfw; Fri, 16 Sep 2022 15:53:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663343638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3hNpKOvYzYICsHttxOpJ1e1W2yzPAUUh2GHeicqPA+Q=; b=opYHIh0A0MrXjxQQFJzIa5jriwDJfOufeMJqWLqtQDj/qDQoFB6tXiu91i/JBn/VIV1j18 kU88ROOTXtbHj3fk2h48gD0DwngjRi1rqbguDzI316C5vINpjHanwB90kInOemlGnC2UhV qRIqSbRf+vI5k5gzk8dN8e4rAATnczAuyBFTdTZgUEv7O4RMwIz99ogxhxUScIgOlxOcgO DE5BvY8b0MtDYsMLFDTls7l7Y26SAozt8zXe4LrUxQyrNupb1nabMc1pzVyXheUPV49u4m MUgOmp3sx2kAWmZNm9pY/p9Rtxt47g1ZCFX+tgUCse8DPPuPMb4ztPwQbi18dA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MTdsf3t4HzPNk; Fri, 16 Sep 2022 15:53:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28GFrwwo086483; Fri, 16 Sep 2022 15:53:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28GFrwCZ086482; Fri, 16 Sep 2022 15:53:58 GMT (envelope-from git) Date: Fri, 16 Sep 2022 15:53:58 GMT Message-Id: <202209161553.28GFrwCZ086482@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: fc352701ff3a - main - stand: collapse all copies of *copyenv into md_copyenv List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fc352701ff3aeb0af22c0da17c4194cf1f8ad5d0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663343638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3hNpKOvYzYICsHttxOpJ1e1W2yzPAUUh2GHeicqPA+Q=; b=fSkS8KkRk/T0c8GJ/n9IVoZkH9WQUFLS9kkXPx16iFp2/AVALkW/U1sW9sZvJi2/ebTHR6 oEFyie8Qu5GJPj0D1Yysdr6DpDx+wywj8IdRJwPlS91vfuxc/KAnr1tfuTm3iaK9r1q0hr G66aDbhhBuvVCxu3VzvOwKTdOtc7BViSMTcR9csCsj70YPARXGyLjDmitre+OPhMpcttNV 577WJ9psu7n6XLHGLGmW36Pymm0R8GjZkdHSjPnkgzrHrnS8kNrx1VpIr2hAZ8JagPQ5A2 4zjb0trAiYF/eQE1YdwDLTGHgAknBRbMA4YZMaxSuEletL/vd+sJt6hnz7BdRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663343638; a=rsa-sha256; cv=none; b=HYozMbcWP2ACmFjWkItjvQ4gzFCxdJil92rzSg9uKp37fyENPMn6AkNxAXE4Yg37YR4SRu NeuK5zOROM+/74wEDHYiodL1l+4Vuj/P33x8tVZNouweSDJlS2HvzQgHBwI7E1sUIpAWdk qagt+nJLAOdjyvhRmOg4uapgDeaxQDvvE2g0e3tKu4olVr2XDiQB0t2i9lWJdD98yT7uAB IZY7PkFPCyh+imxASUjifCUkOSZ0y1IGSbJtJDaOBYCTubSo/RwKzhX6KQbyGxPxK24w7a SXGer10zACOmIYllFnqWRpWL877ZKnK3NNucx1eAPvhZUkx8L/nnItJQJu/gfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=fc352701ff3aeb0af22c0da17c4194cf1f8ad5d0 commit fc352701ff3aeb0af22c0da17c4194cf1f8ad5d0 Author: Warner Losh AuthorDate: 2022-09-16 15:08:57 +0000 Commit: Warner Losh CommitDate: 2022-09-16 15:18:56 +0000 stand: collapse all copies of *copyenv into md_copyenv Use the efi's bi_copyenv to md_copyenv and place it in modinfo.c. Remove all other nearly identical and efi's has the best error handling. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36574 --- stand/common/metadata.c | 28 ------------------------ stand/common/modinfo.c | 39 +++++++++++++++++++++++++++++++++ stand/common/modinfo.h | 1 + stand/efi/loader/bootinfo.c | 41 +---------------------------------- stand/i386/libi386/bootinfo.c | 28 ------------------------ stand/i386/libi386/bootinfo32.c | 2 +- stand/i386/libi386/bootinfo64.c | 2 +- stand/i386/libi386/libi386.h | 1 - stand/userboot/userboot/bootinfo.c | 28 ------------------------ stand/userboot/userboot/bootinfo32.c | 2 +- stand/userboot/userboot/bootinfo64.c | 2 +- stand/userboot/userboot/libuserboot.h | 1 - 12 files changed, 45 insertions(+), 130 deletions(-) diff --git a/stand/common/metadata.c b/stand/common/metadata.c index 37171ec3be99..fc8857ee089e 100644 --- a/stand/common/metadata.c +++ b/stand/common/metadata.c @@ -65,34 +65,6 @@ md_getboothowto(char *kargs) return(howto); } -/* - * Copy the environment into the load area starting at (addr). - * Each variable is formatted as =, with a single nul - * separating each variable, and a double nul terminating the environment. - */ -static vm_offset_t -md_copyenv(vm_offset_t addr) -{ - struct env_var *ep; - - /* traverse the environment */ - for (ep = environ; ep != NULL; ep = ep->ev_next) { - archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name)); - addr += strlen(ep->ev_name); - archsw.arch_copyin("=", addr, 1); - addr++; - if (ep->ev_value != NULL) { - archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value)); - addr += strlen(ep->ev_value); - } - archsw.arch_copyin("", addr, 1); - addr++; - } - archsw.arch_copyin("", addr, 1); - addr++; - return(addr); -} - /* * Load the information expected by a kernel. * diff --git a/stand/common/modinfo.c b/stand/common/modinfo.c index 15116b3b9b78..0c00b2070274 100644 --- a/stand/common/modinfo.c +++ b/stand/common/modinfo.c @@ -148,3 +148,42 @@ md_copymodules(vm_offset_t addr, bool kern64) MOD_END(addr, c); return(addr); } + +/* + * Copy the environment into the load area starting at (addr). + * Each variable is formatted as =, with a single nul + * separating each variable, and a double nul terminating the environment. + */ +vm_offset_t +md_copyenv(vm_offset_t start) +{ + struct env_var *ep; + vm_offset_t addr, last; + size_t len; + + addr = last = start; + + /* Traverse the environment. */ + for (ep = environ; ep != NULL; ep = ep->ev_next) { + len = strlen(ep->ev_name); + if ((size_t)archsw.arch_copyin(ep->ev_name, addr, len) != len) + break; + addr += len; + if (archsw.arch_copyin("=", addr, 1) != 1) + break; + addr++; + if (ep->ev_value != NULL) { + len = strlen(ep->ev_value); + if ((size_t)archsw.arch_copyin(ep->ev_value, addr, len) != len) + break; + addr += len; + } + if (archsw.arch_copyin("", addr, 1) != 1) + break; + last = ++addr; + } + + if (archsw.arch_copyin("", last++, 1) != 1) + last = start; + return(last); +} diff --git a/stand/common/modinfo.h b/stand/common/modinfo.h index fc56173e1c51..e4739df0b68f 100644 --- a/stand/common/modinfo.h +++ b/stand/common/modinfo.h @@ -7,5 +7,6 @@ #define COMMON_MODINFO_H vm_offset_t md_copymodules(vm_offset_t addr, bool kern64); +vm_offset_t md_copyenv(vm_offset_t addr); #endif /* COMMON_MODINFO_H */ diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 9f56365536d1..558f7bdae91e 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -126,45 +126,6 @@ bi_getboothowto(char *kargs) return (howto); } -/* - * Copy the environment into the load area starting at (addr). - * Each variable is formatted as =, with a single nul - * separating each variable, and a double nul terminating the environment. - */ -static vm_offset_t -bi_copyenv(vm_offset_t start) -{ - struct env_var *ep; - vm_offset_t addr, last; - size_t len; - - addr = last = start; - - /* Traverse the environment. */ - for (ep = environ; ep != NULL; ep = ep->ev_next) { - len = strlen(ep->ev_name); - if ((size_t)archsw.arch_copyin(ep->ev_name, addr, len) != len) - break; - addr += len; - if (archsw.arch_copyin("=", addr, 1) != 1) - break; - addr++; - if (ep->ev_value != NULL) { - len = strlen(ep->ev_value); - if ((size_t)archsw.arch_copyin(ep->ev_value, addr, len) != len) - break; - addr += len; - } - if (archsw.arch_copyin("", addr, 1) != 1) - break; - last = ++addr; - } - - if (archsw.arch_copyin("", last++, 1) != 1) - last = start; - return(last); -} - static EFI_STATUS efi_do_vmap(EFI_MEMORY_DESCRIPTOR *mm, UINTN sz, UINTN mmsz, UINT32 mmver) { @@ -408,7 +369,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) /* Copy our environment. */ envp = addr; - addr = bi_copyenv(addr); + addr = md_copyenv(addr); /* Pad to a page boundary. */ addr = roundup(addr, PAGE_SIZE); diff --git a/stand/i386/libi386/bootinfo.c b/stand/i386/libi386/bootinfo.c index 84a0b3586a1c..92238d4fab44 100644 --- a/stand/i386/libi386/bootinfo.c +++ b/stand/i386/libi386/bootinfo.c @@ -103,31 +103,3 @@ bi_setboothowto(int howto) boot_howto_to_env(howto); } - -/* - * Copy the environment into the load area starting at (addr). - * Each variable is formatted as =, with a single nul - * separating each variable, and a double nul terminating the environment. - */ -vm_offset_t -bi_copyenv(vm_offset_t addr) -{ - struct env_var *ep; - - /* traverse the environment */ - for (ep = environ; ep != NULL; ep = ep->ev_next) { - archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name)); - addr += strlen(ep->ev_name); - archsw.arch_copyin("=", addr, 1); - addr++; - if (ep->ev_value != NULL) { - archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value)); - addr += strlen(ep->ev_value); - } - archsw.arch_copyin("", addr, 1); - addr++; - } - archsw.arch_copyin("", addr, 1); - addr++; - return(addr); -} diff --git a/stand/i386/libi386/bootinfo32.c b/stand/i386/libi386/bootinfo32.c index 965b62bbad81..9ca6a70d674e 100644 --- a/stand/i386/libi386/bootinfo32.c +++ b/stand/i386/libi386/bootinfo32.c @@ -126,7 +126,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t /* copy our environment */ envp = addr; - addr = bi_copyenv(addr); + addr = md_copyenv(addr); /* pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); diff --git a/stand/i386/libi386/bootinfo64.c b/stand/i386/libi386/bootinfo64.c index 8b5eb8c1db93..bc8830d09098 100644 --- a/stand/i386/libi386/bootinfo64.c +++ b/stand/i386/libi386/bootinfo64.c @@ -167,7 +167,7 @@ bi_load64(char *args, vm_offset_t *modulep, /* copy our environment */ envp = roundup(addr + size, PAGE_SIZE); - addr = bi_copyenv(envp); + addr = md_copyenv(envp); /* set kernend */ kernend = roundup(addr, PAGE_SIZE); diff --git a/stand/i386/libi386/libi386.h b/stand/i386/libi386/libi386.h index 9c7a452a03ad..0115f30e31c7 100644 --- a/stand/i386/libi386/libi386.h +++ b/stand/i386/libi386/libi386.h @@ -146,7 +146,6 @@ int i386_autoload(void); void bi_load_vbe_data(struct preloaded_file *kfp); int bi_getboothowto(char *kargs); void bi_setboothowto(int howto); -vm_offset_t bi_copyenv(vm_offset_t addr); int bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t *modulep, vm_offset_t *kernend); int bi_load64(char *args, vm_offset_t *modulep, diff --git a/stand/userboot/userboot/bootinfo.c b/stand/userboot/userboot/bootinfo.c index 36a5e1982313..d77b2f3e51c7 100644 --- a/stand/userboot/userboot/bootinfo.c +++ b/stand/userboot/userboot/bootinfo.c @@ -83,31 +83,3 @@ bi_setboothowto(int howto) boot_howto_to_env(howto); } - -/* - * Copy the environment into the load area starting at (addr). - * Each variable is formatted as =, with a single nul - * separating each variable, and a double nul terminating the environment. - */ -vm_offset_t -bi_copyenv(vm_offset_t addr) -{ - struct env_var *ep; - - /* traverse the environment */ - for (ep = environ; ep != NULL; ep = ep->ev_next) { - archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name)); - addr += strlen(ep->ev_name); - archsw.arch_copyin("=", addr, 1); - addr++; - if (ep->ev_value != NULL) { - archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value)); - addr += strlen(ep->ev_value); - } - archsw.arch_copyin("", addr, 1); - addr++; - } - archsw.arch_copyin("", addr, 1); - addr++; - return(addr); -} diff --git a/stand/userboot/userboot/bootinfo32.c b/stand/userboot/userboot/bootinfo32.c index 8203f90c98fe..08dde13baa30 100644 --- a/stand/userboot/userboot/bootinfo32.c +++ b/stand/userboot/userboot/bootinfo32.c @@ -106,7 +106,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t /* copy our environment */ envp = addr; - addr = bi_copyenv(addr); + addr = md_copyenv(addr); /* pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); diff --git a/stand/userboot/userboot/bootinfo64.c b/stand/userboot/userboot/bootinfo64.c index 6d711cf51759..530ddaf768ed 100644 --- a/stand/userboot/userboot/bootinfo64.c +++ b/stand/userboot/userboot/bootinfo64.c @@ -138,7 +138,7 @@ bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernendp) /* copy our environment */ envp = addr; - addr = bi_copyenv(addr); + addr = md_copyenv(addr); /* pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); diff --git a/stand/userboot/userboot/libuserboot.h b/stand/userboot/userboot/libuserboot.h index eb3bada097e4..6d7dc0c3ff40 100644 --- a/stand/userboot/userboot/libuserboot.h +++ b/stand/userboot/userboot/libuserboot.h @@ -61,7 +61,6 @@ int userboot_setcurrdev(struct env_var *ev, int flags, const void *value); int bi_getboothowto(char *kargs); void bi_setboothowto(int howto); -vm_offset_t bi_copyenv(vm_offset_t addr); int bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t *modulep, vm_offset_t *kernend); int bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernend);