2 * Copyright (C) 2016 The Android Open Source Project
4 * SPDX-License-Identifier: MIT
7 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
8 #error "Never include this file directly, include libavb.h instead."
11 #ifndef AVB_SYSDEPS_H_
12 #define AVB_SYSDEPS_H_
18 /* Change these includes to match your platform to bring in the
19 * equivalent types available in a normal C runtime. At least things
20 * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
25 /* If you don't have gcc or clang, these attribute macros may need to
28 #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
29 #define AVB_ATTR_PACKED __attribute__((packed))
30 #define AVB_ATTR_NO_RETURN __attribute__((noreturn))
31 #define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
33 /* Size in bytes used for alignment. */
35 #define AVB_ALIGNMENT_SIZE 8
37 #define AVB_ALIGNMENT_SIZE 4
40 /* Compare |n| bytes in |src1| and |src2|.
42 * Returns an integer less than, equal to, or greater than zero if the
43 * first |n| bytes of |src1| is found, respectively, to be less than,
44 * to match, or be greater than the first |n| bytes of |src2|. */
45 int avb_memcmp(const void* src1,
47 size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
49 /* Compare two strings.
51 * Return an integer less than, equal to, or greater than zero if |s1|
52 * is found, respectively, to be less than, to match, or be greater
55 int avb_strcmp(const char* s1, const char* s2);
57 /* Copy |n| bytes from |src| to |dest|. */
58 void* avb_memcpy(void* dest, const void* src, size_t n);
60 /* Set |n| bytes starting at |s| to |c|. Returns |dest|. */
61 void* avb_memset(void* dest, const int c, size_t n);
63 /* Prints out a message. The string passed must be a NUL-terminated
66 void avb_print(const char* message);
68 /* Prints out a vector of strings. Each argument must point to a
69 * NUL-terminated UTF-8 string and NULL should be the last argument.
71 void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
73 /* Aborts the program or reboots the device. */
74 void avb_abort(void) AVB_ATTR_NO_RETURN;
76 /* Allocates |size| bytes. Returns NULL if no memory is available,
77 * otherwise a pointer to the allocated memory.
79 * The memory is not initialized.
81 * The pointer returned is guaranteed to be word-aligned.
83 * The memory should be freed with avb_free() when you are done with it.
85 void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
87 /* Frees memory previously allocated with avb_malloc(). */
88 void avb_free(void* ptr);
90 /* Returns the lenght of |str|, excluding the terminating NUL-byte. */
91 size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
93 /* Divide the |dividend| by 10 and saves back to the pointer. Return the
95 uint32_t avb_div_by_10(uint64_t* dividend);
101 #endif /* AVB_SYSDEPS_H_ */