summaryrefslogtreecommitdiff
path: root/cpu_ref/rsCpuExecutable.cpp
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2015-04-16 10:27:02 -0700
committerYang Ni <yangni@google.com>2015-04-16 15:29:11 -0700
commitcb17015fed6b11a5028f31cc804a3847e379945d (patch)
tree85179b598a90ed179586cf880321b524a3d49f7e /cpu_ref/rsCpuExecutable.cpp
parentf28aa55e416e662082bfda5716c4afbac7a77bbe (diff)
Dedup checksum calculation routines
I introduced a separate routine to cacluate checksum for ScriptGroup in my previous CL, in addition to the one we use for regular scripts. This CL removes the new one and uses the old one. While I am on it, I made some other minor changes, e.g., changing mBuildChecksum in RsdCpuScriptIml from char* to uint32_t, and a few other minor cleanups in ScriptGroup2 implementation. Change-Id: I168fdbb4e7bd14f1549a687e7b0d0ca6dd4da866
Diffstat (limited to 'cpu_ref/rsCpuExecutable.cpp')
-rw-r--r--cpu_ref/rsCpuExecutable.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index 98f9ef85..f45e8f0d 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -281,7 +281,7 @@ static char* strgets(char *s, int size, const char **ppstr) {
}
ScriptExecutable* ScriptExecutable::createFromSharedObject(
- Context* RSContext, void* sharedObj) {
+ Context* RSContext, void* sharedObj, uint32_t expectedChecksum) {
char line[MAXLINE];
size_t varCount = 0;
@@ -299,7 +299,7 @@ ScriptExecutable* ScriptExecutable::createFromSharedObject(
uint32_t* forEachSignatures = nullptr;
const char ** pragmaKeys = nullptr;
const char ** pragmaValues = nullptr;
- char *checksum = nullptr;
+ uint32_t checksum = 0;
const char *rsInfo = (const char *) dlsym(sharedObj, ".rs.info");
@@ -519,25 +519,21 @@ ScriptExecutable* ScriptExecutable::createFromSharedObject(
}
if (strgets(line, MAXLINE, &rsInfo) != nullptr) {
- if (strncmp(line, CHECKSUM_STR, strlen(CHECKSUM_STR)) != 0) {
+ if (sscanf(line, CHECKSUM_STR "%08x", &checksum) != 1) {
ALOGE("Invalid checksum flag!: %s", line);
goto error;
}
-
- // consume trailing newline character
- char *c = strrchr(line, '\n');
- if (c) {
- *c = '\0';
- }
-
- char *checksumStart = &line[strlen(CHECKSUM_STR)];
- checksum = new char[strlen(checksumStart) + 1];
- strcpy(checksum, checksumStart);
} else {
ALOGE("Missing checksum in shared obj file");
goto error;
}
+ if (expectedChecksum != 0 && checksum != expectedChecksum) {
+ ALOGE("Found invalid checksum. Expected %08x, got %08x\n",
+ expectedChecksum, checksum);
+ goto error;
+ }
+
#endif // RS_COMPATIBILITY_LIB
return new ScriptExecutable(
@@ -550,7 +546,6 @@ ScriptExecutable* ScriptExecutable::createFromSharedObject(
error:
#ifndef RS_COMPATIBILITY_LIB
- delete[] checksum;
for (size_t idx = 0; idx < pragmaCount; ++idx) {
delete [] pragmaKeys[idx];