jdk/src/jdk.pack200/share/native/common-unpack/defines.h
author ksrini
Thu, 07 Apr 2016 12:54:23 -0700
changeset 36960 d7731fdfe7c3
parent 29368 be944a521c76
permissions -rw-r--r--
8150469: unpack200 fails to compare crc correctly. Reviewed-by: jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
     2
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
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: 2624
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
// random definitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#ifdef _MSC_VER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <winuser.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    35
#ifndef NO_ZLIB
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    36
#include <zconf.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    37
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    38
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#ifndef FULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define FULL 1 /* Adds <500 bytes to the zipped final product. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#if FULL  // define this if you want debugging and/or compile-time attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define IF_FULL(x) x
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define IF_FULL(x) /*x*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#ifdef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define IF_PRODUCT(xxx) xxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define NOT_PRODUCT(xxx)
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    52
#define assert(p)
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    53
#define PRINTCR(args)
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
    54
#define VERSION_STRING "%s version %s\n"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define IF_PRODUCT(xxx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define NOT_PRODUCT(xxx) xxx
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    58
#define assert(p) ((p) || assert_failed(#p))
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    59
#define PRINTCR(args)  u->verbose && u->printcr_if_verbose args
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
    60
#define VERSION_STRING "%s version non-product %s\n"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
extern "C" void breakpoint();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    62
extern int assert_failed(const char*);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#define BREAK (breakpoint())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
// Build-time control of some C++ inlining.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
// To make a slightly faster smaller binary, say "CC -Dmaybe_inline=inline"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#ifndef maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define maybe_inline /*inline*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
// By marking larger member functions inline, we remove external linkage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#ifndef local_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define local_inline inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
// Error messages that we have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define ERROR_ENOMEM    "Native allocation failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define ERROR_FORMAT    "Corrupted pack file"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define ERROR_RESOURCE  "Cannot extract resource file"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define ERROR_OVERFLOW  "Internal buffer overflow"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define ERROR_INTERNAL  "Internal error"
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 22258
diff changeset
    82
#define ERROR_INIT      "cannot init class members"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define LOGFILE_STDOUT "-"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#define LOGFILE_STDERR ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define lengthof(array) (sizeof(array)/sizeof(array[0]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
2624
asaha
parents: 1082 2607
diff changeset
    89
#define NEW(T, n)    (T*) must_malloc((int)(scale_size(n, sizeof(T))))
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
    90
#define U_NEW(T, n)  (T*) u->alloc(scale_size(n, sizeof(T)))
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
    91
#define T_NEW(T, n)  (T*) u->temp_alloc(scale_size(n, sizeof(T)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    93
// Dealing with big-endian arch
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    94
#ifdef _BIG_ENDIAN
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    95
#define SWAP_INT(a) (((a>>24)&0xff) | ((a<<8)&0xff0000) | ((a>>8)&0xff00) | ((a<<24)&0xff000000))
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    96
#else
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    97
#define SWAP_INT(a) (a)
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29368
diff changeset
    98
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
// bytes and byte arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
typedef unsigned int uint;
13567
b124faa29aef 7110151: Use underlying platform's zlib library for Java zlib support
andrew
parents: 12544
diff changeset
   103
#if defined(NO_ZLIB)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#ifdef _LP64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
typedef unsigned int uLong; // Historical zlib, should be 32-bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
typedef unsigned long uLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   109
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#ifdef _MSC_VER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
typedef LONGLONG        jlong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
typedef DWORDLONG       julong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#define MKDIR(dir)      mkdir(dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#define getpid()        _getpid()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#define PATH_MAX        MAX_PATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#define dup2(a,b)       _dup2(a,b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#define strcasecmp(s1, s2) _stricmp(s1,s2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#define tempname        _tempname
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 12047
diff changeset
   119
#define sleep           Sleep
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 12047
diff changeset
   120
#define snprintf        _snprintf
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
typedef signed char byte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#ifdef _LP64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
typedef long jlong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
typedef long unsigned julong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
typedef long long jlong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
typedef long long unsigned julong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#define MKDIR(dir) mkdir(dir, 0777);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#ifdef OLDCC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
typedef int bool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
enum { false, true };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#define null (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   140
/* Must cast to void *, then size_t, then int. */
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   141
#define ptrlowbits(x)  ((int)(size_t)(void*)(x))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   143
/* Back and forth from jlong to pointer */
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   144
#define ptr2jlong(x)  ((jlong)(size_t)(void*)(x))
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   145
#define jlong2ptr(x)  ((void*)(size_t)(x))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
// Keys used by Java:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
#define UNPACK_DEFLATE_HINT             "unpack.deflate.hint"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#define COM_PREFIX                      "com.sun.java.util.jar.pack."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
#define UNPACK_MODIFICATION_TIME        COM_PREFIX"unpack.modification.time"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#define DEBUG_VERBOSE                   COM_PREFIX"verbose"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
#define ZIP_ARCHIVE_MARKER_COMMENT      "PACK200"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
// The following are not known to the Java classes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#define UNPACK_LOG_FILE                 COM_PREFIX"unpack.log.file"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#define UNPACK_REMOVE_PACKFILE          COM_PREFIX"unpack.remove.packfile"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
// Called from unpacker layers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#define _CHECK_DO(t,x)          { if (t) {x;} }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#define CHECK                   _CHECK_DO(aborting(), return)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#define CHECK_(y)               _CHECK_DO(aborting(), return y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#define CHECK_0                 _CHECK_DO(aborting(), return 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   168
#define CHECK_COUNT(t)          if (t < 0){abort("bad value count");} CHECK
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#define STR_TRUE   "true"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#define STR_FALSE  "false"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#define STR_TF(x)  ((x) ?  STR_TRUE : STR_FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#define BOOL_TF(x) (((x) != null && strcmp((x),STR_TRUE) == 0) ? true : false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
#define DEFAULT_ARCHIVE_MODTIME 1060000000 // Aug 04, 2003 5:26 PM PDT