Changeset 801 in dev


Ignore:
Timestamp:
Feb 6, 2011, 9:47:29 PM (14 years ago)
Author:
イグトランス (egtra)
Message:

コンパイラにXP以前対応用のコードを適用

Location:
branches/egtra/ab5.0/abdev
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/egtra/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp

    r798 r801  
    590590
    591591    // グローバルローケルを日本語にする
    592     std::locale::global(std::locale("japanese"));
    593     _setmode(_fileno(stdout), _O_BINARY);
     592    //std::locale::global(std::locale("japanese"));
     593    //_setmode(_fileno(stdout), _O_BINARY);
    594594
    595595    //_Test();
  • branches/egtra/ab5.0/abdev/OldWindowsHelper.asm

    r800 r801  
    2020    ImportTrap InterlockedPopEntrySList, 4
    2121    ImportTrap InterlockedCompareExchange, 12
     22    ImportTrap GetModuleHandleW, 4
     23    ImportTrap GetStartupInfoW, 4
     24    ImportTrap GetEnvironmentStringsW, 0
     25    ImportTrap FreeEnvironmentStringsW, 4
    2226    TrapTableLast LABEL DWORD
    2327
  • branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp

    r800 r801  
    11#include "stdafx.h"
    22#include <cstdint>
     3#include <cstring>
    34#include <process.h>
    45#include "OSVersion.h"
     
    1617    extern FARPROC alias__imp__InterlockedPushEntrySList;
    1718    extern FARPROC alias__imp__InterlockedPopEntrySList;
     19    extern FARPROC alias__imp__GetModuleHandleW;
     20    extern FARPROC alias__imp__GetStartupInfoW;
     21    extern FARPROC alias__imp__GetEnvironmentStringsW;
     22    extern FARPROC alias__imp__FreeEnvironmentStringsW;
    1823    extern void* TrapTableLast;
    1924} // extern "C"
     
    2631    if (hmodKernel == nullptr)
    2732    {
    28         hmodKernel = GetModuleHandle(TEXT("kernel32"));
     33        hmodKernel = GetModuleHandleA("kernel32");
    2934    }
    3035    return hmodKernel;
     
    6570#pragma warning(pop)
    6671
    67 __declspec(naked) long __stdcall Alternative_InterlockedCompareExchange(long volatile*, long, long)
     72__declspec(naked) long WINAPI Alternative_InterlockedCompareExchange(long volatile*, long, long)
    6873{
    6974    __asm
     
    8388}
    8489
     90HMODULE WINAPI Alternative_GetModuleHandleW(LPCWSTR moduleName)
     91{
     92    HMODULE ret = nullptr;
     93    auto size = std::wcslen(moduleName) + 1;
     94    auto mbsSize = size * 2;
     95    if (auto buffer = static_cast<LPSTR>(::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, mbsSize)))
     96    {
     97        if (::WideCharToMultiByte(CP_ACP, 0, moduleName, static_cast<int>(size), buffer, static_cast<int>(mbsSize), nullptr, nullptr) > 0)
     98        {
     99            ret = ::GetModuleHandleA(buffer);
     100        }
     101        ::HeapFree(::GetProcessHeap(), 0, buffer);
     102    }
     103    return ret;
     104}
     105
     106// CRT用に最小限の実装
     107void WINAPI Alternative_GetStartupInfoW(LPSTARTUPINFOW psi)
     108{
     109    STARTUPINFOA sia;
     110    ::GetStartupInfoA(&sia);
     111
     112    *psi = STARTUPINFOW();
     113    psi->cb = sizeof *psi;
     114    if (sia.dwFlags & STARTF_USESHOWWINDOW)
     115    {
     116        psi->dwFlags = STARTF_USESHOWWINDOW;
     117        psi->wShowWindow = sia.wShowWindow;
     118    }
     119}
     120
     121LPWCH WINAPI Alternative_GetEnvironmentStringsW()
     122{
     123    static WCHAR c[2];
     124    return c;
     125}
     126
     127BOOL WINAPI Alternative_FreeEnvironmentStringsW(LPWCH)
     128{
     129    return TRUE;
     130}
     131
    85132#define FUNCTION_INIT(name) \
    86133    if (auto f = ::GetProcAddress(GetKernelModule(), #name)) { \
     
    88135    } else { \
    89136        alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \
     137    }
     138
     139#define FUNCTION_INIT_9X(name) \
     140    if (ActiveBasic::Common::Is9x()) { \
     141        alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \
     142    } else { \
     143        alias__imp__ ## name = ::GetProcAddress(GetKernelModule(), #name); \
    90144    }
    91145
     
    100154    FUNCTION_INIT(DecodePointer);
    101155    FUNCTION_INIT(HeapSetInformation);
    102     alias__imp__InitializeCriticalSectionAndSpinCount =
    103         ActiveBasic::Common::Is9x()
    104         ? reinterpret_cast<FARPROC>(Alternative_InitializeCriticalSectionAndSpinCount)
    105         : ::GetProcAddress(GetKernelModule(), "InitializeCriticalSectionAndSpinCount");
     156    FUNCTION_INIT_9X(InitializeCriticalSectionAndSpinCount);
    106157    FUNCTION_INIT(InterlockedCompareExchange);
    107158    FUNCTION_INIT(IsProcessorFeaturePresent);
    108159    alias__imp__InterlockedPushEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPushEntrySList");
    109160    alias__imp__InterlockedPopEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPopEntrySList");
     161    FUNCTION_INIT_9X(GetModuleHandleW);
     162    FUNCTION_INIT_9X(GetStartupInfoW);
     163    FUNCTION_INIT_9X(GetEnvironmentStringsW);
     164    FUNCTION_INIT_9X(FreeEnvironmentStringsW);
    110165
    111166    ::VirtualProtect(&TrapTableFirst,
     
    118173extern "C"
    119174{
    120 #ifdef _UNICODE
    121 int wWinMainCRTStartup();
    122 #define tWinMainCRTStartup wWinMainCRTStartup
     175#ifdef _CONSOLE
     176#   ifdef _UNICODE
     177        int wmainCRTStartup();
     178#       define CRTStartup wmainCRTStartup
     179#   else
     180        int mainCRTStartup();
     181#       define CRTStartup mainCRTStartup
     182#   endif
    123183#else
    124 int WinMainCRTStartup();
    125 #define tWinMainCRTStartup WinMainCRTStartup
     184#   ifdef _UNICODE
     185        int wWinMainCRTStartup();
     186#       define CRTStartup wWinMainCRTStartup
     187#   else
     188        int WinMainCRTStartup();
     189#       define CRTStartup WinMainCRTStartup
     190#   endif
    126191#endif
    127192
    128 void WinMainStartup_OldWindowsHelper()
     193void Startup_OldWindowsHelper()
    129194{
    130195    __security_init_cookie();
    131 
     196//  MessageBox(0, "Startup", "", 0);
    132197    InitializeOldWindowsHelper();
    133198
    134199    __asm
    135200    {
    136         jmp tWinMainCRTStartup;
     201        jmp CRTStartup;
    137202    }
    138203}
  • branches/egtra/ab5.0/abdev/abdev/abdev.vcxproj

    r800 r801  
    115115      <SubSystem>Windows</SubSystem>
    116116      <TargetMachine>MachineX86</TargetMachine>
    117       <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
     117      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
    118118    </Link>
    119119    <Manifest>
     
    153153      <SubSystem>Windows</SubSystem>
    154154      <TargetMachine>MachineX64</TargetMachine>
    155       <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
     155      <EntryPointSymbol>
     156      </EntryPointSymbol>
    156157    </Link>
    157158    <Manifest>
     
    194195      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    195196      <TargetMachine>MachineX86</TargetMachine>
    196       <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
     197      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
    197198    </Link>
    198199    <Manifest>
     
    235236      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    236237      <TargetMachine>MachineX64</TargetMachine>
    237       <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
     238      <EntryPointSymbol>
     239      </EntryPointSymbol>
    238240    </Link>
    239241    <Manifest>
  • branches/egtra/ab5.0/abdev/compiler.vcxproj

    r798 r801  
    4646  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    4747  <ImportGroup Label="ExtensionSettings">
     48    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
    4849  </ImportGroup>
    4950  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
     
    9899      <Optimization>Disabled</Optimization>
    99100      <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    100       <PreprocessorDefinitions>_DEBUG;_WINDOWS;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     101      <PreprocessorDefinitions>_DEBUG;_CONSOLE;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    101102      <MinimalRebuild>false</MinimalRebuild>
    102103      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
     
    116117      <SubSystem>Console</SubSystem>
    117118      <StackReserveSize>4194304</StackReserveSize>
     119      <EntryPointSymbol>mainStartup_OldWindowsHelper</EntryPointSymbol>
     120      <DelayLoadDLLs>PSAPI.DLL</DelayLoadDLLs>
    118121    </Link>
    119122    <Manifest>
     
    138141      <Optimization>Disabled</Optimization>
    139142      <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    140       <PreprocessorDefinitions>_DEBUG;_WINDOWS;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     143      <PreprocessorDefinitions>_DEBUG;_CONSOLE;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    141144      <MinimalRebuild>false</MinimalRebuild>
    142145      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
     
    179182      <Optimization>MaxSpeed</Optimization>
    180183      <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    181       <PreprocessorDefinitions>NDEBUG;_WINDOWS;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     184      <PreprocessorDefinitions>NDEBUG;_CONSOLE;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    182185      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
    183186      <PrecompiledHeader>Use</PrecompiledHeader>
     
    197200      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    198201      <ImageHasSafeExceptionHandlers>true</ImageHasSafeExceptionHandlers>
     202      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
     203      <DelayLoadDLLs>PSAPI.DLL</DelayLoadDLLs>
    199204    </Link>
    200205    <Manifest>
     
    219224      <Optimization>MaxSpeed</Optimization>
    220225      <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    221       <PreprocessorDefinitions>NDEBUG;_WINDOWS;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     226      <PreprocessorDefinitions>NDEBUG;_CONSOLE;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    222227      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
    223228      <PrecompiledHeader>Use</PrecompiledHeader>
     
    839844      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
    840845      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     846    </ClCompile>
     847    <ClCompile Include="OldWindowsHelperImpl.cpp">
     848      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
     849      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
    841850    </ClCompile>
    842851  </ItemGroup>
     
    918927    </ProjectReference>
    919928  </ItemGroup>
     929  <ItemGroup>
     930    <MASM Include="OldWindowsHelper.asm">
     931      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
     932      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
     933    </MASM>
     934  </ItemGroup>
    920935  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    921936  <ImportGroup Label="ExtensionTargets">
     937    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
    922938  </ImportGroup>
    923939</Project>
  • branches/egtra/ab5.0/abdev/compiler.vcxproj.filters

    r777 r801  
    391391      <Filter>Source Files\x64Compiler\Procedure\Opcode</Filter>
    392392    </ClCompile>
     393    <ClCompile Include="OldWindowsHelperImpl.cpp">
     394      <Filter>Source Files</Filter>
     395    </ClCompile>
    393396  </ItemGroup>
    394397  <ItemGroup>
     
    563566    </None>
    564567  </ItemGroup>
     568  <ItemGroup>
     569    <MASM Include="OldWindowsHelper.asm">
     570      <Filter>Source Files</Filter>
     571    </MASM>
     572  </ItemGroup>
    565573</Project>
Note: See TracChangeset for help on using the changeset viewer.