blob: f032de4a2e05410116396686b5735b349fdf438c [file] [log] [blame]
Tom Rini897a1d92018-06-19 11:21:44 -04001/* SPDX-License-Identifier: MIT */
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +03002/*
3 * Copyright (C) 2016 The Android Open Source Project
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +03004 */
5
6#if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7#error "Never include this file directly, include libavb.h instead."
8#endif
9
10#ifndef AVB_SYSDEPS_H_
11#define AVB_SYSDEPS_H_
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/* Change these includes to match your platform to bring in the
18 * equivalent types available in a normal C runtime. At least things
19 * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
20 * must be present.
21 */
22#include <common.h>
23
24/* If you don't have gcc or clang, these attribute macros may need to
25 * be adjusted.
26 */
27#define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
28#define AVB_ATTR_PACKED __attribute__((packed))
29#define AVB_ATTR_NO_RETURN __attribute__((noreturn))
30#define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
31
32/* Size in bytes used for alignment. */
33#ifdef __LP64__
34#define AVB_ALIGNMENT_SIZE 8
35#else
36#define AVB_ALIGNMENT_SIZE 4
37#endif
38
39/* Compare |n| bytes in |src1| and |src2|.
40 *
41 * Returns an integer less than, equal to, or greater than zero if the
42 * first |n| bytes of |src1| is found, respectively, to be less than,
43 * to match, or be greater than the first |n| bytes of |src2|. */
44int avb_memcmp(const void* src1,
45 const void* src2,
46 size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
47
48/* Compare two strings.
49 *
50 * Return an integer less than, equal to, or greater than zero if |s1|
51 * is found, respectively, to be less than, to match, or be greater
52 * than |s2|.
53 */
54int avb_strcmp(const char* s1, const char* s2);
55
56/* Copy |n| bytes from |src| to |dest|. */
57void* avb_memcpy(void* dest, const void* src, size_t n);
58
59/* Set |n| bytes starting at |s| to |c|. Returns |dest|. */
60void* avb_memset(void* dest, const int c, size_t n);
61
62/* Prints out a message. The string passed must be a NUL-terminated
63 * UTF-8 string.
64 */
65void avb_print(const char* message);
66
67/* Prints out a vector of strings. Each argument must point to a
68 * NUL-terminated UTF-8 string and NULL should be the last argument.
69 */
70void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
71
72/* Aborts the program or reboots the device. */
73void avb_abort(void) AVB_ATTR_NO_RETURN;
74
75/* Allocates |size| bytes. Returns NULL if no memory is available,
76 * otherwise a pointer to the allocated memory.
77 *
78 * The memory is not initialized.
79 *
80 * The pointer returned is guaranteed to be word-aligned.
81 *
82 * The memory should be freed with avb_free() when you are done with it.
83 */
84void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
85
86/* Frees memory previously allocated with avb_malloc(). */
87void avb_free(void* ptr);
88
89/* Returns the lenght of |str|, excluding the terminating NUL-byte. */
90size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
91
92/* Divide the |dividend| by 10 and saves back to the pointer. Return the
93 * remainder. */
94uint32_t avb_div_by_10(uint64_t* dividend);
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* AVB_SYSDEPS_H_ */