diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-05-11 20:20:14 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-05-11 22:39:13 +0200 |
commit | 3cccadcf0fbfc7ff4e7dd37299a65bea1cf0eab0 (patch) | |
tree | 58c198d0222b942b8bd1321e1423eaaebd909795 /core | |
parent | a3f82c3d5ec3caad1d4ec74f49ef11adc45807d6 (diff) |
Change plugin interface to prevent segfaults when unloading plugin (#5210)
Fixes: #3473
Closes: #5193
Diffstat (limited to 'core')
-rw-r--r-- | core/lib.rs | 1 | ||||
-rw-r--r-- | core/plugin_api.rs | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/core/lib.rs b/core/lib.rs index 661640910..ffccc8feb 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -17,6 +17,7 @@ mod js_errors; mod module_specifier; mod modules; mod ops; +pub mod plugin_api; mod resources; mod shared_queue; 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<ZeroCopyBuf>) -> Op; + +pub trait Interface { + fn register_op(&mut self, name: &str, dispatcher: DispatchOpFn) -> OpId; +} |