Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include-hax/fake_masm/macamd64.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
push_reg macro Reg
push Reg
.pushreg Reg
endm

alloc_stack macro Size
sub rsp, Size
.allocstack Size
endm
2 changes: 1 addition & 1 deletion src/include/nacl_compiler_annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "native_client/src/include/build_config.h"

/* MSVC supports "inline" only in C++ */
#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
# define INLINE __forceinline
#else
# define INLINE __inline__
Expand Down
5 changes: 4 additions & 1 deletion src/include/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_
#define NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_ 1

#include <stdint.h>
#include <stdlib.h>

#include "native_client/src/include/build_config.h"
Expand All @@ -30,7 +31,9 @@

#if NACL_WINDOWS
/* disable warnings for deprecated functions like getenv, etc. */
#if defined(_MSC_VER)
#pragma warning(disable : 4996)
#endif
# include <malloc.h>
/* TODO: eliminate port_win.h */
# include "native_client/src/include/win/port_win.h"
Expand Down Expand Up @@ -59,7 +62,7 @@
#define GG_UINT32_C(x) (x ## U)
#define GG_UINT64_C(x) GG_ULONGLONG(x)

#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
#define GG_LONGLONG(x) x##I64
#define GG_ULONGLONG(x) x##UI64
#else
Expand Down
4 changes: 4 additions & 0 deletions src/include/portability_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#if NACL_WINDOWS
/* disable warnings for deprecated _snprintf */
#if defined(_MSC_VER)
#pragma warning(disable : 4996)
#endif

#include <io.h>
#include <direct.h>
Expand All @@ -43,7 +45,9 @@
/* missing from win stdio.h and fcntl.h */

/* from bits/fcntl.h */
#if defined(_MSC_VER)
#define O_ACCMODE 0003
#endif

#else

Expand Down
2 changes: 2 additions & 0 deletions src/include/portability_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ size_t strnlen(const char* str, size_t max);

#if NACL_WINDOWS
/* disable warnings for deprecated strncpy */
#if defined(_MSC_VER)
#pragma warning(disable : 4996)
#endif

#define STRDUP _strdup
#define STRTOLL _strtoi64
Expand Down
8 changes: 7 additions & 1 deletion src/include/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

/* TODO: eliminated this file and move its contents to portability*.h */

#if defined(_MSC_VER)
/* wchar_t and unsigned short are not always equivalent*/
#pragma warning(disable : 4255)
/* padding added after struct member */
Expand All @@ -46,6 +47,7 @@
#pragma warning(disable: 4826)
/* conditional expression is constant */
#pragma warning(disable : 4127)
#endif

/* TODO: limit this include to files that really need it */
#ifndef NOMINMAX
Expand Down Expand Up @@ -74,7 +76,9 @@ typedef __int64_t int64_t;
typedef __uint64_t uint64_t;

typedef long off_t;
#if !defined(__MINGW32__)
typedef int mode_t;
#endif
typedef long _off_t;
typedef long int __loff_t;
typedef unsigned long DWORD;
Expand All @@ -94,7 +98,7 @@ typedef int32_t ssize_t;
*
* Only including range values actually used in our codebase.
*/
#if _MSC_VER >= 1800
#if !defined(_MSC_VER) || _MSC_VER >= 1800
#include <stdint.h>
#else
# if !defined(UINT8_MAX)
Expand Down Expand Up @@ -160,6 +164,8 @@ EXTERN_C_END


/* from linux/limits.h, via sys/param.h */
#if defined(_MSC_VER)
#define PATH_MAX 4096
#endif

#endif /* NATIVE_CLIENT_SRC_INCLUDE_WIN_PORT_WIN_H_ */
2 changes: 1 addition & 1 deletion src/shared/platform/win/lock_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_
#define NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_

#include <Windows.h>
#include <windows.h>
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/shared/platform/nacl_sync.h"

