From 8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 27 Dec 2025 03:05:05 +0000 Subject: Do away with memcpy/memset/memcmp Now everything is either explicitly a rep thing, or explicitly some other small run of reasonably efficient instructions. No library calls or function call overhead of any kind. Code size remains nice and small. Ban a few other bad libc functions while we're at it. More can be added later if we decide that's a useful idea. This will require some discipline and workarounds to cope with Clang's tendency to shove mem* calls in places you don't want them even when you tell it not to. Well, c'est la vie. I'm a little nervous that the __builtin_memmove() usage in shuntvars() could still one day emit actual library calls. It appears we're not importing memmove() from anywhere at the moment, though. So I guess it's good enough for now. Also I had to get rid of alloca() in con_.c but that was kind of bad anyway, so that's fine. --- src/l4daddon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/l4daddon.c') diff --git a/src/l4daddon.c b/src/l4daddon.c index 79c5e72..800232b 100644 --- a/src/l4daddon.c +++ b/src/l4daddon.c @@ -121,8 +121,8 @@ static void hookdest_FS_MAFAS(bool disallowaddons, char *mission, !strncmp(gamemode, last_gamemode, gamemodelen + 1); } last_disallowaddons = disallowaddons; - memcpy(last_mission, mission, missionlen + 1); - memcpy(last_gamemode, gamemode, gamemodelen + 1); + mem_copy(last_mission, mission, missionlen + 1); + mem_copy(last_gamemode, gamemode, gamemodelen + 1); if_hot (canskip) return; } else { @@ -198,8 +198,8 @@ static inline void try_fix_broken_addon_check(uchar *insns) { // mprot too just so there's no page boundary issues if_hot (os_mprot(p, 13, PAGE_EXECUTE_READWRITE)) { broken_addon_check = p; // conditional so END doesn't crash! - memcpy(orig_broken_addon_check_bytes, broken_addon_check, 13); - memcpy(broken_addon_check, nops, noplen); + mem_copy(orig_broken_addon_check_bytes, broken_addon_check, 13); + mem_copy(broken_addon_check, nops, noplen); } else { errmsg_warnsys("couldn't fix broken addon check: " @@ -243,7 +243,7 @@ END { unhook_FS_MAFAS(); if_cold (sst_userunloaded) { if (broken_addon_check) { - memcpy(broken_addon_check, orig_broken_addon_check_bytes, 13); + mem_copy(broken_addon_check, orig_broken_addon_check_bytes, 13); } } } -- cgit v1.2.3-54-g00ecf