summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Repinski <repinski23@gmail.com>2016-03-10 12:40:18 -0600
committerZiyan <jaraidaniel@gmail.com>2016-03-11 01:17:05 +0100
commit58ec31efa2512fef35c1ff95a84675734a285769 (patch)
tree7890bfb4d1813f446f63b90bd0d1b37c42c8d6d6
parentc05105e2d70e93f445fec1471c5f83e8cc9f2d78 (diff)
downloaddevice_samsung_tuna-58ec31efa2512fef35c1ff95a84675734a285769.zip
device_samsung_tuna-58ec31efa2512fef35c1ff95a84675734a285769.tar.gz
device_samsung_tuna-58ec31efa2512fef35c1ff95a84675734a285769.tar.bz2
libsecril-shim: Add 'patchMem'; fix maguro LAST_CALL_FAIL_CAUSE bug
-rw-r--r--ril/libsecril-shim/secril-shim.c48
-rw-r--r--ril/libsecril-shim/secril-shim.h3
2 files changed, 51 insertions, 0 deletions
diff --git a/ril/libsecril-shim/secril-shim.c b/ril/libsecril-shim/secril-shim.c
index c83a4ae..f39c59f 100644
--- a/ril/libsecril-shim/secril-shim.c
+++ b/ril/libsecril-shim/secril-shim.c
@@ -72,6 +72,48 @@ static void onRequestShim(int request, void *data, size_t datalen, RIL_Token t)
origRilFunctions->onRequest(request, data, datalen, t);
}
+static void patchMem(void *libHandle, bool beforeRilInit)
+{
+ /* hSecOem is a nice symbol to use, it's in all 3 RILs and gives us easy
+ * access to the memory region we're generally most interested in. */
+ uint8_t *hSecOem;
+
+ hSecOem = dlsym(libHandle, "hSecOem");
+ if (CC_UNLIKELY(!hSecOem)) {
+ RLOGE("%s: hSecOem could not be found!\n", __func__);
+ return;
+ }
+
+ RLOGD("%s: hSecOem found at %p!\n", __func__, hSecOem);
+
+ switch (tunaVariant) {
+ case VARIANT_MAGURO:
+ if (!beforeRilInit) {
+ /* 'ril features' is (only) used to enable/disable an extension
+ * to LAST_CALL_FAIL_CAUSE. Android had just been happily
+ * ignoring the extra data being sent, until it did introduce a
+ * vendor extension for LAST_CALL_FAIL_CAUSE in Android 6.0;
+ * of course it doesn't like this RIL's extra data now (crashes),
+ * so we need to disable it. rilFeatures is initialized in
+ * RIL_Init, so defer it until afterwards. */
+ uint8_t *rilFeatures = hSecOem + 0x1918;
+
+ RLOGD("%s: rilFeatures is currently %" PRIu8 "\n", __func__, *rilFeatures);
+ if (CC_LIKELY(*rilFeatures == 1)) {
+ *rilFeatures = 0;
+ RLOGI("%s: rilFeatures was changed to %" PRIu8 "\n", __func__, *rilFeatures);
+ } else {
+ RLOGD("%s: rilFeatures was not 1; leaving alone\n", __func__);
+ }
+ }
+ break;
+ case VARIANT_TORO:
+ break;
+ case VARIANT_TOROPLUS:
+ break;
+ }
+}
+
const RIL_RadioFunctions* RIL_Init(const struct RIL_Env *env, int argc, char **argv)
{
RIL_RadioFunctions const* (*origRilInit)(const struct RIL_Env *env, int argc, char **argv);
@@ -109,12 +151,18 @@ const RIL_RadioFunctions* RIL_Init(const struct RIL_Env *env, int argc, char **a
goto fail_after_dlopen;
}
+ /* Fix RIL issues by patching memory: pre-init pass. */
+ patchMem(origRil, true);
+
origRilFunctions = origRilInit(env, argc, argv);
if (CC_UNLIKELY(!origRilFunctions)) {
RLOGE("%s: the original RIL_Init derped.\n", __func__);
goto fail_after_dlopen;
}
+ /* Fix RIL issues by patching memory: post-init pass. */
+ patchMem(origRil, false);
+
/* Shim functions as needed. */
shimmedFunctions = *origRilFunctions;
shimmedFunctions.onRequest = onRequestShim;
diff --git a/ril/libsecril-shim/secril-shim.h b/ril/libsecril-shim/secril-shim.h
index b1ee607..f41bbb3 100644
--- a/ril/libsecril-shim/secril-shim.h
+++ b/ril/libsecril-shim/secril-shim.h
@@ -5,6 +5,9 @@
#define RIL_SHLIB
#include <dlfcn.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>