]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use memcpy/memset provided by firmware 23701/head
authorJan Janssen <medhefgo@web.de>
Fri, 10 Jun 2022 13:29:39 +0000 (15:29 +0200)
committerJan Janssen <medhefgo@web.de>
Fri, 10 Jun 2022 13:54:06 +0000 (15:54 +0200)
These are significantly faster and safe us from rolling our own
optimized versions.

src/boot/efi/efi-string.c

index f5b671c7be80c1b683922f562dbaa0e99b91886a..b8c576b8f0fbbca4829249fd0e9c889021e12c33 100644 (file)
@@ -263,6 +263,16 @@ void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n) {
         if (!dest || !src || n == 0)
                 return dest;
 
+#ifdef SD_BOOT
+        /* The firmware-provided memcpy is likely optimized, so use that. The function is guaranteed to be
+         * available by the UEFI spec. We still make it depend on the boot services pointer being set just in
+         * case the compiler emits a call before it is available. */
+        if (_likely_(BS)) {
+                BS->CopyMem(dest, (void *) src, n);
+                return dest;
+        }
+#endif
+
         uint8_t *d = dest;
         const uint8_t *s = src;
 
@@ -280,6 +290,14 @@ void *efi_memset(void *p, int c, size_t n) {
         if (!p || n == 0)
                 return p;
 
+#ifdef SD_BOOT
+        /* See comment in efi_memcpy. Note that the signature has c and n swapped! */
+        if (_likely_(BS)) {
+                BS->SetMem(p, n, c);
+                return p;
+        }
+#endif
+
         uint8_t *q = p;
         while (n > 0) {
                 *q = c;