To ease maintenance burden. Includes lightrec.
Only gpulib_thread_if is left out, unsure what to do with it.
--- /dev/null
+#ifndef _3DS_UTILS_H
+#define _3DS_UTILS_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <3ds.h>
+
+#ifdef OS_HEAP_AREA_BEGIN // defined in libctru 2.0+
+#define USE_CTRULIB_2 1
+#endif
+
+#define MEMOP_PROT 6
+#define MEMOP_MAP 4
+#define MEMOP_UNMAP 5
+
+#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
+
+void wait_for_input(void);
+
+extern __attribute__((weak)) int __ctr_svchax;
+
+static bool has_rosalina;
+
+static inline void check_rosalina() {
+ int64_t version;
+ uint32_t major;
+
+ has_rosalina = false;
+
+ if (!svcGetSystemInfo(&version, 0x10000, 0)) {
+ major = GET_VERSION_MAJOR(version);
+
+ if (major >= 8)
+ has_rosalina = true;
+ }
+}
+
+void ctr_clear_cache(void);
+
+typedef int32_t (*ctr_callback_type)(void);
+
+static inline void ctr_invalidate_ICache_kernel(void)
+{
+ __asm__ volatile(
+ "cpsid aif\n\t"
+ "mov r0, #0\n\t"
+ "mcr p15, 0, r0, c7, c5, 0\n\t");
+}
+
+static inline void ctr_flush_DCache_kernel(void)
+{
+ __asm__ volatile(
+ "cpsid aif\n\t"
+ "mov r0, #0\n\t"
+ "mcr p15, 0, r0, c7, c10, 0\n\t");
+}
+
+static inline void ctr_invalidate_ICache(void)
+{
+ svcBackdoor((ctr_callback_type)ctr_invalidate_ICache_kernel);
+}
+
+static inline void ctr_flush_DCache(void)
+{
+ svcBackdoor((ctr_callback_type)ctr_flush_DCache_kernel);
+}
+
+static inline void ctr_flush_invalidate_cache(void)
+{
+ if (has_rosalina) {
+ ctr_clear_cache();
+ } else {
+ ctr_flush_DCache();
+ ctr_invalidate_ICache();
+ }
+}
+
+#endif // _3DS_UTILS_H
--- /dev/null
+/* Copyright (C) 2010-2020 The RetroArch team
+ *
+ * ---------------------------------------------------------------------------------------
+ * The following license statement only applies to this file (gx_pthread.h).
+ * ---------------------------------------------------------------------------------------
+ *
+ * Permission is hereby granted, free of charge,
+ * to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _CTR_PTHREAD_WRAP_CTR_
+#define _CTR_PTHREAD_WRAP_CTR_
+
+#include "3ds_utils.h"
+
+#include <time.h>
+#include <errno.h>
+
+#define STACKSIZE (4 * 1024)
+#define FALSE 0
+
+#ifndef PTHREAD_SCOPE_PROCESS
+/* An earlier version of devkitARM does not define the pthread types. Can remove in r54+. */
+
+typedef Thread pthread_t;
+typedef LightLock pthread_mutex_t;
+typedef void* pthread_mutexattr_t;
+typedef int pthread_attr_t;
+typedef LightEvent pthread_cond_t;
+typedef int pthread_condattr_t;
+#endif
+
+#ifndef USE_CTRULIB_2
+/* Backported CondVar API from libctru 2.0, and under its license:
+ https://github.com/devkitPro/libctru
+ Slightly modified for compatibility with older libctru. */
+
+typedef s32 CondVar;
+
+static inline Result syncArbitrateAddress(s32* addr, ArbitrationType type, s32 value)
+{
+ return svcArbitrateAddress(__sync_get_arbiter(), (u32)addr, type, value, 0);
+}
+
+static inline Result syncArbitrateAddressWithTimeout(s32* addr, ArbitrationType type, s32 value, s64 timeout_ns)
+{
+ return svcArbitrateAddress(__sync_get_arbiter(), (u32)addr, type, value, timeout_ns);
+}
+
+static inline void __dmb(void)
+{
+ __asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 5" :: [val] "r" (0) : "memory");
+}
+
+static inline void CondVar_BeginWait(CondVar* cv, LightLock* lock)
+{
+ s32 val;
+ do
+ val = __ldrex(cv) - 1;
+ while (__strex(cv, val));
+ LightLock_Unlock(lock);
+}
+
+static inline bool CondVar_EndWait(CondVar* cv, s32 num_threads)
+{
+ bool hasWaiters;
+ s32 val;
+
+ do {
+ val = __ldrex(cv);
+ hasWaiters = val < 0;
+ if (hasWaiters)
+ {
+ if (num_threads < 0)
+ val = 0;
+ else if (val <= -num_threads)
+ val += num_threads;
+ else
+ val = 0;
+ }
+ } while (__strex(cv, val));
+
+ return hasWaiters;
+}
+
+static inline void CondVar_Init(CondVar* cv)
+{
+ *cv = 0;
+}
+
+static inline void CondVar_Wait(CondVar* cv, LightLock* lock)
+{
+ CondVar_BeginWait(cv, lock);
+ syncArbitrateAddress(cv, ARBITRATION_WAIT_IF_LESS_THAN, 0);
+ LightLock_Lock(lock);
+}
+
+static inline int CondVar_WaitTimeout(CondVar* cv, LightLock* lock, s64 timeout_ns)
+{
+ CondVar_BeginWait(cv, lock);
+
+ bool timedOut = false;
+ Result rc = syncArbitrateAddressWithTimeout(cv, ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0, timeout_ns);
+ if (R_DESCRIPTION(rc) == RD_TIMEOUT)
+ {
+ timedOut = CondVar_EndWait(cv, 1);
+ __dmb();
+ }
+
+ LightLock_Lock(lock);
+ return timedOut;
+}
+
+static inline void CondVar_WakeUp(CondVar* cv, s32 num_threads)
+{
+ __dmb();
+ if (CondVar_EndWait(cv, num_threads))
+ syncArbitrateAddress(cv, ARBITRATION_SIGNAL, num_threads);
+ else
+ __dmb();
+}
+
+static inline void CondVar_Signal(CondVar* cv)
+{
+ CondVar_WakeUp(cv, 1);
+}
+
+static inline void CondVar_Broadcast(CondVar* cv)
+{
+ CondVar_WakeUp(cv, ARBITRATION_SIGNAL_ALL);
+}
+/* End libctru 2.0 backport */
+#endif
+
+/* libctru threads return void but pthreads return void pointer */
+static bool mutex_inited = false;
+static LightLock safe_double_thread_launch;
+static void *(*start_routine_jump)(void*);
+
+static void ctr_thread_launcher(void* data)
+{
+ void *(*start_routine_jump_safe)(void*) = start_routine_jump;
+ LightLock_Unlock(&safe_double_thread_launch);
+ start_routine_jump_safe(data);
+}
+
+static inline int pthread_create(pthread_t *thread,
+ const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
+{
+ s32 prio = 0;
+ Thread new_ctr_thread;
+ int procnum = -2; // use default cpu
+ bool isNew3DS;
+
+ APT_CheckNew3DS(&isNew3DS);
+
+ if (isNew3DS)
+ procnum = 2;
+
+ if (!mutex_inited)
+ {
+ LightLock_Init(&safe_double_thread_launch);
+ mutex_inited = true;
+ }
+
+ /*Must wait if attempting to launch 2 threads at once to prevent corruption of function pointer*/
+ while (LightLock_TryLock(&safe_double_thread_launch) != 0);
+
+ svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
+
+ start_routine_jump = start_routine;
+ new_ctr_thread = threadCreate(ctr_thread_launcher, arg, STACKSIZE, prio - 1, procnum, FALSE);
+
+ if (!new_ctr_thread)
+ {
+ LightLock_Unlock(&safe_double_thread_launch);
+ return EAGAIN;
+ }
+
+ *thread = (pthread_t)new_ctr_thread;
+ return 0;
+}
+
+static inline pthread_t pthread_self(void)
+{
+ return (pthread_t)threadGetCurrent();
+}
+
+static inline int pthread_mutex_init(pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *attr)
+{
+ LightLock_Init((LightLock *)mutex);
+ return 0;
+}
+
+static inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ /*Nothing to destroy*/
+ return 0;
+}
+
+static inline int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ LightLock_Lock((LightLock *)mutex);
+ return 0;
+}
+
+static inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ LightLock_Unlock((LightLock *)mutex);
+ return 0;
+}
+
+static inline void pthread_exit(void *retval)
+{
+ /*Yes the pointer to int cast is not ideal*/
+ /*threadExit((int)retval);*/
+ (void)retval;
+
+ threadExit(0);
+}
+
+static inline int pthread_detach(pthread_t thread)
+{
+ threadDetach((Thread)thread);
+ return 0;
+}
+
+static inline int pthread_join(pthread_t thread, void **retval)
+{
+ /*retval is ignored*/
+ if(threadJoin((Thread)thread, INT64_MAX))
+ return -1;
+
+ threadFree((Thread)thread);
+
+ return 0;
+}
+
+static inline int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+ return LightLock_TryLock((LightLock *)mutex);
+}
+
+static inline int pthread_cond_wait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex)
+{
+ CondVar_Wait((CondVar *)cond, (LightLock *)mutex);
+ return 0;
+}
+
+static inline int pthread_cond_timedwait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex, const struct timespec *abstime)
+{
+ struct timespec now = {0};
+ /* Missing clock_gettime*/
+ struct timeval tm;
+ int retval = 0;
+
+ gettimeofday(&tm, NULL);
+ now.tv_sec = tm.tv_sec;
+ now.tv_nsec = tm.tv_usec * 1000;
+ s64 timeout = (abstime->tv_sec - now.tv_sec) * 1000000000 + (abstime->tv_nsec - now.tv_nsec);
+
+ if (timeout < 0)
+ {
+ retval = ETIMEDOUT;
+ }
+ else if (CondVar_WaitTimeout((CondVar *)cond, (LightLock *)mutex, timeout))
+ {
+ retval = ETIMEDOUT;
+ }
+
+ return retval;
+}
+
+static inline int pthread_cond_init(pthread_cond_t *cond,
+ const pthread_condattr_t *attr)
+{
+ CondVar_Init((CondVar *)cond);
+ return 0;
+}
+
+static inline int pthread_cond_signal(pthread_cond_t *cond)
+{
+ CondVar_Signal((CondVar *)cond);
+ return 0;
+}
+
+static inline int pthread_cond_broadcast(pthread_cond_t *cond)
+{
+ CondVar_Broadcast((CondVar *)cond);
+ return 0;
+}
+
+static inline int pthread_cond_destroy(pthread_cond_t *cond)
+{
+ /*Nothing to destroy*/
+ return 0;
+}
+
+static inline int pthread_equal(pthread_t t1, pthread_t t2)
+{
+ if (threadGetHandle((Thread)t1) == threadGetHandle((Thread)t2))
+ return 1;
+ return 0;
+}
+
+#endif
--- /dev/null
+
+#ifndef _3DS_SEMAPHORE_WRAP__
+#define _3DS_SEMAPHORE_WRAP__
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "3ds_utils.h"
+
+typedef uint32_t sem_t;
+
+static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
+{
+ return svcCreateSemaphore(sem, value, INT32_MAX);
+}
+
+static inline int sem_post(sem_t *sem)
+{
+ int32_t count;
+ return svcReleaseSemaphore(&count, *sem, 1);
+}
+
+static inline int sem_wait(sem_t *sem)
+{
+ return svcWaitSynchronization(*sem, INT64_MAX);
+}
+
+static inline int sem_destroy(sem_t *sem)
+{
+ return svcCloseHandle(*sem);
+}
+
+#endif //_3DS_SEMAPHORE_WRAP__
+
--- /dev/null
+#ifndef MMAN_H
+#define MMAN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <malloc.h>
+
+#include "3ds_utils.h"
+
+#define PROT_READ 0b001
+#define PROT_WRITE 0b010
+#define PROT_EXEC 0b100
+#define MAP_PRIVATE 2
+#define MAP_FIXED 0x10
+#define MAP_ANONYMOUS 0x20
+
+#define MAP_FAILED ((void *)-1)
+
+static void* dynarec_cache = NULL;
+static void* dynarec_cache_mapping = NULL;
+
+static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ (void)fd;
+ (void)offset;
+
+ void* addr_out;
+
+ if((prot == (PROT_READ | PROT_WRITE | PROT_EXEC)) &&
+ (flags == (MAP_PRIVATE | MAP_ANONYMOUS)))
+ {
+ if(__ctr_svchax)
+ {
+ /* this hack works only for pcsx_rearmed */
+ uint32_t currentHandle;
+
+ if (!dynarec_cache) {
+ dynarec_cache = memalign(0x1000, len);
+ if (!dynarec_cache)
+ return MAP_FAILED;
+ }
+
+ svcDuplicateHandle(¤tHandle, 0xFFFF8001);
+ svcControlProcessMemory(currentHandle, addr, dynarec_cache,
+ len, MEMOP_MAP, prot);
+ svcCloseHandle(currentHandle);
+ dynarec_cache_mapping = addr;
+ memset(addr, 0, len);
+ return addr;
+ }
+ else
+ {
+ printf("tried to mmap RWX pages without svcControlProcessMemory access !\n");
+ return MAP_FAILED;
+ }
+
+ }
+
+ addr_out = memalign(0x1000, len);
+ if (!addr_out)
+ return MAP_FAILED;
+
+ memset(addr_out, 0, len);
+ return addr_out;
+}
+
+static inline int mprotect(void *addr, size_t len, int prot)
+{
+ if(__ctr_svchax)
+ {
+ uint32_t currentHandle;
+ svcDuplicateHandle(¤tHandle, 0xFFFF8001);
+ svcControlProcessMemory(currentHandle, addr, NULL,
+ len, MEMOP_PROT, prot);
+ svcCloseHandle(currentHandle);
+ return 0;
+ }
+
+ printf("mprotect called without svcControlProcessMemory access !\n");
+ return -1;
+}
+
+static inline int munmap(void *addr, size_t len)
+{
+ if((addr == dynarec_cache_mapping) && __ctr_svchax)
+ {
+ uint32_t currentHandle;
+ svcDuplicateHandle(¤tHandle, 0xFFFF8001);
+ svcControlProcessMemory(currentHandle,
+ dynarec_cache, dynarec_cache_mapping,
+ len, MEMOP_UNMAP, 0b111);
+ svcCloseHandle(currentHandle);
+ dynarec_cache_mapping = NULL;
+
+ }
+ else
+ free(addr);
+
+ return 0;
+}
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // MMAN_H
+
--- /dev/null
+ .text
+ .arm
+ .balign 4
+
+ .func ctr_clear_cache_kernel
+ctr_clear_cache_kernel:
+ cpsid aif
+ mov r0, #0
+ mcr p15, 0, r0, c7, c10, 0 @ Clean entire data cache
+ mcr p15, 0, r0, c7, c10, 5 @ Data Memory Barrier
+ mcr p15, 0, r0, c7, c5, 0 @ Invalidate entire instruction cache / Flush BTB
+ mcr p15, 0, r0, c7, c10, 4 @ Data Sync Barrier
+ bx lr
+ .endfunc
+
+ @@ Clear the entire data cache / invalidate the instruction cache. Uses
+ @@ Rosalina svcCustomBackdoor to avoid svcBackdoor stack corruption
+ @@ during interrupts.
+ .global ctr_clear_cache
+ .func ctr_clear_cache
+ctr_clear_cache:
+ ldr r0, =ctr_clear_cache_kernel
+ svc 0x80 @ svcCustomBackdoor
+ bx lr
+ .endfunc
--- /dev/null
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZCONF_H
+#define ZCONF_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set
+ * this permanently in zconf.h using "./configure --zprefix".
+ */
+#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
+# define Z_PREFIX_SET
+
+/* all linked symbols */
+# define _dist_code z__dist_code
+# define _length_code z__length_code
+# define _tr_align z__tr_align
+# define _tr_flush_bits z__tr_flush_bits
+# define _tr_flush_block z__tr_flush_block
+# define _tr_init z__tr_init
+# define _tr_stored_block z__tr_stored_block
+# define _tr_tally z__tr_tally
+# define adler32 z_adler32
+# define adler32_combine z_adler32_combine
+# define adler32_combine64 z_adler32_combine64
+# ifndef Z_SOLO
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# endif
+# define crc32 z_crc32
+# define crc32_combine z_crc32_combine
+# define crc32_combine64 z_crc32_combine64
+# define deflate z_deflate
+# define deflateBound z_deflateBound
+# define deflateCopy z_deflateCopy
+# define deflateEnd z_deflateEnd
+# define deflateInit2_ z_deflateInit2_
+# define deflateInit_ z_deflateInit_
+# define deflateParams z_deflateParams
+# define deflatePending z_deflatePending
+# define deflatePrime z_deflatePrime
+# define deflateReset z_deflateReset
+# define deflateResetKeep z_deflateResetKeep
+# define deflateSetDictionary z_deflateSetDictionary
+# define deflateSetHeader z_deflateSetHeader
+# define deflateTune z_deflateTune
+# define deflate_copyright z_deflate_copyright
+# define get_crc_table z_get_crc_table
+# ifndef Z_SOLO
+# define gz_error z_gz_error
+# define gz_intmax z_gz_intmax
+# define gz_strwinerror z_gz_strwinerror
+# define gzbuffer z_gzbuffer
+# define gzclearerr z_gzclearerr
+# define gzclose z_gzclose
+# define gzclose_r z_gzclose_r
+# define gzclose_w z_gzclose_w
+# define gzdirect z_gzdirect
+# define gzdopen z_gzdopen
+# define gzeof z_gzeof
+# define gzerror z_gzerror
+# define gzflush z_gzflush
+# define gzgetc z_gzgetc
+# define gzgetc_ z_gzgetc_
+# define gzgets z_gzgets
+# define gzoffset z_gzoffset
+# define gzoffset64 z_gzoffset64
+# define gzopen z_gzopen
+# define gzopen64 z_gzopen64
+# ifdef _WIN32
+# define gzopen_w z_gzopen_w
+# endif
+# define gzprintf z_gzprintf
+# define gzvprintf z_gzvprintf
+# define gzputc z_gzputc
+# define gzputs z_gzputs
+# define gzread z_gzread
+# define gzrewind z_gzrewind
+# define gzseek z_gzseek
+# define gzseek64 z_gzseek64
+# define gzsetparams z_gzsetparams
+# define gztell z_gztell
+# define gztell64 z_gztell64
+# define gzungetc z_gzungetc
+# define gzwrite z_gzwrite
+# endif
+# define inflate z_inflate
+# define inflateBack z_inflateBack
+# define inflateBackEnd z_inflateBackEnd
+# define inflateBackInit_ z_inflateBackInit_
+# define inflateCopy z_inflateCopy
+# define inflateEnd z_inflateEnd
+# define inflateGetHeader z_inflateGetHeader
+# define inflateInit2_ z_inflateInit2_
+# define inflateInit_ z_inflateInit_
+# define inflateMark z_inflateMark
+# define inflatePrime z_inflatePrime
+# define inflateReset z_inflateReset
+# define inflateReset2 z_inflateReset2
+# define inflateSetDictionary z_inflateSetDictionary
+# define inflateGetDictionary z_inflateGetDictionary
+# define inflateSync z_inflateSync
+# define inflateSyncPoint z_inflateSyncPoint
+# define inflateUndermine z_inflateUndermine
+# define inflateResetKeep z_inflateResetKeep
+# define inflate_copyright z_inflate_copyright
+# define inflate_fast z_inflate_fast
+# define inflate_table z_inflate_table
+# ifndef Z_SOLO
+# define uncompress z_uncompress
+# endif
+# define zError z_zError
+# ifndef Z_SOLO
+# define zcalloc z_zcalloc
+# define zcfree z_zcfree
+# endif
+# define zlibCompileFlags z_zlibCompileFlags
+# define zlibVersion z_zlibVersion
+
+/* all zlib typedefs in zlib.h and zconf.h */
+# define Byte z_Byte
+# define Bytef z_Bytef
+# define alloc_func z_alloc_func
+# define charf z_charf
+# define free_func z_free_func
+# ifndef Z_SOLO
+# define gzFile z_gzFile
+# endif
+# define gz_header z_gz_header
+# define gz_headerp z_gz_headerp
+# define in_func z_in_func
+# define intf z_intf
+# define out_func z_out_func
+# define uInt z_uInt
+# define uIntf z_uIntf
+# define uLong z_uLong
+# define uLongf z_uLongf
+# define voidp z_voidp
+# define voidpc z_voidpc
+# define voidpf z_voidpf
+
+/* all zlib structs in zlib.h and zconf.h */
+# define gz_header_s z_gz_header_s
+# define internal_state z_internal_state
+
+#endif
+
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
+# define OS2
+#endif
+#if defined(_WINDOWS) && !defined(WINDOWS)
+# define WINDOWS
+#endif
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
+# ifndef WIN32
+# define WIN32
+# endif
+#endif
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
+# ifndef SYS16BIT
+# define SYS16BIT
+# endif
+# endif
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#ifdef SYS16BIT
+# define MAXSEG_64K
+#endif
+#ifdef MSDOS
+# define UNALIGNED_OK
+#endif
+
+#ifdef __STDC_VERSION__
+# ifndef STDC
+# define STDC
+# endif
+# if __STDC_VERSION__ >= 199901L
+# ifndef STDC99
+# define STDC99
+# endif
+# endif
+#endif
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
+# define STDC
+#endif
+
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
+# define STDC
+#endif
+
+#ifndef STDC
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define const /* note: need a more gentle solution here */
+# endif
+#endif
+
+#if defined(ZLIB_CONST) && !defined(z_const)
+# define z_const const
+#else
+# define z_const
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
+# define NO_DUMMY_DECL
+#endif
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+ /* Type declarations */
+
+#ifndef OF /* function prototypes */
+# ifdef STDC
+# define OF(args) args
+# else
+# define OF(args) ()
+# endif
+#endif
+
+#ifndef Z_ARG /* function prototypes for stdarg */
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# define Z_ARG(args) args
+# else
+# define Z_ARG(args) ()
+# endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#ifdef SYS16BIT
+# if defined(M_I86SM) || defined(M_I86MM)
+ /* MSC small or medium model */
+# define SMALL_MEDIUM
+# ifdef _MSC_VER
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+# if (defined(__SMALL__) || defined(__MEDIUM__))
+ /* Turbo C small or medium model */
+# define SMALL_MEDIUM
+# ifdef __BORLANDC__
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+#endif
+
+#if defined(WINDOWS) || defined(WIN32)
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
+ * This is not mandatory, but it offers a little performance increase.
+ */
+# ifdef ZLIB_DLL
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
+# ifdef ZLIB_INTERNAL
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXTERN extern __declspec(dllimport)
+# endif
+# endif
+# endif /* ZLIB_DLL */
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
+ * define ZLIB_WINAPI.
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
+ */
+# ifdef ZLIB_WINAPI
+# ifdef FAR
+# undef FAR
+# endif
+# include <windows.h>
+ /* No need for _export, use ZLIB.DEF instead. */
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
+# define ZEXPORT WINAPI
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
+# else
+# define ZEXPORTVA FAR CDECL
+# endif
+# endif
+#endif
+
+#if defined (__BEOS__)
+# ifdef ZLIB_DLL
+# ifdef ZLIB_INTERNAL
+# define ZEXPORT __declspec(dllexport)
+# define ZEXPORTVA __declspec(dllexport)
+# else
+# define ZEXPORT __declspec(dllimport)
+# define ZEXPORTVA __declspec(dllimport)
+# endif
+# endif
+#endif
+
+#ifndef ZEXTERN
+# define ZEXTERN extern
+#endif
+#ifndef ZEXPORT
+# define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+# define ZEXPORTVA
+#endif
+
+#ifndef FAR
+# define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char Byte; /* 8 bits */
+#endif
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+# define Bytef Byte FAR
+#else
+ typedef Byte FAR Bytef;
+#endif
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+ typedef void const *voidpc;
+ typedef void FAR *voidpf;
+ typedef void *voidp;
+#else
+ typedef Byte const *voidpc;
+ typedef Byte FAR *voidpf;
+ typedef Byte *voidp;
+#endif
+
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+# include <limits.h>
+# if (UINT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned
+# elif (ULONG_MAX == 0xffffffffUL)
+# define Z_U4 unsigned long
+# elif (USHRT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned short
+# endif
+#endif
+
+#ifdef Z_U4
+ typedef Z_U4 z_crc_t;
+#else
+ typedef unsigned long z_crc_t;
+#endif
+
+#if 1 /* was set to #if 1 by ./configure */
+# define Z_HAVE_UNISTD_H
+#endif
+
+#if 1 /* was set to #if 1 by ./configure */
+# define Z_HAVE_STDARG_H
+#endif
+
+#ifdef STDC
+# ifndef Z_SOLO
+# include <sys/types.h> /* for off_t */
+# endif
+#endif
+
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# ifndef Z_SOLO
+# include <stdarg.h> /* for va_list */
+# endif
+#endif
+
+#ifdef _WIN32
+# ifndef Z_SOLO
+# include <stddef.h> /* for wchar_t */
+# endif
+#endif
+
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
+ * though the former does not conform to the LFS document), but considering
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
+ * equivalently requesting no 64-bit operations
+ */
+#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
+# undef _LARGEFILE64_SOURCE
+#endif
+
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+# define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+# ifdef VMS
+# include <unixio.h> /* for off_t */
+# endif
+# ifndef z_off_t
+# define z_off_t off_t
+# endif
+# endif
+#endif
+
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+# define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+# define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+# define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+
+#ifndef z_off_t
+# define z_off_t long
+#endif
+
+#if !defined(_WIN32) && defined(Z_LARGE64)
+# define z_off64_t off64_t
+#else
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+# define z_off64_t __int64
+# else
+# define z_off64_t z_off_t
+# endif
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+ #pragma map(deflateInit_,"DEIN")
+ #pragma map(deflateInit2_,"DEIN2")
+ #pragma map(deflateEnd,"DEEND")
+ #pragma map(deflateBound,"DEBND")
+ #pragma map(inflateInit_,"ININ")
+ #pragma map(inflateInit2_,"ININ2")
+ #pragma map(inflateEnd,"INEND")
+ #pragma map(inflateSync,"INSY")
+ #pragma map(inflateSetDictionary,"INSEDI")
+ #pragma map(compressBound,"CMBND")
+ #pragma map(inflate_table,"INTABL")
+ #pragma map(inflate_fast,"INFA")
+ #pragma map(inflate_copyright,"INCOPY")
+#endif
+
+#endif /* ZCONF_H */
--- /dev/null
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.2.8, April 28th, 2013
+
+ Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
+*/
+
+#ifndef ZLIB_H
+#define ZLIB_H
+
+#include "zconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZLIB_VERSION "1.2.8"
+#define ZLIB_VERNUM 0x1280
+#define ZLIB_VER_MAJOR 1
+#define ZLIB_VER_MINOR 2
+#define ZLIB_VER_REVISION 8
+#define ZLIB_VER_SUBREVISION 0
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed data.
+ This version of the library supports only one compression method (deflation)
+ but other algorithms will be added later and will have the same stream
+ interface.
+
+ Compression can be done in a single step if the buffers are large enough,
+ or can be done by repeated calls of the compression function. In the latter
+ case, the application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The compressed data format used by default by the in-memory functions is
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
+ around a deflate stream, which is itself documented in RFC 1951.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio using the functions that start
+ with "gz". The gzip format is different from the zlib format. gzip is a
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+
+ This library can optionally read and write gzip streams in memory as well.
+
+ The zlib format was designed to be compact and fast for use in memory
+ and on communications channels. The gzip format was designed for single-
+ file compression on file systems, has a larger header than zlib to maintain
+ directory information, and uses a different, slower check method than zlib.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never crash
+ even in case of corrupted input.
+*/
+
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
+
+struct internal_state;
+
+typedef struct z_stream_s {
+ z_const Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ uLong total_in; /* total number of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ uLong total_out; /* total number of bytes output so far */
+
+ z_const char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
+
+ int data_type; /* best guess about the data type: binary or text */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR *z_streamp;
+
+/*
+ gzip header information passed to and from zlib routines. See RFC 1952
+ for more details on the meanings of these fields.
+*/
+typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /* extra flags (not used when writing a gzip file) */
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+} gz_header;
+
+typedef gz_header FAR *gz_headerp;
+
+/*
+ The application must update next_in and avail_in when avail_in has dropped
+ to zero. It must update next_out and avail_out when avail_out has dropped
+ to zero. The application must initialize zalloc, zfree and opaque before
+ calling the init function. All other fields are set by the compression
+ library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this if
+ the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
+ returned by zalloc for objects of exactly 65536 bytes *must* have their
+ offset normalized to zero. The default allocation function provided by this
+ library ensures this (see zutil.c). To reduce memory requirements and avoid
+ any allocation of 64K objects, at the expense of compression ratio, compile
+ the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or progress
+ reports. After compression, total_in holds the total size of the
+ uncompressed data and may be saved for use in the decompressor (particularly
+ if the decompressor wants to decompress everything in a single step).
+*/
+
+ /* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+#define Z_BLOCK 5
+#define Z_TREES 6
+/* Allowed flush values; see deflate() and inflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions. Negative values
+ * are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
+#define Z_FIXED 4
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_TEXT 1
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field (though see inflate()) */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+
+ /* basic functions */
+
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is not
+ compatible with the zlib.h header file used by the application. This check
+ is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller. If
+ zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
+ allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at all
+ (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
+ requests a default compromise between speed and compression (currently
+ equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if level is not a valid compression level, or
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION). msg is set to null
+ if there is no error message. deflateInit does not perform any compression:
+ this will be done by deflate().
+*/
+
+
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications). Some
+ output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming more
+ output, and updating avail_in or avail_out accordingly; avail_out should
+ never be zero before the call. The application can consume the compressed
+ output when it wants, for example when the output buffer is full (avail_out
+ == 0), or after each call of deflate(). If deflate returns Z_OK and with
+ zero avail_out, it must be called again after making room in the output
+ buffer because there might be more output pending.
+
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
+ decide how much data to accumulate before producing output, in order to
+ maximize compression.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In
+ particular avail_in is zero after the call if enough output space has been
+ provided before the call.) Flushing may degrade compression for some
+ compression algorithms and so it should be used only when necessary. This
+ completes the current deflate block and follows it with an empty stored block
+ that is three bits plus filler bits to the next byte, followed by four bytes
+ (00 00 ff ff).
+
+ If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
+ output buffer, but the output is not aligned to a byte boundary. All of the
+ input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
+ This completes the current deflate block and follows it with an empty fixed
+ codes block that is 10 bits long. This assures that enough bytes are output
+ in order for the decompressor to finish the block before the empty fixed code
+ block.
+
+ If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
+ for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
+ seven bits of the current block are held to be written as the next byte after
+ the next deflate block is completed. In this case, the decompressor may not
+ be provided enough bits at this point in order to complete decompression of
+ the data provided so far to the compressor. It may need to wait for the next
+ block to be emitted. This is for advanced applications that need to control
+ the emission of deflate blocks.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
+ avail_out is greater than six to avoid repeated flush markers due to
+ avail_out == 0 on return.
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there was
+ enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the stream
+ are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least the
+ value returned by deflateBound (see below). Then deflate is guaranteed to
+ return Z_STREAM_END. If not enough output space is provided, deflate will
+ not return Z_STREAM_END, and it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so far (that is, total_in bytes).
+
+ deflate() may update strm->data_type if it can make a good guess about
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect the
+ compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
+ fatal, and deflate() can be called again with more input and more output
+ space to continue compressing.
+*/
+
+
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any pending
+ output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case, msg
+ may be set but then points to a static string (which must not be
+ deallocated).
+*/
+
+
+/*
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the
+ exact value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
+ invalid, such as a null pointer to the structure. msg is set to null if
+ there is no error message. inflateInit does not perform any decompression
+ apart from possibly reading the zlib header if present: actual decompression
+ will be done by inflate(). (So next_in and avail_in may be modified, but
+ next_out and avail_out are unused and unchanged.) The current implementation
+ of inflateInit() does not process any header information -- that is deferred
+ until inflate() is called.
+*/
+
+
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing will
+ resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there is
+ no more input data or no more space in the output buffer (see below about
+ the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming more
+ output, and updating the next_* and avail_* values accordingly. The
+ application can consume the uncompressed output when it wants, for example
+ when the output buffer is full (avail_out == 0), or after each call of
+ inflate(). If inflate returns Z_OK and with zero avail_out, it must be
+ called again after making room in the output buffer because there might be
+ more output pending.
+
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
+ Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
+ output as possible to the output buffer. Z_BLOCK requests that inflate()
+ stop if and when it gets to the next deflate block boundary. When decoding
+ the zlib or gzip format, this will cause inflate() to return immediately
+ after the header and before the first block. When doing a raw inflate,
+ inflate() will go ahead and process the first block, and will return when it
+ gets to the end of that block, or when it runs out of data.
+
+ The Z_BLOCK option assists in appending to or combining deflate streams.
+ Also to assist in this, on return inflate() will set strm->data_type to the
+ number of unused bits in the last byte taken from strm->next_in, plus 64 if
+ inflate() is currently decoding the last block in the deflate stream, plus
+ 128 if inflate() returned immediately after decoding an end-of-block code or
+ decoding the complete header up to just before the first byte of the deflate
+ stream. The end-of-block will not be indicated until all of the uncompressed
+ data from that block has been written to strm->next_out. The number of
+ unused bits may in general be greater than seven, except when bit 7 of
+ data_type is set, in which case the number of unused bits will be less than
+ eight. data_type is set as noted here every time inflate() returns for all
+ flush options, and so can be used to determine the amount of currently
+ consumed input in bits.
+
+ The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
+ end of each deflate block header is reached, before any actual data in that
+ block is decoded. This allows the caller to determine the length of the
+ deflate block header for later use in random access within a deflate block.
+ 256 is added to the value of strm->data_type when inflate() returns
+ immediately after reaching the end of the deflate block header.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step (a
+ single call of inflate), the parameter flush should be set to Z_FINISH. In
+ this case all pending input is processed and all pending output is flushed;
+ avail_out must be large enough to hold all of the uncompressed data for the
+ operation to complete. (The size of the uncompressed data may have been
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
+ required to perform an inflation in one step. However it may be used to
+ inform inflate that a faster approach can be used for the single inflate()
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
+ stream completes, which reduces inflate's memory footprint. If the stream
+ does not complete, either because not all of the stream is provided or not
+ enough output space is provided, then a sliding window will be allocated and
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
+ been used.
+
+ In this implementation, inflate() always flushes as much output as
+ possible to the output buffer, and always uses the faster approach on the
+ first call. So the effects of the flush parameter in this implementation are
+ on the return value of inflate() as noted below, when inflate() returns early
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
+ memory for a sliding window when Z_FINISH is used.
+
+ If a preset dictionary is needed after this call (see inflateSetDictionary
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
+ below. At the end of the stream, inflate() checks that its computed adler32
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
+ only if the checksum is correct.
+
+ inflate() can decompress and check either zlib-wrapped or gzip-wrapped
+ deflate data. The header type is detected automatically, if requested when
+ initializing with inflateInit2(). Any information contained in the gzip
+ header is not retained, so applications that need that information should
+ instead use raw inflate, see inflateInit2() below, or inflateBack() and
+ perform their own processing of the gzip header and trailer. When processing
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
+ producted so far. The CRC-32 is checked against the gzip trailer.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect check
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+ next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ inflate() can be called again with more input and more output space to
+ continue decompressing. If Z_DATA_ERROR is returned, the application may
+ then call inflateSync() to look for a good compression block if a partial
+ recovery of the data is desired.
+*/
+
+
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any pending
+ output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+*/
+
+
+ /* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+*/
+
+/*
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by the
+ caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
+ determines the window size. deflate() will then generate raw deflate data
+ with no zlib header or trailer, and will not compute an adler32 check value.
+
+ windowBits can also be greater than 15 for optional gzip encoding. Add
+ 16 to windowBits to write a simple gzip header and trailer around the
+ compressed data instead of a zlib wrapper. The gzip header will have no
+ file name, no extra data, no comment, no modification time (set to zero), no
+ header crc, and the operating system will be set to 255 (unknown). If a
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but is
+ slow and reduces compression ratio; memLevel=9 uses maximum memory for
+ optimal speed. The default value is 8. See zconf.h for total memory usage
+ as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match), or Z_RLE to limit match distances to one (run-length
+ encoding). Filtered data consists mostly of small values with a somewhat
+ random distribution. In this case, the compression algorithm is tuned to
+ compress them better. The effect of Z_FILTERED is to force more Huffman
+ coding and less string matching; it is somewhat intermediate between
+ Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
+ fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
+ strategy parameter only affects the compression ratio but not the
+ correctness of the compressed output even if it is not set appropriately.
+ Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
+ decoder for special applications.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
+ method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
+ incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
+ set to null if there is no error message. deflateInit2 does not perform any
+ compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. When using the zlib format, this
+ function must be called immediately after deflateInit, deflateInit2 or
+ deflateReset, and before any call of deflate. When doing raw deflate, this
+ function must be called either before any call of deflate, or immediately
+ after the completion of a deflate block, i.e. after all input has been
+ consumed and all output has been delivered when using any of the flush
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
+ compressor and decompressor must use exactly the same dictionary (see
+ inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size
+ provided in deflateInit or deflateInit2. Thus the strings most likely to be
+ useful should be put at the end of the dictionary, not at the front. In
+ addition, the current implementation of deflate will use at most the window
+ size minus 262 bytes of the provided dictionary.
+
+ Upon return of this function, strm->adler is set to the adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.) If a raw deflate was requested, then the
+ adler32 value is not computed and strm->adler is not set.
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
+ not perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and can
+ consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state. The
+ stream will keep the same compression level and any other attributes that
+ may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
+*/
+
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
+ int level,
+ int strategy));
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different strategy.
+ If the compression level is changed, the input available so far is
+ compressed with the old level (and may be flushed); the new level will take
+ effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to be
+ compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
+ strm->avail_out was zero.
+*/
+
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
+ int good_length,
+ int max_lazy,
+ int nice_length,
+ int max_chain));
+/*
+ Fine tune deflate's internal compression parameters. This should only be
+ used by someone who understands the algorithm used by zlib's deflate for
+ searching for the best matching string, and even then only by the most
+ fanatic optimizer trying to squeeze out the last compressed bit for their
+ specific input data. Read the deflate.c source code for the meaning of the
+ max_lazy, good_length, nice_length, and max_chain parameters.
+
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
+ */
+
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
+ uLong sourceLen));
+/*
+ deflateBound() returns an upper bound on the compressed size after
+ deflation of sourceLen bytes. It must be called after deflateInit() or
+ deflateInit2(), and after deflateSetHeader(), if used. This would be used
+ to allocate an output buffer for deflation in a single pass, and so would be
+ called before deflate(). If that first deflate() call is provided the
+ sourceLen input bytes, an output buffer allocated to the size returned by
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
+ be larger than the value returned by deflateBound() if flush options other
+ than Z_FINISH or Z_NO_FLUSH are used.
+*/
+
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
+ unsigned *pending,
+ int *bits));
+/*
+ deflatePending() returns the number of bytes and bits of output that have
+ been generated, but not yet provided in the available output. The bytes not
+ provided would be due to the available output space having being consumed.
+ The number of bits of output not provided are between 0 and 7, where they
+ await more bits to join them in order to fill out a full byte. If pending
+ or bits are Z_NULL, then those values are not set.
+
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+ */
+
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ deflatePrime() inserts bits in the deflate output stream. The intent
+ is that this function is used to start off the deflate output with the bits
+ leftover from a previous deflate stream when appending to it. As such, this
+ function can only be used for raw deflate, and must be used before the first
+ deflate() call after a deflateInit2() or deflateReset(). bits must be less
+ than or equal to 16, and that many of the least significant bits of value
+ will be inserted in the output.
+
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
+ source stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ deflateSetHeader() provides gzip header information for when a gzip
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
+ after deflateInit2() or deflateReset() and before the first call of
+ deflate(). The text, time, os, extra field, name, and comment information
+ in the provided gz_header structure are written to the gzip header (xflag is
+ ignored -- the extra flags are set according to the compression level). The
+ caller must assure that, if not Z_NULL, name and comment are terminated with
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
+ available there. If hcrc is true, a gzip header crc is included. Note that
+ the current versions of the command-line version of gzip (up through version
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
+ gzip file" and give up.
+
+ If deflateSetHeader is not used, the default gzip header has text false,
+ the time set to zero, and os set to 255, with no extra, name, or comment
+ fields. The gzip header is returned to the default state by deflateReset().
+
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. windowBits must be greater than or equal to the windowBits value
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
+ deflateInit2() was not used. If a compressed stream with a larger window
+ size is given as input, inflate() will return with the error code
+ Z_DATA_ERROR instead of trying to allocate a larger window.
+
+ windowBits can also be zero to request that inflate use the window size in
+ the zlib header of the compressed stream.
+
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+ determines the window size. inflate() will then process raw deflate data,
+ not looking for a zlib or gzip header, not generating a check value, and not
+ looking for any check values for comparison at the end of the stream. This
+ is for use with other formats that use the deflate compressed data format
+ such as zip. Those formats provide their own check values. If a custom
+ format is developed using the raw deflate format for compressed data, it is
+ recommended that a check value such as an adler32 or a crc32 be applied to
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
+ most applications, the zlib format should be used as is. Note that comments
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
+
+ windowBits can also be greater than 15 for optional gzip decoding. Add
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
+ detection, or add 16 to decode only the gzip format (the zlib format will
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
+ crc32 instead of an adler32.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
+ invalid, such as a null pointer to the structure. msg is set to null if
+ there is no error message. inflateInit2 does not perform any decompression
+ apart from possibly reading the zlib header if present: actual decompression
+ will be done by inflate(). (So next_in and avail_in may be modified, but
+ next_out and avail_out are unused and unchanged.) The current implementation
+ of inflateInit2() does not process any header information -- that is
+ deferred until inflate() is called.
+*/
+
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate,
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the adler32 value returned by that call of inflate.
+ The compressor and decompressor must use exactly the same dictionary (see
+ deflateSetDictionary). For raw inflate, this function can be called at any
+ time to set the dictionary. If the provided dictionary is smaller than the
+ window and there is already data in the window, then the provided dictionary
+ will amend what's there. The application must insure that the dictionary
+ that was used for compression is provided.
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+*/
+
+ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
+ Bytef *dictionary,
+ uInt *dictLength));
+/*
+ Returns the sliding dictionary being maintained by inflate. dictLength is
+ set to the number of bytes in the dictionary, and that many bytes are copied
+ to dictionary. dictionary must have enough space, where 32768 bytes is
+ always enough. If inflateGetDictionary() is called with dictionary equal to
+ Z_NULL, then only the dictionary length is returned, and nothing is copied.
+ Similary, if dictLength is Z_NULL, then it is not set.
+
+ inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
+ stream state is inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
+/*
+ Skips invalid compressed data until a possible full flush point (see above
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
+ All full flush points have this pattern, but not all occurrences of this
+ pattern are full flush points.
+
+ inflateSync returns Z_OK if a possible full flush point has been found,
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
+ In the success case, the application may save the current current value of
+ total_in which indicates where valid compressed data was found. In the
+ error case, the application may repeatedly call inflateSync, providing more
+ input each time, until success or end of the input data.
+*/
+
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when randomly accessing a large stream. The
+ first pass through the stream can periodically record the inflate state,
+ allowing restarting inflate at those points when randomly accessing the
+ stream.
+
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state. The
+ stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
+*/
+
+ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
+ int windowBits));
+/*
+ This function is the same as inflateReset, but it also permits changing
+ the wrap and window size requests. The windowBits parameter is interpreted
+ the same as it is for inflateInit2.
+
+ inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL), or if
+ the windowBits parameter is invalid.
+*/
+
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ This function inserts bits in the inflate input stream. The intent is
+ that this function is used to start inflating at a bit position in the
+ middle of a byte. The provided bits will be used before any bytes are used
+ from next_in. This function should only be used with raw inflate, and
+ should be used before the first inflate() call after inflateInit2() or
+ inflateReset(). bits must be less than or equal to 16, and that many of the
+ least significant bits of value will be inserted in the input.
+
+ If bits is negative, then the input stream bit buffer is emptied. Then
+ inflatePrime() can be called again to put bits in the buffer. This is used
+ to clear out bits leftover after feeding inflate a block description prior
+ to feeding inflate codes.
+
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
+/*
+ This function returns two values, one in the lower 16 bits of the return
+ value, and the other in the remaining upper bits, obtained by shifting the
+ return value down 16 bits. If the upper value is -1 and the lower value is
+ zero, then inflate() is currently decoding information outside of a block.
+ If the upper value is -1 and the lower value is non-zero, then inflate is in
+ the middle of a stored block, with the lower value equaling the number of
+ bytes from the input remaining to copy. If the upper value is not -1, then
+ it is the number of bits back from the current bit position in the input of
+ the code (literal or length/distance pair) currently being processed. In
+ that case the lower value is the number of bytes already emitted for that
+ code.
+
+ A code is being processed if inflate is waiting for more input to complete
+ decoding of the code, or if it has completed decoding but is waiting for
+ more output space to write the literal or match data.
+
+ inflateMark() is used to mark locations in the input data for random
+ access, which may be at bit positions, and to note those cases where the
+ output of a code may span boundaries of random access blocks. The current
+ location in the input stream can be determined from avail_in and data_type
+ as noted in the description for the Z_BLOCK flush parameter for inflate.
+
+ inflateMark returns the value noted above or -1 << 16 if the provided
+ source stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ inflateGetHeader() requests that gzip header information be stored in the
+ provided gz_header structure. inflateGetHeader() may be called after
+ inflateInit2() or inflateReset(), and before the first call of inflate().
+ As inflate() processes the gzip stream, head->done is zero until the header
+ is completed, at which time head->done is set to one. If a zlib stream is
+ being decoded, then head->done is set to -1 to indicate that there will be
+ no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
+ used to force inflate() to return immediately after header processing is
+ complete and before any actual data is decompressed.
+
+ The text, time, xflags, and os fields are filled in with the gzip header
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
+ contains the maximum number of bytes to write to extra. Once done is true,
+ extra_len contains the actual extra field length, and extra contains the
+ extra field, or that field truncated if extra_max is less than extra_len.
+ If name is not Z_NULL, then up to name_max characters are written there,
+ terminated with a zero unless the length is greater than name_max. If
+ comment is not Z_NULL, then up to comm_max characters are written there,
+ terminated with a zero unless the length is greater than comm_max. When any
+ of extra, name, or comment are not Z_NULL and the respective field is not
+ present in the header, then that field is set to Z_NULL to signal its
+ absence. This allows the use of deflateSetHeader() with the returned
+ structure to duplicate the header. However if those fields are set to
+ allocated memory, then the application will need to save those pointers
+ elsewhere so that they can be eventually freed.
+
+ If inflateGetHeader is not used, then the header information is simply
+ discarded. The header is always checked for validity, including the header
+ CRC if present. inflateReset() will reset the process to discard the header
+ information. The application would need to call inflateGetHeader() again to
+ retrieve the header from the next gzip stream.
+
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window));
+
+ Initialize the internal stream state for decompression using inflateBack()
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
+ derived memory allocation routines are used. windowBits is the base two
+ logarithm of the window size, in the range 8..15. window is a caller
+ supplied buffer of that size. Except for special applications where it is
+ assured that deflate was used with small window sizes, windowBits must be 15
+ and a 32K byte window must be supplied to be able to decompress general
+ deflate streams.
+
+ See inflateBack() for the usage of these routines.
+
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
+ allocated, or Z_VERSION_ERROR if the version of the library does not match
+ the version of the header file.
+*/
+
+typedef unsigned (*in_func) OF((void FAR *,
+ z_const unsigned char FAR * FAR *));
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
+
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
+ in_func in, void FAR *in_desc,
+ out_func out, void FAR *out_desc));
+/*
+ inflateBack() does a raw inflate with a single call using a call-back
+ interface for input and output. This is potentially more efficient than
+ inflate() for file i/o applications, in that it avoids copying between the
+ output and the sliding window by simply making the window itself the output
+ buffer. inflate() can be faster on modern CPUs when used with large
+ buffers. inflateBack() trusts the application to not change the output
+ buffer passed by the output function, at least until inflateBack() returns.
+
+ inflateBackInit() must be called first to allocate the internal state
+ and to initialize the state with the user-provided window buffer.
+ inflateBack() may then be used multiple times to inflate a complete, raw
+ deflate stream with each call. inflateBackEnd() is then called to free the
+ allocated state.
+
+ A raw deflate stream is one with no zlib or gzip header or trailer.
+ This routine would normally be used in a utility that reads zip or gzip
+ files and writes out uncompressed files. The utility would decode the
+ header and process the trailer on its own, hence this routine expects only
+ the raw deflate stream to decompress. This is different from the normal
+ behavior of inflate(), which expects either a zlib or gzip header and
+ trailer around the deflate stream.
+
+ inflateBack() uses two subroutines supplied by the caller that are then
+ called by inflateBack() for input and output. inflateBack() calls those
+ routines until it reads a complete deflate stream and writes out all of the
+ uncompressed data, or until it encounters an error. The function's
+ parameters and return types are defined above in the in_func and out_func
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
+ number of bytes of provided input, and a pointer to that input in buf. If
+ there is no input available, in() must return zero--buf is ignored in that
+ case--and inflateBack() will return a buffer error. inflateBack() will call
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
+ should return zero on success, or non-zero on failure. If out() returns
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
+ are permitted to change the contents of the window provided to
+ inflateBackInit(), which is also the buffer that out() uses to write from.
+ The length written by out() will be at most the window size. Any non-zero
+ amount of input may be provided by in().
+
+ For convenience, inflateBack() can be provided input on the first call by
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
+ in() will be called. Therefore strm->next_in must be initialized before
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
+ must also be initialized, and then if strm->avail_in is not zero, input will
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
+
+ The in_desc and out_desc parameters of inflateBack() is passed as the
+ first parameter of in() and out() respectively when they are called. These
+ descriptors can be optionally used to pass any information that the caller-
+ supplied in() and out() functions need to do their job.
+
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
+ pass back any unused input that was provided by the last in() call. The
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format error
+ in the deflate stream (in which case strm->msg is set to indicate the nature
+ of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
+ In the case of Z_BUF_ERROR, an input or output error can be distinguished
+ using strm->next_in which will be Z_NULL only if in() returned an error. If
+ strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
+ non-zero. (in() will always be called before out(), so strm->next_in is
+ assured to be defined if out() returns non-zero.) Note that inflateBack()
+ cannot return Z_OK.
+*/
+
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
+/*
+ All memory allocated by inflateBackInit() is freed.
+
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
+ state was inconsistent.
+*/
+
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
+/* Return flags indicating compile-time options.
+
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
+ 1.0: size of uInt
+ 3.2: size of uLong
+ 5.4: size of voidpf (pointer)
+ 7.6: size of z_off_t
+
+ Compiler, assembler, and debug options:
+ 8: DEBUG
+ 9: ASMV or ASMINF -- use ASM code
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
+ 11: 0 (reserved)
+
+ One-time table building (smaller code, but not thread-safe if true):
+ 12: BUILDFIXED -- build static block decoding tables when needed
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
+ 14,15: 0 (reserved)
+
+ Library content (indicates missing functionality):
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
+ deflate code when not needed)
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
+ and decode gzip streams (to avoid linking crc code)
+ 18-19: 0 (reserved)
+
+ Operation variations (changes in library functionality):
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
+ 22,23: 0 (reserved)
+
+ The sprintf variant used by gzprintf (zero is best):
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
+
+ Remainder:
+ 27-31: 0 (reserved)
+ */
+
+#ifndef Z_SOLO
+
+ /* utility functions */
+
+/*
+ The following utility functions are implemented on top of the basic
+ stream-oriented functions. To simplify the interface, some default options
+ are assumed (compression level and memory usage, standard memory allocation
+ functions). The source code of these utility functions can be modified if
+ you need special options.
+*/
+
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total size
+ of the destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+*/
+
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
+/*
+ compressBound() returns an upper bound on the compressed size after
+ compress() or compress2() on sourceLen bytes. It would be used before a
+ compress() or compress2() call to allocate the destination buffer.
+*/
+
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total size
+ of the destination buffer, which must be large enough to hold the entire
+ uncompressed data. (The size of the uncompressed data must have been saved
+ previously by the compressor and transmitted to the decompressor by some
+ mechanism outside the scope of this compression library.) Upon exit, destLen
+ is the actual size of the uncompressed buffer.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
+ the case where there is not enough room, uncompress() will fill the output
+ buffer with the uncompressed data up to that point.
+*/
+
+ /* gzip file access functions */
+
+/*
+ This library supports reading and writing files in gzip (.gz) format with
+ an interface similar to that of stdio, using the functions that start with
+ "gz". The gzip format is different from the zlib format. gzip is a gzip
+ wrapper, documented in RFC 1952, wrapped around a deflate stream.
+*/
+
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
+
+/*
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
+
+ Opens a gzip (.gz) file for reading or writing. The mode parameter is as
+ in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
+ a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
+ compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
+ for fixed code compression as in "wb9F". (See the description of
+ deflateInit2 for more information about the strategy parameter.) 'T' will
+ request transparent writing or appending with no compression and not using
+ the gzip format.
+
+ "a" can be used instead of "w" to request that the gzip stream that will
+ be written be appended to the file. "+" will result in an error, since
+ reading and writing to the same gzip file is not supported. The addition of
+ "x" when writing will create the file exclusively, which fails if the file
+ already exists. On systems that support it, the addition of "e" when
+ reading or writing will set the flag to close the file on an execve() call.
+
+ These functions, as well as gzip, will read and decode a sequence of gzip
+ streams in a file. The append function of gzopen() can be used to create
+ such a file. (Also see gzflush() for another way to do this.) When
+ appending, gzopen does not test whether the file begins with a gzip stream,
+ nor does it look for the end of the gzip streams to begin appending. gzopen
+ will simply append a gzip stream to the existing file.
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression. When
+ reading, this will be detected automatically by looking for the magic two-
+ byte gzip header.
+
+ gzopen returns NULL if the file could not be opened, if there was
+ insufficient memory to allocate the gzFile state, or if an invalid mode was
+ specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
+ errno can be checked to determine if the reason gzopen failed was that the
+ file could not be opened.
+*/
+
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
+/*
+ gzdopen associates a gzFile with the file descriptor fd. File descriptors
+ are obtained from calls like open, dup, creat, pipe or fileno (if the file
+ has been previously opened with fopen). The mode parameter is as in gzopen.
+
+ The next call of gzclose on the returned gzFile will also close the file
+ descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
+ fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
+ mode);. The duplicated descriptor should be saved to avoid a leak, since
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
+ file descriptor from a FILE *, then you will have to use dup() to avoid
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
+ close the associated file descriptor, so they need to have different file
+ descriptors.
+
+ gzdopen returns NULL if there was insufficient memory to allocate the
+ gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
+ provided, or '+' was provided), or if fd is -1. The file descriptor is not
+ used until the next gz* read, write, seek, or close operation, so gzdopen
+ will not detect if fd is invalid (unless fd is -1).
+*/
+
+ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
+/*
+ Set the internal buffer size used by this library's functions. The
+ default buffer size is 8192 bytes. This function must be called after
+ gzopen() or gzdopen(), and before any other calls that read or write the
+ file. The buffer memory allocation is always deferred to the first read or
+ write. Two buffers are allocated, either both of the specified size when
+ writing, or one of the specified size and the other twice that size when
+ reading. A larger buffer size of, for example, 64K or 128K bytes will
+ noticeably increase the speed of decompression (reading).
+
+ The new buffer size also affects the maximum length for gzprintf().
+
+ gzbuffer() returns 0 on success, or -1 on failure, such as being called
+ too late.
+*/
+
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+*/
+
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+/*
+ Reads the given number of uncompressed bytes from the compressed file. If
+ the input file is not in gzip format, gzread copies the given number of
+ bytes into the buffer directly from the file.
+
+ After reaching the end of a gzip stream in the input, gzread will continue
+ to read, looking for another gzip stream. Any number of gzip streams may be
+ concatenated in the input file, and will all be decompressed by gzread().
+ If something other than a gzip stream is encountered after a gzip stream,
+ that remaining trailing garbage is ignored (and no error is returned).
+
+ gzread can be used to read a gzip file that is being concurrently written.
+ Upon reaching the end of the input, gzread will return with the available
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+ gzclearerr can be used to clear the end of file indicator in order to permit
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
+ middle of a gzip stream. Note that gzread does not return -1 in the event
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+ stream. Alternatively, gzerror can be used before gzclose to detect this
+ case.
+
+ gzread returns the number of uncompressed bytes actually read, less than
+ len for end of file, or -1 for error.
+*/
+
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
+ voidpc buf, unsigned len));
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes written or 0 in case of
+ error.
+*/
+
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
+/*
+ Converts, formats, and writes the arguments to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written, or 0 in case of error. The number of
+ uncompressed bytes written is limited to 8191, or one less than the buffer
+ size given to gzbuffer(). The caller should assure that this limit is not
+ exceeded. If it is exceeded, then gzprintf() will return an error (0) with
+ nothing written. In this case, there may also be a buffer overflow with
+ unpredictable consequences, which is possible only if zlib was compiled with
+ the insecure functions sprintf() or vsprintf() because the secure snprintf()
+ or vsnprintf() functions were not available. This can be determined using
+ zlibCompileFlags().
+*/
+
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or a
+ newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. If any characters are read or if len == 1, the
+ string is terminated with a null character. If no characters are read due
+ to an end-of-file or len < 1, then the buffer is left untouched.
+
+ gzgets returns buf which is a null-terminated string, or it returns NULL
+ for end-of-file or in case of error. If there was an error, the contents at
+ buf are indeterminate.
+*/
+
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
+/*
+ Writes c, converted to an unsigned char, into the compressed file. gzputc
+ returns the value that was written, or -1 in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte or -1
+ in case of end of file or error. This is implemented as a macro for speed.
+ As such, it does not do all of the checking the other functions do. I.e.
+ it does not check to see if file is NULL, nor whether the structure file
+ points to has been clobbered or not.
+*/
+
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
+/*
+ Push one character back onto the stream to be read as the first character
+ on the next read. At least one character of push-back is allowed.
+ gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
+ fail if c is -1, and may fail if a character has been pushed but not read
+ yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
+ output buffer size of pushed characters is allowed. (See gzbuffer above.)
+ The pushed character will be discarded if the stream is repositioned with
+ gzseek() or gzrewind().
+*/
+
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
+/*
+ Flushes all pending output into the compressed file. The parameter flush
+ is as in the deflate() function. The return value is the zlib error number
+ (see function gzerror below). gzflush is only permitted when writing.
+
+ If the flush parameter is Z_FINISH, the remaining data is written and the
+ gzip stream is completed in the output. If gzwrite() is called again, a new
+ gzip stream will be started in the output. gzread() is able to read such
+ concatented gzip streams.
+
+ gzflush should be called only when strictly necessary because it will
+ degrade compression if called too often.
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
+ z_off_t offset, int whence));
+
+ Sets the starting position for the next gzread or gzwrite on the given
+ compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+*/
+
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
+
+ Returns the starting position for the next gzread or gzwrite on the given
+ compressed file. This position represents a number of bytes in the
+ uncompressed data stream, and is zero when starting, even if appending or
+ reading a gzip stream from the middle of a file using gzdopen().
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
+
+ Returns the current offset in the file being read or written. This offset
+ includes the count of bytes that precede the gzip stream, for example when
+ appending or when using gzdopen() for reading. When reading, the offset
+ does not include as yet unused buffered input. This information can be used
+ for a progress indicator. On error, gzoffset() returns -1.
+*/
+
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
+/*
+ Returns true (1) if the end-of-file indicator has been set while reading,
+ false (0) otherwise. Note that the end-of-file indicator is set only if the
+ read tried to go past the end of the input, but came up short. Therefore,
+ just like feof(), gzeof() may return false even if there is no more data to
+ read, in the event that the last read request was for the exact number of
+ bytes remaining in the input file. This will happen if the input file size
+ is an exact multiple of the buffer size.
+
+ If gzeof() returns true, then the read functions will return no more data,
+ unless the end-of-file indicator is reset by gzclearerr() and the input file
+ has grown since the previous end of file was detected.
+*/
+
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
+/*
+ Returns true (1) if file is being copied directly while reading, or false
+ (0) if file is a gzip stream being decompressed.
+
+ If the input file is empty, gzdirect() will return true, since the input
+ does not contain a gzip stream.
+
+ If gzdirect() is used immediately after gzopen() or gzdopen() it will
+ cause buffers to be allocated to allow reading the file to determine if it
+ is a gzip file. Therefore if gzbuffer() is used, it should be called before
+ gzdirect().
+
+ When writing, gzdirect() returns true (1) if transparent writing was
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
+ gzdirect() is not needed when writing. Transparent writing must be
+ explicitly requested, so the application already knows the answer. When
+ linking statically, using gzdirect() will include all of the zlib code for
+ gzip file reading and decompression, which may not be desired.)
+*/
+
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
+/*
+ Flushes all pending output if necessary, closes the compressed file and
+ deallocates the (de)compression state. Note that once file is closed, you
+ cannot call gzerror with file, since its structures have been deallocated.
+ gzclose must not be called more than once on the same file, just as free
+ must not be called more than once on the same allocation.
+
+ gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+ last read ended in the middle of a gzip stream, or Z_OK on success.
+*/
+
+ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
+ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
+/*
+ Same as gzclose(), but gzclose_r() is only for use when reading, and
+ gzclose_w() is only for use when writing or appending. The advantage to
+ using these instead of gzclose() is that they avoid linking in zlib
+ compression or decompression code that is not used when only reading or only
+ writing respectively. If gzclose() is used, then both compression and
+ decompression code will be included the application when linking to a static
+ zlib library.
+*/
+
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
+/*
+ Returns the error message for the last error which occurred on the given
+ compressed file. errnum is set to zlib error number. If an error occurred
+ in the file system and not in the compression library, errnum is set to
+ Z_ERRNO and the application may consult errno to get the exact error code.
+
+ The application must not modify the returned string. Future calls to
+ this function may invalidate the previously returned string. If file is
+ closed, then the string previously returned by gzerror will no longer be
+ available.
+
+ gzerror() should be used to distinguish errors from end-of-file for those
+ functions above that do not distinguish those cases in their return values.
+*/
+
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
+/*
+ Clears the error and end-of-file flags for file. This is analogous to the
+ clearerr() function in stdio. This is useful for continuing to read a gzip
+ file that is being written concurrently.
+*/
+
+#endif /* !Z_SOLO */
+
+ /* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the compression
+ library.
+*/
+
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is Z_NULL, this function returns the
+ required initial value for the checksum.
+
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster.
+
+ Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+*/
+
+/*
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
+ z_off_t len2));
+
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
+ negative, the result has no meaning or utility.
+*/
+
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+/*
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
+ updated CRC-32. If buf is Z_NULL, this function returns the required
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
+
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+*/
+
+/*
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
+
+ Combine two CRC-32 check values into one. For two sequences of bytes,
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
+ len2.
+*/
+
+
+ /* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size));
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window,
+ const char *version,
+ int stream_size));
+#define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+#define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+#define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
+#define inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, (int)sizeof(z_stream))
+
+#ifndef Z_SOLO
+
+/* gzgetc() macro and its supporting function and exposed data structure. Note
+ * that the real internal state is much larger than the exposed structure.
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
+ * user should not mess with these exposed elements, since their names or
+ * behavior could change in the future, perhaps even capriciously. They can
+ * only be used by the gzgetc() macro. You have been warned.
+ */
+struct gzFile_s {
+ unsigned have;
+ unsigned char *next;
+ z_off64_t pos;
+};
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
+#ifdef Z_PREFIX_SET
+# undef z_gzgetc
+# define z_gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#else
+# define gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#endif
+
+/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
+ * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
+ * both are true, the application gets the *64 functions, and the regular
+ * functions are changed to 64 bits) -- in case these are set on systems
+ * without large file support, _LFS64_LARGEFILE must also be true
+ */
+#ifdef Z_LARGE64
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
+ ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
+ ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
+ ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
+#endif
+
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
+# ifdef Z_PREFIX_SET
+# define z_gzopen z_gzopen64
+# define z_gzseek z_gzseek64
+# define z_gztell z_gztell64
+# define z_gzoffset z_gzoffset64
+# define z_adler32_combine z_adler32_combine64
+# define z_crc32_combine z_crc32_combine64
+# else
+# define gzopen gzopen64
+# define gzseek gzseek64
+# define gztell gztell64
+# define gzoffset gzoffset64
+# define adler32_combine adler32_combine64
+# define crc32_combine crc32_combine64
+# endif
+# ifndef Z_LARGE64
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
+ ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
+ ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
+ ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
+# endif
+#else
+ ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
+ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
+ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
+ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+#endif
+
+#else /* Z_SOLO */
+
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+
+#endif /* !Z_SOLO */
+
+/* hack for buggy compilers */
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
+ struct internal_state {int dummy;};
+#endif
+
+/* undocumented functions */
+ZEXTERN const char * ZEXPORT zError OF((int));
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
+ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
+#if defined(_WIN32) && !defined(Z_SOLO)
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
+ const char *mode));
+#endif
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# ifndef Z_SOLO
+ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
+ const char *format,
+ va_list va));
+# endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZLIB_H */
update_option_visibility();
- if (old_fps != psxGetFps())
+ if (in_flight && old_fps != psxGetFps())
{
struct retro_system_av_info info;
retro_get_system_av_info(&info);
},
"disabled",
},
-#ifndef _WIN32
+#if 0 // ndef _WIN32 // currently disabled, see USE_READ_THREAD in libpcsxcore/cdriso.c
{
"pcsx_rearmed_async_cd",
"CD Access Method (Restart)",
#endif
{
"pcsx_rearmed_psxclock",
- "PSX CPU Clock Speed",
+ "PSX CPU Clock Speed (%)",
NULL,
- "Overclock or under-clock the PSX CPU. Try adjusting this if the game is too slow, too fast or hangs."
+ "Overclock or under-clock the PSX CPU. The value has to be lower than 100 because of some slowdowns (cache misses, hw access penalties, etc.) that are not emulated. Try adjusting this if the game is too slow, too fast or hangs."
#if defined(HAVE_PRE_ARMV7) && !defined(_3DS)
" Default is 50."
#else
#include "arm_features.h"
#include "revision.h"
-#if defined(__has_builtin)
+#if defined(__EMSCRIPTEN__)
+#define DO_CPU_CHECKS 0
+#elif defined(__has_builtin)
#define DO_CPU_CHECKS __has_builtin(__builtin_cpu_init)
#elif defined(__x86_64__) || defined(__i386__)
#define DO_CPU_CHECKS 1
// gpu options
int frameskip;
int fskip_advice;
+ int fskip_force;
+ int fskip_dirty;
unsigned int *gpu_frame_count;
unsigned int *gpu_hcnt;
unsigned int flip_cnt; // increment manually if not using pl_vout_flip
unsigned int only_16bpp; // platform is 16bpp-only
+ unsigned int thread_rendering;
struct {
int allow_interlace; // 0 off, 1 on, 2 guess
int enhancement_enable;
int enhancement_no_main;
+ int allow_dithering;
int enhancement_tex_adj;
} gpu_neon;
struct {
--- /dev/null
+#ifndef MMAN_H
+#define MMAN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <switch.h>
+
+#define PROT_READ 0b001
+#define PROT_WRITE 0b010
+#define PROT_EXEC 0b100
+#define MAP_PRIVATE 2
+#define MAP_FIXED 0x10
+#define MAP_ANONYMOUS 0x20
+
+#define MAP_FAILED ((void *)-1)
+
+#define ALIGNMENT 0x1000
+
+static inline void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ (void)fd;
+ (void)offset;
+
+ // match Linux behavior
+ len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
+
+ Result rc = svcMapPhysicalMemory(addr, len);
+ if (R_FAILED(rc))
+ {
+ //printf("mmap failed\n");
+ addr = aligned_alloc(ALIGNMENT, len);
+ }
+ if (!addr)
+ return MAP_FAILED;
+ memset(addr, 0, len);
+ return addr;
+}
+
+static inline int munmap(void *addr, size_t len)
+{
+ len = (len + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
+ Result rc = svcUnmapPhysicalMemory(addr, len);
+ if (R_FAILED(rc))
+ {
+ //printf("munmap failed\n");
+ free(addr);
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // MMAN_H
+
--- /dev/null
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2013 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZCONF_H
+#define ZCONF_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set
+ * this permanently in zconf.h using "./configure --zprefix".
+ */
+#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
+# define Z_PREFIX_SET
+
+/* all linked symbols */
+# define _dist_code z__dist_code
+# define _length_code z__length_code
+# define _tr_align z__tr_align
+# define _tr_flush_bits z__tr_flush_bits
+# define _tr_flush_block z__tr_flush_block
+# define _tr_init z__tr_init
+# define _tr_stored_block z__tr_stored_block
+# define _tr_tally z__tr_tally
+# define adler32 z_adler32
+# define adler32_combine z_adler32_combine
+# define adler32_combine64 z_adler32_combine64
+# ifndef Z_SOLO
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# endif
+# define crc32 z_crc32
+# define crc32_combine z_crc32_combine
+# define crc32_combine64 z_crc32_combine64
+# define deflate z_deflate
+# define deflateBound z_deflateBound
+# define deflateCopy z_deflateCopy
+# define deflateEnd z_deflateEnd
+# define deflateInit2_ z_deflateInit2_
+# define deflateInit_ z_deflateInit_
+# define deflateParams z_deflateParams
+# define deflatePending z_deflatePending
+# define deflatePrime z_deflatePrime
+# define deflateReset z_deflateReset
+# define deflateResetKeep z_deflateResetKeep
+# define deflateSetDictionary z_deflateSetDictionary
+# define deflateSetHeader z_deflateSetHeader
+# define deflateTune z_deflateTune
+# define deflate_copyright z_deflate_copyright
+# define get_crc_table z_get_crc_table
+# ifndef Z_SOLO
+# define gz_error z_gz_error
+# define gz_intmax z_gz_intmax
+# define gz_strwinerror z_gz_strwinerror
+# define gzbuffer z_gzbuffer
+# define gzclearerr z_gzclearerr
+# define gzclose z_gzclose
+# define gzclose_r z_gzclose_r
+# define gzclose_w z_gzclose_w
+# define gzdirect z_gzdirect
+# define gzdopen z_gzdopen
+# define gzeof z_gzeof
+# define gzerror z_gzerror
+# define gzflush z_gzflush
+# define gzgetc z_gzgetc
+# define gzgetc_ z_gzgetc_
+# define gzgets z_gzgets
+# define gzoffset z_gzoffset
+# define gzoffset64 z_gzoffset64
+# define gzopen z_gzopen
+# define gzopen64 z_gzopen64
+# ifdef _WIN32
+# define gzopen_w z_gzopen_w
+# endif
+# define gzprintf z_gzprintf
+# define gzvprintf z_gzvprintf
+# define gzputc z_gzputc
+# define gzputs z_gzputs
+# define gzread z_gzread
+# define gzrewind z_gzrewind
+# define gzseek z_gzseek
+# define gzseek64 z_gzseek64
+# define gzsetparams z_gzsetparams
+# define gztell z_gztell
+# define gztell64 z_gztell64
+# define gzungetc z_gzungetc
+# define gzwrite z_gzwrite
+# endif
+# define inflate z_inflate
+# define inflateBack z_inflateBack
+# define inflateBackEnd z_inflateBackEnd
+# define inflateBackInit_ z_inflateBackInit_
+# define inflateCopy z_inflateCopy
+# define inflateEnd z_inflateEnd
+# define inflateGetHeader z_inflateGetHeader
+# define inflateInit2_ z_inflateInit2_
+# define inflateInit_ z_inflateInit_
+# define inflateMark z_inflateMark
+# define inflatePrime z_inflatePrime
+# define inflateReset z_inflateReset
+# define inflateReset2 z_inflateReset2
+# define inflateSetDictionary z_inflateSetDictionary
+# define inflateGetDictionary z_inflateGetDictionary
+# define inflateSync z_inflateSync
+# define inflateSyncPoint z_inflateSyncPoint
+# define inflateUndermine z_inflateUndermine
+# define inflateResetKeep z_inflateResetKeep
+# define inflate_copyright z_inflate_copyright
+# define inflate_fast z_inflate_fast
+# define inflate_table z_inflate_table
+# ifndef Z_SOLO
+# define uncompress z_uncompress
+# endif
+# define zError z_zError
+# ifndef Z_SOLO
+# define zcalloc z_zcalloc
+# define zcfree z_zcfree
+# endif
+# define zlibCompileFlags z_zlibCompileFlags
+# define zlibVersion z_zlibVersion
+
+/* all zlib typedefs in zlib.h and zconf.h */
+# define Byte z_Byte
+# define Bytef z_Bytef
+# define alloc_func z_alloc_func
+# define charf z_charf
+# define free_func z_free_func
+# ifndef Z_SOLO
+# define gzFile z_gzFile
+# endif
+# define gz_header z_gz_header
+# define gz_headerp z_gz_headerp
+# define in_func z_in_func
+# define intf z_intf
+# define out_func z_out_func
+# define uInt z_uInt
+# define uIntf z_uIntf
+# define uLong z_uLong
+# define uLongf z_uLongf
+# define voidp z_voidp
+# define voidpc z_voidpc
+# define voidpf z_voidpf
+
+/* all zlib structs in zlib.h and zconf.h */
+# define gz_header_s z_gz_header_s
+# define internal_state z_internal_state
+
+#endif
+
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
+# define OS2
+#endif
+#if defined(_WINDOWS) && !defined(WINDOWS)
+# define WINDOWS
+#endif
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
+# ifndef WIN32
+# define WIN32
+# endif
+#endif
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
+# ifndef SYS16BIT
+# define SYS16BIT
+# endif
+# endif
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#ifdef SYS16BIT
+# define MAXSEG_64K
+#endif
+#ifdef MSDOS
+# define UNALIGNED_OK
+#endif
+
+#ifdef __STDC_VERSION__
+# ifndef STDC
+# define STDC
+# endif
+# if __STDC_VERSION__ >= 199901L
+# ifndef STDC99
+# define STDC99
+# endif
+# endif
+#endif
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
+# define STDC
+#endif
+
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
+# define STDC
+#endif
+
+#ifndef STDC
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define const /* note: need a more gentle solution here */
+# endif
+#endif
+
+#if defined(ZLIB_CONST) && !defined(z_const)
+# define z_const const
+#else
+# define z_const
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
+# define NO_DUMMY_DECL
+#endif
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+ /* Type declarations */
+
+#ifndef OF /* function prototypes */
+# ifdef STDC
+# define OF(args) args
+# else
+# define OF(args) ()
+# endif
+#endif
+
+#ifndef Z_ARG /* function prototypes for stdarg */
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# define Z_ARG(args) args
+# else
+# define Z_ARG(args) ()
+# endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#ifdef SYS16BIT
+# if defined(M_I86SM) || defined(M_I86MM)
+ /* MSC small or medium model */
+# define SMALL_MEDIUM
+# ifdef _MSC_VER
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+# if (defined(__SMALL__) || defined(__MEDIUM__))
+ /* Turbo C small or medium model */
+# define SMALL_MEDIUM
+# ifdef __BORLANDC__
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+#endif
+
+#if defined(WINDOWS) || defined(WIN32)
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
+ * This is not mandatory, but it offers a little performance increase.
+ */
+# ifdef ZLIB_DLL
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
+# ifdef ZLIB_INTERNAL
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXTERN extern __declspec(dllimport)
+# endif
+# endif
+# endif /* ZLIB_DLL */
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
+ * define ZLIB_WINAPI.
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
+ */
+# ifdef ZLIB_WINAPI
+# ifdef FAR
+# undef FAR
+# endif
+# include <windows.h>
+ /* No need for _export, use ZLIB.DEF instead. */
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
+# define ZEXPORT WINAPI
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
+# else
+# define ZEXPORTVA FAR CDECL
+# endif
+# endif
+#endif
+
+#if defined (__BEOS__)
+# ifdef ZLIB_DLL
+# ifdef ZLIB_INTERNAL
+# define ZEXPORT __declspec(dllexport)
+# define ZEXPORTVA __declspec(dllexport)
+# else
+# define ZEXPORT __declspec(dllimport)
+# define ZEXPORTVA __declspec(dllimport)
+# endif
+# endif
+#endif
+
+#ifndef ZEXTERN
+# define ZEXTERN extern
+#endif
+#ifndef ZEXPORT
+# define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+# define ZEXPORTVA
+#endif
+
+#ifndef FAR
+# define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char Byte; /* 8 bits */
+#endif
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+# define Bytef Byte FAR
+#else
+ typedef Byte FAR Bytef;
+#endif
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+ typedef void const *voidpc;
+ typedef void FAR *voidpf;
+ typedef void *voidp;
+#else
+ typedef Byte const *voidpc;
+ typedef Byte FAR *voidpf;
+ typedef Byte *voidp;
+#endif
+
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+# include <limits.h>
+# if (UINT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned
+# elif (ULONG_MAX == 0xffffffffUL)
+# define Z_U4 unsigned long
+# elif (USHRT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned short
+# endif
+#endif
+
+#ifdef Z_U4
+ typedef Z_U4 z_crc_t;
+#else
+ typedef unsigned long z_crc_t;
+#endif
+
+#if 1 /* was set to #if 1 by ./configure */
+# define Z_HAVE_UNISTD_H
+#endif
+
+#if 1 /* was set to #if 1 by ./configure */
+# define Z_HAVE_STDARG_H
+#endif
+
+#ifdef STDC
+# ifndef Z_SOLO
+# include <sys/types.h> /* for off_t */
+# endif
+#endif
+
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# ifndef Z_SOLO
+# include <stdarg.h> /* for va_list */
+# endif
+#endif
+
+#ifdef _WIN32
+# ifndef Z_SOLO
+# include <stddef.h> /* for wchar_t */
+# endif
+#endif
+
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
+ * though the former does not conform to the LFS document), but considering
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
+ * equivalently requesting no 64-bit operations
+ */
+#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
+# undef _LARGEFILE64_SOURCE
+#endif
+
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+# define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+# ifdef VMS
+# include <unixio.h> /* for off_t */
+# endif
+# ifndef z_off_t
+# define z_off_t off_t
+# endif
+# endif
+#endif
+
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+# define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+# define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+# define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+
+#ifndef z_off_t
+# define z_off_t long
+#endif
+
+#if !defined(_WIN32) && defined(Z_LARGE64)
+# define z_off64_t off64_t
+#else
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+# define z_off64_t __int64
+# else
+# define z_off64_t z_off_t
+# endif
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+ #pragma map(deflateInit_,"DEIN")
+ #pragma map(deflateInit2_,"DEIN2")
+ #pragma map(deflateEnd,"DEEND")
+ #pragma map(deflateBound,"DEBND")
+ #pragma map(inflateInit_,"ININ")
+ #pragma map(inflateInit2_,"ININ2")
+ #pragma map(inflateEnd,"INEND")
+ #pragma map(inflateSync,"INSY")
+ #pragma map(inflateSetDictionary,"INSEDI")
+ #pragma map(compressBound,"CMBND")
+ #pragma map(inflate_table,"INTABL")
+ #pragma map(inflate_fast,"INFA")
+ #pragma map(inflate_copyright,"INCOPY")
+#endif
+
+#endif /* ZCONF_H */
--- /dev/null
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.2.8, April 28th, 2013
+
+ Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
+*/
+
+#ifndef ZLIB_H
+#define ZLIB_H
+
+#include "zconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZLIB_VERSION "1.2.8"
+#define ZLIB_VERNUM 0x1280
+#define ZLIB_VER_MAJOR 1
+#define ZLIB_VER_MINOR 2
+#define ZLIB_VER_REVISION 8
+#define ZLIB_VER_SUBREVISION 0
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed data.
+ This version of the library supports only one compression method (deflation)
+ but other algorithms will be added later and will have the same stream
+ interface.
+
+ Compression can be done in a single step if the buffers are large enough,
+ or can be done by repeated calls of the compression function. In the latter
+ case, the application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The compressed data format used by default by the in-memory functions is
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
+ around a deflate stream, which is itself documented in RFC 1951.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio using the functions that start
+ with "gz". The gzip format is different from the zlib format. gzip is a
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+
+ This library can optionally read and write gzip streams in memory as well.
+
+ The zlib format was designed to be compact and fast for use in memory
+ and on communications channels. The gzip format was designed for single-
+ file compression on file systems, has a larger header than zlib to maintain
+ directory information, and uses a different, slower check method than zlib.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never crash
+ even in case of corrupted input.
+*/
+
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
+
+struct internal_state;
+
+typedef struct z_stream_s {
+ z_const Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ uLong total_in; /* total number of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ uLong total_out; /* total number of bytes output so far */
+
+ z_const char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
+
+ int data_type; /* best guess about the data type: binary or text */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR *z_streamp;
+
+/*
+ gzip header information passed to and from zlib routines. See RFC 1952
+ for more details on the meanings of these fields.
+*/
+typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /* extra flags (not used when writing a gzip file) */
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+} gz_header;
+
+typedef gz_header FAR *gz_headerp;
+
+/*
+ The application must update next_in and avail_in when avail_in has dropped
+ to zero. It must update next_out and avail_out when avail_out has dropped
+ to zero. The application must initialize zalloc, zfree and opaque before
+ calling the init function. All other fields are set by the compression
+ library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this if
+ the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
+ returned by zalloc for objects of exactly 65536 bytes *must* have their
+ offset normalized to zero. The default allocation function provided by this
+ library ensures this (see zutil.c). To reduce memory requirements and avoid
+ any allocation of 64K objects, at the expense of compression ratio, compile
+ the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or progress
+ reports. After compression, total_in holds the total size of the
+ uncompressed data and may be saved for use in the decompressor (particularly
+ if the decompressor wants to decompress everything in a single step).
+*/
+
+ /* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+#define Z_BLOCK 5
+#define Z_TREES 6
+/* Allowed flush values; see deflate() and inflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions. Negative values
+ * are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
+#define Z_FIXED 4
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_TEXT 1
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field (though see inflate()) */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+
+ /* basic functions */
+
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is not
+ compatible with the zlib.h header file used by the application. This check
+ is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller. If
+ zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
+ allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at all
+ (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
+ requests a default compromise between speed and compression (currently
+ equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if level is not a valid compression level, or
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION). msg is set to null
+ if there is no error message. deflateInit does not perform any compression:
+ this will be done by deflate().
+*/
+
+
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications). Some
+ output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming more
+ output, and updating avail_in or avail_out accordingly; avail_out should
+ never be zero before the call. The application can consume the compressed
+ output when it wants, for example when the output buffer is full (avail_out
+ == 0), or after each call of deflate(). If deflate returns Z_OK and with
+ zero avail_out, it must be called again after making room in the output
+ buffer because there might be more output pending.
+
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
+ decide how much data to accumulate before producing output, in order to
+ maximize compression.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In
+ particular avail_in is zero after the call if enough output space has been
+ provided before the call.) Flushing may degrade compression for some
+ compression algorithms and so it should be used only when necessary. This
+ completes the current deflate block and follows it with an empty stored block
+ that is three bits plus filler bits to the next byte, followed by four bytes
+ (00 00 ff ff).
+
+ If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
+ output buffer, but the output is not aligned to a byte boundary. All of the
+ input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
+ This completes the current deflate block and follows it with an empty fixed
+ codes block that is 10 bits long. This assures that enough bytes are output
+ in order for the decompressor to finish the block before the empty fixed code
+ block.
+
+ If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
+ for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
+ seven bits of the current block are held to be written as the next byte after
+ the next deflate block is completed. In this case, the decompressor may not
+ be provided enough bits at this point in order to complete decompression of
+ the data provided so far to the compressor. It may need to wait for the next
+ block to be emitted. This is for advanced applications that need to control
+ the emission of deflate blocks.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
+ avail_out is greater than six to avoid repeated flush markers due to
+ avail_out == 0 on return.
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there was
+ enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the stream
+ are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least the
+ value returned by deflateBound (see below). Then deflate is guaranteed to
+ return Z_STREAM_END. If not enough output space is provided, deflate will
+ not return Z_STREAM_END, and it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so far (that is, total_in bytes).
+
+ deflate() may update strm->data_type if it can make a good guess about
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect the
+ compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
+ fatal, and deflate() can be called again with more input and more output
+ space to continue compressing.
+*/
+
+
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any pending
+ output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case, msg
+ may be set but then points to a static string (which must not be
+ deallocated).
+*/
+
+
+/*
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the
+ exact value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
+ invalid, such as a null pointer to the structure. msg is set to null if
+ there is no error message. inflateInit does not perform any decompression
+ apart from possibly reading the zlib header if present: actual decompression
+ will be done by inflate(). (So next_in and avail_in may be modified, but
+ next_out and avail_out are unused and unchanged.) The current implementation
+ of inflateInit() does not process any header information -- that is deferred
+ until inflate() is called.
+*/
+
+
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing will
+ resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there is
+ no more input data or no more space in the output buffer (see below about
+ the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming more
+ output, and updating the next_* and avail_* values accordingly. The
+ application can consume the uncompressed output when it wants, for example
+ when the output buffer is full (avail_out == 0), or after each call of
+ inflate(). If inflate returns Z_OK and with zero avail_out, it must be
+ called again after making room in the output buffer because there might be
+ more output pending.
+
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
+ Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
+ output as possible to the output buffer. Z_BLOCK requests that inflate()
+ stop if and when it gets to the next deflate block boundary. When decoding
+ the zlib or gzip format, this will cause inflate() to return immediately
+ after the header and before the first block. When doing a raw inflate,
+ inflate() will go ahead and process the first block, and will return when it
+ gets to the end of that block, or when it runs out of data.
+
+ The Z_BLOCK option assists in appending to or combining deflate streams.
+ Also to assist in this, on return inflate() will set strm->data_type to the
+ number of unused bits in the last byte taken from strm->next_in, plus 64 if
+ inflate() is currently decoding the last block in the deflate stream, plus
+ 128 if inflate() returned immediately after decoding an end-of-block code or
+ decoding the complete header up to just before the first byte of the deflate
+ stream. The end-of-block will not be indicated until all of the uncompressed
+ data from that block has been written to strm->next_out. The number of
+ unused bits may in general be greater than seven, except when bit 7 of
+ data_type is set, in which case the number of unused bits will be less than
+ eight. data_type is set as noted here every time inflate() returns for all
+ flush options, and so can be used to determine the amount of currently
+ consumed input in bits.
+
+ The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
+ end of each deflate block header is reached, before any actual data in that
+ block is decoded. This allows the caller to determine the length of the
+ deflate block header for later use in random access within a deflate block.
+ 256 is added to the value of strm->data_type when inflate() returns
+ immediately after reaching the end of the deflate block header.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step (a
+ single call of inflate), the parameter flush should be set to Z_FINISH. In
+ this case all pending input is processed and all pending output is flushed;
+ avail_out must be large enough to hold all of the uncompressed data for the
+ operation to complete. (The size of the uncompressed data may have been
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
+ required to perform an inflation in one step. However it may be used to
+ inform inflate that a faster approach can be used for the single inflate()
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
+ stream completes, which reduces inflate's memory footprint. If the stream
+ does not complete, either because not all of the stream is provided or not
+ enough output space is provided, then a sliding window will be allocated and
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
+ been used.
+
+ In this implementation, inflate() always flushes as much output as
+ possible to the output buffer, and always uses the faster approach on the
+ first call. So the effects of the flush parameter in this implementation are
+ on the return value of inflate() as noted below, when inflate() returns early
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
+ memory for a sliding window when Z_FINISH is used.
+
+ If a preset dictionary is needed after this call (see inflateSetDictionary
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
+ below. At the end of the stream, inflate() checks that its computed adler32
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
+ only if the checksum is correct.
+
+ inflate() can decompress and check either zlib-wrapped or gzip-wrapped
+ deflate data. The header type is detected automatically, if requested when
+ initializing with inflateInit2(). Any information contained in the gzip
+ header is not retained, so applications that need that information should
+ instead use raw inflate, see inflateInit2() below, or inflateBack() and
+ perform their own processing of the gzip header and trailer. When processing
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
+ producted so far. The CRC-32 is checked against the gzip trailer.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect check
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+ next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ inflate() can be called again with more input and more output space to
+ continue decompressing. If Z_DATA_ERROR is returned, the application may
+ then call inflateSync() to look for a good compression block if a partial
+ recovery of the data is desired.
+*/
+
+
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any pending
+ output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+*/
+
+
+ /* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+*/
+
+/*
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by the
+ caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
+ determines the window size. deflate() will then generate raw deflate data
+ with no zlib header or trailer, and will not compute an adler32 check value.
+
+ windowBits can also be greater than 15 for optional gzip encoding. Add
+ 16 to windowBits to write a simple gzip header and trailer around the
+ compressed data instead of a zlib wrapper. The gzip header will have no
+ file name, no extra data, no comment, no modification time (set to zero), no
+ header crc, and the operating system will be set to 255 (unknown). If a
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but is
+ slow and reduces compression ratio; memLevel=9 uses maximum memory for
+ optimal speed. The default value is 8. See zconf.h for total memory usage
+ as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match), or Z_RLE to limit match distances to one (run-length
+ encoding). Filtered data consists mostly of small values with a somewhat
+ random distribution. In this case, the compression algorithm is tuned to
+ compress them better. The effect of Z_FILTERED is to force more Huffman
+ coding and less string matching; it is somewhat intermediate between
+ Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
+ fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
+ strategy parameter only affects the compression ratio but not the
+ correctness of the compressed output even if it is not set appropriately.
+ Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
+ decoder for special applications.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
+ method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
+ incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
+ set to null if there is no error message. deflateInit2 does not perform any
+ compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. When using the zlib format, this
+ function must be called immediately after deflateInit, deflateInit2 or
+ deflateReset, and before any call of deflate. When doing raw deflate, this
+ function must be called either before any call of deflate, or immediately
+ after the completion of a deflate block, i.e. after all input has been
+ consumed and all output has been delivered when using any of the flush
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
+ compressor and decompressor must use exactly the same dictionary (see
+ inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size
+ provided in deflateInit or deflateInit2. Thus the strings most likely to be
+ useful should be put at the end of the dictionary, not at the front. In
+ addition, the current implementation of deflate will use at most the window
+ size minus 262 bytes of the provided dictionary.
+
+ Upon return of this function, strm->adler is set to the adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.) If a raw deflate was requested, then the
+ adler32 value is not computed and strm->adler is not set.
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
+ not perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and can
+ consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state. The
+ stream will keep the same compression level and any other attributes that
+ may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
+*/
+
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
+ int level,
+ int strategy));
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different strategy.
+ If the compression level is changed, the input available so far is
+ compressed with the old level (and may be flushed); the new level will take
+ effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to be
+ compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
+ strm->avail_out was zero.
+*/
+
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
+ int good_length,
+ int max_lazy,
+ int nice_length,
+ int max_chain));
+/*
+ Fine tune deflate's internal compression parameters. This should only be
+ used by someone who understands the algorithm used by zlib's deflate for
+ searching for the best matching string, and even then only by the most
+ fanatic optimizer trying to squeeze out the last compressed bit for their
+ specific input data. Read the deflate.c source code for the meaning of the
+ max_lazy, good_length, nice_length, and max_chain parameters.
+
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
+ */
+
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
+ uLong sourceLen));
+/*
+ deflateBound() returns an upper bound on the compressed size after
+ deflation of sourceLen bytes. It must be called after deflateInit() or
+ deflateInit2(), and after deflateSetHeader(), if used. This would be used
+ to allocate an output buffer for deflation in a single pass, and so would be
+ called before deflate(). If that first deflate() call is provided the
+ sourceLen input bytes, an output buffer allocated to the size returned by
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
+ be larger than the value returned by deflateBound() if flush options other
+ than Z_FINISH or Z_NO_FLUSH are used.
+*/
+
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
+ unsigned *pending,
+ int *bits));
+/*
+ deflatePending() returns the number of bytes and bits of output that have
+ been generated, but not yet provided in the available output. The bytes not
+ provided would be due to the available output space having being consumed.
+ The number of bits of output not provided are between 0 and 7, where they
+ await more bits to join them in order to fill out a full byte. If pending
+ or bits are Z_NULL, then those values are not set.
+
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+ */
+
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ deflatePrime() inserts bits in the deflate output stream. The intent
+ is that this function is used to start off the deflate output with the bits
+ leftover from a previous deflate stream when appending to it. As such, this
+ function can only be used for raw deflate, and must be used before the first
+ deflate() call after a deflateInit2() or deflateReset(). bits must be less
+ than or equal to 16, and that many of the least significant bits of value
+ will be inserted in the output.
+
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
+ source stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ deflateSetHeader() provides gzip header information for when a gzip
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
+ after deflateInit2() or deflateReset() and before the first call of
+ deflate(). The text, time, os, extra field, name, and comment information
+ in the provided gz_header structure are written to the gzip header (xflag is
+ ignored -- the extra flags are set according to the compression level). The
+ caller must assure that, if not Z_NULL, name and comment are terminated with
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
+ available there. If hcrc is true, a gzip header crc is included. Note that
+ the current versions of the command-line version of gzip (up through version
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
+ gzip file" and give up.
+
+ If deflateSetHeader is not used, the default gzip header has text false,
+ the time set to zero, and os set to 255, with no extra, name, or comment
+ fields. The gzip header is returned to the default state by deflateReset().
+
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. windowBits must be greater than or equal to the windowBits value
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
+ deflateInit2() was not used. If a compressed stream with a larger window
+ size is given as input, inflate() will return with the error code
+ Z_DATA_ERROR instead of trying to allocate a larger window.
+
+ windowBits can also be zero to request that inflate use the window size in
+ the zlib header of the compressed stream.
+
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+ determines the window size. inflate() will then process raw deflate data,
+ not looking for a zlib or gzip header, not generating a check value, and not
+ looking for any check values for comparison at the end of the stream. This
+ is for use with other formats that use the deflate compressed data format
+ such as zip. Those formats provide their own check values. If a custom
+ format is developed using the raw deflate format for compressed data, it is
+ recommended that a check value such as an adler32 or a crc32 be applied to
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
+ most applications, the zlib format should be used as is. Note that comments
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
+
+ windowBits can also be greater than 15 for optional gzip decoding. Add
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
+ detection, or add 16 to decode only the gzip format (the zlib format will
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
+ crc32 instead of an adler32.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
+ invalid, such as a null pointer to the structure. msg is set to null if
+ there is no error message. inflateInit2 does not perform any decompression
+ apart from possibly reading the zlib header if present: actual decompression
+ will be done by inflate(). (So next_in and avail_in may be modified, but
+ next_out and avail_out are unused and unchanged.) The current implementation
+ of inflateInit2() does not process any header information -- that is
+ deferred until inflate() is called.
+*/
+
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate,
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the adler32 value returned by that call of inflate.
+ The compressor and decompressor must use exactly the same dictionary (see
+ deflateSetDictionary). For raw inflate, this function can be called at any
+ time to set the dictionary. If the provided dictionary is smaller than the
+ window and there is already data in the window, then the provided dictionary
+ will amend what's there. The application must insure that the dictionary
+ that was used for compression is provided.
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+*/
+
+ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm,
+ Bytef *dictionary,
+ uInt *dictLength));
+/*
+ Returns the sliding dictionary being maintained by inflate. dictLength is
+ set to the number of bytes in the dictionary, and that many bytes are copied
+ to dictionary. dictionary must have enough space, where 32768 bytes is
+ always enough. If inflateGetDictionary() is called with dictionary equal to
+ Z_NULL, then only the dictionary length is returned, and nothing is copied.
+ Similary, if dictLength is Z_NULL, then it is not set.
+
+ inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the
+ stream state is inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
+/*
+ Skips invalid compressed data until a possible full flush point (see above
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
+ All full flush points have this pattern, but not all occurrences of this
+ pattern are full flush points.
+
+ inflateSync returns Z_OK if a possible full flush point has been found,
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
+ In the success case, the application may save the current current value of
+ total_in which indicates where valid compressed data was found. In the
+ error case, the application may repeatedly call inflateSync, providing more
+ input each time, until success or end of the input data.
+*/
+
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when randomly accessing a large stream. The
+ first pass through the stream can periodically record the inflate state,
+ allowing restarting inflate at those points when randomly accessing the
+ stream.
+
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state. The
+ stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
+*/
+
+ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
+ int windowBits));
+/*
+ This function is the same as inflateReset, but it also permits changing
+ the wrap and window size requests. The windowBits parameter is interpreted
+ the same as it is for inflateInit2.
+
+ inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being Z_NULL), or if
+ the windowBits parameter is invalid.
+*/
+
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ This function inserts bits in the inflate input stream. The intent is
+ that this function is used to start inflating at a bit position in the
+ middle of a byte. The provided bits will be used before any bytes are used
+ from next_in. This function should only be used with raw inflate, and
+ should be used before the first inflate() call after inflateInit2() or
+ inflateReset(). bits must be less than or equal to 16, and that many of the
+ least significant bits of value will be inserted in the input.
+
+ If bits is negative, then the input stream bit buffer is emptied. Then
+ inflatePrime() can be called again to put bits in the buffer. This is used
+ to clear out bits leftover after feeding inflate a block description prior
+ to feeding inflate codes.
+
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
+/*
+ This function returns two values, one in the lower 16 bits of the return
+ value, and the other in the remaining upper bits, obtained by shifting the
+ return value down 16 bits. If the upper value is -1 and the lower value is
+ zero, then inflate() is currently decoding information outside of a block.
+ If the upper value is -1 and the lower value is non-zero, then inflate is in
+ the middle of a stored block, with the lower value equaling the number of
+ bytes from the input remaining to copy. If the upper value is not -1, then
+ it is the number of bits back from the current bit position in the input of
+ the code (literal or length/distance pair) currently being processed. In
+ that case the lower value is the number of bytes already emitted for that
+ code.
+
+ A code is being processed if inflate is waiting for more input to complete
+ decoding of the code, or if it has completed decoding but is waiting for
+ more output space to write the literal or match data.
+
+ inflateMark() is used to mark locations in the input data for random
+ access, which may be at bit positions, and to note those cases where the
+ output of a code may span boundaries of random access blocks. The current
+ location in the input stream can be determined from avail_in and data_type
+ as noted in the description for the Z_BLOCK flush parameter for inflate.
+
+ inflateMark returns the value noted above or -1 << 16 if the provided
+ source stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ inflateGetHeader() requests that gzip header information be stored in the
+ provided gz_header structure. inflateGetHeader() may be called after
+ inflateInit2() or inflateReset(), and before the first call of inflate().
+ As inflate() processes the gzip stream, head->done is zero until the header
+ is completed, at which time head->done is set to one. If a zlib stream is
+ being decoded, then head->done is set to -1 to indicate that there will be
+ no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
+ used to force inflate() to return immediately after header processing is
+ complete and before any actual data is decompressed.
+
+ The text, time, xflags, and os fields are filled in with the gzip header
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
+ contains the maximum number of bytes to write to extra. Once done is true,
+ extra_len contains the actual extra field length, and extra contains the
+ extra field, or that field truncated if extra_max is less than extra_len.
+ If name is not Z_NULL, then up to name_max characters are written there,
+ terminated with a zero unless the length is greater than name_max. If
+ comment is not Z_NULL, then up to comm_max characters are written there,
+ terminated with a zero unless the length is greater than comm_max. When any
+ of extra, name, or comment are not Z_NULL and the respective field is not
+ present in the header, then that field is set to Z_NULL to signal its
+ absence. This allows the use of deflateSetHeader() with the returned
+ structure to duplicate the header. However if those fields are set to
+ allocated memory, then the application will need to save those pointers
+ elsewhere so that they can be eventually freed.
+
+ If inflateGetHeader is not used, then the header information is simply
+ discarded. The header is always checked for validity, including the header
+ CRC if present. inflateReset() will reset the process to discard the header
+ information. The application would need to call inflateGetHeader() again to
+ retrieve the header from the next gzip stream.
+
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window));
+
+ Initialize the internal stream state for decompression using inflateBack()
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
+ derived memory allocation routines are used. windowBits is the base two
+ logarithm of the window size, in the range 8..15. window is a caller
+ supplied buffer of that size. Except for special applications where it is
+ assured that deflate was used with small window sizes, windowBits must be 15
+ and a 32K byte window must be supplied to be able to decompress general
+ deflate streams.
+
+ See inflateBack() for the usage of these routines.
+
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
+ allocated, or Z_VERSION_ERROR if the version of the library does not match
+ the version of the header file.
+*/
+
+typedef unsigned (*in_func) OF((void FAR *,
+ z_const unsigned char FAR * FAR *));
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
+
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
+ in_func in, void FAR *in_desc,
+ out_func out, void FAR *out_desc));
+/*
+ inflateBack() does a raw inflate with a single call using a call-back
+ interface for input and output. This is potentially more efficient than
+ inflate() for file i/o applications, in that it avoids copying between the
+ output and the sliding window by simply making the window itself the output
+ buffer. inflate() can be faster on modern CPUs when used with large
+ buffers. inflateBack() trusts the application to not change the output
+ buffer passed by the output function, at least until inflateBack() returns.
+
+ inflateBackInit() must be called first to allocate the internal state
+ and to initialize the state with the user-provided window buffer.
+ inflateBack() may then be used multiple times to inflate a complete, raw
+ deflate stream with each call. inflateBackEnd() is then called to free the
+ allocated state.
+
+ A raw deflate stream is one with no zlib or gzip header or trailer.
+ This routine would normally be used in a utility that reads zip or gzip
+ files and writes out uncompressed files. The utility would decode the
+ header and process the trailer on its own, hence this routine expects only
+ the raw deflate stream to decompress. This is different from the normal
+ behavior of inflate(), which expects either a zlib or gzip header and
+ trailer around the deflate stream.
+
+ inflateBack() uses two subroutines supplied by the caller that are then
+ called by inflateBack() for input and output. inflateBack() calls those
+ routines until it reads a complete deflate stream and writes out all of the
+ uncompressed data, or until it encounters an error. The function's
+ parameters and return types are defined above in the in_func and out_func
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
+ number of bytes of provided input, and a pointer to that input in buf. If
+ there is no input available, in() must return zero--buf is ignored in that
+ case--and inflateBack() will return a buffer error. inflateBack() will call
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
+ should return zero on success, or non-zero on failure. If out() returns
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
+ are permitted to change the contents of the window provided to
+ inflateBackInit(), which is also the buffer that out() uses to write from.
+ The length written by out() will be at most the window size. Any non-zero
+ amount of input may be provided by in().
+
+ For convenience, inflateBack() can be provided input on the first call by
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
+ in() will be called. Therefore strm->next_in must be initialized before
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
+ must also be initialized, and then if strm->avail_in is not zero, input will
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
+
+ The in_desc and out_desc parameters of inflateBack() is passed as the
+ first parameter of in() and out() respectively when they are called. These
+ descriptors can be optionally used to pass any information that the caller-
+ supplied in() and out() functions need to do their job.
+
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
+ pass back any unused input that was provided by the last in() call. The
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format error
+ in the deflate stream (in which case strm->msg is set to indicate the nature
+ of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
+ In the case of Z_BUF_ERROR, an input or output error can be distinguished
+ using strm->next_in which will be Z_NULL only if in() returned an error. If
+ strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
+ non-zero. (in() will always be called before out(), so strm->next_in is
+ assured to be defined if out() returns non-zero.) Note that inflateBack()
+ cannot return Z_OK.
+*/
+
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
+/*
+ All memory allocated by inflateBackInit() is freed.
+
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
+ state was inconsistent.
+*/
+
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
+/* Return flags indicating compile-time options.
+
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
+ 1.0: size of uInt
+ 3.2: size of uLong
+ 5.4: size of voidpf (pointer)
+ 7.6: size of z_off_t
+
+ Compiler, assembler, and debug options:
+ 8: DEBUG
+ 9: ASMV or ASMINF -- use ASM code
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
+ 11: 0 (reserved)
+
+ One-time table building (smaller code, but not thread-safe if true):
+ 12: BUILDFIXED -- build static block decoding tables when needed
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
+ 14,15: 0 (reserved)
+
+ Library content (indicates missing functionality):
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
+ deflate code when not needed)
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
+ and decode gzip streams (to avoid linking crc code)
+ 18-19: 0 (reserved)
+
+ Operation variations (changes in library functionality):
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
+ 22,23: 0 (reserved)
+
+ The sprintf variant used by gzprintf (zero is best):
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
+
+ Remainder:
+ 27-31: 0 (reserved)
+ */
+
+#ifndef Z_SOLO
+
+ /* utility functions */
+
+/*
+ The following utility functions are implemented on top of the basic
+ stream-oriented functions. To simplify the interface, some default options
+ are assumed (compression level and memory usage, standard memory allocation
+ functions). The source code of these utility functions can be modified if
+ you need special options.
+*/
+
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total size
+ of the destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+*/
+
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
+/*
+ compressBound() returns an upper bound on the compressed size after
+ compress() or compress2() on sourceLen bytes. It would be used before a
+ compress() or compress2() call to allocate the destination buffer.
+*/
+
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total size
+ of the destination buffer, which must be large enough to hold the entire
+ uncompressed data. (The size of the uncompressed data must have been saved
+ previously by the compressor and transmitted to the decompressor by some
+ mechanism outside the scope of this compression library.) Upon exit, destLen
+ is the actual size of the uncompressed buffer.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
+ the case where there is not enough room, uncompress() will fill the output
+ buffer with the uncompressed data up to that point.
+*/
+
+ /* gzip file access functions */
+
+/*
+ This library supports reading and writing files in gzip (.gz) format with
+ an interface similar to that of stdio, using the functions that start with
+ "gz". The gzip format is different from the zlib format. gzip is a gzip
+ wrapper, documented in RFC 1952, wrapped around a deflate stream.
+*/
+
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
+
+/*
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
+
+ Opens a gzip (.gz) file for reading or writing. The mode parameter is as
+ in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
+ a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
+ compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
+ for fixed code compression as in "wb9F". (See the description of
+ deflateInit2 for more information about the strategy parameter.) 'T' will
+ request transparent writing or appending with no compression and not using
+ the gzip format.
+
+ "a" can be used instead of "w" to request that the gzip stream that will
+ be written be appended to the file. "+" will result in an error, since
+ reading and writing to the same gzip file is not supported. The addition of
+ "x" when writing will create the file exclusively, which fails if the file
+ already exists. On systems that support it, the addition of "e" when
+ reading or writing will set the flag to close the file on an execve() call.
+
+ These functions, as well as gzip, will read and decode a sequence of gzip
+ streams in a file. The append function of gzopen() can be used to create
+ such a file. (Also see gzflush() for another way to do this.) When
+ appending, gzopen does not test whether the file begins with a gzip stream,
+ nor does it look for the end of the gzip streams to begin appending. gzopen
+ will simply append a gzip stream to the existing file.
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression. When
+ reading, this will be detected automatically by looking for the magic two-
+ byte gzip header.
+
+ gzopen returns NULL if the file could not be opened, if there was
+ insufficient memory to allocate the gzFile state, or if an invalid mode was
+ specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
+ errno can be checked to determine if the reason gzopen failed was that the
+ file could not be opened.
+*/
+
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
+/*
+ gzdopen associates a gzFile with the file descriptor fd. File descriptors
+ are obtained from calls like open, dup, creat, pipe or fileno (if the file
+ has been previously opened with fopen). The mode parameter is as in gzopen.
+
+ The next call of gzclose on the returned gzFile will also close the file
+ descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
+ fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
+ mode);. The duplicated descriptor should be saved to avoid a leak, since
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
+ file descriptor from a FILE *, then you will have to use dup() to avoid
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
+ close the associated file descriptor, so they need to have different file
+ descriptors.
+
+ gzdopen returns NULL if there was insufficient memory to allocate the
+ gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
+ provided, or '+' was provided), or if fd is -1. The file descriptor is not
+ used until the next gz* read, write, seek, or close operation, so gzdopen
+ will not detect if fd is invalid (unless fd is -1).
+*/
+
+ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
+/*
+ Set the internal buffer size used by this library's functions. The
+ default buffer size is 8192 bytes. This function must be called after
+ gzopen() or gzdopen(), and before any other calls that read or write the
+ file. The buffer memory allocation is always deferred to the first read or
+ write. Two buffers are allocated, either both of the specified size when
+ writing, or one of the specified size and the other twice that size when
+ reading. A larger buffer size of, for example, 64K or 128K bytes will
+ noticeably increase the speed of decompression (reading).
+
+ The new buffer size also affects the maximum length for gzprintf().
+
+ gzbuffer() returns 0 on success, or -1 on failure, such as being called
+ too late.
+*/
+
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+*/
+
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+/*
+ Reads the given number of uncompressed bytes from the compressed file. If
+ the input file is not in gzip format, gzread copies the given number of
+ bytes into the buffer directly from the file.
+
+ After reaching the end of a gzip stream in the input, gzread will continue
+ to read, looking for another gzip stream. Any number of gzip streams may be
+ concatenated in the input file, and will all be decompressed by gzread().
+ If something other than a gzip stream is encountered after a gzip stream,
+ that remaining trailing garbage is ignored (and no error is returned).
+
+ gzread can be used to read a gzip file that is being concurrently written.
+ Upon reaching the end of the input, gzread will return with the available
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+ gzclearerr can be used to clear the end of file indicator in order to permit
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
+ middle of a gzip stream. Note that gzread does not return -1 in the event
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+ stream. Alternatively, gzerror can be used before gzclose to detect this
+ case.
+
+ gzread returns the number of uncompressed bytes actually read, less than
+ len for end of file, or -1 for error.
+*/
+
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
+ voidpc buf, unsigned len));
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes written or 0 in case of
+ error.
+*/
+
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
+/*
+ Converts, formats, and writes the arguments to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written, or 0 in case of error. The number of
+ uncompressed bytes written is limited to 8191, or one less than the buffer
+ size given to gzbuffer(). The caller should assure that this limit is not
+ exceeded. If it is exceeded, then gzprintf() will return an error (0) with
+ nothing written. In this case, there may also be a buffer overflow with
+ unpredictable consequences, which is possible only if zlib was compiled with
+ the insecure functions sprintf() or vsprintf() because the secure snprintf()
+ or vsnprintf() functions were not available. This can be determined using
+ zlibCompileFlags().
+*/
+
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or a
+ newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. If any characters are read or if len == 1, the
+ string is terminated with a null character. If no characters are read due
+ to an end-of-file or len < 1, then the buffer is left untouched.
+
+ gzgets returns buf which is a null-terminated string, or it returns NULL
+ for end-of-file or in case of error. If there was an error, the contents at
+ buf are indeterminate.
+*/
+
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
+/*
+ Writes c, converted to an unsigned char, into the compressed file. gzputc
+ returns the value that was written, or -1 in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte or -1
+ in case of end of file or error. This is implemented as a macro for speed.
+ As such, it does not do all of the checking the other functions do. I.e.
+ it does not check to see if file is NULL, nor whether the structure file
+ points to has been clobbered or not.
+*/
+
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
+/*
+ Push one character back onto the stream to be read as the first character
+ on the next read. At least one character of push-back is allowed.
+ gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
+ fail if c is -1, and may fail if a character has been pushed but not read
+ yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
+ output buffer size of pushed characters is allowed. (See gzbuffer above.)
+ The pushed character will be discarded if the stream is repositioned with
+ gzseek() or gzrewind().
+*/
+
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
+/*
+ Flushes all pending output into the compressed file. The parameter flush
+ is as in the deflate() function. The return value is the zlib error number
+ (see function gzerror below). gzflush is only permitted when writing.
+
+ If the flush parameter is Z_FINISH, the remaining data is written and the
+ gzip stream is completed in the output. If gzwrite() is called again, a new
+ gzip stream will be started in the output. gzread() is able to read such
+ concatented gzip streams.
+
+ gzflush should be called only when strictly necessary because it will
+ degrade compression if called too often.
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
+ z_off_t offset, int whence));
+
+ Sets the starting position for the next gzread or gzwrite on the given
+ compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+*/
+
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
+
+ Returns the starting position for the next gzread or gzwrite on the given
+ compressed file. This position represents a number of bytes in the
+ uncompressed data stream, and is zero when starting, even if appending or
+ reading a gzip stream from the middle of a file using gzdopen().
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+*/
+
+/*
+ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
+
+ Returns the current offset in the file being read or written. This offset
+ includes the count of bytes that precede the gzip stream, for example when
+ appending or when using gzdopen() for reading. When reading, the offset
+ does not include as yet unused buffered input. This information can be used
+ for a progress indicator. On error, gzoffset() returns -1.
+*/
+
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
+/*
+ Returns true (1) if the end-of-file indicator has been set while reading,
+ false (0) otherwise. Note that the end-of-file indicator is set only if the
+ read tried to go past the end of the input, but came up short. Therefore,
+ just like feof(), gzeof() may return false even if there is no more data to
+ read, in the event that the last read request was for the exact number of
+ bytes remaining in the input file. This will happen if the input file size
+ is an exact multiple of the buffer size.
+
+ If gzeof() returns true, then the read functions will return no more data,
+ unless the end-of-file indicator is reset by gzclearerr() and the input file
+ has grown since the previous end of file was detected.
+*/
+
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
+/*
+ Returns true (1) if file is being copied directly while reading, or false
+ (0) if file is a gzip stream being decompressed.
+
+ If the input file is empty, gzdirect() will return true, since the input
+ does not contain a gzip stream.
+
+ If gzdirect() is used immediately after gzopen() or gzdopen() it will
+ cause buffers to be allocated to allow reading the file to determine if it
+ is a gzip file. Therefore if gzbuffer() is used, it should be called before
+ gzdirect().
+
+ When writing, gzdirect() returns true (1) if transparent writing was
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
+ gzdirect() is not needed when writing. Transparent writing must be
+ explicitly requested, so the application already knows the answer. When
+ linking statically, using gzdirect() will include all of the zlib code for
+ gzip file reading and decompression, which may not be desired.)
+*/
+
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
+/*
+ Flushes all pending output if necessary, closes the compressed file and
+ deallocates the (de)compression state. Note that once file is closed, you
+ cannot call gzerror with file, since its structures have been deallocated.
+ gzclose must not be called more than once on the same file, just as free
+ must not be called more than once on the same allocation.
+
+ gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+ last read ended in the middle of a gzip stream, or Z_OK on success.
+*/
+
+ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
+ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
+/*
+ Same as gzclose(), but gzclose_r() is only for use when reading, and
+ gzclose_w() is only for use when writing or appending. The advantage to
+ using these instead of gzclose() is that they avoid linking in zlib
+ compression or decompression code that is not used when only reading or only
+ writing respectively. If gzclose() is used, then both compression and
+ decompression code will be included the application when linking to a static
+ zlib library.
+*/
+
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
+/*
+ Returns the error message for the last error which occurred on the given
+ compressed file. errnum is set to zlib error number. If an error occurred
+ in the file system and not in the compression library, errnum is set to
+ Z_ERRNO and the application may consult errno to get the exact error code.
+
+ The application must not modify the returned string. Future calls to
+ this function may invalidate the previously returned string. If file is
+ closed, then the string previously returned by gzerror will no longer be
+ available.
+
+ gzerror() should be used to distinguish errors from end-of-file for those
+ functions above that do not distinguish those cases in their return values.
+*/
+
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
+/*
+ Clears the error and end-of-file flags for file. This is analogous to the
+ clearerr() function in stdio. This is useful for continuing to read a gzip
+ file that is being written concurrently.
+*/
+
+#endif /* !Z_SOLO */
+
+ /* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the compression
+ library.
+*/
+
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is Z_NULL, this function returns the
+ required initial value for the checksum.
+
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster.
+
+ Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+*/
+
+/*
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
+ z_off_t len2));
+
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
+ negative, the result has no meaning or utility.
+*/
+
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+/*
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
+ updated CRC-32. If buf is Z_NULL, this function returns the required
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
+
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+*/
+
+/*
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
+
+ Combine two CRC-32 check values into one. For two sequences of bytes,
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
+ len2.
+*/
+
+
+ /* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size));
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window,
+ const char *version,
+ int stream_size));
+#define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
+#define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
+#define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
+#define inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, (int)sizeof(z_stream))
+
+#ifndef Z_SOLO
+
+/* gzgetc() macro and its supporting function and exposed data structure. Note
+ * that the real internal state is much larger than the exposed structure.
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
+ * user should not mess with these exposed elements, since their names or
+ * behavior could change in the future, perhaps even capriciously. They can
+ * only be used by the gzgetc() macro. You have been warned.
+ */
+struct gzFile_s {
+ unsigned have;
+ unsigned char *next;
+ z_off64_t pos;
+};
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
+#ifdef Z_PREFIX_SET
+# undef z_gzgetc
+# define z_gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#else
+# define gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#endif
+
+/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
+ * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
+ * both are true, the application gets the *64 functions, and the regular
+ * functions are changed to 64 bits) -- in case these are set on systems
+ * without large file support, _LFS64_LARGEFILE must also be true
+ */
+#ifdef Z_LARGE64
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
+ ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
+ ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
+ ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
+#endif
+
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
+# ifdef Z_PREFIX_SET
+# define z_gzopen z_gzopen64
+# define z_gzseek z_gzseek64
+# define z_gztell z_gztell64
+# define z_gzoffset z_gzoffset64
+# define z_adler32_combine z_adler32_combine64
+# define z_crc32_combine z_crc32_combine64
+# else
+# define gzopen gzopen64
+# define gzseek gzseek64
+# define gztell gztell64
+# define gzoffset gzoffset64
+# define adler32_combine adler32_combine64
+# define crc32_combine crc32_combine64
+# endif
+# ifndef Z_LARGE64
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
+ ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
+ ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
+ ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
+# endif
+#else
+ ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
+ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
+ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
+ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+#endif
+
+#else /* Z_SOLO */
+
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+
+#endif /* !Z_SOLO */
+
+/* hack for buggy compilers */
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
+ struct internal_state {int dummy;};
+#endif
+
+/* undocumented functions */
+ZEXTERN const char * ZEXPORT zError OF((int));
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
+ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
+#if defined(_WIN32) && !defined(Z_SOLO)
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
+ const char *mode));
+#endif
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# ifndef Z_SOLO
+ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
+ const char *format,
+ va_list va));
+# endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZLIB_H */
--- /dev/null
+/* Copyright (C) 2010-2015 The RetroArch team
+ *
+ * ---------------------------------------------------------------------------------------
+ * The following license statement only applies to this file (retro_inline.h).
+ * ---------------------------------------------------------------------------------------
+ *
+ * Permission is hereby granted, free of charge,
+ * to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LIBRETRO_SDK_INLINE_H
+#define __LIBRETRO_SDK_INLINE_H
+
+#ifndef INLINE
+
+#if !defined(__cplusplus) && defined(_WIN32)
+#define INLINE _inline
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
+#define INLINE inline
+#elif defined(__GNUC__)
+#define INLINE __inline__
+#else
+#define INLINE
+#endif
+
+#endif
+#endif
--- /dev/null
+#ifndef MMAN_H
+#define MMAN_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <psp2/kernel/sysmem.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PROT_READ 0b001
+#define PROT_WRITE 0b010
+#define PROT_EXEC 0b100
+#define MAP_PRIVATE 2
+#define MAP_ANONYMOUS 0x20
+
+#define MAP_FAILED ((void *)-1)
+
+static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
+{
+ (void)prot;
+ (void)flags;
+ (void)fd;
+ (void)offset;
+
+ int block, ret;
+
+ block = sceKernelAllocMemBlockForVM("code", len);
+ if(block<=0){
+ sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, len);
+ exit(1);
+ }
+
+ // get base address
+ ret = sceKernelGetMemBlockBase(block, &addr);
+ if (ret < 0)
+ {
+ sceClibPrintf("could get address @0x%08X 0x%08X \n", block, addr);
+ exit(1);
+ }
+
+
+ if(!addr)
+ return MAP_FAILED;
+
+ return addr;
+}
+
+static inline int mprotect(void *addr, size_t len, int prot)
+{
+ (void)addr;
+ (void)len;
+ (void)prot;
+ return 0;
+}
+
+static inline int munmap(void *addr, size_t len)
+{
+ int uid = sceKernelFindMemBlockByAddr(addr, len);
+
+ return sceKernelFreeMemBlock(uid);
+
+}
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // MMAN_H
--- /dev/null
+//SPDX-License-Identifier: GPL-2.0-or-later
+/* From wut:
+ * https://github.com/devkitPro/wut/blob/0b196e8abcedeb0238105f3ffab7cb0093638b86/include/coreinit/memorymap.h
+ */
+
+#pragma once
+#include <stdint.h>
+#include <stdbool.h>
+typedef bool BOOL;
+
+/**
+ * \defgroup coreinit_memorymap Memory Map
+ * \ingroup coreinit
+ *
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum OSMemoryMapMode
+{
+ OS_MAP_MEMORY_INVALID = 0,
+ OS_MAP_MEMORY_READ_ONLY = 1,
+ OS_MAP_MEMORY_READ_WRITE = 2,
+ OS_MAP_MEMORY_FREE = 3,
+ OS_MAP_MEMORY_ALLOCATED = 4,
+} OSMemoryMapMode;
+
+#define OS_PAGE_SIZE (128 * 1024)
+
+uint32_t
+OSEffectiveToPhysical(uint32_t virtualAddress);
+
+BOOL
+OSIsAddressValid(uint32_t virtualAddress);
+
+BOOL
+__OSValidateAddressSpaceRange(int /* unused */,
+ uint32_t virtualAddress,
+ uint32_t size);
+
+/**
+ * Allocates virtual address range for later mapping.
+ *
+ * \param virtualAddress
+ * Requested start address for the range. If there is no preference, NULL can be
+ * used.
+ *
+ * \param size
+ * Size of address range to allocate.
+ *
+ * \param align
+ * Alignment of address range to allocate.
+ *
+ * \return
+ * The starting address of the newly allocated range, or NULL on failure.
+ *
+ * \sa
+ * - OSFreeVirtAddr()
+ * - OSMapMemory()
+ */
+uint32_t
+OSAllocVirtAddr(uint32_t virtualAddress,
+ uint32_t size,
+ uint32_t align);
+
+/**
+ * Frees a previously allocated virtual address range back to the system.
+ *
+ * \param virtualAddress
+ * The start of the virtual address range to free.
+ *
+ * \param size
+ * The size of the virtual address range to free.
+ *
+ * \return
+ * \c true on success.
+ */
+BOOL
+OSFreeVirtAddr(uint32_t virtualAddress,
+ uint32_t size);
+
+/**
+ * Determines the status of the given virtual memory address - mapped read-write
+ * or read-only, free, allocated or invalid.
+ *
+ * \param virtualAddress
+ * The virtual address to query.
+ *
+ * \return
+ * The status of the memory address - see #OSMemoryMapMode.
+ */
+OSMemoryMapMode
+OSQueryVirtAddr(uint32_t virtualAddress);
+
+/**
+ * Maps a physical address to a virtual address, with a given size and set of
+ * permissions.
+ *
+ * \param virtualAddress
+ * The target virtual address for the mapping.
+ *
+ * \param physicalAddress
+ * Physical address of the memory to back the mapping.
+ *
+ * \param size
+ * Size, in bytes, of the desired mapping. Likely has an alignment requirement.
+ *
+ * \param mode
+ * Permissions to map the memory with - see #OSMemoryMapMode.
+ *
+ * \return
+ * \c true on success.
+ *
+ * \sa
+ * - OSAllocVirtAddr()
+ * - OSUnmapMemory()
+ */
+BOOL
+OSMapMemory(uint32_t virtualAddress,
+ uint32_t physicalAddress,
+ uint32_t size,
+ OSMemoryMapMode mode);
+
+/**
+ * Unmaps previously mapped memory.
+ *
+ * \param virtualAddress
+ * Starting address of the area to unmap.
+ *
+ * \param size
+ * Size of the memory area to unmap.
+ *
+ * \return
+ * \c true on success.
+ */
+BOOL
+OSUnmapMemory(uint32_t virtualAddress,
+ uint32_t size);
+
+/**
+ * Gets the range of virtual addresses available for mapping.
+ *
+ * \param outVirtualAddress
+ * Pointer to write the starting address of the memory area to.
+ *
+ * \param outSize
+ * Pointer to write the size of the memory area to.
+ *
+ * \sa
+ * - OSMapMemory()
+ */
+void
+OSGetMapVirtAddrRange(uint32_t *outVirtualAddress,
+ uint32_t *outSize);
+
+/**
+ * Gets the range of available physical memory (not reserved for app code or
+ * data).
+ *
+ * \param outPhysicalAddress
+ * Pointer to write the starting physical address of the memory area to.
+ *
+ * \param outSize
+ * Pointer to write the size of the memory area to.
+ *
+ * \if false
+ * Is memory returned by this function actually safe to map and use? couldn't
+ * get a straight answer from decaf-emu's kernel_memory.cpp...
+ * \endif
+ */
+void
+OSGetAvailPhysAddrRange(uint32_t *outPhysicalAddress,
+ uint32_t *outSize);
+
+/**
+ * Gets the range of physical memory used for the application's data.
+ *
+ * \param outPhysicalAddress
+ * Pointer to write the starting physical address of the memory area to.
+ *
+ * \param outSize
+ * Pointer to write the size of the memory area to.
+ *
+ * \if false
+ * does this include the main heap?
+ * \endif
+ */
+void
+OSGetDataPhysAddrRange(uint32_t *outPhysicalAddress,
+ uint32_t *outSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
--- /dev/null
+/*
+ * Copyright (C) 2012-2023 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU lightning.
+ *
+ * GNU lightning is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU lightning is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * Authors:
+ * Paulo Cesar Pereira de Andrade
+ */
+
+#ifndef _lightning_h
+#define _lightning_h
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+
+#if defined(__hpux) && defined(__hppa__)
+# include <machine/param.h>
+#endif
+#if defined(__alpha__) && defined(__osf__)
+# include <machine/endian.h>
+#endif
+
+#ifndef __WORDSIZE
+# if defined(WORDSIZE) /* ppc darwin */
+# define __WORDSIZE WORDSIZE
+# elif defined(__SIZEOF_POINTER__) /* ppc aix */
+# define __WORDSIZE (__SIZEOF_POINTER__ << 3)
+# elif defined(_ILP32) /* hppa hp-ux */
+# define __WORDSIZE 32
+# elif defined(_LP64) /* ia64 hp-ux (with cc +DD64) */
+# define __WORDSIZE 64
+# elif defined(_MIPS_SZPTR) /* mips irix */
+# if _MIPS_SZPTR == 32
+# define __WORDSIZE 32
+# else
+# define __WORDSIZE 64
+# endif
+# else /* From FreeBSD 9.1 stdint.h */
+# if defined(UINTPTR_MAX) && defined(UINT64_MAX) && \
+ (UINTPTR_MAX == UINT64_MAX)
+# define __WORDSIZE 64
+# else
+# define __WORDSIZE 32
+# endif
+# endif
+#endif
+#ifndef __LITTLE_ENDIAN
+# if defined(LITTLE_ENDIAN) /* ppc darwin */
+# define __LITTLE_ENDIAN LITTLE_ENDIAN
+# elif defined(__ORDER_LITTLE_ENDIAN__) /* ppc aix */
+# define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+# else
+# define __LITTLE_ENDIAN 1234
+# endif
+#endif
+#ifndef __BIG_ENDIAN
+# if defined(BIG_ENDIAN) /* ppc darwin */
+# define __BIG_ENDIAN BIG_ENDIAN
+# elif defined(__ORDER_BIG_ENDIAN__) /* ppc aix */
+# define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+# else
+# define __BIG_ENDIAN 4321
+# endif
+#endif
+#ifndef __BYTE_ORDER
+# if defined(BYTE_ORDER) /* ppc darwin */
+# define __BYTE_ORDER BYTE_ORDER
+# elif defined(__BYTE_ORDER__) /* ppc aix */
+# define __BYTE_ORDER __BYTE_ORDER__
+# elif defined(_BIG_ENDIAN) /* hppa hp-ux */
+# define __BYTE_ORDER __BIG_ENDIAN
+# elif defined(__BIG_ENDIAN__) /* ia64 hp-ux */
+# define __BYTE_ORDER __BIG_ENDIAN
+# elif defined(__i386__) /* 32 bit x86 solaris */
+# define __BYTE_ORDER __LITTLE_ENDIAN
+# elif defined(__x86_64__) /* 64 bit x86 solaris */
+# define __BYTE_ORDER __LITTLE_ENDIAN
+# elif defined(__MIPSEB) /* mips irix */
+# define __BYTE_ORDER __BIG_ENDIAN
+# else
+# error cannot figure __BYTE_ORDER
+# endif
+#endif
+
+typedef signed char jit_int8_t;
+typedef unsigned char jit_uint8_t;
+typedef signed short jit_int16_t;
+typedef unsigned short jit_uint16_t;
+typedef signed int jit_int32_t;
+typedef unsigned int jit_uint32_t;
+#if __WORDSIZE == 32
+typedef signed long long jit_int64_t;
+typedef unsigned long long jit_uint64_t;
+typedef jit_int32_t jit_word_t;
+typedef jit_uint32_t jit_uword_t;
+#elif (_WIN32 && !__CYGWIN__)
+typedef signed long long jit_int64_t;
+typedef unsigned long long jit_uint64_t;
+typedef jit_int64_t jit_word_t;
+typedef jit_uint64_t jit_uword_t;
+#else
+typedef signed long jit_int64_t;
+typedef unsigned long jit_uint64_t;
+typedef jit_int64_t jit_word_t;
+typedef jit_uint64_t jit_uword_t;
+#endif
+typedef float jit_float32_t;
+typedef double jit_float64_t;
+typedef void* jit_pointer_t;
+typedef jit_int32_t jit_bool_t;
+typedef jit_int32_t jit_gpr_t;
+typedef jit_int32_t jit_fpr_t;
+
+#if !defined(__powerpc__) && \
+ (defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__))
+#define __powerpc__ 1
+#endif
+
+#if defined(__i386__) || defined(__x86_64__)
+# include <lightning/jit_x86.h>
+#elif defined(__mips__)
+# include <lightning/jit_mips.h>
+#elif defined(__arm__)
+# include <lightning/jit_arm.h>
+#elif defined(__powerpc__)
+# include <lightning/jit_ppc.h>
+#elif defined(__sparc__)
+# include <lightning/jit_sparc.h>
+#elif defined(__ia64__)
+# include <lightning/jit_ia64.h>
+#elif defined(__hppa__)
+# include <lightning/jit_hppa.h>
+#elif defined(__aarch64__)
+# include <lightning/jit_aarch64.h>
+#elif defined(__s390__) || defined(__s390x__)
+# include <lightning/jit_s390.h>
+#elif defined(__alpha__)
+# include <lightning/jit_alpha.h>
+#elif defined(__riscv)
+# include <lightning/jit_riscv.h>
+#elif defined(__loongarch__)
+# include <lightning/jit_loongarch.h>
+#endif
+
+#define jit_flag_node 0x0001 /* patch node not absolute */
+#define jit_flag_patch 0x0002 /* jump already patched */
+#define jit_flag_data 0x0004 /* data in the constant pool */
+#define jit_flag_use 0x0008 /* do not remove marker label */
+#define jit_flag_synth 0x0010 /* synthesized instruction */
+#define jit_flag_head 0x1000 /* label reached by normal flow */
+#define jit_flag_varargs 0x2000 /* call{r,i} to varargs function */
+
+#define JIT_R(index) jit_r(index)
+#define JIT_V(index) jit_v(index)
+#define JIT_F(index) jit_f(index)
+#define JIT_R_NUM jit_r_num()
+#define JIT_V_NUM jit_v_num()
+#define JIT_F_NUM jit_f_num()
+
+#define JIT_DISABLE_DATA 1 /* force synthesize of constants */
+#define JIT_DISABLE_NOTE 2 /* disable debug info generation */
+
+#define jit_class_chk 0x02000000 /* just checking */
+#define jit_class_arg 0x08000000 /* argument register */
+#define jit_class_sav 0x10000000 /* callee save */
+#define jit_class_gpr 0x20000000 /* general purpose */
+#define jit_class_fpr 0x40000000 /* float */
+#define jit_class(reg) ((reg) & 0xffff0000)
+#define jit_regno(reg) ((reg) & 0x00007fff)
+
+typedef struct jit_node jit_node_t;
+typedef struct jit_state jit_state_t;
+
+typedef enum {
+ jit_code_data,
+#define jit_live(u) jit_new_node_w(jit_code_live, u)
+#define jit_align(u) jit_new_node_w(jit_code_align, u)
+ jit_code_live, jit_code_align,
+ jit_code_save, jit_code_load,
+#define jit_skip(u) jit_new_node_w(jit_code_skip, u)
+ jit_code_skip,
+#define jit_name(u) _jit_name(_jit,u)
+ jit_code_name,
+#define jit_note(u, v) _jit_note(_jit, u, v)
+#define jit_label() _jit_label(_jit)
+#define jit_forward() _jit_forward(_jit)
+#define jit_indirect() _jit_indirect(_jit)
+#define jit_link(u) _jit_link(_jit,u)
+ jit_code_note, jit_code_label,
+
+#define jit_prolog() _jit_prolog(_jit)
+ jit_code_prolog,
+
+#define jit_ellipsis() _jit_ellipsis(_jit)
+ jit_code_ellipsis,
+#define jit_va_push(u) _jit_va_push(_jit,u)
+ jit_code_va_push,
+#define jit_allocai(u) _jit_allocai(_jit,u)
+#define jit_allocar(u, v) _jit_allocar(_jit,u,v)
+ jit_code_allocai, jit_code_allocar,
+
+#define jit_arg_c() _jit_arg(_jit, jit_code_arg_c)
+#define jit_arg_s() _jit_arg(_jit, jit_code_arg_s)
+#define jit_arg_i() _jit_arg(_jit, jit_code_arg_i)
+# if __WORDSIZE == 32
+# define jit_arg() jit_arg_i()
+#else
+# define jit_arg_l() _jit_arg(_jit, jit_code_arg_l)
+# define jit_arg() jit_arg_l()
+#endif
+ jit_code_arg_c, jit_code_arg_s,
+ jit_code_arg_i, jit_code_arg_l,
+#if __WORDSIZE == 32
+# define jit_code_arg jit_code_arg_i
+#else
+# define jit_code_arg jit_code_arg_l
+#endif
+
+#define jit_getarg_c(u,v) _jit_getarg_c(_jit,u,v)
+#define jit_getarg_uc(u,v) _jit_getarg_uc(_jit,u,v)
+#define jit_getarg_s(u,v) _jit_getarg_s(_jit,u,v)
+#define jit_getarg_us(u,v) _jit_getarg_us(_jit,u,v)
+#define jit_getarg_i(u,v) _jit_getarg_i(_jit,u,v)
+#if __WORDSIZE == 32
+# define jit_getarg(u,v) jit_getarg_i(u,v)
+#else
+# define jit_getarg_ui(u,v) _jit_getarg_ui(_jit,u,v)
+# define jit_getarg_l(u,v) _jit_getarg_l(_jit,u,v)
+# define jit_getarg(u,v) jit_getarg_l(u,v)
+#endif
+ jit_code_getarg_c, jit_code_getarg_uc,
+ jit_code_getarg_s, jit_code_getarg_us,
+ jit_code_getarg_i, jit_code_getarg_ui,
+ jit_code_getarg_l,
+#if __WORDSIZE == 32
+# define jit_code_getarg jit_code_getarg_i
+#else
+# define jit_code_getarg jit_code_getarg_l
+#endif
+
+#define jit_putargr_c(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_c)
+#define jit_putargi_c(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_c)
+#define jit_putargr_uc(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_uc)
+#define jit_putargi_uc(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_uc)
+#define jit_putargr_s(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_s)
+#define jit_putargi_s(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_s)
+#define jit_putargr_us(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_us)
+#define jit_putargi_us(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_us)
+#define jit_putargr_i(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_i)
+#define jit_putargi_i(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_i)
+#if __WORDSIZE == 32
+# define jit_putargr(u,v) jit_putargr_i(u,v)
+# define jit_putargi(u,v) jit_putargi_i(u,v)
+#else
+# define jit_putargr_ui(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_ui)
+# define jit_putargi_ui(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_ui)
+# define jit_putargr_l(u,v) _jit_putargr(_jit,u,v,jit_code_putargr_l)
+# define jit_putargi_l(u,v) _jit_putargi(_jit,u,v,jit_code_putargi_l)
+# define jit_putargr(u,v) jit_putargr_l(u,v)
+# define jit_putargi(u,v) jit_putargi_l(u,v)
+#endif
+ jit_code_putargr_c, jit_code_putargi_c,
+ jit_code_putargr_uc, jit_code_putargi_uc,
+ jit_code_putargr_s, jit_code_putargi_s,
+ jit_code_putargr_us, jit_code_putargi_us,
+ jit_code_putargr_i, jit_code_putargi_i,
+ jit_code_putargr_ui, jit_code_putargi_ui,
+ jit_code_putargr_l, jit_code_putargi_l,
+#if __WORDSIZE == 32
+# define jit_code_putargr jit_code_putargr_i
+# define jit_code_putargi jit_code_putargi_i
+#else
+# define jit_code_putargr jit_code_putargr_l
+# define jit_code_putargi jit_code_putargi_l
+#endif
+
+#define jit_va_start(u) jit_new_node_w(jit_code_va_start, u)
+ jit_code_va_start,
+#define jit_va_arg(u, v) jit_new_node_ww(jit_code_va_arg, u, v)
+#define jit_va_arg_d(u, v) jit_new_node_ww(jit_code_va_arg_d, u, v)
+ jit_code_va_arg, jit_code_va_arg_d,
+#define jit_va_end(u) jit_new_node_w(jit_code_va_end, u)
+ jit_code_va_end,
+
+#define jit_addr(u,v,w) jit_new_node_www(jit_code_addr,u,v,w)
+#define jit_addi(u,v,w) jit_new_node_www(jit_code_addi,u,v,w)
+ jit_code_addr, jit_code_addi,
+#define jit_addcr(u,v,w) jit_new_node_www(jit_code_addcr,u,v,w)
+#define jit_addci(u,v,w) jit_new_node_www(jit_code_addci,u,v,w)
+ jit_code_addcr, jit_code_addci,
+#define jit_addxr(u,v,w) jit_new_node_www(jit_code_addxr,u,v,w)
+#define jit_addxi(u,v,w) jit_new_node_www(jit_code_addxi,u,v,w)
+ jit_code_addxr, jit_code_addxi,
+#define jit_subr(u,v,w) jit_new_node_www(jit_code_subr,u,v,w)
+#define jit_subi(u,v,w) jit_new_node_www(jit_code_subi,u,v,w)
+ jit_code_subr, jit_code_subi,
+#define jit_subcr(u,v,w) jit_new_node_www(jit_code_subcr,u,v,w)
+#define jit_subci(u,v,w) jit_new_node_www(jit_code_subci,u,v,w)
+ jit_code_subcr, jit_code_subci,
+#define jit_subxr(u,v,w) jit_new_node_www(jit_code_subxr,u,v,w)
+#define jit_subxi(u,v,w) jit_new_node_www(jit_code_subxi,u,v,w)
+ jit_code_subxr, jit_code_subxi,
+#define jit_rsbr(u,v,w) jit_subr(u,w,v)
+#define jit_rsbi(u,v,w) jit_new_node_www(jit_code_rsbi,u,v,w)
+ jit_code_rsbi,
+#define jit_mulr(u,v,w) jit_new_node_www(jit_code_mulr,u,v,w)
+#define jit_muli(u,v,w) jit_new_node_www(jit_code_muli,u,v,w)
+ jit_code_mulr, jit_code_muli,
+#define jit_qmulr(l,h,v,w) jit_new_node_qww(jit_code_qmulr,l,h,v,w)
+#define jit_qmuli(l,h,v,w) jit_new_node_qww(jit_code_qmuli,l,h,v,w)
+ jit_code_qmulr, jit_code_qmuli,
+#define jit_qmulr_u(l,h,v,w) jit_new_node_qww(jit_code_qmulr_u,l,h,v,w)
+#define jit_qmuli_u(l,h,v,w) jit_new_node_qww(jit_code_qmuli_u,l,h,v,w)
+ jit_code_qmulr_u, jit_code_qmuli_u,
+#define jit_divr(u,v,w) jit_new_node_www(jit_code_divr,u,v,w)
+#define jit_divi(u,v,w) jit_new_node_www(jit_code_divi,u,v,w)
+ jit_code_divr, jit_code_divi,
+#define jit_divr_u(u,v,w) jit_new_node_www(jit_code_divr_u,u,v,w)
+#define jit_divi_u(u,v,w) jit_new_node_www(jit_code_divi_u,u,v,w)
+ jit_code_divr_u, jit_code_divi_u,
+#define jit_qdivr(l,h,v,w) jit_new_node_qww(jit_code_qdivr,l,h,v,w)
+#define jit_qdivi(l,h,v,w) jit_new_node_qww(jit_code_qdivi,l,h,v,w)
+ jit_code_qdivr, jit_code_qdivi,
+#define jit_qdivr_u(l,h,v,w) jit_new_node_qww(jit_code_qdivr_u,l,h,v,w)
+#define jit_qdivi_u(l,h,v,w) jit_new_node_qww(jit_code_qdivi_u,l,h,v,w)
+ jit_code_qdivr_u, jit_code_qdivi_u,
+#define jit_remr(u,v,w) jit_new_node_www(jit_code_remr,u,v,w)
+#define jit_remi(u,v,w) jit_new_node_www(jit_code_remi,u,v,w)
+ jit_code_remr, jit_code_remi,
+#define jit_remr_u(u,v,w) jit_new_node_www(jit_code_remr_u,u,v,w)
+#define jit_remi_u(u,v,w) jit_new_node_www(jit_code_remi_u,u,v,w)
+ jit_code_remr_u, jit_code_remi_u,
+
+#define jit_andr(u,v,w) jit_new_node_www(jit_code_andr,u,v,w)
+#define jit_andi(u,v,w) jit_new_node_www(jit_code_andi,u,v,w)
+ jit_code_andr, jit_code_andi,
+#define jit_orr(u,v,w) jit_new_node_www(jit_code_orr,u,v,w)
+#define jit_ori(u,v,w) jit_new_node_www(jit_code_ori,u,v,w)
+ jit_code_orr, jit_code_ori,
+#define jit_xorr(u,v,w) jit_new_node_www(jit_code_xorr,u,v,w)
+#define jit_xori(u,v,w) jit_new_node_www(jit_code_xori,u,v,w)
+ jit_code_xorr, jit_code_xori,
+
+#define jit_lshr(u,v,w) jit_new_node_www(jit_code_lshr,u,v,w)
+#define jit_lshi(u,v,w) jit_new_node_www(jit_code_lshi,u,v,w)
+ jit_code_lshr, jit_code_lshi,
+#define jit_rshr(u,v,w) jit_new_node_www(jit_code_rshr,u,v,w)
+#define jit_rshi(u,v,w) jit_new_node_www(jit_code_rshi,u,v,w)
+ jit_code_rshr, jit_code_rshi,
+#define jit_rshr_u(u,v,w) jit_new_node_www(jit_code_rshr_u,u,v,w)
+#define jit_rshi_u(u,v,w) jit_new_node_www(jit_code_rshi_u,u,v,w)
+ jit_code_rshr_u, jit_code_rshi_u,
+
+#define jit_negr(u,v) jit_new_node_ww(jit_code_negr,u,v)
+#define jit_negi(u,v) jit_new_node_ww(jit_code_negi,u,v)
+ jit_code_negr, jit_code_negi,
+#define jit_comr(u,v) jit_new_node_ww(jit_code_comr,u,v)
+#define jit_comi(u,v) jit_new_node_ww(jit_code_comi,u,v)
+ jit_code_comr, jit_code_comi,
+
+#define jit_ltr(u,v,w) jit_new_node_www(jit_code_ltr,u,v,w)
+#define jit_lti(u,v,w) jit_new_node_www(jit_code_lti,u,v,w)
+ jit_code_ltr, jit_code_lti,
+#define jit_ltr_u(u,v,w) jit_new_node_www(jit_code_ltr_u,u,v,w)
+#define jit_lti_u(u,v,w) jit_new_node_www(jit_code_lti_u,u,v,w)
+ jit_code_ltr_u, jit_code_lti_u,
+#define jit_ler(u,v,w) jit_new_node_www(jit_code_ler,u,v,w)
+#define jit_lei(u,v,w) jit_new_node_www(jit_code_lei,u,v,w)
+ jit_code_ler, jit_code_lei,
+#define jit_ler_u(u,v,w) jit_new_node_www(jit_code_ler_u,u,v,w)
+#define jit_lei_u(u,v,w) jit_new_node_www(jit_code_lei_u,u,v,w)
+ jit_code_ler_u, jit_code_lei_u,
+#define jit_eqr(u,v,w) jit_new_node_www(jit_code_eqr,u,v,w)
+#define jit_eqi(u,v,w) jit_new_node_www(jit_code_eqi,u,v,w)
+ jit_code_eqr, jit_code_eqi,
+#define jit_ger(u,v,w) jit_new_node_www(jit_code_ger,u,v,w)
+#define jit_gei(u,v,w) jit_new_node_www(jit_code_gei,u,v,w)
+ jit_code_ger, jit_code_gei,
+#define jit_ger_u(u,v,w) jit_new_node_www(jit_code_ger_u,u,v,w)
+#define jit_gei_u(u,v,w) jit_new_node_www(jit_code_gei_u,u,v,w)
+ jit_code_ger_u, jit_code_gei_u,
+#define jit_gtr(u,v,w) jit_new_node_www(jit_code_gtr,u,v,w)
+#define jit_gti(u,v,w) jit_new_node_www(jit_code_gti,u,v,w)
+ jit_code_gtr, jit_code_gti,
+#define jit_gtr_u(u,v,w) jit_new_node_www(jit_code_gtr_u,u,v,w)
+#define jit_gti_u(u,v,w) jit_new_node_www(jit_code_gti_u,u,v,w)
+ jit_code_gtr_u, jit_code_gti_u,
+#define jit_ner(u,v,w) jit_new_node_www(jit_code_ner,u,v,w)
+#define jit_nei(u,v,w) jit_new_node_www(jit_code_nei,u,v,w)
+ jit_code_ner, jit_code_nei,
+
+#define jit_movr(u,v) jit_new_node_ww(jit_code_movr,u,v)
+#define jit_movi(u,v) jit_new_node_ww(jit_code_movi,u,v)
+ jit_code_movr, jit_code_movi,
+
+#define jit_movnr(u,v,w) jit_new_node_www(jit_code_movnr,u,v,w)
+#define jit_movzr(u,v,w) jit_new_node_www(jit_code_movzr,u,v,w)
+ jit_code_movnr, jit_code_movzr,
+
+ jit_code_casr, jit_code_casi,
+#define jit_casr(u, v, w, x) jit_new_node_wwq(jit_code_casr, u, v, w, x)
+#define jit_casi(u, v, w, x) jit_new_node_wwq(jit_code_casi, u, v, w, x)
+
+#define jit_extr_c(u,v) jit_new_node_ww(jit_code_extr_c,u,v)
+#define jit_exti_c(u,v) jit_new_node_ww(jit_code_exti_c,u,v)
+ jit_code_extr_c, jit_code_exti_c,
+
+#define jit_extr_uc(u,v) jit_new_node_ww(jit_code_extr_uc,u,v)
+#define jit_exti_uc(u,v) jit_new_node_ww(jit_code_exti_uc,u,v)
+ jit_code_extr_uc, jit_code_exti_uc,
+
+#define jit_extr_s(u,v) jit_new_node_ww(jit_code_extr_s,u,v)
+#define jit_exti_s(u,v) jit_new_node_ww(jit_code_exti_s,u,v)
+ jit_code_extr_s, jit_code_exti_s,
+
+#define jit_extr_us(u,v) jit_new_node_ww(jit_code_extr_us,u,v)
+#define jit_exti_us(u,v) jit_new_node_ww(jit_code_exti_us,u,v)
+ jit_code_extr_us, jit_code_exti_us,
+
+#if __WORDSIZE == 64
+# define jit_extr_i(u,v) jit_new_node_ww(jit_code_extr_i,u,v)
+# define jit_exti_i(u,v) jit_new_node_ww(jit_code_exti_i,u,v)
+# define jit_extr_ui(u,v) jit_new_node_ww(jit_code_extr_ui,u,v)
+# define jit_exti_ui(u,v) jit_new_node_ww(jit_code_exti_ui,u,v)
+#endif
+ jit_code_extr_i, jit_code_exti_i,
+ jit_code_extr_ui, jit_code_exti_ui,
+
+#define jit_bswapr_us(u,v) jit_new_node_ww(jit_code_bswapr_us,u,v)
+#define jit_bswapi_us(u,v) jit_new_node_ww(jit_code_bswapi_us,u,v)
+ jit_code_bswapr_us, jit_code_bswapi_us,
+
+#define jit_bswapr_ui(u,v) jit_new_node_ww(jit_code_bswapr_ui,u,v)
+#define jit_bswapi_ui(u,v) jit_new_node_ww(jit_code_bswapi_ui,u,v)
+ jit_code_bswapr_ui, jit_code_bswapi_ui,
+
+#if __WORDSIZE == 64
+# define jit_bswapr_ul(u,v) jit_new_node_ww(jit_code_bswapr_ul,u,v)
+# define jit_bswapi_ul(u,v) jit_new_node_ww(jit_code_bswapi_ul,u,v)
+#endif
+ jit_code_bswapr_ul, jit_code_bswapi_ul,
+
+#if __WORDSIZE == 32
+# define jit_bswapr(u,v) jit_bswapr_ui(u,v)
+# define jit_bswapi(u,v) jit_bswapi_ui(u,v)
+#else
+# define jit_bswapr(u,v) jit_bswapr_ul(u,v)
+# define jit_bswapi(u,v) jit_bswapi_ul(u,v)
+#endif
+
+#define jit_htonr_us(u,v) jit_new_node_ww(jit_code_htonr_us,u,v)
+#define jit_ntohr_us(u,v) jit_htonr_us(u,v)
+#define jit_htoni_us(u,v) jit_new_node_ww(jit_code_htoni_us,u,v)
+#define jit_ntohi_us(u,v) jit_htoni_us(u, v)
+ jit_code_htonr_us, jit_code_htoni_us,
+
+#define jit_htonr_ui(u,v) jit_new_node_ww(jit_code_htonr_ui,u,v)
+#define jit_ntohr_ui(u,v) jit_htonr_ui(u,v)
+#define jit_htoni_ui(u,v) jit_new_node_ww(jit_code_htoni_ui,u,v)
+#define jit_ntohi_ui(u,v) jit_htoni_ui(u, v)
+ jit_code_htonr_ui, jit_code_htoni_ui,
+
+#if __WORDSIZE == 64
+# define jit_htonr_ul(u,v) jit_new_node_ww(jit_code_htonr_ul,u,v)
+# define jit_ntohr_ul(u,v) jit_htonr_ul(u,v)
+# define jit_htoni_ul(u,v) jit_new_node_ww(jit_code_htoni_ul,u,v)
+# define jit_ntohi_ul(u,v) jit_htoni_ul(u, v)
+#endif
+ jit_code_htonr_ul, jit_code_htoni_ul,
+
+#if __WORDSIZE == 32
+# define jit_htonr(u,v) jit_htonr_ui(u,v)
+# define jit_htoni(u,v) jit_htoni_ui(u,v)
+#else
+# define jit_htonr(u,v) jit_htonr_ul(u,v)
+# define jit_htoni(u,v) jit_htoni_ul(u,v)
+#endif
+#define jit_ntohr(u,v) jit_htonr(u,v)
+#define jit_ntohi(u,v) jit_htoni(u,v)
+
+#define jit_ldr_c(u,v) jit_new_node_ww(jit_code_ldr_c,u,v)
+#define jit_ldi_c(u,v) jit_new_node_wp(jit_code_ldi_c,u,v)
+ jit_code_ldr_c, jit_code_ldi_c,
+#define jit_ldr_uc(u,v) jit_new_node_ww(jit_code_ldr_uc,u,v)
+#define jit_ldi_uc(u,v) jit_new_node_wp(jit_code_ldi_uc,u,v)
+ jit_code_ldr_uc, jit_code_ldi_uc,
+#define jit_ldr_s(u,v) jit_new_node_ww(jit_code_ldr_s,u,v)
+#define jit_ldi_s(u,v) jit_new_node_wp(jit_code_ldi_s,u,v)
+ jit_code_ldr_s, jit_code_ldi_s,
+#define jit_ldr_us(u,v) jit_new_node_ww(jit_code_ldr_us,u,v)
+#define jit_ldi_us(u,v) jit_new_node_wp(jit_code_ldi_us,u,v)
+ jit_code_ldr_us, jit_code_ldi_us,
+#define jit_ldr_i(u,v) jit_new_node_ww(jit_code_ldr_i,u,v)
+#define jit_ldi_i(u,v) jit_new_node_wp(jit_code_ldi_i,u,v)
+ jit_code_ldr_i, jit_code_ldi_i,
+#if __WORDSIZE == 32
+# define jit_ldr(u,v) jit_ldr_i(u,v)
+# define jit_ldi(u,v) jit_ldi_i(u,v)
+#else
+# define jit_ldr(u,v) jit_ldr_l(u,v)
+# define jit_ldi(u,v) jit_ldi_l(u,v)
+# define jit_ldr_ui(u,v) jit_new_node_ww(jit_code_ldr_ui,u,v)
+# define jit_ldi_ui(u,v) jit_new_node_wp(jit_code_ldi_ui,u,v)
+#define jit_ldr_l(u,v) jit_new_node_ww(jit_code_ldr_l,u,v)
+#define jit_ldi_l(u,v) jit_new_node_wp(jit_code_ldi_l,u,v)
+#endif
+ jit_code_ldr_ui, jit_code_ldi_ui,
+ jit_code_ldr_l, jit_code_ldi_l,
+
+#define jit_ldxr_c(u,v,w) jit_new_node_www(jit_code_ldxr_c,u,v,w)
+#define jit_ldxi_c(u,v,w) jit_new_node_www(jit_code_ldxi_c,u,v,w)
+ jit_code_ldxr_c, jit_code_ldxi_c,
+#define jit_ldxr_uc(u,v,w) jit_new_node_www(jit_code_ldxr_uc,u,v,w)
+#define jit_ldxi_uc(u,v,w) jit_new_node_www(jit_code_ldxi_uc,u,v,w)
+ jit_code_ldxr_uc, jit_code_ldxi_uc,
+#define jit_ldxr_s(u,v,w) jit_new_node_www(jit_code_ldxr_s,u,v,w)
+#define jit_ldxi_s(u,v,w) jit_new_node_www(jit_code_ldxi_s,u,v,w)
+ jit_code_ldxr_s, jit_code_ldxi_s,
+#define jit_ldxr_us(u,v,w) jit_new_node_www(jit_code_ldxr_us,u,v,w)
+#define jit_ldxi_us(u,v,w) jit_new_node_www(jit_code_ldxi_us,u,v,w)
+ jit_code_ldxr_us, jit_code_ldxi_us,
+#define jit_ldxr_i(u,v,w) jit_new_node_www(jit_code_ldxr_i,u,v,w)
+#define jit_ldxi_i(u,v,w) jit_new_node_www(jit_code_ldxi_i,u,v,w)
+ jit_code_ldxr_i, jit_code_ldxi_i,
+#if __WORDSIZE == 32
+# define jit_ldxr(u,v,w) jit_ldxr_i(u,v,w)
+# define jit_ldxi(u,v,w) jit_ldxi_i(u,v,w)
+#else
+# define jit_ldxr_ui(u,v,w) jit_new_node_www(jit_code_ldxr_ui,u,v,w)
+# define jit_ldxi_ui(u,v,w) jit_new_node_www(jit_code_ldxi_ui,u,v,w)
+# define jit_ldxr_l(u,v,w) jit_new_node_www(jit_code_ldxr_l,u,v,w)
+# define jit_ldxi_l(u,v,w) jit_new_node_www(jit_code_ldxi_l,u,v,w)
+# define jit_ldxr(u,v,w) jit_ldxr_l(u,v,w)
+# define jit_ldxi(u,v,w) jit_ldxi_l(u,v,w)
+#endif
+ jit_code_ldxr_ui, jit_code_ldxi_ui,
+ jit_code_ldxr_l, jit_code_ldxi_l,
+
+#define jit_str_c(u,v) jit_new_node_ww(jit_code_str_c,u,v)
+#define jit_sti_c(u,v) jit_new_node_pw(jit_code_sti_c,u,v)
+ jit_code_str_c, jit_code_sti_c,
+#define jit_str_s(u,v) jit_new_node_ww(jit_code_str_s,u,v)
+#define jit_sti_s(u,v) jit_new_node_pw(jit_code_sti_s,u,v)
+ jit_code_str_s, jit_code_sti_s,
+#define jit_str_i(u,v) jit_new_node_ww(jit_code_str_i,u,v)
+#define jit_sti_i(u,v) jit_new_node_pw(jit_code_sti_i,u,v)
+ jit_code_str_i, jit_code_sti_i,
+#if __WORDSIZE == 32
+# define jit_str(u,v) jit_str_i(u,v)
+# define jit_sti(u,v) jit_sti_i(u,v)
+#else
+# define jit_str(u,v) jit_str_l(u,v)
+# define jit_sti(u,v) jit_sti_l(u,v)
+# define jit_str_l(u,v) jit_new_node_ww(jit_code_str_l,u,v)
+# define jit_sti_l(u,v) jit_new_node_pw(jit_code_sti_l,u,v)
+#endif
+ jit_code_str_l, jit_code_sti_l,
+
+#define jit_stxr_c(u,v,w) jit_new_node_www(jit_code_stxr_c,u,v,w)
+#define jit_stxi_c(u,v,w) jit_new_node_www(jit_code_stxi_c,u,v,w)
+ jit_code_stxr_c, jit_code_stxi_c,
+#define jit_stxr_s(u,v,w) jit_new_node_www(jit_code_stxr_s,u,v,w)
+#define jit_stxi_s(u,v,w) jit_new_node_www(jit_code_stxi_s,u,v,w)
+ jit_code_stxr_s, jit_code_stxi_s,
+#define jit_stxr_i(u,v,w) jit_new_node_www(jit_code_stxr_i,u,v,w)
+#define jit_stxi_i(u,v,w) jit_new_node_www(jit_code_stxi_i,u,v,w)
+ jit_code_stxr_i, jit_code_stxi_i,
+#if __WORDSIZE == 32
+# define jit_stxr(u,v,w) jit_stxr_i(u,v,w)
+# define jit_stxi(u,v,w) jit_stxi_i(u,v,w)
+#else
+# define jit_stxr(u,v,w) jit_stxr_l(u,v,w)
+# define jit_stxi(u,v,w) jit_stxi_l(u,v,w)
+# define jit_stxr_l(u,v,w) jit_new_node_www(jit_code_stxr_l,u,v,w)
+# define jit_stxi_l(u,v,w) jit_new_node_www(jit_code_stxi_l,u,v,w)
+#endif
+ jit_code_stxr_l, jit_code_stxi_l,
+
+#define jit_bltr(v,w) jit_new_node_pww(jit_code_bltr,NULL,v,w)
+#define jit_blti(v,w) jit_new_node_pww(jit_code_blti,NULL,v,w)
+ jit_code_bltr, jit_code_blti,
+#define jit_bltr_u(v,w) jit_new_node_pww(jit_code_bltr_u,NULL,v,w)
+#define jit_blti_u(v,w) jit_new_node_pww(jit_code_blti_u,NULL,v,w)
+ jit_code_bltr_u, jit_code_blti_u,
+#define jit_bler(v,w) jit_new_node_pww(jit_code_bler,NULL,v,w)
+#define jit_blei(v,w) jit_new_node_pww(jit_code_blei,NULL,v,w)
+ jit_code_bler, jit_code_blei,
+#define jit_bler_u(v,w) jit_new_node_pww(jit_code_bler_u,NULL,v,w)
+#define jit_blei_u(v,w) jit_new_node_pww(jit_code_blei_u,NULL,v,w)
+ jit_code_bler_u, jit_code_blei_u,
+#define jit_beqr(v,w) jit_new_node_pww(jit_code_beqr,NULL,v,w)
+#define jit_beqi(v,w) jit_new_node_pww(jit_code_beqi,NULL,v,w)
+ jit_code_beqr, jit_code_beqi,
+#define jit_bger(v,w) jit_new_node_pww(jit_code_bger,NULL,v,w)
+#define jit_bgei(v,w) jit_new_node_pww(jit_code_bgei,NULL,v,w)
+ jit_code_bger, jit_code_bgei,
+#define jit_bger_u(v,w) jit_new_node_pww(jit_code_bger_u,NULL,v,w)
+#define jit_bgei_u(v,w) jit_new_node_pww(jit_code_bgei_u,NULL,v,w)
+ jit_code_bger_u, jit_code_bgei_u,
+#define jit_bgtr(v,w) jit_new_node_pww(jit_code_bgtr,NULL,v,w)
+#define jit_bgti(v,w) jit_new_node_pww(jit_code_bgti,NULL,v,w)
+ jit_code_bgtr, jit_code_bgti,
+#define jit_bgtr_u(v,w) jit_new_node_pww(jit_code_bgtr_u,NULL,v,w)
+#define jit_bgti_u(v,w) jit_new_node_pww(jit_code_bgti_u,NULL,v,w)
+ jit_code_bgtr_u, jit_code_bgti_u,
+#define jit_bner(v,w) jit_new_node_pww(jit_code_bner,NULL,v,w)
+#define jit_bnei(v,w) jit_new_node_pww(jit_code_bnei,NULL,v,w)
+ jit_code_bner, jit_code_bnei,
+
+#define jit_bmsr(v,w) jit_new_node_pww(jit_code_bmsr,NULL,v,w)
+#define jit_bmsi(v,w) jit_new_node_pww(jit_code_bmsi,NULL,v,w)
+ jit_code_bmsr, jit_code_bmsi,
+#define jit_bmcr(v,w) jit_new_node_pww(jit_code_bmcr,NULL,v,w)
+#define jit_bmci(v,w) jit_new_node_pww(jit_code_bmci,NULL,v,w)
+ jit_code_bmcr, jit_code_bmci,
+
+#define jit_boaddr(v,w) jit_new_node_pww(jit_code_boaddr,NULL,v,w)
+#define jit_boaddi(v,w) jit_new_node_pww(jit_code_boaddi,NULL,v,w)
+ jit_code_boaddr, jit_code_boaddi,
+#define jit_boaddr_u(v,w) jit_new_node_pww(jit_code_boaddr_u,NULL,v,w)
+#define jit_boaddi_u(v,w) jit_new_node_pww(jit_code_boaddi_u,NULL,v,w)
+ jit_code_boaddr_u, jit_code_boaddi_u,
+#define jit_bxaddr(v,w) jit_new_node_pww(jit_code_bxaddr,NULL,v,w)
+#define jit_bxaddi(v,w) jit_new_node_pww(jit_code_bxaddi,NULL,v,w)
+ jit_code_bxaddr, jit_code_bxaddi,
+#define jit_bxaddr_u(v,w) jit_new_node_pww(jit_code_bxaddr_u,NULL,v,w)
+#define jit_bxaddi_u(v,w) jit_new_node_pww(jit_code_bxaddi_u,NULL,v,w)
+ jit_code_bxaddr_u, jit_code_bxaddi_u,
+#define jit_bosubr(v,w) jit_new_node_pww(jit_code_bosubr,NULL,v,w)
+#define jit_bosubi(v,w) jit_new_node_pww(jit_code_bosubi,NULL,v,w)
+ jit_code_bosubr, jit_code_bosubi,
+#define jit_bosubr_u(v,w) jit_new_node_pww(jit_code_bosubr_u,NULL,v,w)
+#define jit_bosubi_u(v,w) jit_new_node_pww(jit_code_bosubi_u,NULL,v,w)
+ jit_code_bosubr_u, jit_code_bosubi_u,
+#define jit_bxsubr(v,w) jit_new_node_pww(jit_code_bxsubr,NULL,v,w)
+#define jit_bxsubi(v,w) jit_new_node_pww(jit_code_bxsubi,NULL,v,w)
+ jit_code_bxsubr, jit_code_bxsubi,
+#define jit_bxsubr_u(v,w) jit_new_node_pww(jit_code_bxsubr_u,NULL,v,w)
+#define jit_bxsubi_u(v,w) jit_new_node_pww(jit_code_bxsubi_u,NULL,v,w)
+ jit_code_bxsubr_u, jit_code_bxsubi_u,
+
+#define jit_jmpr(u) jit_new_node_w(jit_code_jmpr,u)
+#define jit_jmpi() jit_new_node_p(jit_code_jmpi,NULL)
+ jit_code_jmpr, jit_code_jmpi,
+#define jit_callr(u) jit_new_node_w(jit_code_callr,u)
+#define jit_calli(u) jit_new_node_p(jit_code_calli,u)
+ jit_code_callr, jit_code_calli,
+
+#define jit_prepare() _jit_prepare(_jit)
+ jit_code_prepare,
+
+#define jit_pushargr_c(u) _jit_pushargr(_jit,u,jit_code_pushargr_c)
+#define jit_pushargi_c(u) _jit_pushargi(_jit,u,jit_code_pushargi_c)
+#define jit_pushargr_uc(u) _jit_pushargr(_jit,u,jit_code_pushargr_uc)
+#define jit_pushargi_uc(u) _jit_pushargi(_jit,u,jit_code_pushargi_uc)
+#define jit_pushargr_s(u) _jit_pushargr(_jit,u,jit_code_pushargr_s)
+#define jit_pushargi_s(u) _jit_pushargi(_jit,u,jit_code_pushargi_s)
+#define jit_pushargr_us(u) _jit_pushargr(_jit,u,jit_code_pushargr_us)
+#define jit_pushargi_us(u) _jit_pushargi(_jit,u,jit_code_pushargi_us)
+#define jit_pushargr_i(u) _jit_pushargr(_jit,u,jit_code_pushargr_i)
+#define jit_pushargi_i(u) _jit_pushargi(_jit,u,jit_code_pushargi_i)
+#if __WORDSIZE == 32
+# define jit_pushargr(u) jit_pushargr_i(u)
+# define jit_pushargi(u) jit_pushargi_i(u)
+#else
+# define jit_pushargr_ui(u) _jit_pushargr(_jit,u,jit_code_pushargr_ui)
+# define jit_pushargi_ui(u) _jit_pushargi(_jit,u,jit_code_pushargi_ui)
+# define jit_pushargr_l(u) _jit_pushargr(_jit,u,jit_code_pushargr_l)
+# define jit_pushargi_l(u) _jit_pushargi(_jit,u,jit_code_pushargi_l)
+# define jit_pushargr(u) jit_pushargr_l(u)
+# define jit_pushargi(u) jit_pushargi_l(u)
+#endif
+ jit_code_pushargr_c, jit_code_pushargi_c,
+ jit_code_pushargr_uc, jit_code_pushargi_uc,
+ jit_code_pushargr_s, jit_code_pushargi_s,
+ jit_code_pushargr_us, jit_code_pushargi_us,
+ jit_code_pushargr_i, jit_code_pushargi_i,
+ jit_code_pushargr_ui, jit_code_pushargi_ui,
+ jit_code_pushargr_l, jit_code_pushargi_l,
+#if __WORDSIZE == 32
+# define jit_code_pushargr jit_code_pushargr_i
+# define jit_code_pushargi jit_code_pushargi_i
+#else
+# define jit_code_pushargr jit_code_pushargr_l
+# define jit_code_pushargi jit_code_pushargi_l
+#endif
+
+#define jit_finishr(u) _jit_finishr(_jit,u)
+#define jit_finishi(u) _jit_finishi(_jit,u)
+ jit_code_finishr, jit_code_finishi,
+#define jit_ret() _jit_ret(_jit)
+ jit_code_ret,
+
+#define jit_retr_c(u) _jit_retr(_jit,u,jit_code_retr_c)
+#define jit_reti_c(u) _jit_reti(_jit,u,jit_code_reti_c)
+#define jit_retr_uc(u) _jit_retr(_jit,u,jit_code_retr_uc)
+#define jit_reti_uc(u) _jit_reti(_jit,u,jit_code_reti_uc)
+#define jit_retr_s(u) _jit_retr(_jit,u,jit_code_retr_s)
+#define jit_reti_s(u) _jit_reti(_jit,u,jit_code_reti_s)
+#define jit_retr_us(u) _jit_retr(_jit,u,jit_code_retr_us)
+#define jit_reti_us(u) _jit_reti(_jit,u,jit_code_reti_us)
+#define jit_retr_i(u) _jit_retr(_jit,u,jit_code_retr_i)
+#define jit_reti_i(u) _jit_reti(_jit,u,jit_code_reti_i)
+#if __WORDSIZE == 32
+# define jit_retr(u) jit_retr_i(u)
+# define jit_reti(u) jit_reti_i(u)
+#else
+# define jit_retr_ui(u) _jit_retr(_jit,u,jit_code_retr_ui)
+# define jit_reti_ui(u) _jit_reti(_jit,u,jit_code_reti_ui)
+# define jit_retr_l(u) _jit_retr(_jit,u,jit_code_retr_l)
+# define jit_reti_l(u) _jit_reti(_jit,u,jit_code_reti_l)
+# define jit_retr(u) jit_retr_l(u)
+# define jit_reti(u) jit_reti_l(u)
+#endif
+ jit_code_retr_c, jit_code_reti_c,
+ jit_code_retr_uc, jit_code_reti_uc,
+ jit_code_retr_s, jit_code_reti_s,
+ jit_code_retr_us, jit_code_reti_us,
+ jit_code_retr_i, jit_code_reti_i,
+ jit_code_retr_ui, jit_code_reti_ui,
+ jit_code_retr_l, jit_code_reti_l,
+#if __WORDSIZE == 32
+# define jit_code_retr jit_code_retr_i
+# define jit_code_reti jit_code_reti_i
+#else
+# define jit_code_retr jit_code_retr_l
+# define jit_code_reti jit_code_reti_l
+#endif
+
+#define jit_retval_c(u) _jit_retval_c(_jit,u)
+#define jit_retval_uc(u) _jit_retval_uc(_jit,u)
+#define jit_retval_s(u) _jit_retval_s(_jit,u)
+#define jit_retval_us(u) _jit_retval_us(_jit,u)
+#define jit_retval_i(u) _jit_retval_i(_jit,u)
+#if __WORDSIZE == 32
+# define jit_retval(u) jit_retval_i(u)
+#else
+# define jit_retval_ui(u) _jit_retval_ui(_jit,u)
+# define jit_retval_l(u) _jit_retval_l(_jit,u)
+# define jit_retval(u) jit_retval_l(u)
+#endif
+ jit_code_retval_c, jit_code_retval_uc,
+ jit_code_retval_s, jit_code_retval_us,
+ jit_code_retval_i, jit_code_retval_ui,
+ jit_code_retval_l,
+#if __WORDSIZE == 32
+# define jit_code_retval jit_code_retval_i
+#else
+# define jit_code_retval jit_code_retval_l
+#endif
+
+#define jit_epilog() _jit_epilog(_jit)
+ jit_code_epilog,
+
+#define jit_arg_f() _jit_arg_f(_jit)
+ jit_code_arg_f,
+#define jit_getarg_f(u,v) _jit_getarg_f(_jit,u,v)
+ jit_code_getarg_f,
+#define jit_putargr_f(u,v) _jit_putargr_f(_jit,u,v)
+#define jit_putargi_f(u,v) _jit_putargi_f(_jit,u,v)
+ jit_code_putargr_f, jit_code_putargi_f,
+
+#define jit_addr_f(u,v,w) jit_new_node_www(jit_code_addr_f,u,v,w)
+#define jit_addi_f(u,v,w) jit_new_node_wwf(jit_code_addi_f,u,v,w)
+ jit_code_addr_f, jit_code_addi_f,
+#define jit_subr_f(u,v,w) jit_new_node_www(jit_code_subr_f,u,v,w)
+#define jit_subi_f(u,v,w) jit_new_node_wwf(jit_code_subi_f,u,v,w)
+ jit_code_subr_f, jit_code_subi_f,
+#define jit_rsbr_f(u,v,w) jit_subr_f(u,w,v)
+#define jit_rsbi_f(u,v,w) jit_new_node_wwf(jit_code_rsbi_f,u,v,w)
+ jit_code_rsbi_f,
+#define jit_mulr_f(u,v,w) jit_new_node_www(jit_code_mulr_f,u,v,w)
+#define jit_muli_f(u,v,w) jit_new_node_wwf(jit_code_muli_f,u,v,w)
+ jit_code_mulr_f, jit_code_muli_f,
+#define jit_divr_f(u,v,w) jit_new_node_www(jit_code_divr_f,u,v,w)
+#define jit_divi_f(u,v,w) jit_new_node_wwf(jit_code_divi_f,u,v,w)
+ jit_code_divr_f, jit_code_divi_f,
+
+#define jit_negr_f(u,v) jit_new_node_ww(jit_code_negr_f,u,v)
+#define jit_negi_f(u,v) _jit_negi_f(_jit,u,v)
+ jit_code_negr_f, jit_code_negi_f,
+#define jit_absr_f(u,v) jit_new_node_ww(jit_code_absr_f,u,v)
+#define jit_absi_f(u,v) _jit_absi_f(_jit,u,v)
+ jit_code_absr_f, jit_code_absi_f,
+#define jit_sqrtr_f(u,v) jit_new_node_ww(jit_code_sqrtr_f,u,v)
+#define jit_sqrti_f(u,v) _jit_sqrti_f(_jit,u,v)
+ jit_code_sqrtr_f, jit_code_sqrti_f,
+
+#define jit_ltr_f(u,v,w) jit_new_node_www(jit_code_ltr_f,u,v,w)
+#define jit_lti_f(u,v,w) jit_new_node_wwf(jit_code_lti_f,u,v,w)
+ jit_code_ltr_f, jit_code_lti_f,
+#define jit_ler_f(u,v,w) jit_new_node_www(jit_code_ler_f,u,v,w)
+#define jit_lei_f(u,v,w) jit_new_node_wwf(jit_code_lei_f,u,v,w)
+ jit_code_ler_f, jit_code_lei_f,
+#define jit_eqr_f(u,v,w) jit_new_node_www(jit_code_eqr_f,u,v,w)
+#define jit_eqi_f(u,v,w) jit_new_node_wwf(jit_code_eqi_f,u,v,w)
+ jit_code_eqr_f, jit_code_eqi_f,
+#define jit_ger_f(u,v,w) jit_new_node_www(jit_code_ger_f,u,v,w)
+#define jit_gei_f(u,v,w) jit_new_node_wwf(jit_code_gei_f,u,v,w)
+ jit_code_ger_f, jit_code_gei_f,
+#define jit_gtr_f(u,v,w) jit_new_node_www(jit_code_gtr_f,u,v,w)
+#define jit_gti_f(u,v,w) jit_new_node_wwf(jit_code_gti_f,u,v,w)
+ jit_code_gtr_f, jit_code_gti_f,
+#define jit_ner_f(u,v,w) jit_new_node_www(jit_code_ner_f,u,v,w)
+#define jit_nei_f(u,v,w) jit_new_node_wwf(jit_code_nei_f,u,v,w)
+ jit_code_ner_f, jit_code_nei_f,
+#define jit_unltr_f(u,v,w) jit_new_node_www(jit_code_unltr_f,u,v,w)
+#define jit_unlti_f(u,v,w) jit_new_node_wwf(jit_code_unlti_f,u,v,w)
+ jit_code_unltr_f, jit_code_unlti_f,
+#define jit_unler_f(u,v,w) jit_new_node_www(jit_code_unler_f,u,v,w)
+#define jit_unlei_f(u,v,w) jit_new_node_wwf(jit_code_unlei_f,u,v,w)
+ jit_code_unler_f, jit_code_unlei_f,
+#define jit_uneqr_f(u,v,w) jit_new_node_www(jit_code_uneqr_f,u,v,w)
+#define jit_uneqi_f(u,v,w) jit_new_node_wwf(jit_code_uneqi_f,u,v,w)
+ jit_code_uneqr_f, jit_code_uneqi_f,
+#define jit_unger_f(u,v,w) jit_new_node_www(jit_code_unger_f,u,v,w)
+#define jit_ungei_f(u,v,w) jit_new_node_wwf(jit_code_ungei_f,u,v,w)
+ jit_code_unger_f, jit_code_ungei_f,
+#define jit_ungtr_f(u,v,w) jit_new_node_www(jit_code_ungtr_f,u,v,w)
+#define jit_ungti_f(u,v,w) jit_new_node_wwf(jit_code_ungti_f,u,v,w)
+ jit_code_ungtr_f, jit_code_ungti_f,
+#define jit_ltgtr_f(u,v,w) jit_new_node_www(jit_code_ltgtr_f,u,v,w)
+#define jit_ltgti_f(u,v,w) jit_new_node_wwf(jit_code_ltgti_f,u,v,w)
+ jit_code_ltgtr_f, jit_code_ltgti_f,
+#define jit_ordr_f(u,v,w) jit_new_node_www(jit_code_ordr_f,u,v,w)
+#define jit_ordi_f(u,v,w) jit_new_node_wwf(jit_code_ordi_f,u,v,w)
+ jit_code_ordr_f, jit_code_ordi_f,
+#define jit_unordr_f(u,v,w) jit_new_node_www(jit_code_unordr_f,u,v,w)
+#define jit_unordi_f(u,v,w) jit_new_node_wwf(jit_code_unordi_f,u,v,w)
+ jit_code_unordr_f, jit_code_unordi_f,
+
+#define jit_truncr_f_i(u,v) jit_new_node_ww(jit_code_truncr_f_i,u,v)
+ jit_code_truncr_f_i,
+#if __WORDSIZE == 32
+# define jit_truncr_f(u,v) jit_truncr_f_i(u,v)
+#else
+# define jit_truncr_f(u,v) jit_truncr_f_l(u,v)
+# define jit_truncr_f_l(u,v) jit_new_node_ww(jit_code_truncr_f_l,u,v)
+#endif
+ jit_code_truncr_f_l,
+#define jit_extr_f(u,v) jit_new_node_ww(jit_code_extr_f,u,v)
+#define jit_extr_d_f(u,v) jit_new_node_ww(jit_code_extr_d_f,u,v)
+ jit_code_extr_f, jit_code_extr_d_f,
+#define jit_movr_f(u,v) jit_new_node_ww(jit_code_movr_f,u,v)
+#define jit_movi_f(u,v) jit_new_node_wf(jit_code_movi_f,u,v)
+ jit_code_movr_f, jit_code_movi_f,
+
+#define jit_ldr_f(u,v) jit_new_node_ww(jit_code_ldr_f,u,v)
+#define jit_ldi_f(u,v) jit_new_node_wp(jit_code_ldi_f,u,v)
+ jit_code_ldr_f, jit_code_ldi_f,
+#define jit_ldxr_f(u,v,w) jit_new_node_www(jit_code_ldxr_f,u,v,w)
+#define jit_ldxi_f(u,v,w) jit_new_node_www(jit_code_ldxi_f,u,v,w)
+ jit_code_ldxr_f, jit_code_ldxi_f,
+#define jit_str_f(u,v) jit_new_node_ww(jit_code_str_f,u,v)
+#define jit_sti_f(u,v) jit_new_node_pw(jit_code_sti_f,u,v)
+ jit_code_str_f, jit_code_sti_f,
+#define jit_stxr_f(u,v,w) jit_new_node_www(jit_code_stxr_f,u,v,w)
+#define jit_stxi_f(u,v,w) jit_new_node_www(jit_code_stxi_f,u,v,w)
+ jit_code_stxr_f, jit_code_stxi_f,
+
+#define jit_bltr_f(v,w) jit_new_node_pww(jit_code_bltr_f,NULL,v,w)
+#define jit_blti_f(v,w) jit_new_node_pwf(jit_code_blti_f,NULL,v,w)
+ jit_code_bltr_f, jit_code_blti_f,
+#define jit_bler_f(v,w) jit_new_node_pww(jit_code_bler_f,NULL,v,w)
+#define jit_blei_f(v,w) jit_new_node_pwf(jit_code_blei_f,NULL,v,w)
+ jit_code_bler_f, jit_code_blei_f,
+#define jit_beqr_f(v,w) jit_new_node_pww(jit_code_beqr_f,NULL,v,w)
+#define jit_beqi_f(v,w) jit_new_node_pwf(jit_code_beqi_f,NULL,v,w)
+ jit_code_beqr_f, jit_code_beqi_f,
+#define jit_bger_f(v,w) jit_new_node_pww(jit_code_bger_f,NULL,v,w)
+#define jit_bgei_f(v,w) jit_new_node_pwf(jit_code_bgei_f,NULL,v,w)
+ jit_code_bger_f, jit_code_bgei_f,
+#define jit_bgtr_f(v,w) jit_new_node_pww(jit_code_bgtr_f,NULL,v,w)
+#define jit_bgti_f(v,w) jit_new_node_pwf(jit_code_bgti_f,NULL,v,w)
+ jit_code_bgtr_f, jit_code_bgti_f,
+#define jit_bner_f(v,w) jit_new_node_pww(jit_code_bner_f,NULL,v,w)
+#define jit_bnei_f(v,w) jit_new_node_pwf(jit_code_bnei_f,NULL,v,w)
+ jit_code_bner_f, jit_code_bnei_f,
+#define jit_bunltr_f(v,w) jit_new_node_pww(jit_code_bunltr_f,NULL,v,w)
+#define jit_bunlti_f(v,w) jit_new_node_pwf(jit_code_bunlti_f,NULL,v,w)
+ jit_code_bunltr_f, jit_code_bunlti_f,
+#define jit_bunler_f(v,w) jit_new_node_pww(jit_code_bunler_f,NULL,v,w)
+#define jit_bunlei_f(v,w) jit_new_node_pwf(jit_code_bunlei_f,NULL,v,w)
+ jit_code_bunler_f, jit_code_bunlei_f,
+#define jit_buneqr_f(v,w) jit_new_node_pww(jit_code_buneqr_f,NULL,v,w)
+#define jit_buneqi_f(v,w) jit_new_node_pwf(jit_code_buneqi_f,NULL,v,w)
+ jit_code_buneqr_f, jit_code_buneqi_f,
+#define jit_bunger_f(v,w) jit_new_node_pww(jit_code_bunger_f,NULL,v,w)
+#define jit_bungei_f(v,w) jit_new_node_pwf(jit_code_bungei_f,NULL,v,w)
+ jit_code_bunger_f, jit_code_bungei_f,
+#define jit_bungtr_f(v,w) jit_new_node_pww(jit_code_bungtr_f,NULL,v,w)
+#define jit_bungti_f(v,w) jit_new_node_pwf(jit_code_bungti_f,NULL,v,w)
+ jit_code_bungtr_f, jit_code_bungti_f,
+#define jit_bltgtr_f(v,w) jit_new_node_pww(jit_code_bltgtr_f,NULL,v,w)
+#define jit_bltgti_f(v,w) jit_new_node_pwf(jit_code_bltgti_f,NULL,v,w)
+ jit_code_bltgtr_f, jit_code_bltgti_f,
+#define jit_bordr_f(v,w) jit_new_node_pww(jit_code_bordr_f,NULL,v,w)
+#define jit_bordi_f(v,w) jit_new_node_pwf(jit_code_bordi_f,NULL,v,w)
+ jit_code_bordr_f, jit_code_bordi_f,
+#define jit_bunordr_f(v,w) jit_new_node_pww(jit_code_bunordr_f,NULL,v,w)
+#define jit_bunordi_f(v,w) jit_new_node_pwf(jit_code_bunordi_f,NULL,v,w)
+ jit_code_bunordr_f, jit_code_bunordi_f,
+
+#define jit_pushargr_f(u) _jit_pushargr_f(_jit,u)
+#define jit_pushargi_f(u) _jit_pushargi_f(_jit,u)
+ jit_code_pushargr_f, jit_code_pushargi_f,
+#define jit_retr_f(u) _jit_retr_f(_jit,u)
+#define jit_reti_f(u) _jit_reti_f(_jit,u)
+ jit_code_retr_f, jit_code_reti_f,
+#define jit_retval_f(u) _jit_retval_f(_jit,u)
+ jit_code_retval_f,
+
+#define jit_arg_d() _jit_arg_d(_jit)
+ jit_code_arg_d,
+#define jit_getarg_d(u,v) _jit_getarg_d(_jit,u,v)
+ jit_code_getarg_d,
+#define jit_putargr_d(u,v) _jit_putargr_d(_jit,u,v)
+#define jit_putargi_d(u,v) _jit_putargi_d(_jit,u,v)
+ jit_code_putargr_d, jit_code_putargi_d,
+
+#define jit_addr_d(u,v,w) jit_new_node_www(jit_code_addr_d,u,v,w)
+#define jit_addi_d(u,v,w) jit_new_node_wwd(jit_code_addi_d,u,v,w)
+ jit_code_addr_d, jit_code_addi_d,
+#define jit_subr_d(u,v,w) jit_new_node_www(jit_code_subr_d,u,v,w)
+#define jit_subi_d(u,v,w) jit_new_node_wwd(jit_code_subi_d,u,v,w)
+ jit_code_subr_d, jit_code_subi_d,
+#define jit_rsbr_d(u,v,w) jit_subr_d(u,w,v)
+#define jit_rsbi_d(u,v,w) jit_new_node_wwd(jit_code_rsbi_d,u,v,w)
+ jit_code_rsbi_d,
+#define jit_mulr_d(u,v,w) jit_new_node_www(jit_code_mulr_d,u,v,w)
+#define jit_muli_d(u,v,w) jit_new_node_wwd(jit_code_muli_d,u,v,w)
+ jit_code_mulr_d, jit_code_muli_d,
+#define jit_divr_d(u,v,w) jit_new_node_www(jit_code_divr_d,u,v,w)
+#define jit_divi_d(u,v,w) jit_new_node_wwd(jit_code_divi_d,u,v,w)
+ jit_code_divr_d, jit_code_divi_d,
+
+#define jit_negr_d(u,v) jit_new_node_ww(jit_code_negr_d,u,v)
+#define jit_negi_d(u,v) _jit_negi_d(_jit,u,v)
+ jit_code_negr_d, jit_code_negi_d,
+#define jit_absr_d(u,v) jit_new_node_ww(jit_code_absr_d,u,v)
+#define jit_absi_d(u,v) _jit_absi_d(_jit,u,v)
+ jit_code_absr_d, jit_code_absi_d,
+#define jit_sqrtr_d(u,v) jit_new_node_ww(jit_code_sqrtr_d,u,v)
+#define jit_sqrti_d(u,v) _jit_sqrti_d(_jit,u,v)
+ jit_code_sqrtr_d, jit_code_sqrti_d,
+
+#define jit_ltr_d(u,v,w) jit_new_node_www(jit_code_ltr_d,u,v,w)
+#define jit_lti_d(u,v,w) jit_new_node_wwd(jit_code_lti_d,u,v,w)
+ jit_code_ltr_d, jit_code_lti_d,
+#define jit_ler_d(u,v,w) jit_new_node_www(jit_code_ler_d,u,v,w)
+#define jit_lei_d(u,v,w) jit_new_node_wwd(jit_code_lei_d,u,v,w)
+ jit_code_ler_d, jit_code_lei_d,
+#define jit_eqr_d(u,v,w) jit_new_node_www(jit_code_eqr_d,u,v,w)
+#define jit_eqi_d(u,v,w) jit_new_node_wwd(jit_code_eqi_d,u,v,w)
+ jit_code_eqr_d, jit_code_eqi_d,
+#define jit_ger_d(u,v,w) jit_new_node_www(jit_code_ger_d,u,v,w)
+#define jit_gei_d(u,v,w) jit_new_node_wwd(jit_code_gei_d,u,v,w)
+ jit_code_ger_d, jit_code_gei_d,
+#define jit_gtr_d(u,v,w) jit_new_node_www(jit_code_gtr_d,u,v,w)
+#define jit_gti_d(u,v,w) jit_new_node_wwd(jit_code_gti_d,u,v,w)
+ jit_code_gtr_d, jit_code_gti_d,
+#define jit_ner_d(u,v,w) jit_new_node_www(jit_code_ner_d,u,v,w)
+#define jit_nei_d(u,v,w) jit_new_node_wwd(jit_code_nei_d,u,v,w)
+ jit_code_ner_d, jit_code_nei_d,
+#define jit_unltr_d(u,v,w) jit_new_node_www(jit_code_unltr_d,u,v,w)
+#define jit_unlti_d(u,v,w) jit_new_node_wwd(jit_code_unlti_d,u,v,w)
+ jit_code_unltr_d, jit_code_unlti_d,
+#define jit_unler_d(u,v,w) jit_new_node_www(jit_code_unler_d,u,v,w)
+#define jit_unlei_d(u,v,w) jit_new_node_wwd(jit_code_unlei_d,u,v,w)
+ jit_code_unler_d, jit_code_unlei_d,
+#define jit_uneqr_d(u,v,w) jit_new_node_www(jit_code_uneqr_d,u,v,w)
+#define jit_uneqi_d(u,v,w) jit_new_node_wwd(jit_code_uneqi_d,u,v,w)
+ jit_code_uneqr_d, jit_code_uneqi_d,
+#define jit_unger_d(u,v,w) jit_new_node_www(jit_code_unger_d,u,v,w)
+#define jit_ungei_d(u,v,w) jit_new_node_wwd(jit_code_ungei_d,u,v,w)
+ jit_code_unger_d, jit_code_ungei_d,
+#define jit_ungtr_d(u,v,w) jit_new_node_www(jit_code_ungtr_d,u,v,w)
+#define jit_ungti_d(u,v,w) jit_new_node_wwd(jit_code_ungti_d,u,v,w)
+ jit_code_ungtr_d, jit_code_ungti_d,
+#define jit_ltgtr_d(u,v,w) jit_new_node_www(jit_code_ltgtr_d,u,v,w)
+#define jit_ltgti_d(u,v,w) jit_new_node_wwd(jit_code_ltgti_d,u,v,w)
+ jit_code_ltgtr_d, jit_code_ltgti_d,
+#define jit_ordr_d(u,v,w) jit_new_node_www(jit_code_ordr_d,u,v,w)
+#define jit_ordi_d(u,v,w) jit_new_node_wwd(jit_code_ordi_d,u,v,w)
+ jit_code_ordr_d, jit_code_ordi_d,
+#define jit_unordr_d(u,v,w) jit_new_node_www(jit_code_unordr_d,u,v,w)
+#define jit_unordi_d(u,v,w) jit_new_node_wwd(jit_code_unordi_d,u,v,w)
+ jit_code_unordr_d, jit_code_unordi_d,
+
+#define jit_truncr_d_i(u,v) jit_new_node_ww(jit_code_truncr_d_i,u,v)
+ jit_code_truncr_d_i,
+#if __WORDSIZE == 32
+# define jit_truncr_d(u,v) jit_truncr_d_i(u,v)
+#else
+# define jit_truncr_d(u,v) jit_truncr_d_l(u,v)
+# define jit_truncr_d_l(u,v) jit_new_node_ww(jit_code_truncr_d_l,u,v)
+#endif
+ jit_code_truncr_d_l,
+#define jit_extr_d(u,v) jit_new_node_ww(jit_code_extr_d,u,v)
+#define jit_extr_f_d(u,v) jit_new_node_ww(jit_code_extr_f_d,u,v)
+ jit_code_extr_d, jit_code_extr_f_d,
+#define jit_movr_d(u,v) jit_new_node_ww(jit_code_movr_d,u,v)
+#define jit_movi_d(u,v) jit_new_node_wd(jit_code_movi_d,u,v)
+ jit_code_movr_d, jit_code_movi_d,
+
+#define jit_ldr_d(u,v) jit_new_node_ww(jit_code_ldr_d,u,v)
+#define jit_ldi_d(u,v) jit_new_node_wp(jit_code_ldi_d,u,v)
+ jit_code_ldr_d, jit_code_ldi_d,
+#define jit_ldxr_d(u,v,w) jit_new_node_www(jit_code_ldxr_d,u,v,w)
+#define jit_ldxi_d(u,v,w) jit_new_node_www(jit_code_ldxi_d,u,v,w)
+ jit_code_ldxr_d, jit_code_ldxi_d,
+#define jit_str_d(u,v) jit_new_node_ww(jit_code_str_d,u,v)
+#define jit_sti_d(u,v) jit_new_node_pw(jit_code_sti_d,u,v)
+ jit_code_str_d, jit_code_sti_d,
+#define jit_stxr_d(u,v,w) jit_new_node_www(jit_code_stxr_d,u,v,w)
+#define jit_stxi_d(u,v,w) jit_new_node_www(jit_code_stxi_d,u,v,w)
+ jit_code_stxr_d, jit_code_stxi_d,
+
+#define jit_bltr_d(v,w) jit_new_node_pww(jit_code_bltr_d,NULL,v,w)
+#define jit_blti_d(v,w) jit_new_node_pwd(jit_code_blti_d,NULL,v,w)
+ jit_code_bltr_d, jit_code_blti_d,
+#define jit_bler_d(v,w) jit_new_node_pww(jit_code_bler_d,NULL,v,w)
+#define jit_blei_d(v,w) jit_new_node_pwd(jit_code_blei_d,NULL,v,w)
+ jit_code_bler_d, jit_code_blei_d,
+#define jit_beqr_d(v,w) jit_new_node_pww(jit_code_beqr_d,NULL,v,w)
+#define jit_beqi_d(v,w) jit_new_node_pwd(jit_code_beqi_d,NULL,v,w)
+ jit_code_beqr_d, jit_code_beqi_d,
+#define jit_bger_d(v,w) jit_new_node_pww(jit_code_bger_d,NULL,v,w)
+#define jit_bgei_d(v,w) jit_new_node_pwd(jit_code_bgei_d,NULL,v,w)
+ jit_code_bger_d, jit_code_bgei_d,
+#define jit_bgtr_d(v,w) jit_new_node_pww(jit_code_bgtr_d,NULL,v,w)
+#define jit_bgti_d(v,w) jit_new_node_pwd(jit_code_bgti_d,NULL,v,w)
+ jit_code_bgtr_d, jit_code_bgti_d,
+#define jit_bner_d(v,w) jit_new_node_pww(jit_code_bner_d,NULL,v,w)
+#define jit_bnei_d(v,w) jit_new_node_pwd(jit_code_bnei_d,NULL,v,w)
+ jit_code_bner_d, jit_code_bnei_d,
+#define jit_bunltr_d(v,w) jit_new_node_pww(jit_code_bunltr_d,NULL,v,w)
+#define jit_bunlti_d(v,w) jit_new_node_pwd(jit_code_bunlti_d,NULL,v,w)
+ jit_code_bunltr_d, jit_code_bunlti_d,
+#define jit_bunler_d(v,w) jit_new_node_pww(jit_code_bunler_d,NULL,v,w)
+#define jit_bunlei_d(v,w) jit_new_node_pwd(jit_code_bunlei_d,NULL,v,w)
+ jit_code_bunler_d, jit_code_bunlei_d,
+#define jit_buneqr_d(v,w) jit_new_node_pww(jit_code_buneqr_d,NULL,v,w)
+#define jit_buneqi_d(v,w) jit_new_node_pwd(jit_code_buneqi_d,NULL,v,w)
+ jit_code_buneqr_d, jit_code_buneqi_d,
+#define jit_bunger_d(v,w) jit_new_node_pww(jit_code_bunger_d,NULL,v,w)
+#define jit_bungei_d(v,w) jit_new_node_pwd(jit_code_bungei_d,NULL,v,w)
+ jit_code_bunger_d, jit_code_bungei_d,
+#define jit_bungtr_d(v,w) jit_new_node_pww(jit_code_bungtr_d,NULL,v,w)
+#define jit_bungti_d(v,w) jit_new_node_pwd(jit_code_bungti_d,NULL,v,w)
+ jit_code_bungtr_d, jit_code_bungti_d,
+#define jit_bltgtr_d(v,w) jit_new_node_pww(jit_code_bltgtr_d,NULL,v,w)
+#define jit_bltgti_d(v,w) jit_new_node_pwd(jit_code_bltgti_d,NULL,v,w)
+ jit_code_bltgtr_d, jit_code_bltgti_d,
+#define jit_bordr_d(v,w) jit_new_node_pww(jit_code_bordr_d,NULL,v,w)
+#define jit_bordi_d(v,w) jit_new_node_pwd(jit_code_bordi_d,NULL,v,w)
+ jit_code_bordr_d, jit_code_bordi_d,
+#define jit_bunordr_d(v,w) jit_new_node_pww(jit_code_bunordr_d,NULL,v,w)
+#define jit_bunordi_d(v,w) jit_new_node_pwd(jit_code_bunordi_d,NULL,v,w)
+ jit_code_bunordr_d, jit_code_bunordi_d,
+
+#define jit_pushargr_d(u) _jit_pushargr_d(_jit,u)
+#define jit_pushargi_d(u) _jit_pushargi_d(_jit,u)
+ jit_code_pushargr_d, jit_code_pushargi_d,
+#define jit_retr_d(u) _jit_retr_d(_jit,u)
+#define jit_reti_d(u) _jit_reti_d(_jit,u)
+ jit_code_retr_d, jit_code_reti_d,
+#define jit_retval_d(u) _jit_retval_d(_jit,u)
+ jit_code_retval_d,
+
+ /* w* -> f|d */
+#define jit_movr_w_f(u, v) jit_new_node_ww(jit_code_movr_w_f, u, v)
+#define jit_movi_w_f(u,v) jit_new_node_ww(jit_code_movi_w_f, u, v)
+ jit_code_movr_w_f, jit_code_movi_w_f,
+#define jit_movr_ww_d(u, v, w) jit_new_node_www(jit_code_movr_ww_d, u, v, w)
+#define jit_movi_ww_d(u,v, w) jit_new_node_www(jit_code_movi_ww_d, u, v, w)
+ jit_code_movr_ww_d, jit_code_movi_ww_d,
+
+ /* w -> d */
+#define jit_movr_w_d(u, v) jit_new_node_ww(jit_code_movr_w_d, u, v)
+#define jit_movi_w_d(u,v) jit_new_node_ww(jit_code_movi_w_d, u, v)
+ jit_code_movr_w_d, jit_code_movi_w_d,
+
+ /* f|d -> w* */
+#define jit_movr_f_w(u, v) jit_new_node_ww(jit_code_movr_f_w, u, v)
+#define jit_movi_f_w(u, v) jit_new_node_wf(jit_code_movi_f_w, u, v)
+ jit_code_movr_f_w, jit_code_movi_f_w,
+#define jit_movr_d_ww(u, v, w) jit_new_node_www(jit_code_movr_d_ww, u, v, w)
+#define jit_movi_d_ww(u, v, w) jit_new_node_wwd(jit_code_movi_d_ww, u, v, w)
+ jit_code_movr_d_ww, jit_code_movi_d_ww,
+
+ /* d -> w */
+#define jit_movr_d_w(u, v) jit_new_node_ww(jit_code_movr_d_w, u, v)
+#define jit_movi_d_w(u, v) jit_new_node_wd(jit_code_movi_d_w, u, v)
+ jit_code_movr_d_w, jit_code_movi_d_w,
+
+#define jit_clor(u,v) jit_new_node_ww(jit_code_clor,u,v)
+#define jit_cloi(u,v) jit_new_node_ww(jit_code_cloi,u,v)
+ jit_code_clor, jit_code_cloi,
+
+#define jit_clzr(u,v) jit_new_node_ww(jit_code_clzr,u,v)
+#define jit_clzi(u,v) jit_new_node_ww(jit_code_clzi,u,v)
+ jit_code_clzr, jit_code_clzi,
+
+#define jit_ctor(u,v) jit_new_node_ww(jit_code_ctor,u,v)
+#define jit_ctoi(u,v) jit_new_node_ww(jit_code_ctoi,u,v)
+ jit_code_ctor, jit_code_ctoi,
+#define jit_ctzr(u,v) jit_new_node_ww(jit_code_ctzr,u,v)
+#define jit_ctzi(u,v) jit_new_node_ww(jit_code_ctzi,u,v)
+ jit_code_ctzr, jit_code_ctzi,
+
+#define jit_rbitr(u,v) jit_new_node_ww(jit_code_rbitr,u,v)
+#define jit_rbiti(u,v) jit_new_node_ww(jit_code_rbiti,u,v)
+ jit_code_rbitr, jit_code_rbiti,
+
+#define jit_popcntr(u,v) jit_new_node_ww(jit_code_popcntr,u,v)
+#define jit_popcnti(u,v) jit_new_node_ww(jit_code_popcnti,u,v)
+ jit_code_popcntr, jit_code_popcnti,
+
+#define jit_lrotr(u,v,w) jit_new_node_www(jit_code_lrotr,u,v,w)
+#define jit_lroti(u,v,w) jit_new_node_www(jit_code_lroti,u,v,w)
+ jit_code_lrotr, jit_code_lroti,
+#define jit_rrotr(u,v,w) jit_new_node_www(jit_code_rrotr,u,v,w)
+#define jit_rroti(u,v,w) jit_new_node_www(jit_code_rroti,u,v,w)
+ jit_code_rrotr, jit_code_rroti,
+
+#define jit_extr(u,v,w,x) jit_new_node_wwq(jit_code_extr, u, v, w, x)
+#define jit_exti(u,v,w,x) jit_new_node_wwq(jit_code_exti, u, v, w, x)
+ jit_code_extr, jit_code_exti,
+#define jit_extr_u(u,v,w,x) jit_new_node_wwq(jit_code_extr_u, u, v, w, x)
+#define jit_exti_u(u,v,w,x) jit_new_node_wwq(jit_code_exti_u, u, v, w, x)
+ jit_code_extr_u, jit_code_exti_u,
+#define jit_depr(u,v,w,x) jit_new_node_wwq(jit_code_depr, u, v, w, x)
+#define jit_depi(u,v,w,x) jit_new_node_wwq(jit_code_depi, u, v, w, x)
+ jit_code_depr, jit_code_depi,
+
+#define jit_qlshr(l,h,v,w) jit_new_node_qww(jit_code_qlshr,l,h,v,w)
+#define jit_qlshi(l,h,v,w) jit_new_node_qww(jit_code_qlshi,l,h,v,w)
+ jit_code_qlshr, jit_code_qlshi,
+#define jit_qlshr_u(l,h,v,w) jit_new_node_qww(jit_code_qlshr_u,l,h,v,w)
+#define jit_qlshi_u(l,h,v,w) jit_new_node_qww(jit_code_qlshi_u,l,h,v,w)
+ jit_code_qlshr_u, jit_code_qlshi_u,
+#define jit_qrshr(l,h,v,w) jit_new_node_qww(jit_code_qrshr,l,h,v,w)
+#define jit_qrshi(l,h,v,w) jit_new_node_qww(jit_code_qrshi,l,h,v,w)
+ jit_code_qrshr, jit_code_qrshi,
+#define jit_qrshr_u(l,h,v,w) jit_new_node_qww(jit_code_qrshr_u,l,h,v,w)
+#define jit_qrshi_u(l,h,v,w) jit_new_node_qww(jit_code_qrshi_u,l,h,v,w)
+ jit_code_qrshr_u, jit_code_qrshi_u,
+
+#define jit_unldr(u,v,w) jit_new_node_www(jit_code_unldr, u, v, w)
+#define jit_unldi(u,v,w) jit_new_node_www(jit_code_unldi, u, v, w)
+ jit_code_unldr, jit_code_unldi,
+#define jit_unldr_u(u,v,w) jit_new_node_www(jit_code_unldr_u, u, v, w)
+#define jit_unldi_u(u,v,w) jit_new_node_www(jit_code_unldi_u, u, v, w)
+ jit_code_unldr_u, jit_code_unldi_u,
+#define jit_unstr(u,v,w) jit_new_node_www(jit_code_unstr, u, v, w)
+#define jit_unsti(u,v,w) jit_new_node_www(jit_code_unsti, u, v, w)
+ jit_code_unstr, jit_code_unsti,
+
+#define jit_unldr_x(u,v,w) jit_new_node_www(jit_code_unldr_x, u, v, w)
+#define jit_unldi_x(u,v,w) jit_new_node_www(jit_code_unldi_x, u, v, w)
+ jit_code_unldr_x, jit_code_unldi_x,
+#define jit_unstr_x(u,v,w) jit_new_node_www(jit_code_unstr_x, u, v, w)
+#define jit_unsti_x(u,v,w) jit_new_node_www(jit_code_unsti_x, u, v, w)
+ jit_code_unstr_x, jit_code_unsti_x,
+
+#define jit_fmar_f(u,v,w,x) jit_new_node_wqw(jit_code_fmar_f, u, v, w, x)
+#define jit_fmai_f(u,v,w,x) _jit_fmai_f(_jit, u, v, w, x)
+ jit_code_fmar_f, jit_code_fmai_f,
+#define jit_fmsr_f(u,v,w,x) jit_new_node_wqw(jit_code_fmsr_f, u, v, w, x)
+#define jit_fmsi_f(u,v,w,x) _jit_fmsi_f(_jit, u, v, w, x)
+ jit_code_fmsr_f, jit_code_fmsi_f,
+#define jit_fmar_d(u,v,w,x) jit_new_node_wqw(jit_code_fmar_d, u, v, w, x)
+#define jit_fmai_d(u,v,w,x) _jit_fmai_d(_jit, u, v, w, x)
+ jit_code_fmar_d, jit_code_fmai_d,
+#define jit_fmsr_d(u,v,w,x) jit_new_node_wqw(jit_code_fmsr_d, u, v, w, x)
+#define jit_fmsi_d(u,v,w,x) _jit_fmsi_d(_jit, u, v, w, x)
+ jit_code_fmsr_d, jit_code_fmsi_d,
+
+#define jit_fnmar_f(u,v,w,x) jit_new_node_wqw(jit_code_fnmar_f, u, v, w, x)
+#define jit_fnmai_f(u,v,w,x) _jit_fnmai_f(_jit, u, v, w, x)
+ jit_code_fnmar_f, jit_code_fnmai_f,
+#define jit_fnmsr_f(u,v,w,x) jit_new_node_wqw(jit_code_fnmsr_f, u, v, w, x)
+#define jit_fnmsi_f(u,v,w,x) _jit_fnmsi_f(_jit, u, v, w, x)
+ jit_code_fnmsr_f, jit_code_fnmsi_f,
+#define jit_fnmar_d(u,v,w,x) jit_new_node_wqw(jit_code_fnmar_d, u, v, w, x)
+#define jit_fnmai_d(u,v,w,x) _jit_fnmai_d(_jit, u, v, w, x)
+ jit_code_fnmar_d, jit_code_fnmai_d,
+#define jit_fnmsr_d(u,v,w,x) jit_new_node_wqw(jit_code_fnmsr_d, u, v, w, x)
+#define jit_fnmsi_d(u,v,w,x) _jit_fnmsi_d(_jit, u, v, w, x)
+ jit_code_fnmsr_d, jit_code_fnmsi_d,
+
+#define jit_hmulr(u,v,w) jit_new_node_www(jit_code_hmulr,u,v,w)
+#define jit_hmuli(u,v,w) jit_new_node_www(jit_code_hmuli,u,v,w)
+ jit_code_hmulr, jit_code_hmuli,
+#define jit_hmulr_u(u,v,w) jit_new_node_www(jit_code_hmulr_u,u,v,w)
+#define jit_hmuli_u(u,v,w) jit_new_node_www(jit_code_hmuli_u,u,v,w)
+ jit_code_hmulr_u, jit_code_hmuli_u,
+
+#define jit_ldxbr_c(u,v,w) jit_new_node_www(jit_code_ldxbr_c,u,v,w)
+#define jit_ldxbi_c(u,v,w) jit_new_node_www(jit_code_ldxbi_c,u,v,w)
+ jit_code_ldxbr_c, jit_code_ldxbi_c,
+#define jit_ldxar_c(u,v,w) jit_new_node_www(jit_code_ldxar_c,u,v,w)
+#define jit_ldxai_c(u,v,w) jit_new_node_www(jit_code_ldxai_c,u,v,w)
+ jit_code_ldxar_c, jit_code_ldxai_c,
+#define jit_ldxbr_uc(u,v,w) jit_new_node_www(jit_code_ldxbr_uc,u,v,w)
+#define jit_ldxbi_uc(u,v,w) jit_new_node_www(jit_code_ldxbi_uc,u,v,w)
+ jit_code_ldxbr_uc, jit_code_ldxbi_uc,
+#define jit_ldxar_uc(u,v,w) jit_new_node_www(jit_code_ldxar_uc,u,v,w)
+#define jit_ldxai_uc(u,v,w) jit_new_node_www(jit_code_ldxai_uc,u,v,w)
+ jit_code_ldxar_uc, jit_code_ldxai_uc,
+#define jit_ldxbr_s(u,v,w) jit_new_node_www(jit_code_ldxbr_s,u,v,w)
+#define jit_ldxbi_s(u,v,w) jit_new_node_www(jit_code_ldxbi_s,u,v,w)
+ jit_code_ldxbr_s, jit_code_ldxbi_s,
+#define jit_ldxar_s(u,v,w) jit_new_node_www(jit_code_ldxar_s,u,v,w)
+#define jit_ldxai_s(u,v,w) jit_new_node_www(jit_code_ldxai_s,u,v,w)
+ jit_code_ldxar_s, jit_code_ldxai_s,
+#define jit_ldxbr_us(u,v,w) jit_new_node_www(jit_code_ldxbr_us,u,v,w)
+#define jit_ldxbi_us(u,v,w) jit_new_node_www(jit_code_ldxbi_us,u,v,w)
+ jit_code_ldxbr_us, jit_code_ldxbi_us,
+#define jit_ldxar_us(u,v,w) jit_new_node_www(jit_code_ldxar_us,u,v,w)
+#define jit_ldxai_us(u,v,w) jit_new_node_www(jit_code_ldxai_us,u,v,w)
+ jit_code_ldxar_us, jit_code_ldxai_us,
+#define jit_ldxbr_i(u,v,w) jit_new_node_www(jit_code_ldxbr_i,u,v,w)
+#define jit_ldxbi_i(u,v,w) jit_new_node_www(jit_code_ldxbi_i,u,v,w)
+ jit_code_ldxbr_i, jit_code_ldxbi_i,
+#define jit_ldxar_i(u,v,w) jit_new_node_www(jit_code_ldxar_i,u,v,w)
+#define jit_ldxai_i(u,v,w) jit_new_node_www(jit_code_ldxai_i,u,v,w)
+ jit_code_ldxar_i, jit_code_ldxai_i,
+#if __WORDSIZE == 32
+# define jit_ldxbr(u,v,w) jit_ldxbr_i(u,v,w)
+# define jit_ldxbi(u,v,w) jit_ldxbi_i(u,v,w)
+# define jit_ldxar(u,v,w) jit_ldxar_i(u,v,w)
+# define jit_ldxai(u,v,w) jit_ldxai_i(u,v,w)
+#else
+# define jit_ldxbr(u,v,w) jit_ldxbr_l(u,v,w)
+# define jit_ldxbi(u,v,w) jit_ldxbi_l(u,v,w)
+# define jit_ldxar(u,v,w) jit_ldxar_l(u,v,w)
+# define jit_ldxai(u,v,w) jit_ldxai_l(u,v,w)
+# define jit_ldxbr_ui(u,v,w) jit_new_node_www(jit_code_ldxbr_ui,u,v,w)
+# define jit_ldxbi_ui(u,v,w) jit_new_node_www(jit_code_ldxbi_ui,u,v,w)
+# define jit_ldxar_ui(u,v,w) jit_new_node_www(jit_code_ldxar_ui,u,v,w)
+# define jit_ldxai_ui(u,v,w) jit_new_node_www(jit_code_ldxai_ui,u,v,w)
+# define jit_ldxbr_l(u,v,w) jit_new_node_www(jit_code_ldxbr_l,u,v,w)
+# define jit_ldxbi_l(u,v,w) jit_new_node_www(jit_code_ldxbi_l,u,v,w)
+# define jit_ldxar_l(u,v,w) jit_new_node_www(jit_code_ldxar_l,u,v,w)
+# define jit_ldxai_l(u,v,w) jit_new_node_www(jit_code_ldxai_l,u,v,w)
+#endif
+ jit_code_ldxbr_ui, jit_code_ldxbi_ui,
+ jit_code_ldxar_ui, jit_code_ldxai_ui,
+ jit_code_ldxbr_l, jit_code_ldxbi_l,
+ jit_code_ldxar_l, jit_code_ldxai_l,
+# define jit_ldxbr_f(u,v,w) jit_new_node_www(jit_code_ldxbr_f,u,v,w)
+# define jit_ldxbi_f(u,v,w) jit_new_node_www(jit_code_ldxbi_f,u,v,w)
+# define jit_ldxar_f(u,v,w) jit_new_node_www(jit_code_ldxar_f,u,v,w)
+# define jit_ldxai_f(u,v,w) jit_new_node_www(jit_code_ldxai_f,u,v,w)
+ jit_code_ldxbr_f, jit_code_ldxbi_f,
+ jit_code_ldxar_f, jit_code_ldxai_f,
+# define jit_ldxbr_d(u,v,w) jit_new_node_www(jit_code_ldxbr_d,u,v,w)
+# define jit_ldxbi_d(u,v,w) jit_new_node_www(jit_code_ldxbi_d,u,v,w)
+# define jit_ldxar_d(u,v,w) jit_new_node_www(jit_code_ldxar_d,u,v,w)
+# define jit_ldxai_d(u,v,w) jit_new_node_www(jit_code_ldxai_d,u,v,w)
+ jit_code_ldxbr_d, jit_code_ldxbi_d,
+ jit_code_ldxar_d, jit_code_ldxai_d,
+#define jit_stxbr_c(u,v,w) jit_new_node_www(jit_code_stxbr_c,u,v,w)
+#define jit_stxbi_c(u,v,w) jit_new_node_www(jit_code_stxbi_c,u,v,w)
+#define jit_stxar_c(u,v,w) jit_new_node_www(jit_code_stxar_c,u,v,w)
+#define jit_stxai_c(u,v,w) jit_new_node_www(jit_code_stxai_c,u,v,w)
+ jit_code_stxbr_c, jit_code_stxbi_c,
+ jit_code_stxar_c, jit_code_stxai_c,
+#define jit_stxbr_s(u,v,w) jit_new_node_www(jit_code_stxbr_s,u,v,w)
+#define jit_stxbi_s(u,v,w) jit_new_node_www(jit_code_stxbi_s,u,v,w)
+#define jit_stxar_s(u,v,w) jit_new_node_www(jit_code_stxar_s,u,v,w)
+#define jit_stxai_s(u,v,w) jit_new_node_www(jit_code_stxai_s,u,v,w)
+ jit_code_stxbr_s, jit_code_stxbi_s,
+ jit_code_stxar_s, jit_code_stxai_s,
+#define jit_stxbr_i(u,v,w) jit_new_node_www(jit_code_stxbr_i,u,v,w)
+#define jit_stxbi_i(u,v,w) jit_new_node_www(jit_code_stxbi_i,u,v,w)
+#define jit_stxar_i(u,v,w) jit_new_node_www(jit_code_stxar_i,u,v,w)
+#define jit_stxai_i(u,v,w) jit_new_node_www(jit_code_stxai_i,u,v,w)
+ jit_code_stxbr_i, jit_code_stxbi_i,
+ jit_code_stxar_i, jit_code_stxai_i,
+#if __WORDSIZE == 32
+# define jit_stxbr(u,v,w) jit_stxbr_i(u,v,w)
+# define jit_stxbi(u,v,w) jit_stxbi_i(u,v,w)
+# define jit_stxar(u,v,w) jit_stxar_i(u,v,w)
+# define jit_stxai(u,v,w) jit_stxai_i(u,v,w)
+#else
+# define jit_stxbr(u,v,w) jit_stxbr_l(u,v,w)
+# define jit_stxbi(u,v,w) jit_stxbi_l(u,v,w)
+# define jit_stxar(u,v,w) jit_stxar_l(u,v,w)
+# define jit_stxai(u,v,w) jit_stxai_l(u,v,w)
+# define jit_stxbr_l(u,v,w) jit_new_node_www(jit_code_stxbr_l,u,v,w)
+# define jit_stxbi_l(u,v,w) jit_new_node_www(jit_code_stxbi_l,u,v,w)
+# define jit_stxar_l(u,v,w) jit_new_node_www(jit_code_stxar_l,u,v,w)
+# define jit_stxai_l(u,v,w) jit_new_node_www(jit_code_stxai_l,u,v,w)
+#endif
+ jit_code_stxbr_l, jit_code_stxbi_l,
+ jit_code_stxar_l, jit_code_stxai_l,
+# define jit_stxbr_f(u,v,w) jit_new_node_www(jit_code_stxbr_f,u,v,w)
+# define jit_stxbi_f(u,v,w) jit_new_node_www(jit_code_stxbi_f,u,v,w)
+# define jit_stxar_f(u,v,w) jit_new_node_www(jit_code_stxar_f,u,v,w)
+# define jit_stxai_f(u,v,w) jit_new_node_www(jit_code_stxai_f,u,v,w)
+ jit_code_stxbr_f, jit_code_stxbi_f,
+ jit_code_stxar_f, jit_code_stxai_f,
+# define jit_stxbr_d(u,v,w) jit_new_node_www(jit_code_stxbr_d,u,v,w)
+# define jit_stxbi_d(u,v,w) jit_new_node_www(jit_code_stxbi_d,u,v,w)
+# define jit_stxar_d(u,v,w) jit_new_node_www(jit_code_stxar_d,u,v,w)
+# define jit_stxai_d(u,v,w) jit_new_node_www(jit_code_stxai_d,u,v,w)
+ jit_code_stxbr_d, jit_code_stxbi_d,
+ jit_code_stxar_d, jit_code_stxai_d,
+
+ jit_code_last_code
+} jit_code_t;
+
+typedef void* (*jit_alloc_func_ptr) (size_t);
+typedef void* (*jit_realloc_func_ptr) (void*, size_t);
+typedef void (*jit_free_func_ptr) (void*);
+
+/*
+ * Prototypes
+ */
+extern void init_jit_with_debug(const char*,FILE*);
+extern void init_jit(const char*);
+extern void finish_jit(void);
+
+extern jit_state_t *jit_new_state(void);
+#define jit_clear_state() _jit_clear_state(_jit)
+extern void _jit_clear_state(jit_state_t*);
+#define jit_destroy_state() _jit_destroy_state(_jit)
+extern void _jit_destroy_state(jit_state_t*);
+
+#define jit_address(node) _jit_address(_jit, node)
+extern jit_pointer_t _jit_address(jit_state_t*, jit_node_t*);
+extern jit_node_t *_jit_name(jit_state_t*, const char*);
+extern jit_node_t *_jit_note(jit_state_t*, const char*, int);
+extern jit_node_t *_jit_label(jit_state_t*);
+extern jit_node_t *_jit_forward(jit_state_t*);
+extern jit_node_t *_jit_indirect(jit_state_t*);
+extern void _jit_link(jit_state_t*, jit_node_t*);
+#define jit_forward_p(u) _jit_forward_p(_jit,u)
+extern jit_bool_t _jit_forward_p(jit_state_t*,jit_node_t*);
+#define jit_indirect_p(u) _jit_indirect_p(_jit,u)
+extern jit_bool_t _jit_indirect_p(jit_state_t*,jit_node_t*);
+#define jit_target_p(u) _jit_target_p(_jit,u)
+extern jit_bool_t _jit_target_p(jit_state_t*,jit_node_t*);
+
+extern void _jit_prolog(jit_state_t*);
+
+extern jit_int32_t _jit_allocai(jit_state_t*, jit_int32_t);
+extern void _jit_allocar(jit_state_t*, jit_int32_t, jit_int32_t);
+extern void _jit_ellipsis(jit_state_t*);
+
+extern jit_node_t *_jit_arg(jit_state_t*, jit_code_t);
+
+extern void _jit_getarg_c(jit_state_t*, jit_gpr_t, jit_node_t*);
+extern void _jit_getarg_uc(jit_state_t*, jit_gpr_t, jit_node_t*);
+extern void _jit_getarg_s(jit_state_t*, jit_gpr_t, jit_node_t*);
+extern void _jit_getarg_us(jit_state_t*, jit_gpr_t, jit_node_t*);
+extern void _jit_getarg_i(jit_state_t*, jit_gpr_t, jit_node_t*);
+#if __WORDSIZE == 64
+extern void _jit_getarg_ui(jit_state_t*, jit_gpr_t, jit_node_t*);
+extern void _jit_getarg_l(jit_state_t*, jit_gpr_t, jit_node_t*);
+#endif
+
+extern void _jit_putargr(jit_state_t*, jit_gpr_t, jit_node_t*, jit_code_t);
+extern void _jit_putargi(jit_state_t*, jit_word_t, jit_node_t*, jit_code_t);
+
+extern void _jit_prepare(jit_state_t*);
+extern void _jit_ellipsis(jit_state_t*);
+extern void _jit_va_push(jit_state_t*, jit_gpr_t);
+
+extern void _jit_pushargr(jit_state_t*, jit_gpr_t, jit_code_t);
+extern void _jit_pushargi(jit_state_t*, jit_word_t, jit_code_t);
+
+extern void _jit_finishr(jit_state_t*, jit_gpr_t);
+extern jit_node_t *_jit_finishi(jit_state_t*, jit_pointer_t);
+extern void _jit_ret(jit_state_t*);
+
+extern void _jit_retr(jit_state_t*, jit_gpr_t, jit_code_t);
+extern void _jit_reti(jit_state_t*, jit_word_t, jit_code_t);
+
+extern void _jit_retval_c(jit_state_t*, jit_gpr_t);
+extern void _jit_retval_uc(jit_state_t*, jit_gpr_t);
+extern void _jit_retval_s(jit_state_t*, jit_gpr_t);
+extern void _jit_retval_us(jit_state_t*, jit_gpr_t);
+extern void _jit_retval_i(jit_state_t*, jit_gpr_t);
+#if __WORDSIZE == 64
+extern void _jit_retval_ui(jit_state_t*, jit_gpr_t);
+extern void _jit_retval_l(jit_state_t*, jit_gpr_t);
+#endif
+
+extern void _jit_epilog(jit_state_t*);
+
+#define jit_patch(u) _jit_patch(_jit,u)
+extern void _jit_patch(jit_state_t*, jit_node_t*);
+#define jit_patch_at(u,v) _jit_patch_at(_jit,u,v)
+extern void _jit_patch_at(jit_state_t*, jit_node_t*, jit_node_t*);
+#define jit_patch_abs(u,v) _jit_patch_abs(_jit,u,v)
+extern void _jit_patch_abs(jit_state_t*, jit_node_t*, jit_pointer_t);
+#define jit_realize() _jit_realize(_jit)
+extern void _jit_realize(jit_state_t*);
+#define jit_get_code(u) _jit_get_code(_jit,u)
+extern jit_pointer_t _jit_get_code(jit_state_t*, jit_word_t*);
+#define jit_set_code(u,v) _jit_set_code(_jit,u,v)
+extern void _jit_set_code(jit_state_t*, jit_pointer_t, jit_word_t);
+#define jit_get_data(u,v) _jit_get_data(_jit,u,v)
+extern jit_pointer_t _jit_get_data(jit_state_t*, jit_word_t*, jit_word_t*);
+#define jit_set_data(u,v,w) _jit_set_data(_jit,u,v,w)
+extern void _jit_set_data(jit_state_t*, jit_pointer_t, jit_word_t, jit_word_t);
+#define jit_frame(u) _jit_frame(_jit,u)
+extern void _jit_frame(jit_state_t*, jit_int32_t);
+#define jit_tramp(u) _jit_tramp(_jit,u)
+extern void _jit_tramp(jit_state_t*, jit_int32_t);
+#define jit_emit() _jit_emit(_jit)
+extern jit_pointer_t _jit_emit(jit_state_t*);
+#define jit_unprotect() _jit_unprotect(_jit)
+extern void _jit_unprotect(jit_state_t*);
+#define jit_protect() _jit_protect(_jit)
+extern void _jit_protect(jit_state_t*);
+
+#define jit_print() _jit_print(_jit)
+extern void _jit_print(jit_state_t*);
+
+extern jit_node_t *_jit_arg_f(jit_state_t*);
+extern void _jit_getarg_f(jit_state_t*, jit_fpr_t, jit_node_t*);
+extern void _jit_putargr_f(jit_state_t*, jit_fpr_t, jit_node_t*);
+extern void _jit_putargi_f(jit_state_t*, jit_float32_t, jit_node_t*);
+extern void _jit_pushargr_f(jit_state_t*, jit_fpr_t);
+extern void _jit_pushargi_f(jit_state_t*, jit_float32_t);
+extern void _jit_retr_f(jit_state_t*, jit_fpr_t);
+extern void _jit_reti_f(jit_state_t*, jit_float32_t);
+extern void _jit_retval_f(jit_state_t*, jit_fpr_t);
+extern void _jit_negi_f(jit_state_t*, jit_fpr_t, jit_float32_t);
+extern void _jit_absi_f(jit_state_t*, jit_fpr_t, jit_float32_t);
+extern void _jit_sqrti_f(jit_state_t*, jit_fpr_t, jit_float32_t);
+extern void _jit_fmai_f(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float32_t);
+extern void _jit_fmsi_f(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float32_t);
+extern void _jit_fnmai_f(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float32_t);
+extern void _jit_fnmsi_f(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float32_t);
+
+extern jit_node_t *_jit_arg_d(jit_state_t*);
+extern void _jit_getarg_d(jit_state_t*, jit_fpr_t, jit_node_t*);
+extern void _jit_putargr_d(jit_state_t*, jit_fpr_t, jit_node_t*);
+extern void _jit_putargi_d(jit_state_t*, jit_float64_t, jit_node_t*);
+extern void _jit_pushargr_d(jit_state_t*, jit_fpr_t);
+extern void _jit_pushargi_d(jit_state_t*, jit_float64_t);
+extern void _jit_retr_d(jit_state_t*, jit_fpr_t);
+extern void _jit_reti_d(jit_state_t*, jit_float64_t);
+extern void _jit_retval_d(jit_state_t*, jit_fpr_t);
+extern void _jit_negi_d(jit_state_t*, jit_fpr_t, jit_float64_t);
+extern void _jit_absi_d(jit_state_t*, jit_fpr_t, jit_float64_t);
+extern void _jit_sqrti_d(jit_state_t*, jit_fpr_t, jit_float64_t);
+extern void _jit_fmai_d(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float64_t);
+extern void _jit_fmsi_d(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float64_t);
+extern void _jit_fnmai_d(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float64_t);
+extern void _jit_fnmsi_d(jit_state_t*,
+ jit_fpr_t, jit_fpr_t, jit_fpr_t, jit_float64_t);
+
+#define jit_get_reg(s) _jit_get_reg(_jit,s)
+extern jit_int32_t _jit_get_reg(jit_state_t*, jit_int32_t);
+
+#define jit_unget_reg(r) _jit_unget_reg(_jit,r)
+extern void _jit_unget_reg(jit_state_t*, jit_int32_t);
+
+#define jit_new_node(c) _jit_new_node(_jit,c)
+extern jit_node_t *_jit_new_node(jit_state_t*, jit_code_t);
+#define jit_new_node_w(c,u) _jit_new_node_w(_jit,c,u)
+extern jit_node_t *_jit_new_node_w(jit_state_t*, jit_code_t,
+ jit_word_t);
+#define jit_new_node_f(c,u) _jit_new_node_f(_jit,c,u)
+extern jit_node_t *_jit_new_node_f(jit_state_t*, jit_code_t,
+ jit_float32_t);
+#define jit_new_node_d(c,u) _jit_new_node_d(_jit,c,u)
+extern jit_node_t *_jit_new_node_d(jit_state_t*, jit_code_t,
+ jit_float64_t);
+#define jit_new_node_p(c,u) _jit_new_node_p(_jit,c,u)
+extern jit_node_t *_jit_new_node_p(jit_state_t*, jit_code_t,
+ jit_pointer_t);
+#define jit_new_node_ww(c,u,v) _jit_new_node_ww(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_ww(jit_state_t*,jit_code_t,
+ jit_word_t, jit_word_t);
+#define jit_new_node_wp(c,u,v) _jit_new_node_wp(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_wp(jit_state_t*,jit_code_t,
+ jit_word_t, jit_pointer_t);
+#define jit_new_node_fp(c,u,v) _jit_new_node_fp(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_fp(jit_state_t*,jit_code_t,
+ jit_float32_t, jit_pointer_t);
+#define jit_new_node_dp(c,u,v) _jit_new_node_dp(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_dp(jit_state_t*,jit_code_t,
+ jit_float64_t, jit_pointer_t);
+#define jit_new_node_pw(c,u,v) _jit_new_node_pw(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_pw(jit_state_t*,jit_code_t,
+ jit_pointer_t, jit_word_t);
+#define jit_new_node_wf(c,u,v) _jit_new_node_wf(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_wf(jit_state_t*, jit_code_t,
+ jit_word_t, jit_float32_t);
+#define jit_new_node_wd(c,u,v) _jit_new_node_wd(_jit,c,u,v)
+extern jit_node_t *_jit_new_node_wd(jit_state_t*, jit_code_t,
+ jit_word_t, jit_float64_t);
+#define jit_new_node_www(c,u,v,w) _jit_new_node_www(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_www(jit_state_t*, jit_code_t,
+ jit_word_t, jit_word_t, jit_word_t);
+#define jit_new_node_qww(c,l,h,v,w) _jit_new_node_qww(_jit,c,l,h,v,w)
+extern jit_node_t *_jit_new_node_qww(jit_state_t*, jit_code_t,
+ jit_int32_t, jit_int32_t,
+ jit_word_t, jit_word_t);
+#define jit_new_node_wqw(c,u,l,h,w) _jit_new_node_wqw(_jit,c,u,l,h,w)
+extern jit_node_t *_jit_new_node_wqw(jit_state_t*, jit_code_t,
+ jit_word_t, jit_int32_t,
+ jit_int32_t, jit_word_t);
+#define jit_new_node_wwq(c,u,v,l,h) _jit_new_node_wwq(_jit,c,u,v,l,h)
+extern jit_node_t *_jit_new_node_wwq(jit_state_t*, jit_code_t,
+ jit_word_t, jit_word_t,
+ jit_int32_t, jit_int32_t);
+#define jit_new_node_wwf(c,u,v,w) _jit_new_node_wwf(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_wwf(jit_state_t*, jit_code_t,
+ jit_word_t, jit_word_t, jit_float32_t);
+#define jit_new_node_wqf(c,u,l,h,w) _jit_new_node_wqf(_jit,c,u,l,h,w)
+extern jit_node_t *_jit_new_node_wqf(jit_state_t*, jit_code_t,
+ jit_word_t, jit_int32_t,
+ jit_int32_t, jit_float32_t);
+#define jit_new_node_wwd(c,u,v,w) _jit_new_node_wwd(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_wwd(jit_state_t*, jit_code_t,
+ jit_word_t, jit_word_t, jit_float64_t);
+#define jit_new_node_wqd(c,u,l,h,w) _jit_new_node_wqd(_jit,c,u,l,h,w)
+extern jit_node_t *_jit_new_node_wqd(jit_state_t*, jit_code_t,
+ jit_word_t, jit_int32_t,
+ jit_int32_t, jit_float64_t);
+#define jit_new_node_pww(c,u,v,w) _jit_new_node_pww(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_pww(jit_state_t*, jit_code_t,
+ jit_pointer_t, jit_word_t, jit_word_t);
+#define jit_new_node_pwf(c,u,v,w) _jit_new_node_pwf(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_pwf(jit_state_t*, jit_code_t,
+ jit_pointer_t, jit_word_t, jit_float32_t);
+#define jit_new_node_pwd(c,u,v,w) _jit_new_node_pwd(_jit,c,u,v,w)
+extern jit_node_t *_jit_new_node_pwd(jit_state_t*, jit_code_t,
+ jit_pointer_t, jit_word_t, jit_float64_t);
+
+#define jit_arg_register_p(u) _jit_arg_register_p(_jit,u)
+extern jit_bool_t _jit_arg_register_p(jit_state_t*, jit_node_t*);
+#define jit_callee_save_p(u) _jit_callee_save_p(_jit,u)
+extern jit_bool_t _jit_callee_save_p(jit_state_t*, jit_int32_t);
+#define jit_pointer_p(u) _jit_pointer_p(_jit,u)
+extern jit_bool_t _jit_pointer_p(jit_state_t*,jit_pointer_t);
+
+#define jit_get_note(n,u,v,w) _jit_get_note(_jit,n,u,v,w)
+extern jit_bool_t _jit_get_note(jit_state_t*,jit_pointer_t,char**,char**,int*);
+
+#define jit_disassemble() _jit_disassemble(_jit)
+extern void _jit_disassemble(jit_state_t*);
+
+extern void jit_set_memory_functions(jit_alloc_func_ptr,
+ jit_realloc_func_ptr,
+ jit_free_func_ptr);
+extern void jit_get_memory_functions(jit_alloc_func_ptr*,
+ jit_realloc_func_ptr*,
+ jit_free_func_ptr*);
+#endif /* _lightning_h */
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019-2021 Paul Cercueil <paul@crapouillou.net>
+ */
+
+#ifndef __LIGHTREC_CONFIG_H__
+#define __LIGHTREC_CONFIG_H__
+
+#define ENABLE_THREADED_COMPILER LIGHTREC_ENABLE_THREADED_COMPILER
+#define ENABLE_FIRST_PASS 1
+#define ENABLE_DISASSEMBLER 0
+#define ENABLE_CODE_BUFFER 1
+
+#define HAS_DEFAULT_ELM 1
+
+#define OPT_REMOVE_DIV_BY_ZERO_SEQ 1
+#define OPT_REPLACE_MEMSET 1
+#define OPT_DETECT_IMPOSSIBLE_BRANCHES 1
+#define OPT_HANDLE_LOAD_DELAYS 1
+#define OPT_TRANSFORM_OPS 1
+#define OPT_LOCAL_BRANCHES 1
+#define OPT_SWITCH_DELAY_SLOTS 1
+#define OPT_FLAG_IO 1
+#define OPT_FLAG_MULT_DIV 1
+#define OPT_EARLY_UNLOAD 1
+#define OPT_PRELOAD_PC 1
+
+#define OPT_SH4_USE_GBR 0
+
+#endif /* __LIGHTREC_CONFIG_H__ */
+
#include "sio.h"
#include "ppf.h"
#include "new_dynarec/new_dynarec.h"
+#include "lightrec/plugin.h"
/* It's duplicated from emu_if.c */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+/* Corresponds to LIGHTREC_OPT_INV_DMA_ONLY of lightrec.h */
+#define LIGHTREC_HACK_INV_DMA_ONLY (1 << 0)
+
+u32 lightrec_hacks;
+
static const char * const MemorycardHack_db[] =
{
/* Lifeforce Tenka, also known as Codename Tenka */
{ 200, { "SLUS00183", "SLES00159", "SLPS00083", "SLPM80008" } },
};
+static const struct
+{
+ const char * const id;
+ u32 hacks;
+}
+lightrec_hacks_db[] =
+{
+ /* Formula One Arcade */
+ { "SCES03886", LIGHTREC_HACK_INV_DMA_ONLY },
+
+ /* Formula One '99 */
+ { "SLUS00870", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCPS10101", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES01979", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SLES01979", LIGHTREC_HACK_INV_DMA_ONLY },
+
+ /* Formula One 2000 */
+ { "SLUS01134", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES02777", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES02778", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES02779", LIGHTREC_HACK_INV_DMA_ONLY },
+
+ /* Formula One 2001 */
+ { "SCES03404", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES03423", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES03424", LIGHTREC_HACK_INV_DMA_ONLY },
+ { "SCES03524", LIGHTREC_HACK_INV_DMA_ONLY },
+};
+
/* Function for automatic patching according to GameID. */
void Apply_Hacks_Cdrom(void)
{
break;
}
}
+
+ lightrec_hacks = 0;
+
+ for (i = 0; drc_is_lightrec() && i < ARRAY_SIZE(lightrec_hacks_db); i++) {
+ if (strcmp(CdromId, lightrec_hacks_db[i].id) == 0)
+ {
+ lightrec_hacks = lightrec_hacks_db[i].hacks;
+ SysPrintf("using lightrec_hacks: 0x%x\n", lightrec_hacks);
+ break;
+ }
+ }
}
// from duckstation's gamedb.json
--- /dev/null
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2022 Paul Cercueil <paul@crapouillou.net>
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#include "../psxhw.h"
+#include "../psxmem.h"
+#include "../r3000a.h"
+
+#include "mem.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) ? (sizeof(a) / sizeof((a)[0])) : 0)
+
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE 0x100000
+#endif
+
+#ifndef MFD_HUGETLB
+#define MFD_HUGETLB 0x0004
+#endif
+
+static const uintptr_t supported_io_bases[] = {
+ 0x0,
+ 0x10000000,
+ 0x40000000,
+ 0x80000000,
+};
+
+static void * mmap_huge(void *addr, size_t length, int prot, int flags,
+ int fd, off_t offset)
+{
+ void *map = MAP_FAILED;
+
+ if (length >= 0x200000) {
+ map = mmap(addr, length, prot,
+ flags | MAP_HUGETLB | (21 << MAP_HUGE_SHIFT),
+ fd, offset);
+ if (map != MAP_FAILED)
+ printf("Hugetlb mmap to address 0x%" PRIxPTR " succeeded\n",
+ (uintptr_t) addr);
+ }
+
+ if (map == MAP_FAILED) {
+ map = mmap(addr, length, prot, flags, fd, offset);
+ if (map != MAP_FAILED) {
+ printf("Regular mmap to address 0x%" PRIxPTR " succeeded\n",
+ (uintptr_t) addr);
+#ifdef MADV_HUGEPAGE
+ madvise(map, length, MADV_HUGEPAGE);
+#endif
+ }
+ }
+
+ return map;
+}
+
+static int lightrec_mmap_ram(bool hugetlb)
+{
+ unsigned int i, j;
+ int err, memfd, flags = 0;
+ uintptr_t base;
+ void *map;
+
+ if (hugetlb)
+ flags |= MFD_HUGETLB;
+
+ memfd = syscall(SYS_memfd_create, "/lightrec_memfd",
+ flags);
+ if (memfd < 0) {
+ err = -errno;
+ fprintf(stderr, "Failed to create memfd: %d\n", err);
+ return err;
+ }
+
+ err = ftruncate(memfd, 0x200000);
+ if (err < 0) {
+ err = -errno;
+ fprintf(stderr, "Could not trim memfd: %d\n", err);
+ goto err_close_memfd;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(supported_io_bases); i++) {
+ base = supported_io_bases[i];
+
+ for (j = 0; j < 4; j++) {
+ void *base_ptr = (void *)(base + j * 0x200000);
+ map = mmap_huge(base_ptr, 0x200000, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_FIXED_NOREPLACE, memfd, 0);
+ if (map == MAP_FAILED)
+ break;
+ // some systems ignore MAP_FIXED_NOREPLACE
+ if (map != base_ptr) {
+ munmap(map, 0x200000);
+ break;
+ }
+ }
+
+ /* Impossible to map using this base */
+ if (j == 0)
+ continue;
+
+ /* All mirrors mapped - we got a match! */
+ if (j == 4)
+ break;
+
+ /* Only some mirrors mapped - clean the mess and try again */
+ for (; j > 0; j--)
+ munmap((void *)(base + (j - 1) * 0x200000), 0x200000);
+ }
+
+ if (i == ARRAY_SIZE(supported_io_bases)) {
+ err = -EINVAL;
+ goto err_close_memfd;
+ }
+
+ err = 0;
+ psxM = (s8 *)base;
+
+err_close_memfd:
+ close(memfd);
+ return err;
+}
+
+int lightrec_init_mmap(void)
+{
+ unsigned int i;
+ uintptr_t base;
+ void *map;
+ int err = lightrec_mmap_ram(true);
+ if (err) {
+ err = lightrec_mmap_ram(false);
+ if (err) {
+ fprintf(stderr, "Unable to mmap RAM and mirrors\n");
+ return err;
+ }
+ }
+
+ base = (uintptr_t) psxM;
+
+ map = mmap((void *)(base + 0x1f000000), 0x10000,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_FIXED_NOREPLACE | MAP_ANONYMOUS, -1, 0);
+ if (map == MAP_FAILED) {
+ err = -EINVAL;
+ fprintf(stderr, "Unable to mmap parallel port\n");
+ goto err_unmap;
+ }
+
+ psxP = (s8 *)map;
+
+ map = mmap_huge((void *)(base + 0x1fc00000), 0x200000,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_FIXED_NOREPLACE | MAP_ANONYMOUS, -1, 0);
+ if (map == MAP_FAILED) {
+ err = -EINVAL;
+ fprintf(stderr, "Unable to mmap BIOS\n");
+ goto err_unmap_parallel;
+ }
+
+ psxR = (s8 *)map;
+
+ map = mmap((void *)(base + 0x1f800000), 0x10000,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_FIXED_NOREPLACE | MAP_ANONYMOUS, 0, 0);
+ if (map == MAP_FAILED) {
+ err = -EINVAL;
+ fprintf(stderr, "Unable to mmap scratchpad\n");
+ goto err_unmap_bios;
+ }
+
+ psxH = (s8 *)map;
+
+ map = mmap_huge((void *)(base + 0x800000), CODE_BUFFER_SIZE,
+ PROT_EXEC | PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_FIXED_NOREPLACE | MAP_ANONYMOUS,
+ -1, 0);
+ if (map == MAP_FAILED) {
+ err = -EINVAL;
+ fprintf(stderr, "Unable to mmap code buffer\n");
+ goto err_unmap_scratch;
+ }
+
+ code_buffer = map;
+
+ return 0;
+
+err_unmap_scratch:
+ munmap(psxH, 0x10000);
+err_unmap_bios:
+ munmap(psxR, 0x200000);
+err_unmap_parallel:
+ munmap(psxP, 0x10000);
+err_unmap:
+ for (i = 0; i < 4; i++)
+ munmap((void *)((uintptr_t)psxM + i * 0x200000), 0x200000);
+ return err;
+}
+
+void lightrec_free_mmap(void)
+{
+ unsigned int i;
+
+ munmap(code_buffer, CODE_BUFFER_SIZE);
+ munmap(psxH, 0x10000);
+ munmap(psxR, 0x200000);
+ munmap(psxP, 0x10000);
+ for (i = 0; i < 4; i++)
+ munmap((void *)((uintptr_t)psxM + i * 0x200000), 0x200000);
+}
#ifdef LIGHTREC
-#define CODE_BUFFER_SIZE (8 * 1024 * 1024)
+#ifdef HW_WUP /* WiiU */
+# define WUP_RWX_MEM_BASE 0x00802000
+# define WUP_RWX_MEM_END 0x01000000
+# define CODE_BUFFER_SIZE_DFT (WUP_RWX_MEM_END - WUP_RWX_MEM_BASE)
+#else
+# define CODE_BUFFER_SIZE_DFT (8 * 1024 * 1024)
+#endif
+
+#ifndef CODE_BUFFER_SIZE
+#define CODE_BUFFER_SIZE CODE_BUFFER_SIZE_DFT
+#endif
extern void *code_buffer;
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2022 Ash Logan <ash@heyquark.com>
+ */
+
+#include <coreinit/memorymap.h>
+#include <malloc.h>
+#include <stdbool.h>
+
+#include "../memmap.h"
+#include "../psxhw.h"
+#include "../psxmem.h"
+#include "../r3000a.h"
+
+#include "mem.h"
+
+void wiiu_clear_cache(void *start, void *end);
+
+static void* wiiu_mmap(uint32_t requested_va, size_t length, void* backing_mem) {
+ if (length < OS_PAGE_SIZE) length = OS_PAGE_SIZE;
+
+ uint32_t va = OSAllocVirtAddr(requested_va, length, 0);
+ if (!va) return MAP_FAILED;
+
+ BOOL mapped = OSMapMemory(va, OSEffectiveToPhysical((uint32_t)backing_mem),
+ length, OS_MAP_MEMORY_READ_WRITE);
+ if (!mapped) {
+ OSFreeVirtAddr(va, length);
+ return MAP_FAILED;
+ }
+
+ return (void*)va;
+}
+
+static void wiiu_unmap(void* va, size_t length) {
+ if (va == MAP_FAILED) return;
+ OSUnmapMemory((uint32_t)va, length);
+ OSFreeVirtAddr((uint32_t)va, length);
+}
+
+static void* psx_mem;
+static void* psx_parallel;
+static void* psx_scratch;
+static void* psx_bios;
+
+int lightrec_init_mmap(void) {
+ psx_mem = memalign(OS_PAGE_SIZE, 0x200000);
+ psx_parallel = memalign(OS_PAGE_SIZE, 0x10000);
+ psx_scratch = memalign(OS_PAGE_SIZE, 0x10000);
+ psx_bios = memalign(OS_PAGE_SIZE, 0x80000);
+ if (!psx_mem || !psx_parallel || !psx_scratch || !psx_bios)
+ goto cleanup_allocations;
+
+ uint32_t avail_va;
+ uint32_t avail_va_size;
+ OSGetMapVirtAddrRange(&avail_va, &avail_va_size);
+ if (!avail_va || avail_va_size < 0x20000000)
+ goto cleanup_allocations;
+
+ // Map 4x ram mirrors
+ int i;
+ for (i = 0; i < 4; i++) {
+ void* ret = wiiu_mmap(avail_va + 0x200000 * i, 0x200000, psx_mem);
+ if (ret == MAP_FAILED) break;
+ }
+ if (i != 4) {
+ for (int i = 0; i < 4; i++)
+ wiiu_unmap(avail_va + 0x200000 * i, 0x200000);
+ goto cleanup_allocations;
+ }
+ psxM = (void*)avail_va;
+
+ psxP = wiiu_mmap(avail_va + 0x1f000000, 0x10000, psx_parallel);
+ psxH = wiiu_mmap(avail_va + 0x1f800000, 0x10000, psx_scratch);
+ psxR = wiiu_mmap(avail_va + 0x1fc00000, 0x80000, psx_bios);
+
+ if (psxP == MAP_FAILED || psxH == MAP_FAILED || psxR == MAP_FAILED) {
+ for (int i = 0; i < 4; i++)
+ wiiu_unmap(psxM + 0x200000 * i, 0x200000);
+ wiiu_unmap(psxP, 0x10000);
+ wiiu_unmap(psxH, 0x10000);
+ wiiu_unmap(psxR, 0x80000);
+ goto cleanup_allocations;
+ }
+
+ code_buffer = WUP_RWX_MEM_BASE;
+
+ return 0;
+
+cleanup_allocations:
+ free(psx_mem);
+ free(psx_parallel);
+ free(psx_scratch);
+ free(psx_bios);
+ return -1;
+}
+
+void lightrec_free_mmap(void) {
+ for (int i = 0; i < 4; i++)
+ wiiu_unmap(psxM + 0x200000 * i, 0x200000);
+ wiiu_unmap(psxP, 0x10000);
+ wiiu_unmap(psxH, 0x10000);
+ wiiu_unmap(psxR, 0x80000);
+ free(psx_mem);
+ free(psx_parallel);
+ free(psx_scratch);
+ free(psx_bios);
+}
+
+void lightrec_code_inv(void *ptr, uint32_t len)
+{
+ wiiu_clear_cache(ptr, (void *)((uintptr_t)ptr + len));
+}
--- /dev/null
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <assert.h>
+
+#if P_HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
+#include "lightrec.h"
+#include "../cdrom.h"
+#include "../gpu.h"
+#include "../gte.h"
+#include "../mdec.h"
+#include "../psxdma.h"
+#include "../psxhw.h"
+#include "../psxmem.h"
+#include "../r3000a.h"
+#include "../psxinterpreter.h"
+#include "../psxhle.h"
+#include "../psxevents.h"
+
+#include "../frontend/main.h"
+
+#include "mem.h"
+#include "plugin.h"
+
+#if (defined(__arm__) || defined(__aarch64__)) && !defined(ALLOW_LIGHTREC_ON_ARM)
+#error "Lightrec should not be used on ARM (please specify DYNAREC=ari64 to make)"
+#endif
+
+#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)
+
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define LE32TOH(x) __builtin_bswap32(x)
+# define HTOLE32(x) __builtin_bswap32(x)
+# define LE16TOH(x) __builtin_bswap16(x)
+# define HTOLE16(x) __builtin_bswap16(x)
+#else
+# define LE32TOH(x) (x)
+# define HTOLE32(x) (x)
+# define LE16TOH(x) (x)
+# define HTOLE16(x) (x)
+#endif
+
+#ifdef __GNUC__
+# define likely(x) __builtin_expect(!!(x),1)
+# define unlikely(x) __builtin_expect(!!(x),0)
+#else
+# define likely(x) (x)
+# define unlikely(x) (x)
+#endif
+
+#ifndef LIGHTREC_PROG_NAME
+# ifdef __linux__
+# define LIGHTREC_PROG_NAME "/proc/self/exe"
+# else
+# define LIGHTREC_PROG_NAME "retroarch.exe"
+# endif
+#endif
+
+psxRegisters psxRegs;
+Rcnt rcnts[4];
+
+void* code_buffer;
+
+static struct lightrec_state *lightrec_state;
+
+static bool use_lightrec_interpreter;
+static bool use_pcsx_interpreter;
+static bool block_stepping;
+
+extern u32 lightrec_hacks;
+
+extern void lightrec_code_inv(void *ptr, uint32_t len);
+
+enum my_cp2_opcodes {
+ OP_CP2_RTPS = 0x01,
+ OP_CP2_NCLIP = 0x06,
+ OP_CP2_OP = 0x0c,
+ OP_CP2_DPCS = 0x10,
+ OP_CP2_INTPL = 0x11,
+ OP_CP2_MVMVA = 0x12,
+ OP_CP2_NCDS = 0x13,
+ OP_CP2_CDP = 0x14,
+ OP_CP2_NCDT = 0x16,
+ OP_CP2_NCCS = 0x1b,
+ OP_CP2_CC = 0x1c,
+ OP_CP2_NCS = 0x1e,
+ OP_CP2_NCT = 0x20,
+ OP_CP2_SQR = 0x28,
+ OP_CP2_DCPL = 0x29,
+ OP_CP2_DPCT = 0x2a,
+ OP_CP2_AVSZ3 = 0x2d,
+ OP_CP2_AVSZ4 = 0x2e,
+ OP_CP2_RTPT = 0x30,
+ OP_CP2_GPF = 0x3d,
+ OP_CP2_GPL = 0x3e,
+ OP_CP2_NCCT = 0x3f,
+};
+
+static void (*cp2_ops[])(struct psxCP2Regs *) = {
+ [OP_CP2_RTPS] = gteRTPS,
+ [OP_CP2_RTPS] = gteRTPS,
+ [OP_CP2_NCLIP] = gteNCLIP,
+ [OP_CP2_OP] = gteOP,
+ [OP_CP2_DPCS] = gteDPCS,
+ [OP_CP2_INTPL] = gteINTPL,
+ [OP_CP2_MVMVA] = gteMVMVA,
+ [OP_CP2_NCDS] = gteNCDS,
+ [OP_CP2_CDP] = gteCDP,
+ [OP_CP2_NCDT] = gteNCDT,
+ [OP_CP2_NCCS] = gteNCCS,
+ [OP_CP2_CC] = gteCC,
+ [OP_CP2_NCS] = gteNCS,
+ [OP_CP2_NCT] = gteNCT,
+ [OP_CP2_SQR] = gteSQR,
+ [OP_CP2_DCPL] = gteDCPL,
+ [OP_CP2_DPCT] = gteDPCT,
+ [OP_CP2_AVSZ3] = gteAVSZ3,
+ [OP_CP2_AVSZ4] = gteAVSZ4,
+ [OP_CP2_RTPT] = gteRTPT,
+ [OP_CP2_GPF] = gteGPF,
+ [OP_CP2_GPL] = gteGPL,
+ [OP_CP2_NCCT] = gteNCCT,
+};
+
+static char cache_buf[64 * 1024];
+
+static void cop2_op(struct lightrec_state *state, u32 func)
+{
+ struct lightrec_registers *regs = lightrec_get_registers(state);
+
+ psxRegs.code = func;
+
+ if (unlikely(!cp2_ops[func & 0x3f])) {
+ fprintf(stderr, "Invalid CP2 function %u\n", func);
+ } else {
+ /* This works because regs->cp2c comes right after regs->cp2d,
+ * so it can be cast to a pcsxCP2Regs pointer. */
+ cp2_ops[func & 0x3f]((psxCP2Regs *) regs->cp2d);
+ }
+}
+
+static bool has_interrupt(void)
+{
+ struct lightrec_registers *regs = lightrec_get_registers(lightrec_state);
+
+ return ((psxHu32(0x1070) & psxHu32(0x1074)) &&
+ (regs->cp0[12] & 0x401) == 0x401) ||
+ (regs->cp0[12] & regs->cp0[13] & 0x0300);
+}
+
+static void lightrec_tansition_to_pcsx(struct lightrec_state *state)
+{
+ psxRegs.cycle += lightrec_current_cycle_count(state) / 1024;
+ lightrec_reset_cycle_count(state, 0);
+}
+
+static void lightrec_tansition_from_pcsx(struct lightrec_state *state)
+{
+ s32 cycles_left = next_interupt - psxRegs.cycle;
+
+ if (block_stepping || cycles_left <= 0 || has_interrupt())
+ lightrec_set_exit_flags(state, LIGHTREC_EXIT_CHECK_INTERRUPT);
+ else {
+ lightrec_set_target_cycle_count(state, cycles_left * 1024);
+ }
+}
+
+static void hw_write_byte(struct lightrec_state *state,
+ u32 op, void *host, u32 mem, u32 val)
+{
+ lightrec_tansition_to_pcsx(state);
+
+ psxHwWrite8(mem, val);
+
+ lightrec_tansition_from_pcsx(state);
+}
+
+static void hw_write_half(struct lightrec_state *state,
+ u32 op, void *host, u32 mem, u32 val)
+{
+ lightrec_tansition_to_pcsx(state);
+
+ psxHwWrite16(mem, val);
+
+ lightrec_tansition_from_pcsx(state);
+}
+
+static void hw_write_word(struct lightrec_state *state,
+ u32 op, void *host, u32 mem, u32 val)
+{
+ lightrec_tansition_to_pcsx(state);
+
+ psxHwWrite32(mem, val);
+
+ lightrec_tansition_from_pcsx(state);
+}
+
+static u8 hw_read_byte(struct lightrec_state *state, u32 op, void *host, u32 mem)
+{
+ u8 val;
+
+ lightrec_tansition_to_pcsx(state);
+
+ val = psxHwRead8(mem);
+
+ lightrec_tansition_from_pcsx(state);
+
+ return val;
+}
+
+static u16 hw_read_half(struct lightrec_state *state,
+ u32 op, void *host, u32 mem)
+{
+ u16 val;
+
+ lightrec_tansition_to_pcsx(state);
+
+ val = psxHwRead16(mem);
+
+ lightrec_tansition_from_pcsx(state);
+
+ return val;
+}
+
+static u32 hw_read_word(struct lightrec_state *state,
+ u32 op, void *host, u32 mem)
+{
+ u32 val;
+
+ lightrec_tansition_to_pcsx(state);
+
+ val = psxHwRead32(mem);
+
+ lightrec_tansition_from_pcsx(state);
+
+ return val;
+}
+
+static struct lightrec_mem_map_ops hw_regs_ops = {
+ .sb = hw_write_byte,
+ .sh = hw_write_half,
+ .sw = hw_write_word,
+ .lb = hw_read_byte,
+ .lh = hw_read_half,
+ .lw = hw_read_word,
+};
+
+static u32 cache_ctrl;
+
+static void cache_ctrl_write_word(struct lightrec_state *state,
+ u32 op, void *host, u32 mem, u32 val)
+{
+ cache_ctrl = val;
+}
+
+static u32 cache_ctrl_read_word(struct lightrec_state *state,
+ u32 op, void *host, u32 mem)
+{
+ return cache_ctrl;
+}
+
+static struct lightrec_mem_map_ops cache_ctrl_ops = {
+ .sw = cache_ctrl_write_word,
+ .lw = cache_ctrl_read_word,
+};
+
+static struct lightrec_mem_map lightrec_map[] = {
+ [PSX_MAP_KERNEL_USER_RAM] = {
+ /* Kernel and user memory */
+ .pc = 0x00000000,
+ .length = 0x200000,
+ },
+ [PSX_MAP_BIOS] = {
+ /* BIOS */
+ .pc = 0x1fc00000,
+ .length = 0x80000,
+ },
+ [PSX_MAP_SCRATCH_PAD] = {
+ /* Scratch pad */
+ .pc = 0x1f800000,
+ .length = 0x400,
+ },
+ [PSX_MAP_PARALLEL_PORT] = {
+ /* Parallel port */
+ .pc = 0x1f000000,
+ .length = 0x10000,
+ },
+ [PSX_MAP_HW_REGISTERS] = {
+ /* Hardware registers */
+ .pc = 0x1f801000,
+ .length = 0x8000,
+ .ops = &hw_regs_ops,
+ },
+ [PSX_MAP_CACHE_CONTROL] = {
+ /* Cache control */
+ .pc = 0x5ffe0130,
+ .length = 4,
+ .ops = &cache_ctrl_ops,
+ },
+
+ /* Mirrors of the kernel/user memory */
+ [PSX_MAP_MIRROR1] = {
+ .pc = 0x00200000,
+ .length = 0x200000,
+ .mirror_of = &lightrec_map[PSX_MAP_KERNEL_USER_RAM],
+ },
+ [PSX_MAP_MIRROR2] = {
+ .pc = 0x00400000,
+ .length = 0x200000,
+ .mirror_of = &lightrec_map[PSX_MAP_KERNEL_USER_RAM],
+ },
+ [PSX_MAP_MIRROR3] = {
+ .pc = 0x00600000,
+ .length = 0x200000,
+ .mirror_of = &lightrec_map[PSX_MAP_KERNEL_USER_RAM],
+ },
+
+ /* Mirror of the parallel port. Only used by the PS2/PS3 BIOS */
+ [PSX_MAP_PPORT_MIRROR] = {
+ .pc = 0x1fa00000,
+ .length = 0x10000,
+ .mirror_of = &lightrec_map[PSX_MAP_PARALLEL_PORT],
+ },
+
+ /* Code buffer */
+ [PSX_MAP_CODE_BUFFER] = {
+ .length = CODE_BUFFER_SIZE,
+ },
+};
+
+static void lightrec_enable_ram(struct lightrec_state *state, bool enable)
+{
+ if (enable)
+ memcpy(psxM, cache_buf, sizeof(cache_buf));
+ else
+ memcpy(cache_buf, psxM, sizeof(cache_buf));
+}
+
+static bool lightrec_can_hw_direct(u32 kaddr, bool is_write, u8 size)
+{
+ if (is_write && size != 32) {
+ // force32 so must go through handlers
+ if (0x1f801000 <= kaddr && kaddr < 0x1f801024)
+ return false;
+ if ((kaddr & 0x1fffff80) == 0x1f801080) // dma
+ return false;
+ }
+
+ switch (size) {
+ case 8:
+ switch (kaddr) {
+ case 0x1f801040:
+ case 0x1f801050:
+ case 0x1f801800:
+ case 0x1f801801:
+ case 0x1f801802:
+ case 0x1f801803:
+ return false;
+ default:
+ return true;
+ }
+ case 16:
+ switch (kaddr) {
+ case 0x1f801040:
+ case 0x1f801044:
+ case 0x1f801048:
+ case 0x1f80104a:
+ case 0x1f80104e:
+ case 0x1f801050:
+ case 0x1f801054:
+ case 0x1f80105a:
+ case 0x1f80105e:
+ case 0x1f801100:
+ case 0x1f801104:
+ case 0x1f801108:
+ case 0x1f801110:
+ case 0x1f801114:
+ case 0x1f801118:
+ case 0x1f801120:
+ case 0x1f801124:
+ case 0x1f801128:
+ return false;
+ case 0x1f801070:
+ case 0x1f801074:
+ return !is_write;
+ default:
+ return kaddr < 0x1f801c00 || kaddr >= 0x1f801e00;
+ }
+ default:
+ switch (kaddr) {
+ case 0x1f801040:
+ case 0x1f801050:
+ case 0x1f801100:
+ case 0x1f801104:
+ case 0x1f801108:
+ case 0x1f801110:
+ case 0x1f801114:
+ case 0x1f801118:
+ case 0x1f801120:
+ case 0x1f801124:
+ case 0x1f801128:
+ case 0x1f801810:
+ case 0x1f801814:
+ case 0x1f801820:
+ case 0x1f801824:
+ return false;
+ case 0x1f801070:
+ case 0x1f801074:
+ case 0x1f801088:
+ case 0x1f801098:
+ case 0x1f8010a8:
+ case 0x1f8010b8:
+ case 0x1f8010c8:
+ case 0x1f8010e8:
+ case 0x1f8010f4:
+ return !is_write;
+ default:
+ return !is_write || kaddr < 0x1f801c00 || kaddr >= 0x1f801e00;
+ }
+ }
+}
+
+static const struct lightrec_ops lightrec_ops = {
+ .cop2_op = cop2_op,
+ .enable_ram = lightrec_enable_ram,
+ .hw_direct = lightrec_can_hw_direct,
+ .code_inv = LIGHTREC_CODE_INV ? lightrec_code_inv : NULL,
+};
+
+static int lightrec_plugin_init(void)
+{
+ lightrec_map[PSX_MAP_KERNEL_USER_RAM].address = psxM;
+ lightrec_map[PSX_MAP_BIOS].address = psxR;
+ lightrec_map[PSX_MAP_SCRATCH_PAD].address = psxH;
+ lightrec_map[PSX_MAP_HW_REGISTERS].address = psxH + 0x1000;
+ lightrec_map[PSX_MAP_PARALLEL_PORT].address = psxP;
+
+ if (!LIGHTREC_CUSTOM_MAP) {
+#if P_HAVE_MMAP
+ code_buffer = mmap(0, CODE_BUFFER_SIZE,
+ PROT_EXEC | PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (code_buffer == MAP_FAILED)
+ return -ENOMEM;
+#else
+ code_buffer = malloc(CODE_BUFFER_SIZE);
+ if (!code_buffer)
+ return -ENOMEM;
+#endif
+ }
+
+ if (LIGHTREC_CUSTOM_MAP) {
+ lightrec_map[PSX_MAP_MIRROR1].address = psxM + 0x200000;
+ lightrec_map[PSX_MAP_MIRROR2].address = psxM + 0x400000;
+ lightrec_map[PSX_MAP_MIRROR3].address = psxM + 0x600000;
+ }
+
+ lightrec_map[PSX_MAP_CODE_BUFFER].address = code_buffer;
+
+ use_lightrec_interpreter = !!getenv("LIGHTREC_INTERPRETER");
+
+ lightrec_state = lightrec_init(LIGHTREC_PROG_NAME,
+ lightrec_map, ARRAY_SIZE(lightrec_map),
+ &lightrec_ops);
+
+ // fprintf(stderr, "M=0x%lx, P=0x%lx, R=0x%lx, H=0x%lx\n",
+ // (uintptr_t) psxM,
+ // (uintptr_t) psxP,
+ // (uintptr_t) psxR,
+ // (uintptr_t) psxH);
+
+#ifndef _WIN32
+ signal(SIGPIPE, exit);
+#endif
+ return 0;
+}
+
+static void lightrec_plugin_sync_regs_to_pcsx(bool need_cp2);
+static void lightrec_plugin_sync_regs_from_pcsx(bool need_cp2);
+
+static void lightrec_plugin_execute_internal(bool block_only)
+{
+ struct lightrec_registers *regs;
+ u32 flags, cycles_pcsx;
+
+ regs = lightrec_get_registers(lightrec_state);
+ gen_interupt((psxCP0Regs *)regs->cp0);
+ if (!block_only && stop)
+ return;
+
+ cycles_pcsx = next_interupt - psxRegs.cycle;
+ assert((s32)cycles_pcsx > 0);
+
+ // step during early boot so that 0x80030000 fastboot hack works
+ block_stepping = block_only;
+ if (block_only)
+ cycles_pcsx = 0;
+
+ if (use_pcsx_interpreter) {
+ intExecuteBlock(0);
+ } else {
+ u32 cycles_lightrec = cycles_pcsx * 1024;
+ if (unlikely(use_lightrec_interpreter)) {
+ psxRegs.pc = lightrec_run_interpreter(lightrec_state,
+ psxRegs.pc,
+ cycles_lightrec);
+ } else {
+ psxRegs.pc = lightrec_execute(lightrec_state,
+ psxRegs.pc, cycles_lightrec);
+ }
+
+ lightrec_tansition_to_pcsx(lightrec_state);
+
+ flags = lightrec_exit_flags(lightrec_state);
+
+ if (flags & LIGHTREC_EXIT_SEGFAULT) {
+ fprintf(stderr, "Exiting at cycle 0x%08x\n",
+ psxRegs.cycle);
+ exit(1);
+ }
+
+ if (flags & LIGHTREC_EXIT_SYSCALL)
+ psxException(R3000E_Syscall << 2, 0, (psxCP0Regs *)regs->cp0);
+ if (flags & LIGHTREC_EXIT_BREAK)
+ psxException(R3000E_Bp << 2, 0, (psxCP0Regs *)regs->cp0);
+ else if (flags & LIGHTREC_EXIT_UNKNOWN_OP) {
+ u32 op = intFakeFetch(psxRegs.pc);
+ u32 hlec = op & 0x03ffffff;
+ if ((op >> 26) == 0x3b && hlec < ARRAY_SIZE(psxHLEt) && Config.HLE) {
+ lightrec_plugin_sync_regs_to_pcsx(0);
+ psxHLEt[hlec]();
+ lightrec_plugin_sync_regs_from_pcsx(0);
+ }
+ else
+ psxException(R3000E_RI << 2, 0, (psxCP0Regs *)regs->cp0);
+ }
+ }
+
+ if ((regs->cp0[13] & regs->cp0[12] & 0x300) && (regs->cp0[12] & 0x1)) {
+ /* Handle software interrupts */
+ regs->cp0[13] &= ~0x7c;
+ psxException(regs->cp0[13], 0, (psxCP0Regs *)regs->cp0);
+ }
+}
+
+static void lightrec_plugin_execute(void)
+{
+ while (!stop)
+ lightrec_plugin_execute_internal(false);
+}
+
+static void lightrec_plugin_execute_block(enum blockExecCaller caller)
+{
+ lightrec_plugin_execute_internal(true);
+}
+
+static void lightrec_plugin_clear(u32 addr, u32 size)
+{
+ if ((addr == 0 && size == UINT32_MAX)
+ || (lightrec_hacks & LIGHTREC_OPT_INV_DMA_ONLY))
+ lightrec_invalidate_all(lightrec_state);
+ else
+ /* size * 4: PCSX uses DMA units */
+ lightrec_invalidate(lightrec_state, addr, size * 4);
+}
+
+static void lightrec_plugin_notify(enum R3000Anote note, void *data)
+{
+ switch (note)
+ {
+ case R3000ACPU_NOTIFY_CACHE_ISOLATED:
+ case R3000ACPU_NOTIFY_CACHE_UNISOLATED:
+ /* not used, lightrec calls lightrec_enable_ram() instead */
+ break;
+ case R3000ACPU_NOTIFY_BEFORE_SAVE:
+ /* non-null 'data' means this is HLE related sync */
+ lightrec_plugin_sync_regs_to_pcsx(data == NULL);
+ break;
+ case R3000ACPU_NOTIFY_AFTER_LOAD:
+ lightrec_plugin_sync_regs_from_pcsx(data == NULL);
+ if (data == NULL)
+ lightrec_invalidate_all(lightrec_state);
+ break;
+ }
+}
+
+static void lightrec_plugin_apply_config()
+{
+ static u32 cycles_per_op_old;
+ u32 cycle_mult = Config.cycle_multiplier_override && Config.cycle_multiplier == CYCLE_MULT_DEFAULT
+ ? Config.cycle_multiplier_override : Config.cycle_multiplier;
+ u32 cycles_per_op = cycle_mult * 1024 / 100;
+ assert(cycles_per_op);
+
+ if (cycles_per_op_old && cycles_per_op_old != cycles_per_op) {
+ SysPrintf("lightrec: reinit block cache for cycles_per_op %.2f\n",
+ cycles_per_op / 1024.f);
+ }
+ cycles_per_op_old = cycles_per_op;
+ lightrec_set_cycles_per_opcode(lightrec_state, cycles_per_op);
+}
+
+static void lightrec_plugin_shutdown(void)
+{
+ lightrec_destroy(lightrec_state);
+
+ if (!LIGHTREC_CUSTOM_MAP) {
+#if P_HAVE_MMAP
+ munmap(code_buffer, CODE_BUFFER_SIZE);
+#else
+ free(code_buffer);
+#endif
+ }
+}
+
+static void lightrec_plugin_reset(void)
+{
+ struct lightrec_registers *regs;
+
+ regs = lightrec_get_registers(lightrec_state);
+
+ /* Invalidate all blocks */
+ lightrec_invalidate_all(lightrec_state);
+
+ /* Reset registers */
+ memset(regs, 0, sizeof(*regs));
+
+ regs->cp0[12] = 0x10900000; // COP0 enabled | BEV = 1 | TS = 1
+ regs->cp0[15] = 0x00000002; // PRevID = Revision ID, same as R3000A
+
+ lightrec_set_unsafe_opt_flags(lightrec_state, lightrec_hacks);
+}
+
+static void lightrec_plugin_sync_regs_from_pcsx(bool need_cp2)
+{
+ struct lightrec_registers *regs;
+
+ regs = lightrec_get_registers(lightrec_state);
+ memcpy(regs->gpr, &psxRegs.GPR, sizeof(regs->gpr));
+ memcpy(regs->cp0, &psxRegs.CP0, sizeof(regs->cp0));
+ if (need_cp2)
+ memcpy(regs->cp2d, &psxRegs.CP2, sizeof(regs->cp2d) + sizeof(regs->cp2c));
+}
+
+static void lightrec_plugin_sync_regs_to_pcsx(bool need_cp2)
+{
+ struct lightrec_registers *regs;
+
+ regs = lightrec_get_registers(lightrec_state);
+ memcpy(&psxRegs.GPR, regs->gpr, sizeof(regs->gpr));
+ memcpy(&psxRegs.CP0, regs->cp0, sizeof(regs->cp0));
+ if (need_cp2)
+ memcpy(&psxRegs.CP2, regs->cp2d, sizeof(regs->cp2d) + sizeof(regs->cp2c));
+}
+
+R3000Acpu psxRec =
+{
+ lightrec_plugin_init,
+ lightrec_plugin_reset,
+ lightrec_plugin_execute,
+ lightrec_plugin_execute_block,
+ lightrec_plugin_clear,
+ lightrec_plugin_notify,
+ lightrec_plugin_apply_config,
+ lightrec_plugin_shutdown,
+};
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022 Paul Cercueil <paul@crapouillou.net>
+ */
+
+#ifndef __LIGHTREC_PLUGIN_H__
+#define __LIGHTREC_PLUGIN_H__
+
+#ifdef LIGHTREC
+
+#define drc_is_lightrec() 1
+
+#else /* if !LIGHTREC */
+
+#define drc_is_lightrec() 0
+
+#endif
+
+#endif /* __LIGHTREC_PLUGIN_H__ */
+
--- /dev/null
+#include <errno.h>
+#include <unistd.h>
+
+/* Implement the sysconf() symbol which is needed by GNU Lightning */
+long sysconf(int name)
+{
+ switch (name) {
+ case _SC_PAGE_SIZE:
+ return 4096;
+ default:
+ return -EINVAL;
+ }
+}
static int pgsize(void)
{
+ long ret = -1;
#ifdef _SC_PAGESIZE
- return sysconf(_SC_PAGESIZE);
-#else
- return 4096;
+ ret = sysconf(_SC_PAGESIZE);
#endif
+ if (ret < 1)
+ ret = 4096;
+ return ret;
}
void new_dynarec_init(void)
// might also need more delay like in set_dma_end()\r
do_irq_io(irq_after * 4);\r
}\r
- for (i = 0; i < 24; i++) {\r
+ for (i = 0; i < MAXCHAN; i++) {\r
size_t ediff, p = spu.s_chan[i].pCurr - spu.spuMemC;\r
if (spu.s_chan[i].ADSRX.State == ADSR_RELEASE && !spu.s_chan[i].ADSRX.EnvelopeVol)\r
continue;\r
u8 texture_4bpp_cache[32][256 * 256];
u8 texture_8bpp_even_cache[16][256 * 256];
u8 texture_8bpp_odd_cache[16][256 * 256];
+ int use_dithering;
} psx_gpu_struct;
typedef struct __attribute__((aligned(16)))
#include <stdio.h>
#include <assert.h>
-#include <sys/mman.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#ifndef min
}
if (cbs->pl_set_gpu_caps)
cbs->pl_set_gpu_caps(GPU_CAP_SUPPORTS_2X);
+
+ egpu.use_dithering = cbs->gpu_neon.allow_dithering;
+ if(!egpu.use_dithering) {
+ egpu.dither_table[0] = dither_table_row(0, 0, 0, 0);
+ egpu.dither_table[1] = dither_table_row(0, 0, 0, 0);
+ egpu.dither_table[2] = dither_table_row(0, 0, 0, 0);
+ egpu.dither_table[3] = dither_table_row(0, 0, 0, 0);
+ } else {
+ egpu.dither_table[0] = dither_table_row(-4, 0, -3, 1);
+ egpu.dither_table[1] = dither_table_row(2, -2, 3, -1);
+ egpu.dither_table[2] = dither_table_row(-3, 1, -4, 0);
+ egpu.dither_table[3] = dither_table_row(3, -1, 2, -2);
+ }
egpu.hack_disable_main = cbs->gpu_neon.enhancement_no_main;
egpu.hack_texture_adj = cbs->gpu_neon.enhancement_tex_adj;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdlib.h> /* for calloc */
+
#include "gpu.h"
#include "gpu_timing.h"
#include "../../libpcsxcore/gpu.h" // meh
}
}
-// double, for overdraw guard
-#define VRAM_SIZE (1024 * 512 * 2 * 2)
+#ifndef max
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+// Minimum 16-byte VRAM alignment needed by gpu_unai's pixel-skipping
+// renderer/downscaler it uses in high res modes:
+#ifdef GCW_ZERO
+ // On GCW platform (MIPS), align to 8192 bytes (1 TLB entry) to reduce # of
+ // fills. (Will change this value if it ever gets large page support)
+ #define VRAM_ALIGN 8192
+#else
+ #define VRAM_ALIGN 16
+#endif
+
+// double, for overdraw guard + at least 1 page before
+#define VRAM_SIZE ((1024 * 512 * 2 * 2) + max(VRAM_ALIGN, 4096))
+
+// vram ptr received from mmap/malloc/alloc (will deallocate using this)
+static uint16_t *vram_ptr_orig = NULL;
+#ifndef GPULIB_USE_MMAP
+# ifdef __linux__
+# define GPULIB_USE_MMAP 1
+# else
+# define GPULIB_USE_MMAP 0
+# endif
+#endif
static int map_vram(void)
{
- gpu.vram = gpu.mmap(VRAM_SIZE);
- if (gpu.vram != NULL) {
- gpu.vram += 4096 / 2;
+#if GPULIB_USE_MMAP
+ gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE);
+#else
+ gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE, 1);
+#endif
+ if (gpu.vram != NULL && gpu.vram != (void *)(intptr_t)-1) {
+ // 4kb guard in front
+ gpu.vram += (4096 / 2);
+ // Align
+ gpu.vram = (uint16_t*)(((uintptr_t)gpu.vram + (VRAM_ALIGN-1)) & ~(VRAM_ALIGN-1));
return 0;
}
else {
gpu.cmd_len = 0;
do_reset();
- if (gpu.mmap != NULL) {
+ /*if (gpu.mmap != NULL) {
if (map_vram() != 0)
ret = -1;
- }
+ }*/
return ret;
}
renderer_finish();
ret = vout_finish();
- if (gpu.vram != NULL) {
- gpu.vram -= 4096 / 2;
- gpu.munmap(gpu.vram, VRAM_SIZE);
+
+ if (vram_ptr_orig != NULL) {
+#if GPULIB_USE_MMAP
+ gpu.munmap(vram_ptr_orig, VRAM_SIZE);
+#else
+ free(vram_ptr_orig);
+#endif
}
- gpu.vram = NULL;
+ vram_ptr_orig = gpu.vram = NULL;
return ret;
}
bpp = 24;
}
+ gpu.state.downscale_active =
+ gpu.get_downscale_buffer != NULL && gpu.state.downscale_enable
+ && (w >= 512 || h >= 256);
+
+ if (gpu.state.downscale_active) {
+ w_out = w < 512 ? w : 320;
+ h_out = h < 256 ? h : h / 2;
+ }
+
// width|rgb24 change?
if (force || (gpu.status ^ gpu.state.status_vo_old) & ((7<<16)|(1<<21))
|| w_out != gpu.state.w_out_old || h_out != gpu.state.h_out_old)
src_x2 *= 2;
}
+ if (gpu.state.downscale_active)
+ vram = (void *)gpu.get_downscale_buffer(&src_x, &src_y, &w, &h, &vram_h);
+
if (src_y + h > vram_h) {
if (src_y + h - vram_h > h / 2) {
// wrap