Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/druntime
Browse files Browse the repository at this point in the history
  • Loading branch information
complexmath committed Sep 16, 2011
2 parents 7f36a14 + 6b53597 commit 38b1dd4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/core/runtime.d
Expand Up @@ -334,8 +334,9 @@ extern (C) bool runModuleUnitTests()
{
version( Windows )
{
uint count = void;
WriteFile( GetStdHandle( 0xfffffff5 ), val.ptr, val.length, &count, null );
DWORD count = void;
assert(val.length <= uint.max, "val must be less than or equal to uint.max");
WriteFile( GetStdHandle( 0xfffffff5 ), val.ptr, cast(uint)val.length, &count, null );
}
else version( Posix )
{
Expand Down
4 changes: 3 additions & 1 deletion src/core/sys/windows/stacktrace.d
Expand Up @@ -299,7 +299,9 @@ private:
auto symbolSize = IMAGEHLP_SYMBOL64.sizeof + MAX_NAMELEN;
auto symbol = cast(IMAGEHLP_SYMBOL64*) calloc( symbolSize, 1 );

symbol.SizeOfStruct = symbolSize;
static assert((IMAGEHLP_SYMBOL64.sizeof + MAX_NAMELEN) <= uint.max, "symbolSize should never exceed uint.max");

symbol.SizeOfStruct = cast(DWORD)symbolSize;
symbol.MaxNameLength = MAX_NAMELEN;

IMAGEHLP_LINE64 line;
Expand Down
24 changes: 13 additions & 11 deletions src/core/sys/windows/windows.d
Expand Up @@ -68,6 +68,8 @@ extern (Windows)
alias int INT;
alias uint UINT;
alias uint *PUINT;

alias size_t SIZE_T;

// ULONG_PTR must be able to store a pointer as an integral type
version (Win64)
Expand Down Expand Up @@ -813,14 +815,14 @@ export
UINT LocalShrink(HLOCAL hMem, UINT cbNewSize);
UINT LocalCompact(UINT uMinFree);
BOOL FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, DWORD dwSize);
LPVOID VirtualAlloc(LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFree(LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType);
BOOL VirtualProtect(LPVOID lpAddress, DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
DWORD VirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, DWORD dwLength);
LPVOID VirtualAllocEx(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFreeEx(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType);
BOOL VirtualProtectEx(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
DWORD VirtualQueryEx(HANDLE hProcess, LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, DWORD dwLength);
LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
BOOL VirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
SIZE_T VirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength);
LPVOID VirtualAllocEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
BOOL VirtualFreeEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType);
BOOL VirtualProtectEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
SIZE_T VirtualQueryEx(HANDLE hProcess, LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength);
}

struct SYSTEMTIME
Expand Down Expand Up @@ -2412,9 +2414,9 @@ export HANDLE CreateFileMappingW(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappi

export BOOL GetMailslotInfo(HANDLE hMailslot, LPDWORD lpMaxMessageSize, LPDWORD lpNextSize, LPDWORD lpMessageCount, LPDWORD lpReadTimeout);
export BOOL SetMailslotInfo(HANDLE hMailslot, DWORD lReadTimeout);
export LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, DWORD dwNumberOfBytesToMap);
export LPVOID MapViewOfFileEx(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, DWORD dwNumberOfBytesToMap, LPVOID lpBaseAddress);
export BOOL FlushViewOfFile(LPCVOID lpBaseAddress, DWORD dwNumberOfBytesToFlush);
export LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap);
export LPVOID MapViewOfFileEx(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap, LPVOID lpBaseAddress);
export BOOL FlushViewOfFile(LPCVOID lpBaseAddress, SIZE_T dwNumberOfBytesToFlush);
export BOOL UnmapViewOfFile(LPCVOID lpBaseAddress);

export HGDIOBJ GetStockObject(int);
Expand Down
3 changes: 2 additions & 1 deletion src/core/thread.d
Expand Up @@ -796,7 +796,8 @@ class Thread
{
version( Windows )
{
m_hndl = cast(HANDLE) _beginthreadex( null, m_sz, &thread_entryPoint, cast(void*) this, 0, &m_addr );
assert(m_sz <= uint.max, "m_sz should not exceed uint.max");
m_hndl = cast(HANDLE) _beginthreadex( null, cast(uint)m_sz, &thread_entryPoint, cast(void*) this, 0, &m_addr );
if( cast(size_t) m_hndl == 0 )
throw new ThreadException( "Error creating thread" );
}
Expand Down
14 changes: 9 additions & 5 deletions src/rt/dmain2.d
Expand Up @@ -367,24 +367,28 @@ extern (C) int main(int argc, char** argv)
version (Windows)
{
wchar_t* wcbuf = GetCommandLineW();
size_t wclen = wcslen(wcbuf);
size_t wclen = wcslen(wcbuf);
int wargc = 0;
wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc);
assert(wargc == argc);

// This is required because WideCharToMultiByte requires int as input.
assert(wclen <= int.max, "wclen must not exceed int.max");

char* cargp = null;
size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0, null, 0);
size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, cast(int)wclen, null, 0, null, 0);

cargp = cast(char*) alloca(cargl);
args = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc];

for (size_t i = 0, p = 0; i < wargc; i++)
{
int wlen = wcslen(wargs[i]);
int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, 0);
size_t wlen = wcslen(wargs[i]);
assert(wlen <= int.max, "wlen cannot exceed int.max");
int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], cast(int)wlen, null, 0, null, 0);
args[i] = cargp[p .. p+clen];
p += clen; assert(p <= cargl);
WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen, null, 0);
WideCharToMultiByte(65001, 0, &wargs[i][0], cast(int)wlen, &args[i][0], clen, null, 0);
}
LocalFree(wargs);
wargs = null;
Expand Down
3 changes: 1 addition & 2 deletions src/rt/memory.d
Expand Up @@ -69,11 +69,10 @@ extern (C) void* rt_stackBottom()
}
else version( D_InlineAsm_X86_64 )
{
static assert( false, "is this right?" );
asm
{
naked;
mov RAX,FS:8;
mov RAX,GS:8;
ret;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/rt/util/console.d
Expand Up @@ -34,8 +34,9 @@ struct Console
{
version( Windows )
{
uint count = void;
WriteFile( GetStdHandle( 0xfffffff5 ), val.ptr, val.length, &count, null );
DWORD count = void;
assert(val.length <= uint.max, "val length cannot exceed uint.max");
WriteFile( GetStdHandle( 0xfffffff5 ), val.ptr, cast(uint)val.length, &count, null );
}
else version( Posix )
{
Expand Down

0 comments on commit 38b1dd4

Please sign in to comment.