diff --git a/sandboxed_api/tools/clang_generator/emitter.cc b/sandboxed_api/tools/clang_generator/emitter.cc index 9f8c0659..2d7a804c 100644 --- a/sandboxed_api/tools/clang_generator/emitter.cc +++ b/sandboxed_api/tools/clang_generator/emitter.cc @@ -107,7 +107,12 @@ constexpr absl::string_view kEmbedClassTemplate = R"( // Sandbox with embedded sandboxee and default policy class %1$s : public ::sapi::Sandbox { public: - %1$s() : ::sapi::Sandbox(%2$s_embed_create()) {} + %1$s() + : ::sapi::Sandbox([]() { + static auto* fork_client_context = + new ::sapi::ForkClientContext(%2$s_embed_create()); + return fork_client_context; + }()) {} }; )"; diff --git a/sandboxed_api/tools/python_generator/code.py b/sandboxed_api/tools/python_generator/code.py index 6727b13e..6fb87f7c 100644 --- a/sandboxed_api/tools/python_generator/code.py +++ b/sandboxed_api/tools/python_generator/code.py @@ -739,10 +739,16 @@ class Generator(object): GUARD_START = ('#ifndef {0}\n' '#define {0}') GUARD_END = '#endif // {}' EMBED_INCLUDE = '#include "{}"' - EMBED_CLASS = ('class {0}Sandbox : public ::sapi::Sandbox {{\n' - ' public:\n' - ' {0}Sandbox() : ::sapi::Sandbox({1}_embed_create()) {{}}\n' - '}};') + EMBED_CLASS = ''' +class {0}Sandbox : public ::sapi::Sandbox {{ + public: + {0}Sandbox() + : ::sapi::Sandbox([]() {{ + static auto* fork_client_context = + new ::sapi::ForkClientContext({1}_embed_create()); + return fork_client_context; + }}()) {{}} +}};''' def __init__(self, translation_units): # type: (List[cindex.TranslationUnit]) -> None