From f04333a4b1f00ad29bc6828854ed17c34e78901b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bram=20Bonn=C3=A9?= Date: Tue, 20 Oct 2020 16:40:52 +0200 Subject: Add Trusty support to libcppbor. Add a rules.mk file to libcppbor to allow Trusty to depend on it. Additionally, remove dependency on the Android logging framework when running in the Trusty environment, and remove dependencies on stringstream to improve portability. Bug: 171373138 Test: trusty/vendor/google/aosp/scripts/build.py generic-arm64-test-debug Test: m -j Change-Id: I7a01db28e6bf448886f4a7a1a4dea02d569493c9 --- rules.mk | 29 +++++++++++++++++++++++++++++ src/cppbor.cpp | 10 +++++++--- src/cppbor_parse.cpp | 17 ++++++++++------- 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 rules.mk diff --git a/rules.mk b/rules.mk new file mode 100644 index 0000000..739fe23 --- /dev/null +++ b/rules.mk @@ -0,0 +1,29 @@ +# Copyright (C) 2020 The Android Open Source Project. +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# This file is not used in the Android build process! It's used only by Trusty. + +LOCAL_DIR := $(GET_LOCAL_DIR) + +MODULE := $(LOCAL_DIR) + +MODULE_CPPFLAGS := -std=c++17 -frtti + +MODULE_SRCS := \ + $(LOCAL_DIR)/src/cppbor.cpp \ + $(LOCAL_DIR)/src/cppbor_parse.cpp + +GLOBAL_INCLUDES += $(LOCAL_DIR)/include/cppbor/ + +include make/module.mk \ No newline at end of file diff --git a/src/cppbor.cpp b/src/cppbor.cpp index 25c2da1..223a445 100644 --- a/src/cppbor.cpp +++ b/src/cppbor.cpp @@ -16,8 +16,12 @@ #include "cppbor.h" -#define LOG_TAG "CppBor" -#include +#ifndef __TRUSTY__ + #include + #define LOG_TAG "CppBor" +#else + #define CHECK(x) (void)(x) +#endif namespace cppbor { @@ -129,7 +133,7 @@ bool Item::operator==(const Item& other) const& { } Nint::Nint(int64_t v) : mValue(v) { - CHECK(v < 0) << "Only negative values allowed"; + CHECK(v < 0); } bool Simple::operator==(const Simple& other) const& { diff --git a/src/cppbor_parse.cpp b/src/cppbor_parse.cpp index 6da0036..5cffe15 100644 --- a/src/cppbor_parse.cpp +++ b/src/cppbor_parse.cpp @@ -16,11 +16,14 @@ #include "cppbor_parse.h" -#include #include -#define LOG_TAG "CppBor" -#include +#ifndef __TRUSTY__ + #include + #define LOG_TAG "CppBor" +#else + #define CHECK(x) (void)(x) +#endif namespace cppbor { @@ -28,10 +31,10 @@ namespace { std::string insufficientLengthString(size_t bytesNeeded, size_t bytesAvail, const std::string& type) { - std::stringstream errStream; - errStream << "Need " << bytesNeeded << " byte(s) for " << type << ", have " << bytesAvail - << "."; - return errStream.str(); + char buf[1024]; + snprintf(buf, sizeof(buf), "Need %zu byte(s) for %s, have %zu", + bytesNeeded, type.c_str(), bytesAvail); + return std::string(buf); } template >> -- cgit v1.2.3