Skip to content

Commit

Permalink
compiler.h: fix a typo and add some more function attribute macros
Browse files Browse the repository at this point in the history
This fixes the ifndef guard on NONNULL and __CONCAT3 and adds
definitions for:
- __CONCAT() for a##b with the intermediate tokenization step
- ALLOCFUNC for __malloc__
- DEPRECATED for __deprecated__
- PURE for __pure__
- RETURNS_NONNULL for __nonnull__

Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela committed Feb 25, 2021
1 parent d27c33b commit c172292
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: c++03
StatementMacros: []
StatementMacros:
- ALLOCFUNC
- NONNULL
TabWidth: 8
UseCRLF: false
UseTab: AlignWithSpaces
Expand Down
31 changes: 29 additions & 2 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#ifndef COMPILER_H_
#define COMPILER_H_

/*
* These are special ones that get our unit tests in trouble with the
* compiler optimizer dropping out tests...
*/
#ifdef NONNULL
# undef NONNULL
#endif
#ifdef RETURNS_NONNULL
# undef RETURNS_NONNULL
#endif
#ifdef SHIM_UNIT_TEST
# define NONNULL(first, args...)
# define RETURNS_NONNULL
#else
# define NONNULL(first, args...) __attribute__((__nonnull__(first, ## args)))
# define RETURNS_NONNULL __attribute__((__returns_nonnull__))
#endif

#ifndef UNUSED
#define UNUSED __attribute__((__unused__))
#endif
Expand All @@ -12,6 +30,9 @@
#ifndef PUBLIC
#define PUBLIC __attribute__((__visibility__ ("default")))
#endif
#ifndef DEPRECATED
#define DEPRECATED __attribute__((__deprecated__))
#endif
#ifndef DESTRUCTOR
#define DESTRUCTOR __attribute__((destructor))
#endif
Expand All @@ -21,12 +42,15 @@
#ifndef ALIAS
#define ALIAS(x) __attribute__((weak, alias (#x)))
#endif
#ifndef NONNULL
#ifndef ALLOCFUNC
#define ALLOCFUNC(dealloc, dealloc_arg) __attribute__((__malloc__(dealloc, dealloc_arg)))
#endif
#define NONNULL(first, args...) __attribute__((__nonnull__(first, ## args)))
#ifndef PRINTF
#define PRINTF(first, args...) __attribute__((__format__(printf, first, ## args)))
#endif
#ifndef PURE
#define PURE __attribute__((__pure__))
#endif
#ifndef FLATTEN
#define FLATTEN __attribute__((__flatten__))
#endif
Expand Down Expand Up @@ -56,6 +80,9 @@
#endif

#ifndef __CONCAT
#define __CONCAT(a, b) a ## b
#endif
#ifndef __CONCAT3
#define __CONCAT3(a, b, c) a ## b ## c
#endif
#ifndef CAT
Expand Down
6 changes: 3 additions & 3 deletions mok.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct mok_state_variable mok_state_variables[] = {

#define should_mirror_addend(v) (((v)->categorize_addend) && ((v)->categorize_addend(v) != VENDOR_ADDEND_NONE))

static inline BOOLEAN nonnull(1)
static inline BOOLEAN NONNULL(1)
should_mirror_build_cert(struct mok_state_variable *v)
{
return (v->build_cert && v->build_cert_size &&
Expand Down Expand Up @@ -530,7 +530,7 @@ mirror_mok_db(CHAR16 *name, CHAR8 *name8, EFI_GUID *guid, UINT32 attrs,
}


static EFI_STATUS nonnull(1)
static EFI_STATUS NONNULL(1)
mirror_one_mok_variable(struct mok_state_variable *v,
BOOLEAN only_first)
{
Expand Down Expand Up @@ -840,7 +840,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
* Mirror a variable if it has an rtname, and preserve any
* EFI_SECURITY_VIOLATION status at the same time.
*/
static EFI_STATUS nonnull(1)
static EFI_STATUS NONNULL(1)
maybe_mirror_one_mok_variable(struct mok_state_variable *v,
EFI_STATUS ret, BOOLEAN only_first)
{
Expand Down
2 changes: 0 additions & 2 deletions shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include <stddef.h>
#include <stdint.h>

#define nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))

#ifdef __x86_64__
#ifndef DEFAULT_LOADER
#define DEFAULT_LOADER L"\\grubx64.efi"
Expand Down

0 comments on commit c172292

Please sign in to comment.