summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorElias Sjögreen <eliassjogreen1@gmail.com>2021-12-15 15:41:49 +0100
committerGitHub <noreply@github.com>2021-12-15 15:41:49 +0100
commitee49cce726c27cdcb372b9dba7f2deab840d9e6b (patch)
treed1a9a843eb5fba782a7cff5e50cb973ee3806225 /runtime
parent4d176b7b7c11aabc584bee45423f108ea47faefe (diff)
feat(ext/ffi): implement UnsafePointer and UnsafePointerView (#12828)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/build.rs2
-rw-r--r--runtime/js/90_deno_ns.js2
-rw-r--r--runtime/permissions.rs49
3 files changed, 36 insertions, 17 deletions
diff --git a/runtime/build.rs b/runtime/build.rs
index 14e2e0362..c83f13070 100644
--- a/runtime/build.rs
+++ b/runtime/build.rs
@@ -85,7 +85,7 @@ mod not_docs {
impl deno_ffi::FfiPermissions for Permissions {
fn check(
&mut self,
- _path: &Path,
+ _path: Option<&Path>,
) -> Result<(), deno_core::error::AnyError> {
unreachable!("snapshotting!")
}
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index e5e52b1f6..029423ee1 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -135,6 +135,8 @@
createHttpClient: __bootstrap.fetch.createHttpClient,
http: __bootstrap.http,
dlopen: __bootstrap.ffi.dlopen,
+ UnsafePointer: __bootstrap.ffi.UnsafePointer,
+ UnsafePointerView: __bootstrap.ffi.UnsafePointerView,
flock: __bootstrap.fs.flock,
flockSync: __bootstrap.fs.flockSync,
funlock: __bootstrap.fs.funlock,
diff --git a/runtime/permissions.rs b/runtime/permissions.rs
index 9a85e5e58..50c126f3f 100644
--- a/runtime/permissions.rs
+++ b/runtime/permissions.rs
@@ -1044,22 +1044,39 @@ impl UnaryPermission<FfiDescriptor> {
self.query(path)
}
- pub fn check(&mut self, path: &Path) -> Result<(), AnyError> {
- let (resolved_path, display_path) = resolved_and_display_path(path);
- let (result, prompted) = self.query(Some(&resolved_path)).check(
- self.name,
- Some(&format!("\"{}\"", display_path.display())),
- self.prompt,
- );
- if prompted {
- if result.is_ok() {
- self.granted_list.insert(FfiDescriptor(resolved_path));
- } else {
- self.denied_list.insert(FfiDescriptor(resolved_path));
- self.global_state = PermissionState::Denied;
+ pub fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError> {
+ if let Some(path) = path {
+ let (resolved_path, display_path) = resolved_and_display_path(path);
+ let (result, prompted) = self.query(Some(&resolved_path)).check(
+ self.name,
+ Some(&format!("\"{}\"", display_path.display())),
+ self.prompt,
+ );
+
+ if prompted {
+ if result.is_ok() {
+ self.granted_list.insert(FfiDescriptor(resolved_path));
+ } else {
+ self.denied_list.insert(FfiDescriptor(resolved_path));
+ self.global_state = PermissionState::Denied;
+ }
}
+
+ result
+ } else {
+ let (result, prompted) =
+ self.query(None).check(self.name, None, self.prompt);
+
+ if prompted {
+ if result.is_ok() {
+ self.global_state = PermissionState::Granted;
+ } else {
+ self.global_state = PermissionState::Denied;
+ }
+ }
+
+ result
}
- result
}
pub fn check_all(&mut self) -> Result<(), AnyError> {
@@ -1314,7 +1331,7 @@ impl deno_websocket::WebSocketPermissions for Permissions {
}
impl deno_ffi::FfiPermissions for Permissions {
- fn check(&mut self, path: &Path) -> Result<(), AnyError> {
+ fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError> {
self.ffi.check(path)
}
}
@@ -1740,7 +1757,7 @@ pub fn create_child_permissions(
.ffi
.granted_list
.iter()
- .all(|desc| main_perms.ffi.check(&desc.0).is_ok())
+ .all(|desc| main_perms.ffi.check(Some(&desc.0)).is_ok())
{
return Err(escalation_error());
}