VirtualBox

Changeset 13 in kStuff


Ignore:
Timestamp:
Apr 20, 2008 10:13:43 AM (17 years ago)
Author:
bird
Message:

Made it (winapi wrapping) work.

Location:
trunk/kProfiler2
Files:
1 added
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/kProfiler2/Makefile.kmk

    r12 r13  
    106106kPrf2_SOURCES.win = \
    107107        dllmain-win.cpp \
     108        kPrf2WinApiWrapperHlp.c \
    108109        prf$(BUILD_TARGET_ARCH)msc.asm \
    109110        kPrf2-win-$(BUILD_TARGET_ARCH).def
     
    135136
    136137DLLS.win += kPrf2WinApiWrappers
    137 kPrf2WinApiWrappers_TEMPLATE = kStuffEXE
     138kPrf2WinApiWrappers_TEMPLATE = kPrf2
    138139kPrf2WinApiWrappers_CFLAGS = -GH -Gh
     140kPrf2WinApiWrappers_LDFLAGS.win.x86 = -Entry:DllMain@12
     141kPrf2WinApiWrappers_LDFLAGS.win.amd64 = -Entry:DllMain
    139142kPrf2WinApiWrappers_SOURCES = \
    140143        kPrf2WinApiWrappers.c \
     
    161164        $(APPEND) [email protected] 'PVOID RtlMoveMemory( PVOID pvDst, PVOID pvSrc, SIZE_T cb );'
    162165        $(APPEND) [email protected] 'VOID NTAPI RtlUnwind( PVOID TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue );'
    163 #       $(APPEND) [email protected] 'VOID NTAPI RtlUnwindEx( FRAME_POINTERS TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue, PCONTEXT ContextRecord, PUNWIND_HISTORY_TABLE HistoryTable );'
     166        $(APPEND) [email protected] 'VOID NTAPI RtlUnwindEx( FRAME_POINTERS TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue, PCONTEXT ContextRecord, PUNWIND_HISTORY_TABLE HistoryTable );'
     167        $(APPEND) [email protected] 'ULONGLONG WINAPI RtlVirtualUnwind( ULONG HandlerType, ULONGLONG ImageBase, ULONGLONG ControlPC, PRUNTIME_FUNCTION FunctionEntry, PCONTEXT ContextRecord, PBOOLEAN InFunction, PFRAME_POINTERS EstablisherFrame, PKNONVOLATILE_CONTEXT_POINTERS ContextPointers );'
     168        $(APPEND) [email protected] 'PVOID WINAPI RtlPcToFileHeader( PVOID PcValue, PVOID * BaseOfImage );'
     169        $(APPEND) [email protected] 'PVOID WINAPI RtlLookupFunctionEntry( ULONGLONG ControlPC, PULONGLONG ImageBase, PULONGLONG TargetGp );'
     170        $(APPEND) [email protected] 'void WINAPI RtlRaiseException(PEXCEPTION_RECORD pXcpRec);'
    164171        $(APPEND) [email protected] 'int WINAPI uaw_lstrcmpW( LPCUWSTR lpString1, LPCUWSTR lpString2 );'
    165172        $(APPEND) [email protected] 'int WINAPI uaw_lstrcmpiW( LPCUWSTR lpString1, LPCUWSTR lpString2 );'
  • trunk/kProfiler2/kPrf2-win-amd64.def

    r2 r13  
    3030    _pexit
    3131    KPrfInit
     32    kPrf2WrapResolve
    3233
    33 
  • trunk/kProfiler2/kPrf2-win-x86.def

    r2 r13  
    3030    _pexit
    3131    KPrfInit
    32 
     32    kPrf2WrapResolve
  • trunk/kProfiler2/kPrf2WinApi-dumpbin.sed

    r11 r13  
    5656s/[[:space:]][[:space:]]*/ /g
    5757/^$/b drop_line
     58
     59# Filter out APIs that hasn't been implemented.
     60/AddLocalAlternateComputerNameA/b drop_line
     61/AddLocalAlternateComputerNameW/b drop_line
     62/EnumerateLocalComputerNamesA/b drop_line
     63/EnumerateLocalComputerNamesW/b drop_line
     64/RemoveLocalAlternateComputerNameA/b drop_line
     65/RemoveLocalAlternateComputerNameW/b drop_line
     66/SetLocalPrimaryComputerNameA/b drop_line
     67/SetLocalPrimaryComputerNameW/b drop_line
     68/__C_specific_handler/b drop_line
     69/__misaligned_access/b drop_line
     70/_local_unwind/b drop_line
     71
    5872b end
    5973
  • trunk/kProfiler2/kPrf2WinApi-pre.sed

    r11 r13  
    1 # $Id:$
     1# $Id$
    22## @file
    33# This SED script will try normalize a windows header
  • trunk/kProfiler2/kPrf2WinApiWrapperHlp.c

    r12 r13  
    11/* $Id$ */
    22/** @file
    3  * Wrappers for a number of common Windows APIs.
     3 * Helpers for the Windows API wrapper DLL.
    44 */
    55
     
    2626*   Header Files                                                               *
    2727*******************************************************************************/
    28 #define _ADVAPI32_
    29 #define _KERNEL32_
    30 #define _WIN32_WINNT 0x0600
    31 #define UNICODE
    3228#include <Windows.h>
    33 #include <TLHelp32.h>
    34 #include <k/kDefs.h>
    35 
    36 #if K_ARCH == K_ARCH_X86_32
    37 typedef PVOID PRUNTIME_FUNCTION;
    38 typedef FARPROC PGET_RUNTIME_FUNCTION_CALLBACK;
    39 #endif
    40 
    41 /*******************************************************************************
    42 *   Structures and Typedefs                                                    *
    43 *******************************************************************************/
    44 typedef struct KPRF2WRAPDLL
    45 {
    46     HMODULE hmod;
    47     char szName[32];
    48 } KPRF2WRAPDLL;
    49 typedef KPRF2WRAPDLL *PKPRF2WRAPDLL;
    50 typedef KPRF2WRAPDLL const *PCKPRF2WRAPDLL;
    51 
    52 
    53 /* TODO (amd64):
    54 
    55 AddLocalAlternateComputerNameA
    56 AddLocalAlternateComputerNameW
    57 EnumerateLocalComputerNamesA
    58 EnumerateLocalComputerNamesW
    59 RemoveLocalAlternateComputerNameA
    60 RemoveLocalAlternateComputerNameW
    61 
    62 RtlLookupFunctionEntry
    63 RtlPcToFileHeader
    64 RtlRaiseException
    65 RtlVirtualUnwind
    66 
    67 SetConsoleCursor
    68 SetLocalPrimaryComputerNameA
    69 SetLocalPrimaryComputerNameW
    70 __C_specific_handler
    71 __misaligned_access
    72 _local_unwind
    73 */
    74 
    75 /*******************************************************************************
    76 *   Global Variables                                                           *
    77 *******************************************************************************/
    78 KPRF2WRAPDLL g_Kernel32 =
    79 {
    80     INVALID_HANDLE_VALUE, "KERNEL32"
    81 };
    82 
    83 
    84 /*******************************************************************************
    85 *   Internal Functions                                                         *
    86 *******************************************************************************/
    87 FARPROC kPrf2WrapResolve(void **ppfn, const char *pszName, PKPRF2WRAPDLL pDll);
     29#include "kPRf2WinApiWRapperHlp.h"
    8830
    8931
     
    10446
    10547
    106 #include "kPrf2WinApiWrappers-kernel32.h"
  • trunk/kProfiler2/kPrf2WinApiWrappers-kernel32.h

    r11 r13  
    91889188}
    91899189
     9190typedef VOID NTAPI FN_RtlUnwindEx( FRAME_POINTERS TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue, PCONTEXT ContextRecord, PUNWIND_HISTORY_TABLE HistoryTable );
     9191__declspec(dllexport) VOID NTAPI kPrf2Wrap_RtlUnwindEx( FRAME_POINTERS TargetFrame, PVOID TargetIp, PEXCEPTION_RECORD ExceptionRecord, PVOID ReturnValue, PCONTEXT ContextRecord, PUNWIND_HISTORY_TABLE HistoryTable )
     9192{
     9193    static FN_RtlUnwindEx *pfn = 0;
     9194    if (!pfn)
     9195        kPrf2WrapResolve((void **)&pfn, "RtlUnwindEx", &g_Kernel32);
     9196    pfn( TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable );
     9197}
     9198
     9199typedef ULONGLONG WINAPI FN_RtlVirtualUnwind( ULONG HandlerType, ULONGLONG ImageBase, ULONGLONG ControlPC, PRUNTIME_FUNCTION FunctionEntry, PCONTEXT ContextRecord, PBOOLEAN InFunction, PFRAME_POINTERS EstablisherFrame, PKNONVOLATILE_CONTEXT_POINTERS ContextPointers );
     9200__declspec(dllexport) ULONGLONG WINAPI kPrf2Wrap_RtlVirtualUnwind( ULONG HandlerType, ULONGLONG ImageBase, ULONGLONG ControlPC, PRUNTIME_FUNCTION FunctionEntry, PCONTEXT ContextRecord, PBOOLEAN InFunction, PFRAME_POINTERS EstablisherFrame, PKNONVOLATILE_CONTEXT_POINTERS ContextPointers )
     9201{
     9202    static FN_RtlVirtualUnwind *pfn = 0;
     9203    if (!pfn)
     9204        kPrf2WrapResolve((void **)&pfn, "RtlVirtualUnwind", &g_Kernel32);
     9205    return pfn( HandlerType, ImageBase, ControlPC, FunctionEntry, ContextRecord, InFunction, EstablisherFrame, ContextPointers );
     9206}
     9207
     9208typedef PVOID WINAPI FN_RtlPcToFileHeader( PVOID PcValue, PVOID * BaseOfImage );
     9209__declspec(dllexport) PVOID WINAPI kPrf2Wrap_RtlPcToFileHeader( PVOID PcValue, PVOID * BaseOfImage )
     9210{
     9211    static FN_RtlPcToFileHeader *pfn = 0;
     9212    if (!pfn)
     9213        kPrf2WrapResolve((void **)&pfn, "RtlPcToFileHeader", &g_Kernel32);
     9214    return pfn( PcValue, BaseOfImage );
     9215}
     9216
     9217typedef PVOID WINAPI FN_RtlLookupFunctionEntry( ULONGLONG ControlPC, PULONGLONG ImageBase, PULONGLONG TargetGp );
     9218__declspec(dllexport) PVOID WINAPI kPrf2Wrap_RtlLookupFunctionEntry( ULONGLONG ControlPC, PULONGLONG ImageBase, PULONGLONG TargetGp )
     9219{
     9220    static FN_RtlLookupFunctionEntry *pfn = 0;
     9221    if (!pfn)
     9222        kPrf2WrapResolve((void **)&pfn, "RtlLookupFunctionEntry", &g_Kernel32);
     9223    return pfn( ControlPC, ImageBase, TargetGp );
     9224}
     9225
     9226typedef void WINAPI FN_RtlRaiseException(PEXCEPTION_RECORD pXcpRec);
     9227__declspec(dllexport) void WINAPI kPrf2Wrap_RtlRaiseException(PEXCEPTION_RECORD pXcpRec)
     9228{
     9229    static FN_RtlRaiseException *pfn = 0;
     9230    if (!pfn)
     9231        kPrf2WrapResolve((void **)&pfn, "RtlRaiseException", &g_Kernel32);
     9232    pfn( pXcpRec);
     9233}
     9234
    91909235typedef int WINAPI FN_uaw_lstrcmpW( LPCUWSTR lpString1, LPCUWSTR lpString2 );
    91919236__declspec(dllexport) int WINAPI kPrf2Wrap_uaw_lstrcmpW( LPCUWSTR lpString1, LPCUWSTR lpString2 )
  • trunk/kProfiler2/kPrf2WinApiWrappers.c

    r12 r13  
    3333#include <TLHelp32.h>
    3434#include <k/kDefs.h>
     35#include "kPrf2WinApiWrapperHlp.h"
    3536
    3637#if K_ARCH == K_ARCH_X86_32
     
    3940#endif
    4041
     42/* RtlUnwindEx is used by msvcrt on amd64, but winnt.h only defines it for IA64... */
     43typedef struct _FRAME_POINTERS {
     44    ULONGLONG MemoryStackFp;
     45    ULONGLONG BackingStoreFp;
     46} FRAME_POINTERS, *PFRAME_POINTERS;
     47typedef PVOID PUNWIND_HISTORY_TABLE;
     48typedef PVOID PKNONVOLATILE_CONTEXT_POINTERS;
     49
     50
    4151/*******************************************************************************
    42 *   Structures and Typedefs                                                    *
     52*   Global Variables                                                           *
    4353*******************************************************************************/
    44 typedef struct KPRF2WRAPDLL
     54KPRF2WRAPDLL g_Kernel32 =
    4555{
    46     HMODULE hmod;
    47     char szName[32];
    48 } KPRF2WRAPDLL;
    49 typedef KPRF2WRAPDLL *PKPRF2WRAPDLL;
    50 typedef KPRF2WRAPDLL const *PCKPRF2WRAPDLL;
     56    INVALID_HANDLE_VALUE, "KERNEL32"
     57};
    5158
     59
     60/*
     61 * Include the generated code.
     62 */
     63#include "kPrf2WinApiWrappers-kernel32.h"
    5264
    5365/* TODO (amd64):
     
    7183__misaligned_access
    7284_local_unwind
     85
    7386*/
    7487
    75 /*******************************************************************************
    76 *   Global Variables                                                           *
    77 *******************************************************************************/
    78 KPRF2WRAPDLL g_Kernel32 =
     88
     89/**
     90 * The DLL Main for the Windows API wrapper DLL.
     91 *
     92 * @returns Success indicator.
     93 * @param   hInstDll        The instance handle of the DLL. (i.e. the module handle)
     94 * @param   fdwReason       The reason why we're here. This is a 'flag' for reasons of
     95 *                          tradition, it's really a kind of enum.
     96 * @param   pReserved       Reserved / undocumented something.
     97 */
     98BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, PVOID pReserved)
    7999{
    80     INVALID_HANDLE_VALUE, "KERNEL32"
    81 };
     100    switch (fdwReason)
     101    {
     102        case DLL_PROCESS_ATTACH:
     103            break;
    82104
     105        case DLL_PROCESS_DETACH:
     106            break;
    83107
    84 /*******************************************************************************
    85 *   Internal Functions                                                         *
    86 *******************************************************************************/
    87 FARPROC kPrf2WrapResolve(void **ppfn, const char *pszName, PKPRF2WRAPDLL pDll);
     108        case DLL_THREAD_ATTACH:
     109            break;
    88110
    89 
    90 FARPROC kPrf2WrapResolve(void **ppfn, const char *pszName, PKPRF2WRAPDLL pDll)
    91 {
    92     FARPROC pfn;
    93     HMODULE hmod = pDll->hmod;
    94     if (hmod == INVALID_HANDLE_VALUE)
    95     {
    96         hmod = LoadLibraryA(pDll->szName);
    97         pDll->hmod = hmod;
     111        case DLL_THREAD_DETACH:
     112            break;
    98113    }
    99114
    100     pfn = GetProcAddress(hmod, pszName);
    101     *ppfn = (void *)pfn;
    102     return pfn;
     115    return TRUE;
    103116}
    104117
    105 
    106 #include "kPrf2WinApiWrappers-kernel32.h"
  • trunk/kProfiler2/kPrf2WinApiWrappersImp-amd64.def

    r11 r13  
    66  AddConsoleAliasA=kPrf2Wrap_AddConsoleAliasA
    77  AddConsoleAliasW=kPrf2Wrap_AddConsoleAliasW
    8   AddLocalAlternateComputerNameA=kPrf2Wrap_AddLocalAlternateComputerNameA
    9   AddLocalAlternateComputerNameW=kPrf2Wrap_AddLocalAlternateComputerNameW
    108  AddRefActCtx=kPrf2Wrap_AddRefActCtx
    119  AddVectoredContinueHandler=kPrf2Wrap_AddVectoredContinueHandler
     
    156154  EnumUILanguagesA=kPrf2Wrap_EnumUILanguagesA
    157155  EnumUILanguagesW=kPrf2Wrap_EnumUILanguagesW
    158   EnumerateLocalComputerNamesA=kPrf2Wrap_EnumerateLocalComputerNamesA
    159   EnumerateLocalComputerNamesW=kPrf2Wrap_EnumerateLocalComputerNamesW
    160156  EraseTape=kPrf2Wrap_EraseTape
    161157  EscapeCommFunction=kPrf2Wrap_EscapeCommFunction
     
    616612  RemoveDirectoryA=kPrf2Wrap_RemoveDirectoryA
    617613  RemoveDirectoryW=kPrf2Wrap_RemoveDirectoryW
    618   RemoveLocalAlternateComputerNameA=kPrf2Wrap_RemoveLocalAlternateComputerNameA
    619   RemoveLocalAlternateComputerNameW=kPrf2Wrap_RemoveLocalAlternateComputerNameW
    620614  RemoveVectoredContinueHandler=kPrf2Wrap_RemoveVectoredContinueHandler
    621615  RemoveVectoredExceptionHandler=kPrf2Wrap_RemoveVectoredExceptionHandler
     
    703697  SetInformationJobObject=kPrf2Wrap_SetInformationJobObject
    704698  SetLastError=kPrf2Wrap_SetLastError
    705   SetLocalPrimaryComputerNameA=kPrf2Wrap_SetLocalPrimaryComputerNameA
    706   SetLocalPrimaryComputerNameW=kPrf2Wrap_SetLocalPrimaryComputerNameW
    707699  SetLocalTime=kPrf2Wrap_SetLocalTime
    708700  SetLocaleInfoA=kPrf2Wrap_SetLocaleInfoA
     
    827819  WriteTapemark=kPrf2Wrap_WriteTapemark
    828820  ZombifyActCtx=kPrf2Wrap_ZombifyActCtx
    829   __C_specific_handler=kPrf2Wrap___C_specific_handler
    830   __misaligned_access=kPrf2Wrap___misaligned_access
    831821  _hread=kPrf2Wrap__hread
    832822  _hwrite=kPrf2Wrap__hwrite
     
    834824  _lcreat=kPrf2Wrap__lcreat
    835825  _llseek=kPrf2Wrap__llseek
    836   _local_unwind=kPrf2Wrap__local_unwind
    837826  _lopen=kPrf2Wrap__lopen
    838827  _lread=kPrf2Wrap__lread
  • trunk/kProfiler2/kPrf2WinApiWrappersImp-x86.def

    r12 r13  
    1111_AddConsoleAliasW@12
    1212_AddConsoleAliasW@12
    13 _AddLocalAlternateComputerNameA@8
    14 _AddLocalAlternateComputerNameA@8
    15 _AddLocalAlternateComputerNameW@8
    16 _AddLocalAlternateComputerNameW@8
    1713_AddRefActCtx@4
    1814_AddRefActCtx@4
     
    311307_EnumUILanguagesW@12
    312308_EnumUILanguagesW@12
    313 _EnumerateLocalComputerNamesA@16
    314 _EnumerateLocalComputerNamesA@16
    315 _EnumerateLocalComputerNamesW@16
    316 _EnumerateLocalComputerNamesW@16
    317309_EraseTape@12
    318310_EraseTape@12
     
    12431235_RemoveDirectoryW@4
    12441236_RemoveDirectoryW@4
    1245 _RemoveLocalAlternateComputerNameA@8
    1246 _RemoveLocalAlternateComputerNameA@8
    1247 _RemoveLocalAlternateComputerNameW@8
    1248 _RemoveLocalAlternateComputerNameW@8
    12491237_RemoveVectoredContinueHandler@4
    12501238_RemoveVectoredContinueHandler@4
     
    13971385_SetLastError@4
    13981386_SetLastError@4
    1399 _SetLocalPrimaryComputerNameA@8
    1400 _SetLocalPrimaryComputerNameA@8
    1401 _SetLocalPrimaryComputerNameW@8
    1402 _SetLocalPrimaryComputerNameW@8
    14031387_SetLocalTime@4
    14041388_SetLocalTime@4
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette