From 3cccadcf0fbfc7ff4e7dd37299a65bea1cf0eab0 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 11 May 2020 20:20:14 +0200 Subject: Change plugin interface to prevent segfaults when unloading plugin (#5210) Fixes: #3473 Closes: #5193 --- core/plugin_api.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 core/plugin_api.rs (limited to 'core/plugin_api.rs') diff --git a/core/plugin_api.rs b/core/plugin_api.rs new file mode 100644 index 000000000..2e93fdb77 --- /dev/null +++ b/core/plugin_api.rs @@ -0,0 +1,23 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +// This file defines the public interface for dynamically loaded plugins. + +// The plugin needs to do all interaction with the CLI crate through trait +// objects and function pointers. This ensures that no concrete internal methods +// (such as register_op and the closures created by it) can end up in the plugin +// shared library itself, which would cause segfaults when the plugin is +// unloaded and all functions in the plugin library are unmapped from memory. + +pub use crate::Buf; +pub use crate::Op; +pub use crate::OpId; +pub use crate::ZeroCopyBuf; + +pub type InitFn = fn(&mut dyn Interface); + +pub type DispatchOpFn = + fn(&mut dyn Interface, &[u8], Option) -> Op; + +pub trait Interface { + fn register_op(&mut self, name: &str, dispatcher: DispatchOpFn) -> OpId; +} -- cgit v1.2.3