src/java.base/unix/native/libjava/jni_util_md.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     1
/*
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     4
 *
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    10
 *
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    15
 * accompanied this code).
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    16
 *
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    23
 * questions.
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    24
 */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    25
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    26
#include <errno.h>
22572
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    27
#include <string.h>
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    28
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    29
#include "jni.h"
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    30
#include "jni_util.h"
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    31
#include "dlfcn.h"
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents:
diff changeset
    32
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    33
#if defined(LINUX) && (defined(_GNU_SOURCE) || \
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    34
         (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 200112L \
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    35
             && defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 600))
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    36
extern int __xpg_strerror_r(int, char *, size_t);
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    37
#define strerror_r(a, b, c) __xpg_strerror_r((a), (b), (c))
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    38
#endif
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    39
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    40
void* getProcessHandle(void) {
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    41
    static void *procHandle = NULL;
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    42
    if (procHandle != NULL) {
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    43
        return procHandle;
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    44
    }
22572
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    45
#ifdef __APPLE__
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    46
    procHandle = (void*)dlopen(NULL, RTLD_FIRST);
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    47
#else
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    48
    procHandle = (void*)dlopen(NULL, RTLD_LAZY);
22572
0680f54048ba 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X
alanb
parents: 16479
diff changeset
    49
#endif
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    50
    return procHandle;
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    51
}
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    52
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    53
void buildJniFunctionName(const char *sym, const char *cname,
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    54
                          char *jniEntryName) {
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    55
    strcpy(jniEntryName, sym);
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    56
    if (cname != NULL) {
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    57
        strcat(jniEntryName, "_");
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    58
        strcat(jniEntryName, cname);
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    59
    }
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    60
}
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 5506
diff changeset
    61
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    62
size_t
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    63
getLastErrorString(char *buf, size_t len)
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    64
{
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    65
    if (errno == 0 || len < 1) return 0;
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    66
    getErrorString(errno, buf, len);
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    67
    return strlen(buf);
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    68
}
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    69
32846
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    70
int
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    71
getErrorString(int err, char *buf, size_t len)
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    72
{
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    73
    if (err == 0 || len < 1) return 0;
5383225ebd0d 8133249: Occasional SIGSEGV: non thread-safe use of strerr in getLastErrorString
robm
parents: 29723
diff changeset
    74
    return strerror_r(err, buf, len);
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
    75
}