diff options
author | Andreas Holzammer <andreas.holzammer@kdab.com> | 2013-02-28 22:18:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-01 13:53:33 +0100 |
commit | 7bba72a901e600be7335a8903ffa4c0e08b1c99a (patch) | |
tree | bfa8c76d0e699e5deef39228777425b124e65107 /src/3rdparty/v8/src/platform-win32.cc | |
parent | 09004dbcb93f197a88b2f7ba386b4a3e8ace8c1f (diff) | |
download | qtjsbackend-7bba72a901e600be7335a8903ffa4c0e08b1c99a.tar.gz |
[V8]Port to Windows Embedded Compact 7
Change-Id: I98524d2d6d255197f706e0aae60858dd2d0b283b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/3rdparty/v8/src/platform-win32.cc')
-rw-r--r-- | src/3rdparty/v8/src/platform-win32.cc | 114 |
1 files changed, 104 insertions, 10 deletions
diff --git a/src/3rdparty/v8/src/platform-win32.cc b/src/3rdparty/v8/src/platform-win32.cc index 7391453..76e35f5 100644 --- a/src/3rdparty/v8/src/platform-win32.cc +++ b/src/3rdparty/v8/src/platform-win32.cc @@ -58,6 +58,20 @@ int strncasecmp(const char* s1, const char* s2, int n) { #endif // _MSC_VER +#ifdef _WIN32_WCE +// Convert a Latin1 string into a utf16 string +wchar_t* wce_mbtowc(const char* a) { + int length = strlen(a); + wchar_t *wbuf = new wchar_t[length]; + + for (int i = 0; i < length; ++i) + wbuf[i] = (wchar_t)a[i]; + + return wbuf; +} +#endif // _WIN32_WCE + + // Extra functions for MinGW. Most of these are the _s functions which are in // the Microsoft Visual Studio C++ CRT. #ifdef __MINGW32__ @@ -162,6 +176,13 @@ void OS::MemCopy(void* dest, const void* src, size_t size) { } #endif // V8_TARGET_ARCH_IA32 +#ifdef _WIN32_WCE +// TODO: Implement +CpuImplementer OS::GetCpuImplementer() { + return UNKNOWN_IMPLEMENTER; +} +#endif // _WIN32_WCE + #ifdef _WIN64 typedef double (*ModuloFunction)(double, double); static ModuloFunction modulo_function = NULL; @@ -377,7 +398,9 @@ void Time::TzSet() { if (tz_initialized_) return; // Initialize POSIX time zone data. +#ifndef _WIN32_WCE _tzset(); +#endif // _WIN32_WCE // Obtain timezone information from operating system. memset(&tzinfo_, 0, sizeof(tzinfo_)); if (GetTimeZoneInformation(&tzinfo_) == TIME_ZONE_ID_INVALID) { @@ -489,6 +512,7 @@ void Time::SetToCurrentTime() { // Also, adding the time-zone offset to the input must not overflow. // The function EquivalentTime() in date.js guarantees this. int64_t Time::LocalOffset() { +#ifndef _WIN32_WCE // Initialize timezone information, if needed. TzSet(); @@ -519,6 +543,11 @@ int64_t Time::LocalOffset() { } else { return tzinfo_.Bias * -kMsPerMinute; } +#else + // Windows CE has a different handling of Timezones. + // TODO: Adapt this for Windows CE + return 0; +#endif } @@ -570,6 +599,14 @@ void OS::PostSetUp() { #endif } +#ifdef V8_TARGET_ARCH_ARM +// TODO: Implement +// Windows CE is the only platform right now that supports ARM. +bool OS::ArmCpuHasFeature(CpuFeature feature) { + return false; +} +#endif // V8_TARGET_ARCH_ARM + // Returns the accumulated user time for thread. int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { @@ -664,6 +701,7 @@ static OutputMode output_mode = UNKNOWN; // Current output mode. static bool HasConsole() { // Only check the first time. Eventual race conditions are not a problem, // because all threads will eventually determine the same mode. +#ifndef _WIN32_WCE if (output_mode == UNKNOWN) { // We cannot just check that the standard output is attached to a console // because this would fail if output is redirected to a file. Therefore we @@ -676,6 +714,10 @@ static bool HasConsole() { output_mode = ODS; } return output_mode == CONSOLE; +#else + // Windows CE has no shell enabled in the standard BSP + return false; +#endif // _WIN32_WCE } @@ -688,7 +730,14 @@ static void VPrintHelper(FILE* stream, const char* format, va_list args) { // does not crash. EmbeddedVector<char, 4096> buffer; OS::VSNPrintF(buffer, format, args); +#ifdef _WIN32_WCE + wchar_t wbuf[4096]; + for (int i = 0; i < 4096; ++i) + wbuf[i] = (wchar_t)buffer.start()[i]; + OutputDebugStringW(wbuf); +#else OutputDebugStringA(buffer.start()); +#endif // _WIN32_WCE } } @@ -704,23 +753,30 @@ FILE* OS::FOpen(const char* path, const char* mode) { bool OS::Remove(const char* path) { +#ifndef _WIN32_WCE return (DeleteFileA(path) != 0); +#else + wchar_t *wpath = wce_mbtowc(path); + bool ret = (DeleteFileW(wpath) != 0); + delete wpath; + return ret; +#endif // _WIN32_WCE } FILE* OS::OpenTemporaryFile() { // tmpfile_s tries to use the root dir, don't use it. - char tempPathBuffer[MAX_PATH]; + wchar_t tempPathBuffer[MAX_PATH]; DWORD path_result = 0; - path_result = GetTempPathA(MAX_PATH, tempPathBuffer); + path_result = GetTempPathW(MAX_PATH, tempPathBuffer); if (path_result > MAX_PATH || path_result == 0) return NULL; UINT name_result = 0; - char tempNameBuffer[MAX_PATH]; - name_result = GetTempFileNameA(tempPathBuffer, "", 0, tempNameBuffer); + wchar_t tempNameBuffer[MAX_PATH]; + name_result = GetTempFileNameW(tempPathBuffer, L"", 0, tempNameBuffer); if (name_result == 0) return NULL; - FILE* result = FOpen(tempNameBuffer, "w+"); // Same mode as tmpfile uses. + FILE* result = _wfopen(tempNameBuffer, L"w+"); // Same mode as tmpfile uses. if (result != NULL) { - Remove(tempNameBuffer); // Delete on close. + DeleteFileW(tempNameBuffer); // Delete on close. } return result; } @@ -974,7 +1030,11 @@ void OS::Abort() { DebugBreak(); } else { // Make the MSVCRT do a silent abort. +#ifndef _WIN32_WCE raise(SIGABRT); +#else + exit(3); +#endif // _WIN32_WCE } } @@ -1011,8 +1071,15 @@ class Win32MemoryMappedFile : public OS::MemoryMappedFile { OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { // Open a physical file +#ifndef _WIN32_WCE HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); +#else + wchar_t *wname = wce_mbtowc(name); + HANDLE file = CreateFileW(wname, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + delete wname; +#endif // _WIN32_WCE if (file == INVALID_HANDLE_VALUE) return NULL; int size = static_cast<int>(GetFileSize(file, NULL)); @@ -1031,8 +1098,15 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, void* initial) { // Open a physical file +#ifndef _WIN32_WCE HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); +#else + wchar_t *wname = wce_mbtowc(name); + HANDLE file = CreateFileW(wname, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); + delete wname; +#endif // _WIN32_WCE if (file == NULL) return NULL; // Create a file mapping for the physical file HANDLE file_mapping = CreateFileMapping(file, NULL, @@ -1094,8 +1168,8 @@ Win32MemoryMappedFile::~Win32MemoryMappedFile() { #define VOID void #endif -// DbgHelp isn't supported on MinGW yet -#ifndef __MINGW32__ +// DbgHelp isn't supported on MinGW yet, nor does Windows CE have it +#if !defined(__MINGW32__) && !defined(_WIN32_WCE) // DbgHelp.h functions. typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, IN PSTR UserSearchPath, @@ -1624,6 +1698,7 @@ Thread::~Thread() { // the Win32 function CreateThread(), because the CreateThread() does not // initialize thread specific structures in the C runtime library. void Thread::Start() { +#ifndef _WIN32_WCE data_->thread_ = reinterpret_cast<HANDLE>( _beginthreadex(NULL, static_cast<unsigned>(stack_size_), @@ -1631,6 +1706,18 @@ void Thread::Start() { this, 0, &data_->thread_id_)); +#else + unsigned initflag = 0; + if (stack_size_ > 0) + initflag |= STACK_SIZE_PARAM_IS_A_RESERVATION; + data_->thread_ = reinterpret_cast<HANDLE>( + CreateThread( NULL, + static_cast<unsigned>(stack_size_), + (LPTHREAD_START_ROUTINE)ThreadEntry, + this, + initflag, + (LPDWORD)&data_->thread_id_)); +#endif // _WIN32_WCE } @@ -1725,7 +1812,7 @@ Mutex* OS::CreateMutex() { class Win32Semaphore : public Semaphore { public: explicit Win32Semaphore(int count) { - sem = ::CreateSemaphoreA(NULL, count, 0x7fffffff, NULL); + sem = ::CreateSemaphoreW(NULL, count, 0x7fffffff, NULL); } ~Win32Semaphore() { @@ -2073,10 +2160,17 @@ class SamplerThread : public Thread { sample->pc = reinterpret_cast<Address>(context.Rip); sample->sp = reinterpret_cast<Address>(context.Rsp); sample->fp = reinterpret_cast<Address>(context.Rbp); -#else +#elif V8_HOST_ARCH_IA32 sample->pc = reinterpret_cast<Address>(context.Eip); sample->sp = reinterpret_cast<Address>(context.Esp); sample->fp = reinterpret_cast<Address>(context.Ebp); +#elif V8_HOST_ARCH_ARM + // Taken from http://msdn.microsoft.com/en-us/library/aa448762.aspx + sample->pc = reinterpret_cast<Address>(context.Pc); + sample->sp = reinterpret_cast<Address>(context.Sp); + sample->fp = reinterpret_cast<Address>(context.R11); +#else +#error This Platform is not supported. #endif sampler->SampleStack(sample); sampler->Tick(sample); |