src/jdk.attach/aix/native/libattach/VirtualMachineImpl.c

Print this page
rev 11622 : 8071687: AIX port of "8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework"
   1 /*
   2  * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2014 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.  Oracle designates this
   9  * particular file as subject to the "Classpath" exception as provided
  10  * by Oracle in the LICENSE file that accompanied this code.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23  * or visit www.oracle.com if you need additional information or have any


 221     RESTARTABLE(close(fd), res);
 222 }
 223 
 224 /*
 225  * Class:     sun_tools_attach_VirtualMachineImpl
 226  * Method:    read
 227  * Signature: (I[BI)I
 228  */
 229 JNIEXPORT jint JNICALL Java_sun_tools_attach_VirtualMachineImpl_read
 230   (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint baLen)
 231 {
 232     unsigned char buf[128];
 233     size_t len = sizeof(buf);
 234     ssize_t n;
 235 
 236     size_t remaining = (size_t)(baLen - off);
 237     if (len > remaining) {
 238         len = remaining;
 239     }
 240 
 241     RESTARTABLE(read(fd, buf+off, len), n);
 242     if (n == -1) {
 243         JNU_ThrowIOExceptionWithLastError(env, "read");
 244     } else {
 245         if (n == 0) {
 246             n = -1;     // EOF
 247         } else {
 248             (*env)->SetByteArrayRegion(env, ba, off, (jint)n, (jbyte *)(buf+off));
 249         }
 250     }
 251     return n;
 252 }
 253 
 254 /*
 255  * Class:     sun_tools_attach_VirtualMachineImpl
 256  * Method:    write
 257  * Signature: (I[B)V
 258  */
 259 JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_write
 260   (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint bufLen)
 261 {
 262     size_t remaining = bufLen;
 263     do {
 264         unsigned char buf[128];
 265         size_t len = sizeof(buf);
 266         int n;
 267 
 268         if (len > remaining) {
   1 /*
   2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2015 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.  Oracle designates this
   9  * particular file as subject to the "Classpath" exception as provided
  10  * by Oracle in the LICENSE file that accompanied this code.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23  * or visit www.oracle.com if you need additional information or have any


 221     RESTARTABLE(close(fd), res);
 222 }
 223 
 224 /*
 225  * Class:     sun_tools_attach_VirtualMachineImpl
 226  * Method:    read
 227  * Signature: (I[BI)I
 228  */
 229 JNIEXPORT jint JNICALL Java_sun_tools_attach_VirtualMachineImpl_read
 230   (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint baLen)
 231 {
 232     unsigned char buf[128];
 233     size_t len = sizeof(buf);
 234     ssize_t n;
 235 
 236     size_t remaining = (size_t)(baLen - off);
 237     if (len > remaining) {
 238         len = remaining;
 239     }
 240 
 241     RESTARTABLE(read(fd, buf, len), n);
 242     if (n == -1) {
 243         JNU_ThrowIOExceptionWithLastError(env, "read");
 244     } else {
 245         if (n == 0) {
 246             n = -1;     // EOF
 247         } else {
 248             (*env)->SetByteArrayRegion(env, ba, off, (jint)n, (jbyte *)(buf));
 249         }
 250     }
 251     return n;
 252 }
 253 
 254 /*
 255  * Class:     sun_tools_attach_VirtualMachineImpl
 256  * Method:    write
 257  * Signature: (I[B)V
 258  */
 259 JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_write
 260   (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint bufLen)
 261 {
 262     size_t remaining = bufLen;
 263     do {
 264         unsigned char buf[128];
 265         size_t len = sizeof(buf);
 266         int n;
 267 
 268         if (len > remaining) {