Expand Down
4 changes: 4 additions & 0 deletions src/shared/platform/win/nacl_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ void NaClAbort(void) {
* http://code.google.com/p/nativeclient/issues/detail?id=2772).
*/
while (1) {
#if defined(_MSC_VER)
__halt();
#else
__asm__("hlt");
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/platform/win/port_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "native_client/src/include/portability.h"

#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) )
#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) || !defined(_MSC_VER) )
int ffs(int x) {
int r = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/platform/win/xlate_system_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include <errno.h>
#include <WinError.h>
#include <winerror.h>

#include "native_client/src/shared/platform/nacl_log.h"
#include "native_client/src/shared/platform/win/xlate_system_error.h"
Expand Down
2 changes: 2 additions & 0 deletions src/trusted/fault_injection/fault_injection.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
*/
# define NACL_HAS_STRNDUP 0
/* could use TLS if not built into a DLL, otherwise must use TLSALLOC */
# define NACL_USE_TLS 0
# define NACL_USE_TSD 0
# define NACL_USE_TLSALLOC 1
# include <windows.h>
#endif
Expand Down
51 changes: 45 additions & 6 deletions src/trusted/platform_qualify/arch/x86/vcpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ const int kMagicConst_ROUNDSS = 0xc0000000;
const int kMagicConst_POPCNT = 13;
const int kMagicConst_CRC32 = 0xb906c3ea;

#if !(NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64))
#if (NACL_WINDOWS && defined(_MSC_VER) && (NACL_BUILD_SUBARCH == 64))
# define NACL_WINDOWS_MSC_64
#endif

#if (NACL_WINDOWS && !defined(_MSC_VER))
# define NACL_WINDOWS_MINGW
#endif

#if !defined(NACL_WINDOWS_MSC_64)
static int asm_HasMMX(void) {
volatile int before, after;
before = kMagicConst;
Expand Down Expand Up @@ -386,20 +394,34 @@ static int asm_HasCX8(void) {
#endif /* 0 */
#endif /* 64-bit Windows */

#if NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64)
#if defined(NACL_WINDOWS_MSC_64)
static int CheckCPUFeatureDetection(NaClCPUFeaturesX86 *cpuf) {
/* Unfortunately the asm_ tests will not work on 64-bit Windows */
return 0;
}
#else
#if (NACL_LINUX || NACL_OSX)
#if (NACL_LINUX || NACL_OSX || defined(NACL_WINDOWS_MINGW))
/* Linux/MacOS signal handling code, for trapping illegal instruction faults */
static int sawbadinstruction = 0;
static struct sigaction crash_detect;
static int signum;

sigjmp_buf crash_load;
#if defined(NACL_WINDOWS_MINGW)
static PVOID crash_handler;
static jmp_buf crash_load;
#else
static struct sigaction crash_detect;
static sigjmp_buf crash_load;
#endif

#if defined(NACL_WINDOWS_MINGW)
static LONG CALLBACK handler_load(EXCEPTION_POINTERS *ep)
{
if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
longjmp(crash_load, SIGILL);
}
return EXCEPTION_CONTINUE_SEARCH;
}
#else
void handler_load(int signal_num) {
siglongjmp(crash_load, signal_num);
}
Expand Down Expand Up @@ -427,13 +449,18 @@ void all_sigs(struct sigaction *new_action,
(void) sigaction(SIGCHLD, &ign, 0);
(void) sigaction(SIGTSTP, &ign, 0);
}
#endif

static void SignalInit(void) {
sawbadinstruction = 0;
#if defined(NACL_WINDOWS_MINGW)
crash_handler = AddVectoredExceptionHandler(1, handler_load);
#else
crash_detect.sa_handler = handler_load;
sigemptyset(&crash_detect.sa_mask);
crash_detect.sa_flags = SA_RESETHAND;
all_sigs(&crash_detect, 0);
#endif
}

static void SetSawBadInst(void) {
Expand All @@ -450,7 +477,13 @@ static int SawBadInst(void) {
*/
static int DoTest(int (*thetest)(void), const char *s) {
SignalInit();
if (0 != (signum = sigsetjmp(crash_load, 1))) {

#if defined(NACL_WINDOWS_MINGW)
signum = setjmp(crash_load);
#else
signum = sigsetjmp(crash_load, 1);
#endif
if (0 != signum) {
SetSawBadInst();
if (SIGILL == signum) {
fprintf(stderr, "%s: illegal instruction\n", s);
Expand All @@ -462,10 +495,16 @@ static int DoTest(int (*thetest)(void), const char *s) {
int hasfeature = thetest();
if (hasfeature && (! SawBadInst())) {
printf("[Has %s]\n", s);
#if defined(NACL_WINDOWS_MINGW)
RemoveVectoredExceptionHandler(crash_handler);
#endif
return 0;
}
}
printf("no %s\n", s);
#if defined(NACL_WINDOWS_MINGW)
RemoveVectoredExceptionHandler(crash_handler);
#endif
return 1;
}
#elif NACL_WINDOWS
Expand Down
2 changes: 1 addition & 1 deletion src/trusted/service_runtime/arch/x86_32/sel_rt_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int NaClAppThreadInitArchSpecific(struct NaClAppThread *natp,
* Save the system's state of the x87 FPU control word so we can restore
* the same state when returning to trusted code.
*/
#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
{
uint16_t sys_fcw;
__asm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; Use of this source code is governed by a BSD-style license that can be
; found in the LICENSE file.

include ksamd64.inc
include macamd64.inc

EXTERN NaClSwitch : QWORD

Expand Down
2 changes: 1 addition & 1 deletion src/trusted/service_runtime/nacl_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct NaClExceptionFrame;
#define NACL_ABI_WIFSIGNALED(status) ((((status) + 1) & 0x7f) > 1)
#define NACL_ABI_W_EXITCODE(ret, sig) ((((ret) & 0xff) << 8) + ((sig) & 0x7f))

#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
enum PosixSignals {
SIGINT = 2,
SIGQUIT = 3,
Expand Down
2 changes: 1 addition & 1 deletion src/trusted/service_runtime/sel_ldr.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ void NaClVmIoPendingCheck_mu(struct NaClApp *nap,
* We need its symbol in the symbol table so don't inline it.
* TODO(dje): add some explanation for the non-GDB person.
*/
#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSVC_VER)
__declspec(dllexport noinline)
#endif
#ifdef __GNUC__
Expand Down
2 changes: 1 addition & 1 deletion src/trusted/validator/validation_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "native_client/src/trusted/validator/validation_metadata.h"

#if NACL_WINDOWS
#include <Windows.h>
#include <windows.h>
#include <io.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/trusted/validator_ragel/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/portability.h"

#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
# define FORCEINLINE __forceinline
#else
# define FORCEINLINE __inline __attribute__ ((always_inline))
Expand Down
2 changes: 1 addition & 1 deletion src/trusted/validator_ragel/decoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "native_client/src/include/build_config.h"
#include "native_client/src/trusted/validator_ragel/decoder.h"

#if NACL_WINDOWS
#if NACL_WINDOWS && defined(_MSC_VER)
# define FORCEINLINE __forceinline
#else
# define FORCEINLINE __inline __attribute__ ((always_inline))
Expand Down