Files
luanti/src/script/scripting_sscsm.cpp
T
DS ab3994b03b Create SSCSM skeleton and scripting (#15818)
Contents:

* Adds a SSCSM controller and environment skeleton
* SSCSMs run in a separate thread, not yet in a separate process.
  API calls will later happen as IPC calls, this is already part of the software architecture.
* Adds a scripting env for SSCSM
  * It's not yet populated with luanti API functions 
  * Should include only safe functions
  * Clock precision (`core.get_us_time()` and `os.clock()`) is limited to 20 us.
    20 us was the value, firefox used as first response to the spectre attacks.
    now it's 100 us or 5 us, depending on whether it's "cross-origin isolated".
    we only have one origin, so choosing 20 us is probably fine, I guess
    see also:
    https://www.mozilla.org/en-US/security/advisories/mfsa2018-01/
    https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#security_requirements
  * other clocks:
    * os.time() and os.date() only have seconds precision, AFAIK.
    * dtime is only given once per step, so it's not useful
    * there might be other ways to build clocks (if we get async envs for sscsm,
      with a busy loop, for example)
  * `tostring` is *not* overridden.
    `tostring({})` and `string.format("%s", {})` give you pointers.
    (see lj_strfmt_obj)
    this is not very critical, but attacks could be made harder if we change this.
    the effort of overwriting is not worth it I think right now
* Includes a `sscsm_security.md`, read it
* Adds a non-binary setting `enable_sscsm`
* Maybe some more tiny stuff. See PR and diffs.

---------

Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
2026-01-27 15:52:21 +01:00

38 lines
823 B
C++

// SPDX-FileCopyrightText: 2025 Luanti authors
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "scripting_sscsm.h"
#include "cpp_api/s_internal.h"
#include "lua_api/l_sscsm.h"
#include "lua_api/l_util.h"
#include "lua_api/l_client.h"
SSCSMScripting::SSCSMScripting(SSCSMEnvironment *env) :
ScriptApiBase(ScriptingType::SSCSM)
{
setSSCSMEnv(env);
SCRIPTAPI_PRECHECKHEADER
initializeSecuritySSCSM();
lua_getglobal(L, "core");
int top = lua_gettop(L);
// Initialize our lua_api modules
initializeModApi(L, top);
lua_pop(L, 1);
// Push builtin initialization type
lua_pushstring(L, "sscsm");
lua_setglobal(L, "INIT");
}
void SSCSMScripting::initializeModApi(lua_State *L, int top)
{
ModApiUtil::InitializeSSCSM(L, top);
ModApiClient::InitializeSSCSM(L, top);
ModApiSSCSM::Initialize(L, top);
}