src/jdk.jdwp.agent/windows/native/libdt_socket/socket_md.c
author amenkov
Wed, 15 May 2019 11:06:33 -0700
changeset 54884 8a6093c186a6
parent 48767 0c6ce8fdb50a
permissions -rw-r--r--
8184770: JDWP support for IPv6 Reviewed-by: sspitsyn, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54884
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
     2
 * Copyright (c) 1998, 2019, 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
54884
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   202
dbgsysGetAddrInfo(const char *hostname, const char *service,
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   203
                  const struct addrinfo *hints,
48767
0c6ce8fdb50a 8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
gadams
parents: 47216
diff changeset
   204
                  struct addrinfo **result) {
54884
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   205
    return getaddrinfo(hostname, service, hints, result);
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   206
}
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   207
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   208
void
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   209
dbgsysFreeAddrInfo(struct addrinfo *info) {
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   210
    freeaddrinfo(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
dbgsysHostToNetworkShort(unsigned short hostshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    return htons(hostshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
dbgsysSocket(int domain, int type, int protocol) {
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   220
  int fd = (int)socket(domain, type, protocol);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  if (fd != SOCKET_ERROR) {
54884
8a6093c186a6 8184770: JDWP support for IPv6
amenkov
parents: 48767
diff changeset
   222
    SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
dbgsysSocketClose(int fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    struct linger l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int len = sizeof(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        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
   234
            shutdown(fd, SD_SEND);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    return closesocket(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
/* Additions to original follow */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   243
dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return bind(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   248
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   249
dbgsysHostToNetworkLong(uint32_t hostlong) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   250
    return (uint32_t)htonl((u_long)hostlong);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
dbgsysNetworkToHostShort(unsigned short netshort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    return ntohs(netshort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
int
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   259
dbgsysGetSocketName(int fd, struct sockaddr *name, socklen_t *namelen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    return getsockname(fd, name, namelen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   263
uint32_t
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   264
dbgsysNetworkToHostLong(uint32_t netlong) {
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   265
    return (uint32_t)ntohl((u_long)netlong);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * Below Adapted from PlainSocketImpl.c, win32 version 1.18. Changed exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * throws to returns of SYS_ERR; we should improve the error codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * eventually. Changed java objects to values the debugger back end can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * more easily deal with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (cmd == TCP_NODELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        struct protoent *proto = getprotobyname("TCP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        long onl = (long)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (setsockopt(fd, tcp_level, TCP_NODELAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                       (char *)&onl, sizeof(long)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    } else if (cmd == SO_LINGER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        struct linger arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        arg.l_onoff = on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if(on) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            arg.l_linger = (unsigned short)value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if(setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                          (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                           (char*)&arg, sizeof(arg)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    } else if (cmd == SO_SNDBUF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        jint buflen = value.i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                       (char *)&buflen, sizeof(buflen)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    } else if (cmd == SO_REUSEADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * On Windows the SO_REUSEADDR socket option doesn't implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * BSD semantics. Specifically, the socket option allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * processes to bind to the same address/port rather than allowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * a process to bind with a previous connection in the TIME_WAIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * state. Hence on Windows we never enable this option for TCP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int sotype, arglen=sizeof(sotype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (sotype != SOCK_STREAM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            int oni = (int)on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                       (char *)&oni, sizeof(oni)) == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    } else {
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
    return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
int dbgsysConfigureBlocking(int fd, jboolean blocking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    u_long argp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    if (blocking == JNI_FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        argp = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        argp = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    result = ioctlsocket(fd, FIONBIO, &argp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (result == SOCKET_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return SYS_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return SYS_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
dbgsysPoll(int fd, jboolean rd, jboolean wr, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    fd_set rd_tbl, wr_tbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    t.tv_sec = timeout / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    t.tv_usec = (timeout % 1000) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    FD_ZERO(&rd_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    if (rd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        FD_SET((unsigned int)fd, &rd_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    FD_ZERO(&wr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    if (wr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        FD_SET((unsigned int)fd, &wr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    rv = select(fd+1, &rd_tbl, &wr_tbl, 0, &t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    if (rv >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (FD_ISSET(fd, &rd_tbl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            rv |= DBG_POLLIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (FD_ISSET(fd, &wr_tbl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            rv |= DBG_POLLOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
dbgsysGetLastIOError(char *buf, jint size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    int table_size = sizeof(winsock_errors) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                     sizeof(winsock_errors[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    int error = WSAGetLastError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Check table for known winsock errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    while (i < table_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (error == winsock_errors[i].errCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if (i < table_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        strcpy(buf, winsock_errors[i].errString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        sprintf(buf, "winsock error %d", error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
dbgsysTlsAlloc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    return TlsAlloc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
dbgsysTlsFree(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    TlsFree(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
dbgsysTlsPut(int index, void *value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    TlsSetValue(index, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
dbgsysTlsGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    return TlsGetValue(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
#define FT2INT64(ft) \
15274
a77cdd5ea6e3 8005120: Compiler warnings in socket transport native code
jzavgren
parents: 5506
diff changeset
   432
        ((INT64)(ft).dwHighDateTime << 32 | (INT64)(ft).dwLowDateTime)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
dbgsysCurrentTimeMillis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    static long fileTime_1_1_70 = 0;    /* midnight 1/1/70 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    SYSTEMTIME st0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    FILETIME   ft0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /* initialize on first usage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    if (fileTime_1_1_70 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        memset(&st0, 0, sizeof(st0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        st0.wYear  = 1970;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        st0.wMonth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        st0.wDay   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        SystemTimeToFileTime(&st0, &ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        fileTime_1_1_70 = FT2INT64(ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    GetSystemTime(&st0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    SystemTimeToFileTime(&st0, &ft0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    return (FT2INT64(ft0) - fileTime_1_1_70) / 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
}