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/nfs_fs.h>
36 #include <linux/quota.h>
37 #include <linux/syscalls.h>
38 #include <linux/sunrpc/svc.h>
39 #include <linux/nfsd/nfsd.h>
40 #include <linux/nfsd/cache.h>
41 #include <linux/nfsd/xdr.h>
42 #include <linux/nfsd/syscall.h>
43 #include <linux/poll.h>
44 #include <linux/eventpoll.h>
45 #include <linux/personality.h>
46 #include <linux/ptrace.h>
47 #include <linux/stat.h>
48 #include <linux/ipc.h>
49 #include <linux/capability.h>
50 #include <linux/compat.h>
51 #include <linux/vfs.h>
52 #include <linux/mman.h>
53 #include <linux/mutex.h>
55 #include <asm/intrinsics.h>
56 #include <asm/types.h>
57 #include <asm/uaccess.h>
58 #include <asm/unistd.h>
68 # define DBG(fmt...) printk(KERN_DEBUG fmt)
73 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
75 #define OFFSET4K(a) ((a) & 0xfff)
76 #define PAGE_START(addr) ((addr) & PAGE_MASK)
77 #define MINSIGSTKSZ_IA32 2048
79 #define high2lowuid(uid) ((uid) > 65535 ? 65534 : (uid))
80 #define high2lowgid(gid) ((gid) > 65535 ? 65534 : (gid))
83 * Anything that modifies or inspects ia32 user virtual memory must hold this semaphore
86 /* XXX make per-mm: */
87 static DEFINE_MUTEX(ia32_mmap_mutex
);
90 sys32_execve (char __user
*name
, compat_uptr_t __user
*argv
, compat_uptr_t __user
*envp
,
95 unsigned long old_map_base
, old_task_size
, tssd
;
97 filename
= getname(name
);
98 error
= PTR_ERR(filename
);
102 old_map_base
= current
->thread
.map_base
;
103 old_task_size
= current
->thread
.task_size
;
104 tssd
= ia64_get_kr(IA64_KR_TSSD
);
106 /* we may be exec'ing a 64-bit process: reset map base, task-size, and io-base: */
107 current
->thread
.map_base
= DEFAULT_MAP_BASE
;
108 current
->thread
.task_size
= DEFAULT_TASK_SIZE
;
109 ia64_set_kr(IA64_KR_IO_BASE
, current
->thread
.old_iob
);
110 ia64_set_kr(IA64_KR_TSSD
, current
->thread
.old_k1
);
112 error
= compat_do_execve(filename
, argv
, envp
, regs
);
116 /* oops, execve failed, switch back to old values... */
117 ia64_set_kr(IA64_KR_IO_BASE
, IA32_IOBASE
);
118 ia64_set_kr(IA64_KR_TSSD
, tssd
);
119 current
->thread
.map_base
= old_map_base
;
120 current
->thread
.task_size
= old_task_size
;
126 int cp_compat_stat(struct kstat
*stat
, struct compat_stat __user
*ubuf
)
130 if ((u64
) stat
->size
> MAX_NON_LFS
||
131 !old_valid_dev(stat
->dev
) ||
132 !old_valid_dev(stat
->rdev
))
135 if (clear_user(ubuf
, sizeof(*ubuf
)))
138 err
= __put_user(old_encode_dev(stat
->dev
), &ubuf
->st_dev
);
139 err
|= __put_user(stat
->ino
, &ubuf
->st_ino
);
140 err
|= __put_user(stat
->mode
, &ubuf
->st_mode
);
141 err
|= __put_user(stat
->nlink
, &ubuf
->st_nlink
);
142 err
|= __put_user(high2lowuid(stat
->uid
), &ubuf
->st_uid
);
143 err
|= __put_user(high2lowgid(stat
->gid
), &ubuf
->st_gid
);
144 err
|= __put_user(old_encode_dev(stat
->rdev
), &ubuf
->st_rdev
);
145 err
|= __put_user(stat
->size
, &ubuf
->st_size
);
146 err
|= __put_user(stat
->atime
.tv_sec
, &ubuf
->st_atime
);
147 err
|= __put_user(stat
->atime
.tv_nsec
, &ubuf
->st_atime_nsec
);
148 err
|= __put_user(stat
->mtime
.tv_sec
, &ubuf
->st_mtime
);
149 err
|= __put_user(stat
->mtime
.tv_nsec
, &ubuf
->st_mtime_nsec
);
150 err
|= __put_user(stat
->ctime
.tv_sec
, &ubuf
->st_ctime
);
151 err
|= __put_user(stat
->ctime
.tv_nsec
, &ubuf
->st_ctime_nsec
);
152 err
|= __put_user(stat
->blksize
, &ubuf
->st_blksize
);
153 err
|= __put_user(stat
->blocks
, &ubuf
->st_blocks
);
157 #if PAGE_SHIFT > IA32_PAGE_SHIFT
161 get_page_prot (struct vm_area_struct
*vma
, unsigned long addr
)
165 if (!vma
|| vma
->vm_start
> addr
)
168 if (vma
->vm_flags
& VM_READ
)
170 if (vma
->vm_flags
& VM_WRITE
)
172 if (vma
->vm_flags
& VM_EXEC
)
178 * Map a subpage by creating an anonymous page that contains the union of the old page and
182 mmap_subpage (struct file
*file
, unsigned long start
, unsigned long end
, int prot
, int flags
,
187 unsigned long ret
= 0;
188 struct vm_area_struct
*vma
= find_vma(current
->mm
, start
);
189 int old_prot
= get_page_prot(vma
, start
);
191 DBG("mmap_subpage(file=%p,start=0x%lx,end=0x%lx,prot=%x,flags=%x,off=0x%llx)\n",
192 file
, start
, end
, prot
, flags
, off
);
195 /* Optimize the case where the old mmap and the new mmap are both anonymous */
196 if ((old_prot
& PROT_WRITE
) && (flags
& MAP_ANONYMOUS
) && !vma
->vm_file
) {
197 if (clear_user((void __user
*) start
, end
- start
)) {
204 page
= (void *) get_zeroed_page(GFP_KERNEL
);
209 copy_from_user(page
, (void __user
*) PAGE_START(start
), PAGE_SIZE
);
211 down_write(¤t
->mm
->mmap_sem
);
213 ret
= do_mmap(NULL
, PAGE_START(start
), PAGE_SIZE
, prot
| PROT_WRITE
,
214 flags
| MAP_FIXED
| MAP_ANONYMOUS
, 0);
216 up_write(¤t
->mm
->mmap_sem
);
218 if (IS_ERR((void *) ret
))
222 /* copy back the old page contents. */
223 if (offset_in_page(start
))
224 copy_to_user((void __user
*) PAGE_START(start
), page
,
225 offset_in_page(start
));
226 if (offset_in_page(end
))
227 copy_to_user((void __user
*) end
, page
+ offset_in_page(end
),
228 PAGE_SIZE
- offset_in_page(end
));
231 if (!(flags
& MAP_ANONYMOUS
)) {
232 /* read the file contents */
233 inode
= file
->f_dentry
->d_inode
;
234 if (!inode
->i_fop
|| !file
->f_op
->read
235 || ((*file
->f_op
->read
)(file
, (char __user
*) start
, end
- start
, &off
) < 0))
243 if (!(prot
& PROT_WRITE
))
244 ret
= sys_mprotect(PAGE_START(start
), PAGE_SIZE
, prot
| old_prot
);
247 free_page((unsigned long) page
);
251 /* SLAB cache for partial_page structures */
252 kmem_cache_t
*partial_page_cachep
;
255 * init partial_page_list.
256 * return 0 means kmalloc fail.
258 struct partial_page_list
*
259 ia32_init_pp_list(void)
261 struct partial_page_list
*p
;
263 if ((p
= kmalloc(sizeof(*p
), GFP_KERNEL
)) == NULL
)
268 atomic_set(&p
->pp_count
, 1);
273 * Search for the partial page with @start in partial page list @ppl.
274 * If finds the partial page, return the found partial page.
275 * Else, return 0 and provide @pprev, @rb_link, @rb_parent to
276 * be used by later __ia32_insert_pp().
278 static struct partial_page
*
279 __ia32_find_pp(struct partial_page_list
*ppl
, unsigned int start
,
280 struct partial_page
**pprev
, struct rb_node
***rb_link
,
281 struct rb_node
**rb_parent
)
283 struct partial_page
*pp
;
284 struct rb_node
**__rb_link
, *__rb_parent
, *rb_prev
;
287 if (pp
&& pp
->base
== start
)
290 __rb_link
= &ppl
->ppl_rb
.rb_node
;
291 rb_prev
= __rb_parent
= NULL
;
294 __rb_parent
= *__rb_link
;
295 pp
= rb_entry(__rb_parent
, struct partial_page
, pp_rb
);
297 if (pp
->base
== start
) {
300 } else if (pp
->base
< start
) {
301 rb_prev
= __rb_parent
;
302 __rb_link
= &__rb_parent
->rb_right
;
304 __rb_link
= &__rb_parent
->rb_left
;
308 *rb_link
= __rb_link
;
309 *rb_parent
= __rb_parent
;
312 *pprev
= rb_entry(rb_prev
, struct partial_page
, pp_rb
);
317 * insert @pp into @ppl.
320 __ia32_insert_pp(struct partial_page_list
*ppl
, struct partial_page
*pp
,
321 struct partial_page
*prev
, struct rb_node
**rb_link
,
322 struct rb_node
*rb_parent
)
326 pp
->next
= prev
->next
;
331 pp
->next
= rb_entry(rb_parent
,
332 struct partial_page
, pp_rb
);
338 rb_link_node(&pp
->pp_rb
, rb_parent
, rb_link
);
339 rb_insert_color(&pp
->pp_rb
, &ppl
->ppl_rb
);
345 * delete @pp from partial page list @ppl.
348 __ia32_delete_pp(struct partial_page_list
*ppl
, struct partial_page
*pp
,
349 struct partial_page
*prev
)
352 prev
->next
= pp
->next
;
353 if (ppl
->pp_hint
== pp
)
356 ppl
->pp_head
= pp
->next
;
357 if (ppl
->pp_hint
== pp
)
358 ppl
->pp_hint
= pp
->next
;
360 rb_erase(&pp
->pp_rb
, &ppl
->ppl_rb
);
361 kmem_cache_free(partial_page_cachep
, pp
);
364 static struct partial_page
*
365 __pp_prev(struct partial_page
*pp
)
367 struct rb_node
*prev
= rb_prev(&pp
->pp_rb
);
369 return rb_entry(prev
, struct partial_page
, pp_rb
);
375 * Delete partial pages with address between @start and @end.
376 * @start and @end are page aligned.
379 __ia32_delete_pp_range(unsigned int start
, unsigned int end
)
381 struct partial_page
*pp
, *prev
;
382 struct rb_node
**rb_link
, *rb_parent
;
387 pp
= __ia32_find_pp(current
->thread
.ppl
, start
, &prev
,
388 &rb_link
, &rb_parent
);
390 prev
= __pp_prev(pp
);
395 pp
= current
->thread
.ppl
->pp_head
;
398 while (pp
&& pp
->base
< end
) {
399 struct partial_page
*tmp
= pp
->next
;
400 __ia32_delete_pp(current
->thread
.ppl
, pp
, prev
);
406 * Set the range between @start and @end in bitmap.
407 * @start and @end should be IA32 page aligned and in the same IA64 page.
410 __ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
412 struct partial_page
*pp
, *prev
;
413 struct rb_node
** rb_link
, *rb_parent
;
414 unsigned int pstart
, start_bit
, end_bit
, i
;
416 pstart
= PAGE_START(start
);
417 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
418 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
420 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
421 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
422 &rb_link
, &rb_parent
);
424 for (i
= start_bit
; i
< end_bit
; i
++)
425 set_bit(i
, &pp
->bitmap
);
427 * Check: if this partial page has been set to a full page,
430 if (find_first_zero_bit(&pp
->bitmap
, sizeof(pp
->bitmap
)*8) >=
431 PAGE_SIZE
/IA32_PAGE_SIZE
) {
432 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
438 * MAP_FIXED may lead to overlapping mmap.
439 * In this case, the requested mmap area may already mmaped as a full
440 * page. So check vma before adding a new partial page.
442 if (flags
& MAP_FIXED
) {
443 struct vm_area_struct
*vma
= find_vma(current
->mm
, pstart
);
444 if (vma
&& vma
->vm_start
<= pstart
)
448 /* new a partial_page */
449 pp
= kmem_cache_alloc(partial_page_cachep
, GFP_KERNEL
);
454 for (i
=start_bit
; i
<end_bit
; i
++)
455 set_bit(i
, &(pp
->bitmap
));
457 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
462 * @start and @end should be IA32 page aligned, but don't need to be in the
463 * same IA64 page. Split @start and @end to make sure they're in the same IA64
464 * page, then call __ia32_set_pp().
467 ia32_set_pp(unsigned int start
, unsigned int end
, int flags
)
469 down_write(¤t
->mm
->mmap_sem
);
470 if (flags
& MAP_FIXED
) {
472 * MAP_FIXED may lead to overlapping mmap. When this happens,
473 * a series of complete IA64 pages results in deletion of
474 * old partial pages in that range.
476 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
479 if (end
< PAGE_ALIGN(start
)) {
480 __ia32_set_pp(start
, end
, flags
);
482 if (offset_in_page(start
))
483 __ia32_set_pp(start
, PAGE_ALIGN(start
), flags
);
484 if (offset_in_page(end
))
485 __ia32_set_pp(PAGE_START(end
), end
, flags
);
487 up_write(¤t
->mm
->mmap_sem
);
491 * Unset the range between @start and @end in bitmap.
492 * @start and @end should be IA32 page aligned and in the same IA64 page.
493 * After doing that, if the bitmap is 0, then free the page and return 1,
495 * If not find the partial page in the list, then
496 * If the vma exists, then the full page is set to a partial page;
497 * Else return -ENOMEM.
500 __ia32_unset_pp(unsigned int start
, unsigned int end
)
502 struct partial_page
*pp
, *prev
;
503 struct rb_node
** rb_link
, *rb_parent
;
504 unsigned int pstart
, start_bit
, end_bit
, i
;
505 struct vm_area_struct
*vma
;
507 pstart
= PAGE_START(start
);
508 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
509 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
511 end_bit
= PAGE_SIZE
/ IA32_PAGE_SIZE
;
513 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
514 &rb_link
, &rb_parent
);
516 for (i
= start_bit
; i
< end_bit
; i
++)
517 clear_bit(i
, &pp
->bitmap
);
518 if (pp
->bitmap
== 0) {
519 __ia32_delete_pp(current
->thread
.ppl
, pp
, __pp_prev(pp
));
525 vma
= find_vma(current
->mm
, pstart
);
526 if (!vma
|| vma
->vm_start
> pstart
) {
530 /* new a partial_page */
531 pp
= kmem_cache_alloc(partial_page_cachep
, GFP_KERNEL
);
536 for (i
= 0; i
< start_bit
; i
++)
537 set_bit(i
, &(pp
->bitmap
));
538 for (i
= end_bit
; i
< PAGE_SIZE
/ IA32_PAGE_SIZE
; i
++)
539 set_bit(i
, &(pp
->bitmap
));
541 __ia32_insert_pp(current
->thread
.ppl
, pp
, prev
, rb_link
, rb_parent
);
546 * Delete pp between PAGE_ALIGN(start) and PAGE_START(end) by calling
547 * __ia32_delete_pp_range(). Unset possible partial pages by calling
549 * The returned value see __ia32_unset_pp().
552 ia32_unset_pp(unsigned int *startp
, unsigned int *endp
)
554 unsigned int start
= *startp
, end
= *endp
;
557 down_write(¤t
->mm
->mmap_sem
);
559 __ia32_delete_pp_range(PAGE_ALIGN(start
), PAGE_START(end
));
561 if (end
< PAGE_ALIGN(start
)) {
562 ret
= __ia32_unset_pp(start
, end
);
564 *startp
= PAGE_START(start
);
565 *endp
= PAGE_ALIGN(end
);
568 /* to shortcut sys_munmap() in sys32_munmap() */
569 *startp
= PAGE_START(start
);
570 *endp
= PAGE_START(end
);
573 if (offset_in_page(start
)) {
574 ret
= __ia32_unset_pp(start
, PAGE_ALIGN(start
));
576 *startp
= PAGE_START(start
);
578 *startp
= PAGE_ALIGN(start
);
582 if (offset_in_page(end
)) {
583 ret
= __ia32_unset_pp(PAGE_START(end
), end
);
585 *endp
= PAGE_ALIGN(end
);
587 *endp
= PAGE_START(end
);
592 up_write(¤t
->mm
->mmap_sem
);
597 * Compare the range between @start and @end with bitmap in partial page.
598 * @start and @end should be IA32 page aligned and in the same IA64 page.
601 __ia32_compare_pp(unsigned int start
, unsigned int end
)
603 struct partial_page
*pp
, *prev
;
604 struct rb_node
** rb_link
, *rb_parent
;
605 unsigned int pstart
, start_bit
, end_bit
, size
;
606 unsigned int first_bit
, next_zero_bit
; /* the first range in bitmap */
608 pstart
= PAGE_START(start
);
610 pp
= __ia32_find_pp(current
->thread
.ppl
, pstart
, &prev
,
611 &rb_link
, &rb_parent
);
615 start_bit
= (start
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
616 end_bit
= (end
% PAGE_SIZE
) / IA32_PAGE_SIZE
;
617 size
= sizeof(pp
->bitmap
) * 8;
618 first_bit
= find_first_bit(&pp
->bitmap
, size
);
619 next_zero_bit
= find_next_zero_bit(&pp
->bitmap
, size
, first_bit
);
620 if ((start_bit
< first_bit
) || (end_bit
> next_zero_bit
)) {
621 /* exceeds the first range in bitmap */
623 } else if ((start_bit
== first_bit
) && (end_bit
== next_zero_bit
)) {
624 first_bit
= find_next_bit(&pp
->bitmap
, size
, next_zero_bit
);
625 if ((next_zero_bit
< first_bit
) && (first_bit
< size
))
626 return 1; /* has next range */
628 return 0; /* no next range */
634 * @start and @end should be IA32 page aligned, but don't need to be in the
635 * same IA64 page. Split @start and @end to make sure they're in the same IA64
636 * page, then call __ia32_compare_pp().
638 * Take this as example: the range is the 1st and 2nd 4K page.
639 * Return 0 if they fit bitmap exactly, i.e. bitmap = 00000011;
640 * Return 1 if the range doesn't cover whole bitmap, e.g. bitmap = 00001111;
641 * Return -ENOMEM if the range exceeds the bitmap, e.g. bitmap = 00000001 or
645 ia32_compare_pp(unsigned int *startp
, unsigned int *endp
)
647 unsigned int start
= *startp
, end
= *endp
;
650 down_write(¤t
->mm
->mmap_sem
);
652 if (end
< PAGE_ALIGN(start
)) {
653 retval
= __ia32_compare_pp(start
, end
);
655 *startp
= PAGE_START(start
);
656 *endp
= PAGE_ALIGN(end
);
659 if (offset_in_page(start
)) {
660 retval
= __ia32_compare_pp(start
,
663 *startp
= PAGE_START(start
);
667 if (offset_in_page(end
)) {
668 retval
= __ia32_compare_pp(PAGE_START(end
), end
);
670 *endp
= PAGE_ALIGN(end
);
675 up_write(¤t
->mm
->mmap_sem
);
680 __ia32_drop_pp_list(struct partial_page_list
*ppl
)
682 struct partial_page
*pp
= ppl
->pp_head
;
685 struct partial_page
*next
= pp
->next
;
686 kmem_cache_free(partial_page_cachep
, pp
);
694 ia32_drop_partial_page_list(struct task_struct
*task
)
696 struct partial_page_list
* ppl
= task
->thread
.ppl
;
698 if (ppl
&& atomic_dec_and_test(&ppl
->pp_count
))
699 __ia32_drop_pp_list(ppl
);
703 * Copy current->thread.ppl to ppl (already initialized).
706 __ia32_copy_pp_list(struct partial_page_list
*ppl
)
708 struct partial_page
*pp
, *tmp
, *prev
;
709 struct rb_node
**rb_link
, *rb_parent
;
713 ppl
->ppl_rb
= RB_ROOT
;
714 rb_link
= &ppl
->ppl_rb
.rb_node
;
718 for (pp
= current
->thread
.ppl
->pp_head
; pp
; pp
= pp
->next
) {
719 tmp
= kmem_cache_alloc(partial_page_cachep
, GFP_KERNEL
);
723 __ia32_insert_pp(ppl
, tmp
, prev
, rb_link
, rb_parent
);
725 rb_link
= &tmp
->pp_rb
.rb_right
;
726 rb_parent
= &tmp
->pp_rb
;
732 ia32_copy_partial_page_list(struct task_struct
*p
, 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
, current
->pid
, 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
, current
->pid
, 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
, current
->pid
, 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_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
, ino_t 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);
1232 buf
->error
= -EINVAL
; /* only used if we fail.. */
1233 if (reclen
> buf
->count
)
1235 buf
->error
= -EFAULT
; /* only used if we fail.. */
1236 dirent
= buf
->previous
;
1238 if (put_user(offset
, &dirent
->d_off
))
1240 dirent
= buf
->current_dir
;
1241 buf
->previous
= dirent
;
1242 if (put_user(ino
, &dirent
->d_ino
)
1243 || put_user(reclen
, &dirent
->d_reclen
)
1244 || copy_to_user(dirent
->d_name
, name
, namlen
)
1245 || put_user(0, dirent
->d_name
+ namlen
))
1247 dirent
= (struct compat_dirent __user
*) ((char __user
*) dirent
+ reclen
);
1248 buf
->current_dir
= dirent
;
1249 buf
->count
-= reclen
;
1254 sys32_getdents (unsigned int fd
, struct compat_dirent __user
*dirent
, unsigned int count
)
1257 struct compat_dirent __user
* lastdirent
;
1258 struct getdents32_callback buf
;
1266 buf
.current_dir
= dirent
;
1267 buf
.previous
= NULL
;
1271 error
= vfs_readdir(file
, filldir32
, &buf
);
1275 lastdirent
= buf
.previous
;
1278 if (put_user(file
->f_pos
, &lastdirent
->d_off
))
1280 error
= count
- buf
.count
;
1290 fillonedir32 (void * __buf
, const char * name
, int namlen
, loff_t offset
, ino_t ino
,
1291 unsigned int d_type
)
1293 struct readdir32_callback
* buf
= (struct readdir32_callback
*) __buf
;
1294 struct old_linux32_dirent __user
* dirent
;
1299 dirent
= buf
->dirent
;
1300 if (put_user(ino
, &dirent
->d_ino
)
1301 || put_user(offset
, &dirent
->d_offset
)
1302 || put_user(namlen
, &dirent
->d_namlen
)
1303 || copy_to_user(dirent
->d_name
, name
, namlen
)
1304 || put_user(0, dirent
->d_name
+ namlen
))
1310 sys32_readdir (unsigned int fd
, void __user
*dirent
, unsigned int count
)
1314 struct readdir32_callback buf
;
1322 buf
.dirent
= dirent
;
1324 error
= vfs_readdir(file
, fillonedir32
, &buf
);
1332 struct sel_arg_struct
{
1341 sys32_old_select (struct sel_arg_struct __user
*arg
)
1343 struct sel_arg_struct a
;
1345 if (copy_from_user(&a
, arg
, sizeof(a
)))
1347 return compat_sys_select(a
.n
, compat_ptr(a
.inp
), compat_ptr(a
.outp
),
1348 compat_ptr(a
.exp
), compat_ptr(a
.tvp
));
1354 #define SEMTIMEDOP 4
1365 sys32_ipc(u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
1369 version
= call
>> 16; /* hack for backward compatibility */
1375 return compat_sys_semtimedop(first
, compat_ptr(ptr
),
1376 second
, compat_ptr(fifth
));
1377 /* else fall through for normal semop() */
1379 /* struct sembuf is the same on 32 and 64bit :)) */
1380 return sys_semtimedop(first
, compat_ptr(ptr
), second
,
1383 return sys_semget(first
, second
, third
);
1385 return compat_sys_semctl(first
, second
, third
, compat_ptr(ptr
));
1388 return compat_sys_msgsnd(first
, second
, third
, compat_ptr(ptr
));
1390 return compat_sys_msgrcv(first
, second
, fifth
, third
, version
, compat_ptr(ptr
));
1392 return sys_msgget((key_t
) first
, second
);
1394 return compat_sys_msgctl(first
, second
, compat_ptr(ptr
));
1397 return compat_sys_shmat(first
, second
, third
, version
, compat_ptr(ptr
));
1400 return sys_shmdt(compat_ptr(ptr
));
1402 return sys_shmget(first
, (unsigned)second
, third
);
1404 return compat_sys_shmctl(first
, second
, compat_ptr(ptr
));
1413 compat_sys_wait4 (compat_pid_t pid
, compat_uint_t
* stat_addr
, int options
,
1414 struct compat_rusage
*ru
);
1417 sys32_waitpid (int pid
, unsigned int *stat_addr
, int options
)
1419 return compat_sys_wait4(pid
, stat_addr
, options
, NULL
);
1423 ia32_peek (struct task_struct
*child
, unsigned long addr
, unsigned int *val
)
1428 copied
= access_process_vm(child
, addr
, val
, sizeof(*val
), 0);
1429 return (copied
!= sizeof(ret
)) ? -EIO
: 0;
1433 ia32_poke (struct task_struct
*child
, unsigned long addr
, unsigned int val
)
1436 if (access_process_vm(child
, addr
, &val
, sizeof(val
), 1) != sizeof(val
))
1442 * The order in which registers are stored in the ptrace regs structure
1455 #define PT_ORIG_EAX 11
1463 getreg (struct task_struct
*child
, int regno
)
1465 struct pt_regs
*child_regs
;
1467 child_regs
= task_pt_regs(child
);
1468 switch (regno
/ sizeof(int)) {
1469 case PT_EBX
: return child_regs
->r11
;
1470 case PT_ECX
: return child_regs
->r9
;
1471 case PT_EDX
: return child_regs
->r10
;
1472 case PT_ESI
: return child_regs
->r14
;
1473 case PT_EDI
: return child_regs
->r15
;
1474 case PT_EBP
: return child_regs
->r13
;
1475 case PT_EAX
: return child_regs
->r8
;
1476 case PT_ORIG_EAX
: return child_regs
->r1
; /* see dispatch_to_ia32_handler() */
1477 case PT_EIP
: return child_regs
->cr_iip
;
1478 case PT_UESP
: return child_regs
->r12
;
1479 case PT_EFL
: return child
->thread
.eflag
;
1480 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1482 case PT_CS
: return __USER_CS
;
1484 printk(KERN_ERR
"ia32.getreg(): unknown register %d\n", regno
);
1491 putreg (struct task_struct
*child
, int regno
, unsigned int value
)
1493 struct pt_regs
*child_regs
;
1495 child_regs
= task_pt_regs(child
);
1496 switch (regno
/ sizeof(int)) {
1497 case PT_EBX
: child_regs
->r11
= value
; break;
1498 case PT_ECX
: child_regs
->r9
= value
; break;
1499 case PT_EDX
: child_regs
->r10
= value
; break;
1500 case PT_ESI
: child_regs
->r14
= value
; break;
1501 case PT_EDI
: child_regs
->r15
= value
; break;
1502 case PT_EBP
: child_regs
->r13
= value
; break;
1503 case PT_EAX
: child_regs
->r8
= value
; break;
1504 case PT_ORIG_EAX
: child_regs
->r1
= value
; break;
1505 case PT_EIP
: child_regs
->cr_iip
= value
; break;
1506 case PT_UESP
: child_regs
->r12
= value
; break;
1507 case PT_EFL
: child
->thread
.eflag
= value
; break;
1508 case PT_DS
: case PT_ES
: case PT_FS
: case PT_GS
: case PT_SS
:
1509 if (value
!= __USER_DS
)
1511 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1515 if (value
!= __USER_CS
)
1517 "ia32.putreg: attempt to to set invalid segment register %d = %x\n",
1521 printk(KERN_ERR
"ia32.putreg: unknown register %d\n", regno
);
1527 put_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1528 struct switch_stack
*swp
, int tos
)
1530 struct _fpreg_ia32
*f
;
1533 f
= (struct _fpreg_ia32
*)(((unsigned long)buf
+ 15) & ~15);
1534 if ((regno
+= tos
) >= 8)
1538 ia64f2ia32f(f
, &ptp
->f8
);
1541 ia64f2ia32f(f
, &ptp
->f9
);
1544 ia64f2ia32f(f
, &ptp
->f10
);
1547 ia64f2ia32f(f
, &ptp
->f11
);
1553 ia64f2ia32f(f
, &swp
->f12
+ (regno
- 4));
1556 copy_to_user(reg
, f
, sizeof(*reg
));
1560 get_fpreg (int regno
, struct _fpreg_ia32 __user
*reg
, struct pt_regs
*ptp
,
1561 struct switch_stack
*swp
, int tos
)
1564 if ((regno
+= tos
) >= 8)
1568 copy_from_user(&ptp
->f8
, reg
, sizeof(*reg
));
1571 copy_from_user(&ptp
->f9
, reg
, sizeof(*reg
));
1574 copy_from_user(&ptp
->f10
, reg
, sizeof(*reg
));
1577 copy_from_user(&ptp
->f11
, reg
, sizeof(*reg
));
1583 copy_from_user(&swp
->f12
+ (regno
- 4), reg
, sizeof(*reg
));
1590 save_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1592 struct switch_stack
*swp
;
1593 struct pt_regs
*ptp
;
1596 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1599 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1600 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1601 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1602 __put_user(tsk
->thread
.fir
, &save
->fip
);
1603 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1604 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1605 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1608 * Stack frames start with 16-bytes of temp space
1610 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1611 ptp
= task_pt_regs(tsk
);
1612 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1613 for (i
= 0; i
< 8; i
++)
1614 put_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1619 restore_ia32_fpstate (struct task_struct
*tsk
, struct ia32_user_i387_struct __user
*save
)
1621 struct switch_stack
*swp
;
1622 struct pt_regs
*ptp
;
1624 unsigned int fsrlo
, fsrhi
, num32
;
1626 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1629 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1630 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1631 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1632 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1633 num32
= (fsrhi
<< 16) | fsrlo
;
1634 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1635 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1636 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1637 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1638 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1641 * Stack frames start with 16-bytes of temp space
1643 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1644 ptp
= task_pt_regs(tsk
);
1645 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1646 for (i
= 0; i
< 8; i
++)
1647 get_fpreg(i
, &save
->st_space
[i
], ptp
, swp
, tos
);
1652 save_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1654 struct switch_stack
*swp
;
1655 struct pt_regs
*ptp
;
1657 unsigned long mxcsr
=0;
1658 unsigned long num128
[2];
1660 if (!access_ok(VERIFY_WRITE
, save
, sizeof(*save
)))
1663 __put_user(tsk
->thread
.fcr
& 0xffff, &save
->cwd
);
1664 __put_user(tsk
->thread
.fsr
& 0xffff, &save
->swd
);
1665 __put_user((tsk
->thread
.fsr
>>16) & 0xffff, &save
->twd
);
1666 __put_user(tsk
->thread
.fir
, &save
->fip
);
1667 __put_user((tsk
->thread
.fir
>>32) & 0xffff, &save
->fcs
);
1668 __put_user(tsk
->thread
.fdr
, &save
->foo
);
1669 __put_user((tsk
->thread
.fdr
>>32) & 0xffff, &save
->fos
);
1672 * Stack frames start with 16-bytes of temp space
1674 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1675 ptp
= task_pt_regs(tsk
);
1676 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1677 for (i
= 0; i
< 8; i
++)
1678 put_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1680 mxcsr
= ((tsk
->thread
.fcr
>>32) & 0xff80) | ((tsk
->thread
.fsr
>>32) & 0x3f);
1681 __put_user(mxcsr
& 0xffff, &save
->mxcsr
);
1682 for (i
= 0; i
< 8; i
++) {
1683 memcpy(&(num128
[0]), &(swp
->f16
) + i
*2, sizeof(unsigned long));
1684 memcpy(&(num128
[1]), &(swp
->f17
) + i
*2, sizeof(unsigned long));
1685 copy_to_user(&save
->xmm_space
[0] + 4*i
, num128
, sizeof(struct _xmmreg_ia32
));
1691 restore_ia32_fpxstate (struct task_struct
*tsk
, struct ia32_user_fxsr_struct __user
*save
)
1693 struct switch_stack
*swp
;
1694 struct pt_regs
*ptp
;
1696 unsigned int fsrlo
, fsrhi
, num32
;
1698 unsigned long num64
;
1699 unsigned long num128
[2];
1701 if (!access_ok(VERIFY_READ
, save
, sizeof(*save
)))
1704 __get_user(num32
, (unsigned int __user
*)&save
->cwd
);
1705 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0x1f3f)) | (num32
& 0x1f3f);
1706 __get_user(fsrlo
, (unsigned int __user
*)&save
->swd
);
1707 __get_user(fsrhi
, (unsigned int __user
*)&save
->twd
);
1708 num32
= (fsrhi
<< 16) | fsrlo
;
1709 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0xffffffff)) | num32
;
1710 __get_user(num32
, (unsigned int __user
*)&save
->fip
);
1711 tsk
->thread
.fir
= (tsk
->thread
.fir
& (~0xffffffff)) | num32
;
1712 __get_user(num32
, (unsigned int __user
*)&save
->foo
);
1713 tsk
->thread
.fdr
= (tsk
->thread
.fdr
& (~0xffffffff)) | num32
;
1716 * Stack frames start with 16-bytes of temp space
1718 swp
= (struct switch_stack
*)(tsk
->thread
.ksp
+ 16);
1719 ptp
= task_pt_regs(tsk
);
1720 tos
= (tsk
->thread
.fsr
>> 11) & 7;
1721 for (i
= 0; i
< 8; i
++)
1722 get_fpreg(i
, (struct _fpreg_ia32 __user
*)&save
->st_space
[4*i
], ptp
, swp
, tos
);
1724 __get_user(mxcsr
, (unsigned int __user
*)&save
->mxcsr
);
1725 num64
= mxcsr
& 0xff10;
1726 tsk
->thread
.fcr
= (tsk
->thread
.fcr
& (~0xff1000000000UL
)) | (num64
<<32);
1727 num64
= mxcsr
& 0x3f;
1728 tsk
->thread
.fsr
= (tsk
->thread
.fsr
& (~0x3f00000000UL
)) | (num64
<<32);
1730 for (i
= 0; i
< 8; i
++) {
1731 copy_from_user(num128
, &save
->xmm_space
[0] + 4*i
, sizeof(struct _xmmreg_ia32
));
1732 memcpy(&(swp
->f16
) + i
*2, &(num128
[0]), sizeof(unsigned long));
1733 memcpy(&(swp
->f17
) + i
*2, &(num128
[1]), sizeof(unsigned long));
1739 sys32_ptrace (int request
, pid_t pid
, unsigned int addr
, unsigned int data
)
1741 struct task_struct
*child
;
1742 unsigned int value
, tmp
;
1746 if (request
== PTRACE_TRACEME
) {
1747 ret
= ptrace_traceme();
1751 child
= ptrace_get_task_struct(pid
);
1752 if (IS_ERR(child
)) {
1753 ret
= PTR_ERR(child
);
1757 if (request
== PTRACE_ATTACH
) {
1758 ret
= sys_ptrace(request
, pid
, addr
, data
);
1762 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
1767 case PTRACE_PEEKTEXT
:
1768 case PTRACE_PEEKDATA
: /* read word at location addr */
1769 ret
= ia32_peek(child
, addr
, &value
);
1771 ret
= put_user(value
, (unsigned int __user
*) compat_ptr(data
));
1776 case PTRACE_POKETEXT
:
1777 case PTRACE_POKEDATA
: /* write the word at location addr */
1778 ret
= ia32_poke(child
, addr
, data
);
1781 case PTRACE_PEEKUSR
: /* read word at addr in USER area */
1783 if ((addr
& 3) || addr
> 17*sizeof(int))
1786 tmp
= getreg(child
, addr
);
1787 if (!put_user(tmp
, (unsigned int __user
*) compat_ptr(data
)))
1791 case PTRACE_POKEUSR
: /* write word at addr in USER area */
1793 if ((addr
& 3) || addr
> 17*sizeof(int))
1796 putreg(child
, addr
, data
);
1800 case IA32_PTRACE_GETREGS
:
1801 if (!access_ok(VERIFY_WRITE
, compat_ptr(data
), 17*sizeof(int))) {
1805 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1806 put_user(getreg(child
, i
), (unsigned int __user
*) compat_ptr(data
));
1807 data
+= sizeof(int);
1812 case IA32_PTRACE_SETREGS
:
1813 if (!access_ok(VERIFY_READ
, compat_ptr(data
), 17*sizeof(int))) {
1817 for (i
= 0; i
< (int) (17*sizeof(int)); i
+= sizeof(int) ) {
1818 get_user(tmp
, (unsigned int __user
*) compat_ptr(data
));
1819 putreg(child
, i
, tmp
);
1820 data
+= sizeof(int);
1825 case IA32_PTRACE_GETFPREGS
:
1826 ret
= save_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1830 case IA32_PTRACE_GETFPXREGS
:
1831 ret
= save_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1835 case IA32_PTRACE_SETFPREGS
:
1836 ret
= restore_ia32_fpstate(child
, (struct ia32_user_i387_struct __user
*)
1840 case IA32_PTRACE_SETFPXREGS
:
1841 ret
= restore_ia32_fpxstate(child
, (struct ia32_user_fxsr_struct __user
*)
1845 case PTRACE_GETEVENTMSG
:
1846 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) compat_ptr(data
));
1849 case PTRACE_SYSCALL
: /* continue, stop after next syscall */
1850 case PTRACE_CONT
: /* restart after signal. */
1852 case PTRACE_SINGLESTEP
: /* execute chile for one instruction */
1853 case PTRACE_DETACH
: /* detach a process */
1854 ret
= sys_ptrace(request
, pid
, addr
, data
);
1858 ret
= ptrace_request(child
, request
, addr
, data
);
1863 put_task_struct(child
);
1871 unsigned int ss_flags
;
1872 unsigned int ss_size
;
1876 sys32_sigaltstack (ia32_stack_t __user
*uss32
, ia32_stack_t __user
*uoss32
,
1877 long arg2
, long arg3
, long arg4
, long arg5
, long arg6
,
1878 long arg7
, struct pt_regs pt
)
1883 mm_segment_t old_fs
= get_fs();
1886 if (copy_from_user(&buf32
, uss32
, sizeof(ia32_stack_t
)))
1888 uss
.ss_sp
= (void __user
*) (long) buf32
.ss_sp
;
1889 uss
.ss_flags
= buf32
.ss_flags
;
1890 /* MINSIGSTKSZ is different for ia32 vs ia64. We lie here to pass the
1891 check and set it to the user requested value later */
1892 if ((buf32
.ss_flags
!= SS_DISABLE
) && (buf32
.ss_size
< MINSIGSTKSZ_IA32
)) {
1896 uss
.ss_size
= MINSIGSTKSZ
;
1899 ret
= do_sigaltstack(uss32
? (stack_t __user
*) &uss
: NULL
,
1900 (stack_t __user
*) &uoss
, pt
.r12
);
1901 current
->sas_ss_size
= buf32
.ss_size
;
1907 buf32
.ss_sp
= (long __user
) uoss
.ss_sp
;
1908 buf32
.ss_flags
= uoss
.ss_flags
;
1909 buf32
.ss_size
= uoss
.ss_size
;
1910 if (copy_to_user(uoss32
, &buf32
, sizeof(ia32_stack_t
)))
1919 current
->state
= TASK_INTERRUPTIBLE
;
1921 return -ERESTARTNOHAND
;
1925 sys32_msync (unsigned int start
, unsigned int len
, int flags
)
1929 if (OFFSET4K(start
))
1931 addr
= PAGE_START(start
);
1932 return sys_msync(addr
, len
+ (start
- addr
), flags
);
1938 unsigned int oldval
;
1939 unsigned int oldlenp
;
1940 unsigned int newval
;
1941 unsigned int newlen
;
1942 unsigned int __unused
[4];
1945 #ifdef CONFIG_SYSCTL
1947 sys32_sysctl (struct sysctl32 __user
*args
)
1949 struct sysctl32 a32
;
1950 mm_segment_t old_fs
= get_fs ();
1951 void __user
*oldvalp
, *newvalp
;
1956 if (copy_from_user(&a32
, args
, sizeof(a32
)))
1960 * We need to pre-validate these because we have to disable address checking
1961 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
1962 * user specifying bad addresses here. Well, since we're dealing with 32 bit
1963 * addresses, we KNOW that access_ok() will always succeed, so this is an
1964 * expensive NOP, but so what...
1966 namep
= (int __user
*) compat_ptr(a32
.name
);
1967 oldvalp
= compat_ptr(a32
.oldval
);
1968 newvalp
= compat_ptr(a32
.newval
);
1970 if ((oldvalp
&& get_user(oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
1971 || !access_ok(VERIFY_WRITE
, namep
, 0)
1972 || !access_ok(VERIFY_WRITE
, oldvalp
, 0)
1973 || !access_ok(VERIFY_WRITE
, newvalp
, 0))
1978 ret
= do_sysctl(namep
, a32
.nlen
, oldvalp
, (size_t __user
*) &oldlen
,
1979 newvalp
, (size_t) a32
.newlen
);
1983 if (oldvalp
&& put_user (oldlen
, (int __user
*) compat_ptr(a32
.oldlenp
)))
1991 sys32_newuname (struct new_utsname __user
*name
)
1993 int ret
= sys_newuname(name
);
1996 if (copy_to_user(name
->machine
, "i686\0\0\0", 8))
2002 sys32_getresuid16 (u16 __user
*ruid
, u16 __user
*euid
, u16 __user
*suid
)
2006 mm_segment_t old_fs
= get_fs();
2009 ret
= sys_getresuid((uid_t __user
*) &a
, (uid_t __user
*) &b
, (uid_t __user
*) &c
);
2012 if (put_user(a
, ruid
) || put_user(b
, euid
) || put_user(c
, suid
))
2018 sys32_getresgid16 (u16 __user
*rgid
, u16 __user
*egid
, u16 __user
*sgid
)
2022 mm_segment_t old_fs
= get_fs();
2025 ret
= sys_getresgid((gid_t __user
*) &a
, (gid_t __user
*) &b
, (gid_t __user
*) &c
);
2031 return put_user(a
, rgid
) | put_user(b
, egid
) | put_user(c
, sgid
);
2035 sys32_lseek (unsigned int fd
, int offset
, unsigned int whence
)
2037 /* Sign-extension of "offset" is important here... */
2038 return sys_lseek(fd
, offset
, whence
);
2042 groups16_to_user(short __user
*grouplist
, struct group_info
*group_info
)
2047 for (i
= 0; i
< group_info
->ngroups
; i
++) {
2048 group
= (short)GROUP_AT(group_info
, i
);
2049 if (put_user(group
, grouplist
+i
))
2057 groups16_from_user(struct group_info
*group_info
, short __user
*grouplist
)
2062 for (i
= 0; i
< group_info
->ngroups
; i
++) {
2063 if (get_user(group
, grouplist
+i
))
2065 GROUP_AT(group_info
, i
) = (gid_t
)group
;
2072 sys32_getgroups16 (int gidsetsize
, short __user
*grouplist
)
2079 get_group_info(current
->group_info
);
2080 i
= current
->group_info
->ngroups
;
2082 if (i
> gidsetsize
) {
2086 if (groups16_to_user(grouplist
, current
->group_info
)) {
2092 put_group_info(current
->group_info
);
2097 sys32_setgroups16 (int gidsetsize
, short __user
*grouplist
)
2099 struct group_info
*group_info
;
2102 if (!capable(CAP_SETGID
))
2104 if ((unsigned)gidsetsize
> NGROUPS_MAX
)
2107 group_info
= groups_alloc(gidsetsize
);
2110 retval
= groups16_from_user(group_info
, grouplist
);
2112 put_group_info(group_info
);
2116 retval
= set_current_groups(group_info
);
2117 put_group_info(group_info
);
2123 sys32_truncate64 (unsigned int path
, unsigned int len_lo
, unsigned int len_hi
)
2125 return sys_truncate(compat_ptr(path
), ((unsigned long) len_hi
<< 32) | len_lo
);
2129 sys32_ftruncate64 (int fd
, unsigned int len_lo
, unsigned int len_hi
)
2131 return sys_ftruncate(fd
, ((unsigned long) len_hi
<< 32) | len_lo
);
2135 putstat64 (struct stat64 __user
*ubuf
, struct kstat
*kbuf
)
2140 if (clear_user(ubuf
, sizeof(*ubuf
)))
2143 hdev
= huge_encode_dev(kbuf
->dev
);
2144 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_dev
);
2145 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_dev
) + 1);
2146 err
|= __put_user(kbuf
->ino
, &ubuf
->__st_ino
);
2147 err
|= __put_user(kbuf
->ino
, &ubuf
->st_ino_lo
);
2148 err
|= __put_user(kbuf
->ino
>> 32, &ubuf
->st_ino_hi
);
2149 err
|= __put_user(kbuf
->mode
, &ubuf
->st_mode
);
2150 err
|= __put_user(kbuf
->nlink
, &ubuf
->st_nlink
);
2151 err
|= __put_user(kbuf
->uid
, &ubuf
->st_uid
);
2152 err
|= __put_user(kbuf
->gid
, &ubuf
->st_gid
);
2153 hdev
= huge_encode_dev(kbuf
->rdev
);
2154 err
= __put_user(hdev
, (u32 __user
*)&ubuf
->st_rdev
);
2155 err
|= __put_user(hdev
>> 32, ((u32 __user
*)&ubuf
->st_rdev
) + 1);
2156 err
|= __put_user(kbuf
->size
, &ubuf
->st_size_lo
);
2157 err
|= __put_user((kbuf
->size
>> 32), &ubuf
->st_size_hi
);
2158 err
|= __put_user(kbuf
->atime
.tv_sec
, &ubuf
->st_atime
);
2159 err
|= __put_user(kbuf
->atime
.tv_nsec
, &ubuf
->st_atime_nsec
);
2160 err
|= __put_user(kbuf
->mtime
.tv_sec
, &ubuf
->st_mtime
);
2161 err
|= __put_user(kbuf
->mtime
.tv_nsec
, &ubuf
->st_mtime_nsec
);
2162 err
|= __put_user(kbuf
->ctime
.tv_sec
, &ubuf
->st_ctime
);
2163 err
|= __put_user(kbuf
->ctime
.tv_nsec
, &ubuf
->st_ctime_nsec
);
2164 err
|= __put_user(kbuf
->blksize
, &ubuf
->st_blksize
);
2165 err
|= __put_user(kbuf
->blocks
, &ubuf
->st_blocks
);
2170 sys32_stat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
2173 long ret
= vfs_stat(filename
, &s
);
2175 ret
= putstat64(statbuf
, &s
);
2180 sys32_lstat64 (char __user
*filename
, struct stat64 __user
*statbuf
)
2183 long ret
= vfs_lstat(filename
, &s
);
2185 ret
= putstat64(statbuf
, &s
);
2190 sys32_fstat64 (unsigned int fd
, struct stat64 __user
*statbuf
)
2193 long ret
= vfs_fstat(fd
, &s
);
2195 ret
= putstat64(statbuf
, &s
);
2217 sys32_sysinfo (struct sysinfo32 __user
*info
)
2222 mm_segment_t old_fs
= get_fs();
2225 ret
= sys_sysinfo((struct sysinfo __user
*) &s
);
2227 /* Check to see if any memory value is too large for 32-bit and
2228 * scale down if needed.
2230 if ((s
.totalram
>> 32) || (s
.totalswap
>> 32)) {
2231 while (s
.mem_unit
< PAGE_SIZE
) {
2235 s
.totalram
>>= bitcount
;
2236 s
.freeram
>>= bitcount
;
2237 s
.sharedram
>>= bitcount
;
2238 s
.bufferram
>>= bitcount
;
2239 s
.totalswap
>>= bitcount
;
2240 s
.freeswap
>>= bitcount
;
2241 s
.totalhigh
>>= bitcount
;
2242 s
.freehigh
>>= bitcount
;
2245 if (!access_ok(VERIFY_WRITE
, info
, sizeof(*info
)))
2248 err
= __put_user(s
.uptime
, &info
->uptime
);
2249 err
|= __put_user(s
.loads
[0], &info
->loads
[0]);
2250 err
|= __put_user(s
.loads
[1], &info
->loads
[1]);
2251 err
|= __put_user(s
.loads
[2], &info
->loads
[2]);
2252 err
|= __put_user(s
.totalram
, &info
->totalram
);
2253 err
|= __put_user(s
.freeram
, &info
->freeram
);
2254 err
|= __put_user(s
.sharedram
, &info
->sharedram
);
2255 err
|= __put_user(s
.bufferram
, &info
->bufferram
);
2256 err
|= __put_user(s
.totalswap
, &info
->totalswap
);
2257 err
|= __put_user(s
.freeswap
, &info
->freeswap
);
2258 err
|= __put_user(s
.procs
, &info
->procs
);
2259 err
|= __put_user (s
.totalhigh
, &info
->totalhigh
);
2260 err
|= __put_user (s
.freehigh
, &info
->freehigh
);
2261 err
|= __put_user (s
.mem_unit
, &info
->mem_unit
);
2268 sys32_sched_rr_get_interval (pid_t pid
, struct compat_timespec __user
*interval
)
2270 mm_segment_t old_fs
= get_fs();
2275 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*) &t
);
2277 if (put_compat_timespec(&t
, interval
))
2283 sys32_pread (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
2285 return sys_pread64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
2289 sys32_pwrite (unsigned int fd
, void __user
*buf
, unsigned int count
, u32 pos_lo
, u32 pos_hi
)
2291 return sys_pwrite64(fd
, buf
, count
, ((unsigned long) pos_hi
<< 32) | pos_lo
);
2295 sys32_sendfile (int out_fd
, int in_fd
, int __user
*offset
, unsigned int count
)
2297 mm_segment_t old_fs
= get_fs();
2301 if (offset
&& get_user(of
, offset
))
2305 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*) &of
: NULL
, count
);
2308 if (offset
&& put_user(of
, offset
))
2315 sys32_personality (unsigned int personality
)
2319 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
2320 personality
= PER_LINUX32
;
2321 ret
= sys_personality(personality
);
2322 if (ret
== PER_LINUX32
)
2327 asmlinkage
unsigned long
2328 sys32_brk (unsigned int brk
)
2330 unsigned long ret
, obrk
;
2331 struct mm_struct
*mm
= current
->mm
;
2336 clear_user(compat_ptr(ret
), PAGE_ALIGN(ret
) - ret
);
2340 /* Structure for ia32 emulation on ia64 */
2341 struct epoll_event32
2348 sys32_epoll_ctl(int epfd
, int op
, int fd
, struct epoll_event32 __user
*event
)
2350 mm_segment_t old_fs
= get_fs();
2351 struct epoll_event event64
;
2355 if (!access_ok(VERIFY_READ
, event
, sizeof(struct epoll_event32
)))
2358 __get_user(event64
.events
, &event
->events
);
2359 __get_user(data_halfword
, &event
->data
[0]);
2360 event64
.data
= data_halfword
;
2361 __get_user(data_halfword
, &event
->data
[1]);
2362 event64
.data
|= (u64
)data_halfword
<< 32;
2365 error
= sys_epoll_ctl(epfd
, op
, fd
, (struct epoll_event __user
*) &event64
);
2372 sys32_epoll_wait(int epfd
, struct epoll_event32 __user
* events
, int maxevents
,
2375 struct epoll_event
*events64
= NULL
;
2376 mm_segment_t old_fs
= get_fs();
2377 int numevents
, size
;
2379 int do_free_pages
= 0;
2381 if (maxevents
<= 0) {
2385 /* Verify that the area passed by the user is writeable */
2386 if (!access_ok(VERIFY_WRITE
, events
, maxevents
* sizeof(struct epoll_event32
)))
2390 * Allocate space for the intermediate copy. If the space needed
2391 * is large enough to cause kmalloc to fail, then try again with
2394 size
= maxevents
* sizeof(struct epoll_event
);
2395 events64
= kmalloc(size
, GFP_KERNEL
);
2396 if (events64
== NULL
) {
2397 events64
= (struct epoll_event
*)
2398 __get_free_pages(GFP_KERNEL
, get_order(size
));
2399 if (events64
== NULL
)
2404 /* Do the system call */
2405 set_fs(KERNEL_DS
); /* copy_to/from_user should work on kernel mem*/
2406 numevents
= sys_epoll_wait(epfd
, (struct epoll_event __user
*) events64
,
2407 maxevents
, timeout
);
2410 /* Don't modify userspace memory if we're returning an error */
2411 if (numevents
> 0) {
2412 /* Translate the 64-bit structures back into the 32-bit
2414 for (evt_idx
= 0; evt_idx
< numevents
; evt_idx
++) {
2415 __put_user(events64
[evt_idx
].events
,
2416 &events
[evt_idx
].events
);
2417 __put_user((u32
)events64
[evt_idx
].data
,
2418 &events
[evt_idx
].data
[0]);
2419 __put_user((u32
)(events64
[evt_idx
].data
>> 32),
2420 &events
[evt_idx
].data
[1]);
2425 free_pages((unsigned long) events64
, get_order(size
));
2432 * Get a yet unused TLS descriptor index.
2437 struct thread_struct
*t
= ¤t
->thread
;
2440 for (idx
= 0; idx
< GDT_ENTRY_TLS_ENTRIES
; idx
++)
2441 if (desc_empty(t
->tls_array
+ idx
))
2442 return idx
+ GDT_ENTRY_TLS_MIN
;
2447 * Set a given TLS descriptor:
2450 sys32_set_thread_area (struct ia32_user_desc __user
*u_info
)
2452 struct thread_struct
*t
= ¤t
->thread
;
2453 struct ia32_user_desc info
;
2454 struct desc_struct
*desc
;
2457 if (copy_from_user(&info
, u_info
, sizeof(info
)))
2459 idx
= info
.entry_number
;
2462 * index -1 means the kernel should try to find and allocate an empty descriptor:
2465 idx
= get_free_idx();
2468 if (put_user(idx
, &u_info
->entry_number
))
2472 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2475 desc
= t
->tls_array
+ idx
- GDT_ENTRY_TLS_MIN
;
2477 cpu
= smp_processor_id();
2479 if (LDT_empty(&info
)) {
2483 desc
->a
= LDT_entry_a(&info
);
2484 desc
->b
= LDT_entry_b(&info
);
2491 * Get the current Thread-Local Storage area:
2494 #define GET_BASE(desc) ( \
2495 (((desc)->a >> 16) & 0x0000ffff) | \
2496 (((desc)->b << 16) & 0x00ff0000) | \
2497 ( (desc)->b & 0xff000000) )
2499 #define GET_LIMIT(desc) ( \
2500 ((desc)->a & 0x0ffff) | \
2501 ((desc)->b & 0xf0000) )
2503 #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
2504 #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
2505 #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
2506 #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
2507 #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
2508 #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
2511 sys32_get_thread_area (struct ia32_user_desc __user
*u_info
)
2513 struct ia32_user_desc info
;
2514 struct desc_struct
*desc
;
2517 if (get_user(idx
, &u_info
->entry_number
))
2519 if (idx
< GDT_ENTRY_TLS_MIN
|| idx
> GDT_ENTRY_TLS_MAX
)
2522 desc
= current
->thread
.tls_array
+ idx
- GDT_ENTRY_TLS_MIN
;
2524 info
.entry_number
= idx
;
2525 info
.base_addr
= GET_BASE(desc
);
2526 info
.limit
= GET_LIMIT(desc
);
2527 info
.seg_32bit
= GET_32BIT(desc
);
2528 info
.contents
= GET_CONTENTS(desc
);
2529 info
.read_exec_only
= !GET_WRITABLE(desc
);
2530 info
.limit_in_pages
= GET_LIMIT_PAGES(desc
);
2531 info
.seg_not_present
= !GET_PRESENT(desc
);
2532 info
.useable
= GET_USEABLE(desc
);
2534 if (copy_to_user(u_info
, &info
, sizeof(info
)))
2539 long sys32_fadvise64_64(int fd
, __u32 offset_low
, __u32 offset_high
,
2540 __u32 len_low
, __u32 len_high
, int advice
)
2542 return sys_fadvise64_64(fd
,
2543 (((u64
)offset_high
)<<32) | offset_low
,
2544 (((u64
)len_high
)<<32) | len_low
,
2548 #ifdef NOTYET /* UNTESTED FOR IA64 FROM HERE DOWN */
2550 asmlinkage
long sys32_setreuid(compat_uid_t ruid
, compat_uid_t euid
)
2554 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2555 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2556 return sys_setreuid(sruid
, seuid
);
2560 sys32_setresuid(compat_uid_t ruid
, compat_uid_t euid
,
2563 uid_t sruid
, seuid
, ssuid
;
2565 sruid
= (ruid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)ruid
);
2566 seuid
= (euid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)euid
);
2567 ssuid
= (suid
== (compat_uid_t
)-1) ? ((uid_t
)-1) : ((uid_t
)suid
);
2568 return sys_setresuid(sruid
, seuid
, ssuid
);
2572 sys32_setregid(compat_gid_t rgid
, compat_gid_t egid
)
2576 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2577 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2578 return sys_setregid(srgid
, segid
);
2582 sys32_setresgid(compat_gid_t rgid
, compat_gid_t egid
,
2585 gid_t srgid
, segid
, ssgid
;
2587 srgid
= (rgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)rgid
);
2588 segid
= (egid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)egid
);
2589 ssgid
= (sgid
== (compat_gid_t
)-1) ? ((gid_t
)-1) : ((gid_t
)sgid
);
2590 return sys_setresgid(srgid
, segid
, ssgid
);