-static vm_offset_t image_ptr = NULL; /* the image itself */
-static off_t image_size = 0; /* and the imagesize */
-
-
-__private_extern__ void
-get_panicimage(vm_offset_t *imageptr, vm_size_t *imagesize, int *imagebits)
-{
- *imageptr = image_ptr;
- *imagesize = image_size;
- *imagebits = image_bits;
-}
-
-static int
-panicimage_from_file(
- char *imname,
- off_t sizelimit,
- vm_offset_t *image,
- off_t *filesize,
- struct proc *p)
-{
- int error = 0;
- int error1 = 0;
- int aresid;
- struct nameidata nd;
- struct vattr vattr;
- struct vnode * vp;
- kern_return_t kret;
- struct pcred *pcred = p->p_cred;
- struct ucred *cred = pcred->pc_ucred;
- vm_offset_t iobuf;
-
- /* Open the file */
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, imname, p);
- error = vn_open(&nd, FREAD, S_IRUSR);
- if (error)
- return (error);
- vp = nd.ni_vp;
-
- if (vp->v_type != VREG) {
- error = EFAULT;
- goto out;
- }
-
- /* get the file size */
- error = VOP_GETATTR(vp, &vattr, cred, p);
- if (error)
- goto out;
-
- /* validate the file size */
- if (vattr.va_size > sizelimit) {
- error = EFBIG;
- goto out;
- }
-
- /* allocate kernel wired memory */
- kret = kmem_alloc_wired(kernel_map, &iobuf,
- (vm_size_t)vattr.va_size);
- if (kret != KERN_SUCCESS) {
- switch (kret) {
- default:
- error = EINVAL;
- break;
- case KERN_NO_SPACE:
- case KERN_RESOURCE_SHORTAGE:
- error = ENOMEM;
- break;
- case KERN_PROTECTION_FAILURE:
- error = EPERM;
- break;
- }
- goto out;
- }
-
- /* read the file in the kernel buffer */
- error = vn_rdwr(UIO_READ, vp, (caddr_t)iobuf, (int)vattr.va_size,
- (off_t)0, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT,
- cred, &aresid, p);
- if (error) {
- (void)kmem_free(kernel_map, iobuf, (vm_size_t)vattr.va_size);
- goto out;
- }
-
- /*
- * return the image to the caller
- * freeing this memory is callers responsibility
- */
- *image = iobuf;
- *filesize = (off_t)vattr.va_size;
-
-out:
- VOP_UNLOCK(vp, 0, p);
- error1 = vn_close(vp, FREAD, cred, p);
- if (error == 0)
- error = error1;
- return (error);
-}