Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / debug_stub / win / debug_stub_win.cc
1 /*
2  * Copyright 2010 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <windows.h>
10
11 #ifndef AF_IPX
12 #include <winsock2.h>
13 #endif
14
15 #include "native_client/src/shared/platform/nacl_log.h"
16 #include "native_client/src/trusted/debug_stub/debug_stub.h"
17 #include "native_client/src/trusted/debug_stub/platform.h"
18
19
20 using port::IPlatform;
21
22 void NaClDebugStubPlatformInit() {
23   WORD wVersionRequested;
24   WSADATA wsaData;
25   int err;
26
27   // Make sure to request the use of sockets.
28   // NOTE:  It is safe to call Startup multiple times
29   wVersionRequested = MAKEWORD(2, 2);
30   err = WSAStartup(wVersionRequested, &wsaData);
31   if (err != 0) {
32     // We could not find a matching DLL
33     NaClLog(LOG_ERROR, "WSAStartup failed with error: %d\n", err);
34     exit(-1);
35   }
36
37   if (HIBYTE(wsaData.wVersion) != 2) {
38     // We couldn't get a matching version
39     NaClLog(LOG_ERROR, "Could not find a usable version of Winsock.dll\n");
40     WSACleanup();
41     exit(-1);
42   }
43 }
44
45 void NaClDebugStubPlatformFini() {
46   WSACleanup();
47 }
48