Permalink
Browse files

Fix exception handling weirdness on ios-arm

Turns out `v8::Trycatch` must be stack-allocated, and we were implicitly
allocating it on the heap by making it part of a heap-allocated object.
  • Loading branch information...
1 parent 03d4a62 commit 2f02e911edc4a5df80051fdaed72e0281ea751e7 @oleavr oleavr committed Jun 17, 2015
@@ -19,6 +19,7 @@ libfrida_gumjs_1_0_la_LIBTOOLFLAGS = \
libfrida_gumjs_la_SOURCES = \
gumscript.cpp \
+ gumscript-priv.h \
gumscript-runtime.h \
gumscriptplatform.h \
gumscriptplatform.cpp \
@@ -29,6 +30,7 @@ libfrida_gumjs_la_SOURCES = \
gumscripttask.h \
gumscripttask.c \
gumscriptscope.h \
+ gumscriptscope.cpp \
gumscriptcore.h \
gumscriptcore.cpp \
gumscriptmemory.h \
@@ -6,6 +6,7 @@
<ClCompile Include="gumscriptbundle.cpp" />
<ClCompile Include="gumscriptscheduler.c" />
<ClCompile Include="gumscripttask.c" />
+ <ClCompile Include="gumscriptscope.cpp" />
<ClCompile Include="gumscriptcore.cpp" />
<ClCompile Include="gumscriptmemory.cpp" />
<ClCompile Include="gumscriptprocess.cpp" />
@@ -21,6 +22,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="gumscript.h" />
+ <ClInclude Include="gumscript-priv.h" />
<ClInclude Include="gumscriptplatform.h" />
<ClInclude Include="gumscriptbundle.h" />
<ClInclude Include="gumscriptscheduler.h" />
@@ -75,4 +77,4 @@
<Filter>runtime</Filter>
</CustomBuild>
</ItemGroup>
-</Project>
+</Project>
@@ -6,6 +6,7 @@
<ClCompile Include="gumscriptbundle.cpp" />
<ClCompile Include="gumscriptscheduler.c" />
<ClCompile Include="gumscripttask.c" />
+ <ClCompile Include="gumscriptscope.cpp" />
<ClCompile Include="gumscriptcore.cpp" />
<ClCompile Include="gumscriptmemory.cpp" />
<ClCompile Include="gumscriptprocess.cpp" />
@@ -21,6 +22,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="gumscript.h" />
+ <ClInclude Include="gumscript-priv.h" />
<ClInclude Include="gumscriptplatform.h" />
<ClInclude Include="gumscriptbundle.h" />
<ClInclude Include="gumscriptscheduler.h" />
@@ -75,4 +77,4 @@
<Filter>runtime</Filter>
</CustomBuild>
</ItemGroup>
-</Project>
+</Project>
@@ -10,6 +10,7 @@
<ItemGroup>
<ClInclude Include="gumscript.h" />
+ <ClInclude Include="gumscript-priv.h" />
<ClInclude Include="gumscriptplatform.h" />
<ClInclude Include="$(IntDir)gumjs\gumscript-runtime.h" />
<ClInclude Include="$(IntDir)gumjs\gumscript-debug.h" />
@@ -37,6 +38,7 @@
<ClCompile Include="gumscriptbundle.cpp" />
<ClCompile Include="gumscriptscheduler.c" />
<ClCompile Include="gumscripttask.c" />
+ <ClCompile Include="gumscriptscope.cpp" />
<ClCompile Include="gumscriptcore.cpp" />
<ClCompile Include="gumscriptmemory.cpp" />
<ClCompile Include="gumscriptprocess.cpp" />
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015 Ole André Vadla Ravnås <oleavr@nowsecure.com>
+ *
+ * Licence: wxWindows Library Licence, Version 3.1
+ */
+
+#ifndef __GUM_SCRIPT_PRIV_H__
+#define __GUM_SCRIPT_PRIV_H__
+
+#include "gumscript.h"
+#include "gumscriptcore.h"
+#include "gumscriptfile.h"
+#include "gumscriptinstruction.h"
+#include "gumscriptinterceptor.h"
+#include "gumscriptmemory.h"
+#include "gumscriptmodule.h"
+#include "gumscriptplatform.h"
+#include "gumscriptprocess.h"
+#include "gumscriptscope.h"
+#include "gumscriptsocket.h"
+#include "gumscriptstalker.h"
+#include "gumscriptsymbol.h"
+#include "gumscripttask.h"
+#include "gumscriptthread.h"
+
+G_BEGIN_DECLS
+
+struct _GumScriptPrivate
+{
+ gchar * name;
+ gchar * source;
+ GMainContext * main_context;
+
+ v8::Isolate * isolate;
+ GumScriptCore core;
+ GumScriptMemory memory;
+ GumScriptProcess process;
+ GumScriptThread thread;
+ GumScriptModule module;
+ GumScriptFile file;
+ GumScriptSocket socket;
+ GumScriptInterceptor interceptor;
+ GumScriptStalker stalker;
+ GumScriptSymbol symbol;
+ GumScriptInstruction instruction;
+ GumPersistent<v8::Context>::type * context;
+ GumPersistent<v8::Script>::type * code;
+ gboolean loaded;
+
+ GumScriptMessageHandler message_handler;
+ gpointer message_handler_data;
+ GDestroyNotify message_handler_data_destroy;
+};
+
+G_END_DECLS
+
+#endif
@@ -7,20 +7,7 @@
#include "gumscript.h"
-#include "gumscriptcore.h"
-#include "gumscriptfile.h"
-#include "gumscriptinstruction.h"
-#include "gumscriptinterceptor.h"
-#include "gumscriptmemory.h"
-#include "gumscriptmodule.h"
-#include "gumscriptplatform.h"
-#include "gumscriptprocess.h"
-#include "gumscriptscope.h"
-#include "gumscriptsocket.h"
-#include "gumscriptstalker.h"
-#include "gumscriptsymbol.h"
-#include "gumscripttask.h"
-#include "gumscriptthread.h"
+#include "gumscript-priv.h"
#include <gum/gum-init.h>
#include <string.h>
@@ -51,33 +38,6 @@ enum
PROP_MAIN_CONTEXT
};
-struct _GumScriptPrivate
-{
- gchar * name;
- gchar * source;
- GMainContext * main_context;
-
- Isolate * isolate;
- GumScriptCore core;
- GumScriptMemory memory;
- GumScriptProcess process;
- GumScriptThread thread;
- GumScriptModule module;
- GumScriptFile file;
- GumScriptSocket socket;
- GumScriptInterceptor interceptor;
- GumScriptStalker stalker;
- GumScriptSymbol symbol;
- GumScriptInstruction instruction;
- GumPersistent<Context>::type * context;
- GumPersistent<Script>::type * code;
- gboolean loaded;
-
- GumScriptMessageHandler message_handler;
- gpointer message_handler_data;
- GDestroyNotify message_handler_data_destroy;
-};
-
struct _GumScriptFromStringData
{
gchar * name;
@@ -975,93 +935,3 @@ gum_script_on_leave (GumInvocationListener * listener,
_gum_script_interceptor_on_leave (&self->priv->interceptor, context);
}
-class ScriptScopeImpl
-{
-public:
- ScriptScopeImpl (GumScript * parent)
- : parent (parent),
- locker (parent->priv->isolate),
- isolate_scope (parent->priv->isolate),
- handle_scope (parent->priv->isolate),
- context (Local<Context>::New (parent->priv->isolate, *parent->priv->context)),
- context_scope (context),
- trycatch (parent->priv->isolate)
- {
- }
-
- ~ScriptScopeImpl ()
- {
- GumScriptPrivate * priv = parent->priv;
-
- if (trycatch.HasCaught ())
- {
- Handle<Message> message = trycatch.Message ();
- Handle<Value> exception = trycatch.Exception ();
- trycatch.Reset ();
-
- GString * error = g_string_new ("{\"type\":\"error\"");
-
- Local<Value> resource_name = message->GetScriptResourceName ();
- if (!resource_name->IsUndefined ())
- {
- String::Utf8Value resource_name_str (resource_name->ToString ());
- g_string_append_printf (error, ",\"fileName\":\"%s\"",
- *resource_name_str);
-
- Maybe<int> line_number = message->GetLineNumber (context);
- if (line_number.IsJust ())
- {
- g_string_append_printf (error, ",\"lineNumber\":%d",
- line_number.FromJust ());
- }
- }
-
- String::Utf8Value exception_str (exception);
- gchar * exception_str_escaped = g_strescape (*exception_str, "");
- g_string_append_printf (error, ",\"description\":\"%s\"",
- exception_str_escaped);
- g_free (exception_str_escaped);
-
- g_string_append_c (error, '}');
-
- _gum_script_core_emit_message (&priv->core, error->str, NULL, 0);
-
- g_string_free (error, TRUE);
- }
- }
-
- bool HasPendingException () const
- {
- return trycatch.HasCaught ();
- }
-
-private:
- GumScript * parent;
- Locker locker;
- Isolate::Scope isolate_scope;
- HandleScope handle_scope;
- Local<Context> context;
- Context::Scope context_scope;
- TryCatch trycatch;
-};
-
-ScriptScope::ScriptScope (GumScript * parent)
- : parent (parent),
- impl (new ScriptScopeImpl (parent))
-{
-}
-
-ScriptScope::~ScriptScope ()
-{
- delete impl;
- impl = NULL;
-
- _gum_script_stalker_process_pending (&parent->priv->stalker);
-}
-
-bool
-ScriptScope::HasPendingException () const
-{
- return impl->HasPendingException ();
-}
-
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015 Ole André Vadla Ravnås <oleavr@nowsecure.com>
+ *
+ * Licence: wxWindows Library Licence, Version 3.1
+ */
+
+#include "gumscriptscope.h"
+
+#include "gumscript-priv.h"
+
+using namespace v8;
+
+ScriptScope::ScriptScope (GumScript * parent)
+ : parent (parent),
+ stalker_scope (parent),
+ locker (parent->priv->isolate),
+ isolate_scope (parent->priv->isolate),
+ handle_scope (parent->priv->isolate),
+ context (Local<Context>::New (parent->priv->isolate, *parent->priv->context)),
+ context_scope (context),
+ trycatch (parent->priv->isolate)
+{
+}
+
+ScriptScope::~ScriptScope ()
+{
+ GumScriptPrivate * priv = parent->priv;
+
+ if (trycatch.HasCaught ())
+ {
+ Handle<Message> message = trycatch.Message ();
+ Handle<Value> exception = trycatch.Exception ();
+ trycatch.Reset ();
+
+ GString * error = g_string_new ("{\"type\":\"error\"");
+
+ Local<Value> resource_name = message->GetScriptResourceName ();
+ if (!resource_name->IsUndefined ())
+ {
+ String::Utf8Value resource_name_str (resource_name->ToString ());
+ g_string_append_printf (error, ",\"fileName\":\"%s\"",
+ *resource_name_str);
+
+ Maybe<int> line_number = message->GetLineNumber (context);
+ if (line_number.IsJust ())
+ {
+ g_string_append_printf (error, ",\"lineNumber\":%d",
+ line_number.FromJust ());
+ }
+ }
+
+ String::Utf8Value exception_str (exception);
+ gchar * exception_str_escaped = g_strescape (*exception_str, "");
+ g_string_append_printf (error, ",\"description\":\"%s\"",
+ exception_str_escaped);
+ g_free (exception_str_escaped);
+
+ g_string_append_c (error, '}');
+
+ _gum_script_core_emit_message (&priv->core, error->str, NULL, 0);
+
+ g_string_free (error, TRUE);
+ }
+}
+
+ScriptStalkerScope::ScriptStalkerScope (GumScript * parent)
+ : parent (parent)
+{
+}
+
+ScriptStalkerScope::~ScriptStalkerScope ()
+{
+ _gum_script_stalker_process_pending (&parent->priv->stalker);
+}
+
Oops, something went wrong.

0 comments on commit 2f02e91

Please sign in to comment.