1 // SPDX-License-Identifier: BSD-2-Clause-Patent
3 * model.c - modeling file for coverity
4 * Copyright Peter Jones <pjones@redhat.com>
8 /* This is so vim's Syntastic checker won't yell about all these. */
9 extern void __coverity_string_size_sanitize__(int);
10 extern void __coverity_negative_sink__(int);
11 extern void __coverity_alloc_nosize__(void);
12 extern void *__coverity_alloc__(int);
13 extern void __coverity_sleep__();
14 extern void __coverity_tainted_data_sanitize__(void *);
20 __coverity_alloc_nosize__();
24 UTF8_getc(const unsigned char *str
, int len
, unsigned long *val
)
26 /* You can't quite express the right thing here, so instead we're
27 * telling covscan that if len is a certain value, the string has
28 * been checked for having a NUL at the right place. Ideally what
29 * we'd tell it is it's never allowed to give us a string shorter
30 * than a certain length if certain bits (i.e. the UTF-8 surrogate
31 * length bits) are set. */
33 __coverity_string_size_sanitize__(0);
35 } else if (len
<= 6) {
36 __coverity_string_size_sanitize__(0);
42 typedef unsigned long long u64
;
44 unsigned long long hi
;
45 unsigned long long lo
;
49 gcm_gmult_4bit(u64 Xi
[2], u128 Htable
[16])
51 __coverity_tainted_data_sanitize__(Htable
);
60 /* From MdePkg/Include/Base.h or so */
61 typedef unsigned long long UINT64
;
62 typedef unsigned long UINTN
;
64 typedef UINT64 EFI_PHYSICAL_ADDRESS
;
65 typedef UINTN RETURN_STATUS
;
66 typedef RETURN_STATUS EFI_STATUS
;
68 #define MAX_BIT (1ULL << (sizeof (INTN) * 8 - 1))
69 #define MAX_INTN ((INTN)~MAX_BIT)
71 #define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode)))
72 #define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode))
73 #define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0)
74 #define RETURN_SUCCESS 0
75 #define RETURN_INVALID_PARAMETER ENCODE_ERROR (2)
76 #define RETURN_OUT_OF_RESOURCES ENCODE_ERROR (9)
78 /* From MdePkg/Include/Uefi/UefiBaseType.h */
79 #define EFI_SUCCESS RETURN_SUCCESS
80 #define EFI_INVALID_PARAMETER RETURN_INVALID_PARAMETER
81 #define EFI_OUT_OF_RESOURCES RETURN_OUT_OF_RESOURCES
83 #define EFI_PAGE_MASK 0xFFF
84 #define EFI_PAGE_SHIFT 12
85 #define EFI_SIZE_TO_PAGES(a) (((a) >> EFI_PAGE_SHIFT) + (((a) & EFI_PAGE_MASK) ? 1 : 0))
86 #define EFI_PAGES_TO_SIZE(a) ((a) << EFI_PAGE_SHIFT)
88 /* From MdePkg/Include/Uefi/UefiMultiPhase.h */
90 EfiReservedMemoryType
,
95 EfiRuntimeServicesCode
,
96 EfiRuntimeServicesData
,
97 EfiConventionalMemory
,
102 EfiMemoryMappedIOPortSpace
,
108 /* From MdePkg/Include/Uefi/UefiSpec.h */
117 AllocatePages(EFI_ALLOCATE_TYPE Type
,
118 EFI_MEMORY_TYPE MemoryType
,
120 EFI_PHYSICAL_ADDRESS
*Memory
)
123 unsigned long bytes
= EFI_PAGES_TO_SIZE(Pages
);
125 if (Pages
>= (unsigned long)((-1L) >> EFI_PAGE_SHIFT
))
126 return EFI_INVALID_PARAMETER
;
128 __coverity_negative_sink__(bytes
);
130 *Memory
= (EFI_PHYSICAL_ADDRESS
)__coverity_alloc__(bytes
);
133 return EFI_OUT_OF_RESOURCES
;
136 // vim:fenc=utf-8:tw=75