jpayne@69: /* jpayne@69: * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. jpayne@69: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jpayne@69: * jpayne@69: * This code is free software; you can redistribute it and/or modify it jpayne@69: * under the terms of the GNU General Public License version 2 only, as jpayne@69: * published by the Free Software Foundation. Oracle designates this jpayne@69: * particular file as subject to the "Classpath" exception as provided jpayne@69: * by Oracle in the LICENSE file that accompanied this code. jpayne@69: * jpayne@69: * This code is distributed in the hope that it will be useful, but WITHOUT jpayne@69: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jpayne@69: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jpayne@69: * version 2 for more details (a copy is included in the LICENSE file that jpayne@69: * accompanied this code). jpayne@69: * jpayne@69: * You should have received a copy of the GNU General Public License version jpayne@69: * 2 along with this work; if not, write to the Free Software Foundation, jpayne@69: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jpayne@69: * jpayne@69: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jpayne@69: * or visit www.oracle.com if you need additional information or have any jpayne@69: * questions. jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * Java Debug Wire Protocol Transport Service Provider Interface. jpayne@69: */ jpayne@69: jpayne@69: #ifndef JDWPTRANSPORT_H jpayne@69: #define JDWPTRANSPORT_H jpayne@69: jpayne@69: #include "jni.h" jpayne@69: jpayne@69: enum { jpayne@69: JDWPTRANSPORT_VERSION_1_0 = 0x00010000, jpayne@69: JDWPTRANSPORT_VERSION_1_1 = 0x00010001 jpayne@69: }; jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: struct jdwpTransportNativeInterface_; jpayne@69: jpayne@69: struct _jdwpTransportEnv; jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: typedef _jdwpTransportEnv jdwpTransportEnv; jpayne@69: #else jpayne@69: typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv; jpayne@69: #endif /* __cplusplus */ jpayne@69: jpayne@69: /* jpayne@69: * Errors. Universal errors with JVMTI/JVMDI equivalents keep the jpayne@69: * values the same. jpayne@69: */ jpayne@69: typedef enum { jpayne@69: JDWPTRANSPORT_ERROR_NONE = 0, jpayne@69: JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103, jpayne@69: JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110, jpayne@69: JDWPTRANSPORT_ERROR_INTERNAL = 113, jpayne@69: JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201, jpayne@69: JDWPTRANSPORT_ERROR_IO_ERROR = 202, jpayne@69: JDWPTRANSPORT_ERROR_TIMEOUT = 203, jpayne@69: JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204 jpayne@69: } jdwpTransportError; jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Structure to define capabilities jpayne@69: */ jpayne@69: typedef struct { jpayne@69: unsigned int can_timeout_attach :1; jpayne@69: unsigned int can_timeout_accept :1; jpayne@69: unsigned int can_timeout_handshake :1; jpayne@69: unsigned int reserved3 :1; jpayne@69: unsigned int reserved4 :1; jpayne@69: unsigned int reserved5 :1; jpayne@69: unsigned int reserved6 :1; jpayne@69: unsigned int reserved7 :1; jpayne@69: unsigned int reserved8 :1; jpayne@69: unsigned int reserved9 :1; jpayne@69: unsigned int reserved10 :1; jpayne@69: unsigned int reserved11 :1; jpayne@69: unsigned int reserved12 :1; jpayne@69: unsigned int reserved13 :1; jpayne@69: unsigned int reserved14 :1; jpayne@69: unsigned int reserved15 :1; jpayne@69: } JDWPTransportCapabilities; jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Structures to define packet layout. jpayne@69: * jpayne@69: * See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html jpayne@69: */ jpayne@69: jpayne@69: #define JDWP_HEADER_SIZE 11 jpayne@69: jpayne@69: enum { jpayne@69: /* jpayne@69: * If additional flags are added that apply to jdwpCmdPacket, jpayne@69: * then debugLoop.c: reader() will need to be updated to jpayne@69: * accept more than JDWPTRANSPORT_FLAGS_NONE. jpayne@69: */ jpayne@69: JDWPTRANSPORT_FLAGS_NONE = 0x0, jpayne@69: JDWPTRANSPORT_FLAGS_REPLY = 0x80 jpayne@69: }; jpayne@69: jpayne@69: typedef struct { jpayne@69: jint len; jpayne@69: jint id; jpayne@69: jbyte flags; jpayne@69: jbyte cmdSet; jpayne@69: jbyte cmd; jpayne@69: jbyte *data; jpayne@69: } jdwpCmdPacket; jpayne@69: jpayne@69: typedef struct { jpayne@69: jint len; jpayne@69: jint id; jpayne@69: jbyte flags; jpayne@69: jshort errorCode; jpayne@69: jbyte *data; jpayne@69: } jdwpReplyPacket; jpayne@69: jpayne@69: typedef struct { jpayne@69: union { jpayne@69: jdwpCmdPacket cmd; jpayne@69: jdwpReplyPacket reply; jpayne@69: } type; jpayne@69: } jdwpPacket; jpayne@69: jpayne@69: /* jpayne@69: * JDWP functions called by the transport. jpayne@69: */ jpayne@69: typedef struct jdwpTransportCallback { jpayne@69: void *(*alloc)(jint numBytes); /* Call this for all allocations */ jpayne@69: void (*free)(void *buffer); /* Call this for all deallocations */ jpayne@69: } jdwpTransportCallback; jpayne@69: jpayne@69: typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm, jpayne@69: jdwpTransportCallback *callback, jpayne@69: jint version, jpayne@69: jdwpTransportEnv** env); jpayne@69: jpayne@69: /* jpayne@69: * JDWP transport configuration from the agent. jpayne@69: */ jpayne@69: typedef struct jdwpTransportConfiguration { jpayne@69: /* Field added in JDWPTRANSPORT_VERSION_1_1: */ jpayne@69: const char* allowed_peers; /* Peers allowed for connection */ jpayne@69: } jdwpTransportConfiguration; jpayne@69: jpayne@69: jpayne@69: /* Function Interface */ jpayne@69: jpayne@69: struct jdwpTransportNativeInterface_ { jpayne@69: /* 1 : RESERVED */ jpayne@69: void *reserved1; jpayne@69: jpayne@69: /* 2 : Get Capabilities */ jpayne@69: jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env, jpayne@69: JDWPTransportCapabilities *capabilities_ptr); jpayne@69: jpayne@69: /* 3 : Attach */ jpayne@69: jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env, jpayne@69: const char* address, jpayne@69: jlong attach_timeout, jpayne@69: jlong handshake_timeout); jpayne@69: jpayne@69: /* 4: StartListening */ jpayne@69: jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env, jpayne@69: const char* address, jpayne@69: char** actual_address); jpayne@69: jpayne@69: /* 5: StopListening */ jpayne@69: jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env); jpayne@69: jpayne@69: /* 6: Accept */ jpayne@69: jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env, jpayne@69: jlong accept_timeout, jpayne@69: jlong handshake_timeout); jpayne@69: jpayne@69: /* 7: IsOpen */ jpayne@69: jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env); jpayne@69: jpayne@69: /* 8: Close */ jpayne@69: jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env); jpayne@69: jpayne@69: /* 9: ReadPacket */ jpayne@69: jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env, jpayne@69: jdwpPacket *pkt); jpayne@69: jpayne@69: /* 10: Write Packet */ jpayne@69: jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env, jpayne@69: const jdwpPacket* pkt); jpayne@69: jpayne@69: /* 11: GetLastError */ jpayne@69: jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env, jpayne@69: char** error); jpayne@69: jpayne@69: /* 12: SetTransportConfiguration added in JDWPTRANSPORT_VERSION_1_1 */ jpayne@69: jdwpTransportError (JNICALL *SetTransportConfiguration)(jdwpTransportEnv* env, jpayne@69: jdwpTransportConfiguration *config); jpayne@69: }; jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Use inlined functions so that C++ code can use syntax such as jpayne@69: * env->Attach("mymachine:5000", 10*1000, 0); jpayne@69: * jpayne@69: * rather than using C's :- jpayne@69: * jpayne@69: * (*env)->Attach(env, "mymachine:5000", 10*1000, 0); jpayne@69: */ jpayne@69: struct _jdwpTransportEnv { jpayne@69: const struct jdwpTransportNativeInterface_ *functions; jpayne@69: #ifdef __cplusplus jpayne@69: jpayne@69: jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) { jpayne@69: return functions->GetCapabilities(this, capabilities_ptr); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError Attach(const char* address, jlong attach_timeout, jpayne@69: jlong handshake_timeout) { jpayne@69: return functions->Attach(this, address, attach_timeout, handshake_timeout); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError StartListening(const char* address, jpayne@69: char** actual_address) { jpayne@69: return functions->StartListening(this, address, actual_address); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError StopListening(void) { jpayne@69: return functions->StopListening(this); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) { jpayne@69: return functions->Accept(this, accept_timeout, handshake_timeout); jpayne@69: } jpayne@69: jpayne@69: jboolean IsOpen(void) { jpayne@69: return functions->IsOpen(this); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError Close(void) { jpayne@69: return functions->Close(this); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError ReadPacket(jdwpPacket *pkt) { jpayne@69: return functions->ReadPacket(this, pkt); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError WritePacket(const jdwpPacket* pkt) { jpayne@69: return functions->WritePacket(this, pkt); jpayne@69: } jpayne@69: jpayne@69: jdwpTransportError GetLastError(char** error) { jpayne@69: return functions->GetLastError(this, error); jpayne@69: } jpayne@69: jpayne@69: /* SetTransportConfiguration added in JDWPTRANSPORT_VERSION_1_1 */ jpayne@69: jdwpTransportError SetTransportConfiguration(jdwpTransportEnv* env, jpayne@69: return functions->SetTransportConfiguration(this, config); jpayne@69: } jpayne@69: jpayne@69: #endif /* __cplusplus */ jpayne@69: }; jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } /* extern "C" */ jpayne@69: #endif /* __cplusplus */ jpayne@69: jpayne@69: #endif /* JDWPTRANSPORT_H */