From 0e731c9ee1ffbd59ba6241be7f310d04f50fc8e6 Mon Sep 17 00:00:00 2001 From: short <> Date: Sat, 2 Nov 2002 02:43:23 +0000 Subject: [PATCH] +respected proper function calling types cdecl/stdcall/fastcall --- NEWS | 8 +++- doc/FAQ | 32 ++++++++++++++++ src/libcaptive/client/init.c | 1 + src/libcaptive/halcaptive/intrlck.c | 4 +- src/libcaptive/halcaptive/irql.c | 2 +- src/libcaptive/halcaptive/spinlock.c | 8 ++-- src/libcaptive/include/captive/Makefile.am | 1 + src/libcaptive/include/captive/ldr.h | 20 ---------- src/libcaptive/include/captive/ldr_exports.h | 56 ++++++++++++++++++++++++++++ src/libcaptive/include/reactos/compat.h | 14 +++++++ src/libcaptive/ke/Makefile.am | 5 ++- src/libcaptive/ke/bug.c | 2 +- src/libcaptive/ke/event.c | 2 +- src/libcaptive/ke/exports.captivesym | 18 ++++----- src/libcaptive/ke/sem.c | 2 +- src/libcaptive/ke/spinlock.c | 2 +- src/libcaptive/mm/mminit.c | 2 +- src/libcaptive/mm/pool.c | 6 +-- src/libcaptive/mm/section.c | 2 +- 19 files changed, 139 insertions(+), 48 deletions(-) create mode 100644 src/libcaptive/include/captive/ldr_exports.h diff --git a/NEWS b/NEWS index adde8d4..fd76253 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,10 @@ -NEWS for captive-0.1 +NEWS for captive-0.2 +-------------------- + +* Implemented cdecl/stdcall/fastcall function calling types + + +NEWS for captive-0.1 (2002-10-31) -------------------- * Project build framework done diff --git a/doc/FAQ b/doc/FAQ index 05eb672..8cfd7e5 100644 --- a/doc/FAQ +++ b/doc/FAQ @@ -177,6 +177,38 @@ A: Depending on your demands you may be interested in one of: Acronis OS Selector: proprietary; $45 +Q: Do you differentiate cdecl/stdcall/fastcall functions? +A: W32 uses + three different types of function calls. + captive is completely compiled with the GNU standard function calls "cdecl" + - _even_ the functions from reactos source files with different design + function call type are all compiled as GNU standard "cdecl" ones and thus + the whole project uses one unified call type. There is always one 'relaying' + function generated inside libcaptive/ke/exports.c file named + functionname_calltype (such as functionname_fastcall etc.). + + Realying function are generated as:
+
cdecl
No relaying function generated, just a simple #define. + You won't see this function in the gdb backtrace. + We cannot generate it by C code as we do not know the number of its arguments. + We require the host OS GCC feature "__attribute__((__cdecl__))" + although it should be the default function call. +
+
stdcall
Relaying stub generated, all arguments passed. + We require the host OS GCC feature "__attribute__((__stdcall__))". +
+
fastcall
W32 puts first two arguments to ECX and EDX. + GCC puts the arguments in the order EAX, EDX, ECX, ... + Although GCC can change this order by "-mreg-alloc=REGS" commandline + option such option is not supported by stock GNU/Linux GCC compilers. + Therefore we pretend an unused first argument and swap the order of + second vs. third function argument to get the right parameter pass. + We require the host OS GCC feature "__attribute__((__regparm__(3)))". + We require the host OS GCC feature "__attribute__((__stdcall__))". +
+ 32-bit return value in EAX is always passed back although it may be vain. + Please see the documentation of "captivesym.pl" for more information. Eric Kohl, reactos developer: ..." and ReactOS cannot run on Linux!" diff --git a/src/libcaptive/client/init.c b/src/libcaptive/client/init.c index cc874fb..37e4f92 100644 --- a/src/libcaptive/client/init.c +++ b/src/libcaptive/client/init.c @@ -21,6 +21,7 @@ #include "captive/client.h" /* self */ #include "captive/ldr.h" +#include "captive/ldr_exports.h" #include "captive/unicode.h" #include "captive/file.h" #include diff --git a/src/libcaptive/halcaptive/intrlck.c b/src/libcaptive/halcaptive/intrlck.c index fadbbb8..1c17f0b 100644 --- a/src/libcaptive/halcaptive/intrlck.c +++ b/src/libcaptive/halcaptive/intrlck.c @@ -35,7 +35,7 @@ * a positive number if the @result > %0. * The returned number need not be equal to the result!!!! */ -LONG /* FASTCALL */ InterlockedIncrement(PLONG Addend) +LONG InterlockedIncrement(PLONG Addend) { /* TODO:thread; really? */ return ++*Addend; @@ -55,7 +55,7 @@ LONG /* FASTCALL */ InterlockedIncrement(PLONG Addend) * a positive number if the @result > %0. * The returned number need not be equal to the result!!!! */ -LONG /* FASTCALL */ InterlockedDecrement(PLONG Subend) +LONG InterlockedDecrement(PLONG Subend) { /* TODO:thread; really? */ return --*Subend; diff --git a/src/libcaptive/halcaptive/irql.c b/src/libcaptive/halcaptive/irql.c index d1955cd..a1da196 100644 --- a/src/libcaptive/halcaptive/irql.c +++ b/src/libcaptive/halcaptive/irql.c @@ -31,7 +31,7 @@ * * Returns: Current CPU IRQ level. libcaptive always returns %PASSIVE_LEVEL. */ -KIRQL STDCALL KeGetCurrentIrql(VOID) +KIRQL KeGetCurrentIrql(VOID) { /* TODO:thread */ /* reactos/hal/halx86/irql.c/CurrentIrql is initialized to HIGH_LEVEL */ diff --git a/src/libcaptive/halcaptive/spinlock.c b/src/libcaptive/halcaptive/spinlock.c index 5f50aff..afb204c 100644 --- a/src/libcaptive/halcaptive/spinlock.c +++ b/src/libcaptive/halcaptive/spinlock.c @@ -30,7 +30,7 @@ * Acquires a spinlock. Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. #GMutex would be needed otherwise. */ -VOID STDCALL KeAcquireSpinLock(PKSPIN_LOCK SpinLock,PKIRQL OldIrql) +VOID KeAcquireSpinLock(PKSPIN_LOCK SpinLock,PKIRQL OldIrql) { /* TODO:thread */ /* reactos/hal/halx86/irql.c/CurrentIrql is initialized to HIGH_LEVEL */ @@ -46,7 +46,7 @@ VOID STDCALL KeAcquireSpinLock(PKSPIN_LOCK SpinLock,PKIRQL OldIrql) * Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. #GMutex would be needed otherwise. */ -VOID STDCALL KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock) +VOID KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock) { /* TODO:thread */ } @@ -60,7 +60,7 @@ VOID STDCALL KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock) * Releases a spinlock. Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. #GMutex would be needed otherwise. */ -VOID STDCALL KeReleaseSpinLock(PKSPIN_LOCK SpinLock,KIRQL NewIrql) +VOID KeReleaseSpinLock(PKSPIN_LOCK SpinLock,KIRQL NewIrql) { /* TODO:thread */ } @@ -75,7 +75,7 @@ VOID STDCALL KeReleaseSpinLock(PKSPIN_LOCK SpinLock,KIRQL NewIrql) * Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. #GMutex would be needed otherwise. */ -VOID STDCALL KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock) +VOID KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock) { /* TODO:thread */ } diff --git a/src/libcaptive/include/captive/Makefile.am b/src/libcaptive/include/captive/Makefile.am index 5e09560..d5b5da7 100644 --- a/src/libcaptive/include/captive/Makefile.am +++ b/src/libcaptive/include/captive/Makefile.am @@ -23,6 +23,7 @@ pkginclude_HEADERS+= \ client.h \ file.h \ ldr.h \ + ldr_exports.h \ macros.h \ mm.h \ ps_reactos.h \ diff --git a/src/libcaptive/include/captive/ldr.h b/src/libcaptive/include/captive/ldr.h index 4405aba..ed612f2 100644 --- a/src/libcaptive/include/captive/ldr.h +++ b/src/libcaptive/include/captive/ldr.h @@ -29,28 +29,8 @@ G_BEGIN_DECLS -/** - * captive_kernel_exports: - * - * Export all libcaptive symbols to reactos. It is done by *.def files used - * by dlltool(1) of Mingw32 compiler suite. We use native host OS compiler and - * we also have just a limited set of functions over reactos itself. - * We use our captive_ModuleList_add_builtin() to simulate PE headers exporting - * our symbols; this export simulation is invocated from this function. - * - * This function is generated automatically from #exports.captivesym file - * by #captivesym.pl script. - * - * Multiple calls of this function are forbidden. - * - * Returns: %TRUE if the export was successful. - */ -gboolean captive_kernel_exports(void); - - NTSTATUS captive_LdrpLoadAndCallImage(PMODULE_OBJECT *ModuleObjectp,PUNICODE_STRING ModuleName, PDRIVER_OBJECT DriverEntry_DriverObject,PUNICODE_STRING DriverEntry_RegistryPath); -gboolean captive_ModuleList_add_builtin(const gchar *FullName_utf8,...); /* LdrLoadModule() declared in reactos includes */ /* reactos/ntoskrnl/ldr/loader.c file-scope global declaration: */ diff --git a/src/libcaptive/include/captive/ldr_exports.h b/src/libcaptive/include/captive/ldr_exports.h new file mode 100644 index 0000000..68b941f --- /dev/null +++ b/src/libcaptive/include/captive/ldr_exports.h @@ -0,0 +1,56 @@ +/* $Id$ + * Include file for reactos ldr/ (loader) to be used from ke/exports.c of libcaptive + * Copyright (C) 2002 Jan Kratochvil + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; exactly version 2 of June 1991 is required + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _CAPTIVE_LDR_EXPORTS_H +#define _CAPTIVE_LDR_EXPORTS_H 1 + + +#include +/* NEVER include any captive/reactos include file as we are included + * from libcaptive/ke/exports.c which conflicts on any export symbol declaration. + */ + + +G_BEGIN_DECLS + +/** + * captive_kernel_exports: + * + * Export all libcaptive symbols to reactos. It is done by *.def files used + * by dlltool(1) of Mingw32 compiler suite. We use native host OS compiler and + * we also have just a limited set of functions over reactos itself. + * We use our captive_ModuleList_add_builtin() to simulate PE headers exporting + * our symbols; this export simulation is invocated from this function. + * + * This function is generated automatically from #exports.captivesym file + * by #captivesym.pl script. + * + * Multiple calls of this function are forbidden. + * + * Returns: %TRUE if the export was successful. + */ +gboolean captive_kernel_exports(void); + + +gboolean captive_ModuleList_add_builtin(const gchar *FullName_utf8,...); + +G_END_DECLS + + +#endif /* _CAPTIVE_LDR_EXPORTS_H */ diff --git a/src/libcaptive/include/reactos/compat.h b/src/libcaptive/include/reactos/compat.h index 3b474b2..7c72caa 100644 --- a/src/libcaptive/include/reactos/compat.h +++ b/src/libcaptive/include/reactos/compat.h @@ -55,6 +55,20 @@ #undef FASTCALL #endif +/* It gets defined to __attribute__((stdcall)) by "base.h" and "ntos/types.h". */ +#ifdef REACTOS_COMPAT +#define STDCALL +#else +#undef STDCALL +#endif + +/* It gets defined to __attribute__((cdecl)) by "base.h" and "ntos/types.h"; should not hurt. */ +#ifdef REACTOS_COMPAT +#define CDECL +#else +#undef CDECL +#endif + #ifdef REACTOS_COMPAT #define wcscpy captive_reactos_wcscpy #else diff --git a/src/libcaptive/ke/Makefile.am b/src/libcaptive/ke/Makefile.am index 13cd99f..3443864 100644 --- a/src/libcaptive/ke/Makefile.am +++ b/src/libcaptive/ke/Makefile.am @@ -38,5 +38,6 @@ BUILT_SOURCES+=exports.c CLEANFILES+=exports.c libke_la_SOURCES+=exports.c -exports.c: exports.captivesym captivesym.pl - perl captivesym.pl $< >$@ +# FIXME: a difference between "ntoskrnl/ntoskrnl.def" vs. "ntoskrnl/ntoskrnl.edf"? +exports.c: exports.captivesym captivesym.pl $(top_srcdir)/reactos/ntoskrnl/ntoskrnl.def + perl captivesym.pl $(top_srcdir)/reactos/ntoskrnl/ntoskrnl.def $< >$@ diff --git a/src/libcaptive/ke/bug.c b/src/libcaptive/ke/bug.c index 1612704..a778118 100644 --- a/src/libcaptive/ke/bug.c +++ b/src/libcaptive/ke/bug.c @@ -29,7 +29,7 @@ * * Report fatal kernel bug. This call never returns. */ -VOID STDCALL KeBugCheck(ULONG BugCheckCode) +VOID KeBugCheck(ULONG BugCheckCode) { /* FIXME: Search for BugCheckCode's message text * by in RT_MESSAGETABLE as done by reactos/ntoskrnl/ke/bug.c/KeBugCheckEx() diff --git a/src/libcaptive/ke/event.c b/src/libcaptive/ke/event.c index 44f040c..1134b28 100644 --- a/src/libcaptive/ke/event.c +++ b/src/libcaptive/ke/event.c @@ -31,7 +31,7 @@ * Initalizes a kernel event. Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. */ -VOID STDCALL KeInitializeEvent(PKEVENT Event,EVENT_TYPE Type,BOOLEAN State) +VOID KeInitializeEvent(PKEVENT Event,EVENT_TYPE Type,BOOLEAN State) { /* TODO:thread */ } diff --git a/src/libcaptive/ke/exports.captivesym b/src/libcaptive/ke/exports.captivesym index e7279a6..84ceda7 100644 --- a/src/libcaptive/ke/exports.captivesym +++ b/src/libcaptive/ke/exports.captivesym @@ -44,16 +44,16 @@ ntoskrnl.exe IoDeleteDevice undef ntoskrnl.exe IoUnregisterFileSystem undef ntoskrnl.exe ExDeleteResourceLite undef ntoskrnl.exe IoFreeWorkItem undef -ntoskrnl.exe MmQuerySystemSize "reactos/ddk/mmfuncs.h" -ntoskrnl.exe IoAllocateWorkItem "reactos/ddk/iofuncs.h" -ntoskrnl.exe KeInitializeEvent "reactos/ddk/kefuncs.h" -ntoskrnl.exe ExInitializeResourceLite "reactos/ddk/exfuncs.h" +ntoskrnl.exe MmQuerySystemSize +ntoskrnl.exe IoAllocateWorkItem +ntoskrnl.exe KeInitializeEvent +ntoskrnl.exe ExInitializeResourceLite ntoskrnl.exe FsRtlCopyRead undef -ntoskrnl.exe ObfReferenceObject "reactos/ddk/obfuncs.h" -ntoskrnl.exe IoRegisterFileSystem "reactos/ddk/iofuncs.h" -ntoskrnl.exe IoRegisterShutdownNotification "reactos/ddk/iofuncs.h" -ntoskrnl.exe IoCreateDevice "reactos/ddk/iofuncs.h" -ntoskrnl.exe RtlInitUnicodeString "reactos/ddk/rtl.h" +ntoskrnl.exe ObfReferenceObject +ntoskrnl.exe IoRegisterFileSystem +ntoskrnl.exe IoRegisterShutdownNotification +ntoskrnl.exe IoCreateDevice +ntoskrnl.exe RtlInitUnicodeString ntoskrnl.exe FsRtlNotifyVolumeEvent undef ntoskrnl.exe IoRemoveShareAccess undef ntoskrnl.exe IoReleaseVpbSpinLock undef diff --git a/src/libcaptive/ke/sem.c b/src/libcaptive/ke/sem.c index a5e97db..63f3941 100644 --- a/src/libcaptive/ke/sem.c +++ b/src/libcaptive/ke/sem.c @@ -31,7 +31,7 @@ * Initalizes a semaphore. Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. */ -VOID STDCALL KeInitializeSemaphore(PKSEMAPHORE Semaphore,LONG Count,LONG Limit) +VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore,LONG Count,LONG Limit) { /* TODO:thread */ Semaphore->Limit=Limit; diff --git a/src/libcaptive/ke/spinlock.c b/src/libcaptive/ke/spinlock.c index aa403fd..7b943b4 100644 --- a/src/libcaptive/ke/spinlock.c +++ b/src/libcaptive/ke/spinlock.c @@ -29,7 +29,7 @@ * Initalizes a spinlock. Currently libcaptive doesn't use multithreading * and thus this function is a NOP now. #GMutex would be needed otherwise. */ -VOID STDCALL KeInitializeSpinLock(PKSPIN_LOCK SpinLock) +VOID KeInitializeSpinLock(PKSPIN_LOCK SpinLock) { /* TODO:thread */ } diff --git a/src/libcaptive/mm/mminit.c b/src/libcaptive/mm/mminit.c index 264f3d7..445db4f 100644 --- a/src/libcaptive/mm/mminit.c +++ b/src/libcaptive/mm/mminit.c @@ -34,7 +34,7 @@ * * Returns: %$(top_srcdir)/src/libcaptive/mm/mminit.c/CAPTIVE_SYSTEM_SIZE. */ -MM_SYSTEM_SIZE STDCALL MmQuerySystemSize(VOID) +MM_SYSTEM_SIZE MmQuerySystemSize(VOID) { return CAPTIVE_SYSTEM_SIZE; } diff --git a/src/libcaptive/mm/pool.c b/src/libcaptive/mm/pool.c index 53d7b7a..36224c8 100644 --- a/src/libcaptive/mm/pool.c +++ b/src/libcaptive/mm/pool.c @@ -41,7 +41,7 @@ * Returns: Memory block base if successfuly allocated. %NULL otherwise. * The allocated memory block is not cleared. */ -PVOID STDCALL ExAllocatePoolWithTag(ULONG PoolType,ULONG NumberOfBytes,ULONG Tag) +PVOID ExAllocatePoolWithTag(ULONG PoolType,ULONG NumberOfBytes,ULONG Tag) { if (!NumberOfBytes) return NULL; @@ -61,7 +61,7 @@ PVOID STDCALL ExAllocatePoolWithTag(ULONG PoolType,ULONG NumberOfBytes,ULONG Tag * Returns: Memory block base if successfuly allocated. %NULL otherwise. * The allocated memory block is not cleared. */ -PVOID STDCALL ExAllocatePool(POOL_TYPE PoolType,ULONG NumberOfBytes) +PVOID ExAllocatePool(POOL_TYPE PoolType,ULONG NumberOfBytes) { return ExAllocatePoolWithTag(PoolType,NumberOfBytes, 0); /* Tag; reactos uses TAG_NONE ('None') but it is not documented for W32 */ @@ -75,7 +75,7 @@ PVOID STDCALL ExAllocatePool(POOL_TYPE PoolType,ULONG NumberOfBytes) * allocated by a previous ExAllocatePool() or ExAllocatePoolWithTag() call. * You can no longer assume anything about this base address / memory block. */ -VOID STDCALL ExFreePool(IN PVOID Block) +VOID ExFreePool(IN PVOID Block) { g_return_if_fail(Block!=NULL); diff --git a/src/libcaptive/mm/section.c b/src/libcaptive/mm/section.c index 8b260a5..4d1916d 100644 --- a/src/libcaptive/mm/section.c +++ b/src/libcaptive/mm/section.c @@ -35,7 +35,7 @@ * * Returns: Allocated address space if the allocation was successful. */ -PVOID STDCALL MmAllocateSection(IN ULONG Length) +PVOID MmAllocateSection(IN ULONG Length) { int mmap_prot=captive_flProtect_to_mmap_prot(PAGE_READWRITE); PVOID r; -- 1.8.3.1