@bravemobile/react-native-code-push 13.0.0 → 13.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CodePush.podspec +35 -3
  2. package/README.md +117 -3
  3. package/THIRD-PARTY-NOTICES +96 -0
  4. package/android/app/build.gradle +19 -0
  5. package/android/app/proguard-rules.pro +5 -0
  6. package/android/app/src/main/cpp/CMakeLists.txt +38 -0
  7. package/android/app/src/main/cpp/binarypatch_jni.c +181 -0
  8. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchAttempt.java +92 -0
  9. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchResult.java +64 -0
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +1 -1
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBinaryPatch.java +293 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +25 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +20 -6
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +168 -4
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +7 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressEventDispatcher.java +25 -4
  18. package/android/app/src/main/java/com/microsoft/codepush/react/HDiffPatchNative.java +52 -0
  19. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushBinaryPatchTest.java +393 -0
  20. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerBinaryPatchTest.java +211 -0
  21. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerDownloadTest.java +489 -0
  22. package/android/app/src/test/java/com/microsoft/codepush/react/DownloadProgressEventDispatcherTest.java +80 -0
  23. package/android/codepush-export.gradle +115 -0
  24. package/cli/commands/bundleCommand/bundleCodePush.ts +39 -7
  25. package/cli/commands/bundleCommand/index.ts +9 -1
  26. package/cli/commands/releaseCommand/addToReleaseHistory.ts +7 -0
  27. package/cli/commands/releaseCommand/index.test.ts +118 -0
  28. package/cli/commands/releaseCommand/index.ts +20 -2
  29. package/cli/commands/releaseCommand/release.test.ts +582 -0
  30. package/cli/commands/releaseCommand/release.ts +232 -15
  31. package/cli/dist/commands/bundleCommand/bundleCodePush.js +26 -7
  32. package/cli/dist/commands/bundleCommand/index.js +5 -1
  33. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +6 -1
  34. package/cli/dist/commands/releaseCommand/index.js +8 -1
  35. package/cli/dist/commands/releaseCommand/index.test.js +96 -0
  36. package/cli/dist/commands/releaseCommand/release.js +165 -17
  37. package/cli/dist/commands/releaseCommand/release.test.js +367 -0
  38. package/cli/dist/functions/makeBinaryPatchBundle.js +248 -0
  39. package/cli/dist/functions/makeBinaryPatchBundle.test.js +321 -0
  40. package/cli/dist/functions/makeCodePushBundle.js +4 -2
  41. package/cli/dist/functions/runHermesEmitBinaryCommand.js +48 -1
  42. package/cli/dist/functions/runHermesEmitBinaryCommand.test.js +100 -0
  43. package/cli/dist/jest.globalSetup.js +38 -0
  44. package/cli/dist/utils/binaryPatch.js +86 -0
  45. package/cli/dist/utils/binaryPatch.test.js +190 -0
  46. package/cli/functions/makeBinaryPatchBundle.test.ts +410 -0
  47. package/cli/functions/makeBinaryPatchBundle.ts +367 -0
  48. package/cli/functions/makeCodePushBundle.ts +4 -2
  49. package/cli/functions/runHermesEmitBinaryCommand.test.ts +124 -0
  50. package/cli/functions/runHermesEmitBinaryCommand.ts +57 -1
  51. package/cli/jest.globalSetup.ts +43 -0
  52. package/cli/utils/binaryPatch.test.ts +234 -0
  53. package/cli/utils/binaryPatch.ts +103 -0
  54. package/cpp/binarypatch/binarypatch_zstd_decompressor.c +187 -0
  55. package/cpp/binarypatch/binarypatch_zstd_decompressor.h +47 -0
  56. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/checksum_plugin.h +52 -0
  57. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/hpatch_mt/hpatch_mt.h +147 -0
  58. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.c +3315 -0
  59. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.h +268 -0
  60. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_private.h +297 -0
  61. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_types.h +434 -0
  62. package/cpp/binarypatch/vendor/zstd/common/allocations.h +55 -0
  63. package/cpp/binarypatch/vendor/zstd/common/bits.h +205 -0
  64. package/cpp/binarypatch/vendor/zstd/common/bitstream.h +454 -0
  65. package/cpp/binarypatch/vendor/zstd/common/compiler.h +464 -0
  66. package/cpp/binarypatch/vendor/zstd/common/cpu.h +249 -0
  67. package/cpp/binarypatch/vendor/zstd/common/debug.c +30 -0
  68. package/cpp/binarypatch/vendor/zstd/common/debug.h +107 -0
  69. package/cpp/binarypatch/vendor/zstd/common/entropy_common.c +340 -0
  70. package/cpp/binarypatch/vendor/zstd/common/error_private.c +64 -0
  71. package/cpp/binarypatch/vendor/zstd/common/error_private.h +158 -0
  72. package/cpp/binarypatch/vendor/zstd/common/fse.h +625 -0
  73. package/cpp/binarypatch/vendor/zstd/common/fse_decompress.c +315 -0
  74. package/cpp/binarypatch/vendor/zstd/common/huf.h +277 -0
  75. package/cpp/binarypatch/vendor/zstd/common/mem.h +422 -0
  76. package/cpp/binarypatch/vendor/zstd/common/pool.c +371 -0
  77. package/cpp/binarypatch/vendor/zstd/common/pool.h +81 -0
  78. package/cpp/binarypatch/vendor/zstd/common/portability_macros.h +171 -0
  79. package/cpp/binarypatch/vendor/zstd/common/threading.c +182 -0
  80. package/cpp/binarypatch/vendor/zstd/common/threading.h +142 -0
  81. package/cpp/binarypatch/vendor/zstd/common/xxhash.c +18 -0
  82. package/cpp/binarypatch/vendor/zstd/common/xxhash.h +7094 -0
  83. package/cpp/binarypatch/vendor/zstd/common/zstd_common.c +48 -0
  84. package/cpp/binarypatch/vendor/zstd/common/zstd_deps.h +123 -0
  85. package/cpp/binarypatch/vendor/zstd/common/zstd_internal.h +324 -0
  86. package/cpp/binarypatch/vendor/zstd/common/zstd_trace.h +156 -0
  87. package/cpp/binarypatch/vendor/zstd/decompress/huf_decompress.c +1944 -0
  88. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.c +244 -0
  89. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.h +44 -0
  90. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress.c +2410 -0
  91. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.c +2209 -0
  92. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.h +73 -0
  93. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_internal.h +240 -0
  94. package/cpp/binarypatch/vendor/zstd/zstd.h +3206 -0
  95. package/cpp/binarypatch/vendor/zstd/zstd_errors.h +107 -0
  96. package/ios/CodePush/CodePush.h +18 -1
  97. package/ios/CodePush/CodePush.mm +24 -1
  98. package/ios/CodePush/CodePushBinaryPatch.h +80 -0
  99. package/ios/CodePush/CodePushBinaryPatch.m +473 -0
  100. package/ios/CodePush/CodePushDownloadHandler.m +6 -0
  101. package/ios/CodePush/CodePushPackage.m +183 -2
  102. package/ios/CodePush/CodePushUpdateUtils.m +49 -1
  103. package/package.json +10 -3
  104. package/scripts/binary-patch/build-hdiffpatch.sh +86 -0
  105. package/scripts/export-embedded-bundle.sh +76 -0
  106. package/src/CodePush.js +46 -3
  107. package/src/CodePush.test.js +382 -0
  108. package/src/package-mixins.js +20 -2
  109. package/typings/react-native-code-push.d.ts +80 -1
