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/stat.h>
42 #include <linux/ipc.h>
43 #include <linux/capability.h>
44 #include <linux/compat.h>
45 #include <linux/vfs.h>
46 #include <linux/mman.h>
47 #include <linux/mutex.h>
49 #include <asm/intrinsics.h>
50 #include <asm/types.h>
51 #include <asm/uaccess.h>
52 #include <asm/unistd.h>
62 # define DBG(fmt...) printk(KERN_DEBUG fmt)
67 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
69 #define OFFSET4K(a) ((a) & 0xfff)
70 #define PAGE_START(addr) ((addr) & PAGE_MASK)
71 #define MINSIGSTKSZ_IA32 2048
73 #define high2lowuid(uid) ((uid) > 65535 ? 65534 : (uid))
74 #define high2lowgid(gid) ((gid) > 65535 ? 65534 : (gid))
77 * Anything that modifies or inspects ia32 user virtual memory must hold this semaphore
80 /* XXX make per-mm: */
81 static DEFINE_MUTEX(ia32_mmap_mutex
);
84 sys32_execve (char __user
*name
, compat_uptr_t __user
*argv
, compat_uptr_t __user
*envp
,
89 unsigned long old_map_base
, old_task_size
, tssd
;
91 filename
= getname(name
);
92 error
= PTR_ERR(filename
);
96 old_map_base
= current
->thread
.map_base
;
97 old_task_size
= current
->thread
.task_size
;
98 tssd
= ia64_get_kr(IA64_KR_TSSD
);
100 /* we may be exec'ing a 64-bit process: reset map base, task-size, and io-base: */
101 current
->thread
.map_base
= DEFAULT_MAP_BASE
;
102 current
->thread
.task_size
= DEFAULT_TASK_SIZE
;
103 ia64_set_kr(IA64_KR_IO_BASE
, current
->thread
.old_iob
);
104 ia64_set_kr(IA64_KR_TSSD
, current
->thread
.old_k1
);
106 error
= compat_do_execve(filename
, argv
, envp
, regs
);
110 /* oops, execve failed, switch back to old values... */
111 ia64_set_kr(IA64_KR_IO_BASE
, IA32_IOBASE
);
112 ia64_set_kr(IA64_KR_TSSD
, tssd
);
113 current
->thread
.map_base
= old_map_base
;
114 current
->thread
.task_size
= old_task_size
;
120 int cp_compat_stat(struct kstat
*stat
, struct compat_stat __user
*ubuf
)
125 if ((u64
) stat
->size
> MAX_NON_LFS
||
126 !old_valid_dev(stat
->dev
) ||
127 !old_valid_dev(stat
->rdev
))
131 if (sizeof(ino
) < sizeof(stat
->ino
) && ino
!= stat
->ino
)
134 if (clear_user(ubuf
, sizeof(*ubuf
)))
137 err
= __put_user(old_encode_dev(stat
->dev
), &ubuf
->st_dev
);
138 err
|= __put_user(ino
, &ubuf
->st_ino
);
139 err
|= __put_user(stat
->mode
, &ubuf
->st_mode
);
140 err
|= __put_user(stat
->nlink
, &ubuf
->st_nlink
);
141 err
|= __put_user(high2lowuid(stat
->uid
), &ubuf
->st_uid
);
142 err
|= __put_user(high2lowgid(stat
->gid
), &ubuf
->st_gid
);
143 err
|= __put_user(old_encode_dev(stat
->rdev
), &ubuf
->st_rdev
);
144 err
|= __put_user(stat
->size
, &ubuf
->st_size
);
145 err
|= __put_user(stat
->atime
.tv_sec
, &ubuf
->st_atime
);
146 err
|= __put_user(stat
->atime
.tv_nsec
, &ubuf
->st_atime_nsec
);
147 err
|= __put_user(stat
->mtime
.tv_sec
, &ubuf
->st_mtime
);
148 err
|= __put_user(stat
->mtime
.tv_nsec
, &ubuf
->st_mtime_nsec
);
149 err
|= __put_user(stat
->ctime
.tv_sec
, &ubuf
->st_ctime
);
150 err
|= __put_user(stat
->ctime
.tv_nsec
, &ubuf
->st_ctime_nsec
);
151 err
|= __put_user(stat
->blksize
, &ubuf
->st_blksize
);
152 err
|= __put_user(stat
->blocks
, &ubuf
->st_blocks
);
156 #if PAGE_SHIFT > IA32_PAGE_SHIFT
160 get_page_prot (struct vm_area_struct
*vma
, unsigned long addr
)
164 if (!vma
|| vma
->vm_start
> addr
)
167 if (vma
->vm_flags
& VM_READ
)
169 if (vma
->vm_flags
& VM_WRITE
)
171 if (vma
->vm_flags
& VM_EXEC
)
177 * Map a subpage by creating an anonymous page that contains the union of the old page and
181 mmap_subpage (struct file
*file
, unsigned long start
, unsigned long end
, int prot
, int flags
,
186 unsigned long ret
= 0;
187 struct vm_area_struct
*vma
= find_vma(current
->mm
, start
);
188 int old_prot
= get_page_prot(vma
, start
);
190 DBG("mmap_subpage(file=%p,start=0x%lx,end=0x%lx,prot=%x,flags=%x,off=0x%llx)\n",
191 file
, start
, end
, prot
, flags
, off
);
194 /* Optimize the case where the old mmap and the new mmap are both anonymous */
195 if ((old_prot
& PROT_WRITE
) && (flags
& MAP_ANONYMOUS
) && !vma
->vm_file
) {
196 if (clear_user((void __user
*) start
, end
- start
)) {
203 page
= (void *) get_zeroed_page(GFP_KERNEL
);
208 copy_from_user(page
, (void __user
*) PAGE_START(start
), PAGE_SIZE
);
210 down_write(¤t
->mm
->mmap_sem
);
212 ret
= do_mmap(NULL
, PAGE_START(start
), PAGE_SIZE
, prot
| PROT_WRITE
,
213 flags
| MAP_FIXED
| MAP_ANONYMOUS
, 0);
215 up_write(¤t
->mm
->mmap_sem
);
217 if (IS_ERR((void *) ret
))
221 /* copy back the old page contents. */
222 if (offset_in_page(start
))
223 copy_to_user((void __user
*) PAGE_START(start
), page
,
224 offset_in_page(start
));
225 if (offset_in_page(end
))
226 copy_to_user((void __user
*) end
, page
+ offset_in_page(end
),
227 PAGE_SIZE
- offset_in_page(end
));
230 if (!(flags
& MAP_ANONYMOUS
)) {
231 /* read the file contents */
232 inode
= file
->f_path
.dentry
->d_inode
;
233 if (!inode
->i_fop
|| !file
->f_op
->read
234 || ((*file
->f_op
->read
)(file
, (char __user
*) start
, end
- start
, &off
) < 0))
242 if (!(prot
& PROT_WRITE
))
243 ret
= sys_mprotect(PAGE_START(start
), PAGE_SIZE
, prot
| old_prot
);
246 free_page((unsigned long) page
);
250 /* SLAB cache for ia64_partial_page structures */
251 struct kmem_cache
*ia64_partial_page_cachep
;
254 * init ia64_partial_page_list.
255 * return 0 means kmalloc fail.
257 struct ia64_partial_page_list
*
258 ia32_init_pp_list(void)
260 struct ia64_partial_page_list
*p
;
262 if ((p
= kmalloc(sizeof(*p
), GFP_KERNEL
)) == NULL
)
267 atomic_set(&p
->pp_count
, 1);
272 * Search for the partial page with @start in partial page list @ppl.
273 * If finds the partial page, return the found partial page.
274 * Else, return 0 and provide @pprev, @rb_link, @rb_parent to
275 * be used by later __ia32_insert_pp().
277 static struct ia64_partial_page
*
278 __ia32_find_pp(struct ia64_partial_page_list
*ppl
, unsigned int start
,
279 struct ia64_partial_page
**pprev
, struct rb_node
***rb_link
,
280 struct rb_node
**rb_parent
)
282 struct ia64_partial_page
*pp
;
283 struct rb_node
**__rb_link
, *__rb_parent
, *rb_prev
;
286 if (pp
&& pp
->base
== start
)
289 __rb_link
= &ppl
->ppl_rb
.rb_node
;
290 rb_prev
= __rb_parent
= NULL
;
293 __rb_parent
= *__rb_link
;
294 pp
= rb_entry(__rb_parent
, struct ia64_partial_page
, pp_rb
);
296 if (pp
->base
== start
) {
299 } else if (pp
->base
< start
) {
300 rb_prev
= __rb_parent
;
301 __rb_link
= &__rb_parent
->rb_right
;
303 __rb_link
= &__rb_parent
->rb_left
;
307 *rb_link
= __rb_link
;
308 *rb_parent
= __rb_parent
;
311 *pprev
= rb_entry(rb_prev
, struct ia64_partial_page
, pp_rb
);
316 * insert @pp into @ppl.
319 __ia32_insert_pp(struct ia64_partial_page_list
*ppl
,
320 struct ia64_partial_page
*pp
, struct ia64_partial_page
*prev
,
321 struct rb_node
**rb_link
, struct rb_node
*rb_parent
)
325 pp
->next
= prev
->next
;
330 pp
->next
= rb_entry(rb_parent
,
331 struct ia64_partial_page
, pp_rb
);
337 rb_link_node(&pp
->pp_rb
, rb_parent
, rb_link
);
338 rb_insert_color(&pp
->pp_rb
, &ppl
->ppl_rb
);
344 * delete @pp from partial page list @ppl.
347 __ia32_delete_pp(struct ia64_partial_page_list
*ppl
,
348 struct ia64_partial_page
*pp
, struct ia64_partial_page
*prev
)
351 prev
->next
= pp
->next
;
352 if (ppl
->pp_hint
== pp
)
355 ppl
->pp_head
= pp
->next
;
356 if (ppl
->pp_hint
== pp
)
357 ppl
->pp_hint
= pp
->next
;
359 rb_erase(&pp
->pp_rb
, &ppl
->ppl_rb
);
360 kmem_cache_free(ia64_partial_page_cachep
, pp
);
363 static struct ia64_partial_page
*
364 __pp_prev(struct ia64_partial_page
*pp
)
366 struct rb_node
*prev
= rb_prev(&pp
->pp_rb
);
368 return rb_entry(prev
, struct ia64_partial_page
, pp_rb
);
374 * Delete partial pages with address between @start and @end.
375 * @start and @end are page aligned.
378 __ia32_delete_pp_range(unsigned int start
, unsigned int end
)
380 struct ia64_partial_page
*pp
, *prev
;
381 struct rb_node
**rb_link
, *rb_parent
;
386 pp
= __ia32_find_pp(current
->thread
.ppl
, start
, &prev
,
387 &rb_link
, &rb_parent
);
389 prev
= __pp_prev(pp
);
394 pp
= current
->thread
.ppl
->pp_head
;
397 while (pp
&& pp
->base
< end
) {
398 struct ia64_partial_page
*tmp
= pp
->next
;
399 __ia32_delete_pp(current
->thread
.ppl
, pp
, prev
);
405 * Set the range between @start and @end in bitmap.
406 * @start and @end should be IA32 page aligned and in the same IA64 page.
409 __ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
411 struct ia64_partial_page
*pp
, *prev
;
412 struct rb_node
** rb_link
, *rb_parent
;
413 unsigned int pstart
, start_bit
, end_bit
, i
;
415 pstart
= PAGE_START(start
);
416 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
417 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
419 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
420 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
421 &rb_link
, &rb_parent
);
423 for (i
= start_bit
; i
< end_bit
; i
++)
424 set_bit(i
, &pp
->bitmap
);
426 * Check: if this partial page has been set to a full page,
429 if (find_first_zero_bit(&pp
->bitmap
, sizeof(pp
->bitmap
)*8) >=
430 PAGE_SIZE
/IA32_PAGE_SIZE
) {
431 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
437 * MAP_FIXED may lead to overlapping mmap.
438 * In this case, the requested mmap area may already mmaped as a full
439 * page. So check vma before adding a new partial page.
441 if (flags
& MAP_FIXED
) {
442 struct vm_area_struct
*vma
= find_vma(current
->mm
, pstart
);
443 if (vma
&& vma
->vm_start
<= pstart
)
447 /* new a ia64_partial_page */
448 pp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
453 for (i
=start_bit
; i
<end_bit
; i
++)
454 set_bit(i
, &(pp
->bitmap
));
456 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
461 * @start and @end should be IA32 page aligned, but don't need to be in the
462 * same IA64 page. Split @start and @end to make sure they're in the same IA64
463 * page, then call __ia32_set_pp().
466 ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
468 down_write(¤t
->mm
->mmap_sem
);
469 if (flags
& MAP_FIXED
) {
471 * MAP_FIXED may lead to overlapping mmap. When this happens,
472 * a series of complete IA64 pages results in deletion of
473 * old partial pages in that range.
475 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
478 if (end
< PAGE_ALIGN(start
)) {
479 __ia32_set_pp(start
, end
, flags
);
481 if (offset_in_page(start
))
482 __ia32_set_pp(start
, PAGE_ALIGN(start
), flags
);
483 if (offset_in_page(end
))
484 __ia32_set_pp(PAGE_START(end
), end
, flags
);
486 up_write(¤t
->mm
->mmap_sem
);
490 * Unset the range between @start and @end in bitmap.
491 * @start and @end should be IA32 page aligned and in the same IA64 page.
492 * After doing that, if the bitmap is 0, then free the page and return 1,
494 * If not find the partial page in the list, then
495 * If the vma exists, then the full page is set to a partial page;
496 * Else return -ENOMEM.
499 __ia32_unset_pp(unsigned int start
, unsigned int end
)
501 struct ia64_partial_page
*pp
, *prev
;
502 struct rb_node
** rb_link
, *rb_parent
;
503 unsigned int pstart
, start_bit
, end_bit
, i
;
504 struct vm_area_struct
*vma
;
506 pstart
= PAGE_START(start
);
507 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
508 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
510 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
512 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
513 &rb_link
, &rb_parent
);
515 for (i
= start_bit
; i
< end_bit
; i
++)
516 clear_bit(i
, &pp
->bitmap
);
517 if (pp
->bitmap
== 0) {
518 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
524 vma
= find_vma(current
->mm
, pstart
);
525 if (!vma
|| vma
->vm_start
> pstart
) {
529 /* new a ia64_partial_page */
530 pp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
535 for (i
= 0; i
< start_bit
; i
++)
536 set_bit(i
, &(pp
->bitmap
));
537 for (i
= end_bit
; i
< PAGE_SIZE
/ IA32_PAGE_SIZE
; i
++)
538 set_bit(i
, &(pp
->bitmap
));
540 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
545 * Delete pp between PAGE_ALIGN(start) and PAGE_START(end) by calling
546 * __ia32_delete_pp_range(). Unset possible partial pages by calling
548 * The returned value see __ia32_unset_pp().
551 ia32_unset_pp(unsigned int *startp
, unsigned int *endp
)
553 unsigned int start
= *startp
, end
= *endp
;
556 down_write(¤t
->mm
->mmap_sem
);
558 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
560 if (end
< PAGE_ALIGN(start
)) {
561 ret
= __ia32_unset_pp(start
, end
);
563 *startp
= PAGE_START(start
);
564 *endp
= PAGE_ALIGN(end
);
567 /* to shortcut sys_munmap() in sys32_munmap() */
568 *startp
= PAGE_START(start
);
569 *endp
= PAGE_START(end
);
572 if (offset_in_page(start
)) {
573 ret
= __ia32_unset_pp(start
, PAGE_ALIGN(start
));
575 *startp
= PAGE_START(start
);
577 *startp
= PAGE_ALIGN(start
);
581 if (offset_in_page(end
)) {
582 ret
= __ia32_unset_pp(PAGE_START(end
), end
);
584 *endp
= PAGE_ALIGN(end
);
586 *endp
= PAGE_START(end
);
591 up_write(¤t
->mm
->mmap_sem
);
596 * Compare the range between @start and @end with bitmap in partial page.
597 * @start and @end should be IA32 page aligned and in the same IA64 page.
600 __ia32_compare_pp(unsigned int start
, unsigned int end
)
602 struct ia64_partial_page
*pp
, *prev
;
603 struct rb_node
** rb_link
, *rb_parent
;
604 unsigned int pstart
, start_bit
, end_bit
, size
;
605 unsigned int first_bit
, next_zero_bit
; /* the first range in bitmap */
607 pstart
= PAGE_START(start
);
609 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
610 &rb_link
, &rb_parent
);
614 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
615 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
616 size
= sizeof(pp
->bitmap
) * 8;
617 first_bit
= find_first_bit(&pp
->bitmap
, size
);
618 next_zero_bit
= find_next_zero_bit(&pp
->bitmap
, size
, first_bit
);
619 if ((start_bit
< first_bit
) || (end_bit
> next_zero_bit
)) {
620 /* exceeds the first range in bitmap */
622 } else if ((start_bit
== first_bit
) && (end_bit
== next_zero_bit
)) {
623 first_bit
= find_next_bit(&pp
->bitmap
, size
, next_zero_bit
);
624 if ((next_zero_bit
< first_bit
) && (first_bit
< size
))
625 return 1; /* has next range */
627 return 0; /* no next range */
633 * @start and @end should be IA32 page aligned, but don't need to be in the
634 * same IA64 page. Split @start and @end to make sure they're in the same IA64
635 * page, then call __ia32_compare_pp().
637 * Take this as example: the range is the 1st and 2nd 4K page.
638 * Return 0 if they fit bitmap exactly, i.e. bitmap = 00000011;
639 * Return 1 if the range doesn't cover whole bitmap, e.g. bitmap = 00001111;
640 * Return -ENOMEM if the range exceeds the bitmap, e.g. bitmap = 00000001 or
644 ia32_compare_pp(unsigned int *startp
, unsigned int *endp
)
646 unsigned int start
= *startp
, end
= *endp
;
649 down_write(¤t
->mm
->mmap_sem
);
651 if (end
< PAGE_ALIGN(start
)) {
652 retval
= __ia32_compare_pp(start
, end
);
654 *startp
= PAGE_START(start
);
655 *endp
= PAGE_ALIGN(end
);
658 if (offset_in_page(start
)) {
659 retval
= __ia32_compare_pp(start
,
662 *startp
= PAGE_START(start
);
666 if (offset_in_page(end
)) {
667 retval
= __ia32_compare_pp(PAGE_START(end
), end
);
669 *endp
= PAGE_ALIGN(end
);
674 up_write(¤t
->mm
->mmap_sem
);
679 __ia32_drop_pp_list(struct ia64_partial_page_list
*ppl
)
681 struct ia64_partial_page
*pp
= ppl
->pp_head
;
684 struct ia64_partial_page
*next
= pp
->next
;
685 kmem_cache_free(ia64_partial_page_cachep
, pp
);
693 ia32_drop_ia64_partial_page_list(struct task_struct
*task
)
695 struct ia64_partial_page_list
* ppl
= task
->thread
.ppl
;
697 if (ppl
&& atomic_dec_and_test(&ppl
->pp_count
))
698 __ia32_drop_pp_list(ppl
);
702 * Copy current->thread.ppl to ppl (already initialized).
705 __ia32_copy_pp_list(struct ia64_partial_page_list
*ppl
)
707 struct ia64_partial_page
*pp
, *tmp
, *prev
;
708 struct rb_node
**rb_link
, *rb_parent
;
712 ppl
->ppl_rb
= RB_ROOT
;
713 rb_link
= &ppl
->ppl_rb
.rb_node
;
717 for (pp
= current
->thread
.ppl
->pp_head
; pp
; pp
= pp
->next
) {
718 tmp
= kmem_cache_alloc(ia64_partial_page_cachep
, GFP_KERNEL
);
722 __ia32_insert_pp(ppl
, tmp
, prev
, rb_link
, rb_parent
);
724 rb_link
= &tmp
->pp_rb
.rb_right
;
725 rb_parent
= &tmp
->pp_rb
;
731 ia32_copy_ia64_partial_page_list(struct task_struct
*p
,
732 unsigned long clone_flags
)
736 if (clone_flags
& CLONE_VM
) {
737 atomic_inc(¤t
->thread
.ppl
->pp_count
);
738 p
->thread
.ppl
= current
->thread
.ppl
;
740 p
->thread
.ppl
= ia32_init_pp_list();
743 down_write(¤t
->mm
->mmap_sem
);
745 retval
= __ia32_copy_pp_list(p
->thread
.ppl
);
747 up_write(¤t
->mm
->mmap_sem
);
754 emulate_mmap (struct file
*file
, unsigned long start
, unsigned long len
, int prot
, int flags
,
757 unsigned long tmp
, end
, pend
, pstart
, ret
, is_congruent
, fudge
= 0;
762 pstart
= PAGE_START(start
);
763 pend
= PAGE_ALIGN(end
);
765 if (flags
& MAP_FIXED
) {
766 ia32_set_pp((unsigned int)start
, (unsigned int)end
, flags
);
767 if (start
> pstart
) {
768 if (flags
& MAP_SHARED
)
770 "%s(%d): emulate_mmap() can't share head (addr=0x%lx)\n",
771 current
->comm
, task_pid_nr(current
), start
);
772 ret
= mmap_subpage(file
, start
, min(PAGE_ALIGN(start
), end
), prot
, flags
,
774 if (IS_ERR((void *) ret
))
781 if (flags
& MAP_SHARED
)
783 "%s(%d): emulate_mmap() can't share tail (end=0x%lx)\n",
784 current
->comm
, task_pid_nr(current
), end
);
785 ret
= mmap_subpage(file
, max(start
, PAGE_START(end
)), end
, prot
, flags
,
786 (off
+ len
) - offset_in_page(end
));
787 if (IS_ERR((void *) ret
))
795 * If a start address was specified, use it if the entire rounded out area
798 if (start
&& !pstart
)
799 fudge
= 1; /* handle case of mapping to range (0,PAGE_SIZE) */
800 tmp
= arch_get_unmapped_area(file
, pstart
- fudge
, pend
- pstart
, 0, flags
);
803 start
= pstart
+ offset_in_page(off
); /* make start congruent with off */
805 pend
= PAGE_ALIGN(end
);
809 poff
= off
+ (pstart
- start
); /* note: (pstart - start) may be negative */
810 is_congruent
= (flags
& MAP_ANONYMOUS
) || (offset_in_page(poff
) == 0);
812 if ((flags
& MAP_SHARED
) && !is_congruent
)
813 printk(KERN_INFO
"%s(%d): emulate_mmap() can't share contents of incongruent mmap "
814 "(addr=0x%lx,off=0x%llx)\n", current
->comm
, task_pid_nr(current
), start
, off
);
816 DBG("mmap_body: mapping [0x%lx-0x%lx) %s with poff 0x%llx\n", pstart
, pend
,
817 is_congruent
? "congruent" : "not congruent", poff
);
819 down_write(¤t
->mm
->mmap_sem
);
821 if (!(flags
& MAP_ANONYMOUS
) && is_congruent
)
822 ret
= do_mmap(file
, pstart
, pend
- pstart
, prot
, flags
| MAP_FIXED
, poff
);
824 ret
= do_mmap(NULL
, pstart
, pend
- pstart
,
825 prot
| ((flags
& MAP_ANONYMOUS
) ? 0 : PROT_WRITE
),
826 flags
| MAP_FIXED
| MAP_ANONYMOUS
, 0);
828 up_write(¤t
->mm
->mmap_sem
);
830 if (IS_ERR((void *) ret
))
834 /* read the file contents */
835 inode
= file
->f_path
.dentry
->d_inode
;
836 if (!inode
->i_fop
|| !file
->f_op
->read
837 || ((*file
->f_op
->read
)(file
, (char __user
*) pstart
, pend
- pstart
, &poff
)
840 sys_munmap(pstart
, pend
- pstart
);
843 if (!(prot
& PROT_WRITE
) && sys_mprotect(pstart
, pend
- pstart
, prot
) < 0)
847 if (!(flags
& MAP_FIXED
))
848 ia32_set_pp((unsigned int)start
, (unsigned int)end
, flags
);
853 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
855 static inline unsigned int
856 get_prot32 (unsigned int prot
)
858 if (prot
& PROT_WRITE
)
859 /* on x86, PROT_WRITE implies PROT_READ which implies PROT_EEC */
860 prot
|= PROT_READ
| PROT_WRITE
| PROT_EXEC
;
861 else if (prot
& (PROT_READ
| PROT_EXEC
))
862 /* on x86, there is no distinction between PROT_READ and PROT_EXEC */
863 prot
|= (PROT_READ
| PROT_EXEC
);
869 ia32_do_mmap (struct file
*file
, unsigned long addr
, unsigned long len
, int prot
, int flags
,
872 DBG("ia32_do_mmap(file=%p,addr=0x%lx,len=0x%lx,prot=%x,flags=%x,offset=0x%llx)\n",
873 file
, addr
, len
, prot
, flags
, offset
);
875 if (file
&& (!file
->f_op
|| !file
->f_op
->mmap
))
878 len
= IA32_PAGE_ALIGN(len
);
882 if (len
> IA32_PAGE_OFFSET
|| addr
> IA32_PAGE_OFFSET
- len
)
884 if (flags
& MAP_FIXED
)
890 if (OFFSET4K(offset
))
893 prot
= get_prot32(prot
);
895 #if PAGE_SHIFT > IA32_PAGE_SHIFT
896 mutex_lock(&ia32_mmap_mutex
);
898 addr
= emulate_mmap(file
, addr
, len
, prot
, flags
, offset
);
900 mutex_unlock(&ia32_mmap_mutex
);
902 down_write(¤t
->mm
->mmap_sem
);
904 addr
= do_mmap(file
, addr
, len
, prot
, flags
, offset
);
906 up_write(¤t
->mm
->mmap_sem
);
908 DBG("ia32_do_mmap: returning 0x%lx\n", addr
);
913 * Linux/i386 didn't use to be able to handle more than 4 system call parameters, so these
914 * system calls used a memory block for parameter passing..
917 struct mmap_arg_struct
{
927 sys32_mmap (struct mmap_arg_struct __user
*arg
)
929 struct mmap_arg_struct a
;
930 struct file
*file
= NULL
;
934 if (copy_from_user(&a
, arg
, sizeof(a
)))
937 if (OFFSET4K(a
.offset
))
942 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
943 if (!(flags
& MAP_ANONYMOUS
)) {
949 addr
= ia32_do_mmap(file
, a
.addr
, a
.len
, a
.prot
, flags
, a
.offset
);
957 sys32_mmap2 (unsigned int addr
, unsigned int len
, unsigned int prot
, unsigned int flags
,
958 unsigned int fd
, unsigned int pgoff
)
960 struct file
*file
= NULL
;
961 unsigned long retval
;
963 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
964 if (!(flags
& MAP_ANONYMOUS
)) {
970 retval
= ia32_do_mmap(file
, addr
, len
, prot
, flags
,
971 (unsigned long) pgoff
<< IA32_PAGE_SHIFT
);
979 sys32_munmap (unsigned int start
, unsigned int len
)
981 unsigned int end
= start
+ len
;
984 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
985 ret
= sys_munmap(start
, end
- start
);
990 end
= IA32_PAGE_ALIGN(end
);
994 ret
= ia32_unset_pp(&start
, &end
);
1001 mutex_lock(&ia32_mmap_mutex
);
1002 ret
= sys_munmap(start
, end
- start
);
1003 mutex_unlock(&ia32_mmap_mutex
);
1008 #if PAGE_SHIFT > IA32_PAGE_SHIFT
1011 * When mprotect()ing a partial page, we set the permission to the union of the old
1012 * settings and the new settings. In other words, it's only possible to make access to a
1013 * partial page less restrictive.
1016 mprotect_subpage (unsigned long address
, int new_prot
)
1019 struct vm_area_struct
*vma
;
1021 if (new_prot
== PROT_NONE
)
1022 return 0; /* optimize case where nothing changes... */
1023 vma
= find_vma(current
->mm
, address
);
1024 old_prot
= get_page_prot(vma
, address
);
1025 return sys_mprotect(address
, PAGE_SIZE
, new_prot
| old_prot
);
1028 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
1031 sys32_mprotect (unsigned int start
, unsigned int len
, int prot
)
1033 unsigned int end
= start
+ len
;
1034 #if PAGE_SHIFT > IA32_PAGE_SHIFT
1038 prot
= get_prot32(prot
);
1040 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1041 return sys_mprotect(start
, end
- start
, prot
);
1043 if (OFFSET4K(start
))
1046 end
= IA32_PAGE_ALIGN(end
);
1050 retval
= ia32_compare_pp(&start
, &end
);
1055 mutex_lock(&ia32_mmap_mutex
);
1057 if (offset_in_page(start
)) {
1058 /* start address is 4KB aligned but not page aligned. */
1059 retval
= mprotect_subpage(PAGE_START(start
), prot
);
1063 start
= PAGE_ALIGN(start
);
1065 goto out
; /* retval is already zero... */
1068 if (offset_in_page(end
)) {
1069 /* end address is 4KB aligned but not page aligned. */
1070 retval
= mprotect_subpage(PAGE_START(end
), prot
);
1074 end
= PAGE_START(end
);
1076 retval
= sys_mprotect(start
, end
- start
, prot
);
1079 mutex_unlock(&ia32_mmap_mutex
);
1085 sys32_mremap (unsigned int addr
, unsigned int old_len
, unsigned int new_len
,
1086 unsigned int flags
, unsigned int new_addr
)
1090 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1091 ret
= sys_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
1093 unsigned int old_end
, new_end
;
1098 old_len
= IA32_PAGE_ALIGN(old_len
);
1099 new_len
= IA32_PAGE_ALIGN(new_len
);
1100 old_end
= addr
+ old_len
;
1101 new_end
= addr
+ new_len
;
1106 if ((flags
& MREMAP_FIXED
) && (OFFSET4K(new_addr
)))
1109 if (old_len
>= new_len
) {
1110 ret
= sys32_munmap(addr
+ new_len
, old_len
- new_len
);
1111 if (ret
&& old_len
!= new_len
)
1114 if (!(flags
& MREMAP_FIXED
) || (new_addr
== addr
))
1119 addr
= PAGE_START(addr
);
1120 old_len
= PAGE_ALIGN(old_end
) - addr
;
1121 new_len
= PAGE_ALIGN(new_end
) - addr
;
1123 mutex_lock(&ia32_mmap_mutex
);
1124 ret
= sys_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
1125 mutex_unlock(&ia32_mmap_mutex
);
1127 if ((ret
>= 0) && (old_len
< new_len
)) {
1128 /* mremap expanded successfully */
1129 ia32_set_pp(old_end
, new_end
, flags
);
1136 sys32_pipe (int __user
*fd
)
1141 retval
= do_pipe(fds
);
1144 if (copy_to_user(fd
, fds
, sizeof(fds
)))
1151 get_tv32 (struct timeval
*o
, struct compat_timeval __user
*i
)
1153 return (!access_ok(VERIFY_READ
, i
, sizeof(*i
)) ||
1154 (__get_user(o
->tv_sec
, &i
->tv_sec
) | __get_user(o
->tv_usec
, &i
->tv_usec
)));
1158 put_tv32 (struct compat_timeval __user
*o
, struct timeval
*i
)
1160 return (!access_ok(VERIFY_WRITE
, o
, sizeof(*o
)) ||
1161 (__put_user(i
->tv_sec
, &o
->tv_sec
) | __put_user(i
->tv_usec
, &o
->tv_usec
)));
1164 asmlinkage
unsigned long
1165 sys32_alarm (unsigned int seconds
)
1167 return alarm_setitimer(seconds
);
1170 /* Translations due to time_t size differences. Which affects all
1171 sorts of things, like timeval and itimerval. */
1173 extern struct timezone sys_tz
;
1176 sys32_gettimeofday (struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
1180 do_gettimeofday(&ktv
);
1181 if (put_tv32(tv
, &ktv
))
1185 if (copy_to_user(tz
, &sys_tz
, sizeof(sys_tz
)))
1192 sys32_settimeofday (struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
1195 struct timespec kts
;
1196 struct timezone ktz
;
1199 if (get_tv32(&ktv
, tv
))
1201 kts
.tv_sec
= ktv
.tv_sec
;
1202 kts
.tv_nsec
= ktv
.tv_usec
* 1000;
1205 if (copy_from_user(&ktz
, tz
, sizeof(ktz
)))
1209 return do_sys_settimeofday(tv
? &kts
: NULL
, tz
? &ktz
: NULL
);
1212 struct getdents32_callback
{
1213 struct compat_dirent __user
*current_dir
;
1214 struct compat_dirent __user
*previous
;
1219 struct readdir32_callback
{
1220 struct old_linux32_dirent __user
* dirent
;
1225 filldir32 (void *__buf
, const char *name
, int namlen
, loff_t offset
, u64 ino
,
1226 unsigned int d_type
)
1228 struct compat_dirent __user
* dirent
;
1229 struct getdents32_callback
* buf
= (struct getdents32_callback
*) __buf
;
1230 int reclen
= ROUND_UP(offsetof(struct compat_dirent
, d_name
) + namlen
+ 1, 4);
1233 buf
->error
= -EINVAL
; /* only used if we fail.. */
1234 if (reclen
> buf
->count
)
1237 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
1239 buf
->error
= -EFAULT
; /* only used if we fail.. */
1240 dirent
= buf
->previous
;
1242 if (put_user(offset
, &dirent
->d_off
))
1244 dirent
= buf
->current_dir
;
1245 buf
->previous
= dirent
;
1246 if (put_user(d_ino
, &dirent
->d_ino
)
1247 || put_user(reclen
, &dirent
->d_reclen
)
1248 || copy_to_user(dirent
->d_name
, name
, namlen
)
1249 || put_user(0, dirent
->d_name
+ namlen
))
1251 dirent
= (struct compat_dirent __user
*) ((char __user
*) dirent
+ reclen
);
1252 buf
->current_dir
= dirent
;
1253 buf
->count
-= reclen
;
1258 sys32_getdents (unsigned int fd
, struct compat_dirent __user
*dirent
, unsigned int count
)
1261 struct compat_dirent __user
* lastdirent
;
1262 struct getdents32_callback buf
;
1266 if (!access_ok(VERIFY_WRITE
, dirent
, count
))
1274 buf
.current_dir
= dirent
;
1275 buf
.previous
= NULL
;
1279 error
= vfs_readdir(file
, filldir32
, &buf
);
1283 lastdirent
= buf
.previous
;
1285 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1288 error
= count
- buf
.count
;
1298 fillonedir32 (void * __buf
, const char * name
, int namlen
, loff_t offset
, u64 ino
,
1299 unsigned int d_type
)
1301 struct readdir32_callback
* buf
= (struct readdir32_callback
*) __buf
;
1302 struct old_linux32_dirent __user
* dirent
;
1308 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
1311 dirent
= buf
->dirent
;
1312 if (put_user(d_ino
, &dirent
->d_ino
)
1313 || put_user(offset
, &dirent
->d_offset
)
1314 || put_user(namlen
, &dirent
->d_namlen
)
1315 || copy_to_user(dirent
->d_name
, name
, namlen
)
1316 || put_user(0, dirent
->d_name
+ namlen
))
1322 sys32_readdir (unsigned int fd
, void __user
*dirent
, unsigned int count
)
1326 struct readdir32_callback buf
;
1334 buf
.dirent
= dirent
;
1336 error
= vfs_readdir(file
, fillonedir32
, &buf
);
1344 struct sel_arg_struct
{
1353 sys32_old_select (struct sel_arg_struct __user
*arg
)
1355 struct sel_arg_struct a
;
1357 if (copy_from_user(&a
, arg
, sizeof(a
)))
1359 return compat_sys_select(a
.n
, compat_ptr(a
.inp
), compat_ptr(a
.outp
),
1360 compat_ptr(a
.exp
), compat_ptr(a
.tvp
));
1366 #define SEMTIMEDOP 4
1377 sys32_ipc(u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
1381 version
= call
>> 16; /* hack for backward compatibility */
1387 return compat_sys_semtimedop(first
, compat_ptr(ptr
),
1388 second
, compat_ptr(fifth
));
1389 /* else fall through for normal semop() */
1391 /* struct sembuf is the same on 32 and 64bit :)) */
1392 return sys_semtimedop(first
, compat_ptr(ptr
), second
,
1395 return sys_semget(first
, second
, third
);
1397 return compat_sys_semctl(first
, second
, third
, compat_ptr(ptr
));
1400 return compat_sys_msgsnd(first
, second
, third
, compat_ptr(ptr
));
1402 return compat_sys_msgrcv(first
, second
, fifth
, third
, version
, compat_ptr(ptr
));
1404 return sys_msgget((key_t
) first
, second
);
1406 return compat_sys_msgctl(first
, second
, compat_ptr(ptr
));
1409 return compat_sys_shmat(first
, second
, third
, version
, compat_ptr(ptr
));
1412 return sys_shmdt(compat_ptr(ptr
));
1414 return sys_shmget(first
, (unsigned)second
, third
);
1416 return compat_sys_shmctl(first
, second
, compat_ptr(ptr
));
1425 compat_sys_wait4 (compat_pid_t pid
, compat_uint_t
* stat_addr
, int options
,
1426 struct compat_rusage
*ru
);
1429 sys32_waitpid (int pid
, unsigned int *stat_addr
, int options
)
1431 return compat_sys_wait4(pid
, stat_addr
, options
, NULL
);
1435 ia32_peek (struct task_struct
*child
, unsigned long addr
, unsigned int *val
)
1440 copied
= access_process_vm(child
, addr
, val
, sizeof(*val
), 0);
1441 return (copied
!= sizeof(ret
)) ? -EIO
: 0;
1445 ia32_poke (struct task_struct
*child
, unsigned long addr
, unsigned int val
)
1448 if (access_process_vm(child
, addr
, &val
, sizeof(val
), 1) != sizeof(val
))
1454 * The order in which registers are stored in the ptrace regs structure
1467 #define PT_ORIG_EAX 11
1475 getreg (struct task_struct
*child
, int regno
)
1477 struct pt_regs
*child_regs
;
1479 child_regs
= task_pt_regs(child
);
1480 switch (regno
/ sizeof(int)) {
1481 case PT_EBX
: return child_regs
->r11
;
1482 case PT_ECX
: return child_regs
->r9
;
1483 case PT_EDX
: return child_regs
->r10
;
1484 case PT_ESI
: return child_regs
->r14
;
1485 case PT_EDI
: return child_regs
->r15
;
1486 case PT_EBP
: return child_regs
->r13
;
1487 case PT_EAX
: return child_regs
->r8
;
1488 case PT_ORIG_EAX
: return child_regs
->r1
; /* see dispatch_to_ia32_handler() */
1489 case PT_EIP
: return child_regs
->cr_iip
;
1490 case PT_UESP
: return child_regs
->r12
;
1491 case PT_EFL
: return child
->thread
.eflag
;
1492 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1494 case PT_CS
: return __USER_CS
;
1496 printk(KERN_ERR
"ia32.getreg(): unknown register %d\n", regno
);
1503 putreg (struct task_struct
*child
, int regno
, unsigned int value
)
1505 struct pt_regs
*child_regs
;
1507 child_regs
= task_pt_regs(child
);
1508 switch (regno
/ sizeof(int)) {
1509 case PT_EBX
: child_regs
->r11
= value
; break;
1510 case PT_ECX
: child_regs
->r9
= value
; break;
1511 case PT_EDX
: child_regs
->r10
= value
; break;
1512 case PT_ESI
: child_regs
->r14
= value
; break;
1513 case PT_EDI
: child_regs
->r15
= value
; break;
1514 case PT_EBP
: child_regs
->r13
= value
; break;
1515 case PT_EAX
: child_regs
->r8
= value
; break;
1516 case PT_ORIG_EAX
: child_regs
->r1
= value
; break;
1517 case PT_EIP
: child_regs
->cr_iip
= value
; break;
1518 case PT_UESP
: child_regs
->r12
= value
; break;
1519 case PT_EFL
: child
->thread
.eflag
= value
; break;
1520 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1521 if (value
!= __USER_DS
)
1523 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1527 if (value
!= __USER_CS
)
1529 "ia32.putreg: attempt to to set invalid segment register %d = %x\n",
1533 printk(KERN_ERR
"ia32.putreg: unknown register %d\n", regno
);
1539 put_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1540 struct switch_stack
*swp
, int tos
)
1542 struct _fpreg_ia32
*f
;
1545 f
= (struct _fpreg_ia32
*)(((unsigned long)buf
+ 15) & ~15);
1546 if ((regno
+= tos
) >= 8)
1550 ia64f2ia32f(f
, &ptp
->f8
);
1553 ia64f2ia32f(f
, &ptp
->f9
);
1556 ia64f2ia32f(f
, &ptp
->f10
);
1559 ia64f2ia32f(f
, &ptp
->f11
);
1565 ia64f2ia32f(f
, &swp
->f12
+ (regno
- 4));
1568 copy_to_user(reg
, f
, sizeof(*reg
));
1572 get_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1573 struct switch_stack
*swp
, int tos
)
1576 if ((regno
+= tos
) >= 8)
1580 copy_from_user(&ptp
->f8
, reg
, sizeof(*reg
));
1583 copy_from_user(&ptp
->f9
, reg
, sizeof(*reg
));
1586 copy_from_user(&ptp
->f10
, reg
, sizeof(*reg
));
1589 copy_from_user(&ptp
->f11
, reg
, sizeof(*reg
));
1595 copy_from_user(&swp
->f12
+ (regno
- 4), reg
, sizeof(*reg
));
1602 save_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1604 struct switch_stack
*swp
;
1605 struct pt_regs
*ptp
;
1608 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1611 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1612 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1613 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1614 __put_user(tsk
->thread
.fir
, &save
->fip
);
1615 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1616 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1617 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1620 * Stack frames start with 16-bytes of temp space
1622 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1623 ptp
= task_pt_regs(tsk
);
1624 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1625 for (i
= 0; i
< 8; i
++)
1626 put_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1631 restore_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1633 struct switch_stack
*swp
;
1634 struct pt_regs
*ptp
;
1636 unsigned int fsrlo
, fsrhi
, num32
;
1638 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1641 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1642 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1643 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1644 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1645 num32
= (fsrhi
<< 16) | fsrlo
;
1646 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1647 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1648 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1649 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1650 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1653 * Stack frames start with 16-bytes of temp space
1655 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1656 ptp
= task_pt_regs(tsk
);
1657 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1658 for (i
= 0; i
< 8; i
++)
1659 get_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1664 save_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1666 struct switch_stack
*swp
;
1667 struct pt_regs
*ptp
;
1669 unsigned long mxcsr
=0;
1670 unsigned long num128
[2];
1672 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1675 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1676 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1677 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1678 __put_user(tsk
->thread
.fir
, &save
->fip
);
1679 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1680 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1681 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1684 * Stack frames start with 16-bytes of temp space
1686 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1687 ptp
= task_pt_regs(tsk
);
1688 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1689 for (i
= 0; i
< 8; i
++)
1690 put_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1692 mxcsr
= ((tsk
->thread
.fcr
>>32) & 0xff80) | ((tsk
->thread
.fsr
>>32) & 0x3f);
1693 __put_user(mxcsr
& 0xffff, &save
->mxcsr
);
1694 for (i
= 0; i
< 8; i
++) {
1695 memcpy(&(num128
[0]), &(swp
->f16
) + i
*2, sizeof(unsigned long));
1696 memcpy(&(num128
[1]), &(swp
->f17
) + i
*2, sizeof(unsigned long));
1697 copy_to_user(&save
->xmm_space
[0] + 4*i
, num128
, sizeof(struct _xmmreg_ia32
));
1703 restore_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1705 struct switch_stack
*swp
;
1706 struct pt_regs
*ptp
;
1708 unsigned int fsrlo
, fsrhi
, num32
;
1710 unsigned long num64
;
1711 unsigned long num128
[2];
1713 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1716 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1717 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1718 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1719 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1720 num32
= (fsrhi
<< 16) | fsrlo
;
1721 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1722 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1723 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1724 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1725 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1728 * Stack frames start with 16-bytes of temp space
1730 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1731 ptp
= task_pt_regs(tsk
);
1732 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1733 for (i
= 0; i
< 8; i
++)
1734 get_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1736 __get_user(mxcsr
, (unsigned int __user
*)&save
->mxcsr
);
1737 num64
= mxcsr
& 0xff10;
1738 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0xff1000000000UL
)) | (num64
<<32);
1739 num64
= mxcsr
& 0x3f;
1740 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0x3f00000000UL
)) | (num64
<<32);
1742 for (i
= 0; i
< 8; i
++) {
1743 copy_from_user(num128
, &save
->xmm_space
[0] + 4*i
, sizeof(struct _xmmreg_ia32
));
1744 memcpy(&(swp
->f16
) + i
*2, &(num128
[0]), sizeof(unsigned long));
1745 memcpy(&(swp
->f17
) + i
*2, &(num128
[1]), sizeof(unsigned long));
1751 sys32_ptrace (int request
, pid_t pid
, unsigned int addr
, unsigned int data
)
1753 struct task_struct
*child
;
1754 unsigned int value
, tmp
;
1758 if (request
== PTRACE_TRACEME
) {
1759 ret
= ptrace_traceme();
1763 child
= ptrace_get_task_struct(pid
);
1764 if (IS_ERR(child
)) {
1765 ret
= PTR_ERR(child
);
1769 if (request
== PTRACE_ATTACH
) {
1770 ret
= sys_ptrace(request
, pid
, addr
, data
);
1774 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
1779 case PTRACE_PEEKTEXT
:
1780 case PTRACE_PEEKDATA
: /* read word at location addr */
1781 ret
= ia32_peek(child
, addr
, &value
);
1783 ret
= put_user(value
, (unsigned int __user
*) compat_ptr(data
));
1788 case PTRACE_POKETEXT
:
1789 case PTRACE_POKEDATA
: /* write the word at location addr */
1790 ret
= ia32_poke(child
, addr
, data
);
1793 case PTRACE_PEEKUSR
: /* read word at addr in USER area */
1795 if ((addr
& 3) || addr
> 17*sizeof(int))
1798 tmp
= getreg(child
, addr
);
1799 if (!put_user(tmp
, (unsigned int __user
*) compat_ptr(data
)))
1803 case PTRACE_POKEUSR
: /* write word at addr in USER area */
1805 if ((addr
& 3) || addr
> 17*sizeof(int))
1808 putreg(child
, addr
, data
);
1812 case IA32_PTRACE_GETREGS
:
1813 if (!access_ok(VERIFY_WRITE
, compat_ptr(data
), 17*sizeof(int))) {
1817 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1818 put_user(getreg(child
, i
), (unsigned int __user
*) compat_ptr(data
));
1819 data
+= sizeof(int);
1824 case IA32_PTRACE_SETREGS
:
1825 if (!access_ok(VERIFY_READ
, compat_ptr(data
), 17*sizeof(int))) {
1829 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1830 get_user(tmp
, (unsigned int __user
*) compat_ptr(data
));
1831 putreg(child
, i
, tmp
);
1832 data
+= sizeof(int);
1837 case IA32_PTRACE_GETFPREGS
:
1838 ret
= save_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1842 case IA32_PTRACE_GETFPXREGS
:
1843 ret
= save_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1847 case IA32_PTRACE_SETFPREGS
:
1848 ret
= restore_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1852 case IA32_PTRACE_SETFPXREGS
:
1853 ret
= restore_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1857 case PTRACE_GETEVENTMSG
:
1858 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) compat_ptr(data
));
1861 case PTRACE_SYSCALL
: /* continue, stop after next syscall */
1862 case PTRACE_CONT
: /* restart after signal. */
1864 case PTRACE_SINGLESTEP
: /* execute chile for one instruction */
1865 case PTRACE_DETACH
: /* detach a process */
1866 ret
= sys_ptrace(request
, pid
, addr
, data
);
1870 ret
= ptrace_request(child
, request
, addr
, data
);
1875 put_task_struct(child
);
1883 unsigned int ss_flags
;
1884 unsigned int ss_size
;
1888 sys32_sigaltstack (ia32_stack_t __user
*uss32
, ia32_stack_t __user
*uoss32
,
1889 long arg2
, long arg3
, long arg4
, long arg5
, long arg6
,
1890 long arg7
, struct pt_regs pt
)
1895 mm_segment_t old_fs
= get_fs();
1898 if (copy_from_user(&buf32
, uss32
, sizeof(ia32_stack_t
)))
1900 uss
.ss_sp
= (void __user
*) (long) buf32
.ss_sp
;
1901 uss
.ss_flags
= buf32
.ss_flags
;
1902 /* MINSIGSTKSZ is different for ia32 vs ia64. We lie here to pass the
1903 check and set it to the user requested value later */
1904 if ((buf32
.ss_flags
!= SS_DISABLE
) && (buf32
.ss_size
< MINSIGSTKSZ_IA32
)) {
1908 uss
.ss_size
= MINSIGSTKSZ
;
1911 ret
= do_sigaltstack(uss32
? (stack_t __user
*) &uss
: NULL
,
1912 (stack_t __user
*) &uoss
, pt
.r12
);
1913 current
->sas_ss_size
= buf32
.ss_size
;
1919 buf32
.ss_sp
= (long __user
) uoss
.ss_sp
;
1920 buf32
.ss_flags
= uoss
.ss_flags
;
1921 buf32
.ss_size
= uoss
.ss_size
;
1922 if (copy_to_user(uoss32
, &buf32
, sizeof(ia32_stack_t
)))
1931 current
->state
= TASK_INTERRUPTIBLE
;
1933 return -ERESTARTNOHAND
;
1937 sys32_msync (unsigned int start
, unsigned int len
, int flags
)
1941 if (OFFSET4K(start
))
1943 addr
= PAGE_START(start
);
1944 return sys_msync(addr
, len
+ (start
- addr
), flags
);
1950 unsigned int oldval
;
1951 unsigned int oldlenp
;
1952 unsigned int newval
;
1953 unsigned int newlen
;
1954 unsigned int __unused
[4];
1957 #ifdef CONFIG_SYSCTL_SYSCALL
1959 sys32_sysctl (struct sysctl32 __user
*args
)
1961 struct sysctl32 a32
;
1962 mm_segment_t old_fs
= get_fs ();
1963 void __user
*oldvalp
, *newvalp
;
1968 if (copy_from_user(&a32
, args
, sizeof(a32
)))
1972 * We need to pre-validate these because we have to disable address checking
1973 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
1974 * user specifying bad addresses here. Well, since we're dealing with 32 bit
1975 * addresses, we KNOW that access_ok() will always succeed, so this is an
1976 * expensive NOP, but so what...
1978 namep
= (int __user
*) compat_ptr(a32
.name
);
1979 oldvalp
= compat_ptr(a32
.oldval
);
1980 newvalp
= compat_ptr(a32
.newval
);
1982 if ((oldvalp
&& get_user(oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
1983 || !access_ok(VERIFY_WRITE
, namep
, 0)
1984 || !access_ok(VERIFY_WRITE
, oldvalp
, 0)
1985 || !access_ok(VERIFY_WRITE
, newvalp
, 0))
1990 ret
= do_sysctl(namep
, a32
.nlen
, oldvalp
, (size_t __user
*) &oldlen
,
1991 newvalp
, (size_t) a32
.newlen
);
1995 if (oldvalp
&& put_user (oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
2003 sys32_newuname (struct new_utsname __user
*name
)
2005 int ret
= sys_newuname(name
);
2008 if (copy_to_user(name
->machine
, "i686\0\0\0", 8))
2014 sys32_getresuid16 (u16 __user
*ruid
, u16 __user
*euid
, u16 __user
*suid
)
2018 mm_segment_t old_fs
= get_fs();
2021 ret
= sys_getresuid((uid_t __user
*) &a
, (uid_t __user
*) &b
, (uid_t __user
*) &c
);
2024 if (put_user(a
, ruid
) || put_user(b
, euid
) || put_user(c
, suid
))
2030 sys32_getresgid16 (u16 __user
*rgid
, u16 __user
*egid
, u16 __user
*sgid
)
2034 mm_segment_t old_fs
= get_fs();
2037 ret
= sys_getresgid((gid_t __user
*) &a
, (gid_t __user
*) &b
, (gid_t __user
*) &c
);
2043 return put_user(a
, rgid
) | put_user(b
, egid
) | put_user(c
, sgid
);
2047 sys32_lseek (unsigned int fd
, int offset
, unsigned int whence
)
2049 /* Sign-extension of "offset" is important here... */
2050 return sys_lseek(fd
, offset
, whence
);
2054 groups16_to_user(short __user
*grouplist
, struct group_info
*group_info
)
2059 for (i
= 0; i
< group_info
->ngroups
; i
++) {
2060 group
= (short)GROUP_AT(group_info
, i
);
2061 if (put_user(group
, grouplist
+i
))
2069 groups16_from_user(struct group_info
*group_info
, short __user
*grouplist
)
2074 for (i
= 0; i
< group_info
->ngroups
; i
++) {
2075 if (get_user(group
, grouplist
+i
))
2077 GROUP_AT(group_info
, i
) = (gid_t
)group
;
2084 sys32_getgroups16 (int gidsetsize
, short __user
*grouplist
)
2091 get_group_info(current
->group_info
);
2092 i
= current
->group_info
->ngroups
;
2094 if (i
> gidsetsize
) {
2098 if (groups16_to_user(grouplist
, current
->group_info
)) {
2104 put_group_info(current
->group_info
);
2109 sys32_setgroups16 (int gidsetsize
, short __user
*grouplist
)
2111 struct group_info
*group_info
;
2114 if (!capable(CAP_SETGID
))
2116 if ((unsigned)gidsetsize
> NGROUPS_MAX
)
2119 group_info
= groups_alloc(gidsetsize
);
2122 retval
= groups16_from_user(group_info
, grouplist
);
2124 put_group_info(group_info
);
2128 retval
= set_current_groups(group_info
);
2129 put_group_info(group_info
);
2135 sys32_truncate64 (unsigned int path
, unsigned int len_lo
, unsigned int len_hi
)
2137 return sys_truncate(compat_ptr(path
), ((unsigned long) len_hi
<< 32) | len_lo
);
2141 sys32_ftruncate64 (int fd
, unsigned int len_lo
, unsigned int len_hi
)
2143 return sys_ftruncate(fd
, ((unsigned long) len_hi
<< 32) | len_lo
);
2147 putstat64 (struct stat64 __user
*ubuf
, struct kstat
*kbuf
)
2152 if (clear_user(ubuf
, sizeof(*ubuf
)))
2155 hdev
= huge_encode_dev(kbuf
->dev
);
2156 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_dev
);
2157 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_dev
) + 1);
2158 err
|= __put_user(kbuf
->ino
, &ubuf
->__st_ino
);
2159 err
|= __put_user(kbuf
->ino
, &ubuf
->st_ino_lo
);
2160 err
|= __put_user(kbuf
->ino
>> 32, &ubuf
->st_ino_hi
);
2161 err
|= __put_user(kbuf
->mode
, &ubuf
->st_mode
);
2162 err
|= __put_user(kbuf
->nlink
, &ubuf
->st_nlink
);
2163 err
|= __put_user(kbuf
->uid
, &ubuf
->st_uid
);
2164 err
|= __put_user(kbuf
->gid
, &ubuf
->st_gid
);
2165 hdev
= huge_encode_dev(kbuf
->rdev
);
2166 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_rdev
);
2167 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_rdev
) + 1);
2168 err
|= __put_user(kbuf
->size
, &ubuf
->st_size_lo
);
2169 err
|= __put_user((kbuf
->size
>> 32), &ubuf
->st_size_hi
);
2170 err
|= __put_user(kbuf
->atime
.tv_sec
, &ubuf
->st_atime
);
2171 err
|= __put_user(kbuf
->atime
.tv_nsec
, &ubuf
->st_atime_nsec
);
2172 err
|= __put_user(kbuf
->mtime
.tv_sec
, &ubuf
->st_mtime
);
2173 err
|= __put_user(kbuf
->mtime
.tv_nsec
, &ubuf
->st_mtime_nsec
);
2174 err
|= __put_user(kbuf
->ctime
.tv_sec
, &ubuf
->st_ctime
);
2175 err
|= __put_user(kbuf
->ctime
.tv_nsec
, &ubuf
->st_ctime_nsec
);
2176 err
|= __put_user(kbuf
->blksize
, &ubuf
->st_blksize
);
2177 err
|= __put_user(kbuf
->blocks
, &ubuf
->st_blocks
);
2182 sys32_stat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
2185 long ret
= vfs_stat(filename
, &s
);
2187 ret
= putstat64(statbuf
, &s
);
2192 sys32_lstat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
2195 long ret
= vfs_lstat(filename
, &s
);
2197 ret
= putstat64(statbuf
, &s
);
2202 sys32_fstat64 (unsigned int fd
, struct stat64 __user
*statbuf
)
2205 long ret
= vfs_fstat(fd
, &s
);
2207 ret
= putstat64(statbuf
, &s
);
2212 sys32_sched_rr_get_interval (pid_t pid
, struct compat_timespec __user
*interval
)
2214 mm_segment_t old_fs
= get_fs();
2219 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*) &t
);
2221 if (put_compat_timespec(&t
, interval
))
2227 sys32_pread (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
2229 return sys_pread64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
2233 sys32_pwrite (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
2235 return sys_pwrite64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
2239 sys32_sendfile (int out_fd
, int in_fd
, int __user
*offset
, unsigned int count
)
2241 mm_segment_t old_fs
= get_fs();
2245 if (offset
&& get_user(of
, offset
))
2249 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*) &of
: NULL
, count
);
2252 if (offset
&& put_user(of
, offset
))
2259 sys32_personality (unsigned int personality
)
2263 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
2264 personality
= PER_LINUX32
;
2265 ret
= sys_personality(personality
);
2266 if (ret
== PER_LINUX32
)
2271 asmlinkage
unsigned long
2272 sys32_brk (unsigned int brk
)
2274 unsigned long ret
, obrk
;
2275 struct mm_struct
*mm
= current
->mm
;
2280 clear_user(compat_ptr(ret
), PAGE_ALIGN(ret
) - ret
);
2284 /* Structure for ia32 emulation on ia64 */
2285 struct epoll_event32
2292 sys32_epoll_ctl(int epfd
, int op
, int fd
, struct epoll_event32 __user
*event
)
2294 mm_segment_t old_fs
= get_fs();
2295 struct epoll_event event64
;
2299 if (!access_ok(VERIFY_READ
, event
, sizeof(struct epoll_event32
)))
2302 __get_user(event64
.events
, &event
->events
);
2303 __get_user(data_halfword
, &event
->data
[0]);
2304 event64
.data
= data_halfword
;
2305 __get_user(data_halfword
, &event
->data
[1]);
2306 event64
.data
|= (u64
)data_halfword
<< 32;
2309 error
= sys_epoll_ctl(epfd
, op
, fd
, (struct epoll_event __user
*) &event64
);
2316 sys32_epoll_wait(int epfd
, struct epoll_event32 __user
* events
, int maxevents
,
2319 struct epoll_event
*events64
= NULL
;
2320 mm_segment_t old_fs
= get_fs();
2321 int numevents
, size
;
2323 int do_free_pages
= 0;
2325 if (maxevents
<= 0) {
2329 /* Verify that the area passed by the user is writeable */
2330 if (!access_ok(VERIFY_WRITE
, events
, maxevents
* sizeof(struct epoll_event32
)))
2334 * Allocate space for the intermediate copy. If the space needed
2335 * is large enough to cause kmalloc to fail, then try again with
2338 size
= maxevents
* sizeof(struct epoll_event
);
2339 events64
= kmalloc(size
, GFP_KERNEL
);
2340 if (events64
== NULL
) {
2341 events64
= (struct epoll_event
*)
2342 __get_free_pages(GFP_KERNEL
, get_order(size
));
2343 if (events64
== NULL
)
2348 /* Do the system call */
2349 set_fs(KERNEL_DS
); /* copy_to/from_user should work on kernel mem*/
2350 numevents
= sys_epoll_wait(epfd
, (struct epoll_event __user
*) events64
,
2351 maxevents
, timeout
);
2354 /* Don't modify userspace memory if we're returning an error */
2355 if (numevents
> 0) {
2356 /* Translate the 64-bit structures back into the 32-bit
2358 for (evt_idx
= 0; evt_idx
< numevents
; evt_idx
++) {
2359 __put_user(events64
[evt_idx
].events
,
2360 &events
[evt_idx
].events
);
2361 __put_user((u32
)events64
[evt_idx
].data
,
2362 &events
[evt_idx
].data
[0]);
2363 __put_user((u32
)(events64
[evt_idx
].data
>> 32),
2364 &events
[evt_idx
].data
[1]);
2369 free_pages((unsigned long) events64
, get_order(size
));
2376 * Get a yet unused TLS descriptor index.
2381 struct thread_struct
*t
= ¤t
->thread
;
2384 for (idx
= 0; idx
< GDT_ENTRY_TLS_ENTRIES
; idx
++)
2385 if (desc_empty(t
->tls_array
+ idx
))
2386 return idx
+ GDT_ENTRY_TLS_MIN
;
2391 * Set a given TLS descriptor:
2394 sys32_set_thread_area (struct ia32_user_desc __user
*u_info
)
2396 struct thread_struct
*t
= ¤t
->thread
;
2397 struct ia32_user_desc info
;
2398 struct desc_struct
*desc
;
2401 if (copy_from_user(&info
, u_info
, sizeof(info
)))
2403 idx
= info
.entry_number
;
2406 * index -1 means the kernel should try to find and allocate an empty descriptor:
2409 idx
= get_free_idx();
2412 if (put_user(idx
, &u_info
->entry_number
))
2416 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2419 desc
= t
->tls_array
+ idx
- GDT_ENTRY_TLS_MIN
;
2421 cpu
= smp_processor_id();
2423 if (LDT_empty(&info
)) {
2427 desc
->a
= LDT_entry_a(&info
);
2428 desc
->b
= LDT_entry_b(&info
);
2435 * Get the current Thread-Local Storage area:
2438 #define GET_BASE(desc) ( \
2439 (((desc)->a >> 16) & 0x0000ffff) | \
2440 (((desc)->b << 16) & 0x00ff0000) | \
2441 ( (desc)->b & 0xff000000) )
2443 #define GET_LIMIT(desc) ( \
2444 ((desc)->a & 0x0ffff) | \
2445 ((desc)->b & 0xf0000) )
2447 #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
2448 #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
2449 #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
2450 #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
2451 #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
2452 #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
2455 sys32_get_thread_area (struct ia32_user_desc __user
*u_info
)
2457 struct ia32_user_desc info
;
2458 struct desc_struct
*desc
;
2461 if (get_user(idx
, &u_info
->entry_number
))
2463 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2466 desc
= current
->thread
.tls_array
+ idx
- GDT_ENTRY_TLS_MIN
;
2468 info
.entry_number
= idx
;
2469 info
.base_addr
= GET_BASE(desc
);
2470 info
.limit
= GET_LIMIT(desc
);
2471 info
.seg_32bit
= GET_32BIT(desc
);
2472 info
.contents
= GET_CONTENTS(desc
);
2473 info
.read_exec_only
= !GET_WRITABLE(desc
);
2474 info
.limit_in_pages
= GET_LIMIT_PAGES(desc
);
2475 info
.seg_not_present
= !GET_PRESENT(desc
);
2476 info
.useable
= GET_USEABLE(desc
);
2478 if (copy_to_user(u_info
, &info
, sizeof(info
)))
2483 long sys32_fadvise64_64(int fd
, __u32 offset_low
, __u32 offset_high
,
2484 __u32 len_low
, __u32 len_high
, int advice
)
2486 return sys_fadvise64_64(fd
,
2487 (((u64
)offset_high
)<<32) | offset_low
,
2488 (((u64
)len_high
)<<32) | len_low
,
2492 #ifdef NOTYET /* UNTESTED FOR IA64 FROM HERE DOWN */
2494 asmlinkage
long sys32_setreuid(compat_uid_t ruid
, compat_uid_t euid
)
2498 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2499 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2500 return sys_setreuid(sruid
, seuid
);
2504 sys32_setresuid(compat_uid_t ruid
, compat_uid_t euid
,
2507 uid_t sruid
, seuid
, ssuid
;
2509 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2510 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2511 ssuid
= (suid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)suid
);
2512 return sys_setresuid(sruid
, seuid
, ssuid
);
2516 sys32_setregid(compat_gid_t rgid
, compat_gid_t egid
)
2520 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2521 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2522 return sys_setregid(srgid
, segid
);
2526 sys32_setresgid(compat_gid_t rgid
, compat_gid_t egid
,
2529 gid_t srgid
, segid
, ssgid
;
2531 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2532 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2533 ssgid
= (sgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)sgid
);
2534 return sys_setresgid(srgid
, segid
, ssgid
);