Deleted Added
full compact
imgact_gzip.c (220373) imgact_gzip.c (231885)
1/*-
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 */

--- 8 unchanged lines hidden (view full) ---

17 * should handle the entire header of gzip'ed stuff.
18 * inflate isn't quite reentrant yet...
19 * error-handling is a mess...
20 * so is the rest...
21 * tidy up unnecesary includes
22 */
23
24#include <sys/cdefs.h>
1/*-
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 */

--- 8 unchanged lines hidden (view full) ---

17 * should handle the entire header of gzip'ed stuff.
18 * inflate isn't quite reentrant yet...
19 * error-handling is a mess...
20 * so is the rest...
21 * tidy up unnecesary includes
22 */
23
24#include <sys/cdefs.h>
25__FBSDID("$FreeBSD: head/sys/kern/imgact_gzip.c 220373 2011-04-05 20:23:59Z trasz $");
25__FBSDID("$FreeBSD: head/sys/kern/imgact_gzip.c 231885 2012-02-17 23:47:16Z kib $");
26
27#include <sys/param.h>
28#include <sys/exec.h>
29#include <sys/imgact.h>
30#include <sys/imgact_aout.h>
31#include <sys/kernel.h>
32#include <sys/lock.h>
33#include <sys/mman.h>

--- 31 unchanged lines hidden (view full) ---

65static int NextByte(void *vp);
66static int do_aout_hdr(struct imgact_gzip *);
67static int Flush(void *vp, u_char *, u_long siz);
68
69static int
70exec_gzip_imgact(imgp)
71 struct image_params *imgp;
72{
26
27#include <sys/param.h>
28#include <sys/exec.h>
29#include <sys/imgact.h>
30#include <sys/imgact_aout.h>
31#include <sys/kernel.h>
32#include <sys/lock.h>
33#include <sys/mman.h>

--- 31 unchanged lines hidden (view full) ---

65static int NextByte(void *vp);
66static int do_aout_hdr(struct imgact_gzip *);
67static int Flush(void *vp, u_char *, u_long siz);
68
69static int
70exec_gzip_imgact(imgp)
71 struct image_params *imgp;
72{
73 int error, error2 = 0;
73 int error;
74 const u_char *p = (const u_char *) imgp->image_header;
75 struct imgact_gzip igz;
76 struct inflate infl;
77 struct vmspace *vmspace;
78
79 /* If these four are not OK, it isn't a gzip file */
80 if (p[0] != 0x1f)
81 return -1; /* 0 Simply magic */

--- 49 unchanged lines hidden (view full) ---

131 vmspace = imgp->proc->p_vmspace;
132 error = vm_map_protect(&vmspace->vm_map,
133 (vm_offset_t) vmspace->vm_taddr,
134 (vm_offset_t) (vmspace->vm_taddr +
135 (vmspace->vm_tsize << PAGE_SHIFT)) ,
136 VM_PROT_READ|VM_PROT_EXECUTE,0);
137 }
138
74 const u_char *p = (const u_char *) imgp->image_header;
75 struct imgact_gzip igz;
76 struct inflate infl;
77 struct vmspace *vmspace;
78
79 /* If these four are not OK, it isn't a gzip file */
80 if (p[0] != 0x1f)
81 return -1; /* 0 Simply magic */

--- 49 unchanged lines hidden (view full) ---

131 vmspace = imgp->proc->p_vmspace;
132 error = vm_map_protect(&vmspace->vm_map,
133 (vm_offset_t) vmspace->vm_taddr,
134 (vm_offset_t) (vmspace->vm_taddr +
135 (vmspace->vm_tsize << PAGE_SHIFT)) ,
136 VM_PROT_READ|VM_PROT_EXECUTE,0);
137 }
138
139 if (igz.inbuf) {
140 error2 =
141 vm_map_remove(kernel_map, (vm_offset_t) igz.inbuf,
142 (vm_offset_t) igz.inbuf + PAGE_SIZE);
143 }
144 if (igz.error || error || error2) {
139 if (igz.inbuf)
140 kmem_free_wakeup(exec_map, (vm_offset_t)igz.inbuf, PAGE_SIZE);
141 if (igz.error || error) {
145 printf("Output=%lu ", igz.output);
142 printf("Output=%lu ", igz.output);
146 printf("Inflate_error=%d igz.error=%d error2=%d where=%d\n",
147 error, igz.error, error2, igz.where);
143 printf("Inflate_error=%d igz.error=%d where=%d\n",
144 error, igz.error, igz.where);
148 }
149 if (igz.error)
150 return igz.error;
151 if (error)
152 return ENOEXEC;
145 }
146 if (igz.error)
147 return igz.error;
148 if (error)
149 return ENOEXEC;
153 if (error2)
154 return error2;
155 return 0;
156}
157
158static int
159do_aout_hdr(struct imgact_gzip * gz)
160{
161 int error;
162 struct vmspace *vmspace;

--- 146 unchanged lines hidden (view full) ---

309
310 if (igz->idx >= igz->len) {
311 igz->where = __LINE__;
312 return GZ_EOF;
313 }
314 if (igz->inbuf && igz->idx < (igz->offset + PAGE_SIZE)) {
315 return igz->inbuf[(igz->idx++) - igz->offset];
316 }
150 return 0;
151}
152
153static int
154do_aout_hdr(struct imgact_gzip * gz)
155{
156 int error;
157 struct vmspace *vmspace;

--- 146 unchanged lines hidden (view full) ---

304
305 if (igz->idx >= igz->len) {
306 igz->where = __LINE__;
307 return GZ_EOF;
308 }
309 if (igz->inbuf && igz->idx < (igz->offset + PAGE_SIZE)) {
310 return igz->inbuf[(igz->idx++) - igz->offset];
311 }
317 if (igz->inbuf) {
318 error = vm_map_remove(kernel_map, (vm_offset_t) igz->inbuf,
319 (vm_offset_t) igz->inbuf + PAGE_SIZE);
320 if (error) {
321 igz->where = __LINE__;
322 igz->error = error;
323 return GZ_EOF;
324 }
325 }
312 if (igz->inbuf)
313 kmem_free_wakeup(exec_map, (vm_offset_t)igz->inbuf, PAGE_SIZE);
326 igz->offset = igz->idx & ~PAGE_MASK;
327
314 igz->offset = igz->idx & ~PAGE_MASK;
315
328 error = vm_mmap(kernel_map, /* map */
316 error = vm_mmap(exec_map, /* map */
329 (vm_offset_t *) & igz->inbuf, /* address */
330 PAGE_SIZE, /* size */
331 VM_PROT_READ, /* protection */
332 VM_PROT_READ, /* max protection */
333 0, /* flags */
334 OBJT_VNODE, /* handle type */
335 igz->ip->vp, /* vnode */
336 igz->offset); /* offset */

--- 69 unchanged lines hidden ---
317 (vm_offset_t *) & igz->inbuf, /* address */
318 PAGE_SIZE, /* size */
319 VM_PROT_READ, /* protection */
320 VM_PROT_READ, /* max protection */
321 0, /* flags */
322 OBJT_VNODE, /* handle type */
323 igz->ip->vp, /* vnode */
324 igz->offset); /* offset */

--- 69 unchanged lines hidden ---