Skip to content

Commit

Permalink
build: Redirect mem{cpy,move,cmp,set} to NTDLL
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Dec 9, 2024
1 parent 3addad8 commit cdfcd52
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
6 changes: 3 additions & 3 deletions mcfgthread/gthr_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ do_gthr_get_thread_record(_MCF_thread* thrd)

/* Check the GUID. As user-defined data are aligned to 16-byte boundaries,
* there must be at least 16 bytes available. */
if(__builtin_memcmp(rec->__magic_guid, &__MCF_crt_gthread_guid, 16) != 0)
if(!__MCF_mequal(rec->__magic_guid, &__MCF_crt_gthread_guid, 16))
return __MCF_nullptr;

/* Assume so. `do_gthr_thread_thunk_v3()` is not shared across modules,
Expand All @@ -331,8 +331,8 @@ __MCF_DLLEXPORT
_MCF_thread*
__MCF_gthr_thread_create_v3(__MCF_gthr_thread_procedure* proc, void* arg)
{
__MCF_ALIGNED(16) __MCF_gthr_thread_record record;
__builtin_memcpy(record.__magic_guid, &__MCF_crt_gthread_guid, 16);
__MCF_gthr_thread_record record;
__MCF_mcopy(record.__magic_guid, &__MCF_crt_gthread_guid, 16);
record.__proc = proc;
record.__arg_or_result = arg;
return _MCF_thread_new(do_gthr_thread_thunk_v3, &record, sizeof(record));
Expand Down
12 changes: 12 additions & 0 deletions mcfgthread/mcfgthread.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; This file is part of MCF Gthread.
;; Copyright (C) 2022-2024 LH_Mouse. All wrongs reserved.
;;
;; MCF Gthread is free software. Licensing information is included in
;; LICENSE.TXT as a whole. The GCC Runtime Library Exception applies
;; to this file.

EXPORTS
memcpy = ntdll.memcpy
memmove = ntdll.memmove
memcmp = ntdll.memcmp
memset = ntdll.memset
50 changes: 0 additions & 50 deletions mcfgthread/xglobals.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,56 +349,6 @@ DllMainCRTStartup(PVOID instance, ULONG reason, PVOID reserved)
}
}

# if defined _MSC_VER
__pragma(comment(linker, "/export:" __MCF_USYM "memcpy,DATA"))
# else
__attribute__((__dllexport__))
# endif
void*
__cdecl
memcpy(void* dst, const void* src, size_t size)
{
return __MCF_mcopy(dst, src, size);
}

# if defined _MSC_VER
__pragma(comment(linker, "/export:" __MCF_USYM "memmove,DATA"))
# else
__attribute__((__dllexport__))
# endif
void*
__cdecl
memmove(void* dst, const void* src, size_t size)
{
return ((uintptr_t) dst - (uintptr_t) src >= size)
? __MCF_mcopy(dst, src, size)
: __MCF_mcopy_backward(dst, src, size);
}

# if defined _MSC_VER
__pragma(comment(linker, "/export:" __MCF_USYM "memcmp,DATA"))
# else
__attribute__((__dllexport__))
# endif
int
__cdecl
memcmp(const void* src, const void* cmp, size_t size)
{
return __MCF_mcompare(src, cmp, size);
}

# if defined _MSC_VER
__pragma(comment(linker, "/export:" __MCF_USYM "memset,DATA"))
# else
__attribute__((__dllexport__))
# endif
void*
__cdecl
memset(void* dst, int val, size_t size)
{
return __MCF_mfill(dst, val, size);
}

# if defined __i386__
extern const PVOID __safe_se_handler_table[];
extern const ULONG __safe_se_handler_count;
Expand Down
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ lib_mcfgthread_minimal_dll = shared_library('mcfgthread-minimal',
link_args: lib_mcfgthread_dll_link_args,
sources: [ mcfgthread_src_min, mcfgthread_version_o ],
dependencies: [ dep_kernel32, dep_ntdll ],
vs_module_defs: 'mcfgthread/mcfgthread.def',
name_prefix: 'lib',
soversion: ver.get('abi_major'),
version: '.'.join([ ver.get('abi_major'), ver.get('abi_minor'), '0' ]),
Expand All @@ -207,9 +208,10 @@ lib_mcfgthread_dll = shared_library('mcfgthread',
c_pch: 'mcfgthread/xprecompiled.h',
c_args: [ '-fasynchronous-unwind-tables', '-ffreestanding', '-D__MCF_IN_DLL' ],
link_args: lib_mcfgthread_dll_link_args,
objects: lib_mcfgthread_minimal_dll.extract_objects(mcfgthread_src_min),
sources: [ mcfgthread_src_ex, mcfgthread_version_o ],
objects: [ lib_mcfgthread_minimal_dll.extract_objects(mcfgthread_src_min) ],
dependencies: [ dep_kernel32, dep_ntdll ],
vs_module_defs: 'mcfgthread/mcfgthread.def',
name_prefix: 'lib',
soversion: ver.get('abi_major'),
version: '.'.join([ ver.get('abi_major'), ver.get('abi_minor'), '0' ]),
Expand Down

0 comments on commit cdfcd52

Please sign in to comment.