From abb535bc6978fbc735dcfc45215cef5aaffc654a Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Tue, 28 Apr 2015 14:40:45 -0700 Subject: Handle older structure sizes by zeroing new fields Bug 19734267 Bug 19866850 Prior fix handled only rsForEach calls from a script. It is not sufficient, as launch options in support library also will also use old structures. Apps compiled for support library still run in native mode when available, thus necessitating this fix. This fix copies and extends the input in ScriptC::runForEach instead of rsrForEach. Change-Id: I3bb2527eadcbcdb85a76a1f5568269bbfdee972b (cherry-pick of 9479e5bf0152ecff022cd374e2e80905f88b1a5d from AOSP) --- driver/rsdRuntimeStubs.cpp | 15 +++++---------- rsRuntime.h | 3 +-- rsScriptC.cpp | 9 +++++++++ rsScriptC_Lib.cpp | 19 +++---------------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp index bc5c8922..c728ca71 100644 --- a/driver/rsdRuntimeStubs.cpp +++ b/driver/rsdRuntimeStubs.cpp @@ -439,9 +439,8 @@ void __attribute__((overloadable)) rsForEach(::rs_script script, const void *usr, const rs_script_call *call) { Context *rsc = RsdCpuReference::getTlsContext(); - const Script *sc = RsdCpuReference::getTlsScript(); rsrForEach(rsc, (Script *)script.p, (Allocation *)in.p, - (Allocation *)out.p, usr, 0, (RsScriptCall *)call, sc); + (Allocation *)out.p, usr, 0, (RsScriptCall *)call); } void __attribute__((overloadable)) rsForEach(::rs_script script, @@ -449,18 +448,16 @@ void __attribute__((overloadable)) rsForEach(::rs_script script, ::rs_allocation out, const void *usr) { Context *rsc = RsdCpuReference::getTlsContext(); - const Script *sc = RsdCpuReference::getTlsScript(); rsrForEach(rsc, (Script *)script.p, (Allocation *)in.p, (Allocation *)out.p, - usr, 0, nullptr, sc); + usr, 0, nullptr); } void __attribute__((overloadable)) rsForEach(::rs_script script, ::rs_allocation in, ::rs_allocation out) { Context *rsc = RsdCpuReference::getTlsContext(); - const Script *sc = RsdCpuReference::getTlsScript(); rsrForEach(rsc, (Script *)script.p, (Allocation *)in.p, (Allocation *)out.p, - nullptr, 0, nullptr, sc); + nullptr, 0, nullptr); } // These functions are only supported in 32-bit. @@ -471,9 +468,8 @@ void __attribute__((overloadable)) rsForEach(::rs_script script, const void *usr, uint32_t usrLen) { Context *rsc = RsdCpuReference::getTlsContext(); - const Script *sc = RsdCpuReference::getTlsScript(); rsrForEach(rsc, (Script *)script.p, (Allocation *)in.p, (Allocation *)out.p, - usr, usrLen, nullptr, sc); + usr, usrLen, nullptr); } void __attribute__((overloadable)) rsForEach(::rs_script script, @@ -483,9 +479,8 @@ void __attribute__((overloadable)) rsForEach(::rs_script script, uint32_t usrLen, const rs_script_call *call) { Context *rsc = RsdCpuReference::getTlsContext(); - const Script *sc = RsdCpuReference::getTlsScript(); rsrForEach(rsc, (Script *)script.p, (Allocation *)in.p, (Allocation *)out.p, - usr, usrLen, (RsScriptCall *)call, sc); + usr, usrLen, (RsScriptCall *)call); } #endif diff --git a/rsRuntime.h b/rsRuntime.h index de6ede36..5a058830 100644 --- a/rsRuntime.h +++ b/rsRuntime.h @@ -159,8 +159,7 @@ void rsrForEach(Context *, Script *target, Allocation *out, const void *usr, uint32_t usrBytes, - const RsScriptCall *call, - const Script *callingScript); + const RsScriptCall *call); ////////////////////////////////////////////////////////////////////////////// diff --git a/rsScriptC.cpp b/rsScriptC.cpp index e1685b91..a24334e3 100644 --- a/rsScriptC.cpp +++ b/rsScriptC.cpp @@ -192,6 +192,15 @@ void ScriptC::runForEach(Context *rsc, const void * usr, size_t usrBytes, const RsScriptCall *sc) { + // Make a copy of RsScriptCall and zero out extra fields that are absent + // in API levels below 23. + RsScriptCall sc_copy; + if (sc != nullptr && getApiLevel() < 23) { + memset(&sc_copy, 0, sizeof(sc_copy)); + memcpy(&sc_copy, sc, 7*4); + sc = &sc_copy; + } + // Trace this function call. // To avoid overhead we only build the string if tracing is actually // enabled. diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp index cc930211..c404bde9 100644 --- a/rsScriptC_Lib.cpp +++ b/rsScriptC_Lib.cpp @@ -238,30 +238,17 @@ void rsrForEach(Context *rsc, Script *target, Allocation *in, Allocation *out, const void *usr, uint32_t usrBytes, - const RsScriptCall *call, - const Script *callingScript) { - - RsScriptCall c, *cptr = nullptr; - memset(&c, 0, sizeof(c)); - if (call != nullptr) { - cptr = &c; - if (callingScript->getApiLevel() < 23) { - // Up to API 23, the structure was smaller and we need to zero extend - memcpy(&c, call, 7*4); - } else { - c = *call; - } - } + const RsScriptCall *call) { if (in == nullptr) { target->runForEach(rsc, /* root slot */ 0, nullptr, 0, out, usr, - usrBytes, cptr); + usrBytes, call); } else { const Allocation *ins[1] = {in}; target->runForEach(rsc, /* root slot */ 0, ins, sizeof(ins) / sizeof(RsAllocation), out, usr, - usrBytes, cptr); + usrBytes, call); } } -- cgit v1.2.3 From 5126e3eb5af9bc2113e4071f00c642e35f89f651 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Tue, 28 Apr 2015 15:41:48 -0700 Subject: SetError if forEachMtlsSetup fails sanity check bug 19866850 Explicitly set error when a kernel launch fails. Change-Id: If42419f3cf7557c524afc5bb27a0753460ca7e4e (cherry-pick 80afd424b02291e6f088cab2961537c7ba1ee2a5 from AOSP) --- cpu_ref/rsCpuScript.cpp | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp index fd40c21d..3f64534a 100644 --- a/cpu_ref/rsCpuScript.cpp +++ b/cpu_ref/rsCpuScript.cpp @@ -566,7 +566,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.x = rsMin(mtls->fep.dim.x, sc->xStart); mtls->end.x = rsMin(mtls->fep.dim.x, sc->xEnd); - if (mtls->start.x >= mtls->end.x) return false; + if (mtls->start.x >= mtls->end.x) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid xStart or xEnd."); + return false; + } } if (!sc || (sc->yEnd == 0)) { @@ -574,7 +578,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.y = rsMin(mtls->fep.dim.y, sc->yStart); mtls->end.y = rsMin(mtls->fep.dim.y, sc->yEnd); - if (mtls->start.y >= mtls->end.y) return false; + if (mtls->start.y >= mtls->end.y) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid yStart or yEnd."); + return false; + } } if (!sc || (sc->zEnd == 0)) { @@ -582,7 +590,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.z = rsMin(mtls->fep.dim.z, sc->zStart); mtls->end.z = rsMin(mtls->fep.dim.z, sc->zEnd); - if (mtls->start.z >= mtls->end.z) return false; + if (mtls->start.z >= mtls->end.z) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid zStart or zEnd."); + return false; + } } if (!sc || (sc->arrayEnd == 0)) { @@ -590,7 +602,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayStart); mtls->end.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayEnd); - if (mtls->start.array[0] >= mtls->end.array[0]) return false; + if (mtls->start.array[0] >= mtls->end.array[0]) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid arrayStart or arrayEnd."); + return false; + } } if (!sc || (sc->array2End == 0)) { @@ -598,7 +614,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2Start); mtls->end.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2End); - if (mtls->start.array[1] >= mtls->end.array[1]) return false; + if (mtls->start.array[1] >= mtls->end.array[1]) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid array2Start or array2End."); + return false; + } } if (!sc || (sc->array3End == 0)) { @@ -606,7 +626,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3Start); mtls->end.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3End); - if (mtls->start.array[2] >= mtls->end.array[2]) return false; + if (mtls->start.array[2] >= mtls->end.array[2]) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid array3Start or array3End."); + return false; + } } if (!sc || (sc->array4End == 0)) { @@ -614,7 +638,11 @@ bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, } else { mtls->start.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4Start); mtls->end.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4End); - if (mtls->start.array[3] >= mtls->end.array[3]) return false; + if (mtls->start.array[3] >= mtls->end.array[3]) { + mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, + "Failed to launch kernel; Invalid array4Start or array4End."); + return false; + } } -- cgit v1.2.3