Harden LinuxCNC wasm and native probe workflows

This commit is contained in:
cnc
2026-05-26 17:00:58 +08:00
parent 86734622d7
commit ce2f3f3769
98 changed files with 7384 additions and 877 deletions

View File

@@ -0,0 +1,50 @@
#include "pythonplugin/python_plugin.hh"
__attribute__((weak)) std::string handle_pyerror() {
return "python disabled in wasm-safe probe";
}
PythonPlugin *python_plugin = nullptr;
PythonPlugin *PythonPlugin::instantiate(struct _inittab *) {
static PythonPlugin plugin;
python_plugin = &plugin;
python_plugin->status = PLUGIN_OK;
return python_plugin;
}
int PythonPlugin::configure(const char *, const char *) {
status = PLUGIN_OK;
return status;
}
bool PythonPlugin::is_callable(const char *, const char *) {
return false;
}
int PythonPlugin::call(const char *,
const char *,
boost::python::object,
boost::python::object,
boost::python::object &retval) {
retval = boost::python::object();
status = PLUGIN_NO_CALLABLE;
return status;
}
int PythonPlugin::run_string(const char *, boost::python::object &retval, bool) {
retval = boost::python::object();
status = PLUGIN_OK;
return status;
}
int PythonPlugin::call_method(boost::python::object, boost::python::object &retval) {
retval = boost::python::object();
status = PLUGIN_OK;
return status;
}
int PythonPlugin::initialize() {
status = PLUGIN_OK;
return status;
}

View File

@@ -0,0 +1,60 @@
#pragma once
#include <string>
#include <vector>
#include <sys/types.h>
#include "boost/python/object.hpp"
extern std::string handle_pyerror();
enum pp_status {
PLUGIN_NO_SECTION = -1,
PLUGIN_NO_INIFILE = -2,
PLUGIN_BAD_INIFILE = -3,
PLUGIN_NO_TOPLEVEL = -4,
PLUGIN_BAD_PATH = -5,
PLUGIN_STAT_FAILED = -6,
PLUGIN_INITTAB_FAILED = -7,
PLUGIN_PYTHON_ALREADY_INITIALIZED = -8,
PLUGIN_EXCEPTION_DURING_PATH_PREPEND = -9,
PLUGIN_EXCEPTION_DURING_PATH_APPEND = -10,
PLUGIN_INIT_EXCEPTION = -11,
PLUGIN_PYTHON_NOT_INITIALIZED = -12,
PLUGIN_PATH_TOO_LONG = -13,
PLUGIN_OK = 0,
PLUGIN_NO_CALLABLE = 1,
PLUGIN_EXCEPTION = 2
};
class PythonPlugin {
public:
static PythonPlugin *instantiate(struct _inittab *inittab = nullptr);
int configure(const char *iniFilename = nullptr, const char *section = nullptr);
bool is_callable(const char *module, const char *funcname);
int call(const char *module,
const char *callable,
boost::python::object tupleargs,
boost::python::object kwargs,
boost::python::object &retval);
int run_string(const char *cmd, boost::python::object &retval, bool as_file = false);
int call_method(boost::python::object method, boost::python::object &retval);
int plugin_status() { return status; }
bool usable() { return status >= PLUGIN_OK; }
int initialize();
const std::string &last_exception() { return exception_msg; }
const std::string &last_errmsg() { return error_msg; }
boost::python::object main_namespace;
private:
PythonPlugin() = default;
int status = PLUGIN_OK;
std::string exception_msg;
std::string error_msg;
int log_level = 0;
};
extern PythonPlugin *python_plugin;

View File

@@ -0,0 +1,23 @@
#include "pythonplugin/python_plugin.hh"
int main() {
auto *plugin = PythonPlugin::instantiate(nullptr);
if (!plugin) {
return 1;
}
if (!plugin->usable()) {
return 2;
}
boost::python::object retval;
if (plugin->run_string("noop", retval, false) != PLUGIN_OK) {
return 3;
}
if (plugin->is_callable(nullptr, "noop")) {
return 4;
}
if (handle_pyerror().empty()) {
return 5;
}
return 0;
}