15b69db07SJason Zhu /* 25b69db07SJason Zhu * Copyright (C) 2016 The Android Open Source Project 35b69db07SJason Zhu * 45b69db07SJason Zhu * Permission is hereby granted, free of charge, to any person 55b69db07SJason Zhu * obtaining a copy of this software and associated documentation 65b69db07SJason Zhu * files (the "Software"), to deal in the Software without 75b69db07SJason Zhu * restriction, including without limitation the rights to use, copy, 85b69db07SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 95b69db07SJason Zhu * of the Software, and to permit persons to whom the Software is 105b69db07SJason Zhu * furnished to do so, subject to the following conditions: 115b69db07SJason Zhu * 125b69db07SJason Zhu * The above copyright notice and this permission notice shall be 135b69db07SJason Zhu * included in all copies or substantial portions of the Software. 145b69db07SJason Zhu * 155b69db07SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 165b69db07SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 175b69db07SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 185b69db07SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 195b69db07SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 205b69db07SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 215b69db07SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 225b69db07SJason Zhu * SOFTWARE. 235b69db07SJason Zhu */ 245b69db07SJason Zhu 255b69db07SJason Zhu /* 265b69db07SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION) 275b69db07SJason Zhu #error "Never include this file directly, include libavb.h instead." 285b69db07SJason Zhu #endif 295b69db07SJason Zhu */ 305b69db07SJason Zhu 315b69db07SJason Zhu #ifndef AVB_SYSDEPS_H_ 325b69db07SJason Zhu #define AVB_SYSDEPS_H_ 335b69db07SJason Zhu 345b69db07SJason Zhu #ifdef __cplusplus 355b69db07SJason Zhu extern "C" { 365b69db07SJason Zhu #endif 375b69db07SJason Zhu 385b69db07SJason Zhu /* Change these includes to match your platform to bring in the 395b69db07SJason Zhu * equivalent types available in a normal C runtime. At least things 405b69db07SJason Zhu * like uint8_t, uint64_t, and bool (with |false|, |true| keywords) 415b69db07SJason Zhu * must be present. 425b69db07SJason Zhu */ 435b69db07SJason Zhu #include <inttypes.h> 445b69db07SJason Zhu #include <stdbool.h> 455b69db07SJason Zhu #include <stddef.h> 465b69db07SJason Zhu #ifdef CONFIG_USE_STDINT 475b69db07SJason Zhu /* Provided by gcc. */ 485b69db07SJason Zhu #include <stdint.h> 495b69db07SJason Zhu #else 505b69db07SJason Zhu /* Type for `void *' pointers. */ 515b69db07SJason Zhu typedef unsigned long int uintptr_t; 525b69db07SJason Zhu #endif 535b69db07SJason Zhu 545b69db07SJason Zhu /* If you don't have gcc or clang, these attribute macros may need to 555b69db07SJason Zhu * be adjusted. 565b69db07SJason Zhu */ 575b69db07SJason Zhu #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 585b69db07SJason Zhu #define AVB_ATTR_PACKED __attribute__((packed)) 595b69db07SJason Zhu #define AVB_ATTR_NO_RETURN __attribute__((noreturn)) 605b69db07SJason Zhu #define AVB_ATTR_SENTINEL __attribute__((__sentinel__)) 615b69db07SJason Zhu 625b69db07SJason Zhu /* Size in bytes used for alignment. */ 635b69db07SJason Zhu #ifdef __LP64__ 645b69db07SJason Zhu #define AVB_ALIGNMENT_SIZE 8 655b69db07SJason Zhu #else 665b69db07SJason Zhu #define AVB_ALIGNMENT_SIZE 4 675b69db07SJason Zhu #endif 685b69db07SJason Zhu 695b69db07SJason Zhu /* Compare |n| bytes in |src1| and |src2|. 705b69db07SJason Zhu * 715b69db07SJason Zhu * Returns an integer less than, equal to, or greater than zero if the 725b69db07SJason Zhu * first |n| bytes of |src1| is found, respectively, to be less than, 735b69db07SJason Zhu * to match, or be greater than the first |n| bytes of |src2|. */ 745b69db07SJason Zhu int avb_memcmp(const void* src1, 755b69db07SJason Zhu const void* src2, 765b69db07SJason Zhu size_t n) AVB_ATTR_WARN_UNUSED_RESULT; 775b69db07SJason Zhu 785b69db07SJason Zhu /* Compare two strings. 795b69db07SJason Zhu * 805b69db07SJason Zhu * Return an integer less than, equal to, or greater than zero if |s1| 815b69db07SJason Zhu * is found, respectively, to be less than, to match, or be greater 825b69db07SJason Zhu * than |s2|. 835b69db07SJason Zhu */ 845b69db07SJason Zhu int avb_strcmp(const char* s1, const char* s2); 855b69db07SJason Zhu 865b69db07SJason Zhu /* Copy |n| bytes from |src| to |dest|. */ 875b69db07SJason Zhu void* avb_memcpy(void* dest, const void* src, size_t n); 885b69db07SJason Zhu 895b69db07SJason Zhu /* Set |n| bytes starting at |s| to |c|. Returns |dest|. */ 905b69db07SJason Zhu void* avb_memset(void* dest, const int c, size_t n); 915b69db07SJason Zhu 925b69db07SJason Zhu /* Prints out a message. The string passed must be a NUL-terminated 935b69db07SJason Zhu * UTF-8 string. 945b69db07SJason Zhu */ 955b69db07SJason Zhu void avb_print(const char* message); 965b69db07SJason Zhu 975b69db07SJason Zhu /* Prints out a vector of strings. Each argument must point to a 985b69db07SJason Zhu * NUL-terminated UTF-8 string and NULL should be the last argument. 995b69db07SJason Zhu */ 1005b69db07SJason Zhu void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL; 1015b69db07SJason Zhu 1025b69db07SJason Zhu /* Aborts the program or reboots the device. */ 103*37a7bc39SJason Zhu void avb_abort(void); 1045b69db07SJason Zhu 1055b69db07SJason Zhu /* Allocates |size| bytes. Returns NULL if no memory is available, 1065b69db07SJason Zhu * otherwise a pointer to the allocated memory. 1075b69db07SJason Zhu * 1085b69db07SJason Zhu * The memory is not initialized. 1095b69db07SJason Zhu * 1105b69db07SJason Zhu * The pointer returned is guaranteed to be word-aligned. 1115b69db07SJason Zhu * 1125b69db07SJason Zhu * The memory should be freed with avb_free() when you are done with it. 1135b69db07SJason Zhu */ 1145b69db07SJason Zhu void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT; 1155b69db07SJason Zhu 1165b69db07SJason Zhu /* Frees memory previously allocated with avb_malloc(). */ 1175b69db07SJason Zhu void avb_free(void* ptr); 1185b69db07SJason Zhu 1195b69db07SJason Zhu /* Returns the lenght of |str|, excluding the terminating NUL-byte. */ 1205b69db07SJason Zhu size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT; 1215b69db07SJason Zhu 122*37a7bc39SJason Zhu /* Divide the |dividend| by 10 and saves back to the pointer. Return the 123*37a7bc39SJason Zhu * remainder. */ 124*37a7bc39SJason Zhu uint32_t avb_div_by_10(uint64_t* dividend); 125*37a7bc39SJason Zhu 1265b69db07SJason Zhu #ifdef __cplusplus 1275b69db07SJason Zhu } 1285b69db07SJason Zhu #endif 1295b69db07SJason Zhu 1305b69db07SJason Zhu #endif /* AVB_SYSDEPS_H_ */ 131