Refine SHA-1 related stuffs.
1. Introduce libbcc.sha1.so instead of raw file libbcc.so.sha1
* Now tools/build/gen-sha1-stamp.py generated assembly contains
symbols libbcc_so_SHA1 and libRS_so_SHA1 associated with their
SHA-1 digests.
* In that way, their SHA-1 information can be obtained via
dlopen().
2. Refine Sha1Helper to Sha1Util.
2. Remove unused tools/build/dataconvert.py by the way.
diff --git a/lib/RenderScript/RSInfo.cpp b/lib/RenderScript/RSInfo.cpp
index 536c83b..f3010cf 100644
--- a/lib/RenderScript/RSInfo.cpp
+++ b/lib/RenderScript/RSInfo.cpp
@@ -17,35 +17,36 @@
//#define LOG_NDEBUG 0
#include "bcc/RenderScript/RSInfo.h"
+#include <dlfcn.h>
+
#include <cstring>
#include <new>
#include "bcc/Support/FileBase.h"
#include "bcc/Support/Log.h"
-#include "bcc/Support/Sha1Helper.h"
using namespace bcc;
const char RSInfo::LibBCCPath[] = "/system/lib/libbcc.so";
const char RSInfo::LibRSPath[] = "/system/lib/libRS.so";
-uint8_t RSInfo::LibBCCSHA1[20];
-uint8_t RSInfo::LibRSSHA1[20];
+const uint8_t *RSInfo::LibBCCSHA1 = NULL;
+const uint8_t *RSInfo::LibRSSHA1 = NULL;
void RSInfo::LoadBuiltInSHA1Information() {
- static bool loaded = false;
-
- if (loaded) {
+ if (LibBCCSHA1 != NULL) {
+ // Loaded before.
return;
}
- // Read SHA-1 checksum of libbcc from hard-coded patch
- // /system/lib/libbcc.so.sha1.
- readSHA1(LibBCCSHA1, 20, "/system/lib/libbcc.so.sha1");
+ void *h = ::dlopen("/system/lib/libbcc.sha1.so", RTLD_LAZY | RTLD_NOW);
+ if (h == NULL) {
+ ALOGE("Failed to load SHA-1 information from shared library '"
+ "/system/lib/libbcc.sha1.so'! (%s)", ::dlerror());
+ return;
+ }
- // Calculate the SHA-1 checksum of libRS.so.
- calcFileSHA1(LibRSSHA1, LibRSPath);
-
- loaded = true;
+ LibBCCSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libbcc_so_SHA1"));
+ LibRSSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libRS_so_SHA1"));
return;
}
@@ -86,7 +87,7 @@
pInfo.mDependencyTable[1];
// Check libbcc.so.
- if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, 20) != 0) {
+ if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, SHA1_DIGEST_LENGTH) != 0) {
ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename,
LibBCCPath);
PRINT_DEPENDENCY("current - ", LibBCCPath, LibBCCSHA1);
@@ -96,7 +97,7 @@
}
// Check libRS.so.
- if (::memcmp(cache_libRS_dep.second, LibRSSHA1, 20) != 0) {
+ if (::memcmp(cache_libRS_dep.second, LibRSSHA1, SHA1_DIGEST_LENGTH) != 0) {
ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename,
LibRSPath);
PRINT_DEPENDENCY("current - ", LibRSPath, LibRSSHA1);
@@ -113,7 +114,8 @@
if ((::strncmp(in_dep.getSourceName().c_str(),
cache_dep.first,
in_dep.getSourceName().length()) != 0) ||
- (::memcmp(in_dep.getSHA1Checksum(), cache_dep.second, 20) != 0)) {
+ (::memcmp(in_dep.getSHA1Checksum(), cache_dep.second,
+ SHA1_DIGEST_LENGTH) != 0)) {
ALOGD("Cache %s is dirty due to the source it dependends on has been "
"changed:", pInputFilename);
PRINT_DEPENDENCY("given - ", in_dep.getSourceName().c_str(),
diff --git a/lib/RenderScript/RSInfoExtractor.cpp b/lib/RenderScript/RSInfoExtractor.cpp
index 549e5e0..c303ef3 100644
--- a/lib/RenderScript/RSInfoExtractor.cpp
+++ b/lib/RenderScript/RSInfoExtractor.cpp
@@ -112,12 +112,13 @@
uint8_t *sha1 = reinterpret_cast<uint8_t *>(pStringPool + *pWriteStart);
- // SHA-1 is special. It's 20-bytes long without null-terminator.
- ::memcpy(sha1, pSHA1, 20);
+ // SHA-1 is special. It's size of SHA1_DIGEST_LENGTH (=20) bytes long without
+ // null-terminator.
+ ::memcpy(sha1, pSHA1, SHA1_DIGEST_LENGTH);
// Record in the result RSInfo object.
pDepTable.push(std::make_pair(source_name, sha1));
// Update the string pool pointer.
- *pWriteStart += 20;
+ *pWriteStart += SHA1_DIGEST_LENGTH;
return true;
}
@@ -164,15 +165,15 @@
// Don't forget to reserve the space for the dependency informationin string
// pool.
- string_pool_size += ::strlen(LibBCCPath) + 1 + 20;
- string_pool_size += ::strlen(LibRSPath) + 1 + 20;
+ string_pool_size += ::strlen(LibBCCPath) + 1 + SHA1_DIGEST_LENGTH;
+ string_pool_size += ::strlen(LibRSPath) + 1 + SHA1_DIGEST_LENGTH;
for (unsigned i = 0, e = pDeps.size(); i != e; i++) {
const RSScript::SourceDependency *source_dep = pDeps[i];
if (source_dep != NULL) {
// +1 for null-terminator
string_pool_size += source_dep->getSourceName().length() + 1;
- // +20 for SHA-1 checksum
- string_pool_size += 20;
+ // +SHA1_DIGEST_LENGTH for SHA-1 checksum
+ string_pool_size += SHA1_DIGEST_LENGTH;
}
}