Debian Codegraph @

Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/dfltcc_common.c

raw
1 /* dfltcc_deflate.c - IBM Z DEFLATE CONVERSION CALL general support. */
2
3 #include "zbuild.h"
4 #include "dfltcc_common.h"
5 #include "dfltcc_detail.h"
6
7 /*
8 Memory management.
9
10 DFLTCC requires parameter blocks and window to be aligned. zlib-ng allows
11 users to specify their own allocation functions, so using e.g.
12 `posix_memalign' is not an option. Thus, we overallocate and take the
13 aligned portion of the buffer.
14 */
15
16 static const int PAGE_ALIGN = 0x1000;
17
18 void Z_INTERNAL *PREFIX(dfltcc_alloc_window)(PREFIX3(streamp) strm, uInt items, uInt size) {
19 void *p;
20 void *w;
21
22 /* To simplify freeing, we store the pointer to the allocated buffer right
23 * before the window. Note that DFLTCC always uses HB_SIZE bytes.
24 */
25 p = ZALLOC(strm, sizeof(void *) + MAX(items * size, HB_SIZE) + PAGE_ALIGN, sizeof(unsigned char));
26 if (p == NULL)
27 return NULL;
28 w = ALIGN_UP((char *)p + sizeof(void *), PAGE_ALIGN);
29 *(void **)((char *)w - sizeof(void *)) = p;
30 return w;
31 }
32
33 void Z_INTERNAL PREFIX(dfltcc_copy_window)(void *dest, const void *src, size_t n) {
34 memcpy(dest, src, MAX(n, HB_SIZE));
35 }
36
37 void Z_INTERNAL PREFIX(dfltcc_free_window)(PREFIX3(streamp) strm, void *w) {
38 if (w)
39 ZFREE(strm, *(void **)((unsigned char *)w - sizeof(void *)));
40 }