From 855995325e7f8a48a8015d85ee1ad8e8080b5058 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 21 Jul 2020 23:34:52 +0000 Subject: feat(3p/nix): remove builtins.importNative This is the shared object equivalent of builtins.exec, or a plugins equivalent accessible from the Nix language. Either way, since we don't have builtins.exec or plugins any more, I think it makes sense to remove this builtin. This will also allow us to drop the allow-unsafe-native-code-during-evaluation option, which formerly controlled whether builtins.exec and builtins.importNative were enabled. Cc: Griffin Smith Cc: Profpatsch Change-Id: I8993a8a79d559c102647308a2684c089bbc06713 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1340 Reviewed-by: glittershark Reviewed-by: Profpatsch Tested-by: BuildkiteCI --- third_party/nix/src/libexpr/primops.cc | 50 ---------------------------------- third_party/nix/src/libexpr/primops.hh | 5 ---- 2 files changed, 55 deletions(-) (limited to 'third_party') diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 107cacb963..06b9788bdf 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -162,52 +161,6 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args, } } -/* Want reasonable symbol names, so extern C */ -/* !!! Should we pass the Pos or the file name too? */ -extern "C" using ValueInitializer = void(*)(EvalState&, Value&); - -/* Load a ValueInitializer from a DSO and return whatever it initializes */ -void prim_importNative(EvalState& state, const Pos& pos, Value** args, - Value& v) { - PathSet context; - Path path = state.coerceToPath(pos, *args[0], context); - - try { - state.realiseContext(context); - } catch (InvalidPathError& e) { - throw EvalError( - format("cannot import '%1%', since path '%2%' is not valid, at %3%") % - path % e.path % pos); - } - - path = state.checkSourcePath(path); - - std::string sym = state.forceStringNoCtx(*args[1], pos); - - void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL); - if (handle == nullptr) { - throw EvalError(format("could not open '%1%': %2%") % path % dlerror()); - } - - dlerror(); - auto func = (ValueInitializer)dlsym(handle, sym.c_str()); - if (func == nullptr) { - char* message = dlerror(); - if (message != nullptr) { - throw EvalError(format("could not load symbol '%1%' from '%2%': %3%") % - sym % path % message); - } - throw EvalError(format("symbol '%1%' from '%2%' resolved to NULL when a " - "function pointer was expected") % - sym % path); - } - - (func)(state, v); - - /* We don't dlclose because v may be a primop referencing a function in the - * shared object file */ -} - /* Return a string representing the type of the expression. */ static void prim_typeOf(EvalState& state, const Pos& pos, Value** args, Value& v) { @@ -2239,9 +2192,6 @@ void EvalState::createBaseEnv() { mkApp(v, *vScopedImport, *v2); forceValue(v); addConstant("import", v); - if (evalSettings.enableNativeCode) { - addPrimOp("__importNative", 2, prim_importNative); - } addPrimOp("__typeOf", 1, prim_typeOf); addPrimOp("isNull", 1, prim_isNull); addPrimOp("__isFunction", 1, prim_isFunction); diff --git a/third_party/nix/src/libexpr/primops.hh b/third_party/nix/src/libexpr/primops.hh index 388066f390..0c9f6ccab1 100644 --- a/third_party/nix/src/libexpr/primops.hh +++ b/third_party/nix/src/libexpr/primops.hh @@ -14,9 +14,4 @@ struct RegisterPrimOp { RegisterPrimOp(const std::string& name, size_t arity, PrimOpFun fun); }; -/* These primops are disabled without enableNativeCode */ -/* Load a ValueInitializer from a DSO and return whatever it initializes */ -void prim_importNative(EvalState& state, const Pos& pos, Value** args, - Value& v); - } // namespace nix -- cgit 1.4.1