src/jdk.jdwp.agent/windows/native/libdt_socket/socket_md.c
author erikj
Tue, 30 Apr 2019 10:24:14 -0700
changeset 54656 3f72db799fbd
parent 48767 0c6ce8fdb50a
child 54884 8a6093c186a6
permissions -rw-r--r--
8222913: Add Jib support for VERSION_EXTRA* Reviewed-by: tbell, mikael
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <winsock2.h>
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
    27
#include <ws2tcpip.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sysSocket.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "socketTransport.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
typedef jboolean bool_t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Table of Windows Sockets errors, the specific exception we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * throw for the error, and the error text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Note that this table excludes OS dependent errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
static struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    int errCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    const char *errString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
} const winsock_errors[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    { WSAEPROVIDERFAILEDINIT,   "Provider initialization failed (check %SystemRoot%)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    { WSAEACCES,                "Permission denied" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    { WSAEADDRINUSE,            "Address already in use" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    { WSAEADDRNOTAVAIL,         "Cannot assign requested address" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    { WSAEAFNOSUPPORT,          "Address family not supported by protocol family" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    { WSAEALREADY,              "Operation already in progress" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    { WSAECONNABORTED,          "Software caused connection abort" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    { WSAECONNREFUSED,          "Connection refused" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    { WSAECONNRESET,            "Connection reset by peer" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    { WSAEDESTADDRREQ,          "Destination address required" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    { WSAEFAULT,                "Bad address" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    { WSAEHOSTDOWN,             "Host is down" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    { WSAEHOSTUNREACH,          "No route to host" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    { WSAEINPROGRESS,           "Operation now in progress" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    { WSAEINTR,                 "Interrupted function call" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    { WSAEINVAL,                "Invalid argument" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    { WSAEISCONN,               "Socket is already connected" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    { WSAEMFILE,                "Too many open files" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    { WSAEMSGSIZE,              "The message is larger than the maximum supported by the underlying transport" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    { WSAENETDOWN,              "Network is down" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    { WSAENETRESET,             "Network dropped connection on reset" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    { WSAENETUNREACH,           "Network is unreachable" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    { WSAENOBUFS,               "No buffer space available (maximum connections reached?)" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    { WSAENOPROTOOPT,           "Bad protocol option" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    { WSAENOTCONN,              "Socket is not connected" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    { WSAENOTSOCK,              "Socket operation on nonsocket" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    { WSAEOPNOTSUPP,            "Operation not supported" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    { WSAEPFNOSUPPORT,          "Protocol family not supported" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    { WSAEPROCLIM,              "Too many processes" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    { WSAEPROTONOSUPPORT,       "Protocol not supported" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    { WSAEPROTOTYPE,            "Protocol wrong type for socket" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    { WSAESHUTDOWN,             "Cannot send after socket shutdown" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    { WSAESOCKTNOSUPPORT,       "Socket type not supported" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    { WSAETIMEDOUT,             "Connection timed out" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    { WSATYPE_NOT_FOUND,        "Class type not found" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    { WSAEWOULDBLOCK,           "Resource temporarily unavailable" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    { WSAHOST_NOT_FOUND,        "Host not found" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    { WSA_NOT_ENOUGH_MEMORY,    "Insufficient memory available" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    { WSANOTINITIALISED,        "Successful WSAStartup not yet performed" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    { WSANO_DATA,               "Valid name, no data record of requested type" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    { WSANO_RECOVERY,           "This is a nonrecoverable error" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    { WSASYSNOTREADY,           "Network subsystem is unavailable" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    { WSATRY_AGAIN,             "Nonauthoritative host not found" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    { WSAVERNOTSUPPORTED,       "Winsock.dll version out of range" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    { WSAEDISCON,               "Graceful shutdown in progress" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    { WSA_OPERATION_ABORTED,    "Overlapped operation aborted" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Initialize Windows Sockets API support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
BOOL WINAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    WSADATA wsadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        case DLL_PROCESS_ATTACH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case DLL_PROCESS_DETACH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            WSACleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * If we get a nonnull function pointer it might still be the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * that some other thread is in the process of initializing the socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * function pointer table, but our pointer should still be good.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
int
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   124
dbgsysListen(int fd, int backlog) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   125
    return listen(fd, backlog);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   129
dbgsysConnect(int fd, struct sockaddr *name, socklen_t namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    int rv = connect(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if (rv == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return DBG_EINPROGRESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   139
int dbgsysFinishConnect(int fd, int timeout) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    fd_set wr, ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    t.tv_sec = timeout / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    t.tv_usec = (timeout % 1000) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    FD_ZERO(&wr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    FD_ZERO(&ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    FD_SET((unsigned int)fd, &wr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    FD_SET((unsigned int)fd, &ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    rv = select(fd+1, 0, &wr, &ex, &t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    if (rv == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return SYS_ERR;     /* timeout */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Check if there was an error - this is preferable to check if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * the socket is writable because some versions of Windows don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * report a connected socket as being writable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    if (!FD_ISSET(fd, &ex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Unable to establish connection - to get the reason we must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * call getsockopt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   175
dbgsysAccept(int fd, struct sockaddr *name, socklen_t *namelen) {
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   176
    return (int)accept(fd, name, namelen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   180
dbgsysRecvFrom(int fd, char *buf, size_t nBytes,
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   181
                  int flags, struct sockaddr *from, socklen_t *fromlen) {
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   182
    return recvfrom(fd, buf, (int)nBytes, flags, from, fromlen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   186
dbgsysSendTo(int fd, char *buf, size_t len,
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   187
                int flags, struct sockaddr *to, socklen_t tolen) {
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   188
    return sendto(fd, buf, (int)len, flags, to, tolen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   192
dbgsysRecv(int fd, char *buf, size_t nBytes, int flags) {
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   193
    return recv(fd, buf, (int) nBytes, flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   197
dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   198
    return send(fd, buf, (int)nBytes, flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   201
int
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   202
dbgsysGetAddrInfo(char *hostname, char *service,
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   203
                  struct addrinfo *hints,
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   204
                  struct addrinfo **result) {
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   205
  return getaddrinfo(hostname, service, hints, result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
dbgsysHostToNetworkShort(unsigned short hostshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    return htons(hostshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
dbgsysSocket(int domain, int type, int protocol) {
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   215
  int fd = (int)socket(domain, type, protocol);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  if (fd != SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
dbgsysSocketClose(int fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    struct linger l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    int len = sizeof(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (l.l_onoff == 0) {
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   229
            shutdown(fd, SD_SEND);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return closesocket(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
/* Additions to original follow */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   238
dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    return bind(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   243
uint32_t
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
dbgsysInetAddr(const char* cp) {
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   245
    uint32_t addr;
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   246
    if (inet_pton(AF_INET, cp, &addr) < 1) {
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   247
      return -1;
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   248
    }
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   249
    return addr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   252
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   253
dbgsysHostToNetworkLong(uint32_t hostlong) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   254
    return (uint32_t)htonl((u_long)hostlong);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
dbgsysNetworkToHostShort(unsigned short netshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    return ntohs(netshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   263
dbgsysGetSocketName(int fd, struct sockaddr *name, socklen_t *namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    return getsockname(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   267
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   268
dbgsysNetworkToHostLong(uint32_t netlong) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   269
    return (uint32_t)ntohl((u_long)netlong);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * Below Adapted from PlainSocketImpl.c, win32 version 1.18. Changed exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * throws to returns of SYS_ERR; we should improve the error codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * eventually. Changed java objects to values the debugger back end can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * more easily deal with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    if (cmd == TCP_NODELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        struct protoent *proto = getprotobyname("TCP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        long onl = (long)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (setsockopt(fd, tcp_level, TCP_NODELAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                       (char *)&onl, sizeof(long)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    } else if (cmd == SO_LINGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        struct linger arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        arg.l_onoff = on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if(on) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            arg.l_linger = (unsigned short)value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if(setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                          (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                           (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    } else if (cmd == SO_SNDBUF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        jint buflen = value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                       (char *)&buflen, sizeof(buflen)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    } else if (cmd == SO_REUSEADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * On Windows the SO_REUSEADDR socket option doesn't implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * BSD semantics. Specifically, the socket option allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         * processes to bind to the same address/port rather than allowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         * a process to bind with a previous connection in the TIME_WAIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         * state. Hence on Windows we never enable this option for TCP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         * option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int sotype, arglen=sizeof(sotype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (sotype != SOCK_STREAM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            int oni = (int)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                       (char *)&oni, sizeof(oni)) == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
int dbgsysConfigureBlocking(int fd, jboolean blocking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    u_long argp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    if (blocking == JNI_FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        argp = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        argp = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    result = ioctlsocket(fd, FIONBIO, &argp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    if (result == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
dbgsysPoll(int fd, jboolean rd, jboolean wr, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    fd_set rd_tbl, wr_tbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    t.tv_sec = timeout / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    t.tv_usec = (timeout % 1000) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    FD_ZERO(&rd_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (rd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        FD_SET((unsigned int)fd, &rd_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    FD_ZERO(&wr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    if (wr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        FD_SET((unsigned int)fd, &wr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    rv = select(fd+1, &rd_tbl, &wr_tbl, 0, &t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (FD_ISSET(fd, &rd_tbl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            rv |= DBG_POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (FD_ISSET(fd, &wr_tbl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            rv |= DBG_POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
dbgsysGetLastIOError(char *buf, jint size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    int table_size = sizeof(winsock_errors) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                     sizeof(winsock_errors[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    int error = WSAGetLastError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Check table for known winsock errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    while (i < table_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (error == winsock_errors[i].errCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    if (i < table_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        strcpy(buf, winsock_errors[i].errString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        sprintf(buf, "winsock error %d", error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
dbgsysTlsAlloc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    return TlsAlloc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    TlsFree(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    TlsSetValue(index, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    return TlsGetValue(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
#define FT2INT64(ft) \
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   436
        ((INT64)(ft).dwHighDateTime << 32 | (INT64)(ft).dwLowDateTime)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
dbgsysCurrentTimeMillis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    static long fileTime_1_1_70 = 0;    /* midnight 1/1/70 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    SYSTEMTIME st0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    FILETIME   ft0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /* initialize on first usage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    if (fileTime_1_1_70 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        memset(&st0, 0, sizeof(st0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        st0.wYear  = 1970;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        st0.wMonth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        st0.wDay   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        SystemTimeToFileTime(&st0, &ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        fileTime_1_1_70 = FT2INT64(ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    GetSystemTime(&st0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    SystemTimeToFileTime(&st0, &ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    return (FT2INT64(ft0) - fileTime_1_1_70) / 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
}