blueloveTH 3 недель назад
Родитель
Сommit
048df25e6f
2 измененных файлов с 28 добавлено и 0 удалено
  1. 3 0
      include/pocketpy/pocketpy.h
  2. 25 0
      include/pocketpy/sandbox.h

+ 3 - 0
include/pocketpy/pocketpy.h

@@ -8,6 +8,9 @@
 #include "pocketpy/export.h"
 #include "pocketpy/export.h"
 #include "pocketpy/vmath.h"
 #include "pocketpy/vmath.h"
 
 
+// for sandbox branch
+#include "pocketpy/sandbox.h"
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif

+ 25 - 0
include/pocketpy/sandbox.h

@@ -0,0 +1,25 @@
+#pragma once
+
+#include "pocketpy/export.h"
+#include <stdbool.h>
+
+// Fine-grained capabilities of the VM for sandboxing.
+typedef struct py_Capabilities {
+    // FileIO
+    bool (*file_open)(const char* path, const char* mode);
+    // os
+    bool (*os_chdir)(const char* path);
+    bool (*os_getcwd)();
+    bool (*os_system)(const char* command);
+    bool (*os_remove)(const char* path);
+    // stdc
+    bool stdc_write;    // memset, write_bytes, ...
+    bool stdc_read;     // memcmp, read_bytes, ...
+    bool stdc_malloc;   // malloc
+    bool stdc_free;     // free
+} py_Capabilities;
+
+/// Setup the capabilities for the current VM.
+PK_API py_Capabilities* py_capabilities();
+/// Raise a `KeyboardInterrupt` to interrupt the current execution.
+PK_API void py_interrupt();