diff options
author | 2011-07-09 00:27:31 +0000 | |
---|---|---|
committer | 2011-07-09 00:27:31 +0000 | |
commit | 22378a8fccbf90e08b01c8bcacf9cb522db24e65 (patch) | |
tree | 6c0d9354d952f10b91bc22f778aad3ab03047a56 | |
parent | KNF (diff) | |
download | wireguard-openbsd-22378a8fccbf90e08b01c8bcacf9cb522db24e65.tar.xz wireguard-openbsd-22378a8fccbf90e08b01c8bcacf9cb522db24e65.zip |
Add zlib reset, alloc, and free functions for hibernate image compression
-rw-r--r-- | sys/arch/i386/i386/hibernate_machdep.c | 36 | ||||
-rw-r--r-- | sys/arch/i386/include/hibernate.h | 1 | ||||
-rw-r--r-- | sys/kern/subr_hibernate.c | 29 | ||||
-rw-r--r-- | sys/sys/hibernate.h | 5 |
4 files changed, 68 insertions, 3 deletions
diff --git a/sys/arch/i386/i386/hibernate_machdep.c b/sys/arch/i386/i386/hibernate_machdep.c index c5a81b837bb..39c04951d2b 100644 --- a/sys/arch/i386/i386/hibernate_machdep.c +++ b/sys/arch/i386/i386/hibernate_machdep.c @@ -54,6 +54,7 @@ void hibernate_populate_resume_pt(paddr_t *, paddr_t *); int get_hibernate_info_md(union hibernate_info *); int hibernate_write_signature(void); int hibernate_clear_signature(void); + union hibernate_info *global_hiber_info; paddr_t global_image_start; @@ -64,13 +65,46 @@ extern char *disk_readlabel(struct disklabel *, dev_t, char *, size_t); extern caddr_t start, end; extern int ndumpmem; extern struct dumpmem dumpmem[]; - +extern struct hibernate_state *hibernate_state; /* * i386 MD Hibernate functions */ /* + * hibernate_zlib_reset + * + * Reset the zlib stream state and allocate a new hiballoc area for either + * inflate or deflate. This function is called once for each hibernate chunk + * Calling hiballoc_init multiple times is acceptable since the memory it is + * provided is unmanaged memory (stolen). + * + */ +int +hibernate_zlib_reset(int deflate) +{ + hibernate_state = (struct hibernate_state *)HIBERNATE_ZLIB_SCRATCH; + + bzero((caddr_t)HIBERNATE_ZLIB_START, HIBERNATE_ZLIB_SIZE); + bzero((caddr_t)HIBERNATE_ZLIB_SCRATCH, PAGE_SIZE); + + /* Set up stream structure */ + hibernate_state->hib_stream.zalloc = (alloc_func)hibernate_zlib_alloc; + hibernate_state->hib_stream.zfree = (free_func)hibernate_zlib_free; + + /* Initialize the hiballoc arena for zlib allocs/frees */ + hiballoc_init(&hibernate_state->hiballoc_arena, + (caddr_t)HIBERNATE_ZLIB_START, HIBERNATE_ZLIB_SIZE); + + if (deflate) { + return deflateInit(&hibernate_state->hib_stream, + Z_DEFAULT_COMPRESSION); + } + else + return inflateInit(&hibernate_state->hib_stream); +} + +/* * get_hibernate_io_function * * Returns the hibernate write I/O function to use on this machine diff --git a/sys/arch/i386/include/hibernate.h b/sys/arch/i386/include/hibernate.h index 352de896b7c..8efe8d2e31c 100644 --- a/sys/arch/i386/include/hibernate.h +++ b/sys/arch/i386/include/hibernate.h @@ -19,5 +19,6 @@ /* i386 hibernate support structures and functions */ int get_hibernate_info_md(union hibernate_info *); +int hibernate_zlib_reset(int); int hibernate_suspend(void); void hibernate_resume(void); diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c index 41767cc3abf..60db171c1ac 100644 --- a/sys/kern/subr_hibernate.c +++ b/sys/kern/subr_hibernate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_hibernate.c,v 1.8 2011/07/09 00:08:04 mlarkin Exp $ */ +/* $OpenBSD: subr_hibernate.c,v 1.9 2011/07/09 00:27:31 mlarkin Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -28,6 +28,8 @@ extern char *disk_readlabel(struct disklabel *, dev_t, char *, size_t); +struct hibernate_state *hibernate_state; + /* * Hib alloc enforced alignment. */ @@ -594,3 +596,28 @@ get_hibernate_info(union hibernate_info *hiber_info) return get_hibernate_info_md(hiber_info); } + +/* + * hibernate_zlib_alloc + * + * Allocate nitems*size bytes from the hiballoc area presently in use + * + */ +void +*hibernate_zlib_alloc(void *unused, int nitems, int size) +{ + return hib_alloc(&hibernate_state->hiballoc_arena, nitems*size); +} + +/* + * hibernate_zlib_free + * + * Free the memory pointed to by addr in the hiballoc area presently in + * use + * + */ +void +hibernate_zlib_free(void *unused, void *addr) +{ + hib_free(&hibernate_state->hiballoc_arena, addr); +} diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h index 275a8edb9ce..354f1a038c9 100644 --- a/sys/sys/hibernate.h +++ b/sys/sys/hibernate.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hibernate.h,v 1.7 2011/07/09 00:08:04 mlarkin Exp $ */ +/* $OpenBSD: hibernate.h,v 1.8 2011/07/09 00:27:31 mlarkin Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -114,4 +114,7 @@ psize_t uvm_page_rle(paddr_t); void *get_hibernate_io_function(void); int get_hibernate_info(union hibernate_info *); +void *hibernate_zlib_alloc(void *, int, int); +void hibernate_zlib_free(void *, void *); + #endif /* _SYS_HIBERNATE_H_ */ |