Add HAL version check, with fallback to CPU reference driver on failure.
am: 8e70791ff7
Change-Id: I93c6c4638b57a0b3173d5b7b86519bb14798096e
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index f0a7334..503da5a 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -265,7 +265,7 @@
extern "C" bool rsdHalQueryVersion(uint32_t *major, uint32_t *minor) {
- *major = 23;
+ *major = RS_HAL_VERSION;
*minor = 0;
return true;
}
diff --git a/rsDriverLoader.cpp b/rsDriverLoader.cpp
index 426c519..83c6cf6 100644
--- a/rsDriverLoader.cpp
+++ b/rsDriverLoader.cpp
@@ -201,6 +201,12 @@
goto error;
}
+ if (version_major != RS_HAL_VERSION) {
+ ALOGE("Mismatched RS HAL versions: %s is version %u but version %u is expected",
+ filename, version_major, RS_HAL_VERSION);
+ goto error;
+ }
+
if (!LoadHalTable(this, fnQueryHal, mIsGraphicsContext)) {
ALOGE("Error loading RS HAL table, %s", filename);
goto error;
diff --git a/rs_hal.h b/rs_hal.h
index 2f3aa1a..faee684 100644
--- a/rs_hal.h
+++ b/rs_hal.h
@@ -19,13 +19,34 @@
#include <rsInternalDefines.h>
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * !! Major version number of the driver. This is used to ensure that
+ * !! the driver (e.g., libRSDriver) is compatible with the shell
+ * !! (i.e., libRS_internal) responsible for loading the driver.
+ * !! There is no notion of backwards compatibility -- the driver and
+ * !! the shell must agree on the major version number.
+ * !!
+ * !! The version number must change whenever there is a semantic change
+ * !! to the HAL such as adding or removing an entry point or changing
+ * !! the meaning of an entry point. By convention it is monotonically
+ * !! increasing across all branches (e.g., aosp/master and all internal
+ * !! branches).
+ * !!
+ * !! Be very careful when merging or cherry picking between branches!
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+#define RS_HAL_VERSION 100
+
/**
* The interface for loading RenderScript drivers
*
* The startup sequence is
*
* 1: dlopen driver
- * 2: Query driver version with rsdHalQueryVersion()
+ * 2: Query driver version with rsdHalQueryVersion() and verify
+ * that the driver (e.g., libRSDriver) is compatible with the shell
+ * (i.e., libRS_internal) responsible for loading the driver
* 3: Fill in HAL pointer table with calls to rsdHalQueryHAL()
* 4: Initialize the context with rsdHalInit()
*
@@ -479,10 +500,16 @@
/**
* Get the major version number of the driver. The major
- * version should be the API version number
+ * version should be the RS_HAL_VERSION against which the
+ * driver was built
*
* The Minor version number is vendor specific
*
+ * The caller should ensure that *version_major is the same as
+ * RS_HAL_VERSION -- i.e., that the driver (e.g., libRSDriver)
+ * is compatible with the shell (i.e., libRS_internal) responsible
+ * for loading the driver
+ *
* return: False will abort loading the driver, true indicates
* success
*/