Fix `is_x86_64` on Linux 32-bit x86-64 server

This commit is contained in:
William Venner 2021-09-18 13:41:58 +01:00
parent c7f08b5c7a
commit 761b2b050a
4 changed files with 10 additions and 8 deletions

2
Cargo.lock generated
View File

@ -68,7 +68,7 @@ dependencies = [
[[package]] [[package]]
name = "gmod" name = "gmod"
version = "0.1.2" version = "0.1.3"
dependencies = [ dependencies = [
"cstr", "cstr",
"ctor", "ctor",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "gmod" name = "gmod"
version = "0.1.2" version = "0.1.3"
authors = ["William Venner <william@venner.io>"] authors = ["William Venner <william@venner.io>"]
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"

View File

@ -18,9 +18,15 @@ pub mod hax;
/// Returns whether this client is running the x86-64 branch /// Returns whether this client is running the x86-64 branch
/// ///
/// Current implementation checks the LuaJIT version exported by lua_shared /// Current implementation checks the contents of the bin/ directory, so this is a blocking operation and requires syscalls, use sparingly
pub fn is_x86_64() -> bool { pub fn is_x86_64() -> bool {
lua::LUA_SHARED.x86_64 use std::path::PathBuf;
#[cfg(target_os = "linux")] {
PathBuf::from("bin/linux64").is_dir()
}
#[cfg(target_os = "windows")] {
PathBuf::from("bin/win64").is_dir()
}
} }
/// Opens & returns a shared library loaded by Garry's Mod using the raw path to the module. /// Opens & returns a shared library loaded by Garry's Mod using the raw path to the module.

View File

@ -73,8 +73,6 @@ lazy_static::lazy_static! {
} }
pub(crate) struct LuaShared { pub(crate) struct LuaShared {
pub x86_64: bool,
pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>, pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>,
pub lual_loadstring: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>, pub lual_loadstring: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>,
pub lua_getfield: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32, k: LuaString)>, pub lua_getfield: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32, k: LuaString)>,
@ -134,8 +132,6 @@ impl LuaShared {
} }
Self { Self {
x86_64: library.get::<unsafe extern "C-unwind" fn()>(b"luaJIT_version_2_1_0_beta3\0").is_ok(),
lual_loadfile: find_symbol!("luaL_loadfile"), lual_loadfile: find_symbol!("luaL_loadfile"),
lual_loadstring: find_symbol!("luaL_loadstring"), lual_loadstring: find_symbol!("luaL_loadstring"),
lua_getfield: find_symbol!("lua_getfield"), lua_getfield: find_symbol!("lua_getfield"),