@@ -0,0 +1,434 @@
1
+ // patch_types.h
2
+ //
3
+ /*
4
+ The MIT License (MIT)
5
+ Copyright (c) 2012-2018 HouSisong
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ #ifndef HPatch_patch_types_h
30
+ #define HPatch_patch_types_h
31
+
32
+ #include <string.h> //for size_t memset memcpy memmove
33
+ #include <assert.h>
34
+
35
+ #ifdef __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ #define HDIFFPATCH_VERSION_MAJOR 5
40
+ #define HDIFFPATCH_VERSION_MINOR 1
41
+ #define HDIFFPATCH_VERSION_RELEASE 3
42
+
43
+ #define _HDIFFPATCH_VERSION HDIFFPATCH_VERSION_MAJOR.HDIFFPATCH_VERSION_MINOR.HDIFFPATCH_VERSION_RELEASE
44
+ #define _HDIFFPATCH_QUOTE(str) #str
45
+ #define _HDIFFPATCH_EXPAND_AND_QUOTE(str) _HDIFFPATCH_QUOTE(str)
46
+ #define HDIFFPATCH_VERSION_STRING _HDIFFPATCH_EXPAND_AND_QUOTE(_HDIFFPATCH_VERSION)
47
+ #define HDIFFPATCH_VERSION_NUMBER ((HDIFFPATCH_VERSION_MAJOR*1000+HDIFFPATCH_VERSION_MINOR)*1000+HDIFFPATCH_VERSION_RELEASE)
48
+
49
+ #ifndef _IS_USED_MULTITHREAD
50
+ # define _IS_USED_MULTITHREAD 1
51
+ #endif
52
+ #ifndef _HPATCH_IS_USED_MULTITHREAD
53
+ # define _HPATCH_IS_USED_MULTITHREAD _IS_USED_MULTITHREAD
54
+ #endif
55
+
56
+ #ifndef hpatch_int
57
+ typedef int hpatch_int;
58
+ #endif
59
+ #ifndef hpatch_uint
60
+ typedef unsigned int hpatch_uint;
61
+ #endif
62
+ #ifndef hpatch_size_t
63
+ typedef size_t hpatch_size_t;
64
+ #endif
65
+ #ifndef hpatch_uint32_t
66
+ #ifdef _MSC_VER
67
+ # if (_MSC_VER >= 1300)
68
+ typedef unsigned __int32 hpatch_uint32_t;
69
+ # else
70
+ typedef unsigned int hpatch_uint32_t;
71
+ # endif
72
+ #else
73
+ typedef unsigned int hpatch_uint32_t;
74
+ #endif
75
+ #endif
76
+ #ifndef hpatch_uint64_t
77
+ #ifdef _MSC_VER
78
+ typedef unsigned __int64 hpatch_uint64_t;
79
+ #else
80
+ typedef unsigned long long hpatch_uint64_t;
81
+ #endif
82
+ #endif
83
+ #ifndef hpatch_int64_t
84
+ #ifdef _MSC_VER
85
+ typedef __int64 hpatch_int64_t;
86
+ #else
87
+ typedef long long hpatch_int64_t;
88
+ #endif
89
+ #endif
90
+ #ifndef hpatch_StreamPos_t
91
+ typedef hpatch_uint64_t hpatch_StreamPos_t; // file size type
92
+ #endif
93
+ #define hpatch_kNullStreamPos (~(hpatch_StreamPos_t)0)
94
+
95
+ #ifndef hpatch_BOOL
96
+ typedef unsigned int hpatch_BOOL;
97
+ #endif
98
+ #define hpatch_FALSE 0
99
+ #define hpatch_TRUE ((hpatch_BOOL)(!hpatch_FALSE))
100
+
101
+ #ifndef hpatch_byte
102
+ typedef unsigned char hpatch_byte;
103
+ #endif
104
+
105
+ #if (_HPATCH_IS_USED_errno)
106
+ typedef unsigned int hpatch_FileError_t;// 0: no error; other: saved errno value;
107
+ #else
108
+ typedef hpatch_BOOL hpatch_FileError_t;// 0: no error; other: error;
109
+ #endif
110
+
111
+ #ifdef _MSC_VER
112
+ # define hpatch_inline _inline
113
+ #else
114
+ # define hpatch_inline inline
115
+ #endif
116
+
117
+ #ifndef hpatch_force_inline
118
+ #if defined(_MSC_VER)
119
+ # define hpatch_force_inline __forceinline
120
+ #elif defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
121
+ # define hpatch_force_inline __attribute__((always_inline)) inline
122
+ #elif defined(__ICCARM__)
123
+ # define hpatch_force_inline _Pragma("inline=forced")
124
+ #else
125
+ # define hpatch_force_inline hpatch_inline
126
+ #endif
127
+ #endif
128
+
129
+ //PRIu64 for printf type hpatch_StreamPos_t
130
+ #ifndef PRIu64
131
+ # ifdef _MSC_VER
132
+ # define PRIu64 "I64u"
133
+ # else
134
+ # define PRIu64 "llu"
135
+ # endif
136
+ #endif
137
+
138
+ #ifdef ANDROID
139
+ # include <android/log.h>
140
+ # define LOG_ERR(...) __android_log_print(ANDROID_LOG_ERROR, "hpatch", __VA_ARGS__)
141
+ #else
142
+ # include <stdio.h> //for stderr
143
+ # define LOG_ERR(...) fprintf(stderr,__VA_ARGS__)
144
+ #endif
145
+ #ifndef _HPATCH_IS_USED_errno
146
+ # define _HPATCH_IS_USED_errno 1
147
+ #endif
148
+ #define _hpatch_import_system_tag "call import system api"
149
+ #if (_HPATCH_IS_USED_errno)
150
+ # define LOG_ERRNO(_err_no) \
151
+ LOG_ERR(_hpatch_import_system_tag" error! errno: %d, errmsg: %s.\n",_err_no,strerror(_err_no))
152
+ #else
153
+ # define LOG_ERRNO(_err_no) LOG_ERR(_hpatch_import_system_tag" error!\n")
154
+ #endif
155
+
156
+ #define _hpatch_align_type_lower(uint_type,p,align2pow) (((uint_type)(p)) & (~(uint_type)((align2pow)-1)))
157
+ #define _hpatch_align_lower(p,align2pow) _hpatch_align_type_lower(hpatch_size_t,p,align2pow)
158
+ #define _hpatch_align_upper(p,align2pow) _hpatch_align_lower(((hpatch_size_t)(p))+((align2pow)-1),align2pow)
159
+
160
+ static hpatch_force_inline hpatch_StreamPos_t _hpatch_pos_min(hpatch_StreamPos_t a,hpatch_StreamPos_t b){ return (a<b)?a:b; }
161
+ static hpatch_force_inline hpatch_StreamPos_t _hpatch_pos_max(hpatch_StreamPos_t a,hpatch_StreamPos_t b){ return (a>b)?a:b; }
162
+
163
+
164
+ typedef void* hpatch_TStreamInputHandle;
165
+ typedef void* hpatch_TStreamOutputHandle;
166
+
167
+ typedef struct hpatch_TStreamInput{
168
+ void* streamImport;
169
+ hpatch_StreamPos_t streamSize; //stream size,max readable range;
170
+ //read() must read (out_data_end-out_data), otherwise error return hpatch_FALSE
171
+ hpatch_BOOL (*read)(const struct hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
172
+ unsigned char* out_data,unsigned char* out_data_end);
173
+ void* _private_reserved;
174
+ } hpatch_TStreamInput;
175
+
176
+ typedef struct hpatch_TStreamOutput{
177
+ void* streamImport;
178
+ hpatch_StreamPos_t streamSize; //stream size,max writable range; not is write pos!
179
+ //read_writed for ReadWriteIO, can null!
180
+ hpatch_BOOL (*read_writed)(const struct hpatch_TStreamOutput* stream,hpatch_StreamPos_t readFromPos,
181
+ unsigned char* out_data,unsigned char* out_data_end);
182
+ //write() must wrote (out_data_end-out_data), otherwise error return hpatch_FALSE
183
+ hpatch_BOOL (*write)(const struct hpatch_TStreamOutput* stream,hpatch_StreamPos_t writeToPos,
184
+ const unsigned char* data,const unsigned char* data_end);
185
+ } hpatch_TStreamOutput;
186
+
187
+ //default once I/O (read/write) byte size
188
+ #ifndef hpatch_kStreamCacheSize
189
+ # define hpatch_kStreamCacheSize 4096
190
+ #endif
191
+ #ifndef hpatch_kFileIOBufBetterSize
192
+ # define hpatch_kFileIOBufBetterSize (1024*64)
193
+ #endif
194
+
195
+ #ifndef hpatch_kMaxPluginTypeLength
196
+ # define hpatch_kMaxPluginTypeLength (256+8-1)
197
+ #endif
198
+
199
+ #ifndef hpatch_kWindowDiffHeadMaxSize
200
+ # define hpatch_kWindowDiffHeadMaxSize hpatch_kStreamCacheSize
201
+ #endif
202
+
203
+ #ifndef hpatch_kMaxWindowMetaCount
204
+ # define hpatch_kMaxWindowMetaCount 64 //must 2^N
205
+ #endif
206
+
207
+ typedef struct hpatch_compressedDiffInfo{
208
+ hpatch_StreamPos_t newDataSize;
209
+ hpatch_StreamPos_t oldDataSize;
210
+ hpatch_uint compressedCount;//number of decompress handles that must be opened simultaneously
211
+ char compressType[hpatch_kMaxPluginTypeLength+1]; //ascii cstring
212
+ } hpatch_compressedDiffInfo;
213
+
214
+ typedef void* hpatch_decompressHandle;
215
+ typedef enum{
216
+ hpatch_dec_ok=0,
217
+ hpatch_dec_mem_error,
218
+ hpatch_dec_open_error,
219
+ hpatch_dec_error,
220
+ hpatch_dec_close_error,
221
+ } hpatch_dec_error_t;
222
+ typedef struct hpatch_TDecompress{
223
+ hpatch_BOOL (*is_can_open)(const char* compressType);
224
+ //error return 0.
225
+ hpatch_decompressHandle (*open)(struct hpatch_TDecompress* decompressPlugin,
226
+ hpatch_StreamPos_t dataSize,
227
+ const struct hpatch_TStreamInput* codeStream,
228
+ hpatch_StreamPos_t code_begin,
229
+ hpatch_StreamPos_t code_end);//codeSize==code_end-code_begin
230
+ hpatch_BOOL (*close)(struct hpatch_TDecompress* decompressPlugin,
231
+ hpatch_decompressHandle decompressHandle);
232
+ //decompress_part() must out (out_part_data_end-out_part_data), otherwise error return hpatch_FALSE
233
+ hpatch_BOOL (*decompress_part)(hpatch_decompressHandle decompressHandle,
234
+ unsigned char* out_part_data,unsigned char* out_part_data_end);
235
+ //reset_code add new compressed data; for support vcpatch, can NULL
236
+ hpatch_BOOL (*reset_code)(hpatch_decompressHandle decompressHandle,
237
+ hpatch_StreamPos_t dataSize,
238
+ const struct hpatch_TStreamInput* codeStream,
239
+ hpatch_StreamPos_t code_begin,
240
+ hpatch_StreamPos_t code_end);
241
+ volatile hpatch_dec_error_t decError; //if decError is read, each patch session must use its own hpatch_TDecompress instance
242
+ size_t dec_threadNum; //for multi-thread decompress, <=1 means single thread (default)
243
+ } hpatch_TDecompress;
244
+ #define _hpatch_update_decError(decompressPlugin,errorCode) \
245
+ do { if ((decompressPlugin)->decError==hpatch_dec_ok) \
246
+ (decompressPlugin)->decError=errorCode; } while(0)
247
+
248
+
249
+ const hpatch_TStreamInput* mem_as_hStreamInput(hpatch_TStreamInput* out_stream,
250
+ const unsigned char* mem,const unsigned char* mem_end);
251
+ const hpatch_TStreamOutput* mem_as_hStreamOutput(hpatch_TStreamOutput* out_stream,
252
+ unsigned char* mem,unsigned char* mem_end);
253
+
254
+ hpatch_BOOL hpatch_deccompress_mem(hpatch_TDecompress* decompressPlugin,
255
+ const unsigned char* code,const unsigned char* code_end,
256
+ unsigned char* out_data,unsigned char* out_data_end);
257
+
258
+ typedef struct{
259
+ hpatch_TStreamInput base;
260
+ const hpatch_TStreamInput* srcStream;
261
+ hpatch_StreamPos_t clipBeginPos;
262
+ } TStreamInputClip;
263
+ //clip srcStream from clipBeginPos to clipEndPos as a new StreamInput;
264
+ void TStreamInputClip_init(TStreamInputClip* self,const hpatch_TStreamInput* srcStream,
265
+ hpatch_StreamPos_t clipBeginPos,hpatch_StreamPos_t clipEndPos);
266
+ typedef struct{
267
+ hpatch_TStreamOutput base;
268
+ const hpatch_TStreamOutput* srcStream;
269
+ hpatch_StreamPos_t clipBeginPos;
270
+ } TStreamOutputClip;
271
+ //clip srcStream from clipBeginPos to clipEndPos as a new StreamInput;
272
+ void TStreamOutputClip_init(TStreamOutputClip* self,const hpatch_TStreamOutput* srcStream,
273
+ hpatch_StreamPos_t clipBeginPos,hpatch_StreamPos_t clipEndPos);
274
+
275
+
276
+ #define hpatch_kMaxPackedUIntBytes ((sizeof(hpatch_StreamPos_t)*8+6)/7+1)
277
+ hpatch_BOOL hpatch_packUIntWithTag(unsigned char** out_code,unsigned char* out_code_end,
278
+ hpatch_StreamPos_t uValue,hpatch_uint highTag,const hpatch_uint kTagBit);
279
+ hpatch_uint hpatch_packUIntWithTag_size(hpatch_StreamPos_t uValue,const hpatch_uint kTagBit);
280
+ #define hpatch_packUInt(out_code,out_code_end,uValue) \
281
+ hpatch_packUIntWithTag(out_code,out_code_end,uValue,0,0)
282
+ #define hpatch_packUInt_size(uValue) hpatch_packUIntWithTag_size(uValue,0)
283
+
284
+ hpatch_BOOL hpatch_unpackUIntWithTag(const unsigned char** src_code,const unsigned char* src_code_end,
285
+ hpatch_StreamPos_t* result,const hpatch_uint kTagBit);
286
+ #define hpatch_unpackUInt(src_code,src_code_end,result) \
287
+ hpatch_unpackUIntWithTag(src_code,src_code_end,result,0)
288
+
289
+
290
+ typedef struct hpatch_TCover{
291
+ hpatch_StreamPos_t oldPos;
292
+ hpatch_StreamPos_t newPos;
293
+ hpatch_StreamPos_t length;
294
+ } hpatch_TCover;
295
+
296
+ //opened input covers
297
+ typedef struct hpatch_TCovers{
298
+ hpatch_StreamPos_t (*leave_cover_count)(const struct hpatch_TCovers* covers);
299
+ //read out a cover,and to next cover pos; if error then return false
300
+ hpatch_BOOL (*read_cover)(struct hpatch_TCovers* covers,hpatch_TCover* out_cover);
301
+ hpatch_BOOL (*is_finish)(const struct hpatch_TCovers* covers);
302
+ hpatch_BOOL (*close)(struct hpatch_TCovers* covers);
303
+ } hpatch_TCovers;
304
+
305
+ typedef struct{
306
+ hpatch_StreamPos_t newDataSize;
307
+ hpatch_StreamPos_t oldDataSize;
308
+ hpatch_StreamPos_t uncompressedSize;
309
+ hpatch_StreamPos_t compressedSize;
310
+ hpatch_StreamPos_t diffDataPos;
311
+ hpatch_StreamPos_t coverCount;
312
+ hpatch_StreamPos_t stepMemSize;
313
+ char compressType[hpatch_kMaxPluginTypeLength+1]; //ascii cstring
314
+ } hpatch_singleCompressedDiffInfo;
315
+
316
+ hpatch_inline static void _singleDiffInfoToHDiffInfo(hpatch_compressedDiffInfo* out_diffInfo,const hpatch_singleCompressedDiffInfo* singleDiffInfo){
317
+ out_diffInfo->newDataSize=singleDiffInfo->newDataSize;
318
+ out_diffInfo->oldDataSize=singleDiffInfo->oldDataSize;
319
+ out_diffInfo->compressedCount=(singleDiffInfo->compressedSize>0)?1:0;
320
+ memcpy(out_diffInfo->compressType,singleDiffInfo->compressType,strlen(singleDiffInfo->compressType)+1);
321
+ }
322
+
323
+ typedef struct sspatch_listener_t{
324
+ void* import;
325
+ hpatch_BOOL (*onDiffInfo)(struct sspatch_listener_t* listener,
326
+ const hpatch_singleCompressedDiffInfo* info,
327
+ hpatch_TDecompress** out_decompressPlugin,//find decompressPlugin by info->compressType
328
+ unsigned char** out_temp_cache, //*out_temp_cacheEnd-*out_temp_cache == info->stepMemSize + (I/O cache memory)
329
+ unsigned char** out_temp_cacheEnd);// note: (I/O cache memory) >= hpatch_kStreamCacheSize*3
330
+ void (*onPatchFinish)(struct sspatch_listener_t* listener, //onPatchFinish can null
331
+ unsigned char* temp_cache, unsigned char* temp_cacheEnd);
332
+ } sspatch_listener_t;
333
+
334
+ typedef struct{
335
+ hpatch_TStreamInput base;
336
+ hpatch_TDecompress* _decompressPlugin;
337
+ hpatch_decompressHandle _decompressHandle;
338
+ } hpatch_TUncompresser_t;
339
+
340
+ typedef struct sspatch_coversListener_t{
341
+ void* import;
342
+ void (*onStepCoversReset)(struct sspatch_coversListener_t* listener,hpatch_StreamPos_t leaveCoverCount);//can be NULL; data in covers_cache will become invalid; if leaveCoverCount==0, the step is finished
343
+ void (*onStepCovers)(struct sspatch_coversListener_t* listener,
344
+ const unsigned char* covers_cache,const unsigned char* covers_cacheEnd);//if covers_cache==covers_cacheEnd==0, step finish
345
+ } sspatch_coversListener_t;
346
+
347
+ typedef struct{
348
+ const unsigned char* covers_cache;
349
+ const unsigned char* covers_cacheEnd;
350
+ hpatch_StreamPos_t lastOldEnd;
351
+ hpatch_StreamPos_t lastNewEnd;
352
+ hpatch_TCover cover;
353
+ } sspatch_covers_t;
354
+
355
+ hpatch_inline static void sspatch_covers_init(sspatch_covers_t* self) { memset(self,0,sizeof(*self)); }
356
+ hpatch_inline static void sspatch_covers_setCoversCache(sspatch_covers_t* self,const unsigned char* covers_cache,const unsigned char* covers_cacheEnd){
357
+ self->covers_cache=covers_cache; self->covers_cacheEnd=covers_cacheEnd; }
358
+ hpatch_inline static hpatch_BOOL sspatch_covers_isHaveNextCover(const sspatch_covers_t* self) { return (self->covers_cache!=(self)->covers_cacheEnd); }
359
+
360
+ hpatch_BOOL sspatch_covers_nextCover(sspatch_covers_t* self);
361
+
362
+
363
+ typedef struct{
364
+ hpatch_StreamPos_t oldPos;
365
+ hpatch_StreamPos_t newPos;
366
+ hpatch_StreamPos_t oldLength;
367
+ hpatch_StreamPos_t newLength;
368
+ } hpatch_TWindow;
369
+
370
+
371
+ typedef struct hpatch_windowDiffInfo{
372
+ hpatch_StreamPos_t newDataSize;
373
+ hpatch_StreamPos_t oldDataSize;
374
+ hpatch_StreamPos_t coverCount;
375
+ hpatch_StreamPos_t windowCount;
376
+ hpatch_StreamPos_t windowMetaCount; //2^N, >=2 & <= hpatch_kMaxWindowMetaCount
377
+ hpatch_StreamPos_t maxStepMemSize;
378
+ hpatch_StreamPos_t maxSubCoverCount;
379
+ hpatch_StreamPos_t maxWindowOldSize;
380
+ hpatch_StreamPos_t checksumByteSize; //0 no checksum
381
+ hpatch_StreamPos_t extraDataSize;
382
+ hpatch_StreamPos_t uncompressedSize; //windowDiffStreamSize
383
+ hpatch_StreamPos_t compressedSize; //0 uncompressed, >0 compressed
384
+ hpatch_StreamPos_t otherInfoPos;
385
+ hpatch_StreamPos_t otherInfoEndPos;
386
+ hpatch_StreamPos_t windowDataPos; //window data begin pos(compressed data begin pos);
387
+ //the checksum section for old/new/diff data begin pos = windowDataPos-3*checksumByteSize;
388
+ hpatch_StreamPos_t _headFixedInfoPos;
389
+ char compressType[hpatch_kMaxPluginTypeLength+1];
390
+ char checksumType[hpatch_kMaxPluginTypeLength+1];
391
+ } hpatch_windowDiffInfo;
392
+
393
+ typedef enum TWindowPatchResult{
394
+ kWindowPatch_ok=0,
395
+ kWindowPatch_load_head_error,
396
+ kWindowPatch_new_size_error,
397
+ kWindowPatch_old_size_error,
398
+ kWindowPatch_onDiffInfo_error,
399
+ kWindowPatch_temp_mem_error,
400
+ kWindowPatch_decompress_open_error,
401
+ kWindowPatch_patch_error,
402
+ kWindowPatch_checksum_plugin_error,
403
+ kWindowPatch_checksum_open_error,
404
+ kWindowPatch_checksum_old_error,
405
+ kWindowPatch_checksum_new_error,
406
+ kWindowPatch_checksum_diff_error,
407
+ } TWindowPatchResult;
408
+
409
+ hpatch_inline static void _winDiffInfoToHDiffInfo(hpatch_compressedDiffInfo* out_diffInfo,const hpatch_windowDiffInfo* winDiffInfo){
410
+ out_diffInfo->newDataSize=winDiffInfo->newDataSize;
411
+ out_diffInfo->oldDataSize=winDiffInfo->oldDataSize;
412
+ out_diffInfo->compressedCount=(winDiffInfo->compressedSize>0)?1:0;
413
+ memcpy(out_diffInfo->compressType,winDiffInfo->compressType,strlen(winDiffInfo->compressType)+1);
414
+ }
415
+
416
+ struct hpatch_TChecksum;
417
+ typedef struct winpatch_listener_t{
418
+ void* import;
419
+ hpatch_BOOL (*onDiffInfo)(struct winpatch_listener_t* listener,
420
+ const hpatch_windowDiffInfo* info,
421
+ hpatch_TDecompress** out_decompressPlugin,//find decompressPlugin by info->compressType
422
+ struct hpatch_TChecksum** out_checksumPlugin, //find checksumPlugin by info->checksumType
423
+ hpatch_BOOL* isChecksumNew, // *isChecksumNew default true when info->checksumByteSize>0
424
+ hpatch_BOOL* isChecksumOld,hpatch_BOOL* isChecksumDiff,//*isChecksumOld & *isChecksumDiff default false
425
+ unsigned char** out_temp_cache, //*out_temp_cacheEnd-*out_temp_cache == info->maxWindowOldSize + info->stepMemSize + (I/O cache memory)
426
+ unsigned char** out_temp_cacheEnd);// note: (I/O cache memory) >= hpatch_kStreamCacheSize*3
427
+ void (*onPatchFinish)(struct winpatch_listener_t* listener, //onPatchFinish can null
428
+ unsigned char* temp_cache, unsigned char* temp_cacheEnd);
429
+ } winpatch_listener_t;
430
+
431
+ #ifdef __cplusplus
432
+ }
433
+ #endif
434
+ #endif
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ /* This file provides custom allocation primitives
12
+ */
13
+
14
+ #define ZSTD_DEPS_NEED_MALLOC
15
+ #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16
+
17
+ #include "compiler.h" /* MEM_STATIC */
18
+ #define ZSTD_STATIC_LINKING_ONLY
19
+ #include "../zstd.h" /* ZSTD_customMem */
20
+
21
+ #ifndef ZSTD_ALLOCATIONS_H
22
+ #define ZSTD_ALLOCATIONS_H
23
+
24
+ /* custom memory allocation functions */
25
+
26
+ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27
+ {
28
+ if (customMem.customAlloc)
29
+ return customMem.customAlloc(customMem.opaque, size);
30
+ return ZSTD_malloc(size);
31
+ }
32
+
33
+ MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
+ {
35
+ if (customMem.customAlloc) {
36
+ /* calloc implemented as malloc+memset;
37
+ * not as efficient as calloc, but next best guess for custom malloc */
38
+ void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
+ ZSTD_memset(ptr, 0, size);
40
+ return ptr;
41
+ }
42
+ return ZSTD_calloc(1, size);
43
+ }
44
+
45
+ MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46
+ {
47
+ if (ptr!=NULL) {
48
+ if (customMem.customFree)
49
+ customMem.customFree(customMem.opaque, ptr);
50
+ else
51
+ ZSTD_free(ptr);
52
+ }
53
+ }
54
+
55
+ #endif /* ZSTD_ALLOCATIONS_H */
@@ -0,0 +1,205 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #ifndef ZSTD_BITS_H
12
+ #define ZSTD_BITS_H
13
+
14
+ #include "mem.h"
15
+
16
+ MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
17
+ {
18
+ assert(val != 0);
19
+ {
20
+ static const U32 DeBruijnBytePos[32] = {0, 1, 28, 2, 29, 14, 24, 3,
21
+ 30, 22, 20, 15, 25, 17, 4, 8,
22
+ 31, 27, 13, 23, 21, 19, 16, 7,
23
+ 26, 12, 18, 6, 11, 5, 10, 9};
24
+ return DeBruijnBytePos[((U32) ((val & -(S32) val) * 0x077CB531U)) >> 27];
25
+ }
26
+ }
27
+
28
+ MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
29
+ {
30
+ assert(val != 0);
31
+ #if defined(_MSC_VER)
32
+ # if STATIC_BMI2
33
+ return (unsigned)_tzcnt_u32(val);
34
+ # else
35
+ if (val != 0) {
36
+ unsigned long r;
37
+ _BitScanForward(&r, val);
38
+ return (unsigned)r;
39
+ } else {
40
+ __assume(0); /* Should not reach this code path */
41
+ }
42
+ # endif
43
+ #elif defined(__GNUC__) && (__GNUC__ >= 4)
44
+ return (unsigned)__builtin_ctz(val);
45
+ #elif defined(__ICCARM__)
46
+ return (unsigned)__builtin_ctz(val);
47
+ #else
48
+ return ZSTD_countTrailingZeros32_fallback(val);
49
+ #endif
50
+ }
51
+
52
+ MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val)
53
+ {
54
+ assert(val != 0);
55
+ {
56
+ static const U32 DeBruijnClz[32] = {0, 9, 1, 10, 13, 21, 2, 29,
57
+ 11, 14, 16, 18, 22, 25, 3, 30,
58
+ 8, 12, 20, 28, 15, 17, 24, 7,
59
+ 19, 27, 23, 6, 26, 5, 4, 31};
60
+ val |= val >> 1;
61
+ val |= val >> 2;
62
+ val |= val >> 4;
63
+ val |= val >> 8;
64
+ val |= val >> 16;
65
+ return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
66
+ }
67
+ }
68
+
69
+ MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
70
+ {
71
+ assert(val != 0);
72
+ #if defined(_MSC_VER)
73
+ # if STATIC_BMI2
74
+ return (unsigned)_lzcnt_u32(val);
75
+ # else
76
+ if (val != 0) {
77
+ unsigned long r;
78
+ _BitScanReverse(&r, val);
79
+ return (unsigned)(31 - r);
80
+ } else {
81
+ __assume(0); /* Should not reach this code path */
82
+ }
83
+ # endif
84
+ #elif defined(__GNUC__) && (__GNUC__ >= 4)
85
+ return (unsigned)__builtin_clz(val);
86
+ #elif defined(__ICCARM__)
87
+ return (unsigned)__builtin_clz(val);
88
+ #else
89
+ return ZSTD_countLeadingZeros32_fallback(val);
90
+ #endif
91
+ }
92
+
93
+ MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
94
+ {
95
+ assert(val != 0);
96
+ #if defined(_MSC_VER) && defined(_WIN64)
97
+ # if STATIC_BMI2
98
+ return (unsigned)_tzcnt_u64(val);
99
+ # else
100
+ if (val != 0) {
101
+ unsigned long r;
102
+ _BitScanForward64(&r, val);
103
+ return (unsigned)r;
104
+ } else {
105
+ __assume(0); /* Should not reach this code path */
106
+ }
107
+ # endif
108
+ #elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__)
109
+ return (unsigned)__builtin_ctzll(val);
110
+ #elif defined(__ICCARM__)
111
+ return (unsigned)__builtin_ctzll(val);
112
+ #else
113
+ {
114
+ U32 mostSignificantWord = (U32)(val >> 32);
115
+ U32 leastSignificantWord = (U32)val;
116
+ if (leastSignificantWord == 0) {
117
+ return 32 + ZSTD_countTrailingZeros32(mostSignificantWord);
118
+ } else {
119
+ return ZSTD_countTrailingZeros32(leastSignificantWord);
120
+ }
121
+ }
122
+ #endif
123
+ }
124
+
125
+ MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
126
+ {
127
+ assert(val != 0);
128
+ #if defined(_MSC_VER) && defined(_WIN64)
129
+ # if STATIC_BMI2
130
+ return (unsigned)_lzcnt_u64(val);
131
+ # else
132
+ if (val != 0) {
133
+ unsigned long r;
134
+ _BitScanReverse64(&r, val);
135
+ return (unsigned)(63 - r);
136
+ } else {
137
+ __assume(0); /* Should not reach this code path */
138
+ }
139
+ # endif
140
+ #elif defined(__GNUC__) && (__GNUC__ >= 4)
141
+ return (unsigned)(__builtin_clzll(val));
142
+ #elif defined(__ICCARM__)
143
+ return (unsigned)(__builtin_clzll(val));
144
+ #else
145
+ {
146
+ U32 mostSignificantWord = (U32)(val >> 32);
147
+ U32 leastSignificantWord = (U32)val;
148
+ if (mostSignificantWord == 0) {
149
+ return 32 + ZSTD_countLeadingZeros32(leastSignificantWord);
150
+ } else {
151
+ return ZSTD_countLeadingZeros32(mostSignificantWord);
152
+ }
153
+ }
154
+ #endif
155
+ }
156
+
157
+ MEM_STATIC unsigned ZSTD_NbCommonBytes(size_t val)
158
+ {
159
+ if (MEM_isLittleEndian()) {
160
+ if (MEM_64bits()) {
161
+ return ZSTD_countTrailingZeros64((U64)val) >> 3;
162
+ } else {
163
+ return ZSTD_countTrailingZeros32((U32)val) >> 3;
164
+ }
165
+ } else { /* Big Endian CPU */
166
+ if (MEM_64bits()) {
167
+ return ZSTD_countLeadingZeros64((U64)val) >> 3;
168
+ } else {
169
+ return ZSTD_countLeadingZeros32((U32)val) >> 3;
170
+ }
171
+ }
172
+ }
173
+
174
+ MEM_STATIC unsigned ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
175
+ {
176
+ assert(val != 0);
177
+ return 31 - ZSTD_countLeadingZeros32(val);
178
+ }
179
+
180
+ /* ZSTD_rotateRight_*():
181
+ * Rotates a bitfield to the right by "count" bits.
182
+ * https://en.wikipedia.org/w/index.php?title=Circular_shift&oldid=991635599#Implementing_circular_shifts
183
+ */
184
+ MEM_STATIC
185
+ U64 ZSTD_rotateRight_U64(U64 const value, U32 count) {
186
+ assert(count < 64);
187
+ count &= 0x3F; /* for fickle pattern recognition */
188
+ return (value >> count) | (U64)(value << ((0U - count) & 0x3F));
189
+ }
190
+
191
+ MEM_STATIC
192
+ U32 ZSTD_rotateRight_U32(U32 const value, U32 count) {
193
+ assert(count < 32);
194
+ count &= 0x1F; /* for fickle pattern recognition */
195
+ return (value >> count) | (U32)(value << ((0U - count) & 0x1F));
196
+ }
197
+
198
+ MEM_STATIC
199
+ U16 ZSTD_rotateRight_U16(U16 const value, U32 count) {
200
+ assert(count < 16);
201
+ count &= 0x0F; /* for fickle pattern recognition */
202
+ return (value >> count) | (U16)(value << ((0U - count) & 0x0F));
203
+ }
204
+
205
+ #endif /* ZSTD_BITS_H */