Deleted Added
full compact
linux_misc.c (230132) linux_misc.c (231885)
1/*-
2 * Copyright (c) 2002 Doug Rabson
3 * Copyright (c) 1994-1995 S��ren Schmidt
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002 Doug Rabson
3 * Copyright (c) 1994-1995 S��ren Schmidt
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/compat/linux/linux_misc.c 230132 2012-01-15 13:23:18Z uqs $");
31__FBSDID("$FreeBSD: head/sys/compat/linux/linux_misc.c 231885 2012-02-17 23:47:16Z kib $");
32
33#include "opt_compat.h"
34
35#include <sys/param.h>
36#include <sys/blist.h>
37#include <sys/fcntl.h>
38#if defined(__i386__)
39#include <sys/imgact_aout.h>

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

224linux_uselib(struct thread *td, struct linux_uselib_args *args)
225{
226 struct nameidata ni;
227 struct vnode *vp;
228 struct exec *a_out;
229 struct vattr attr;
230 vm_offset_t vmaddr;
231 unsigned long file_offset;
32
33#include "opt_compat.h"
34
35#include <sys/param.h>
36#include <sys/blist.h>
37#include <sys/fcntl.h>
38#if defined(__i386__)
39#include <sys/imgact_aout.h>

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

224linux_uselib(struct thread *td, struct linux_uselib_args *args)
225{
226 struct nameidata ni;
227 struct vnode *vp;
228 struct exec *a_out;
229 struct vattr attr;
230 vm_offset_t vmaddr;
231 unsigned long file_offset;
232 vm_offset_t buffer;
233 unsigned long bss_size;
234 char *library;
232 unsigned long bss_size;
233 char *library;
234 ssize_t aresid;
235 int error;
236 int locked, vfslocked;
237
238 LCONVPATHEXIST(td, args->library, &library);
239
240#ifdef DEBUG
241 if (ldebug(uselib))
242 printf(ARGS(uselib, "%s"), library);

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

303 error = mac_vnode_check_open(td->td_ucred, vp, VREAD);
304 if (error)
305 goto cleanup;
306#endif
307 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
308 if (error)
309 goto cleanup;
310
235 int error;
236 int locked, vfslocked;
237
238 LCONVPATHEXIST(td, args->library, &library);
239
240#ifdef DEBUG
241 if (ldebug(uselib))
242 printf(ARGS(uselib, "%s"), library);

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

303 error = mac_vnode_check_open(td->td_ucred, vp, VREAD);
304 if (error)
305 goto cleanup;
306#endif
307 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
308 if (error)
309 goto cleanup;
310
311 /* Pull in executable header into kernel_map */
312 error = vm_mmap(kernel_map, (vm_offset_t *)&a_out, PAGE_SIZE,
311 /* Pull in executable header into exec_map */
312 error = vm_mmap(exec_map, (vm_offset_t *)&a_out, PAGE_SIZE,
313 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp, 0);
314 if (error)
315 goto cleanup;
316
317 /* Is it a Linux binary ? */
318 if (((a_out->a_magic >> 16) & 0xff) != 0x64) {
319 error = ENOEXEC;
320 goto cleanup;

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

397
398 /* get anon user mapping, read+write+execute */
399 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
400 &vmaddr, a_out->a_text + a_out->a_data, FALSE, VM_PROT_ALL,
401 VM_PROT_ALL, 0);
402 if (error)
403 goto cleanup;
404
313 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp, 0);
314 if (error)
315 goto cleanup;
316
317 /* Is it a Linux binary ? */
318 if (((a_out->a_magic >> 16) & 0xff) != 0x64) {
319 error = ENOEXEC;
320 goto cleanup;

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

397
398 /* get anon user mapping, read+write+execute */
399 error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
400 &vmaddr, a_out->a_text + a_out->a_data, FALSE, VM_PROT_ALL,
401 VM_PROT_ALL, 0);
402 if (error)
403 goto cleanup;
404
405 /* map file into kernel_map */
406 error = vm_mmap(kernel_map, &buffer,
407 round_page(a_out->a_text + a_out->a_data + file_offset),
408 VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp,
409 trunc_page(file_offset));
410 if (error)
405 error = vn_rdwr(UIO_READ, vp, (void *)vmaddr, file_offset,
406 a_out->a_text + a_out->a_data, UIO_USERSPACE, 0,
407 td->td_ucred, NOCRED, &aresid, td);
408 if (error != 0)
411 goto cleanup;
409 goto cleanup;
412
413 /* copy from kernel VM space to user space */
414 error = copyout(PTRIN(buffer + file_offset),
415 (void *)vmaddr, a_out->a_text + a_out->a_data);
416
417 /* release temporary kernel space */
418 vm_map_remove(kernel_map, buffer, buffer +
419 round_page(a_out->a_text + a_out->a_data + file_offset));
420
421 if (error)
410 if (aresid != 0) {
411 error = ENOEXEC;
422 goto cleanup;
412 goto cleanup;
413 }
423 } else {
424#ifdef DEBUG
425 printf("uselib: Page aligned binary %lu\n", file_offset);
426#endif
427 /*
428 * for QMAGIC, a_entry is 20 bytes beyond the load address
429 * to skip the executable header
430 */

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

458
459cleanup:
460 /* Unlock vnode if needed */
461 if (locked) {
462 VOP_UNLOCK(vp, 0);
463 VFS_UNLOCK_GIANT(vfslocked);
464 }
465
414 } else {
415#ifdef DEBUG
416 printf("uselib: Page aligned binary %lu\n", file_offset);
417#endif
418 /*
419 * for QMAGIC, a_entry is 20 bytes beyond the load address
420 * to skip the executable header
421 */

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

449
450cleanup:
451 /* Unlock vnode if needed */
452 if (locked) {
453 VOP_UNLOCK(vp, 0);
454 VFS_UNLOCK_GIANT(vfslocked);
455 }
456
466 /* Release the kernel mapping. */
457 /* Release the temporary mapping. */
467 if (a_out)
458 if (a_out)
468 vm_map_remove(kernel_map, (vm_offset_t)a_out,
469 (vm_offset_t)a_out + PAGE_SIZE);
459 kmem_free_wakeup(exec_map, (vm_offset_t)a_out, PAGE_SIZE);
470
471 return (error);
472}
473
474#endif /* __i386__ */
475
476int
477linux_select(struct thread *td, struct linux_select_args *args)

--- 1449 unchanged lines hidden ---
460
461 return (error);
462}
463
464#endif /* __i386__ */
465
466int
467linux_select(struct thread *td, struct linux_select_args *args)

--- 1449 unchanged lines hidden ---