diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-08-20 07:31:21 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-08-20 07:31:21 +0000 |
commit | e21a73530e490999057921c5aad86226967a71a1 (patch) | |
tree | 76e40f8f5eb1fc9665912ce4935b4773f68e721e | |
parent | 23e3be19aeca215bbfb397792363db8059fed366 (diff) | |
parent | 002c8667ef19be4b80ef7079a3a5cfb4ca85038c (diff) | |
download | gatekeeper-oreo-m5-release.tar.gz |
release-request-369362fc-cc6c-4cb1-95c0-90b5ac7c52cb-for-git_oc-mr1-release-4288633 snap-temp-L81700000095141745android-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r9android-8.1.0_r8android-8.1.0_r7android-8.1.0_r67android-8.1.0_r65android-8.1.0_r64android-8.1.0_r63android-8.1.0_r62android-8.1.0_r61android-8.1.0_r60android-8.1.0_r6android-8.1.0_r53android-8.1.0_r52android-8.1.0_r51android-8.1.0_r50android-8.1.0_r5android-8.1.0_r48android-8.1.0_r47android-8.1.0_r46android-8.1.0_r45android-8.1.0_r43android-8.1.0_r42android-8.1.0_r41android-8.1.0_r40android-8.1.0_r4android-8.1.0_r39android-8.1.0_r38android-8.1.0_r37android-8.1.0_r36android-8.1.0_r35android-8.1.0_r33android-8.1.0_r32android-8.1.0_r31android-8.1.0_r30android-8.1.0_r3android-8.1.0_r29android-8.1.0_r28android-8.1.0_r27android-8.1.0_r26android-8.1.0_r25android-8.1.0_r23android-8.1.0_r22android-8.1.0_r21android-8.1.0_r20android-8.1.0_r2android-8.1.0_r19android-8.1.0_r18android-8.1.0_r17android-8.1.0_r16android-8.1.0_r15android-8.1.0_r14android-8.1.0_r13android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1oreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-m8-releaseoreo-m7-releaseoreo-m6-s4-releaseoreo-m6-s3-releaseoreo-m6-s2-releaseoreo-m5-releaseoreo-m4-s9-releaseoreo-m4-s8-releaseoreo-m4-s7-releaseoreo-m4-s6-releaseoreo-m4-s5-releaseoreo-m4-s4-releaseoreo-m4-s3-releaseoreo-m4-s2-releaseoreo-m4-s12-releaseoreo-m4-s11-releaseoreo-m4-s10-releaseoreo-m4-s1-releaseoreo-m3-releaseoreo-m2-s5-releaseoreo-m2-s4-releaseoreo-m2-s3-releaseoreo-m2-s2-releaseoreo-m2-s1-releaseoreo-m2-release
Change-Id: I0aba255dcbde4766bc504e223de29fdb6f73b710
-rw-r--r-- | Android.bp | 7 | ||||
-rw-r--r-- | gatekeeper.cpp | 2 | ||||
-rw-r--r-- | include/gatekeeper/UniquePtr.h | 137 | ||||
-rw-r--r-- | include/gatekeeper/gatekeeper.h | 2 | ||||
-rw-r--r-- | include/gatekeeper/gatekeeper_messages.h | 2 |
5 files changed, 147 insertions, 3 deletions
@@ -16,6 +16,10 @@ // GoogleGateKeeper implementation, e.g. one running in TrustZone. cc_library_shared { name: "libgatekeeper", + vendor_available: true, + vndk: { + enabled: true, + }, srcs: [ "gatekeeper_messages.cpp", "gatekeeper.cpp", @@ -25,6 +29,9 @@ cc_library_shared { "-Werror", "-g", ], + header_libs: [ + "libhardware_headers", + ], export_include_dirs: ["include"], diff --git a/gatekeeper.cpp b/gatekeeper.cpp index cfd878f..83e84fe 100644 --- a/gatekeeper.cpp +++ b/gatekeeper.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <UniquePtr.h> +#include <gatekeeper/UniquePtr.h> #include <gatekeeper/gatekeeper.h> #include <endian.h> diff --git a/include/gatekeeper/UniquePtr.h b/include/gatekeeper/UniquePtr.h new file mode 100644 index 0000000..77ff99f --- /dev/null +++ b/include/gatekeeper/UniquePtr.h @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GATEKEEPER_UNIQUE_PTR_H_included +#define GATEKEEPER_UNIQUE_PTR_H_included + +#include <stdlib.h> // For NULL. + +namespace gatekeeper { + +// Default deleter for pointer types. +template <typename T> +struct DefaultDelete { + enum { type_must_be_complete = sizeof(T) }; + DefaultDelete() {} + void operator()(T* p) const { + delete p; + } +}; + +// Default deleter for array types. +template <typename T> +struct DefaultDelete<T[]> { + enum { type_must_be_complete = sizeof(T) }; + void operator()(T* p) const { + delete[] p; + } +}; + +// A smart pointer that deletes the given pointer on destruction. +// Equivalent to C++0x's std::unique_ptr (a combination of boost::scoped_ptr +// and boost::scoped_array). +// Named to be in keeping with Android style but also to avoid +// collision with any other implementation, until we can switch over +// to unique_ptr. +// Use thus: +// UniquePtr<C> c(new C); +template <typename T, typename D = DefaultDelete<T> > +class UniquePtr { +public: + // Construct a new UniquePtr, taking ownership of the given raw pointer. + explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) { + } + + ~UniquePtr() { + reset(); + } + + // Accessors. + T& operator*() const { return *mPtr; } + T* operator->() const { return mPtr; } + T* get() const { return mPtr; } + + // Returns the raw pointer and hands over ownership to the caller. + // The pointer will not be deleted by UniquePtr. + T* release() __attribute__((warn_unused_result)) { + T* result = mPtr; + mPtr = NULL; + return result; + } + + // Takes ownership of the given raw pointer. + // If this smart pointer previously owned a different raw pointer, that + // raw pointer will be freed. + void reset(T* ptr = NULL) { + if (ptr != mPtr) { + D()(mPtr); + mPtr = ptr; + } + } + +private: + // The raw pointer. + T* mPtr; + + // Comparing unique pointers is probably a mistake, since they're unique. + template <typename T2> bool operator==(const UniquePtr<T2>& p) const; + template <typename T2> bool operator!=(const UniquePtr<T2>& p) const; + + // Disallow copy and assignment. + UniquePtr(const UniquePtr&); + void operator=(const UniquePtr&); +}; + +// Partial specialization for array types. Like std::unique_ptr, this removes +// operator* and operator-> but adds operator[]. +template <typename T, typename D> +class UniquePtr<T[], D> { +public: + explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) { + } + + ~UniquePtr() { + reset(); + } + + T& operator[](size_t i) const { + return mPtr[i]; + } + T* get() const { return mPtr; } + + T* release() __attribute__((warn_unused_result)) { + T* result = mPtr; + mPtr = NULL; + return result; + } + + void reset(T* ptr = NULL) { + if (ptr != mPtr) { + D()(mPtr); + mPtr = ptr; + } + } + +private: + T* mPtr; + + // Disallow copy and assignment. + UniquePtr(const UniquePtr&); + void operator=(const UniquePtr&); +}; + +} //namespace gatekeeper +#endif // GATEKEEPER_UNIQUE_PTR_H_included diff --git a/include/gatekeeper/gatekeeper.h b/include/gatekeeper/gatekeeper.h index 7e1421f..c5cd5dd 100644 --- a/include/gatekeeper/gatekeeper.h +++ b/include/gatekeeper/gatekeeper.h @@ -18,7 +18,7 @@ #define GATEKEEPER_H_ #include <stdint.h> -#include <UniquePtr.h> +#include <gatekeeper/UniquePtr.h> #include <hardware/hw_auth_token.h> #include "gatekeeper_messages.h" diff --git a/include/gatekeeper/gatekeeper_messages.h b/include/gatekeeper/gatekeeper_messages.h index 1ec1e18..3cbd817 100644 --- a/include/gatekeeper/gatekeeper_messages.h +++ b/include/gatekeeper/gatekeeper_messages.h @@ -17,7 +17,7 @@ #define GATEKEEPER_MESSAGES_H_ #include <stdint.h> -#include <UniquePtr.h> +#include <gatekeeper/UniquePtr.h> #include "gatekeeper_utils.h" |