2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "ChecksumCalculatorThreadInfo.h"
19 #include "emugl/common/crash_reporter.h"
20 #include "emugl/common/lazy_instance.h"
21 #include "emugl/common/thread_store.h"
29 class ChecksumCalculatorThreadStore : public ::emugl::ThreadStore {
31 ChecksumCalculatorThreadStore() : ::emugl::ThreadStore(NULL) {}
34 #ifdef TRACE_CHECKSUMHELPER
35 std::atomic<size_t> sNumInstances(0);
36 #endif // TRACE_CHECKSUMHELPER
40 static ::emugl::LazyInstance<ChecksumCalculatorThreadStore> s_tls =
43 static ChecksumCalculatorThreadInfo* getChecksumCalculatorThreadInfo() {
44 return static_cast<ChecksumCalculatorThreadInfo*>(s_tls->get());
47 ChecksumCalculatorThreadInfo::ChecksumCalculatorThreadInfo() {
49 "%s: Checksum thread created (%u instances)\n", __FUNCTION__,
50 (size_t)sNumInstances);
54 ChecksumCalculatorThreadInfo::~ChecksumCalculatorThreadInfo() {
56 "%s: GLprotocol destroyed (%u instances)\n", __FUNCTION__,
57 (size_t)sNumInstances);
61 uint32_t ChecksumCalculatorThreadInfo::getVersion() {
62 return getChecksumCalculatorThreadInfo()->m_protocol.getVersion();
65 bool ChecksumCalculatorThreadInfo::setVersion(uint32_t version) {
66 return getChecksumCalculatorThreadInfo()->m_protocol.setVersion(version);
69 size_t ChecksumCalculatorThreadInfo::checksumByteSize() {
70 return getChecksumCalculatorThreadInfo()->m_protocol.checksumByteSize();
73 bool ChecksumCalculatorThreadInfo::writeChecksum(void* buf,
76 size_t outputChecksumLen) {
77 ChecksumCalculator& protocol =
78 getChecksumCalculatorThreadInfo()->m_protocol;
79 protocol.addBuffer(buf, bufLen);
80 return protocol.writeChecksum(outputChecksum, outputChecksumLen);
83 bool ChecksumCalculatorThreadInfo::validate(void* buf,
87 ChecksumCalculator& protocol =
88 getChecksumCalculatorThreadInfo()->m_protocol;
89 protocol.addBuffer(buf, bufLen);
90 return protocol.validate(checksum, checksumLen);
93 void ChecksumCalculatorThreadInfo::validOrDie(void* buf,
97 const char* message) {
98 // We should actually call crashhandler_die(message), but I don't think we
99 // can link to that library from here
100 if (!validate(buf, bufLen, checksum, checksumLen)) {
101 emugl_crash_reporter(emugl::LogLevel::FATAL, message);