/* * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ #include <string.h> #include"jni.h"
/* * The Shared Memory Transport Library. * * This module is an implementation of the Java Debug Wire Protocol Transport * Service Provider Interface - see src/share/javavm/export/jdwpTransport.h.
*/
static SharedMemoryTransport *transport = NULL; /* maximum of 1 transport */ static SharedMemoryConnection *connection = NULL; /* maximum of 1 connection */ static jdwpTransportCallback *callbacks; static jboolean initialized; staticstruct jdwpTransportNativeInterface_ interface; static jdwpTransportEnv single_env = (jdwpTransportEnv)&interface;
/* * Thread-local index to the per-thread error message
*/ staticint tlsIndex;
/* * Return an error and record the error message associated with * the error. Note the if (1==1) { } usage here is to avoid * compilers complaining that a statement isn't reached which * will arise if the semicolon (;) appears after the macro,
*/ #define RETURN_ERROR(err, msg) \ if (1==1) { \
setLastError(err, msg); \ return err; \
}
/* * Return an I/O error and record the error message.
*/ #define RETURN_IO_ERROR(msg) RETURN_ERROR(JDWPTRANSPORT_ERROR_IO_ERROR, msg);
/* * Set the error message for this thread. If the error is an I/O * error then augment the supplied error message with the textual * representation of the I/O error.
*/ staticvoid
setLastError(int err, char *newmsg) { char buf[255]; char *msg;
/* get any I/O first in case any system calls override errno */ if (err == JDWPTRANSPORT_ERROR_IO_ERROR) { if (shmemBase_getlasterror(buf, sizeof(buf)) != SYS_OK) {
buf[0] = '\0';
}
}
/* free any current error */
msg = (char *)sysTlsGet(tlsIndex); if (msg != NULL) {
(*callbacks->free)(msg);
}
/* * For I/O errors append the I/O error message with to the * supplied message. For all other errors just use the supplied * message.
*/ if (err == JDWPTRANSPORT_ERROR_IO_ERROR) { char *join_str = ": "; int msg_len = (int)strlen(newmsg) + (int)strlen(join_str) +
(int)strlen(buf) + 3;
msg = (*callbacks->alloc)(msg_len); if (msg != NULL) {
strcpy(msg, newmsg);
strcat(msg, join_str);
strcat(msg, buf);
}
} else {
msg = (*callbacks->alloc)((int)strlen(newmsg)+1); if (msg != NULL) {
strcpy(msg, newmsg);
}
}
/* Put a pointer to the message in TLS */
sysTlsPut(tlsIndex, msg);
}
for (i=0; i<strlen(hello); i++) {
jbyte b; int rv = shmemBase_receiveByte(connection, &b); if (rv != 0) {
RETURN_IO_ERROR("receive failed during handshake");
} if ((char)b != hello[i]) {
RETURN_IO_ERROR("handshake failed - debugger sent unexpected message");
}
}
for (i=0; i<strlen(hello); i++) { int rv = shmemBase_sendByte(connection, (jbyte)hello[i]); if (rv != 0) {
RETURN_IO_ERROR("write failed during handshake");
}
}
return JDWPTRANSPORT_ERROR_NONE;
}
/* * Return the capabilities of the shared memory transport. The shared * memory transport supports both the attach and accept timeouts but * doesn't support a handshake timeout.
*/ static jdwpTransportError JNICALL
shmemGetCapabilities(jdwpTransportEnv* env, JDWPTransportCapabilities *capabilitiesPtr)
{
JDWPTransportCapabilities result;
if (connection != NULL || transport != NULL) {
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_STATE, "already connected or already listening");
}
rc = shmemBase_listen(address, &transport);
/* * If a name was selected by the function above, find it and return * it in place of the original arg.
*/ if (rc == SYS_OK) { char *name; char *name2;
rc = shmemBase_name(transport, &name); if (rc == SYS_OK) {
name2 = (callbacks->alloc)((int)strlen(name) + 1); if (name2 == NULL) {
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory");
} else {
strcpy(name2, name);
*actualAddress = name2;
}
}
} else {
RETURN_IO_ERROR("failed to create shared memory listener");
} return JDWPTRANSPORT_ERROR_NONE;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.