2 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Derived from sys_sparc32.c.
4 * Copyright (C) 2000 VA Linux Co
5 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
6 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
9 * Copyright (C) 2000-2003, 2005 Hewlett-Packard Co
10 * David Mosberger-Tang <davidm@hpl.hp.com>
11 * Copyright (C) 2004 Gordon Jin <gordon.jin@intel.com>
13 * These routines maintain argument size conversion between 32bit and 64bit
17 #include <linux/kernel.h>
18 #include <linux/syscalls.h>
19 #include <linux/sysctl.h>
20 #include <linux/sched.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/resource.h>
25 #include <linux/times.h>
26 #include <linux/utsname.h>
27 #include <linux/smp.h>
28 #include <linux/smp_lock.h>
29 #include <linux/sem.h>
30 #include <linux/msg.h>
32 #include <linux/shm.h>
33 #include <linux/slab.h>
34 #include <linux/uio.h>
35 #include <linux/socket.h>
36 #include <linux/quota.h>
37 #include <linux/poll.h>
38 #include <linux/eventpoll.h>
39 #include <linux/personality.h>
40 #include <linux/ptrace.h>
41 #include <linux/regset.h>
42 #include <linux/stat.h>
43 #include <linux/ipc.h>
44 #include <linux/capability.h>
45 #include <linux/compat.h>
46 #include <linux/vfs.h>
47 #include <linux/mman.h>
48 #include <linux/mutex.h>
50 #include <asm/intrinsics.h>
51 #include <asm/types.h>
52 #include <asm/uaccess.h>
53 #include <asm/unistd.h>
63 # define DBG(fmt...) printk(KERN_DEBUG fmt)
68 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
70 #define OFFSET4K(a) ((a) & 0xfff)
71 #define PAGE_START(addr) ((addr) & PAGE_MASK)
72 #define MINSIGSTKSZ_IA32 2048
74 #define high2lowuid(uid) ((uid) > 65535 ? 65534 : (uid))
75 #define high2lowgid(gid) ((gid) > 65535 ? 65534 : (gid))
78 * Anything that modifies or inspects ia32 user virtual memory must hold this semaphore
81 /* XXX make per-mm: */
82 static DEFINE_MUTEX(ia32_mmap_mutex
);
85 sys32_execve (char __user
*name
, compat_uptr_t __user
*argv
, compat_uptr_t __user
*envp
,
90 unsigned long old_map_base
, old_task_size
, tssd
;
92 filename
= getname(name
);
93 error
= PTR_ERR(filename
);
97 old_map_base
= current
->thread
.map_base
;
98 old_task_size
= current
->thread
.task_size
;
99 tssd
= ia64_get_kr(IA64_KR_TSSD
);
101 /* we may be exec'ing a 64-bit process: reset map base, task-size, and io-base: */
102 current
->thread
.map_base
= DEFAULT_MAP_BASE
;
103 current
->thread
.task_size
= DEFAULT_TASK_SIZE
;
104 ia64_set_kr(IA64_KR_IO_BASE
, current
->thread
.old_iob
);
105 ia64_set_kr(IA64_KR_TSSD
, current
->thread
.old_k1
);
107 error
= compat_do_execve(filename
, argv
, envp
, regs
);
111 /* oops, execve failed, switch back to old values... */
112 ia64_set_kr(IA64_KR_IO_BASE
, IA32_IOBASE
);
113 ia64_set_kr(IA64_KR_TSSD
, tssd
);
114 current
->thread
.map_base
= old_map_base
;
115 current
->thread
.task_size
= old_task_size
;
122 #if PAGE_SHIFT > IA32_PAGE_SHIFT
126 get_page_prot (struct vm_area_struct
*vma
, unsigned long addr
)
130 if (!vma
|| vma
->vm_start
> addr
)
133 if (vma
->vm_flags
& VM_READ
)
135 if (vma
->vm_flags
& VM_WRITE
)
137 if (vma
->vm_flags
& VM_EXEC
)
143 * Map a subpage by creating an anonymous page that contains the union of the old page and
147 mmap_subpage (struct file
*file
, unsigned long start
, unsigned long end
, int prot
, int flags
,
152 unsigned long ret
= 0;
153 struct vm_area_struct
*vma
= find_vma(current
->mm
, start
);
154 int old_prot
= get_page_prot(vma
, start
);
156 DBG("mmap_subpage(file=%p,start=0x%lx,end=0x%lx,prot=%x,flags=%x,off=0x%llx)\n",
157 file
, start
, end
, prot
, flags
, off
);
160 /* Optimize the case where the old mmap and the new mmap are both anonymous */
161 if ((old_prot
& PROT_WRITE
) && (flags
& MAP_ANONYMOUS
) && !vma
->vm_file
) {
162 if (clear_user((void __user
*) start
, end
- start
)) {
169 page
= (void *) get_zeroed_page(GFP_KERNEL
);
174 copy_from_user(page
, (void __user
*) PAGE_START(start
), PAGE_SIZE
);
176 down_write(¤t
->mm
->mmap_sem
);
178 ret
= do_mmap(NULL
, PAGE_START(start
), PAGE_SIZE
, prot
| PROT_WRITE
,
179 flags
| MAP_FIXED
| MAP_ANONYMOUS
, 0);
181 up_write(¤t
->mm
->mmap_sem
);
183 if (IS_ERR((void *) ret
))
187 /* copy back the old page contents. */
188 if (offset_in_page(start
))
189 copy_to_user((void __user
*) PAGE_START(start
), page
,
190 offset_in_page(start
));
191 if (offset_in_page(end
))
192 copy_to_user((void __user
*) end
, page
+ offset_in_page(end
),
193 PAGE_SIZE
- offset_in_page(end
));
196 if (!(flags
& MAP_ANONYMOUS
)) {
197 /* read the file contents */
198 inode
= file
->f_path
.dentry
->d_inode
;
199 if (!inode
->i_fop
|| !file
->f_op
->read
200 || ((*file
->f_op
->read
)(file
, (char __user
*) start
, end
- start
, &off
) < 0))
208 if (!(prot
& PROT_WRITE
))
209 ret
= sys_mprotect(PAGE_START(start
), PAGE_SIZE
, prot
| old_prot
);
212 free_page((unsigned long) page
);
216 /* SLAB cache for ia64_partial_page structures */
217 struct kmem_cache
*ia64_partial_page_cachep
;
220 * init ia64_partial_page_list.
221 * return 0 means kmalloc fail.
223 struct ia64_partial_page_list
*
224 ia32_init_pp_list(void)
226 struct ia64_partial_page_list
*p
;
228 if ((p
= kmalloc(sizeof(*p
), GFP_KERNEL
)) == NULL
)
233 atomic_set(&p
->pp_count
, 1);
238 * Search for the partial page with @start in partial page list @ppl.
239 * If finds the partial page, return the found partial page.
240 * Else, return 0 and provide @pprev, @rb_link, @rb_parent to
241 * be used by later __ia32_insert_pp().
243 static struct ia64_partial_page
*
244 __ia32_find_pp(struct ia64_partial_page_list
*ppl
, unsigned int start
,
245 struct ia64_partial_page
**pprev
, struct rb_node
***rb_link
,
246 struct rb_node
**rb_parent
)
248 struct ia64_partial_page
*pp
;
249 struct rb_node
**__rb_link
, *__rb_parent
, *rb_prev
;
252 if (pp
&& pp
->base
== start
)
255 __rb_link
= &ppl
->ppl_rb
.rb_node
;
256 rb_prev
= __rb_parent
= NULL
;
259 __rb_parent
= *__rb_link
;
260 pp
= rb_entry(__rb_parent
, struct ia64_partial_page
, pp_rb
);
262 if (pp
->base
== start
) {
265 } else if (pp
->base
< start
) {
266 rb_prev
= __rb_parent
;
267 __rb_link
= &__rb_parent
->rb_right
;
269 __rb_link
= &__rb_parent
->rb_left
;
273 *rb_link
= __rb_link
;
274 *rb_parent
= __rb_parent
;
277 *pprev
= rb_entry(rb_prev
, struct ia64_partial_page
, pp_rb
);
282 * insert @pp into @ppl.
285 __ia32_insert_pp(struct ia64_partial_page_list
*ppl
,
286 struct ia64_partial_page
*pp
, struct ia64_partial_page
*prev
,
287 struct rb_node
**rb_link
, struct rb_node
*rb_parent
)
291 pp
->next
= prev
->next
;
296 pp
->next
= rb_entry(rb_parent
,
297 struct ia64_partial_page
, pp_rb
);
303 rb_link_node(&pp
->pp_rb
, rb_parent
, rb_link
);
304 rb_insert_color(&pp
->pp_rb
, &ppl
->ppl_rb
);
310 * delete @pp from partial page list @ppl.
313 __ia32_delete_pp(struct ia64_partial_page_list
*ppl
,
314 struct ia64_partial_page
*pp
, struct ia64_partial_page
*prev
)
317 prev
->next
= pp
->next
;
318 if (ppl
->pp_hint
== pp
)
321 ppl
->pp_head
= pp
->next
;
322 if (ppl
->pp_hint
== pp
)
323 ppl
->pp_hint
= pp
->next
;
325 rb_erase(&pp
->pp_rb
, &ppl
->ppl_rb
);
326 kmem_cache_free(ia64_partial_page_cachep
, pp
);
329 static struct ia64_partial_page
*
330 __pp_prev(struct ia64_partial_page
*pp
)
332 struct rb_node
*prev
= rb_prev(&pp
->pp_rb
);
334 return rb_entry(prev
, struct ia64_partial_page
, pp_rb
);
340 * Delete partial pages with address between @start and @end.
341 * @start and @end are page aligned.
344 __ia32_delete_pp_range(unsigned int start
, unsigned int end
)
346 struct ia64_partial_page
*pp
, *prev
;
347 struct rb_node
**rb_link
, *rb_parent
;
352 pp
= __ia32_find_pp(current
->thread
.ppl
, start
, &prev
,
353 &rb_link
, &rb_parent
);
355 prev
= __pp_prev(pp
);
360 pp
= current
->thread
.ppl
->pp_head
;
363 while (pp
&& pp
->base
< end
) {
364 struct ia64_partial_page
*tmp
= pp
->next
;
365 __ia32_delete_pp(current
->thread
.ppl
, pp
, prev
);
371 * Set the range between @start and @end in bitmap.
372 * @start and @end should be IA32 page aligned and in the same IA64 page.
375 __ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
377 struct ia64_partial_page
*pp
, *prev
;
378 struct rb_node
** rb_link
, *rb_parent
;
379 unsigned int pstart
, start_bit
, end_bit
, i
;
381 pstart
= PAGE_START(start
);
382 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
383 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
385 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
386 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
387 &rb_link
, &rb_parent
);
389 for (i
= start_bit
; i
< end_bit
; i
++)
390 set_bit(i
, &pp
->bitmap
);
392 * Check: if this partial page has been set to a full page,
395 if (find_first_zero_bit(&pp
->bitmap
, sizeof(pp
->bitmap
)*8) >=
396 PAGE_SIZE
/IA32_PAGE_SIZE
) {
397 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
403 * MAP_FIXED may lead to overlapping mmap.
404 * In this case, the requested mmap area may already mmaped as a full
405 * page. So check vma before adding a new partial page.
407 if (flags
& MAP_FIXED
) {
408 struct vm_area_struct
*vma
= find_vma(current
->mm
, pstart
);
409 if (vma
&& vma
->vm_start
<= pstart
)
413 /* new a ia64_partial_page */
414 pp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
419 for (i
=start_bit
; i
<end_bit
; i
++)
420 set_bit(i
, &(pp
->bitmap
));
422 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
427 * @start and @end should be IA32 page aligned, but don't need to be in the
428 * same IA64 page. Split @start and @end to make sure they're in the same IA64
429 * page, then call __ia32_set_pp().
432 ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
434 down_write(¤t
->mm
->mmap_sem
);
435 if (flags
& MAP_FIXED
) {
437 * MAP_FIXED may lead to overlapping mmap. When this happens,
438 * a series of complete IA64 pages results in deletion of
439 * old partial pages in that range.
441 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
444 if (end
< PAGE_ALIGN(start
)) {
445 __ia32_set_pp(start
, end
, flags
);
447 if (offset_in_page(start
))
448 __ia32_set_pp(start
, PAGE_ALIGN(start
), flags
);
449 if (offset_in_page(end
))
450 __ia32_set_pp(PAGE_START(end
), end
, flags
);
452 up_write(¤t
->mm
->mmap_sem
);
456 * Unset the range between @start and @end in bitmap.
457 * @start and @end should be IA32 page aligned and in the same IA64 page.
458 * After doing that, if the bitmap is 0, then free the page and return 1,
460 * If not find the partial page in the list, then
461 * If the vma exists, then the full page is set to a partial page;
462 * Else return -ENOMEM.
465 __ia32_unset_pp(unsigned int start
, unsigned int end
)
467 struct ia64_partial_page
*pp
, *prev
;
468 struct rb_node
** rb_link
, *rb_parent
;
469 unsigned int pstart
, start_bit
, end_bit
, i
;
470 struct vm_area_struct
*vma
;
472 pstart
= PAGE_START(start
);
473 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
474 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
476 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
478 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
479 &rb_link
, &rb_parent
);
481 for (i
= start_bit
; i
< end_bit
; i
++)
482 clear_bit(i
, &pp
->bitmap
);
483 if (pp
->bitmap
== 0) {
484 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
490 vma
= find_vma(current
->mm
, pstart
);
491 if (!vma
|| vma
->vm_start
> pstart
) {
495 /* new a ia64_partial_page */
496 pp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
501 for (i
= 0; i
< start_bit
; i
++)
502 set_bit(i
, &(pp
->bitmap
));
503 for (i
= end_bit
; i
< PAGE_SIZE
/ IA32_PAGE_SIZE
; i
++)
504 set_bit(i
, &(pp
->bitmap
));
506 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
511 * Delete pp between PAGE_ALIGN(start) and PAGE_START(end) by calling
512 * __ia32_delete_pp_range(). Unset possible partial pages by calling
514 * The returned value see __ia32_unset_pp().
517 ia32_unset_pp(unsigned int *startp
, unsigned int *endp
)
519 unsigned int start
= *startp
, end
= *endp
;
522 down_write(¤t
->mm
->mmap_sem
);
524 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
526 if (end
< PAGE_ALIGN(start
)) {
527 ret
= __ia32_unset_pp(start
, end
);
529 *startp
= PAGE_START(start
);
530 *endp
= PAGE_ALIGN(end
);
533 /* to shortcut sys_munmap() in sys32_munmap() */
534 *startp
= PAGE_START(start
);
535 *endp
= PAGE_START(end
);
538 if (offset_in_page(start
)) {
539 ret
= __ia32_unset_pp(start
, PAGE_ALIGN(start
));
541 *startp
= PAGE_START(start
);
543 *startp
= PAGE_ALIGN(start
);
547 if (offset_in_page(end
)) {
548 ret
= __ia32_unset_pp(PAGE_START(end
), end
);
550 *endp
= PAGE_ALIGN(end
);
552 *endp
= PAGE_START(end
);
557 up_write(¤t
->mm
->mmap_sem
);
562 * Compare the range between @start and @end with bitmap in partial page.
563 * @start and @end should be IA32 page aligned and in the same IA64 page.
566 __ia32_compare_pp(unsigned int start
, unsigned int end
)
568 struct ia64_partial_page
*pp
, *prev
;
569 struct rb_node
** rb_link
, *rb_parent
;
570 unsigned int pstart
, start_bit
, end_bit
, size
;
571 unsigned int first_bit
, next_zero_bit
; /* the first range in bitmap */
573 pstart
= PAGE_START(start
);
575 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
576 &rb_link
, &rb_parent
);
580 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
581 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
582 size
= sizeof(pp
->bitmap
) * 8;
583 first_bit
= find_first_bit(&pp
->bitmap
, size
);
584 next_zero_bit
= find_next_zero_bit(&pp
->bitmap
, size
, first_bit
);
585 if ((start_bit
< first_bit
) || (end_bit
> next_zero_bit
)) {
586 /* exceeds the first range in bitmap */
588 } else if ((start_bit
== first_bit
) && (end_bit
== next_zero_bit
)) {
589 first_bit
= find_next_bit(&pp
->bitmap
, size
, next_zero_bit
);
590 if ((next_zero_bit
< first_bit
) && (first_bit
< size
))
591 return 1; /* has next range */
593 return 0; /* no next range */
599 * @start and @end should be IA32 page aligned, but don't need to be in the
600 * same IA64 page. Split @start and @end to make sure they're in the same IA64
601 * page, then call __ia32_compare_pp().
603 * Take this as example: the range is the 1st and 2nd 4K page.
604 * Return 0 if they fit bitmap exactly, i.e. bitmap = 00000011;
605 * Return 1 if the range doesn't cover whole bitmap, e.g. bitmap = 00001111;
606 * Return -ENOMEM if the range exceeds the bitmap, e.g. bitmap = 00000001 or
610 ia32_compare_pp(unsigned int *startp
, unsigned int *endp
)
612 unsigned int start
= *startp
, end
= *endp
;
615 down_write(¤t
->mm
->mmap_sem
);
617 if (end
< PAGE_ALIGN(start
)) {
618 retval
= __ia32_compare_pp(start
, end
);
620 *startp
= PAGE_START(start
);
621 *endp
= PAGE_ALIGN(end
);
624 if (offset_in_page(start
)) {
625 retval
= __ia32_compare_pp(start
,
628 *startp
= PAGE_START(start
);
632 if (offset_in_page(end
)) {
633 retval
= __ia32_compare_pp(PAGE_START(end
), end
);
635 *endp
= PAGE_ALIGN(end
);
640 up_write(¤t
->mm
->mmap_sem
);
645 __ia32_drop_pp_list(struct ia64_partial_page_list
*ppl
)
647 struct ia64_partial_page
*pp
= ppl
->pp_head
;
650 struct ia64_partial_page
*next
= pp
->next
;
651 kmem_cache_free(ia64_partial_page_cachep
, pp
);
659 ia32_drop_ia64_partial_page_list(struct task_struct
*task
)
661 struct ia64_partial_page_list
* ppl
= task
->thread
.ppl
;
663 if (ppl
&& atomic_dec_and_test(&ppl
->pp_count
))
664 __ia32_drop_pp_list(ppl
);
668 * Copy current->thread.ppl to ppl (already initialized).
671 __ia32_copy_pp_list(struct ia64_partial_page_list
*ppl
)
673 struct ia64_partial_page
*pp
, *tmp
, *prev
;
674 struct rb_node
**rb_link
, *rb_parent
;
678 ppl
->ppl_rb
= RB_ROOT
;
679 rb_link
= &ppl
->ppl_rb
.rb_node
;
683 for (pp
= current
->thread
.ppl
->pp_head
; pp
; pp
= pp
->next
) {
684 tmp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
688 __ia32_insert_pp(ppl
, tmp
, prev
, rb_link
, rb_parent
);
690 rb_link
= &tmp
->pp_rb
.rb_right
;
691 rb_parent
= &tmp
->pp_rb
;
697 ia32_copy_ia64_partial_page_list(struct task_struct
*p
,
698 unsigned long clone_flags
)
702 if (clone_flags
& CLONE_VM
) {
703 atomic_inc(¤t
->thread
.ppl
->pp_count
);
704 p
->thread
.ppl
= current
->thread
.ppl
;
706 p
->thread
.ppl
= ia32_init_pp_list();
709 down_write(¤t
->mm
->mmap_sem
);
711 retval
= __ia32_copy_pp_list(p
->thread
.ppl
);
713 up_write(¤t
->mm
->mmap_sem
);
720 emulate_mmap (struct file
*file
, unsigned long start
, unsigned long len
, int prot
, int flags
,
723 unsigned long tmp
, end
, pend
, pstart
, ret
, is_congruent
, fudge
= 0;
728 pstart
= PAGE_START(start
);
729 pend
= PAGE_ALIGN(end
);
731 if (flags
& MAP_FIXED
) {
732 ia32_set_pp((unsigned int)start
, (unsigned int)end
, flags
);
733 if (start
> pstart
) {
734 if (flags
& MAP_SHARED
)
736 "%s(%d): emulate_mmap() can't share head (addr=0x%lx)\n",
737 current
->comm
, task_pid_nr(current
), start
);
738 ret
= mmap_subpage(file
, start
, min(PAGE_ALIGN(start
), end
), prot
, flags
,
740 if (IS_ERR((void *) ret
))
747 if (flags
& MAP_SHARED
)
749 "%s(%d): emulate_mmap() can't share tail (end=0x%lx)\n",
750 current
->comm
, task_pid_nr(current
), end
);
751 ret
= mmap_subpage(file
, max(start
, PAGE_START(end
)), end
, prot
, flags
,
752 (off
+ len
) - offset_in_page(end
));
753 if (IS_ERR((void *) ret
))
761 * If a start address was specified, use it if the entire rounded out area
764 if (start
&& !pstart
)
765 fudge
= 1; /* handle case of mapping to range (0,PAGE_SIZE) */
766 tmp
= arch_get_unmapped_area(file
, pstart
- fudge
, pend
- pstart
, 0, flags
);
769 start
= pstart
+ offset_in_page(off
); /* make start congruent with off */
771 pend
= PAGE_ALIGN(end
);
775 poff
= off
+ (pstart
- start
); /* note: (pstart - start) may be negative */
776 is_congruent
= (flags
& MAP_ANONYMOUS
) || (offset_in_page(poff
) == 0);
778 if ((flags
& MAP_SHARED
) && !is_congruent
)
779 printk(KERN_INFO
"%s(%d): emulate_mmap() can't share contents of incongruent mmap "
780 "(addr=0x%lx,off=0x%llx)\n", current
->comm
, task_pid_nr(current
), start
, off
);
782 DBG("mmap_body: mapping [0x%lx-0x%lx) %s with poff 0x%llx\n", pstart
, pend
,
783 is_congruent
? "congruent" : "not congruent", poff
);
785 down_write(¤t
->mm
->mmap_sem
);
787 if (!(flags
& MAP_ANONYMOUS
) && is_congruent
)
788 ret
= do_mmap(file
, pstart
, pend
- pstart
, prot
, flags
| MAP_FIXED
, poff
);
790 ret
= do_mmap(NULL
, pstart
, pend
- pstart
,
791 prot
| ((flags
& MAP_ANONYMOUS
) ? 0 : PROT_WRITE
),
792 flags
| MAP_FIXED
| MAP_ANONYMOUS
, 0);
794 up_write(¤t
->mm
->mmap_sem
);
796 if (IS_ERR((void *) ret
))
800 /* read the file contents */
801 inode
= file
->f_path
.dentry
->d_inode
;
802 if (!inode
->i_fop
|| !file
->f_op
->read
803 || ((*file
->f_op
->read
)(file
, (char __user
*) pstart
, pend
- pstart
, &poff
)
806 sys_munmap(pstart
, pend
- pstart
);
809 if (!(prot
& PROT_WRITE
) && sys_mprotect(pstart
, pend
- pstart
, prot
) < 0)
813 if (!(flags
& MAP_FIXED
))
814 ia32_set_pp((unsigned int)start
, (unsigned int)end
, flags
);
819 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
821 static inline unsigned int
822 get_prot32 (unsigned int prot
)
824 if (prot
& PROT_WRITE
)
825 /* on x86, PROT_WRITE implies PROT_READ which implies PROT_EEC */
826 prot
|= PROT_READ
| PROT_WRITE
| PROT_EXEC
;
827 else if (prot
& (PROT_READ
| PROT_EXEC
))
828 /* on x86, there is no distinction between PROT_READ and PROT_EXEC */
829 prot
|= (PROT_READ
| PROT_EXEC
);
835 ia32_do_mmap (struct file
*file
, unsigned long addr
, unsigned long len
, int prot
, int flags
,
838 DBG("ia32_do_mmap(file=%p,addr=0x%lx,len=0x%lx,prot=%x,flags=%x,offset=0x%llx)\n",
839 file
, addr
, len
, prot
, flags
, offset
);
841 if (file
&& (!file
->f_op
|| !file
->f_op
->mmap
))
844 len
= IA32_PAGE_ALIGN(len
);
848 if (len
> IA32_PAGE_OFFSET
|| addr
> IA32_PAGE_OFFSET
- len
)
850 if (flags
& MAP_FIXED
)
856 if (OFFSET4K(offset
))
859 prot
= get_prot32(prot
);
861 #if PAGE_SHIFT > IA32_PAGE_SHIFT
862 mutex_lock(&ia32_mmap_mutex
);
864 addr
= emulate_mmap(file
, addr
, len
, prot
, flags
, offset
);
866 mutex_unlock(&ia32_mmap_mutex
);
868 down_write(¤t
->mm
->mmap_sem
);
870 addr
= do_mmap(file
, addr
, len
, prot
, flags
, offset
);
872 up_write(¤t
->mm
->mmap_sem
);
874 DBG("ia32_do_mmap: returning 0x%lx\n", addr
);
879 * Linux/i386 didn't use to be able to handle more than 4 system call parameters, so these
880 * system calls used a memory block for parameter passing..
883 struct mmap_arg_struct
{
893 sys32_mmap (struct mmap_arg_struct __user
*arg
)
895 struct mmap_arg_struct a
;
896 struct file
*file
= NULL
;
900 if (copy_from_user(&a
, arg
, sizeof(a
)))
903 if (OFFSET4K(a
.offset
))
908 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
909 if (!(flags
& MAP_ANONYMOUS
)) {
915 addr
= ia32_do_mmap(file
, a
.addr
, a
.len
, a
.prot
, flags
, a
.offset
);
923 sys32_mmap2 (unsigned int addr
, unsigned int len
, unsigned int prot
, unsigned int flags
,
924 unsigned int fd
, unsigned int pgoff
)
926 struct file
*file
= NULL
;
927 unsigned long retval
;
929 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
930 if (!(flags
& MAP_ANONYMOUS
)) {
936 retval
= ia32_do_mmap(file
, addr
, len
, prot
, flags
,
937 (unsigned long) pgoff
<< IA32_PAGE_SHIFT
);
945 sys32_munmap (unsigned int start
, unsigned int len
)
947 unsigned int end
= start
+ len
;
950 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
951 ret
= sys_munmap(start
, end
- start
);
956 end
= IA32_PAGE_ALIGN(end
);
960 ret
= ia32_unset_pp(&start
, &end
);
967 mutex_lock(&ia32_mmap_mutex
);
968 ret
= sys_munmap(start
, end
- start
);
969 mutex_unlock(&ia32_mmap_mutex
);
974 #if PAGE_SHIFT > IA32_PAGE_SHIFT
977 * When mprotect()ing a partial page, we set the permission to the union of the old
978 * settings and the new settings. In other words, it's only possible to make access to a
979 * partial page less restrictive.
982 mprotect_subpage (unsigned long address
, int new_prot
)
985 struct vm_area_struct
*vma
;
987 if (new_prot
== PROT_NONE
)
988 return 0; /* optimize case where nothing changes... */
989 vma
= find_vma(current
->mm
, address
);
990 old_prot
= get_page_prot(vma
, address
);
991 return sys_mprotect(address
, PAGE_SIZE
, new_prot
| old_prot
);
994 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
997 sys32_mprotect (unsigned int start
, unsigned int len
, int prot
)
999 unsigned int end
= start
+ len
;
1000 #if PAGE_SHIFT > IA32_PAGE_SHIFT
1004 prot
= get_prot32(prot
);
1006 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1007 return sys_mprotect(start
, end
- start
, prot
);
1009 if (OFFSET4K(start
))
1012 end
= IA32_PAGE_ALIGN(end
);
1016 retval
= ia32_compare_pp(&start
, &end
);
1021 mutex_lock(&ia32_mmap_mutex
);
1023 if (offset_in_page(start
)) {
1024 /* start address is 4KB aligned but not page aligned. */
1025 retval
= mprotect_subpage(PAGE_START(start
), prot
);
1029 start
= PAGE_ALIGN(start
);
1031 goto out
; /* retval is already zero... */
1034 if (offset_in_page(end
)) {
1035 /* end address is 4KB aligned but not page aligned. */
1036 retval
= mprotect_subpage(PAGE_START(end
), prot
);
1040 end
= PAGE_START(end
);
1042 retval
= sys_mprotect(start
, end
- start
, prot
);
1045 mutex_unlock(&ia32_mmap_mutex
);
1051 sys32_mremap (unsigned int addr
, unsigned int old_len
, unsigned int new_len
,
1052 unsigned int flags
, unsigned int new_addr
)
1056 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1057 ret
= sys_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
1059 unsigned int old_end
, new_end
;
1064 old_len
= IA32_PAGE_ALIGN(old_len
);
1065 new_len
= IA32_PAGE_ALIGN(new_len
);
1066 old_end
= addr
+ old_len
;
1067 new_end
= addr
+ new_len
;
1072 if ((flags
& MREMAP_FIXED
) && (OFFSET4K(new_addr
)))
1075 if (old_len
>= new_len
) {
1076 ret
= sys32_munmap(addr
+ new_len
, old_len
- new_len
);
1077 if (ret
&& old_len
!= new_len
)
1080 if (!(flags
& MREMAP_FIXED
) || (new_addr
== addr
))
1085 addr
= PAGE_START(addr
);
1086 old_len
= PAGE_ALIGN(old_end
) - addr
;
1087 new_len
= PAGE_ALIGN(new_end
) - addr
;
1089 mutex_lock(&ia32_mmap_mutex
);
1090 ret
= sys_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
1091 mutex_unlock(&ia32_mmap_mutex
);
1093 if ((ret
>= 0) && (old_len
< new_len
)) {
1094 /* mremap expanded successfully */
1095 ia32_set_pp(old_end
, new_end
, flags
);
1101 asmlinkage
unsigned long
1102 sys32_alarm (unsigned int seconds
)
1104 return alarm_setitimer(seconds
);
1107 struct sel_arg_struct
{
1116 sys32_old_select (struct sel_arg_struct __user
*arg
)
1118 struct sel_arg_struct a
;
1120 if (copy_from_user(&a
, arg
, sizeof(a
)))
1122 return compat_sys_select(a
.n
, compat_ptr(a
.inp
), compat_ptr(a
.outp
),
1123 compat_ptr(a
.exp
), compat_ptr(a
.tvp
));
1129 #define SEMTIMEDOP 4
1140 sys32_ipc(u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
1144 version
= call
>> 16; /* hack for backward compatibility */
1150 return compat_sys_semtimedop(first
, compat_ptr(ptr
),
1151 second
, compat_ptr(fifth
));
1152 /* else fall through for normal semop() */
1154 /* struct sembuf is the same on 32 and 64bit :)) */
1155 return sys_semtimedop(first
, compat_ptr(ptr
), second
,
1158 return sys_semget(first
, second
, third
);
1160 return compat_sys_semctl(first
, second
, third
, compat_ptr(ptr
));
1163 return compat_sys_msgsnd(first
, second
, third
, compat_ptr(ptr
));
1165 return compat_sys_msgrcv(first
, second
, fifth
, third
, version
, compat_ptr(ptr
));
1167 return sys_msgget((key_t
) first
, second
);
1169 return compat_sys_msgctl(first
, second
, compat_ptr(ptr
));
1172 return compat_sys_shmat(first
, second
, third
, version
, compat_ptr(ptr
));
1175 return sys_shmdt(compat_ptr(ptr
));
1177 return sys_shmget(first
, (unsigned)second
, third
);
1179 return compat_sys_shmctl(first
, second
, compat_ptr(ptr
));
1188 compat_sys_wait4 (compat_pid_t pid
, compat_uint_t
* stat_addr
, int options
,
1189 struct compat_rusage
*ru
);
1192 sys32_waitpid (int pid
, unsigned int *stat_addr
, int options
)
1194 return compat_sys_wait4(pid
, stat_addr
, options
, NULL
);
1198 * The order in which registers are stored in the ptrace regs structure
1211 #define PT_ORIG_EAX 11
1219 getreg (struct task_struct
*child
, int regno
)
1221 struct pt_regs
*child_regs
;
1223 child_regs
= task_pt_regs(child
);
1224 switch (regno
/ sizeof(int)) {
1225 case PT_EBX
: return child_regs
->r11
;
1226 case PT_ECX
: return child_regs
->r9
;
1227 case PT_EDX
: return child_regs
->r10
;
1228 case PT_ESI
: return child_regs
->r14
;
1229 case PT_EDI
: return child_regs
->r15
;
1230 case PT_EBP
: return child_regs
->r13
;
1231 case PT_EAX
: return child_regs
->r8
;
1232 case PT_ORIG_EAX
: return child_regs
->r1
; /* see dispatch_to_ia32_handler() */
1233 case PT_EIP
: return child_regs
->cr_iip
;
1234 case PT_UESP
: return child_regs
->r12
;
1235 case PT_EFL
: return child
->thread
.eflag
;
1236 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1238 case PT_CS
: return __USER_CS
;
1240 printk(KERN_ERR
"ia32.getreg(): unknown register %d\n", regno
);
1247 putreg (struct task_struct
*child
, int regno
, unsigned int value
)
1249 struct pt_regs
*child_regs
;
1251 child_regs
= task_pt_regs(child
);
1252 switch (regno
/ sizeof(int)) {
1253 case PT_EBX
: child_regs
->r11
= value
; break;
1254 case PT_ECX
: child_regs
->r9
= value
; break;
1255 case PT_EDX
: child_regs
->r10
= value
; break;
1256 case PT_ESI
: child_regs
->r14
= value
; break;
1257 case PT_EDI
: child_regs
->r15
= value
; break;
1258 case PT_EBP
: child_regs
->r13
= value
; break;
1259 case PT_EAX
: child_regs
->r8
= value
; break;
1260 case PT_ORIG_EAX
: child_regs
->r1
= value
; break;
1261 case PT_EIP
: child_regs
->cr_iip
= value
; break;
1262 case PT_UESP
: child_regs
->r12
= value
; break;
1263 case PT_EFL
: child
->thread
.eflag
= value
; break;
1264 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1265 if (value
!= __USER_DS
)
1267 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1271 if (value
!= __USER_CS
)
1273 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1277 printk(KERN_ERR
"ia32.putreg: unknown register %d\n", regno
);
1283 put_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1284 struct switch_stack
*swp
, int tos
)
1286 struct _fpreg_ia32
*f
;
1289 f
= (struct _fpreg_ia32
*)(((unsigned long)buf
+ 15) & ~15);
1290 if ((regno
+= tos
) >= 8)
1294 ia64f2ia32f(f
, &ptp
->f8
);
1297 ia64f2ia32f(f
, &ptp
->f9
);
1300 ia64f2ia32f(f
, &ptp
->f10
);
1303 ia64f2ia32f(f
, &ptp
->f11
);
1309 ia64f2ia32f(f
, &swp
->f12
+ (regno
- 4));
1312 copy_to_user(reg
, f
, sizeof(*reg
));
1316 get_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1317 struct switch_stack
*swp
, int tos
)
1320 if ((regno
+= tos
) >= 8)
1324 copy_from_user(&ptp
->f8
, reg
, sizeof(*reg
));
1327 copy_from_user(&ptp
->f9
, reg
, sizeof(*reg
));
1330 copy_from_user(&ptp
->f10
, reg
, sizeof(*reg
));
1333 copy_from_user(&ptp
->f11
, reg
, sizeof(*reg
));
1339 copy_from_user(&swp
->f12
+ (regno
- 4), reg
, sizeof(*reg
));
1346 save_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1348 struct switch_stack
*swp
;
1349 struct pt_regs
*ptp
;
1352 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1355 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1356 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1357 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1358 __put_user(tsk
->thread
.fir
, &save
->fip
);
1359 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1360 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1361 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1364 * Stack frames start with 16-bytes of temp space
1366 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1367 ptp
= task_pt_regs(tsk
);
1368 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1369 for (i
= 0; i
< 8; i
++)
1370 put_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1375 restore_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1377 struct switch_stack
*swp
;
1378 struct pt_regs
*ptp
;
1380 unsigned int fsrlo
, fsrhi
, num32
;
1382 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1385 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1386 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1387 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1388 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1389 num32
= (fsrhi
<< 16) | fsrlo
;
1390 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1391 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1392 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1393 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1394 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1397 * Stack frames start with 16-bytes of temp space
1399 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1400 ptp
= task_pt_regs(tsk
);
1401 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1402 for (i
= 0; i
< 8; i
++)
1403 get_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1408 save_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1410 struct switch_stack
*swp
;
1411 struct pt_regs
*ptp
;
1413 unsigned long mxcsr
=0;
1414 unsigned long num128
[2];
1416 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1419 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1420 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1421 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1422 __put_user(tsk
->thread
.fir
, &save
->fip
);
1423 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1424 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1425 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1428 * Stack frames start with 16-bytes of temp space
1430 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1431 ptp
= task_pt_regs(tsk
);
1432 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1433 for (i
= 0; i
< 8; i
++)
1434 put_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1436 mxcsr
= ((tsk
->thread
.fcr
>>32) & 0xff80) | ((tsk
->thread
.fsr
>>32) & 0x3f);
1437 __put_user(mxcsr
& 0xffff, &save
->mxcsr
);
1438 for (i
= 0; i
< 8; i
++) {
1439 memcpy(&(num128
[0]), &(swp
->f16
) + i
*2, sizeof(unsigned long));
1440 memcpy(&(num128
[1]), &(swp
->f17
) + i
*2, sizeof(unsigned long));
1441 copy_to_user(&save
->xmm_space
[0] + 4*i
, num128
, sizeof(struct _xmmreg_ia32
));
1447 restore_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1449 struct switch_stack
*swp
;
1450 struct pt_regs
*ptp
;
1452 unsigned int fsrlo
, fsrhi
, num32
;
1454 unsigned long num64
;
1455 unsigned long num128
[2];
1457 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1460 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1461 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1462 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1463 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1464 num32
= (fsrhi
<< 16) | fsrlo
;
1465 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1466 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1467 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1468 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1469 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1472 * Stack frames start with 16-bytes of temp space
1474 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1475 ptp
= task_pt_regs(tsk
);
1476 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1477 for (i
= 0; i
< 8; i
++)
1478 get_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1480 __get_user(mxcsr
, (unsigned int __user
*)&save
->mxcsr
);
1481 num64
= mxcsr
& 0xff10;
1482 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0xff1000000000UL
)) | (num64
<<32);
1483 num64
= mxcsr
& 0x3f;
1484 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0x3f00000000UL
)) | (num64
<<32);
1486 for (i
= 0; i
< 8; i
++) {
1487 copy_from_user(num128
, &save
->xmm_space
[0] + 4*i
, sizeof(struct _xmmreg_ia32
));
1488 memcpy(&(swp
->f16
) + i
*2, &(num128
[0]), sizeof(unsigned long));
1489 memcpy(&(swp
->f17
) + i
*2, &(num128
[1]), sizeof(unsigned long));
1494 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
1495 compat_ulong_t caddr
, compat_ulong_t cdata
)
1497 unsigned long addr
= caddr
;
1498 unsigned long data
= cdata
;
1503 case PTRACE_PEEKUSR
: /* read word at addr in USER area */
1505 if ((addr
& 3) || addr
> 17*sizeof(int))
1508 tmp
= getreg(child
, addr
);
1509 if (!put_user(tmp
, (unsigned int __user
*) compat_ptr(data
)))
1513 case PTRACE_POKEUSR
: /* write word at addr in USER area */
1515 if ((addr
& 3) || addr
> 17*sizeof(int))
1518 putreg(child
, addr
, data
);
1522 case IA32_PTRACE_GETREGS
:
1523 if (!access_ok(VERIFY_WRITE
, compat_ptr(data
), 17*sizeof(int))) {
1527 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1528 put_user(getreg(child
, i
), (unsigned int __user
*) compat_ptr(data
));
1529 data
+= sizeof(int);
1534 case IA32_PTRACE_SETREGS
:
1535 if (!access_ok(VERIFY_READ
, compat_ptr(data
), 17*sizeof(int))) {
1539 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1540 get_user(tmp
, (unsigned int __user
*) compat_ptr(data
));
1541 putreg(child
, i
, tmp
);
1542 data
+= sizeof(int);
1547 case IA32_PTRACE_GETFPREGS
:
1548 ret
= save_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1552 case IA32_PTRACE_GETFPXREGS
:
1553 ret
= save_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1557 case IA32_PTRACE_SETFPREGS
:
1558 ret
= restore_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1562 case IA32_PTRACE_SETFPXREGS
:
1563 ret
= restore_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1568 return compat_ptrace_request(child
, request
, caddr
, cdata
);
1575 unsigned int ss_flags
;
1576 unsigned int ss_size
;
1580 sys32_sigaltstack (ia32_stack_t __user
*uss32
, ia32_stack_t __user
*uoss32
,
1581 long arg2
, long arg3
, long arg4
, long arg5
, long arg6
,
1582 long arg7
, struct pt_regs pt
)
1587 mm_segment_t old_fs
= get_fs();
1590 if (copy_from_user(&buf32
, uss32
, sizeof(ia32_stack_t
)))
1592 uss
.ss_sp
= (void __user
*) (long) buf32
.ss_sp
;
1593 uss
.ss_flags
= buf32
.ss_flags
;
1594 /* MINSIGSTKSZ is different for ia32 vs ia64. We lie here to pass the
1595 check and set it to the user requested value later */
1596 if ((buf32
.ss_flags
!= SS_DISABLE
) && (buf32
.ss_size
< MINSIGSTKSZ_IA32
)) {
1600 uss
.ss_size
= MINSIGSTKSZ
;
1603 ret
= do_sigaltstack(uss32
? (stack_t __user
*) &uss
: NULL
,
1604 (stack_t __user
*) &uoss
, pt
.r12
);
1605 current
->sas_ss_size
= buf32
.ss_size
;
1611 buf32
.ss_sp
= (long __user
) uoss
.ss_sp
;
1612 buf32
.ss_flags
= uoss
.ss_flags
;
1613 buf32
.ss_size
= uoss
.ss_size
;
1614 if (copy_to_user(uoss32
, &buf32
, sizeof(ia32_stack_t
)))
1621 sys32_msync (unsigned int start
, unsigned int len
, int flags
)
1625 if (OFFSET4K(start
))
1627 addr
= PAGE_START(start
);
1628 return sys_msync(addr
, len
+ (start
- addr
), flags
);
1634 unsigned int oldval
;
1635 unsigned int oldlenp
;
1636 unsigned int newval
;
1637 unsigned int newlen
;
1638 unsigned int __unused
[4];
1641 #ifdef CONFIG_SYSCTL_SYSCALL
1643 sys32_sysctl (struct sysctl32 __user
*args
)
1645 struct sysctl32 a32
;
1646 mm_segment_t old_fs
= get_fs ();
1647 void __user
*oldvalp
, *newvalp
;
1652 if (copy_from_user(&a32
, args
, sizeof(a32
)))
1656 * We need to pre-validate these because we have to disable address checking
1657 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
1658 * user specifying bad addresses here. Well, since we're dealing with 32 bit
1659 * addresses, we KNOW that access_ok() will always succeed, so this is an
1660 * expensive NOP, but so what...
1662 namep
= (int __user
*) compat_ptr(a32
.name
);
1663 oldvalp
= compat_ptr(a32
.oldval
);
1664 newvalp
= compat_ptr(a32
.newval
);
1666 if ((oldvalp
&& get_user(oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
1667 || !access_ok(VERIFY_WRITE
, namep
, 0)
1668 || !access_ok(VERIFY_WRITE
, oldvalp
, 0)
1669 || !access_ok(VERIFY_WRITE
, newvalp
, 0))
1674 ret
= do_sysctl(namep
, a32
.nlen
, oldvalp
, (size_t __user
*) &oldlen
,
1675 newvalp
, (size_t) a32
.newlen
);
1679 if (oldvalp
&& put_user (oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
1687 sys32_newuname (struct new_utsname __user
*name
)
1689 int ret
= sys_newuname(name
);
1692 if (copy_to_user(name
->machine
, "i686\0\0\0", 8))
1698 sys32_getresuid16 (u16 __user
*ruid
, u16 __user
*euid
, u16 __user
*suid
)
1702 mm_segment_t old_fs
= get_fs();
1705 ret
= sys_getresuid((uid_t __user
*) &a
, (uid_t __user
*) &b
, (uid_t __user
*) &c
);
1708 if (put_user(a
, ruid
) || put_user(b
, euid
) || put_user(c
, suid
))
1714 sys32_getresgid16 (u16 __user
*rgid
, u16 __user
*egid
, u16 __user
*sgid
)
1718 mm_segment_t old_fs
= get_fs();
1721 ret
= sys_getresgid((gid_t __user
*) &a
, (gid_t __user
*) &b
, (gid_t __user
*) &c
);
1727 return put_user(a
, rgid
) | put_user(b
, egid
) | put_user(c
, sgid
);
1731 sys32_lseek (unsigned int fd
, int offset
, unsigned int whence
)
1733 /* Sign-extension of "offset" is important here... */
1734 return sys_lseek(fd
, offset
, whence
);
1738 groups16_to_user(short __user
*grouplist
, struct group_info
*group_info
)
1743 for (i
= 0; i
< group_info
->ngroups
; i
++) {
1744 group
= (short)GROUP_AT(group_info
, i
);
1745 if (put_user(group
, grouplist
+i
))
1753 groups16_from_user(struct group_info
*group_info
, short __user
*grouplist
)
1758 for (i
= 0; i
< group_info
->ngroups
; i
++) {
1759 if (get_user(group
, grouplist
+i
))
1761 GROUP_AT(group_info
, i
) = (gid_t
)group
;
1768 sys32_getgroups16 (int gidsetsize
, short __user
*grouplist
)
1770 const struct cred
*cred
= current_cred();
1776 i
= cred
->group_info
->ngroups
;
1778 if (i
> gidsetsize
) {
1782 if (groups16_to_user(grouplist
, cred
->group_info
)) {
1792 sys32_setgroups16 (int gidsetsize
, short __user
*grouplist
)
1794 struct group_info
*group_info
;
1797 if (!capable(CAP_SETGID
))
1799 if ((unsigned)gidsetsize
> NGROUPS_MAX
)
1802 group_info
= groups_alloc(gidsetsize
);
1805 retval
= groups16_from_user(group_info
, grouplist
);
1807 put_group_info(group_info
);
1811 retval
= set_current_groups(group_info
);
1812 put_group_info(group_info
);
1818 sys32_truncate64 (unsigned int path
, unsigned int len_lo
, unsigned int len_hi
)
1820 return sys_truncate(compat_ptr(path
), ((unsigned long) len_hi
<< 32) | len_lo
);
1824 sys32_ftruncate64 (int fd
, unsigned int len_lo
, unsigned int len_hi
)
1826 return sys_ftruncate(fd
, ((unsigned long) len_hi
<< 32) | len_lo
);
1830 putstat64 (struct stat64 __user
*ubuf
, struct kstat
*kbuf
)
1835 if (clear_user(ubuf
, sizeof(*ubuf
)))
1838 hdev
= huge_encode_dev(kbuf
->dev
);
1839 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_dev
);
1840 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_dev
) + 1);
1841 err
|= __put_user(kbuf
->ino
, &ubuf
->__st_ino
);
1842 err
|= __put_user(kbuf
->ino
, &ubuf
->st_ino_lo
);
1843 err
|= __put_user(kbuf
->ino
>> 32, &ubuf
->st_ino_hi
);
1844 err
|= __put_user(kbuf
->mode
, &ubuf
->st_mode
);
1845 err
|= __put_user(kbuf
->nlink
, &ubuf
->st_nlink
);
1846 err
|= __put_user(kbuf
->uid
, &ubuf
->st_uid
);
1847 err
|= __put_user(kbuf
->gid
, &ubuf
->st_gid
);
1848 hdev
= huge_encode_dev(kbuf
->rdev
);
1849 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_rdev
);
1850 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_rdev
) + 1);
1851 err
|= __put_user(kbuf
->size
, &ubuf
->st_size_lo
);
1852 err
|= __put_user((kbuf
->size
>> 32), &ubuf
->st_size_hi
);
1853 err
|= __put_user(kbuf
->atime
.tv_sec
, &ubuf
->st_atime
);
1854 err
|= __put_user(kbuf
->atime
.tv_nsec
, &ubuf
->st_atime_nsec
);
1855 err
|= __put_user(kbuf
->mtime
.tv_sec
, &ubuf
->st_mtime
);
1856 err
|= __put_user(kbuf
->mtime
.tv_nsec
, &ubuf
->st_mtime_nsec
);
1857 err
|= __put_user(kbuf
->ctime
.tv_sec
, &ubuf
->st_ctime
);
1858 err
|= __put_user(kbuf
->ctime
.tv_nsec
, &ubuf
->st_ctime_nsec
);
1859 err
|= __put_user(kbuf
->blksize
, &ubuf
->st_blksize
);
1860 err
|= __put_user(kbuf
->blocks
, &ubuf
->st_blocks
);
1865 sys32_stat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
1868 long ret
= vfs_stat(filename
, &s
);
1870 ret
= putstat64(statbuf
, &s
);
1875 sys32_lstat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
1878 long ret
= vfs_lstat(filename
, &s
);
1880 ret
= putstat64(statbuf
, &s
);
1885 sys32_fstat64 (unsigned int fd
, struct stat64 __user
*statbuf
)
1888 long ret
= vfs_fstat(fd
, &s
);
1890 ret
= putstat64(statbuf
, &s
);
1895 sys32_sched_rr_get_interval (pid_t pid
, struct compat_timespec __user
*interval
)
1897 mm_segment_t old_fs
= get_fs();
1902 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*) &t
);
1904 if (put_compat_timespec(&t
, interval
))
1910 sys32_pread (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
1912 return sys_pread64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
1916 sys32_pwrite (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
1918 return sys_pwrite64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
1922 sys32_sendfile (int out_fd
, int in_fd
, int __user
*offset
, unsigned int count
)
1924 mm_segment_t old_fs
= get_fs();
1928 if (offset
&& get_user(of
, offset
))
1932 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*) &of
: NULL
, count
);
1935 if (offset
&& put_user(of
, offset
))
1942 sys32_personality (unsigned int personality
)
1946 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
1947 personality
= PER_LINUX32
;
1948 ret
= sys_personality(personality
);
1949 if (ret
== PER_LINUX32
)
1954 asmlinkage
unsigned long
1955 sys32_brk (unsigned int brk
)
1957 unsigned long ret
, obrk
;
1958 struct mm_struct
*mm
= current
->mm
;
1963 clear_user(compat_ptr(ret
), PAGE_ALIGN(ret
) - ret
);
1967 /* Structure for ia32 emulation on ia64 */
1968 struct epoll_event32
1975 sys32_epoll_ctl(int epfd
, int op
, int fd
, struct epoll_event32 __user
*event
)
1977 mm_segment_t old_fs
= get_fs();
1978 struct epoll_event event64
;
1982 if (!access_ok(VERIFY_READ
, event
, sizeof(struct epoll_event32
)))
1985 __get_user(event64
.events
, &event
->events
);
1986 __get_user(data_halfword
, &event
->data
[0]);
1987 event64
.data
= data_halfword
;
1988 __get_user(data_halfword
, &event
->data
[1]);
1989 event64
.data
|= (u64
)data_halfword
<< 32;
1992 error
= sys_epoll_ctl(epfd
, op
, fd
, (struct epoll_event __user
*) &event64
);
1999 sys32_epoll_wait(int epfd
, struct epoll_event32 __user
* events
, int maxevents
,
2002 struct epoll_event
*events64
= NULL
;
2003 mm_segment_t old_fs
= get_fs();
2004 int numevents
, size
;
2006 int do_free_pages
= 0;
2008 if (maxevents
<= 0) {
2012 /* Verify that the area passed by the user is writeable */
2013 if (!access_ok(VERIFY_WRITE
, events
, maxevents
* sizeof(struct epoll_event32
)))
2017 * Allocate space for the intermediate copy. If the space needed
2018 * is large enough to cause kmalloc to fail, then try again with
2021 size
= maxevents
* sizeof(struct epoll_event
);
2022 events64
= kmalloc(size
, GFP_KERNEL
);
2023 if (events64
== NULL
) {
2024 events64
= (struct epoll_event
*)
2025 __get_free_pages(GFP_KERNEL
, get_order(size
));
2026 if (events64
== NULL
)
2031 /* Do the system call */
2032 set_fs(KERNEL_DS
); /* copy_to/from_user should work on kernel mem*/
2033 numevents
= sys_epoll_wait(epfd
, (struct epoll_event __user
*) events64
,
2034 maxevents
, timeout
);
2037 /* Don't modify userspace memory if we're returning an error */
2038 if (numevents
> 0) {
2039 /* Translate the 64-bit structures back into the 32-bit
2041 for (evt_idx
= 0; evt_idx
< numevents
; evt_idx
++) {
2042 __put_user(events64
[evt_idx
].events
,
2043 &events
[evt_idx
].events
);
2044 __put_user((u32
)events64
[evt_idx
].data
,
2045 &events
[evt_idx
].data
[0]);
2046 __put_user((u32
)(events64
[evt_idx
].data
>> 32),
2047 &events
[evt_idx
].data
[1]);
2052 free_pages((unsigned long) events64
, get_order(size
));
2059 * Get a yet unused TLS descriptor index.
2064 struct thread_struct
*t
= ¤t
->thread
;
2067 for (idx
= 0; idx
< GDT_ENTRY_TLS_ENTRIES
; idx
++)
2068 if (desc_empty(t
->tls_array
+ idx
))
2069 return idx
+ GDT_ENTRY_TLS_MIN
;
2073 static void set_tls_desc(struct task_struct
*p
, int idx
,
2074 const struct ia32_user_desc
*info
, int n
)
2076 struct thread_struct
*t
= &p
->thread
;
2077 struct desc_struct
*desc
= &t
->tls_array
[idx
- GDT_ENTRY_TLS_MIN
];
2081 * We must not get preempted while modifying the TLS.
2086 if (LDT_empty(info
)) {
2090 desc
->a
= LDT_entry_a(info
);
2091 desc
->b
= LDT_entry_b(info
);
2098 if (t
== ¤t
->thread
)
2105 * Set a given TLS descriptor:
2108 sys32_set_thread_area (struct ia32_user_desc __user
*u_info
)
2110 struct ia32_user_desc info
;
2113 if (copy_from_user(&info
, u_info
, sizeof(info
)))
2115 idx
= info
.entry_number
;
2118 * index -1 means the kernel should try to find and allocate an empty descriptor:
2121 idx
= get_free_idx();
2124 if (put_user(idx
, &u_info
->entry_number
))
2128 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2131 set_tls_desc(current
, idx
, &info
, 1);
2136 * Get the current Thread-Local Storage area:
2139 #define GET_BASE(desc) ( \
2140 (((desc)->a >> 16) & 0x0000ffff) | \
2141 (((desc)->b << 16) & 0x00ff0000) | \
2142 ( (desc)->b & 0xff000000) )
2144 #define GET_LIMIT(desc) ( \
2145 ((desc)->a & 0x0ffff) | \
2146 ((desc)->b & 0xf0000) )
2148 #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
2149 #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
2150 #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
2151 #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
2152 #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
2153 #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
2155 static void fill_user_desc(struct ia32_user_desc
*info
, int idx
,
2156 const struct desc_struct
*desc
)
2158 info
->entry_number
= idx
;
2159 info
->base_addr
= GET_BASE(desc
);
2160 info
->limit
= GET_LIMIT(desc
);
2161 info
->seg_32bit
= GET_32BIT(desc
);
2162 info
->contents
= GET_CONTENTS(desc
);
2163 info
->read_exec_only
= !GET_WRITABLE(desc
);
2164 info
->limit_in_pages
= GET_LIMIT_PAGES(desc
);
2165 info
->seg_not_present
= !GET_PRESENT(desc
);
2166 info
->useable
= GET_USEABLE(desc
);
2170 sys32_get_thread_area (struct ia32_user_desc __user
*u_info
)
2172 struct ia32_user_desc info
;
2173 struct desc_struct
*desc
;
2176 if (get_user(idx
, &u_info
->entry_number
))
2178 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2181 desc
= current
->thread
.tls_array
+ idx
- GDT_ENTRY_TLS_MIN
;
2182 fill_user_desc(&info
, idx
, desc
);
2184 if (copy_to_user(u_info
, &info
, sizeof(info
)))
2196 const void __user
*ubuf
;
2199 struct regset_getset
{
2200 struct task_struct
*target
;
2201 const struct user_regset
*regset
;
2203 struct regset_get get
;
2204 struct regset_set set
;
2211 static void getfpreg(struct task_struct
*task
, int regno
, int *val
)
2213 switch (regno
/ sizeof(int)) {
2215 *val
= task
->thread
.fcr
& 0xffff;
2218 *val
= task
->thread
.fsr
& 0xffff;
2221 *val
= (task
->thread
.fsr
>>16) & 0xffff;
2224 *val
= task
->thread
.fir
;
2227 *val
= (task
->thread
.fir
>>32) & 0xffff;
2230 *val
= task
->thread
.fdr
;
2233 *val
= (task
->thread
.fdr
>> 32) & 0xffff;
2238 static void setfpreg(struct task_struct
*task
, int regno
, int val
)
2240 switch (regno
/ sizeof(int)) {
2242 task
->thread
.fcr
= (task
->thread
.fcr
& (~0x1f3f))
2246 task
->thread
.fsr
= (task
->thread
.fsr
& (~0xffff)) | val
;
2249 task
->thread
.fsr
= (task
->thread
.fsr
& (~0xffff0000))
2253 task
->thread
.fir
= (task
->thread
.fir
& (~0xffffffff)) | val
;
2256 task
->thread
.fdr
= (task
->thread
.fdr
& (~0xffffffff)) | val
;
2261 static void access_fpreg_ia32(int regno
, void *reg
,
2262 struct pt_regs
*pt
, struct switch_stack
*sw
,
2267 if ((regno
+= tos
) >= 8)
2270 f
= &pt
->f8
+ regno
;
2271 else if (regno
<= 7)
2272 f
= &sw
->f12
+ (regno
- 4);
2274 printk(KERN_ERR
"regno must be less than 7 \n");
2279 memcpy(f
, reg
, sizeof(struct _fpreg_ia32
));
2281 memcpy(reg
, f
, sizeof(struct _fpreg_ia32
));
2284 static void do_fpregs_get(struct unw_frame_info
*info
, void *arg
)
2286 struct regset_getset
*dst
= arg
;
2287 struct task_struct
*task
= dst
->target
;
2289 int start
, end
, tos
;
2292 if (dst
->count
== 0 || unw_unwind_to_user(info
) < 0)
2294 if (dst
->pos
< 7 * sizeof(int)) {
2295 end
= min((dst
->pos
+ dst
->count
),
2296 (unsigned int)(7 * sizeof(int)));
2297 for (start
= dst
->pos
; start
< end
; start
+= sizeof(int))
2298 getfpreg(task
, start
, (int *)(buf
+ start
));
2299 dst
->ret
= user_regset_copyout(&dst
->pos
, &dst
->count
,
2300 &dst
->u
.get
.kbuf
, &dst
->u
.get
.ubuf
, buf
,
2301 0, 7 * sizeof(int));
2302 if (dst
->ret
|| dst
->count
== 0)
2305 if (dst
->pos
< sizeof(struct ia32_user_i387_struct
)) {
2306 pt
= task_pt_regs(task
);
2307 tos
= (task
->thread
.fsr
>> 11) & 7;
2308 end
= min(dst
->pos
+ dst
->count
,
2309 (unsigned int)(sizeof(struct ia32_user_i387_struct
)));
2310 start
= (dst
->pos
- 7 * sizeof(int)) /
2311 sizeof(struct _fpreg_ia32
);
2312 end
= (end
- 7 * sizeof(int)) / sizeof(struct _fpreg_ia32
);
2313 for (; start
< end
; start
++)
2314 access_fpreg_ia32(start
,
2315 (struct _fpreg_ia32
*)buf
+ start
,
2316 pt
, info
->sw
, tos
, 0);
2317 dst
->ret
= user_regset_copyout(&dst
->pos
, &dst
->count
,
2318 &dst
->u
.get
.kbuf
, &dst
->u
.get
.ubuf
,
2319 buf
, 7 * sizeof(int),
2320 sizeof(struct ia32_user_i387_struct
));
2321 if (dst
->ret
|| dst
->count
== 0)
2326 static void do_fpregs_set(struct unw_frame_info
*info
, void *arg
)
2328 struct regset_getset
*dst
= arg
;
2329 struct task_struct
*task
= dst
->target
;
2332 int end
, start
, tos
;
2334 if (dst
->count
== 0 || unw_unwind_to_user(info
) < 0)
2337 if (dst
->pos
< 7 * sizeof(int)) {
2339 dst
->ret
= user_regset_copyin(&dst
->pos
, &dst
->count
,
2340 &dst
->u
.set
.kbuf
, &dst
->u
.set
.ubuf
, buf
,
2341 0, 7 * sizeof(int));
2344 for (; start
< dst
->pos
; start
+= sizeof(int))
2345 setfpreg(task
, start
, *((int *)(buf
+ start
)));
2346 if (dst
->count
== 0)
2349 if (dst
->pos
< sizeof(struct ia32_user_i387_struct
)) {
2350 start
= (dst
->pos
- 7 * sizeof(int)) /
2351 sizeof(struct _fpreg_ia32
);
2352 dst
->ret
= user_regset_copyin(&dst
->pos
, &dst
->count
,
2353 &dst
->u
.set
.kbuf
, &dst
->u
.set
.ubuf
,
2354 buf
, 7 * sizeof(int),
2355 sizeof(struct ia32_user_i387_struct
));
2358 pt
= task_pt_regs(task
);
2359 tos
= (task
->thread
.fsr
>> 11) & 7;
2360 end
= (dst
->pos
- 7 * sizeof(int)) / sizeof(struct _fpreg_ia32
);
2361 for (; start
< end
; start
++)
2362 access_fpreg_ia32(start
,
2363 (struct _fpreg_ia32
*)buf
+ start
,
2364 pt
, info
->sw
, tos
, 1);
2365 if (dst
->count
== 0)
2370 #define OFFSET(member) ((int)(offsetof(struct ia32_user_fxsr_struct, member)))
2371 static void getfpxreg(struct task_struct
*task
, int start
, int end
, char *buf
)
2375 min_val
= min(end
, OFFSET(fop
));
2376 while (start
< min_val
) {
2377 if (start
== OFFSET(cwd
))
2378 *((short *)buf
) = task
->thread
.fcr
& 0xffff;
2379 else if (start
== OFFSET(swd
))
2380 *((short *)buf
) = task
->thread
.fsr
& 0xffff;
2381 else if (start
== OFFSET(twd
))
2382 *((short *)buf
) = (task
->thread
.fsr
>>16) & 0xffff;
2386 /* skip fop element */
2387 if (start
== OFFSET(fop
)) {
2391 while (start
< end
) {
2392 if (start
== OFFSET(fip
))
2393 *((int *)buf
) = task
->thread
.fir
;
2394 else if (start
== OFFSET(fcs
))
2395 *((int *)buf
) = (task
->thread
.fir
>>32) & 0xffff;
2396 else if (start
== OFFSET(foo
))
2397 *((int *)buf
) = task
->thread
.fdr
;
2398 else if (start
== OFFSET(fos
))
2399 *((int *)buf
) = (task
->thread
.fdr
>>32) & 0xffff;
2400 else if (start
== OFFSET(mxcsr
))
2401 *((int *)buf
) = ((task
->thread
.fcr
>>32) & 0xff80)
2402 | ((task
->thread
.fsr
>>32) & 0x3f);
2408 static void setfpxreg(struct task_struct
*task
, int start
, int end
, char *buf
)
2412 unsigned long num64
;
2414 min_val
= min(end
, OFFSET(fop
));
2415 while (start
< min_val
) {
2416 num
= *((short *)buf
);
2417 if (start
== OFFSET(cwd
)) {
2418 task
->thread
.fcr
= (task
->thread
.fcr
& (~0x1f3f))
2420 } else if (start
== OFFSET(swd
)) {
2421 task
->thread
.fsr
= (task
->thread
.fsr
& (~0xffff)) | num
;
2422 } else if (start
== OFFSET(twd
)) {
2423 task
->thread
.fsr
= (task
->thread
.fsr
& (~0xffff0000))
2424 | (((int)num
) << 16);
2429 /* skip fop element */
2430 if (start
== OFFSET(fop
)) {
2434 while (start
< end
) {
2435 num32
= *((int *)buf
);
2436 if (start
== OFFSET(fip
))
2437 task
->thread
.fir
= (task
->thread
.fir
& (~0xffffffff))
2439 else if (start
== OFFSET(foo
))
2440 task
->thread
.fdr
= (task
->thread
.fdr
& (~0xffffffff))
2442 else if (start
== OFFSET(mxcsr
)) {
2443 num64
= num32
& 0xff10;
2444 task
->thread
.fcr
= (task
->thread
.fcr
&
2445 (~0xff1000000000UL
)) | (num64
<<32);
2446 num64
= num32
& 0x3f;
2447 task
->thread
.fsr
= (task
->thread
.fsr
&
2448 (~0x3f00000000UL
)) | (num64
<<32);
2455 static void do_fpxregs_get(struct unw_frame_info
*info
, void *arg
)
2457 struct regset_getset
*dst
= arg
;
2458 struct task_struct
*task
= dst
->target
;
2461 int start
, end
, tos
;
2463 if (dst
->count
== 0 || unw_unwind_to_user(info
) < 0)
2465 if (dst
->pos
< OFFSET(st_space
[0])) {
2466 end
= min(dst
->pos
+ dst
->count
, (unsigned int)32);
2467 getfpxreg(task
, dst
->pos
, end
, buf
);
2468 dst
->ret
= user_regset_copyout(&dst
->pos
, &dst
->count
,
2469 &dst
->u
.get
.kbuf
, &dst
->u
.get
.ubuf
, buf
,
2470 0, OFFSET(st_space
[0]));
2471 if (dst
->ret
|| dst
->count
== 0)
2474 if (dst
->pos
< OFFSET(xmm_space
[0])) {
2475 pt
= task_pt_regs(task
);
2476 tos
= (task
->thread
.fsr
>> 11) & 7;
2477 end
= min(dst
->pos
+ dst
->count
,
2478 (unsigned int)OFFSET(xmm_space
[0]));
2479 start
= (dst
->pos
- OFFSET(st_space
[0])) / 16;
2480 end
= (end
- OFFSET(st_space
[0])) / 16;
2481 for (; start
< end
; start
++)
2482 access_fpreg_ia32(start
, buf
+ 16 * start
, pt
,
2484 dst
->ret
= user_regset_copyout(&dst
->pos
, &dst
->count
,
2485 &dst
->u
.get
.kbuf
, &dst
->u
.get
.ubuf
,
2486 buf
, OFFSET(st_space
[0]), OFFSET(xmm_space
[0]));
2487 if (dst
->ret
|| dst
->count
== 0)
2490 if (dst
->pos
< OFFSET(padding
[0]))
2491 dst
->ret
= user_regset_copyout(&dst
->pos
, &dst
->count
,
2492 &dst
->u
.get
.kbuf
, &dst
->u
.get
.ubuf
,
2493 &info
->sw
->f16
, OFFSET(xmm_space
[0]),
2494 OFFSET(padding
[0]));
2497 static void do_fpxregs_set(struct unw_frame_info
*info
, void *arg
)
2499 struct regset_getset
*dst
= arg
;
2500 struct task_struct
*task
= dst
->target
;
2504 if (dst
->count
== 0 || unw_unwind_to_user(info
) < 0)
2507 if (dst
->pos
< OFFSET(st_space
[0])) {
2509 dst
->ret
= user_regset_copyin(&dst
->pos
, &dst
->count
,
2510 &dst
->u
.set
.kbuf
, &dst
->u
.set
.ubuf
,
2511 buf
, 0, OFFSET(st_space
[0]));
2514 setfpxreg(task
, start
, dst
->pos
, buf
);
2515 if (dst
->count
== 0)
2518 if (dst
->pos
< OFFSET(xmm_space
[0])) {
2521 pt
= task_pt_regs(task
);
2522 tos
= (task
->thread
.fsr
>> 11) & 7;
2523 start
= (dst
->pos
- OFFSET(st_space
[0])) / 16;
2524 dst
->ret
= user_regset_copyin(&dst
->pos
, &dst
->count
,
2525 &dst
->u
.set
.kbuf
, &dst
->u
.set
.ubuf
,
2526 buf
, OFFSET(st_space
[0]), OFFSET(xmm_space
[0]));
2529 end
= (dst
->pos
- OFFSET(st_space
[0])) / 16;
2530 for (; start
< end
; start
++)
2531 access_fpreg_ia32(start
, buf
+ 16 * start
, pt
, info
->sw
,
2533 if (dst
->count
== 0)
2536 if (dst
->pos
< OFFSET(padding
[0]))
2537 dst
->ret
= user_regset_copyin(&dst
->pos
, &dst
->count
,
2538 &dst
->u
.set
.kbuf
, &dst
->u
.set
.ubuf
,
2539 &info
->sw
->f16
, OFFSET(xmm_space
[0]),
2540 OFFSET(padding
[0]));
2544 static int do_regset_call(void (*call
)(struct unw_frame_info
*, void *),
2545 struct task_struct
*target
,
2546 const struct user_regset
*regset
,
2547 unsigned int pos
, unsigned int count
,
2548 const void *kbuf
, const void __user
*ubuf
)
2550 struct regset_getset info
= { .target
= target
, .regset
= regset
,
2551 .pos
= pos
, .count
= count
,
2552 .u
.set
= { .kbuf
= kbuf
, .ubuf
= ubuf
},
2555 if (target
== current
)
2556 unw_init_running(call
, &info
);
2558 struct unw_frame_info ufi
;
2559 memset(&ufi
, 0, sizeof(ufi
));
2560 unw_init_from_blocked_task(&ufi
, target
);
2561 (*call
)(&ufi
, &info
);
2567 static int ia32_fpregs_get(struct task_struct
*target
,
2568 const struct user_regset
*regset
,
2569 unsigned int pos
, unsigned int count
,
2570 void *kbuf
, void __user
*ubuf
)
2572 return do_regset_call(do_fpregs_get
, target
, regset
, pos
, count
,
2576 static int ia32_fpregs_set(struct task_struct
*target
,
2577 const struct user_regset
*regset
,
2578 unsigned int pos
, unsigned int count
,
2579 const void *kbuf
, const void __user
*ubuf
)
2581 return do_regset_call(do_fpregs_set
, target
, regset
, pos
, count
,
2585 static int ia32_fpxregs_get(struct task_struct
*target
,
2586 const struct user_regset
*regset
,
2587 unsigned int pos
, unsigned int count
,
2588 void *kbuf
, void __user
*ubuf
)
2590 return do_regset_call(do_fpxregs_get
, target
, regset
, pos
, count
,
2594 static int ia32_fpxregs_set(struct task_struct
*target
,
2595 const struct user_regset
*regset
,
2596 unsigned int pos
, unsigned int count
,
2597 const void *kbuf
, const void __user
*ubuf
)
2599 return do_regset_call(do_fpxregs_set
, target
, regset
, pos
, count
,
2603 static int ia32_genregs_get(struct task_struct
*target
,
2604 const struct user_regset
*regset
,
2605 unsigned int pos
, unsigned int count
,
2606 void *kbuf
, void __user
*ubuf
)
2611 *kp
++ = getreg(target
, pos
);
2616 u32 __user
*up
= ubuf
;
2618 if (__put_user(getreg(target
, pos
), up
++))
2627 static int ia32_genregs_set(struct task_struct
*target
,
2628 const struct user_regset
*regset
,
2629 unsigned int pos
, unsigned int count
,
2630 const void *kbuf
, const void __user
*ubuf
)
2635 const u32
*kp
= kbuf
;
2636 while (!ret
&& count
> 0) {
2637 putreg(target
, pos
, *kp
++);
2642 const u32 __user
*up
= ubuf
;
2644 while (!ret
&& count
> 0) {
2645 ret
= __get_user(val
, up
++);
2647 putreg(target
, pos
, val
);
2655 static int ia32_tls_active(struct task_struct
*target
,
2656 const struct user_regset
*regset
)
2658 struct thread_struct
*t
= &target
->thread
;
2659 int n
= GDT_ENTRY_TLS_ENTRIES
;
2660 while (n
> 0 && desc_empty(&t
->tls_array
[n
-1]))
2665 static int ia32_tls_get(struct task_struct
*target
,
2666 const struct user_regset
*regset
, unsigned int pos
,
2667 unsigned int count
, void *kbuf
, void __user
*ubuf
)
2669 const struct desc_struct
*tls
;
2671 if (pos
> GDT_ENTRY_TLS_ENTRIES
* sizeof(struct ia32_user_desc
) ||
2672 (pos
% sizeof(struct ia32_user_desc
)) != 0 ||
2673 (count
% sizeof(struct ia32_user_desc
)) != 0)
2676 pos
/= sizeof(struct ia32_user_desc
);
2677 count
/= sizeof(struct ia32_user_desc
);
2679 tls
= &target
->thread
.tls_array
[pos
];
2682 struct ia32_user_desc
*info
= kbuf
;
2684 fill_user_desc(info
++, GDT_ENTRY_TLS_MIN
+ pos
++,
2687 struct ia32_user_desc __user
*u_info
= ubuf
;
2688 while (count
-- > 0) {
2689 struct ia32_user_desc info
;
2690 fill_user_desc(&info
, GDT_ENTRY_TLS_MIN
+ pos
++, tls
++);
2691 if (__copy_to_user(u_info
++, &info
, sizeof(info
)))
2699 static int ia32_tls_set(struct task_struct
*target
,
2700 const struct user_regset
*regset
, unsigned int pos
,
2701 unsigned int count
, const void *kbuf
, const void __user
*ubuf
)
2703 struct ia32_user_desc infobuf
[GDT_ENTRY_TLS_ENTRIES
];
2704 const struct ia32_user_desc
*info
;
2706 if (pos
> GDT_ENTRY_TLS_ENTRIES
* sizeof(struct ia32_user_desc
) ||
2707 (pos
% sizeof(struct ia32_user_desc
)) != 0 ||
2708 (count
% sizeof(struct ia32_user_desc
)) != 0)
2713 else if (__copy_from_user(infobuf
, ubuf
, count
))
2718 set_tls_desc(target
,
2719 GDT_ENTRY_TLS_MIN
+ (pos
/ sizeof(struct ia32_user_desc
)),
2720 info
, count
/ sizeof(struct ia32_user_desc
));
2726 * This should match arch/i386/kernel/ptrace.c:native_regsets.
2729 static const struct user_regset ia32_regsets
[] = {
2731 .core_note_type
= NT_PRSTATUS
,
2732 .n
= sizeof(struct user_regs_struct32
)/4,
2733 .size
= 4, .align
= 4,
2734 .get
= ia32_genregs_get
, .set
= ia32_genregs_set
2737 .core_note_type
= NT_PRFPREG
,
2738 .n
= sizeof(struct ia32_user_i387_struct
) / 4,
2739 .size
= 4, .align
= 4,
2740 .get
= ia32_fpregs_get
, .set
= ia32_fpregs_set
2743 .core_note_type
= NT_PRXFPREG
,
2744 .n
= sizeof(struct ia32_user_fxsr_struct
) / 4,
2745 .size
= 4, .align
= 4,
2746 .get
= ia32_fpxregs_get
, .set
= ia32_fpxregs_set
2749 .core_note_type
= NT_386_TLS
,
2750 .n
= GDT_ENTRY_TLS_ENTRIES
,
2751 .bias
= GDT_ENTRY_TLS_MIN
,
2752 .size
= sizeof(struct ia32_user_desc
),
2753 .align
= sizeof(struct ia32_user_desc
),
2754 .active
= ia32_tls_active
,
2755 .get
= ia32_tls_get
, .set
= ia32_tls_set
,
2759 const struct user_regset_view user_ia32_view
= {
2760 .name
= "i386", .e_machine
= EM_386
,
2761 .regsets
= ia32_regsets
, .n
= ARRAY_SIZE(ia32_regsets
)
2764 long sys32_fadvise64_64(int fd
, __u32 offset_low
, __u32 offset_high
,
2765 __u32 len_low
, __u32 len_high
, int advice
)
2767 return sys_fadvise64_64(fd
,
2768 (((u64
)offset_high
)<<32) | offset_low
,
2769 (((u64
)len_high
)<<32) | len_low
,
2773 #ifdef NOTYET /* UNTESTED FOR IA64 FROM HERE DOWN */
2775 asmlinkage
long sys32_setreuid(compat_uid_t ruid
, compat_uid_t euid
)
2779 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2780 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2781 return sys_setreuid(sruid
, seuid
);
2785 sys32_setresuid(compat_uid_t ruid
, compat_uid_t euid
,
2788 uid_t sruid
, seuid
, ssuid
;
2790 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2791 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2792 ssuid
= (suid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)suid
);
2793 return sys_setresuid(sruid
, seuid
, ssuid
);
2797 sys32_setregid(compat_gid_t rgid
, compat_gid_t egid
)
2801 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2802 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2803 return sys_setregid(srgid
, segid
);
2807 sys32_setresgid(compat_gid_t rgid
, compat_gid_t egid
,
2810 gid_t srgid
, segid
, ssgid
;
2812 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2813 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2814 ssgid
= (sgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)sgid
);
2815 return sys_setresgid(srgid
, segid
, ssgid
);