src/jdk.jdwp.agent/share/native/libjdwp/transport.c
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58220 2c4185d7276a
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51120
dccdf51b10dd 8207233: Minor improvements of jdk C-coding
goetz
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "util.h"
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents: 23010
diff changeset
    27
#include "utf_util.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "transport.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "debugLoop.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "sys.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
    32
static jdwpTransportEnv *transport = NULL;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
    33
static unsigned transportVersion = JDWPTRANSPORT_VERSION_1_0;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
static jrawMonitorID listenerLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
static jrawMonitorID sendLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * data structure used for passing transport info from thread to thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
typedef struct TransportInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    jdwpTransportEnv *transport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    char *address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    long timeout;
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
    46
    char *allowed_peers;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
    47
    unsigned transportVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
} TransportInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static struct jdwpTransportCallback callback = {jvmtiAllocate, jvmtiDeallocate};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    52
static void freeTransportInfo(TransportInfo *info) {
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    53
    if (info) {
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    54
        jvmtiDeallocate(info->name);
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    55
        jvmtiDeallocate(info->address);
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    56
        jvmtiDeallocate(info->allowed_peers);
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    57
        jvmtiDeallocate(info);
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    58
    }
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    59
}
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
    60
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Print the last transport error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
printLastError(jdwpTransportEnv *t, jdwpTransportError err)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    char  *msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    jbyte *utf8msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    jdwpTransportError rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    msg     = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    utf8msg = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    rv = (*t)->GetLastError(t, &msg); /* This is a platform encoded string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if ( msg != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        int maxlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        /* Convert this string to UTF8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        len = (int)strlen(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        maxlen = len+len/2+2; /* Should allow for plenty of room */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
    82
        if (utf8msg != NULL) {
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 33653
diff changeset
    83
           (void)utf8FromPlatform(msg, len, utf8msg, maxlen+1);
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
    84
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (rv == JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        ERROR_MESSAGE(("transport error %d: %s",err, utf8msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    } else if ( msg!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        ERROR_MESSAGE(("transport error %d: %s",err, utf8msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ERROR_MESSAGE(("transport error %d: %s",err, "UNKNOWN"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jvmtiDeallocate(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    jvmtiDeallocate(utf8msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/* Find OnLoad symbol */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static jdwpTransport_OnLoad_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
findTransportOnLoad(void *handle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jdwpTransport_OnLoad_t onLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    onLoad = (jdwpTransport_OnLoad_t)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return onLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
53184
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   107
#if defined(_WIN32) && !defined(_WIN64)
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   108
    onLoad = (jdwpTransport_OnLoad_t)
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   109
                 dbgsysFindLibraryEntry(handle, "_jdwpTransport_OnLoad@16");
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   110
    if (onLoad != NULL) {
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   111
        return onLoad;
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   112
    }
9eee0b148002 8214122: JDWP is broken on 32 bit Windows: transport library missing onLoad entry
aivanov
parents: 51120
diff changeset
   113
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    onLoad = (jdwpTransport_OnLoad_t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                 dbgsysFindLibraryEntry(handle, "jdwpTransport_OnLoad");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return onLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
/* Load transport library (directory=="" means do system search) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static void *
16726
f76b2e6bd199 8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents: 16057
diff changeset
   121
loadTransportLibrary(const char *libdir, const char *name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
{
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 27959
diff changeset
   123
    char buf[MAXPATHLEN*2+100];
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 27959
diff changeset
   124
#ifndef STATIC_BUILD
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    void *handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    char libname[MAXPATHLEN+2];
16726
f76b2e6bd199 8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents: 16057
diff changeset
   127
    const char *plibdir;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /* Convert libdir from UTF-8 to platform encoding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    plibdir = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if ( libdir != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int  len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        len = (int)strlen(libdir);
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents: 23010
diff changeset
   135
        (void)utf8ToPlatform((jbyte*)libdir, len, buf, (int)sizeof(buf));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        plibdir = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /* Construct library name (simple name or full path) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    dbgsysBuildLibName(libname, sizeof(libname), plibdir, name);
16057
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
   141
    if (strlen(libname) == 0) {
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
   142
        return NULL;
16a81953a291 8009397: test/com/sun/jdi/PrivateTransportTest.sh: ERROR: transport library missing onLoad entry: private_dt_socket
sla
parents: 14698
diff changeset
   143
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* dlopen (unix) / LoadLibrary (windows) the transport library */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    handle = dbgsysLoadLibrary(libname, buf, sizeof(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    return handle;
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 27959
diff changeset
   148
#else
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 27959
diff changeset
   149
    return (dbgsysLoadLibrary(NULL, buf, sizeof(buf)));
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 27959
diff changeset
   150
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * loadTransport() is adapted from loadJVMHelperLib() in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * JDK 1.2 javai.c v1.61
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
static jdwpError
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   158
loadTransport(const char *name, TransportInfo *info)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    JNIEnv                 *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    jdwpTransport_OnLoad_t  onLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    void                   *handle;
16726
f76b2e6bd199 8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents: 16057
diff changeset
   163
    const char             *libdir;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* Make sure library name is not empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if (name == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        ERROR_MESSAGE(("library name is empty"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   170
    if (info == NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   171
        ERROR_MESSAGE(("internal error: info should not be NULL"));
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   172
        return JDWP_ERROR(TRANSPORT_LOAD);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   173
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /* First, look in sun.boot.library.path. This should find the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *  dt_socket and dt_shmem transport libraries, or any library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *  that was delivered with the J2SE.
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 5506
diff changeset
   178
     *  Note: Since 6819213 fixed, Java property sun.boot.library.path can
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 5506
diff changeset
   179
     *  contain multiple paths. Dll_dir is the first entry and
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 5506
diff changeset
   180
     *  -Dsun.boot.library.path entries are appended.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    libdir = gdata->property_sun_boot_library_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (libdir == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        ERROR_MESSAGE(("Java property sun.boot.library.path is not set"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    handle = loadTransportLibrary(libdir, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /* Second, look along the path used by the native dlopen/LoadLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         *  functions. This should effectively try and load the simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         *  library name, which will cause the default system library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         *  search technique to happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         *  We should only reach here if the transport library wasn't found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         *  in the J2SE directory, e.g. it's a custom transport library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         *  not installed in the J2SE like dt_socket and dt_shmem is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         *  Note: Why not use java.library.path? Several reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         *        a) This matches existing agentlib search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         *        b) These are technically not JNI libraries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        handle = loadTransportLibrary("", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /* See if a library was found with this name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        ERROR_MESSAGE(("transport library not found: %s", name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /* Find the onLoad address */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    onLoad = findTransportOnLoad(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if (onLoad == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        ERROR_MESSAGE(("transport library missing onLoad entry: %s", name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /* Get transport interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    env = getEnv();
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   219
    if (env != NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   220
        jdwpTransportEnv *t = NULL;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   221
        JavaVM           *jvm = NULL;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   222
        jint              rc;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   223
        size_t            i;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   224
        /* If a new version is added here, update 'case JNI_EVERSION' below. */
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   225
        jint supported_versions[2] = {JDWPTRANSPORT_VERSION_1_1, JDWPTRANSPORT_VERSION_1_0};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        JNI_FUNC_PTR(env,GetJavaVM)(env, &jvm);
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   228
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   229
        /* Try version 1.1 first, fallback to 1.0 on error */
51120
dccdf51b10dd 8207233: Minor improvements of jdk C-coding
goetz
parents: 47216
diff changeset
   230
        for (i = 0; i < sizeof(supported_versions)/sizeof(jint); ++i) {
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   231
            rc = (*onLoad)(jvm, &callback, supported_versions[i], &t);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   232
            if (rc != JNI_EVERSION) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   233
                info->transportVersion = supported_versions[i];
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   234
                break;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   235
            }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   236
        }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   237
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   238
        if (rc != JNI_OK) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   239
            switch (rc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                case JNI_ENOMEM :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    ERROR_MESSAGE(("insufficient memory to complete initialization"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                case JNI_EVERSION :
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   245
                    ERROR_MESSAGE(("transport doesn't recognize all supported versions: "
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   246
                                   "{ 1_1, 1_0 }"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                case JNI_EEXIST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    ERROR_MESSAGE(("transport doesn't support multiple environments"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                default:
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   254
                    ERROR_MESSAGE(("unrecognized error %d from transport", rc));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            return JDWP_ERROR(TRANSPORT_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   260
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   261
        /* Store transport version to global variable to be able to
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   262
         * set correct transport version for subsequent connect,
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   263
         * even if info is already deallocated.
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   264
         */
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   265
        transportVersion = info->transportVersion;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   266
        info->transport = t;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return JDWP_ERROR(TRANSPORT_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
connectionInitiated(jdwpTransportEnv *t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    jint isValid = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    debugMonitorEnter(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Don't allow a connection until initialization is complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    debugInit_waitInitComplete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /* Are we the first transport to get a connection? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (transport == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        transport = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        isValid = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (transport == t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            /* connected with the same transport as before */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            isValid = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             * Another transport got a connection - multiple transports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             * not fully supported yet so shouldn't get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            (*t)->Close(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            JDI_ASSERT(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    if (isValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        debugMonitorNotifyAll(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    debugMonitorExit(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (isValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        debugLoop_run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 * Set the transport property (sun.jdwp.listenerAddress) to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
setTransportProperty(JNIEnv* env, char* value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    char* prop_value = (value == NULL) ? "" : value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    setAgentPropertyValue(env, "sun.jdwp.listenerAddress", prop_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
transport_waitForConnection(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * If the VM is suspended on debugger initialization, we wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * for a connection before continuing. This ensures that all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * events are delivered to the debugger. (We might as well do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * this since the VM won't continue until a remote debugger attaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * and resumes it.) If not suspending on initialization, we must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * just drop any packets (i.e. events) so that the VM can continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * to run. The debugger may not attach until much later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    if (debugInit_suspendOnInit()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        debugMonitorEnter(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        while (transport == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            debugMonitorWait(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        debugMonitorExit(listenerLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
acceptThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    TransportInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    jdwpTransportEnv *t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    jdwpTransportError rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    LOG_MISC(("Begin accept thread"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   357
    info = (TransportInfo*)arg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    t = info->transport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    rc = (*t)->Accept(t, info->timeout, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /* System property no longer needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    setTransportProperty(jni_env, NULL);
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   363
    /* TransportInfo data no longer needed */
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   364
    freeTransportInfo(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (rc != JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * If accept fails it probably means a timeout, or another fatal error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * We thus exit the VM after stopping the listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        printLastError(t, rc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        (*t)->StopListening(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        EXIT_ERROR(JVMTI_ERROR_NONE, "could not connect, timeout or fatal error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        (*t)->StopListening(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        connectionInitiated(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    LOG_MISC(("End accept thread"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
attachThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
{
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   385
    TransportInfo *info = (TransportInfo*)arg;
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   386
    jdwpTransportEnv *t = info->transport;
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   387
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   388
    /* TransportInfo data no longer needed */
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   389
    freeTransportInfo(info);
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   390
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    LOG_MISC(("Begin attach thread"));
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   392
    connectionInitiated(t);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    LOG_MISC(("End attach thread"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
transport_initialize(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    transport = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    listenerLock = debugMonitorCreate("JDWP Transport Listener Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    sendLock = debugMonitorCreate("JDWP Transport Send Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
transport_reset(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Reset the transport by closing any listener (will silently fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * with JDWPTRANSPORT_ERROR_ILLEGAL_STATE if not listening), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * closing any connection (will also fail silently if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * connected).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Note: There's an assumption here that we don't yet support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * multiple transports. When we do then we need a clear transition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * from the current transport to the new transport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    if (transport != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        setTransportProperty(getEnv(), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        (*transport)->StopListening(transport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        (*transport)->Close(transport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
launch(char *command, char *name, char *address)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    jint rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    char *buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    char *commandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    int  len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /* Construct complete command line (all in UTF-8) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    commandLine = jvmtiAllocate((int)strlen(command) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                 (int)strlen(name) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                 (int)strlen(address) + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    if (commandLine == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    (void)strcpy(commandLine, command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    (void)strcat(commandLine, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    (void)strcat(commandLine, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    (void)strcat(commandLine, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    (void)strcat(commandLine, address);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /* Convert commandLine from UTF-8 to platform encoding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    len = (int)strlen(commandLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    buf = jvmtiAllocate(len*3+3);
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   448
    if (buf == NULL) {
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   449
        jvmtiDeallocate(commandLine);
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   450
        return JDWP_ERROR(OUT_OF_MEMORY);
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   451
    }
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents: 23010
diff changeset
   452
    (void)utf8ToPlatform((jbyte*)commandLine, len, buf, len*3+3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /* Exec commandLine */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    rc = dbgsysExec(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /* Free up buffers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    jvmtiDeallocate(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    jvmtiDeallocate(commandLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /* And non-zero exit status means we had an error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (rc != SYS_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return JDWP_ERROR(TRANSPORT_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
transport_startTransport(jboolean isServer, char *name, char *address,
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   470
                         long timeout, char *allowed_peers)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    jvmtiStartFunction func;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    char threadName[MAXPATHLEN + 100];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    jint err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    jdwpError serror;
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   476
    jdwpTransportConfiguration cfg = {0};
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   477
    TransportInfo *info;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   478
    jdwpTransportEnv *trans;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   479
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   480
    info = jvmtiAllocate(sizeof(*info));
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   481
    if (info == NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   482
        return JDWP_ERROR(OUT_OF_MEMORY);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   483
    }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   484
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   485
    info->transport = transport;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   486
    info->transportVersion = transportVersion;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   487
    info->name = NULL;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   488
    info->address = NULL;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   489
    info->allowed_peers = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * If the transport is already loaded then use it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Note: We're assuming here that we don't support multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * transports - when we do then we need to handle the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * where the transport library only supports a single environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * That probably means we have a bag a transport environments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * to correspond to the transports bag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   499
    if (info->transport == NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   500
        serror = loadTransport(name, info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (serror != JDWP_ERROR(NONE)) {
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   502
            freeTransportInfo(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   507
    // Cache the value
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   508
    trans = info->transport;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    if (isServer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        char *retAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        char *launchCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        char* prop_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   517
        info->timeout = timeout;
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   518
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        info->name = jvmtiAllocate((int)strlen(name)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (info->name == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            serror = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            goto handleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   524
        (void)strcpy(info->name, name);
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   525
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (address != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            info->address = jvmtiAllocate((int)strlen(address)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (info->address == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                serror = JDWP_ERROR(OUT_OF_MEMORY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                goto handleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   532
            (void)strcpy(info->address, address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   535
        if (info->transportVersion == JDWPTRANSPORT_VERSION_1_0) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   536
            if (allowed_peers != NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   537
                ERROR_MESSAGE(("Allow parameter is specified but transport doesn't support it"));
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   538
                serror = JDWP_ERROR(TRANSPORT_INIT);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   539
                goto handleError;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   540
            }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   541
        } else {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   542
            /* Memory is allocated only for transport versions > 1.0
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   543
             * as the version 1.0 does not support the 'allow' option.
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   544
             */
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   545
            if (allowed_peers != NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   546
                info->allowed_peers = jvmtiAllocate((int)strlen(allowed_peers) + 1);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   547
                if (info->allowed_peers == NULL) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   548
                    serror = JDWP_ERROR(OUT_OF_MEMORY);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   549
                    goto handleError;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   550
                }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   551
                (void)strcpy(info->allowed_peers, allowed_peers);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   552
            }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   553
            cfg.allowed_peers = info->allowed_peers;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   554
            err = (*trans)->SetTransportConfiguration(trans, &cfg);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   555
            if (err != JDWPTRANSPORT_ERROR_NONE) {
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   556
                printLastError(trans, err);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   557
                serror = JDWP_ERROR(TRANSPORT_INIT);
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   558
                goto handleError;
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   559
            }
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   560
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        err = (*trans)->StartListening(trans, address, &retAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (err != JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            printLastError(trans, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            serror = JDWP_ERROR(TRANSPORT_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            goto handleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         * Record listener address in a system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         */
896
5c02031316bf 6725543: Compiler warnings in serviceability native code
ohair
parents: 2
diff changeset
   572
        len = (int)strlen(name) + (int)strlen(retAddress) + 2; /* ':' and '\0' */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        prop_value = (char*)jvmtiAllocate(len);
27959
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   574
        if (prop_value == NULL) {
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   575
            serror = JDWP_ERROR(OUT_OF_MEMORY);
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   576
            goto handleError;
701e99e828ca 8067030: JDWP crash in transport_startTransport on OOM
dsamersoff
parents: 25859
diff changeset
   577
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        strcpy(prop_value, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        strcat(prop_value, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        strcat(prop_value, retAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        setTransportProperty(getEnv(), prop_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        jvmtiDeallocate(prop_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        (void)strcpy(threadName, "JDWP Transport Listener: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        (void)strcat(threadName, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        func = &acceptThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        error = spawnNewThread(func, (void*)info, threadName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            serror = map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            goto handleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   595
        /* reset info - it will be deallocated by acceptThread */
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   596
        info = NULL;
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   597
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        launchCommand = debugInit_launchOnInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (launchCommand != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            serror = launch(launchCommand, name, retAddress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                goto handleError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            if ( ! gdata->quiet ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                TTY_MESSAGE(("Listening for transport %s at address: %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    name, retAddress));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
handleError:
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   613
        freeTransportInfo(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         * Note that we don't attempt to do a launch here. Launching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         * is currently supported only in server mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * If we're connecting to another process, there shouldn't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * any concurrent listens, so its ok if we block here in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         * thread, waiting for the attach to finish.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         err = (*trans)->Attach(trans, address, timeout, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         if (err != JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
             printLastError(trans, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
             serror = JDWP_ERROR(TRANSPORT_INIT);
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   629
             /* The name, address and allowed_peers fields in 'info'
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   630
              * are not allocated in the non-server case so
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   631
              * they do not need to be freed. */
58220
2c4185d7276a 8186825: some memory leak issues in the transport_startTransport
amenkov
parents: 53184
diff changeset
   632
             freeTransportInfo(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
             return serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
          * Start the transport loop in a separate thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         (void)strcpy(threadName, "JDWP Transport Listener: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         (void)strcat(threadName, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         func = &attachThread;
47121
3aceb4fc0e84 8061228: Allow JDWP socket connector to accept connections from certain ip addresses only
dsamersoff
parents: 39466
diff changeset
   643
         err = spawnNewThread(func, (void*)info, threadName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         serror = map2jdwpError(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    return serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
transport_close(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    if ( transport != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        (*transport)->Close(transport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
transport_is_open(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    jboolean is_open = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    if ( transport != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        is_open = (*transport)->IsOpen(transport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    return is_open;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
transport_sendPacket(jdwpPacket *packet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    jdwpTransportError err = JDWPTRANSPORT_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    jint rc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    if (transport != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if ( (*transport)->IsOpen(transport) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            debugMonitorEnter(sendLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            err = (*transport)->WritePacket(transport, packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            debugMonitorExit(sendLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        if (err != JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            if ((*transport)->IsOpen(transport)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                printLastError(transport, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
             * The users of transport_sendPacket except 0 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
             * success; non-0 otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            rc = (jint)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    } /* else, bit bucket */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
transport_receivePacket(jdwpPacket *packet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    jdwpTransportError err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    err = (*transport)->ReadPacket(transport, packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    if (err != JDWPTRANSPORT_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
         * If transport has been closed return EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (!(*transport)->IsOpen(transport)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            packet->type.cmd.len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        printLastError(transport, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         * Users of transport_receivePacket expect 0 for success,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
         * non-0 otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        return (jint)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
}