8193258: Better usage of JDWP HEADER SIZE

Reviewed-by: sspitsyn, cjplummer
This commit is contained in:
Christoph Langer 2017-12-12 09:16:12 +01:00
parent a760808350
commit 4b41440094
8 changed files with 27 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2017, 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
@ -111,7 +111,7 @@ packetToByteArray(JNIEnv *env, jdwpPacket *str)
jint tmpInt;
total_length = str->type.cmd.len;
data_length = total_length - 11;
data_length = total_length - JDWP_HEADER_SIZE;
/* total packet length is header + data */
array = (*env)->NewByteArray(env, total_length);
@ -142,7 +142,7 @@ packetToByteArray(JNIEnv *env, jdwpPacket *str)
/* finally the data */
if (data_length > 0) {
(*env)->SetByteArrayRegion(env, array, 11,
(*env)->SetByteArrayRegion(env, array, JDWP_HEADER_SIZE,
data_length, str->type.cmd.data);
if ((*env)->ExceptionOccurred(env)) {
return NULL;
@ -168,7 +168,7 @@ byteArrayToPacket(JNIEnv *env, jbyteArray b, jdwpPacket *str)
{
jsize total_length, data_length;
jbyte *data;
unsigned char pktHeader[11]; /* sizeof length + id + flags + cmdSet + cmd */
unsigned char pktHeader[JDWP_HEADER_SIZE];
/*
* Get the packet header

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2017, 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
@ -270,7 +270,7 @@ shmemWritePacket(jdwpTransportEnv* env, const jdwpPacket *packet)
if (packet == NULL) {
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "packet is null");
}
if (packet->type.cmd.len < 11) {
if (packet->type.cmd.len < JDWP_HEADER_SIZE) {
RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "invalid length");
}
if (connection == NULL) {

View File

@ -1049,7 +1049,7 @@ shmemBase_sendPacket(SharedMemoryConnection *connection, const jdwpPacket *packe
CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmd, sizeof(jbyte)));
}
data_length = packet->type.cmd.len - 11;
data_length = packet->type.cmd.len - JDWP_HEADER_SIZE;
SHMEM_GUARANTEE(data_length >= 0);
CHECK_ERROR(sendBytes(connection, &data_length, sizeof(jint)));
@ -1125,10 +1125,10 @@ shmemBase_receivePacket(SharedMemoryConnection *connection, jdwpPacket *packet)
if (data_length < 0) {
return SYS_ERR;
} else if (data_length == 0) {
packet->type.cmd.len = 11;
packet->type.cmd.len = JDWP_HEADER_SIZE;
packet->type.cmd.data = NULL;
} else {
packet->type.cmd.len = data_length + 11;
packet->type.cmd.len = data_length + JDWP_HEADER_SIZE;
packet->type.cmd.data = (*callback->alloc)(data_length);
if (packet->type.cmd.data == NULL) {
return SYS_ERR;

View File

@ -96,6 +96,8 @@ typedef struct {
* See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
*/
#define JDWP_HEADER_SIZE 11
enum {
/*
* If additional flags are added that apply to jdwpCmdPacket,

View File

@ -70,7 +70,6 @@ static jdwpTransportEnv single_env = (jdwpTransportEnv)&interface;
RETURN_IO_ERROR("recv error"); \
}
#define HEADER_SIZE 11
#define MAX_DATA_SIZE 1000
static jint recv_fully(int, char *, int);
@ -790,7 +789,7 @@ socketTransport_writePacket(jdwpTransportEnv* env, const jdwpPacket *packet)
/*
* room for header and up to MAX_DATA_SIZE data bytes
*/
char header[HEADER_SIZE + MAX_DATA_SIZE];
char header[JDWP_HEADER_SIZE + MAX_DATA_SIZE];
jbyte *data;
/* packet can't be null */
@ -799,7 +798,7 @@ socketTransport_writePacket(jdwpTransportEnv* env, const jdwpPacket *packet)
}
len = packet->type.cmd.len; /* includes header */
data_len = len - HEADER_SIZE;
data_len = len - JDWP_HEADER_SIZE;
/* bad packet */
if (data_len < 0) {
@ -825,15 +824,15 @@ socketTransport_writePacket(jdwpTransportEnv* env, const jdwpPacket *packet)
data = packet->type.cmd.data;
/* Do one send for short packets, two for longer ones */
if (data_len <= MAX_DATA_SIZE) {
memcpy(header + HEADER_SIZE, data, data_len);
if (send_fully(socketFD, (char *)&header, HEADER_SIZE + data_len) !=
HEADER_SIZE + data_len) {
memcpy(header + JDWP_HEADER_SIZE, data, data_len);
if (send_fully(socketFD, (char *)&header, JDWP_HEADER_SIZE + data_len) !=
JDWP_HEADER_SIZE + data_len) {
RETURN_IO_ERROR("send failed");
}
} else {
memcpy(header + HEADER_SIZE, data, MAX_DATA_SIZE);
if (send_fully(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE) !=
HEADER_SIZE + MAX_DATA_SIZE) {
memcpy(header + JDWP_HEADER_SIZE, data, MAX_DATA_SIZE);
if (send_fully(socketFD, (char *)&header, JDWP_HEADER_SIZE + MAX_DATA_SIZE) !=
JDWP_HEADER_SIZE + MAX_DATA_SIZE) {
RETURN_IO_ERROR("send failed");
}
/* Send the remaining data bytes right out of the data area. */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2017, 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
@ -43,7 +43,7 @@ inStream_init(PacketInputStream *stream, jdwpPacket packet)
{
stream->packet = packet;
stream->error = JDWP_ERROR(NONE);
stream->left = packet.type.cmd.len;
stream->left = packet.type.cmd.len - JDWP_HEADER_SIZE;
stream->current = packet.type.cmd.data;
stream->refs = bagCreateBag(sizeof(jobject), INITIAL_REF_ALLOC);
if (stream->refs == NULL) {
@ -411,12 +411,6 @@ inStream_readString(PacketInputStream *stream)
return string;
}
jboolean
inStream_endOfInput(PacketInputStream *stream)
{
return (stream->left > 0);
}
jdwpError
inStream_error(PacketInputStream *stream)
{
@ -424,7 +418,8 @@ inStream_error(PacketInputStream *stream)
}
void
inStream_clearError(PacketInputStream *stream) {
inStream_clearError(PacketInputStream *stream)
{
stream->error = JDWP_ERROR(NONE);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2017, 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
@ -74,7 +74,6 @@ jvalue inStream_readValue(struct PacketInputStream *in, jbyte *typeKeyPtr);
jdwpError inStream_skipBytes(PacketInputStream *stream, jint count);
jboolean inStream_endOfInput(PacketInputStream *stream);
jdwpError inStream_error(PacketInputStream *stream);
void inStream_clearError(PacketInputStream *stream);
void inStream_destroy(PacketInputStream *stream);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2017, 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
@ -418,7 +418,7 @@ outStream_send(PacketOutputStream *stream) {
* packet.
*/
if (stream->firstSegment.next == NULL) {
stream->packet.type.cmd.len = 11 + stream->firstSegment.length;
stream->packet.type.cmd.len = JDWP_HEADER_SIZE + stream->firstSegment.length;
stream->packet.type.cmd.data = stream->firstSegment.data;
rc = transport_sendPacket(&stream->packet);
return rc;
@ -447,7 +447,7 @@ outStream_send(PacketOutputStream *stream) {
segment = segment->next;
}
stream->packet.type.cmd.len = 11 + len;
stream->packet.type.cmd.len = JDWP_HEADER_SIZE + len;
stream->packet.type.cmd.data = data;
rc = transport_sendPacket(&stream->packet);
stream->packet.type.cmd.data = NULL;