+respected proper function calling types cdecl/stdcall/fastcall
authorshort <>
Sat, 2 Nov 2002 02:43:23 +0000 (02:43 +0000)
committershort <>
Sat, 2 Nov 2002 02:43:23 +0000 (02:43 +0000)
19 files changed:
NEWS
doc/FAQ
src/libcaptive/client/init.c
src/libcaptive/halcaptive/intrlck.c
src/libcaptive/halcaptive/irql.c
src/libcaptive/halcaptive/spinlock.c
src/libcaptive/include/captive/Makefile.am
src/libcaptive/include/captive/ldr.h
src/libcaptive/include/captive/ldr_exports.h [new file with mode: 0644]
src/libcaptive/include/reactos/compat.h
src/libcaptive/ke/Makefile.am
src/libcaptive/ke/bug.c
src/libcaptive/ke/event.c
src/libcaptive/ke/exports.captivesym
src/libcaptive/ke/sem.c
src/libcaptive/ke/spinlock.c
src/libcaptive/mm/mminit.c
src/libcaptive/mm/pool.c
src/libcaptive/mm/section.c

diff --git a/NEWS b/NEWS
index adde8d4..fd76253 100644 (file)
--- 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 (file)
--- a/doc/FAQ
+++ b/doc/FAQ
@@ -177,6 +177,38 @@ A: Depending on your demands you may be interested in one of:
    <a href="http://www.acronis.com/products/osselector/">Acronis OS Selector</a>:
        proprietary; $45
 
+Q: Do you differentiate cdecl/stdcall/fastcall functions?
+A: W32 uses
+   <a href="http://msdn.microsoft.com/library/en-us/vclang/html/_core_argument_passing_and_naming_conventions.asp"
+   >three different types of function calls</a>.
+   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:<dl>
+   <dt>cdecl</dt><dd>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.
+       </dd>
+   <dt>stdcall</dt><dd>Relaying stub generated, all arguments passed.
+       We require the host OS GCC feature "__attribute__((__stdcall__))".
+       </dd>
+   <dt>fastcall</dt><dd>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__))".
+   </dl>
+   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!"
index cc874fb..37e4f92 100644 (file)
@@ -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 <glib/gtypes.h>
index fadbbb8..1c17f0b 100644 (file)
@@ -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;
index d1955cd..a1da196 100644 (file)
@@ -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 */
index 5f50aff..afb204c 100644 (file)
@@ -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 */
 }
index 5e09560..d5b5da7 100644 (file)
@@ -23,6 +23,7 @@ pkginclude_HEADERS+= \
                client.h \
                file.h \
                ldr.h \
+               ldr_exports.h \
                macros.h \
                mm.h \
                ps_reactos.h \
index 4405aba..ed612f2 100644 (file)
 
 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 (file)
index 0000000..68b941f
--- /dev/null
@@ -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 <project-captive@jankratochvil.net>
+ * 
+ * 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 <glib/gtypes.h>
+/* 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 */
index 3b474b2..7c72caa 100644 (file)
 #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
index 13cd99f..3443864 100644 (file)
@@ -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 $< >$@
index 1612704..a778118 100644 (file)
@@ -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()
index 44f040c..1134b28 100644 (file)
@@ -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 */
 }
index e7279a6..84ceda7 100644 (file)
@@ -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
index a5e97db..63f3941 100644 (file)
@@ -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;
index aa403fd..7b943b4 100644 (file)
@@ -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 */
 }
index 264f3d7..445db4f 100644 (file)
@@ -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;
 }
index 53d7b7a..36224c8 100644 (file)
@@ -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);
 
index 8b260a5..4d1916d 100644 (file)
@@ -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;