1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 #include <string.h>
26
27 #include "jdwpTransport.h"
28 #include "shmemBase.h"
29 #include "sysShmem.h"
30 #include "sys.h"
31
32 /*
33 * The Shared Memory Transport Library.
34 *
35 * This module is an implementation of the Java Debug Wire Protocol Transport
36 * Service Provider Interface - see src/share/javavm/export/jdwpTransport.h.
37 */
38
39 static SharedMemoryTransport *transport = NULL; /* maximum of 1 transport */
40 static SharedMemoryConnection *connection = NULL; /* maximum of 1 connection */
41 static jdwpTransportCallback *callbacks;
42 static jboolean initialized;
43 static struct jdwpTransportNativeInterface_ interface;
44 static jdwpTransportEnv single_env = (jdwpTransportEnv)&interface;
45
321 }
322
323 /*
324 * Return the error message for this thread.
325 */
326 static jdwpTransportError JNICALL
327 shmemGetLastError(jdwpTransportEnv* env, char **msgP)
328 {
329 char *msg = (char *)sysTlsGet(tlsIndex);
330 if (msg == NULL) {
331 return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE;
332 }
333 *msgP = (*callbacks->alloc)((int)strlen(msg)+1);
334 if (*msgP == NULL) {
335 return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
336 }
337 strcpy(*msgP, msg);
338 return JDWPTRANSPORT_ERROR_NONE;
339 }
340
341 jint JNICALL
342 jdwpTransport_OnLoad(JavaVM *vm, jdwpTransportCallback* cbTablePtr,
343 jint version, jdwpTransportEnv** result)
344 {
345 if (version != JDWPTRANSPORT_VERSION_1_0) {
346 return JNI_EVERSION;
347 }
348 if (initialized) {
349 /*
350 * This library doesn't support multiple environments (yet)
351 */
352 return JNI_EEXIST;
353 }
354 initialized = JNI_TRUE;
355
356 /* initialize base shared memory system */
357 (void) shmemBase_initialize(vm, cbTablePtr);
358
359 /* save callbacks */
360 callbacks = cbTablePtr;
361
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 #include <string.h>
26 #include "jni.h"
27
28 #include "jdwpTransport.h"
29 #include "shmemBase.h"
30 #include "sysShmem.h"
31 #include "sys.h"
32
33 /*
34 * The Shared Memory Transport Library.
35 *
36 * This module is an implementation of the Java Debug Wire Protocol Transport
37 * Service Provider Interface - see src/share/javavm/export/jdwpTransport.h.
38 */
39
40 static SharedMemoryTransport *transport = NULL; /* maximum of 1 transport */
41 static SharedMemoryConnection *connection = NULL; /* maximum of 1 connection */
42 static jdwpTransportCallback *callbacks;
43 static jboolean initialized;
44 static struct jdwpTransportNativeInterface_ interface;
45 static jdwpTransportEnv single_env = (jdwpTransportEnv)&interface;
46
322 }
323
324 /*
325 * Return the error message for this thread.
326 */
327 static jdwpTransportError JNICALL
328 shmemGetLastError(jdwpTransportEnv* env, char **msgP)
329 {
330 char *msg = (char *)sysTlsGet(tlsIndex);
331 if (msg == NULL) {
332 return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE;
333 }
334 *msgP = (*callbacks->alloc)((int)strlen(msg)+1);
335 if (*msgP == NULL) {
336 return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
337 }
338 strcpy(*msgP, msg);
339 return JDWPTRANSPORT_ERROR_NONE;
340 }
341
342 JNIEXPORT jint JNICALL
343 jdwpTransport_OnLoad(JavaVM *vm, jdwpTransportCallback* cbTablePtr,
344 jint version, jdwpTransportEnv** result)
345 {
346 if (version != JDWPTRANSPORT_VERSION_1_0) {
347 return JNI_EVERSION;
348 }
349 if (initialized) {
350 /*
351 * This library doesn't support multiple environments (yet)
352 */
353 return JNI_EEXIST;
354 }
355 initialized = JNI_TRUE;
356
357 /* initialize base shared memory system */
358 (void) shmemBase_initialize(vm, cbTablePtr);
359
360 /* save callbacks */
361 callbacks = cbTablePtr;
362
|