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 <grfn@gws.fyi> Cc: Profpatsch <mail@profpatsch.de> Change-Id: I8993a8a79d559c102647308a2684c089bbc06713 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1340 Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									b1c0866037
								
							
						
					
					
						commit
						855995325e
					
				
					 2 changed files with 0 additions and 55 deletions
				
			
		
							
								
								
									
										50
									
								
								third_party/nix/src/libexpr/primops.cc
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										50
									
								
								third_party/nix/src/libexpr/primops.cc
									
										
									
									
										vendored
									
									
								
							|  | @ -5,7 +5,6 @@ | |||
| #include <regex> | ||||
| 
 | ||||
| #include <absl/strings/str_split.h> | ||||
| #include <dlfcn.h> | ||||
| #include <glog/logging.h> | ||||
| #include <sys/stat.h> | ||||
| #include <sys/types.h> | ||||
|  | @ -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); | ||||
|  |  | |||
							
								
								
									
										5
									
								
								third_party/nix/src/libexpr/primops.hh
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								third_party/nix/src/libexpr/primops.hh
									
										
									
									
										vendored
									
									
								
							|  | @ -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
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue