summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-03-09 11:42:34 -0500
committerPeter Jones <pjones@redhat.com>2021-03-10 15:54:20 -0500
commitf033a1da9f4c3acf7e3dfef906d01e348b6fcf42 (patch)
tree1c325b0dd61cb1bd78b585ca870298fb74f857d4
parent758b795a86589994065099d0af02eb30626a3c21 (diff)
downloadefi-boot-shim-f033a1da9f4c3acf7e3dfef906d01e348b6fcf42.tar.gz
efi-boot-shim-f033a1da9f4c3acf7e3dfef906d01e348b6fcf42.zip
Restructure our includes.
This re-structures our includes so we can be sure everything is always including all the system headers in a uniform, predictable way. Temporarily it also adds a bunch of junk at all the places we use variadic functions to specifically pick either the MS (cdecl) or ELF ABIs. I'm not 100% sure that's all correct (see later patch) but it's enough to allow this to build. Signed-off-by: Peter Jones <pjones@redhat.com>
-rw-r--r--Cryptlib/Include/OpenSslSupport.h13
-rw-r--r--Cryptlib/Include/ctype.h16
-rw-r--r--Cryptlib/Include/openssl/crypto.h1
-rw-r--r--Cryptlib/Include/stdarg.h16
-rw-r--r--Cryptlib/Include/stddef.h15
-rw-r--r--Cryptlib/Include/stdlib.h16
-rw-r--r--Cryptlib/Include/string.h16
-rw-r--r--Cryptlib/Include/strings.h15
-rw-r--r--Cryptlib/InternalCryptLib.h2
-rw-r--r--Cryptlib/Makefile14
-rw-r--r--Cryptlib/OpenSSL/Makefile16
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_print.c8
-rw-r--r--Make.defaults3
-rw-r--r--Makefile7
-rw-r--r--MokManager.c8
-rw-r--r--PasswordCrypt.c6
-rw-r--r--crypt_blowfish.c5
-rw-r--r--errlog.c29
-rw-r--r--fallback.c4
-rw-r--r--httpboot.c4
-rw-r--r--include/console.h8
-rw-r--r--include/hexdump.h17
-rw-r--r--include/system/alloca.h10
-rw-r--r--include/system/ctype.h14
-rw-r--r--include/system/inttypes.h13
-rw-r--r--include/system/stdarg.h31
-rw-r--r--include/system/stdio.h13
-rw-r--r--include/system/stdlib.h16
-rw-r--r--include/system/string.h14
-rw-r--r--include/system/strings.h10
-rw-r--r--include/test.h4
-rw-r--r--lib/Makefile39
-rw-r--r--lib/configtable.c3
-rw-r--r--lib/console.c21
-rw-r--r--lib/execute.c4
-rw-r--r--lib/print_crypto.c5
-rw-r--r--lib/security_policy.c4
-rw-r--r--lib/shell.c3
-rw-r--r--lib/simple_file.c4
-rw-r--r--lib/variables.c3
-rw-r--r--mok.c4
-rw-r--r--netboot.c2
-rw-r--r--pe.c1
-rw-r--r--replacements.c5
-rw-r--r--sbat.c1
-rw-r--r--shim.c1
-rw-r--r--shim.h25
-rw-r--r--test.c3
-rw-r--r--tpm.c6
49 files changed, 262 insertions, 236 deletions
diff --git a/Cryptlib/Include/OpenSslSupport.h b/Cryptlib/Include/OpenSslSupport.h
index 0b555271..7af9650f 100644
--- a/Cryptlib/Include/OpenSslSupport.h
+++ b/Cryptlib/Include/OpenSslSupport.h
@@ -15,6 +15,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __OPEN_SSL_SUPPORT_H__
#define __OPEN_SSL_SUPPORT_H__
+/*
+ * Include stddef.h to avoid redefining "offsetof"
+ */
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+
#include <efi.h>
#include <efilib.h>
#include "Base.h"
@@ -23,11 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Library/MemoryAllocationLib.h"
#include "Library/DebugLib.h"
-/*
- * Include stddef.h to avoid redefining "offsetof"
- */
-#include <stddef.h>
-
#define CONST const
//
diff --git a/Cryptlib/Include/ctype.h b/Cryptlib/Include/ctype.h
deleted file mode 100644
index ee07f6bc..00000000
--- a/Cryptlib/Include/ctype.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
-
diff --git a/Cryptlib/Include/openssl/crypto.h b/Cryptlib/Include/openssl/crypto.h
index bea4ca19..e201a123 100644
--- a/Cryptlib/Include/openssl/crypto.h
+++ b/Cryptlib/Include/openssl/crypto.h
@@ -117,6 +117,7 @@
#ifndef HEADER_CRYPTO_H
# define HEADER_CRYPTO_H
+# include <string.h>
# include <stdlib.h>
# include <openssl/e_os2.h>
diff --git a/Cryptlib/Include/stdarg.h b/Cryptlib/Include/stdarg.h
deleted file mode 100644
index ee07f6bc..00000000
--- a/Cryptlib/Include/stdarg.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
-
diff --git a/Cryptlib/Include/stddef.h b/Cryptlib/Include/stddef.h
deleted file mode 100644
index 8dfc36ff..00000000
--- a/Cryptlib/Include/stddef.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
diff --git a/Cryptlib/Include/stdlib.h b/Cryptlib/Include/stdlib.h
deleted file mode 100644
index ee07f6bc..00000000
--- a/Cryptlib/Include/stdlib.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
-
diff --git a/Cryptlib/Include/string.h b/Cryptlib/Include/string.h
deleted file mode 100644
index ee07f6bc..00000000
--- a/Cryptlib/Include/string.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
-
diff --git a/Cryptlib/Include/strings.h b/Cryptlib/Include/strings.h
deleted file mode 100644
index 8dfc36ff..00000000
--- a/Cryptlib/Include/strings.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/** @file
- Include file to support building OpenSSL Crypto Library.
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <OpenSslSupport.h>
diff --git a/Cryptlib/InternalCryptLib.h b/Cryptlib/InternalCryptLib.h
index e9a4c20a..dc1a95e6 100644
--- a/Cryptlib/InternalCryptLib.h
+++ b/Cryptlib/InternalCryptLib.h
@@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __INTERNAL_CRYPT_LIB_H__
#define __INTERNAL_CRYPT_LIB_H__
+#include <stdarg.h>
+
#include "Library/BaseLib.h"
#include "Library/BaseMemoryLib.h"
#include "Library/MemoryAllocationLib.h"
diff --git a/Cryptlib/Makefile b/Cryptlib/Makefile
index bc5681c5..65a3918c 100644
--- a/Cryptlib/Makefile
+++ b/Cryptlib/Makefile
@@ -2,8 +2,14 @@ ifneq ($(CCACHE_DISABLE),)
export CCACHE_DISABLE
endif
-INCLUDES = -I$(TOPDIR) -iquote $(TOPDIR) -I$(TOPDIR)/Include \
- $(EFI_INCLUDES) -I$(shell $(CC) -print-file-name=include)
+CRYPTDIR = $(TOPDIR)/Cryptlib
+
+FEATUREFLAGS += -nostdinc
+
+INCLUDES = -I$(CRYPTDIR) -I$(CRYPTDIR)/Include \
+ $(EFI_INCLUDES) \
+ -isystem $(TOPDIR)/include/system \
+ -isystem $(shell $(CC) -print-file-name=include)
CFLAGS = $(FEATUREFLAGS) \
$(OPTIMIZATIONS) \
@@ -15,12 +21,12 @@ CFLAGS = $(FEATUREFLAGS) \
CLANG_BUGS = $(if $(findstring gcc,$(CC)),-maccumulate-outgoing-args,)
ifeq ($(ARCH),x86_64)
-FEATUREFLAGS += -m64 -mno-mmx -mno-sse -mno-red-zone -nostdinc $(CLANG_BUGS)
+FEATUREFLAGS += -m64 -mno-mmx -mno-sse -mno-red-zone $(CLANG_BUGS)
DEFINES += -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI \
-DNO_BUILTIN_VA_FUNCS -DMDE_CPU_X64
endif
ifeq ($(ARCH),ia32)
-FEATUREFLAGS += -m32 -mno-mmx -mno-sse -mno-red-zone -nostdinc $(CLANG_BUGS)
+FEATUREFLAGS += -m32 -mno-mmx -mno-sse -mno-red-zone $(CLANG_BUGS)
DEFINES += -DMDE_CPU_IA32
endif
ifeq ($(ARCH),aarch64)
diff --git a/Cryptlib/OpenSSL/Makefile b/Cryptlib/OpenSSL/Makefile
index 5bd72481..294e889a 100644
--- a/Cryptlib/OpenSSL/Makefile
+++ b/Cryptlib/OpenSSL/Makefile
@@ -2,17 +2,23 @@ ifneq ($(CCACHE_DISABLE),)
export CCACHE_DISABLE
endif
+CRYPTDIR = $(TOPDIR)/Cryptlib
+OSSLDIR = $(TOPDIR)/Cryptlib/OpenSSL
+
DEFINES = -DL_ENDIAN \
-D_CRT_SECURE_NO_DEPRECATE \
-D_CRT_NONSTDC_NO_DEPRECATE \
-DOPENSSL_SMALL_FOOTPRINT \
-DPEDANTIC
-INCLUDES = -I$(TOPDIR) -I$(TOPDIR)/.. -I$(TOPDIR)/../Include/ -I$(TOPDIR)/crypto \
- -I$(shell $(CC) -print-file-name=include) \
- -I$(TOPDIR)/../Include $(EFI_INCLUDES) \
- -I$(TOPDIR)/crypto/asn1 -I$(TOPDIR)/crypto/evp \
- -I$(TOPDIR)/crypto/modes -I$(TOPDIR)/crypto/include
+INCLUDES = -I$(OSSLDIR) -I$(CRYPTDIR) -I$(OSSLDIR)/Include/ \
+ -I$(OSSLDIR)/crypto -I$(CRYPTDIR)/Include $(EFI_INCLUDES) \
+ -I$(OSSLDIR)/crypto/asn1 -I$(OSSLDIR)/crypto/evp \
+ -I$(OSSLDIR)/crypto/modes -I$(OSSLDIR)/crypto/include \
+ -isystem $(TOPDIR)/include/system \
+ -isystem $(shell $(CC) -print-file-name=include)
+
+FEATUREFLAGS += -nostdinc
WERRFLAGS += -Wno-error=discarded-qualifiers \
-Wno-error=maybe-uninitialized \
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_print.c b/Cryptlib/OpenSSL/crypto/bio/b_print.c
index fea73864..2d303ee8 100644
--- a/Cryptlib/OpenSSL/crypto/bio/b_print.c
+++ b/Cryptlib/OpenSSL/crypto/bio/b_print.c
@@ -134,9 +134,9 @@ static int fmtfp(char **, char **, size_t *, size_t *,
LDOUBLE, int, int, int);
#endif
static int doapr_outch(char **, char **, size_t *, size_t *, int);
-static int _dopr(char **sbuffer, char **buffer,
- size_t *maxlen, size_t *retlen, int *truncated,
- const char *format, va_list args);
+static int EFIAPI _dopr(char **sbuffer, char **buffer,
+ size_t *maxlen, size_t *retlen, int *truncated,
+ const char *format, va_list args);
/* format read states */
#define DP_S_DEFAULT 0
@@ -167,7 +167,7 @@ static int _dopr(char **sbuffer, char **buffer,
#define char_to_int(p) (p - '0')
#define OSSL_MAX(p,q) ((p >= q) ? p : q)
-static int
+static int EFIAPI
_dopr(char **sbuffer,
char **buffer,
size_t *maxlen,
diff --git a/Make.defaults b/Make.defaults
index bef3cb51..ebb9e3c3 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -102,7 +102,8 @@ INCLUDES = -nostdinc \
-I$(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include) \
-I$(TOPDIR)/Cryptlib -I$(TOPDIR)/Cryptlib/Include \
-I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH_GNUEFI) -I$(EFI_INCLUDE)/protocol \
- -I$(TOPDIR)/include -iquote $(TOPDIR) -iquote $(shell pwd)
+ -I$(TOPDIR)/include -iquote $(TOPDIR) -iquote $(shell pwd) \
+ -isystem $(TOPDIR)/include/system
override DEFAULT_FEATUREFLAGS = \
-std=gnu11 \
diff --git a/Makefile b/Makefile
index c1d13947..6a62e00a 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ override TOPDIR := $(shell pwd)
endif
override TOPDIR := $(abspath $(TOPDIR))
VPATH = $(TOPDIR)
+export TOPDIR
include $(TOPDIR)/Make.rules
include $(TOPDIR)/Make.defaults
@@ -134,15 +135,15 @@ gnu-efi/$(ARCH_GNUEFI)/gnuefi/libgnuefi.a gnu-efi/$(ARCH_GNUEFI)/lib/libefi.a:
Cryptlib/libcryptlib.a:
for i in Hash Hmac Cipher Rand Pk Pem SysCall; do mkdir -p Cryptlib/$$i; done
- $(MAKE) VPATH=$(TOPDIR)/Cryptlib TOPDIR=$(TOPDIR)/Cryptlib -C Cryptlib -f $(TOPDIR)/Cryptlib/Makefile
+ $(MAKE) VPATH=$(TOPDIR)/Cryptlib -C Cryptlib -f $(TOPDIR)/Cryptlib/Makefile
Cryptlib/OpenSSL/libopenssl.a:
for i in x509v3 x509 txt_db stack sha rsa rc4 rand pkcs7 pkcs12 pem ocsp objects modes md5 lhash kdf hmac evp err dso dh conf comp cmac buffer bn bio async/arch asn1 aes; do mkdir -p Cryptlib/OpenSSL/crypto/$$i; done
- $(MAKE) VPATH=$(TOPDIR)/Cryptlib/OpenSSL TOPDIR=$(TOPDIR)/Cryptlib/OpenSSL -C Cryptlib/OpenSSL -f $(TOPDIR)/Cryptlib/OpenSSL/Makefile
+ $(MAKE) VPATH=$(TOPDIR)/Cryptlib/OpenSSL -C Cryptlib/OpenSSL -f $(TOPDIR)/Cryptlib/OpenSSL/Makefile
lib/lib.a: | $(TOPDIR)/lib/Makefile $(wildcard $(TOPDIR)/include/*.[ch])
if [ ! -d lib ]; then mkdir lib ; fi
- $(MAKE) VPATH=$(TOPDIR)/lib TOPDIR=$(TOPDIR) CFLAGS="$(CFLAGS)" -C lib -f $(TOPDIR)/lib/Makefile lib.a
+ $(MAKE) VPATH=$(TOPDIR)/lib -C lib -f $(TOPDIR)/lib/Makefile lib.a
buildid : $(TOPDIR)/buildid.c
$(CC) -Og -g3 -Wall -Werror -Wextra -o $@ $< -lelf
diff --git a/MokManager.c b/MokManager.c
index 5a851d86..cd1492f8 100644
--- a/MokManager.c
+++ b/MokManager.c
@@ -1,18 +1,12 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
+#include "shim.h"
-#include <efi.h>
-#include <efilib.h>
-#include <stdarg.h>
#include <Library/BaseCryptLib.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/asn1.h>
#include <openssl/bn.h>
-#include "shim.h"
-
-#include "hexdump.h"
-
#define PASSWORD_MAX 256
#define PASSWORD_MIN 1
#define SB_PASSWORD_LEN 16
diff --git a/PasswordCrypt.c b/PasswordCrypt.c
index 311c914b..1030a6dd 100644
--- a/PasswordCrypt.c
+++ b/PasswordCrypt.c
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
-#include <efi.h>
-#include <efilib.h>
+#include "shim.h"
+
#include <Library/BaseCryptLib.h>
#include <openssl/sha.h>
#include <openssl/md5.h>
-#include "shim.h"
-
#define TRAD_DES_HASH_SIZE 13 /* (64/6+1) + (12/6) */
#define BSDI_DES_HASH_SIZE 20 /* (64/6+1) + (24/6) + 4 + 1 */
#define BLOWFISH_HASH_SIZE 31 /* 184/6+1 */
diff --git a/crypt_blowfish.c b/crypt_blowfish.c
index 7a474f26..b1eb0e60 100644
--- a/crypt_blowfish.c
+++ b/crypt_blowfish.c
@@ -43,11 +43,6 @@
* Blowfish library (I can't be sure if I would think of something if I
* hadn't seen his code).
*/
-
-#include <efi.h>
-#include <efilib.h>
-
-/* Just to make sure the prototypes match the actual definitions */
#include "shim.h"
typedef unsigned int BF_word;
diff --git a/errlog.c b/errlog.c
index 714d09d3..16af23b0 100644
--- a/errlog.c
+++ b/errlog.c
@@ -5,30 +5,29 @@
*/
#include "shim.h"
-#include "hexdump.h"
static CHAR16 **errs = NULL;
static UINTN nerrs = 0;
-EFI_STATUS
-vdprint_(const CHAR16 *fmt, const char *file, int line, const char *func, va_list args)
+EFI_STATUS EFIAPI
+vdprint_(const CHAR16 *fmt, const char *file, int line, const char *func, elf_va_list args)
{
- va_list args2;
+ elf_va_list args2;
EFI_STATUS efi_status = EFI_SUCCESS;
if (verbose) {
- va_copy(args2, args);
+ elf_va_copy(args2, args);
console_print(L"%a:%d:%a() ", file, line, func);
efi_status = VPrint(fmt, args2);
- va_end(args2);
+ elf_va_end(args2);
}
return efi_status;
}
-EFI_STATUS
-VLogError(const char *file, int line, const char *func, const CHAR16 *fmt, va_list args)
+EFI_STATUS EFIAPI
+VLogError(const char *file, int line, const char *func, const CHAR16 *fmt, elf_va_list args)
{
- va_list args2;
+ elf_va_list args2;
CHAR16 **newerrs;
newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs),
@@ -39,11 +38,11 @@ VLogError(const char *file, int line, const char *func, const CHAR16 *fmt, va_li
newerrs[nerrs] = PoolPrint(L"%a:%d %a() ", file, line, func);
if (!newerrs[nerrs])
return EFI_OUT_OF_RESOURCES;
- va_copy(args2, args);
+ elf_va_copy(args2, args);
newerrs[nerrs+1] = VPoolPrint(fmt, args2);
if (!newerrs[nerrs+1])
return EFI_OUT_OF_RESOURCES;
- va_end(args2);
+ elf_va_end(args2);
nerrs += 2;
newerrs[nerrs] = NULL;
@@ -52,15 +51,15 @@ VLogError(const char *file, int line, const char *func, const CHAR16 *fmt, va_li
return EFI_SUCCESS;
}
-EFI_STATUS
+EFI_STATUS EFIAPI
LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
{
- va_list args;
+ elf_va_list args;
EFI_STATUS efi_status;
- va_start(args, fmt);
+ elf_va_start(args, fmt);
efi_status = VLogError(file, line, func, fmt, args);
- va_end(args);
+ elf_va_end(args);
return efi_status;
}
diff --git a/fallback.c b/fallback.c
index fc81c5e4..ba90bb3b 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,10 +3,6 @@
* Copyright Red Hat, Inc.
* Copyright Peter Jones <pjones@redhat.com>
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
#define NO_REBOOT L"FB_NO_REBOOT"
diff --git a/httpboot.c b/httpboot.c
index bedb99d2..fe08f3f7 100644
--- a/httpboot.c
+++ b/httpboot.c
@@ -7,10 +7,6 @@
* (http://tianocore.sf.net) and are Copyright 2009-2012 Intel
* Corporation.
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
static UINTN
diff --git a/include/console.h b/include/console.h
index b2ab5fe4..d8af3cd3 100644
--- a/include/console.h
+++ b/include/console.h
@@ -17,9 +17,9 @@
EFI_STATUS
console_get_keystroke(EFI_INPUT_KEY *key);
-UINTN
+UINTN EFIAPI
console_print(const CHAR16 *fmt, ...);
-UINTN
+UINTN EFIAPI
console_print_at(UINTN col, UINTN row, const CHAR16 *fmt, ...);
void
console_print_box_at(CHAR16 *str_arr[], int highlight,
@@ -101,8 +101,8 @@ extern UINT32 verbose;
#define dprint(fmt, ...) \
dprint_(L"%a:%d:%a() " fmt, __FILE__, __LINE__ - 1, __func__, \
##__VA_ARGS__)
-extern EFI_STATUS
-vdprint_(const CHAR16 *fmt, const char *file, int line, const char *func, va_list args);
+extern EFI_STATUS EFIAPI vdprint_(const CHAR16 *fmt, const char *file, int line,
+ const char *func, elf_va_list args);
#define vdprint(fmt, ...) \
vdprint_(fmt, __FILE__, __LINE__ - 1, __func__, ##__VA_ARGS__)
diff --git a/include/hexdump.h b/include/hexdump.h
index 8b8b4557..36d77ec4 100644
--- a/include/hexdump.h
+++ b/include/hexdump.h
@@ -3,7 +3,8 @@
#ifndef STATIC_HEXDUMP_H
#define STATIC_HEXDUMP_H
-#include <stdint.h>
+#include "shim.h"
+#include "include/console.h"
static inline unsigned long UNUSED
prepare_hex(const void *data, size_t size, char *buf, unsigned int position)
@@ -80,8 +81,9 @@ prepare_text(const void *data, size_t size, char *buf, unsigned int position)
* variadic hexdump formatted
* think of it as: printf("%s%s\n", vformat(fmt, ap), hexdump(data,size));
*/
-static inline void UNUSED
-vhexdumpf(const char *file, int line, const char *func, const CHAR16 * const fmt, const void *data, unsigned long size, size_t at, va_list ap)
+static inline void UNUSED EFIAPI
+vhexdumpf(const char *file, int line, const char *func, const CHAR16 *const fmt,
+ const void *data, unsigned long size, size_t at, elf_va_list ap)
{
unsigned long display_offset = at;
unsigned long offset = 0;
@@ -115,13 +117,14 @@ vhexdumpf(const char *file, int line, const char *func, const CHAR16 * const fmt
* think of it as: printf("%s%s", format(fmt, ...), hexdump(data,size)[lineN]);
*/
static inline void UNUSED
-hexdumpf(const char *file, int line, const char *func, const CHAR16 * const fmt, const void *data, unsigned long size, size_t at, ...)
+hexdumpf(const char *file, int line, const char *func, const CHAR16 *const fmt,
+ const void *data, unsigned long size, size_t at, ...)
{
- va_list ap;
+ elf_va_list ap;
- va_start(ap, at);
+ elf_va_start(ap, at);
vhexdumpf(file, line, func, fmt, data, size, at, ap);
- va_end(ap);
+ elf_va_end(ap);
}
static inline void UNUSED
diff --git a/include/system/alloca.h b/include/system/alloca.h
new file mode 100644
index 00000000..dc11b60d
--- /dev/null
+++ b/include/system/alloca.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+#ifdef SHIM_UNIT_TEST
+#include_next <alloca.h>
+#else
+#ifndef _ALLOCA_H
+#define _ALLOCA_H
+
+#endif /* !_ALLOCA_H */
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/ctype.h b/include/system/ctype.h
new file mode 100644
index 00000000..c771bb69
--- /dev/null
+++ b/include/system/ctype.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+/*
+ * ctype.h - standard ctype functions
+ */
+#ifdef SHIM_UNIT_TEST
+#include_next <string.h>
+#else
+#ifndef _CTYPE_H
+#define _CTYPE_H
+
+
+#endif /* !_CTYPE_H */
+#endif /* !SHIM_UNIT_TEST */
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/inttypes.h b/include/system/inttypes.h
new file mode 100644
index 00000000..a35b0090
--- /dev/null
+++ b/include/system/inttypes.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+#ifdef SHIM_UNIT_TEST
+#include_next <inttypes.h>
+#else
+#ifndef _INTTYPES_H
+#define _INTTYPES_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#endif /* !INTTYPES_H_ */
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/stdarg.h b/include/system/stdarg.h
new file mode 100644
index 00000000..346b760d
--- /dev/null
+++ b/include/system/stdarg.h
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+/*
+ * stdarg.h - try to make consistent va_* handling for EFI
+ */
+#ifdef SHIM_UNIT_TEST
+#include_next <stdarg.h>
+#else
+#ifndef _STDARG_H
+#define _STDARG_H
+
+#include <efistdarg.h>
+
+#endif /* !_STDARG_H */
+#endif
+#ifndef SHIM_STDARG_H_
+#define SHIM_STDARG_H_
+
+typedef __builtin_ms_va_list ms_va_list;
+#define ms_va_copy(dest, start) __builtin_ms_va_copy(dest, start)
+#define ms_va_start(marker, arg) __builtin_ms_va_start(marker, arg)
+#define ms_va_arg(marker, type) __builtin_va_arg(marker, type)
+#define ms_va_end(marker) __builtin_ms_va_end(marker)
+
+typedef __builtin_va_list elf_va_list;
+#define elf_va_copy(dest, start) __builtin_va_copy(dest, start)
+#define elf_va_start(marker, arg) __builtin_va_start(marker, arg)
+#define elf_va_arg(marker, type) __builtin_va_arg(marker, type)
+#define elf_va_end(marker) __builtin_va_end(marker)
+
+#endif /* !SHIM_STDARG_H_ */
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/stdio.h b/include/system/stdio.h
new file mode 100644
index 00000000..6ea60d71
--- /dev/null
+++ b/include/system/stdio.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+/*
+ * stdio.h - sigh
+ */
+#ifdef SHIM_UNIT_TEST
+#include_next <stdio.h>
+#else
+#ifndef _STDIO_H
+#define _STDIO_H
+
+#endif /* !_STDIO_H */
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/stdlib.h b/include/system/stdlib.h
new file mode 100644
index 00000000..f2660f63
--- /dev/null
+++ b/include/system/stdlib.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+#ifdef SHIM_UNIT_TEST
+#include_next <stdlib.h>
+#else
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+/*
+ * I don't know why, but openssl expects to get size_t from stdlib.h
+ * instead of stddef.h, so... whatever.
+ */
+#include <stddef.h>
+
+#endif /* !_STDLIB_H */
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/string.h b/include/system/string.h
new file mode 100644
index 00000000..21e46c1d
--- /dev/null
+++ b/include/system/string.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+#ifdef SHIM_UNIT_TEST
+#include_next <string.h>
+#else
+#ifndef _STRING_H
+#define _STRING_H
+
+#include <stddef.h>
+
+__typeof__(__builtin_memset) memset;
+__typeof__(__builtin_memcpy) memcpy;
+
+#endif /* _STRING_H */
+#endif
diff --git a/include/system/strings.h b/include/system/strings.h
new file mode 100644
index 00000000..c82bd917
--- /dev/null
+++ b/include/system/strings.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+#ifdef SHIM_UNIT_TEST
+#include_next <strings.h>
+#else
+#ifndef _STRINGS_H
+#define _STRINGS_H
+
+#endif /* !_STRINGS_H */
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/test.h b/include/test.h
index 6fc178ba..8a970fd2 100644
--- a/include/test.h
+++ b/include/test.h
@@ -11,13 +11,13 @@
#include <stdarg.h>
#if defined(__aarch64__)
-#include <aa64/efibind.h>
+#include <aarch64/efibind.h>
#elif defined(__arm__)
#include <arm/efibind.h>
#elif defined(__i386__) || defined(__i486__) || defined(__i686__)
#include <ia32/efibind.h>
#elif defined(__x86_64__)
-#include <x64/efibind.h>
+#include <x86_64/efibind.h>
#else
#error what arch is this
#endif
diff --git a/lib/Makefile b/lib/Makefile
index d9188c74..63893c3e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -2,9 +2,44 @@ TARGET = lib.a
LIBFILES = $(foreach x,$(wildcard *.c),$(patsubst %.c,%.o,$(x)))
+CRYPTDIR = $(TOPDIR)/Cryptlib
+
INCLUDES = $(EFI_INCLUDES) \
- -I$(TOPDIR)/../include \
- -I$(TOPDIR)/CryptLib/Include/openssl/
+ -I$(TOPDIR)/include \
+ -I$(CRYPTDIR)/Include/openssl/ \
+ -I$(CRYPTDIR)/Include/ \
+ -I$(CRYPTDIR) \
+ -I$(TOPDIR) \
+ -isystem $(TOPDIR)/include/system \
+ -isystem $(shell $(CC) -print-file-name=include)
+
+CLANG_BUGS = $(if $(findstring gcc,$(CC)),-maccumulate-outgoing-args,)
+
+ifeq ($(ARCH),x86_64)
+FEATUREFLAGS += -m64 -mno-mmx -mno-sse -mno-red-zone -nostdinc $(CLANG_BUGS)
+DEFINES += -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI \
+ -UNO_BUILTIN_VA_FUNCS -DMDE_CPU_X64
+endif
+ifeq ($(ARCH),ia32)
+FEATUREFLAGS += -m32 -mno-mmx -mno-sse -mno-red-zone -nostdinc $(CLANG_BUGS)
+DEFINES += -DMDE_CPU_IA32
+endif
+ifeq ($(ARCH),aarch64)
+DEFINES += -DMDE_CPU_AARCH64
+endif
+ifeq ($(ARCH),arm)
+DEFINES += -DMDE_CPU_ARM
+endif
+
+LDFLAGS = -nostdlib -znocombreloc
+
+
+CFLAGS = $(FEATUREFLAGS) \
+ $(OPTIMIZATIONS) \
+ $(WARNFLAGS) \
+ $(WERRFLAGS) \
+ $(INCLUDES) \
+ $(DEFINES)
lib.a: $(LIBFILES)
$(AR) rcs lib.a $(LIBFILES)
diff --git a/lib/configtable.c b/lib/configtable.c
index 8675fad1..66e97f63 100644
--- a/lib/configtable.c
+++ b/lib/configtable.c
@@ -4,9 +4,6 @@
*
* read some platform configuration tables
*/
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
void *
diff --git a/lib/console.c b/lib/console.c
index ffa8ea5c..32c6d55d 100644
--- a/lib/console.c
+++ b/lib/console.c
@@ -3,11 +3,6 @@
* Copyright 2012 <James.Bottomley@HansenPartnership.com>
* Copyright 2013 Red Hat Inc. <pjones@redhat.com>
*/
-#include <efi.h>
-#include <efilib.h>
-#include <stdarg.h>
-#include <stdbool.h>
-
#include "shim.h"
static UINT8 console_text_mode = 0;
@@ -88,27 +83,27 @@ VOID console_fini(VOID)
setup_console(0);
}
-UINTN
+UINTN EFIAPI
console_print(const CHAR16 *fmt, ...)
{
- va_list args;
+ elf_va_list args;
UINTN ret;
if (!console_text_mode)
setup_console(1);
- va_start(args, fmt);
+ elf_va_start(args, fmt);
ret = VPrint(fmt, args);
- va_end(args);
+ elf_va_end(args);
return ret;
}
-UINTN
+UINTN EFIAPI
console_print_at(UINTN col, UINTN row, const CHAR16 *fmt, ...)
{
SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;
- va_list args;
+ elf_va_list args;
UINTN ret;
if (!console_text_mode)
@@ -116,9 +111,9 @@ console_print_at(UINTN col, UINTN row, const CHAR16 *fmt, ...)
co->SetCursorPosition(co, col, row);
- va_start(args, fmt);
+ elf_va_start(args, fmt);
ret = VPrint(fmt, args);
- va_end(args);
+ elf_va_end(args);
return ret;
}
diff --git a/lib/execute.c b/lib/execute.c
index f57a6321..642f94a3 100644
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -3,10 +3,6 @@
* Copyright 2012 <James.Bottomley@HansenPartnership.com>
* Code Copyright 2012 Red Hat, Inc <mjg@redhat.com>
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
EFI_STATUS
diff --git a/lib/print_crypto.c b/lib/print_crypto.c
index 39dfd2c0..ccdb65b1 100644
--- a/lib/print_crypto.c
+++ b/lib/print_crypto.c
@@ -2,11 +2,6 @@
/*
* Copyright 2019 SUSE LLC <glin@suse.com>
*/
-
-#include <efi.h>
-#include <efilib.h>
-#include <stdarg.h>
-
#include "shim.h"
#include <Library/BaseCryptLib.h>
diff --git a/lib/security_policy.c b/lib/security_policy.c
index 6a9b13ed..6c42cc14 100644
--- a/lib/security_policy.c
+++ b/lib/security_policy.c
@@ -4,10 +4,6 @@
*
* Install and remove a platform security2 override policy
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
#if defined(OVERRIDE_SECURITY_POLICY)
diff --git a/lib/shell.c b/lib/shell.c
index 87f279d6..146d9a21 100644
--- a/lib/shell.c
+++ b/lib/shell.c
@@ -4,9 +4,6 @@
*
* misc shell helper functions
*/
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
EFI_STATUS
diff --git a/lib/simple_file.c b/lib/simple_file.c
index e6544709..5fd3e1a6 100644
--- a/lib/simple_file.c
+++ b/lib/simple_file.c
@@ -2,10 +2,6 @@
/*
* Copyright 2012 <James.Bottomley@HansenPartnership.com>
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
EFI_STATUS
diff --git a/lib/variables.c b/lib/variables.c
index 6db069ef..57875e26 100644
--- a/lib/variables.c
+++ b/lib/variables.c
@@ -10,9 +10,6 @@
* Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
*
*/
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
EFI_STATUS
diff --git a/mok.c b/mok.c
index ac0276ec..6bd506be 100644
--- a/mok.c
+++ b/mok.c
@@ -6,10 +6,6 @@
#include "shim.h"
-#include <stdint.h>
-
-#include "hexdump.h"
-
/*
* Check if a variable exists
*/
diff --git a/netboot.c b/netboot.c
index 25a6df7f..450e9def 100644
--- a/netboot.c
+++ b/netboot.c
@@ -13,8 +13,6 @@
#include "shim.h"
-#include <string.h>
-
#define ntohs(x) __builtin_bswap16(x) /* supported both by GCC and clang */
#define htons(x) ntohs(x)
diff --git a/pe.c b/pe.c
index 45dd4714..73b05a51 100644
--- a/pe.c
+++ b/pe.c
@@ -5,7 +5,6 @@
*/
#include "shim.h"
-#include "hexdump.h"
#include <openssl/err.h>
#include <openssl/bn.h>
diff --git a/replacements.c b/replacements.c
index 69dbd5a2..278a8e78 100644
--- a/replacements.c
+++ b/replacements.c
@@ -18,11 +18,6 @@
* National Security Policy and Scientific Developments, November 20,
* 1969.
*/
-
-#include <efi.h>
-#include <efiapi.h>
-#include <efilib.h>
-
#include "shim.h"
static EFI_SYSTEM_TABLE *systab;
diff --git a/sbat.c b/sbat.c
index f46bb8ab..d8750962 100644
--- a/sbat.c
+++ b/sbat.c
@@ -4,7 +4,6 @@
*/
#include "shim.h"
-#include "string.h"
EFI_STATUS
parse_sbat_section(char *section_base, size_t section_size,
diff --git a/shim.c b/shim.c
index 32bc3e81..6f627b1f 100644
--- a/shim.c
+++ b/shim.c
@@ -12,7 +12,6 @@
*/
#include "shim.h"
-#include "hexdump.h"
#if defined(ENABLE_SHIM_CERT)
#include "shim_cert.h"
#endif /* defined(ENABLE_SHIM_CERT) */
diff --git a/shim.h b/shim.h
index d28e16b7..61dafa82 100644
--- a/shim.h
+++ b/shim.h
@@ -26,6 +26,14 @@
#endif
#endif
+#include <ctype.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <system/stdarg.h>
+#include <string.h>
+#include <strings.h>
+
#ifndef SHIM_UNIT_TEST
#include <efi.h>
#include <efilib.h>
@@ -34,9 +42,6 @@
#include <efiip.h>
#endif
-#include <stddef.h>
-#include <stdint.h>
-
#ifdef SHIM_UNIT_TEST
#include "include/test.h"
#endif
@@ -158,9 +163,14 @@
#include "include/tpm.h"
#include "include/ucs2.h"
#include "include/variables.h"
+#include "include/hexdump.h"
#include "version.h"
+#ifndef SHIM_UNIT_TEST
+#include "Cryptlib/Include/OpenSslSupport.h"
+#endif
+
INTERFACE_DECL(_SHIM_LOCK);
typedef
@@ -196,9 +206,12 @@ typedef struct _SHIM_LOCK {
extern EFI_STATUS shim_init(void);
extern void shim_fini(void);
-extern EFI_STATUS LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...);
-extern EFI_STATUS VLogError(const char *file, int line, const char *func, const CHAR16 *fmt, va_list args);
-extern VOID LogHexdump_(const char *file, int line, const char *func, const void *data, size_t sz);
+extern EFI_STATUS EFIAPI LogError_(const char *file, int line, const char *func,
+ const CHAR16 *fmt, ...);
+extern EFI_STATUS EFIAPI VLogError(const char *file, int line, const char *func,
+ const CHAR16 *fmt, elf_va_list args);
+extern VOID LogHexdump_(const char *file, int line, const char *func,
+ const void *data, size_t sz);
extern VOID PrintErrors(VOID);
extern VOID ClearErrors(VOID);
extern VOID restore_loaded_image(VOID);
diff --git a/test.c b/test.c
index b21e2191..aa0da1fd 100644
--- a/test.c
+++ b/test.c
@@ -12,7 +12,8 @@
UINT8 in_protocol = 0;
int debug = DEFAULT_DEBUG_PRINT_STATE;
-EFI_STATUS LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
+EFI_STATUS EFIAPI
+LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
{
assert(0);
return EFI_SUCCESS;
diff --git a/tpm.c b/tpm.c
index e1fcb8be..808e0444 100644
--- a/tpm.c
+++ b/tpm.c
@@ -1,10 +1,4 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
-
-#include <efi.h>
-#include <efilib.h>
-#include <string.h>
-#include <stdint.h>
-
#include "shim.h"
typedef struct {