initial commit with v2.6.32.60
[linux-2.6.32.60-moxart.git] / arch / ia64 / ia32 / sys_ia32.c
blobe031ee8ecb0585c20e0769e59956139cfbd46c48
1 /*
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
14 * environment.
17 #include <linux/kernel.h>
18 #include <linux/syscalls.h>
19 #include <linux/sysctl.h>
20 #include <linux/sched.h>
21 #include <linux/fs.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>
31 #include <linux/mm.h>
32 #include <linux/shm.h>
33 #include <linux/slab.h>
34 #include <linux/uio.h>
35 #include <linux/socket.h>
36 #include <linux/quota.h>
37 #include <linux/poll.h>
38 #include <linux/eventpoll.h>
39 #include <linux/personality.h>
40 #include <linux/ptrace.h>
41 #include <linux/regset.h>
42 #include <linux/stat.h>
43 #include <linux/ipc.h>
44 #include <linux/capability.h>
45 #include <linux/compat.h>
46 #include <linux/vfs.h>
47 #include <linux/mman.h>
48 #include <linux/mutex.h>
50 #include <asm/intrinsics.h>
51 #include <asm/types.h>
52 #include <asm/uaccess.h>
53 #include <asm/unistd.h>
55 #include "ia32priv.h"
57 #include <net/scm.h>
58 #include <net/sock.h>
60 #define DEBUG 0
62 #if DEBUG
63 # define DBG(fmt...) printk(KERN_DEBUG fmt)
64 #else
65 # define DBG(fmt...)
66 #endif
68 #define ROUND_UP(x,a) ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
70 #define OFFSET4K(a) ((a) & 0xfff)
71 #define PAGE_START(addr) ((addr) & PAGE_MASK)
72 #define MINSIGSTKSZ_IA32 2048
74 #define high2lowuid(uid) ((uid) > 65535 ? 65534 : (uid))
75 #define high2lowgid(gid) ((gid) > 65535 ? 65534 : (gid))
78 * Anything that modifies or inspects ia32 user virtual memory must hold this semaphore
79 * while doing so.
81 /* XXX make per-mm: */
82 static DEFINE_MUTEX(ia32_mmap_mutex);
84 asmlinkage long
85 sys32_execve (char __user *name, compat_uptr_t __user *argv, compat_uptr_t __user *envp,
86 struct pt_regs *regs)
88 long error;
89 char *filename;
90 unsigned long old_map_base, old_task_size, tssd;
92 filename = getname(name);
93 error = PTR_ERR(filename);
94 if (IS_ERR(filename))
95 return error;
97 old_map_base = current->thread.map_base;
98 old_task_size = current->thread.task_size;
99 tssd = ia64_get_kr(IA64_KR_TSSD);
101 /* we may be exec'ing a 64-bit process: reset map base, task-size, and io-base: */
102 current->thread.map_base = DEFAULT_MAP_BASE;
103 current->thread.task_size = DEFAULT_TASK_SIZE;
104 ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob);
105 ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1);
107 error = compat_do_execve(filename, argv, envp, regs);
108 putname(filename);
110 if (error < 0) {
111 /* oops, execve failed, switch back to old values... */
112 ia64_set_kr(IA64_KR_IO_BASE, IA32_IOBASE);
113 ia64_set_kr(IA64_KR_TSSD, tssd);
114 current->thread.map_base = old_map_base;
115 current->thread.task_size = old_task_size;
118 return error;
122 #if PAGE_SHIFT > IA32_PAGE_SHIFT
125 static int
126 get_page_prot (struct vm_area_struct *vma, unsigned long addr)
128 int prot = 0;
130 if (!vma || vma->vm_start > addr)
131 return 0;
133 if (vma->vm_flags & VM_READ)
134 prot |= PROT_READ;
135 if (vma->vm_flags & VM_WRITE)
136 prot |= PROT_WRITE;
137 if (vma->vm_flags & VM_EXEC)
138 prot |= PROT_EXEC;
139 return prot;
143 * Map a subpage by creating an anonymous page that contains the union of the old page and
144 * the subpage.
146 static unsigned long
147 mmap_subpage (struct file *file, unsigned long start, unsigned long end, int prot, int flags,
148 loff_t off)
150 void *page = NULL;
151 struct inode *inode;
152 unsigned long ret = 0;
153 struct vm_area_struct *vma = find_vma(current->mm, start);
154 int old_prot = get_page_prot(vma, start);
156 DBG("mmap_subpage(file=%p,start=0x%lx,end=0x%lx,prot=%x,flags=%x,off=0x%llx)\n",
157 file, start, end, prot, flags, off);
160 /* Optimize the case where the old mmap and the new mmap are both anonymous */
161 if ((old_prot & PROT_WRITE) && (flags & MAP_ANONYMOUS) && !vma->vm_file) {
162 if (clear_user((void __user *) start, end - start)) {
163 ret = -EFAULT;
164 goto out;
166 goto skip_mmap;
169 page = (void *) get_zeroed_page(GFP_KERNEL);
170 if (!page)
171 return -ENOMEM;
173 if (old_prot)
174 copy_from_user(page, (void __user *) PAGE_START(start), PAGE_SIZE);
176 down_write(&current->mm->mmap_sem);
178 ret = do_mmap(NULL, PAGE_START(start), PAGE_SIZE, prot | PROT_WRITE,
179 flags | MAP_FIXED | MAP_ANONYMOUS, 0);
181 up_write(&current->mm->mmap_sem);
183 if (IS_ERR((void *) ret))
184 goto out;
186 if (old_prot) {
187 /* copy back the old page contents. */
188 if (offset_in_page(start))
189 copy_to_user((void __user *) PAGE_START(start), page,
190 offset_in_page(start));
191 if (offset_in_page(end))
192 copy_to_user((void __user *) end, page + offset_in_page(end),
193 PAGE_SIZE - offset_in_page(end));
196 if (!(flags & MAP_ANONYMOUS)) {
197 /* read the file contents */
198 inode = file->f_path.dentry->d_inode;
199 if (!inode->i_fop || !file->f_op->read
200 || ((*file->f_op->read)(file, (char __user *) start, end - start, &off) < 0))
202 ret = -EINVAL;
203 goto out;
207 skip_mmap:
208 if (!(prot & PROT_WRITE))
209 ret = sys_mprotect(PAGE_START(start), PAGE_SIZE, prot | old_prot);
210 out:
211 if (page)
212 free_page((unsigned long) page);
213 return ret;
216 /* SLAB cache for ia64_partial_page structures */
217 struct kmem_cache *ia64_partial_page_cachep;
220 * init ia64_partial_page_list.
221 * return 0 means kmalloc fail.
223 struct ia64_partial_page_list*
224 ia32_init_pp_list(void)
226 struct ia64_partial_page_list *p;
228 if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL)
229 return p;
230 p->pp_head = NULL;
231 p->ppl_rb = RB_ROOT;
232 p->pp_hint = NULL;
233 atomic_set(&p->pp_count, 1);
234 return p;
238 * Search for the partial page with @start in partial page list @ppl.
239 * If finds the partial page, return the found partial page.
240 * Else, return 0 and provide @pprev, @rb_link, @rb_parent to
241 * be used by later __ia32_insert_pp().
243 static struct ia64_partial_page *
244 __ia32_find_pp(struct ia64_partial_page_list *ppl, unsigned int start,
245 struct ia64_partial_page **pprev, struct rb_node ***rb_link,
246 struct rb_node **rb_parent)
248 struct ia64_partial_page *pp;
249 struct rb_node **__rb_link, *__rb_parent, *rb_prev;
251 pp = ppl->pp_hint;
252 if (pp && pp->base == start)
253 return pp;
255 __rb_link = &ppl->ppl_rb.rb_node;
256 rb_prev = __rb_parent = NULL;
258 while (*__rb_link) {
259 __rb_parent = *__rb_link;
260 pp = rb_entry(__rb_parent, struct ia64_partial_page, pp_rb);
262 if (pp->base == start) {
263 ppl->pp_hint = pp;
264 return pp;
265 } else if (pp->base < start) {
266 rb_prev = __rb_parent;
267 __rb_link = &__rb_parent->rb_right;
268 } else {
269 __rb_link = &__rb_parent->rb_left;
273 *rb_link = __rb_link;
274 *rb_parent = __rb_parent;
275 *pprev = NULL;
276 if (rb_prev)
277 *pprev = rb_entry(rb_prev, struct ia64_partial_page, pp_rb);
278 return NULL;
282 * insert @pp into @ppl.
284 static void
285 __ia32_insert_pp(struct ia64_partial_page_list *ppl,
286 struct ia64_partial_page *pp, struct ia64_partial_page *prev,
287 struct rb_node **rb_link, struct rb_node *rb_parent)
289 /* link list */
290 if (prev) {
291 pp->next = prev->next;
292 prev->next = pp;
293 } else {
294 ppl->pp_head = pp;
295 if (rb_parent)
296 pp->next = rb_entry(rb_parent,
297 struct ia64_partial_page, pp_rb);
298 else
299 pp->next = NULL;
302 /* link rb */
303 rb_link_node(&pp->pp_rb, rb_parent, rb_link);
304 rb_insert_color(&pp->pp_rb, &ppl->ppl_rb);
306 ppl->pp_hint = pp;
310 * delete @pp from partial page list @ppl.
312 static void
313 __ia32_delete_pp(struct ia64_partial_page_list *ppl,
314 struct ia64_partial_page *pp, struct ia64_partial_page *prev)
316 if (prev) {
317 prev->next = pp->next;
318 if (ppl->pp_hint == pp)
319 ppl->pp_hint = prev;
320 } else {
321 ppl->pp_head = pp->next;
322 if (ppl->pp_hint == pp)
323 ppl->pp_hint = pp->next;
325 rb_erase(&pp->pp_rb, &ppl->ppl_rb);
326 kmem_cache_free(ia64_partial_page_cachep, pp);
329 static struct ia64_partial_page *
330 __pp_prev(struct ia64_partial_page *pp)
332 struct rb_node *prev = rb_prev(&pp->pp_rb);
333 if (prev)
334 return rb_entry(prev, struct ia64_partial_page, pp_rb);
335 else
336 return NULL;
340 * Delete partial pages with address between @start and @end.
341 * @start and @end are page aligned.
343 static void
344 __ia32_delete_pp_range(unsigned int start, unsigned int end)
346 struct ia64_partial_page *pp, *prev;
347 struct rb_node **rb_link, *rb_parent;
349 if (start >= end)
350 return;
352 pp = __ia32_find_pp(current->thread.ppl, start, &prev,
353 &rb_link, &rb_parent);
354 if (pp)
355 prev = __pp_prev(pp);
356 else {
357 if (prev)
358 pp = prev->next;
359 else
360 pp = current->thread.ppl->pp_head;
363 while (pp && pp->base < end) {
364 struct ia64_partial_page *tmp = pp->next;
365 __ia32_delete_pp(current->thread.ppl, pp, prev);
366 pp = tmp;
371 * Set the range between @start and @end in bitmap.
372 * @start and @end should be IA32 page aligned and in the same IA64 page.
374 static int
375 __ia32_set_pp(unsigned int start, unsigned int end, int flags)
377 struct ia64_partial_page *pp, *prev;
378 struct rb_node ** rb_link, *rb_parent;
379 unsigned int pstart, start_bit, end_bit, i;
381 pstart = PAGE_START(start);
382 start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE;
383 end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE;
384 if (end_bit == 0)
385 end_bit = PAGE_SIZE / IA32_PAGE_SIZE;
386 pp = __ia32_find_pp(current->thread.ppl, pstart, &prev,
387 &rb_link, &rb_parent);
388 if (pp) {
389 for (i = start_bit; i < end_bit; i++)
390 set_bit(i, &pp->bitmap);
392 * Check: if this partial page has been set to a full page,
393 * then delete it.
395 if (find_first_zero_bit(&pp->bitmap, sizeof(pp->bitmap)*8) >=
396 PAGE_SIZE/IA32_PAGE_SIZE) {
397 __ia32_delete_pp(current->thread.ppl, pp, __pp_prev(pp));
399 return 0;
403 * MAP_FIXED may lead to overlapping mmap.
404 * In this case, the requested mmap area may already mmaped as a full
405 * page. So check vma before adding a new partial page.
407 if (flags & MAP_FIXED) {
408 struct vm_area_struct *vma = find_vma(current->mm, pstart);
409 if (vma && vma->vm_start <= pstart)
410 return 0;
413 /* new a ia64_partial_page */
414 pp = kmem_cache_alloc(ia64_partial_page_cachep, GFP_KERNEL);
415 if (!pp)
416 return -ENOMEM;
417 pp->base = pstart;
418 pp->bitmap = 0;
419 for (i=start_bit; i<end_bit; i++)
420 set_bit(i, &(pp->bitmap));
421 pp->next = NULL;
422 __ia32_insert_pp(current->thread.ppl, pp, prev, rb_link, rb_parent);
423 return 0;
427 * @start and @end should be IA32 page aligned, but don't need to be in the
428 * same IA64 page. Split @start and @end to make sure they're in the same IA64
429 * page, then call __ia32_set_pp().
431 static void
432 ia32_set_pp(unsigned int start, unsigned int end, int flags)
434 down_write(&current->mm->mmap_sem);
435 if (flags & MAP_FIXED) {
437 * MAP_FIXED may lead to overlapping mmap. When this happens,
438 * a series of complete IA64 pages results in deletion of
439 * old partial pages in that range.
441 __ia32_delete_pp_range(PAGE_ALIGN(start), PAGE_START(end));
444 if (end < PAGE_ALIGN(start)) {
445 __ia32_set_pp(start, end, flags);
446 } else {
447 if (offset_in_page(start))
448 __ia32_set_pp(start, PAGE_ALIGN(start), flags);
449 if (offset_in_page(end))
450 __ia32_set_pp(PAGE_START(end), end, flags);
452 up_write(&current->mm->mmap_sem);
456 * Unset the range between @start and @end in bitmap.
457 * @start and @end should be IA32 page aligned and in the same IA64 page.
458 * After doing that, if the bitmap is 0, then free the page and return 1,
459 * else return 0;
460 * If not find the partial page in the list, then
461 * If the vma exists, then the full page is set to a partial page;
462 * Else return -ENOMEM.
464 static int
465 __ia32_unset_pp(unsigned int start, unsigned int end)
467 struct ia64_partial_page *pp, *prev;
468 struct rb_node ** rb_link, *rb_parent;
469 unsigned int pstart, start_bit, end_bit, i;
470 struct vm_area_struct *vma;
472 pstart = PAGE_START(start);
473 start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE;
474 end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE;
475 if (end_bit == 0)
476 end_bit = PAGE_SIZE / IA32_PAGE_SIZE;
478 pp = __ia32_find_pp(current->thread.ppl, pstart, &prev,
479 &rb_link, &rb_parent);
480 if (pp) {
481 for (i = start_bit; i < end_bit; i++)
482 clear_bit(i, &pp->bitmap);
483 if (pp->bitmap == 0) {
484 __ia32_delete_pp(current->thread.ppl, pp, __pp_prev(pp));
485 return 1;
487 return 0;
490 vma = find_vma(current->mm, pstart);
491 if (!vma || vma->vm_start > pstart) {
492 return -ENOMEM;
495 /* new a ia64_partial_page */
496 pp = kmem_cache_alloc(ia64_partial_page_cachep, GFP_KERNEL);
497 if (!pp)
498 return -ENOMEM;
499 pp->base = pstart;
500 pp->bitmap = 0;
501 for (i = 0; i < start_bit; i++)
502 set_bit(i, &(pp->bitmap));
503 for (i = end_bit; i < PAGE_SIZE / IA32_PAGE_SIZE; i++)
504 set_bit(i, &(pp->bitmap));
505 pp->next = NULL;
506 __ia32_insert_pp(current->thread.ppl, pp, prev, rb_link, rb_parent);
507 return 0;
511 * Delete pp between PAGE_ALIGN(start) and PAGE_START(end) by calling
512 * __ia32_delete_pp_range(). Unset possible partial pages by calling
513 * __ia32_unset_pp().
514 * The returned value see __ia32_unset_pp().
516 static int
517 ia32_unset_pp(unsigned int *startp, unsigned int *endp)
519 unsigned int start = *startp, end = *endp;
520 int ret = 0;
522 down_write(&current->mm->mmap_sem);
524 __ia32_delete_pp_range(PAGE_ALIGN(start), PAGE_START(end));
526 if (end < PAGE_ALIGN(start)) {
527 ret = __ia32_unset_pp(start, end);
528 if (ret == 1) {
529 *startp = PAGE_START(start);
530 *endp = PAGE_ALIGN(end);
532 if (ret == 0) {
533 /* to shortcut sys_munmap() in sys32_munmap() */
534 *startp = PAGE_START(start);
535 *endp = PAGE_START(end);
537 } else {
538 if (offset_in_page(start)) {
539 ret = __ia32_unset_pp(start, PAGE_ALIGN(start));
540 if (ret == 1)
541 *startp = PAGE_START(start);
542 if (ret == 0)
543 *startp = PAGE_ALIGN(start);
544 if (ret < 0)
545 goto out;
547 if (offset_in_page(end)) {
548 ret = __ia32_unset_pp(PAGE_START(end), end);
549 if (ret == 1)
550 *endp = PAGE_ALIGN(end);
551 if (ret == 0)
552 *endp = PAGE_START(end);
556 out:
557 up_write(&current->mm->mmap_sem);
558 return ret;
562 * Compare the range between @start and @end with bitmap in partial page.
563 * @start and @end should be IA32 page aligned and in the same IA64 page.
565 static int
566 __ia32_compare_pp(unsigned int start, unsigned int end)
568 struct ia64_partial_page *pp, *prev;
569 struct rb_node ** rb_link, *rb_parent;
570 unsigned int pstart, start_bit, end_bit, size;
571 unsigned int first_bit, next_zero_bit; /* the first range in bitmap */
573 pstart = PAGE_START(start);
575 pp = __ia32_find_pp(current->thread.ppl, pstart, &prev,
576 &rb_link, &rb_parent);
577 if (!pp)
578 return 1;
580 start_bit = (start % PAGE_SIZE) / IA32_PAGE_SIZE;
581 end_bit = (end % PAGE_SIZE) / IA32_PAGE_SIZE;
582 size = sizeof(pp->bitmap) * 8;
583 first_bit = find_first_bit(&pp->bitmap, size);
584 next_zero_bit = find_next_zero_bit(&pp->bitmap, size, first_bit);
585 if ((start_bit < first_bit) || (end_bit > next_zero_bit)) {
586 /* exceeds the first range in bitmap */
587 return -ENOMEM;
588 } else if ((start_bit == first_bit) && (end_bit == next_zero_bit)) {
589 first_bit = find_next_bit(&pp->bitmap, size, next_zero_bit);
590 if ((next_zero_bit < first_bit) && (first_bit < size))
591 return 1; /* has next range */
592 else
593 return 0; /* no next range */
594 } else
595 return 1;
599 * @start and @end should be IA32 page aligned, but don't need to be in the
600 * same IA64 page. Split @start and @end to make sure they're in the same IA64
601 * page, then call __ia32_compare_pp().
603 * Take this as example: the range is the 1st and 2nd 4K page.
604 * Return 0 if they fit bitmap exactly, i.e. bitmap = 00000011;
605 * Return 1 if the range doesn't cover whole bitmap, e.g. bitmap = 00001111;
606 * Return -ENOMEM if the range exceeds the bitmap, e.g. bitmap = 00000001 or
607 * bitmap = 00000101.
609 static int
610 ia32_compare_pp(unsigned int *startp, unsigned int *endp)
612 unsigned int start = *startp, end = *endp;
613 int retval = 0;
615 down_write(&current->mm->mmap_sem);
617 if (end < PAGE_ALIGN(start)) {
618 retval = __ia32_compare_pp(start, end);
619 if (retval == 0) {
620 *startp = PAGE_START(start);
621 *endp = PAGE_ALIGN(end);
623 } else {
624 if (offset_in_page(start)) {
625 retval = __ia32_compare_pp(start,
626 PAGE_ALIGN(start));
627 if (retval == 0)
628 *startp = PAGE_START(start);
629 if (retval < 0)
630 goto out;
632 if (offset_in_page(end)) {
633 retval = __ia32_compare_pp(PAGE_START(end), end);
634 if (retval == 0)
635 *endp = PAGE_ALIGN(end);
639 out:
640 up_write(&current->mm->mmap_sem);
641 return retval;
644 static void
645 __ia32_drop_pp_list(struct ia64_partial_page_list *ppl)
647 struct ia64_partial_page *pp = ppl->pp_head;
649 while (pp) {
650 struct ia64_partial_page *next = pp->next;
651 kmem_cache_free(ia64_partial_page_cachep, pp);
652 pp = next;
655 kfree(ppl);
658 void
659 ia32_drop_ia64_partial_page_list(struct task_struct *task)
661 struct ia64_partial_page_list* ppl = task->thread.ppl;
663 if (ppl && atomic_dec_and_test(&ppl->pp_count))
664 __ia32_drop_pp_list(ppl);
668 * Copy current->thread.ppl to ppl (already initialized).
670 static int
671 __ia32_copy_pp_list(struct ia64_partial_page_list *ppl)
673 struct ia64_partial_page *pp, *tmp, *prev;
674 struct rb_node **rb_link, *rb_parent;
676 ppl->pp_head = NULL;
677 ppl->pp_hint = NULL;
678 ppl->ppl_rb = RB_ROOT;
679 rb_link = &ppl->ppl_rb.rb_node;
680 rb_parent = NULL;
681 prev = NULL;
683 for (pp = current->thread.ppl->pp_head; pp; pp = pp->next) {
684 tmp = kmem_cache_alloc(ia64_partial_page_cachep, GFP_KERNEL);
685 if (!tmp)
686 return -ENOMEM;
687 *tmp = *pp;
688 __ia32_insert_pp(ppl, tmp, prev, rb_link, rb_parent);
689 prev = tmp;
690 rb_link = &tmp->pp_rb.rb_right;
691 rb_parent = &tmp->pp_rb;
693 return 0;
697 ia32_copy_ia64_partial_page_list(struct task_struct *p,
698 unsigned long clone_flags)
700 int retval = 0;
702 if (clone_flags & CLONE_VM) {
703 atomic_inc(&current->thread.ppl->pp_count);
704 p->thread.ppl = current->thread.ppl;
705 } else {
706 p->thread.ppl = ia32_init_pp_list();
707 if (!p->thread.ppl)
708 return -ENOMEM;
709 down_write(&current->mm->mmap_sem);
711 retval = __ia32_copy_pp_list(p->thread.ppl);
713 up_write(&current->mm->mmap_sem);
716 return retval;
719 static unsigned long
720 emulate_mmap (struct file *file, unsigned long start, unsigned long len, int prot, int flags,
721 loff_t off)
723 unsigned long tmp, end, pend, pstart, ret, is_congruent, fudge = 0;
724 struct inode *inode;
725 loff_t poff;
727 end = start + len;
728 pstart = PAGE_START(start);
729 pend = PAGE_ALIGN(end);
731 if (flags & MAP_FIXED) {
732 ia32_set_pp((unsigned int)start, (unsigned int)end, flags);
733 if (start > pstart) {
734 if (flags & MAP_SHARED)
735 printk(KERN_INFO
736 "%s(%d): emulate_mmap() can't share head (addr=0x%lx)\n",
737 current->comm, task_pid_nr(current), start);
738 ret = mmap_subpage(file, start, min(PAGE_ALIGN(start), end), prot, flags,
739 off);
740 if (IS_ERR((void *) ret))
741 return ret;
742 pstart += PAGE_SIZE;
743 if (pstart >= pend)
744 goto out; /* done */
746 if (end < pend) {
747 if (flags & MAP_SHARED)
748 printk(KERN_INFO
749 "%s(%d): emulate_mmap() can't share tail (end=0x%lx)\n",
750 current->comm, task_pid_nr(current), end);
751 ret = mmap_subpage(file, max(start, PAGE_START(end)), end, prot, flags,
752 (off + len) - offset_in_page(end));
753 if (IS_ERR((void *) ret))
754 return ret;
755 pend -= PAGE_SIZE;
756 if (pstart >= pend)
757 goto out; /* done */
759 } else {
761 * If a start address was specified, use it if the entire rounded out area
762 * is available.
764 if (start && !pstart)
765 fudge = 1; /* handle case of mapping to range (0,PAGE_SIZE) */
766 tmp = arch_get_unmapped_area(file, pstart - fudge, pend - pstart, 0, flags);
767 if (tmp != pstart) {
768 pstart = tmp;
769 start = pstart + offset_in_page(off); /* make start congruent with off */
770 end = start + len;
771 pend = PAGE_ALIGN(end);
775 poff = off + (pstart - start); /* note: (pstart - start) may be negative */
776 is_congruent = (flags & MAP_ANONYMOUS) || (offset_in_page(poff) == 0);
778 if ((flags & MAP_SHARED) && !is_congruent)
779 printk(KERN_INFO "%s(%d): emulate_mmap() can't share contents of incongruent mmap "
780 "(addr=0x%lx,off=0x%llx)\n", current->comm, task_pid_nr(current), start, off);
782 DBG("mmap_body: mapping [0x%lx-0x%lx) %s with poff 0x%llx\n", pstart, pend,
783 is_congruent ? "congruent" : "not congruent", poff);
785 down_write(&current->mm->mmap_sem);
787 if (!(flags & MAP_ANONYMOUS) && is_congruent)
788 ret = do_mmap(file, pstart, pend - pstart, prot, flags | MAP_FIXED, poff);
789 else
790 ret = do_mmap(NULL, pstart, pend - pstart,
791 prot | ((flags & MAP_ANONYMOUS) ? 0 : PROT_WRITE),
792 flags | MAP_FIXED | MAP_ANONYMOUS, 0);
794 up_write(&current->mm->mmap_sem);
796 if (IS_ERR((void *) ret))
797 return ret;
799 if (!is_congruent) {
800 /* read the file contents */
801 inode = file->f_path.dentry->d_inode;
802 if (!inode->i_fop || !file->f_op->read
803 || ((*file->f_op->read)(file, (char __user *) pstart, pend - pstart, &poff)
804 < 0))
806 sys_munmap(pstart, pend - pstart);
807 return -EINVAL;
809 if (!(prot & PROT_WRITE) && sys_mprotect(pstart, pend - pstart, prot) < 0)
810 return -EINVAL;
813 if (!(flags & MAP_FIXED))
814 ia32_set_pp((unsigned int)start, (unsigned int)end, flags);
815 out:
816 return start;
819 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
821 static inline unsigned int
822 get_prot32 (unsigned int prot)
824 if (prot & PROT_WRITE)
825 /* on x86, PROT_WRITE implies PROT_READ which implies PROT_EEC */
826 prot |= PROT_READ | PROT_WRITE | PROT_EXEC;
827 else if (prot & (PROT_READ | PROT_EXEC))
828 /* on x86, there is no distinction between PROT_READ and PROT_EXEC */
829 prot |= (PROT_READ | PROT_EXEC);
831 return prot;
834 unsigned long
835 ia32_do_mmap (struct file *file, unsigned long addr, unsigned long len, int prot, int flags,
836 loff_t offset)
838 DBG("ia32_do_mmap(file=%p,addr=0x%lx,len=0x%lx,prot=%x,flags=%x,offset=0x%llx)\n",
839 file, addr, len, prot, flags, offset);
841 if (file && (!file->f_op || !file->f_op->mmap))
842 return -ENODEV;
844 len = IA32_PAGE_ALIGN(len);
845 if (len == 0)
846 return addr;
848 if (len > IA32_PAGE_OFFSET || addr > IA32_PAGE_OFFSET - len)
850 if (flags & MAP_FIXED)
851 return -ENOMEM;
852 else
853 return -EINVAL;
856 if (OFFSET4K(offset))
857 return -EINVAL;
859 prot = get_prot32(prot);
861 if (flags & MAP_HUGETLB)
862 return -ENOMEM;
864 #if PAGE_SHIFT > IA32_PAGE_SHIFT
865 mutex_lock(&ia32_mmap_mutex);
867 addr = emulate_mmap(file, addr, len, prot, flags, offset);
869 mutex_unlock(&ia32_mmap_mutex);
870 #else
871 down_write(&current->mm->mmap_sem);
873 addr = do_mmap(file, addr, len, prot, flags, offset);
875 up_write(&current->mm->mmap_sem);
876 #endif
877 DBG("ia32_do_mmap: returning 0x%lx\n", addr);
878 return addr;
882 * Linux/i386 didn't use to be able to handle more than 4 system call parameters, so these
883 * system calls used a memory block for parameter passing..
886 struct mmap_arg_struct {
887 unsigned int addr;
888 unsigned int len;
889 unsigned int prot;
890 unsigned int flags;
891 unsigned int fd;
892 unsigned int offset;
895 asmlinkage long
896 sys32_mmap (struct mmap_arg_struct __user *arg)
898 struct mmap_arg_struct a;
899 struct file *file = NULL;
900 unsigned long addr;
901 int flags;
903 if (copy_from_user(&a, arg, sizeof(a)))
904 return -EFAULT;
906 if (OFFSET4K(a.offset))
907 return -EINVAL;
909 flags = a.flags;
911 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
912 if (!(flags & MAP_ANONYMOUS)) {
913 file = fget(a.fd);
914 if (!file)
915 return -EBADF;
918 addr = ia32_do_mmap(file, a.addr, a.len, a.prot, flags, a.offset);
920 if (file)
921 fput(file);
922 return addr;
925 asmlinkage long
926 sys32_mmap2 (unsigned int addr, unsigned int len, unsigned int prot, unsigned int flags,
927 unsigned int fd, unsigned int pgoff)
929 struct file *file = NULL;
930 unsigned long retval;
932 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
933 if (!(flags & MAP_ANONYMOUS)) {
934 file = fget(fd);
935 if (!file)
936 return -EBADF;
939 retval = ia32_do_mmap(file, addr, len, prot, flags,
940 (unsigned long) pgoff << IA32_PAGE_SHIFT);
942 if (file)
943 fput(file);
944 return retval;
947 asmlinkage long
948 sys32_munmap (unsigned int start, unsigned int len)
950 unsigned int end = start + len;
951 long ret;
953 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
954 ret = sys_munmap(start, end - start);
955 #else
956 if (OFFSET4K(start))
957 return -EINVAL;
959 end = IA32_PAGE_ALIGN(end);
960 if (start >= end)
961 return -EINVAL;
963 ret = ia32_unset_pp(&start, &end);
964 if (ret < 0)
965 return ret;
967 if (start >= end)
968 return 0;
970 mutex_lock(&ia32_mmap_mutex);
971 ret = sys_munmap(start, end - start);
972 mutex_unlock(&ia32_mmap_mutex);
973 #endif
974 return ret;
977 #if PAGE_SHIFT > IA32_PAGE_SHIFT
980 * When mprotect()ing a partial page, we set the permission to the union of the old
981 * settings and the new settings. In other words, it's only possible to make access to a
982 * partial page less restrictive.
984 static long
985 mprotect_subpage (unsigned long address, int new_prot)
987 int old_prot;
988 struct vm_area_struct *vma;
990 if (new_prot == PROT_NONE)
991 return 0; /* optimize case where nothing changes... */
992 vma = find_vma(current->mm, address);
993 old_prot = get_page_prot(vma, address);
994 return sys_mprotect(address, PAGE_SIZE, new_prot | old_prot);
997 #endif /* PAGE_SHIFT > IA32_PAGE_SHIFT */
999 asmlinkage long
1000 sys32_mprotect (unsigned int start, unsigned int len, int prot)
1002 unsigned int end = start + len;
1003 #if PAGE_SHIFT > IA32_PAGE_SHIFT
1004 long retval = 0;
1005 #endif
1007 prot = get_prot32(prot);
1009 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1010 return sys_mprotect(start, end - start, prot);
1011 #else
1012 if (OFFSET4K(start))
1013 return -EINVAL;
1015 end = IA32_PAGE_ALIGN(end);
1016 if (end < start)
1017 return -EINVAL;
1019 retval = ia32_compare_pp(&start, &end);
1021 if (retval < 0)
1022 return retval;
1024 mutex_lock(&ia32_mmap_mutex);
1026 if (offset_in_page(start)) {
1027 /* start address is 4KB aligned but not page aligned. */
1028 retval = mprotect_subpage(PAGE_START(start), prot);
1029 if (retval < 0)
1030 goto out;
1032 start = PAGE_ALIGN(start);
1033 if (start >= end)
1034 goto out; /* retval is already zero... */
1037 if (offset_in_page(end)) {
1038 /* end address is 4KB aligned but not page aligned. */
1039 retval = mprotect_subpage(PAGE_START(end), prot);
1040 if (retval < 0)
1041 goto out;
1043 end = PAGE_START(end);
1045 retval = sys_mprotect(start, end - start, prot);
1047 out:
1048 mutex_unlock(&ia32_mmap_mutex);
1049 return retval;
1050 #endif
1053 asmlinkage long
1054 sys32_mremap (unsigned int addr, unsigned int old_len, unsigned int new_len,
1055 unsigned int flags, unsigned int new_addr)
1057 long ret;
1059 #if PAGE_SHIFT <= IA32_PAGE_SHIFT
1060 ret = sys_mremap(addr, old_len, new_len, flags, new_addr);
1061 #else
1062 unsigned int old_end, new_end;
1064 if (OFFSET4K(addr))
1065 return -EINVAL;
1067 old_len = IA32_PAGE_ALIGN(old_len);
1068 new_len = IA32_PAGE_ALIGN(new_len);
1069 old_end = addr + old_len;
1070 new_end = addr + new_len;
1072 if (!new_len)
1073 return -EINVAL;
1075 if ((flags & MREMAP_FIXED) && (OFFSET4K(new_addr)))
1076 return -EINVAL;
1078 if (old_len >= new_len) {
1079 ret = sys32_munmap(addr + new_len, old_len - new_len);
1080 if (ret && old_len != new_len)
1081 return ret;
1082 ret = addr;
1083 if (!(flags & MREMAP_FIXED) || (new_addr == addr))
1084 return ret;
1085 old_len = new_len;
1088 addr = PAGE_START(addr);
1089 old_len = PAGE_ALIGN(old_end) - addr;
1090 new_len = PAGE_ALIGN(new_end) - addr;
1092 mutex_lock(&ia32_mmap_mutex);
1093 ret = sys_mremap(addr, old_len, new_len, flags, new_addr);
1094 mutex_unlock(&ia32_mmap_mutex);
1096 if ((ret >= 0) && (old_len < new_len)) {
1097 /* mremap expanded successfully */
1098 ia32_set_pp(old_end, new_end, flags);
1100 #endif
1101 return ret;
1104 asmlinkage unsigned long
1105 sys32_alarm (unsigned int seconds)
1107 return alarm_setitimer(seconds);
1110 struct sel_arg_struct {
1111 unsigned int n;
1112 unsigned int inp;
1113 unsigned int outp;
1114 unsigned int exp;
1115 unsigned int tvp;
1118 asmlinkage long
1119 sys32_old_select (struct sel_arg_struct __user *arg)
1121 struct sel_arg_struct a;
1123 if (copy_from_user(&a, arg, sizeof(a)))
1124 return -EFAULT;
1125 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
1126 compat_ptr(a.exp), compat_ptr(a.tvp));
1129 #define SEMOP 1
1130 #define SEMGET 2
1131 #define SEMCTL 3
1132 #define SEMTIMEDOP 4
1133 #define MSGSND 11
1134 #define MSGRCV 12
1135 #define MSGGET 13
1136 #define MSGCTL 14
1137 #define SHMAT 21
1138 #define SHMDT 22
1139 #define SHMGET 23
1140 #define SHMCTL 24
1142 asmlinkage long
1143 sys32_ipc(u32 call, int first, int second, int third, u32 ptr, u32 fifth)
1145 int version;
1147 version = call >> 16; /* hack for backward compatibility */
1148 call &= 0xffff;
1150 switch (call) {
1151 case SEMTIMEDOP:
1152 if (fifth)
1153 return compat_sys_semtimedop(first, compat_ptr(ptr),
1154 second, compat_ptr(fifth));
1155 /* else fall through for normal semop() */
1156 case SEMOP:
1157 /* struct sembuf is the same on 32 and 64bit :)) */
1158 return sys_semtimedop(first, compat_ptr(ptr), second,
1159 NULL);
1160 case SEMGET:
1161 return sys_semget(first, second, third);
1162 case SEMCTL:
1163 return compat_sys_semctl(first, second, third, compat_ptr(ptr));
1165 case MSGSND:
1166 return compat_sys_msgsnd(first, second, third, compat_ptr(ptr));
1167 case MSGRCV:
1168 return compat_sys_msgrcv(first, second, fifth, third, version, compat_ptr(ptr));
1169 case MSGGET:
1170 return sys_msgget((key_t) first, second);
1171 case MSGCTL:
1172 return compat_sys_msgctl(first, second, compat_ptr(ptr));
1174 case SHMAT:
1175 return compat_sys_shmat(first, second, third, version, compat_ptr(ptr));
1176 break;
1177 case SHMDT:
1178 return sys_shmdt(compat_ptr(ptr));
1179 case SHMGET:
1180 return sys_shmget(first, (unsigned)second, third);
1181 case SHMCTL:
1182 return compat_sys_shmctl(first, second, compat_ptr(ptr));
1184 default:
1185 return -ENOSYS;
1187 return -EINVAL;
1190 asmlinkage long
1191 compat_sys_wait4 (compat_pid_t pid, compat_uint_t * stat_addr, int options,
1192 struct compat_rusage *ru);
1194 asmlinkage long
1195 sys32_waitpid (int pid, unsigned int *stat_addr, int options)
1197 return compat_sys_wait4(pid, stat_addr, options, NULL);
1201 * The order in which registers are stored in the ptrace regs structure
1203 #define PT_EBX 0
1204 #define PT_ECX 1
1205 #define PT_EDX 2
1206 #define PT_ESI 3
1207 #define PT_EDI 4
1208 #define PT_EBP 5
1209 #define PT_EAX 6
1210 #define PT_DS 7
1211 #define PT_ES 8
1212 #define PT_FS 9
1213 #define PT_GS 10
1214 #define PT_ORIG_EAX 11
1215 #define PT_EIP 12
1216 #define PT_CS 13
1217 #define PT_EFL 14
1218 #define PT_UESP 15
1219 #define PT_SS 16
1221 static unsigned int
1222 getreg (struct task_struct *child, int regno)
1224 struct pt_regs *child_regs;
1226 child_regs = task_pt_regs(child);
1227 switch (regno / sizeof(int)) {
1228 case PT_EBX: return child_regs->r11;
1229 case PT_ECX: return child_regs->r9;
1230 case PT_EDX: return child_regs->r10;
1231 case PT_ESI: return child_regs->r14;
1232 case PT_EDI: return child_regs->r15;
1233 case PT_EBP: return child_regs->r13;
1234 case PT_EAX: return child_regs->r8;
1235 case PT_ORIG_EAX: return child_regs->r1; /* see dispatch_to_ia32_handler() */
1236 case PT_EIP: return child_regs->cr_iip;
1237 case PT_UESP: return child_regs->r12;
1238 case PT_EFL: return child->thread.eflag;
1239 case PT_DS: case PT_ES: case PT_FS: case PT_GS: case PT_SS:
1240 return __USER_DS;
1241 case PT_CS: return __USER_CS;
1242 default:
1243 printk(KERN_ERR "ia32.getreg(): unknown register %d\n", regno);
1244 break;
1246 return 0;
1249 static void
1250 putreg (struct task_struct *child, int regno, unsigned int value)
1252 struct pt_regs *child_regs;
1254 child_regs = task_pt_regs(child);
1255 switch (regno / sizeof(int)) {
1256 case PT_EBX: child_regs->r11 = value; break;
1257 case PT_ECX: child_regs->r9 = value; break;
1258 case PT_EDX: child_regs->r10 = value; break;
1259 case PT_ESI: child_regs->r14 = value; break;
1260 case PT_EDI: child_regs->r15 = value; break;
1261 case PT_EBP: child_regs->r13 = value; break;
1262 case PT_EAX: child_regs->r8 = value; break;
1263 case PT_ORIG_EAX: child_regs->r1 = value; break;
1264 case PT_EIP: child_regs->cr_iip = value; break;
1265 case PT_UESP: child_regs->r12 = value; break;
1266 case PT_EFL: child->thread.eflag = value; break;
1267 case PT_DS: case PT_ES: case PT_FS: case PT_GS: case PT_SS:
1268 if (value != __USER_DS)
1269 printk(KERN_ERR
1270 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1271 regno, value);
1272 break;
1273 case PT_CS:
1274 if (value != __USER_CS)
1275 printk(KERN_ERR
1276 "ia32.putreg: attempt to set invalid segment register %d = %x\n",
1277 regno, value);
1278 break;
1279 default:
1280 printk(KERN_ERR "ia32.putreg: unknown register %d\n", regno);
1281 break;
1285 static void
1286 put_fpreg (int regno, struct _fpreg_ia32 __user *reg, struct pt_regs *ptp,
1287 struct switch_stack *swp, int tos)
1289 struct _fpreg_ia32 *f;
1290 char buf[32];
1292 f = (struct _fpreg_ia32 *)(((unsigned long)buf + 15) & ~15);
1293 if ((regno += tos) >= 8)
1294 regno -= 8;
1295 switch (regno) {
1296 case 0:
1297 ia64f2ia32f(f, &ptp->f8);
1298 break;
1299 case 1:
1300 ia64f2ia32f(f, &ptp->f9);
1301 break;
1302 case 2:
1303 ia64f2ia32f(f, &ptp->f10);
1304 break;
1305 case 3:
1306 ia64f2ia32f(f, &ptp->f11);
1307 break;
1308 case 4:
1309 case 5:
1310 case 6:
1311 case 7:
1312 ia64f2ia32f(f, &swp->f12 + (regno - 4));
1313 break;
1315 copy_to_user(reg, f, sizeof(*reg));
1318 static void
1319 get_fpreg (int regno, struct _fpreg_ia32 __user *reg, struct pt_regs *ptp,
1320 struct switch_stack *swp, int tos)
1323 if ((regno += tos) >= 8)
1324 regno -= 8;
1325 switch (regno) {
1326 case 0:
1327 copy_from_user(&ptp->f8, reg, sizeof(*reg));
1328 break;
1329 case 1:
1330 copy_from_user(&ptp->f9, reg, sizeof(*reg));
1331 break;
1332 case 2:
1333 copy_from_user(&ptp->f10, reg, sizeof(*reg));
1334 break;
1335 case 3:
1336 copy_from_user(&ptp->f11, reg, sizeof(*reg));
1337 break;
1338 case 4:
1339 case 5:
1340 case 6:
1341 case 7:
1342 copy_from_user(&swp->f12 + (regno - 4), reg, sizeof(*reg));
1343 break;
1345 return;
1349 save_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct __user *save)
1351 struct switch_stack *swp;
1352 struct pt_regs *ptp;
1353 int i, tos;
1355 if (!access_ok(VERIFY_WRITE, save, sizeof(*save)))
1356 return -EFAULT;
1358 __put_user(tsk->thread.fcr & 0xffff, &save->cwd);
1359 __put_user(tsk->thread.fsr & 0xffff, &save->swd);
1360 __put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd);
1361 __put_user(tsk->thread.fir, &save->fip);
1362 __put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs);
1363 __put_user(tsk->thread.fdr, &save->foo);
1364 __put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos);
1367 * Stack frames start with 16-bytes of temp space
1369 swp = (struct switch_stack *)(tsk->thread.ksp + 16);
1370 ptp = task_pt_regs(tsk);
1371 tos = (tsk->thread.fsr >> 11) & 7;
1372 for (i = 0; i < 8; i++)
1373 put_fpreg(i, &save->st_space[i], ptp, swp, tos);
1374 return 0;
1377 static int
1378 restore_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct __user *save)
1380 struct switch_stack *swp;
1381 struct pt_regs *ptp;
1382 int i, tos;
1383 unsigned int fsrlo, fsrhi, num32;
1385 if (!access_ok(VERIFY_READ, save, sizeof(*save)))
1386 return(-EFAULT);
1388 __get_user(num32, (unsigned int __user *)&save->cwd);
1389 tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f);
1390 __get_user(fsrlo, (unsigned int __user *)&save->swd);
1391 __get_user(fsrhi, (unsigned int __user *)&save->twd);
1392 num32 = (fsrhi << 16) | fsrlo;
1393 tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32;
1394 __get_user(num32, (unsigned int __user *)&save->fip);
1395 tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32;
1396 __get_user(num32, (unsigned int __user *)&save->foo);
1397 tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32;
1400 * Stack frames start with 16-bytes of temp space
1402 swp = (struct switch_stack *)(tsk->thread.ksp + 16);
1403 ptp = task_pt_regs(tsk);
1404 tos = (tsk->thread.fsr >> 11) & 7;
1405 for (i = 0; i < 8; i++)
1406 get_fpreg(i, &save->st_space[i], ptp, swp, tos);
1407 return 0;
1411 save_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct __user *save)
1413 struct switch_stack *swp;
1414 struct pt_regs *ptp;
1415 int i, tos;
1416 unsigned long mxcsr=0;
1417 unsigned long num128[2];
1419 if (!access_ok(VERIFY_WRITE, save, sizeof(*save)))
1420 return -EFAULT;
1422 __put_user(tsk->thread.fcr & 0xffff, &save->cwd);
1423 __put_user(tsk->thread.fsr & 0xffff, &save->swd);
1424 __put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd);
1425 __put_user(tsk->thread.fir, &save->fip);
1426 __put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs);
1427 __put_user(tsk->thread.fdr, &save->foo);
1428 __put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos);
1431 * Stack frames start with 16-bytes of temp space
1433 swp = (struct switch_stack *)(tsk->thread.ksp + 16);
1434 ptp = task_pt_regs(tsk);
1435 tos = (tsk->thread.fsr >> 11) & 7;
1436 for (i = 0; i < 8; i++)
1437 put_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos);
1439 mxcsr = ((tsk->thread.fcr>>32) & 0xff80) | ((tsk->thread.fsr>>32) & 0x3f);
1440 __put_user(mxcsr & 0xffff, &save->mxcsr);
1441 for (i = 0; i < 8; i++) {
1442 memcpy(&(num128[0]), &(swp->f16) + i*2, sizeof(unsigned long));
1443 memcpy(&(num128[1]), &(swp->f17) + i*2, sizeof(unsigned long));
1444 copy_to_user(&save->xmm_space[0] + 4*i, num128, sizeof(struct _xmmreg_ia32));
1446 return 0;
1449 static int
1450 restore_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct __user *save)
1452 struct switch_stack *swp;
1453 struct pt_regs *ptp;
1454 int i, tos;
1455 unsigned int fsrlo, fsrhi, num32;
1456 int mxcsr;
1457 unsigned long num64;
1458 unsigned long num128[2];
1460 if (!access_ok(VERIFY_READ, save, sizeof(*save)))
1461 return(-EFAULT);
1463 __get_user(num32, (unsigned int __user *)&save->cwd);
1464 tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f);
1465 __get_user(fsrlo, (unsigned int __user *)&save->swd);
1466 __get_user(fsrhi, (unsigned int __user *)&save->twd);
1467 num32 = (fsrhi << 16) | fsrlo;
1468 tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32;
1469 __get_user(num32, (unsigned int __user *)&save->fip);
1470 tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32;
1471 __get_user(num32, (unsigned int __user *)&save->foo);
1472 tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32;
1475 * Stack frames start with 16-bytes of temp space
1477 swp = (struct switch_stack *)(tsk->thread.ksp + 16);
1478 ptp = task_pt_regs(tsk);
1479 tos = (tsk->thread.fsr >> 11) & 7;
1480 for (i = 0; i < 8; i++)
1481 get_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos);
1483 __get_user(mxcsr, (unsigned int __user *)&save->mxcsr);
1484 num64 = mxcsr & 0xff10;
1485 tsk->thread.fcr = (tsk->thread.fcr & (~0xff1000000000UL)) | (num64<<32);
1486 num64 = mxcsr & 0x3f;
1487 tsk->thread.fsr = (tsk->thread.fsr & (~0x3f00000000UL)) | (num64<<32);
1489 for (i = 0; i < 8; i++) {
1490 copy_from_user(num128, &save->xmm_space[0] + 4*i, sizeof(struct _xmmreg_ia32));
1491 memcpy(&(swp->f16) + i*2, &(num128[0]), sizeof(unsigned long));
1492 memcpy(&(swp->f17) + i*2, &(num128[1]), sizeof(unsigned long));
1494 return 0;
1497 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1498 compat_ulong_t caddr, compat_ulong_t cdata)
1500 unsigned long addr = caddr;
1501 unsigned long data = cdata;
1502 unsigned int tmp;
1503 long i, ret;
1505 switch (request) {
1506 case PTRACE_PEEKUSR: /* read word at addr in USER area */
1507 ret = -EIO;
1508 if ((addr & 3) || addr > 17*sizeof(int))
1509 break;
1511 tmp = getreg(child, addr);
1512 if (!put_user(tmp, (unsigned int __user *) compat_ptr(data)))
1513 ret = 0;
1514 break;
1516 case PTRACE_POKEUSR: /* write word at addr in USER area */
1517 ret = -EIO;
1518 if ((addr & 3) || addr > 17*sizeof(int))
1519 break;
1521 putreg(child, addr, data);
1522 ret = 0;
1523 break;
1525 case IA32_PTRACE_GETREGS:
1526 if (!access_ok(VERIFY_WRITE, compat_ptr(data), 17*sizeof(int))) {
1527 ret = -EIO;
1528 break;
1530 for (i = 0; i < (int) (17*sizeof(int)); i += sizeof(int) ) {
1531 put_user(getreg(child, i), (unsigned int __user *) compat_ptr(data));
1532 data += sizeof(int);
1534 ret = 0;
1535 break;
1537 case IA32_PTRACE_SETREGS:
1538 if (!access_ok(VERIFY_READ, compat_ptr(data), 17*sizeof(int))) {
1539 ret = -EIO;
1540 break;
1542 for (i = 0; i < (int) (17*sizeof(int)); i += sizeof(int) ) {
1543 get_user(tmp, (unsigned int __user *) compat_ptr(data));
1544 putreg(child, i, tmp);
1545 data += sizeof(int);
1547 ret = 0;
1548 break;
1550 case IA32_PTRACE_GETFPREGS:
1551 ret = save_ia32_fpstate(child, (struct ia32_user_i387_struct __user *)
1552 compat_ptr(data));
1553 break;
1555 case IA32_PTRACE_GETFPXREGS:
1556 ret = save_ia32_fpxstate(child, (struct ia32_user_fxsr_struct __user *)
1557 compat_ptr(data));
1558 break;
1560 case IA32_PTRACE_SETFPREGS:
1561 ret = restore_ia32_fpstate(child, (struct ia32_user_i387_struct __user *)
1562 compat_ptr(data));
1563 break;
1565 case IA32_PTRACE_SETFPXREGS:
1566 ret = restore_ia32_fpxstate(child, (struct ia32_user_fxsr_struct __user *)
1567 compat_ptr(data));
1568 break;
1570 default:
1571 return compat_ptrace_request(child, request, caddr, cdata);
1573 return ret;
1576 typedef struct {
1577 unsigned int ss_sp;
1578 unsigned int ss_flags;
1579 unsigned int ss_size;
1580 } ia32_stack_t;
1582 asmlinkage long
1583 sys32_sigaltstack (ia32_stack_t __user *uss32, ia32_stack_t __user *uoss32,
1584 long arg2, long arg3, long arg4, long arg5, long arg6,
1585 long arg7, struct pt_regs pt)
1587 stack_t uss, uoss;
1588 ia32_stack_t buf32;
1589 int ret;
1590 mm_segment_t old_fs = get_fs();
1592 if (uss32) {
1593 if (copy_from_user(&buf32, uss32, sizeof(ia32_stack_t)))
1594 return -EFAULT;
1595 uss.ss_sp = (void __user *) (long) buf32.ss_sp;
1596 uss.ss_flags = buf32.ss_flags;
1597 /* MINSIGSTKSZ is different for ia32 vs ia64. We lie here to pass the
1598 check and set it to the user requested value later */
1599 if ((buf32.ss_flags != SS_DISABLE) && (buf32.ss_size < MINSIGSTKSZ_IA32)) {
1600 ret = -ENOMEM;
1601 goto out;
1603 uss.ss_size = MINSIGSTKSZ;
1605 set_fs(KERNEL_DS);
1606 ret = do_sigaltstack(uss32 ? (stack_t __user *) &uss : NULL,
1607 (stack_t __user *) &uoss, pt.r12);
1608 current->sas_ss_size = buf32.ss_size;
1609 set_fs(old_fs);
1610 out:
1611 if (ret < 0)
1612 return(ret);
1613 if (uoss32) {
1614 buf32.ss_sp = (long __user) uoss.ss_sp;
1615 buf32.ss_flags = uoss.ss_flags;
1616 buf32.ss_size = uoss.ss_size;
1617 if (copy_to_user(uoss32, &buf32, sizeof(ia32_stack_t)))
1618 return -EFAULT;
1620 return ret;
1623 asmlinkage int
1624 sys32_msync (unsigned int start, unsigned int len, int flags)
1626 unsigned int addr;
1628 if (OFFSET4K(start))
1629 return -EINVAL;
1630 addr = PAGE_START(start);
1631 return sys_msync(addr, len + (start - addr), flags);
1634 struct sysctl32 {
1635 unsigned int name;
1636 int nlen;
1637 unsigned int oldval;
1638 unsigned int oldlenp;
1639 unsigned int newval;
1640 unsigned int newlen;
1641 unsigned int __unused[4];
1644 #ifdef CONFIG_SYSCTL_SYSCALL
1645 asmlinkage long
1646 sys32_sysctl (struct sysctl32 __user *args)
1648 struct sysctl32 a32;
1649 mm_segment_t old_fs = get_fs ();
1650 void __user *oldvalp, *newvalp;
1651 size_t oldlen;
1652 int __user *namep;
1653 long ret;
1655 if (copy_from_user(&a32, args, sizeof(a32)))
1656 return -EFAULT;
1659 * We need to pre-validate these because we have to disable address checking
1660 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
1661 * user specifying bad addresses here. Well, since we're dealing with 32 bit
1662 * addresses, we KNOW that access_ok() will always succeed, so this is an
1663 * expensive NOP, but so what...
1665 namep = (int __user *) compat_ptr(a32.name);
1666 oldvalp = compat_ptr(a32.oldval);
1667 newvalp = compat_ptr(a32.newval);
1669 if ((oldvalp && get_user(oldlen, (int __user *) compat_ptr(a32.oldlenp)))
1670 || !access_ok(VERIFY_WRITE, namep, 0)
1671 || !access_ok(VERIFY_WRITE, oldvalp, 0)
1672 || !access_ok(VERIFY_WRITE, newvalp, 0))
1673 return -EFAULT;
1675 set_fs(KERNEL_DS);
1676 lock_kernel();
1677 ret = do_sysctl(namep, a32.nlen, oldvalp, (size_t __user *) &oldlen,
1678 newvalp, (size_t) a32.newlen);
1679 unlock_kernel();
1680 set_fs(old_fs);
1682 if (oldvalp && put_user (oldlen, (int __user *) compat_ptr(a32.oldlenp)))
1683 return -EFAULT;
1685 return ret;
1687 #endif
1689 asmlinkage long
1690 sys32_newuname (struct new_utsname __user *name)
1692 int ret = sys_newuname(name);
1694 if (!ret)
1695 if (copy_to_user(name->machine, "i686\0\0\0", 8))
1696 ret = -EFAULT;
1697 return ret;
1700 asmlinkage long
1701 sys32_getresuid16 (u16 __user *ruid, u16 __user *euid, u16 __user *suid)
1703 uid_t a, b, c;
1704 int ret;
1705 mm_segment_t old_fs = get_fs();
1707 set_fs(KERNEL_DS);
1708 ret = sys_getresuid((uid_t __user *) &a, (uid_t __user *) &b, (uid_t __user *) &c);
1709 set_fs(old_fs);
1711 if (put_user(a, ruid) || put_user(b, euid) || put_user(c, suid))
1712 return -EFAULT;
1713 return ret;
1716 asmlinkage long
1717 sys32_getresgid16 (u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
1719 gid_t a, b, c;
1720 int ret;
1721 mm_segment_t old_fs = get_fs();
1723 set_fs(KERNEL_DS);
1724 ret = sys_getresgid((gid_t __user *) &a, (gid_t __user *) &b, (gid_t __user *) &c);
1725 set_fs(old_fs);
1727 if (ret)
1728 return ret;
1730 return put_user(a, rgid) | put_user(b, egid) | put_user(c, sgid);
1733 asmlinkage long
1734 sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1736 /* Sign-extension of "offset" is important here... */
1737 return sys_lseek(fd, offset, whence);
1740 static int
1741 groups16_to_user(short __user *grouplist, struct group_info *group_info)
1743 int i;
1744 short group;
1746 for (i = 0; i < group_info->ngroups; i++) {
1747 group = (short)GROUP_AT(group_info, i);
1748 if (put_user(group, grouplist+i))
1749 return -EFAULT;
1752 return 0;
1755 static int
1756 groups16_from_user(struct group_info *group_info, short __user *grouplist)
1758 int i;
1759 short group;
1761 for (i = 0; i < group_info->ngroups; i++) {
1762 if (get_user(group, grouplist+i))
1763 return -EFAULT;
1764 GROUP_AT(group_info, i) = (gid_t)group;
1767 return 0;
1770 asmlinkage long
1771 sys32_getgroups16 (int gidsetsize, short __user *grouplist)
1773 const struct cred *cred = current_cred();
1774 int i;
1776 if (gidsetsize < 0)
1777 return -EINVAL;
1779 i = cred->group_info->ngroups;
1780 if (gidsetsize) {
1781 if (i > gidsetsize) {
1782 i = -EINVAL;
1783 goto out;
1785 if (groups16_to_user(grouplist, cred->group_info)) {
1786 i = -EFAULT;
1787 goto out;
1790 out:
1791 return i;
1794 asmlinkage long
1795 sys32_setgroups16 (int gidsetsize, short __user *grouplist)
1797 struct group_info *group_info;
1798 int retval;
1800 if (!capable(CAP_SETGID))
1801 return -EPERM;
1802 if ((unsigned)gidsetsize > NGROUPS_MAX)
1803 return -EINVAL;
1805 group_info = groups_alloc(gidsetsize);
1806 if (!group_info)
1807 return -ENOMEM;
1808 retval = groups16_from_user(group_info, grouplist);
1809 if (retval) {
1810 put_group_info(group_info);
1811 return retval;
1814 retval = set_current_groups(group_info);
1815 put_group_info(group_info);
1817 return retval;
1820 asmlinkage long
1821 sys32_truncate64 (unsigned int path, unsigned int len_lo, unsigned int len_hi)
1823 return sys_truncate(compat_ptr(path), ((unsigned long) len_hi << 32) | len_lo);
1826 asmlinkage long
1827 sys32_ftruncate64 (int fd, unsigned int len_lo, unsigned int len_hi)
1829 return sys_ftruncate(fd, ((unsigned long) len_hi << 32) | len_lo);
1832 static int
1833 putstat64 (struct stat64 __user *ubuf, struct kstat *kbuf)
1835 int err;
1836 u64 hdev;
1838 if (clear_user(ubuf, sizeof(*ubuf)))
1839 return -EFAULT;
1841 hdev = huge_encode_dev(kbuf->dev);
1842 err = __put_user(hdev, (u32 __user*)&ubuf->st_dev);
1843 err |= __put_user(hdev >> 32, ((u32 __user*)&ubuf->st_dev) + 1);
1844 err |= __put_user(kbuf->ino, &ubuf->__st_ino);
1845 err |= __put_user(kbuf->ino, &ubuf->st_ino_lo);
1846 err |= __put_user(kbuf->ino >> 32, &ubuf->st_ino_hi);
1847 err |= __put_user(kbuf->mode, &ubuf->st_mode);
1848 err |= __put_user(kbuf->nlink, &ubuf->st_nlink);
1849 err |= __put_user(kbuf->uid, &ubuf->st_uid);
1850 err |= __put_user(kbuf->gid, &ubuf->st_gid);
1851 hdev = huge_encode_dev(kbuf->rdev);
1852 err = __put_user(hdev, (u32 __user*)&ubuf->st_rdev);
1853 err |= __put_user(hdev >> 32, ((u32 __user*)&ubuf->st_rdev) + 1);
1854 err |= __put_user(kbuf->size, &ubuf->st_size_lo);
1855 err |= __put_user((kbuf->size >> 32), &ubuf->st_size_hi);
1856 err |= __put_user(kbuf->atime.tv_sec, &ubuf->st_atime);
1857 err |= __put_user(kbuf->atime.tv_nsec, &ubuf->st_atime_nsec);
1858 err |= __put_user(kbuf->mtime.tv_sec, &ubuf->st_mtime);
1859 err |= __put_user(kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec);
1860 err |= __put_user(kbuf->ctime.tv_sec, &ubuf->st_ctime);
1861 err |= __put_user(kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec);
1862 err |= __put_user(kbuf->blksize, &ubuf->st_blksize);
1863 err |= __put_user(kbuf->blocks, &ubuf->st_blocks);
1864 return err;
1867 asmlinkage long
1868 sys32_stat64 (char __user *filename, struct stat64 __user *statbuf)
1870 struct kstat s;
1871 long ret = vfs_stat(filename, &s);
1872 if (!ret)
1873 ret = putstat64(statbuf, &s);
1874 return ret;
1877 asmlinkage long
1878 sys32_lstat64 (char __user *filename, struct stat64 __user *statbuf)
1880 struct kstat s;
1881 long ret = vfs_lstat(filename, &s);
1882 if (!ret)
1883 ret = putstat64(statbuf, &s);
1884 return ret;
1887 asmlinkage long
1888 sys32_fstat64 (unsigned int fd, struct stat64 __user *statbuf)
1890 struct kstat s;
1891 long ret = vfs_fstat(fd, &s);
1892 if (!ret)
1893 ret = putstat64(statbuf, &s);
1894 return ret;
1897 asmlinkage long
1898 sys32_sched_rr_get_interval (pid_t pid, struct compat_timespec __user *interval)
1900 mm_segment_t old_fs = get_fs();
1901 struct timespec t;
1902 long ret;
1904 set_fs(KERNEL_DS);
1905 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
1906 set_fs(old_fs);
1907 if (put_compat_timespec(&t, interval))
1908 return -EFAULT;
1909 return ret;
1912 asmlinkage long
1913 sys32_pread (unsigned int fd, void __user *buf, unsigned int count, u32 pos_lo, u32 pos_hi)
1915 return sys_pread64(fd, buf, count, ((unsigned long) pos_hi << 32) | pos_lo);
1918 asmlinkage long
1919 sys32_pwrite (unsigned int fd, void __user *buf, unsigned int count, u32 pos_lo, u32 pos_hi)
1921 return sys_pwrite64(fd, buf, count, ((unsigned long) pos_hi << 32) | pos_lo);
1924 asmlinkage long
1925 sys32_sendfile (int out_fd, int in_fd, int __user *offset, unsigned int count)
1927 mm_segment_t old_fs = get_fs();
1928 long ret;
1929 off_t of;
1931 if (offset && get_user(of, offset))
1932 return -EFAULT;
1934 set_fs(KERNEL_DS);
1935 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *) &of : NULL, count);
1936 set_fs(old_fs);
1938 if (offset && put_user(of, offset))
1939 return -EFAULT;
1941 return ret;
1944 asmlinkage long
1945 sys32_personality (unsigned int personality)
1947 long ret;
1949 if (current->personality == PER_LINUX32 && personality == PER_LINUX)
1950 personality = PER_LINUX32;
1951 ret = sys_personality(personality);
1952 if (ret == PER_LINUX32)
1953 ret = PER_LINUX;
1954 return ret;
1957 asmlinkage unsigned long
1958 sys32_brk (unsigned int brk)
1960 unsigned long ret, obrk;
1961 struct mm_struct *mm = current->mm;
1963 obrk = mm->brk;
1964 ret = sys_brk(brk);
1965 if (ret < obrk)
1966 clear_user(compat_ptr(ret), PAGE_ALIGN(ret) - ret);
1967 return ret;
1970 /* Structure for ia32 emulation on ia64 */
1971 struct epoll_event32
1973 u32 events;
1974 u32 data[2];
1977 asmlinkage long
1978 sys32_epoll_ctl(int epfd, int op, int fd, struct epoll_event32 __user *event)
1980 mm_segment_t old_fs = get_fs();
1981 struct epoll_event event64;
1982 int error;
1983 u32 data_halfword;
1985 if (!access_ok(VERIFY_READ, event, sizeof(struct epoll_event32)))
1986 return -EFAULT;
1988 __get_user(event64.events, &event->events);
1989 __get_user(data_halfword, &event->data[0]);
1990 event64.data = data_halfword;
1991 __get_user(data_halfword, &event->data[1]);
1992 event64.data |= (u64)data_halfword << 32;
1994 set_fs(KERNEL_DS);
1995 error = sys_epoll_ctl(epfd, op, fd, (struct epoll_event __user *) &event64);
1996 set_fs(old_fs);
1998 return error;
2001 asmlinkage long
2002 sys32_epoll_wait(int epfd, struct epoll_event32 __user * events, int maxevents,
2003 int timeout)
2005 struct epoll_event *events64 = NULL;
2006 mm_segment_t old_fs = get_fs();
2007 int numevents, size;
2008 int evt_idx;
2009 int do_free_pages = 0;
2011 if (maxevents <= 0) {
2012 return -EINVAL;
2015 /* Verify that the area passed by the user is writeable */
2016 if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event32)))
2017 return -EFAULT;
2020 * Allocate space for the intermediate copy. If the space needed
2021 * is large enough to cause kmalloc to fail, then try again with
2022 * __get_free_pages.
2024 size = maxevents * sizeof(struct epoll_event);
2025 events64 = kmalloc(size, GFP_KERNEL);
2026 if (events64 == NULL) {
2027 events64 = (struct epoll_event *)
2028 __get_free_pages(GFP_KERNEL, get_order(size));
2029 if (events64 == NULL)
2030 return -ENOMEM;
2031 do_free_pages = 1;
2034 /* Do the system call */
2035 set_fs(KERNEL_DS); /* copy_to/from_user should work on kernel mem*/
2036 numevents = sys_epoll_wait(epfd, (struct epoll_event __user *) events64,
2037 maxevents, timeout);
2038 set_fs(old_fs);
2040 /* Don't modify userspace memory if we're returning an error */
2041 if (numevents > 0) {
2042 /* Translate the 64-bit structures back into the 32-bit
2043 structures */
2044 for (evt_idx = 0; evt_idx < numevents; evt_idx++) {
2045 __put_user(events64[evt_idx].events,
2046 &events[evt_idx].events);
2047 __put_user((u32)events64[evt_idx].data,
2048 &events[evt_idx].data[0]);
2049 __put_user((u32)(events64[evt_idx].data >> 32),
2050 &events[evt_idx].data[1]);
2054 if (do_free_pages)
2055 free_pages((unsigned long) events64, get_order(size));
2056 else
2057 kfree(events64);
2058 return numevents;
2062 * Get a yet unused TLS descriptor index.
2064 static int
2065 get_free_idx (void)
2067 struct thread_struct *t = &current->thread;
2068 int idx;
2070 for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++)
2071 if (desc_empty(t->tls_array + idx))
2072 return idx + GDT_ENTRY_TLS_MIN;
2073 return -ESRCH;
2076 static void set_tls_desc(struct task_struct *p, int idx,
2077 const struct ia32_user_desc *info, int n)
2079 struct thread_struct *t = &p->thread;
2080 struct desc_struct *desc = &t->tls_array[idx - GDT_ENTRY_TLS_MIN];
2081 int cpu;
2084 * We must not get preempted while modifying the TLS.
2086 cpu = get_cpu();
2088 while (n-- > 0) {
2089 if (LDT_empty(info)) {
2090 desc->a = 0;
2091 desc->b = 0;
2092 } else {
2093 desc->a = LDT_entry_a(info);
2094 desc->b = LDT_entry_b(info);
2097 ++info;
2098 ++desc;
2101 if (t == &current->thread)
2102 load_TLS(t, cpu);
2104 put_cpu();
2108 * Set a given TLS descriptor:
2110 asmlinkage int
2111 sys32_set_thread_area (struct ia32_user_desc __user *u_info)
2113 struct ia32_user_desc info;
2114 int idx;
2116 if (copy_from_user(&info, u_info, sizeof(info)))
2117 return -EFAULT;
2118 idx = info.entry_number;
2121 * index -1 means the kernel should try to find and allocate an empty descriptor:
2123 if (idx == -1) {
2124 idx = get_free_idx();
2125 if (idx < 0)
2126 return idx;
2127 if (put_user(idx, &u_info->entry_number))
2128 return -EFAULT;
2131 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
2132 return -EINVAL;
2134 set_tls_desc(current, idx, &info, 1);
2135 return 0;
2139 * Get the current Thread-Local Storage area:
2142 #define GET_BASE(desc) ( \
2143 (((desc)->a >> 16) & 0x0000ffff) | \
2144 (((desc)->b << 16) & 0x00ff0000) | \
2145 ( (desc)->b & 0xff000000) )
2147 #define GET_LIMIT(desc) ( \
2148 ((desc)->a & 0x0ffff) | \
2149 ((desc)->b & 0xf0000) )
2151 #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
2152 #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
2153 #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
2154 #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
2155 #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
2156 #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
2158 static void fill_user_desc(struct ia32_user_desc *info, int idx,
2159 const struct desc_struct *desc)
2161 info->entry_number = idx;
2162 info->base_addr = GET_BASE(desc);
2163 info->limit = GET_LIMIT(desc);
2164 info->seg_32bit = GET_32BIT(desc);
2165 info->contents = GET_CONTENTS(desc);
2166 info->read_exec_only = !GET_WRITABLE(desc);
2167 info->limit_in_pages = GET_LIMIT_PAGES(desc);
2168 info->seg_not_present = !GET_PRESENT(desc);
2169 info->useable = GET_USEABLE(desc);
2172 asmlinkage int
2173 sys32_get_thread_area (struct ia32_user_desc __user *u_info)
2175 struct ia32_user_desc info;
2176 struct desc_struct *desc;
2177 int idx;
2179 if (get_user(idx, &u_info->entry_number))
2180 return -EFAULT;
2181 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
2182 return -EINVAL;
2184 desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
2185 fill_user_desc(&info, idx, desc);
2187 if (copy_to_user(u_info, &info, sizeof(info)))
2188 return -EFAULT;
2189 return 0;
2192 struct regset_get {
2193 void *kbuf;
2194 void __user *ubuf;
2197 struct regset_set {
2198 const void *kbuf;
2199 const void __user *ubuf;
2202 struct regset_getset {
2203 struct task_struct *target;
2204 const struct user_regset *regset;
2205 union {
2206 struct regset_get get;
2207 struct regset_set set;
2208 } u;
2209 unsigned int pos;
2210 unsigned int count;
2211 int ret;
2214 static void getfpreg(struct task_struct *task, int regno, int *val)
2216 switch (regno / sizeof(int)) {
2217 case 0:
2218 *val = task->thread.fcr & 0xffff;
2219 break;
2220 case 1:
2221 *val = task->thread.fsr & 0xffff;
2222 break;
2223 case 2:
2224 *val = (task->thread.fsr>>16) & 0xffff;
2225 break;
2226 case 3:
2227 *val = task->thread.fir;
2228 break;
2229 case 4:
2230 *val = (task->thread.fir>>32) & 0xffff;
2231 break;
2232 case 5:
2233 *val = task->thread.fdr;
2234 break;
2235 case 6:
2236 *val = (task->thread.fdr >> 32) & 0xffff;
2237 break;
2241 static void setfpreg(struct task_struct *task, int regno, int val)
2243 switch (regno / sizeof(int)) {
2244 case 0:
2245 task->thread.fcr = (task->thread.fcr & (~0x1f3f))
2246 | (val & 0x1f3f);
2247 break;
2248 case 1:
2249 task->thread.fsr = (task->thread.fsr & (~0xffff)) | val;
2250 break;
2251 case 2:
2252 task->thread.fsr = (task->thread.fsr & (~0xffff0000))
2253 | (val << 16);
2254 break;
2255 case 3:
2256 task->thread.fir = (task->thread.fir & (~0xffffffff)) | val;
2257 break;
2258 case 5:
2259 task->thread.fdr = (task->thread.fdr & (~0xffffffff)) | val;
2260 break;
2264 static void access_fpreg_ia32(int regno, void *reg,
2265 struct pt_regs *pt, struct switch_stack *sw,
2266 int tos, int write)
2268 void *f;
2270 if ((regno += tos) >= 8)
2271 regno -= 8;
2272 if (regno < 4)
2273 f = &pt->f8 + regno;
2274 else if (regno <= 7)
2275 f = &sw->f12 + (regno - 4);
2276 else {
2277 printk(KERN_ERR "regno must be less than 7 \n");
2278 return;
2281 if (write)
2282 memcpy(f, reg, sizeof(struct _fpreg_ia32));
2283 else
2284 memcpy(reg, f, sizeof(struct _fpreg_ia32));
2287 static void do_fpregs_get(struct unw_frame_info *info, void *arg)
2289 struct regset_getset *dst = arg;
2290 struct task_struct *task = dst->target;
2291 struct pt_regs *pt;
2292 int start, end, tos;
2293 char buf[80];
2295 if (dst->count == 0 || unw_unwind_to_user(info) < 0)
2296 return;
2297 if (dst->pos < 7 * sizeof(int)) {
2298 end = min((dst->pos + dst->count),
2299 (unsigned int)(7 * sizeof(int)));
2300 for (start = dst->pos; start < end; start += sizeof(int))
2301 getfpreg(task, start, (int *)(buf + start));
2302 dst->ret = user_regset_copyout(&dst->pos, &dst->count,
2303 &dst->u.get.kbuf, &dst->u.get.ubuf, buf,
2304 0, 7 * sizeof(int));
2305 if (dst->ret || dst->count == 0)
2306 return;
2308 if (dst->pos < sizeof(struct ia32_user_i387_struct)) {
2309 pt = task_pt_regs(task);
2310 tos = (task->thread.fsr >> 11) & 7;
2311 end = min(dst->pos + dst->count,
2312 (unsigned int)(sizeof(struct ia32_user_i387_struct)));
2313 start = (dst->pos - 7 * sizeof(int)) /
2314 sizeof(struct _fpreg_ia32);
2315 end = (end - 7 * sizeof(int)) / sizeof(struct _fpreg_ia32);
2316 for (; start < end; start++)
2317 access_fpreg_ia32(start,
2318 (struct _fpreg_ia32 *)buf + start,
2319 pt, info->sw, tos, 0);
2320 dst->ret = user_regset_copyout(&dst->pos, &dst->count,
2321 &dst->u.get.kbuf, &dst->u.get.ubuf,
2322 buf, 7 * sizeof(int),
2323 sizeof(struct ia32_user_i387_struct));
2324 if (dst->ret || dst->count == 0)
2325 return;
2329 static void do_fpregs_set(struct unw_frame_info *info, void *arg)
2331 struct regset_getset *dst = arg;
2332 struct task_struct *task = dst->target;
2333 struct pt_regs *pt;
2334 char buf[80];
2335 int end, start, tos;
2337 if (dst->count == 0 || unw_unwind_to_user(info) < 0)
2338 return;
2340 if (dst->pos < 7 * sizeof(int)) {
2341 start = dst->pos;
2342 dst->ret = user_regset_copyin(&dst->pos, &dst->count,
2343 &dst->u.set.kbuf, &dst->u.set.ubuf, buf,
2344 0, 7 * sizeof(int));
2345 if (dst->ret)
2346 return;
2347 for (; start < dst->pos; start += sizeof(int))
2348 setfpreg(task, start, *((int *)(buf + start)));
2349 if (dst->count == 0)
2350 return;
2352 if (dst->pos < sizeof(struct ia32_user_i387_struct)) {
2353 start = (dst->pos - 7 * sizeof(int)) /
2354 sizeof(struct _fpreg_ia32);
2355 dst->ret = user_regset_copyin(&dst->pos, &dst->count,
2356 &dst->u.set.kbuf, &dst->u.set.ubuf,
2357 buf, 7 * sizeof(int),
2358 sizeof(struct ia32_user_i387_struct));
2359 if (dst->ret)
2360 return;
2361 pt = task_pt_regs(task);
2362 tos = (task->thread.fsr >> 11) & 7;
2363 end = (dst->pos - 7 * sizeof(int)) / sizeof(struct _fpreg_ia32);
2364 for (; start < end; start++)
2365 access_fpreg_ia32(start,
2366 (struct _fpreg_ia32 *)buf + start,
2367 pt, info->sw, tos, 1);
2368 if (dst->count == 0)
2369 return;
2373 #define OFFSET(member) ((int)(offsetof(struct ia32_user_fxsr_struct, member)))
2374 static void getfpxreg(struct task_struct *task, int start, int end, char *buf)
2376 int min_val;
2378 min_val = min(end, OFFSET(fop));
2379 while (start < min_val) {
2380 if (start == OFFSET(cwd))
2381 *((short *)buf) = task->thread.fcr & 0xffff;
2382 else if (start == OFFSET(swd))
2383 *((short *)buf) = task->thread.fsr & 0xffff;
2384 else if (start == OFFSET(twd))
2385 *((short *)buf) = (task->thread.fsr>>16) & 0xffff;
2386 buf += 2;
2387 start += 2;
2389 /* skip fop element */
2390 if (start == OFFSET(fop)) {
2391 start += 2;
2392 buf += 2;
2394 while (start < end) {
2395 if (start == OFFSET(fip))
2396 *((int *)buf) = task->thread.fir;
2397 else if (start == OFFSET(fcs))
2398 *((int *)buf) = (task->thread.fir>>32) & 0xffff;
2399 else if (start == OFFSET(foo))
2400 *((int *)buf) = task->thread.fdr;
2401 else if (start == OFFSET(fos))
2402 *((int *)buf) = (task->thread.fdr>>32) & 0xffff;
2403 else if (start == OFFSET(mxcsr))
2404 *((int *)buf) = ((task->thread.fcr>>32) & 0xff80)
2405 | ((task->thread.fsr>>32) & 0x3f);
2406 buf += 4;
2407 start += 4;
2411 static void setfpxreg(struct task_struct *task, int start, int end, char *buf)
2413 int min_val, num32;
2414 short num;
2415 unsigned long num64;
2417 min_val = min(end, OFFSET(fop));
2418 while (start < min_val) {
2419 num = *((short *)buf);
2420 if (start == OFFSET(cwd)) {
2421 task->thread.fcr = (task->thread.fcr & (~0x1f3f))
2422 | (num & 0x1f3f);
2423 } else if (start == OFFSET(swd)) {
2424 task->thread.fsr = (task->thread.fsr & (~0xffff)) | num;
2425 } else if (start == OFFSET(twd)) {
2426 task->thread.fsr = (task->thread.fsr & (~0xffff0000))
2427 | (((int)num) << 16);
2429 buf += 2;
2430 start += 2;
2432 /* skip fop element */
2433 if (start == OFFSET(fop)) {
2434 start += 2;
2435 buf += 2;
2437 while (start < end) {
2438 num32 = *((int *)buf);
2439 if (start == OFFSET(fip))
2440 task->thread.fir = (task->thread.fir & (~0xffffffff))
2441 | num32;
2442 else if (start == OFFSET(foo))
2443 task->thread.fdr = (task->thread.fdr & (~0xffffffff))
2444 | num32;
2445 else if (start == OFFSET(mxcsr)) {
2446 num64 = num32 & 0xff10;
2447 task->thread.fcr = (task->thread.fcr &
2448 (~0xff1000000000UL)) | (num64<<32);
2449 num64 = num32 & 0x3f;
2450 task->thread.fsr = (task->thread.fsr &
2451 (~0x3f00000000UL)) | (num64<<32);
2453 buf += 4;
2454 start += 4;
2458 static void do_fpxregs_get(struct unw_frame_info *info, void *arg)
2460 struct regset_getset *dst = arg;
2461 struct task_struct *task = dst->target;
2462 struct pt_regs *pt;
2463 char buf[128];
2464 int start, end, tos;
2466 if (dst->count == 0 || unw_unwind_to_user(info) < 0)
2467 return;
2468 if (dst->pos < OFFSET(st_space[0])) {
2469 end = min(dst->pos + dst->count, (unsigned int)32);
2470 getfpxreg(task, dst->pos, end, buf);
2471 dst->ret = user_regset_copyout(&dst->pos, &dst->count,
2472 &dst->u.get.kbuf, &dst->u.get.ubuf, buf,
2473 0, OFFSET(st_space[0]));
2474 if (dst->ret || dst->count == 0)
2475 return;
2477 if (dst->pos < OFFSET(xmm_space[0])) {
2478 pt = task_pt_regs(task);
2479 tos = (task->thread.fsr >> 11) & 7;
2480 end = min(dst->pos + dst->count,
2481 (unsigned int)OFFSET(xmm_space[0]));
2482 start = (dst->pos - OFFSET(st_space[0])) / 16;
2483 end = (end - OFFSET(st_space[0])) / 16;
2484 for (; start < end; start++)
2485 access_fpreg_ia32(start, buf + 16 * start, pt,
2486 info->sw, tos, 0);
2487 dst->ret = user_regset_copyout(&dst->pos, &dst->count,
2488 &dst->u.get.kbuf, &dst->u.get.ubuf,
2489 buf, OFFSET(st_space[0]), OFFSET(xmm_space[0]));
2490 if (dst->ret || dst->count == 0)
2491 return;
2493 if (dst->pos < OFFSET(padding[0]))
2494 dst->ret = user_regset_copyout(&dst->pos, &dst->count,
2495 &dst->u.get.kbuf, &dst->u.get.ubuf,
2496 &info->sw->f16, OFFSET(xmm_space[0]),
2497 OFFSET(padding[0]));
2500 static void do_fpxregs_set(struct unw_frame_info *info, void *arg)
2502 struct regset_getset *dst = arg;
2503 struct task_struct *task = dst->target;
2504 char buf[128];
2505 int start, end;
2507 if (dst->count == 0 || unw_unwind_to_user(info) < 0)
2508 return;
2510 if (dst->pos < OFFSET(st_space[0])) {
2511 start = dst->pos;
2512 dst->ret = user_regset_copyin(&dst->pos, &dst->count,
2513 &dst->u.set.kbuf, &dst->u.set.ubuf,
2514 buf, 0, OFFSET(st_space[0]));
2515 if (dst->ret)
2516 return;
2517 setfpxreg(task, start, dst->pos, buf);
2518 if (dst->count == 0)
2519 return;
2521 if (dst->pos < OFFSET(xmm_space[0])) {
2522 struct pt_regs *pt;
2523 int tos;
2524 pt = task_pt_regs(task);
2525 tos = (task->thread.fsr >> 11) & 7;
2526 start = (dst->pos - OFFSET(st_space[0])) / 16;
2527 dst->ret = user_regset_copyin(&dst->pos, &dst->count,
2528 &dst->u.set.kbuf, &dst->u.set.ubuf,
2529 buf, OFFSET(st_space[0]), OFFSET(xmm_space[0]));
2530 if (dst->ret)
2531 return;
2532 end = (dst->pos - OFFSET(st_space[0])) / 16;
2533 for (; start < end; start++)
2534 access_fpreg_ia32(start, buf + 16 * start, pt, info->sw,
2535 tos, 1);
2536 if (dst->count == 0)
2537 return;
2539 if (dst->pos < OFFSET(padding[0]))
2540 dst->ret = user_regset_copyin(&dst->pos, &dst->count,
2541 &dst->u.set.kbuf, &dst->u.set.ubuf,
2542 &info->sw->f16, OFFSET(xmm_space[0]),
2543 OFFSET(padding[0]));
2545 #undef OFFSET
2547 static int do_regset_call(void (*call)(struct unw_frame_info *, void *),
2548 struct task_struct *target,
2549 const struct user_regset *regset,
2550 unsigned int pos, unsigned int count,
2551 const void *kbuf, const void __user *ubuf)
2553 struct regset_getset info = { .target = target, .regset = regset,
2554 .pos = pos, .count = count,
2555 .u.set = { .kbuf = kbuf, .ubuf = ubuf },
2556 .ret = 0 };
2558 if (target == current)
2559 unw_init_running(call, &info);
2560 else {
2561 struct unw_frame_info ufi;
2562 memset(&ufi, 0, sizeof(ufi));
2563 unw_init_from_blocked_task(&ufi, target);
2564 (*call)(&ufi, &info);
2567 return info.ret;
2570 static int ia32_fpregs_get(struct task_struct *target,
2571 const struct user_regset *regset,
2572 unsigned int pos, unsigned int count,
2573 void *kbuf, void __user *ubuf)
2575 return do_regset_call(do_fpregs_get, target, regset, pos, count,
2576 kbuf, ubuf);
2579 static int ia32_fpregs_set(struct task_struct *target,
2580 const struct user_regset *regset,
2581 unsigned int pos, unsigned int count,
2582 const void *kbuf, const void __user *ubuf)
2584 return do_regset_call(do_fpregs_set, target, regset, pos, count,
2585 kbuf, ubuf);
2588 static int ia32_fpxregs_get(struct task_struct *target,
2589 const struct user_regset *regset,
2590 unsigned int pos, unsigned int count,
2591 void *kbuf, void __user *ubuf)
2593 return do_regset_call(do_fpxregs_get, target, regset, pos, count,
2594 kbuf, ubuf);
2597 static int ia32_fpxregs_set(struct task_struct *target,
2598 const struct user_regset *regset,
2599 unsigned int pos, unsigned int count,
2600 const void *kbuf, const void __user *ubuf)
2602 return do_regset_call(do_fpxregs_set, target, regset, pos, count,
2603 kbuf, ubuf);
2606 static int ia32_genregs_get(struct task_struct *target,
2607 const struct user_regset *regset,
2608 unsigned int pos, unsigned int count,
2609 void *kbuf, void __user *ubuf)
2611 if (kbuf) {
2612 u32 *kp = kbuf;
2613 while (count > 0) {
2614 *kp++ = getreg(target, pos);
2615 pos += 4;
2616 count -= 4;
2618 } else {
2619 u32 __user *up = ubuf;
2620 while (count > 0) {
2621 if (__put_user(getreg(target, pos), up++))
2622 return -EFAULT;
2623 pos += 4;
2624 count -= 4;
2627 return 0;
2630 static int ia32_genregs_set(struct task_struct *target,
2631 const struct user_regset *regset,
2632 unsigned int pos, unsigned int count,
2633 const void *kbuf, const void __user *ubuf)
2635 int ret = 0;
2637 if (kbuf) {
2638 const u32 *kp = kbuf;
2639 while (!ret && count > 0) {
2640 putreg(target, pos, *kp++);
2641 pos += 4;
2642 count -= 4;
2644 } else {
2645 const u32 __user *up = ubuf;
2646 u32 val;
2647 while (!ret && count > 0) {
2648 ret = __get_user(val, up++);
2649 if (!ret)
2650 putreg(target, pos, val);
2651 pos += 4;
2652 count -= 4;
2655 return ret;
2658 static int ia32_tls_active(struct task_struct *target,
2659 const struct user_regset *regset)
2661 struct thread_struct *t = &target->thread;
2662 int n = GDT_ENTRY_TLS_ENTRIES;
2663 while (n > 0 && desc_empty(&t->tls_array[n -1]))
2664 --n;
2665 return n;
2668 static int ia32_tls_get(struct task_struct *target,
2669 const struct user_regset *regset, unsigned int pos,
2670 unsigned int count, void *kbuf, void __user *ubuf)
2672 const struct desc_struct *tls;
2674 if (pos > GDT_ENTRY_TLS_ENTRIES * sizeof(struct ia32_user_desc) ||
2675 (pos % sizeof(struct ia32_user_desc)) != 0 ||
2676 (count % sizeof(struct ia32_user_desc)) != 0)
2677 return -EINVAL;
2679 pos /= sizeof(struct ia32_user_desc);
2680 count /= sizeof(struct ia32_user_desc);
2682 tls = &target->thread.tls_array[pos];
2684 if (kbuf) {
2685 struct ia32_user_desc *info = kbuf;
2686 while (count-- > 0)
2687 fill_user_desc(info++, GDT_ENTRY_TLS_MIN + pos++,
2688 tls++);
2689 } else {
2690 struct ia32_user_desc __user *u_info = ubuf;
2691 while (count-- > 0) {
2692 struct ia32_user_desc info;
2693 fill_user_desc(&info, GDT_ENTRY_TLS_MIN + pos++, tls++);
2694 if (__copy_to_user(u_info++, &info, sizeof(info)))
2695 return -EFAULT;
2699 return 0;
2702 static int ia32_tls_set(struct task_struct *target,
2703 const struct user_regset *regset, unsigned int pos,
2704 unsigned int count, const void *kbuf, const void __user *ubuf)
2706 struct ia32_user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
2707 const struct ia32_user_desc *info;
2709 if (pos > GDT_ENTRY_TLS_ENTRIES * sizeof(struct ia32_user_desc) ||
2710 (pos % sizeof(struct ia32_user_desc)) != 0 ||
2711 (count % sizeof(struct ia32_user_desc)) != 0)
2712 return -EINVAL;
2714 if (kbuf)
2715 info = kbuf;
2716 else if (__copy_from_user(infobuf, ubuf, count))
2717 return -EFAULT;
2718 else
2719 info = infobuf;
2721 set_tls_desc(target,
2722 GDT_ENTRY_TLS_MIN + (pos / sizeof(struct ia32_user_desc)),
2723 info, count / sizeof(struct ia32_user_desc));
2725 return 0;
2729 * This should match arch/i386/kernel/ptrace.c:native_regsets.
2730 * XXX ioperm? vm86?
2732 static const struct user_regset ia32_regsets[] = {
2734 .core_note_type = NT_PRSTATUS,
2735 .n = sizeof(struct user_regs_struct32)/4,
2736 .size = 4, .align = 4,
2737 .get = ia32_genregs_get, .set = ia32_genregs_set
2740 .core_note_type = NT_PRFPREG,
2741 .n = sizeof(struct ia32_user_i387_struct) / 4,
2742 .size = 4, .align = 4,
2743 .get = ia32_fpregs_get, .set = ia32_fpregs_set
2746 .core_note_type = NT_PRXFPREG,
2747 .n = sizeof(struct ia32_user_fxsr_struct) / 4,
2748 .size = 4, .align = 4,
2749 .get = ia32_fpxregs_get, .set = ia32_fpxregs_set
2752 .core_note_type = NT_386_TLS,
2753 .n = GDT_ENTRY_TLS_ENTRIES,
2754 .bias = GDT_ENTRY_TLS_MIN,
2755 .size = sizeof(struct ia32_user_desc),
2756 .align = sizeof(struct ia32_user_desc),
2757 .active = ia32_tls_active,
2758 .get = ia32_tls_get, .set = ia32_tls_set,
2762 const struct user_regset_view user_ia32_view = {
2763 .name = "i386", .e_machine = EM_386,
2764 .regsets = ia32_regsets, .n = ARRAY_SIZE(ia32_regsets)
2767 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
2768 __u32 len_low, __u32 len_high, int advice)
2770 return sys_fadvise64_64(fd,
2771 (((u64)offset_high)<<32) | offset_low,
2772 (((u64)len_high)<<32) | len_low,
2773 advice);
2776 #ifdef NOTYET /* UNTESTED FOR IA64 FROM HERE DOWN */
2778 asmlinkage long sys32_setreuid(compat_uid_t ruid, compat_uid_t euid)
2780 uid_t sruid, seuid;
2782 sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid);
2783 seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid);
2784 return sys_setreuid(sruid, seuid);
2787 asmlinkage long
2788 sys32_setresuid(compat_uid_t ruid, compat_uid_t euid,
2789 compat_uid_t suid)
2791 uid_t sruid, seuid, ssuid;
2793 sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid);
2794 seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid);
2795 ssuid = (suid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)suid);
2796 return sys_setresuid(sruid, seuid, ssuid);
2799 asmlinkage long
2800 sys32_setregid(compat_gid_t rgid, compat_gid_t egid)
2802 gid_t srgid, segid;
2804 srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid);
2805 segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid);
2806 return sys_setregid(srgid, segid);
2809 asmlinkage long
2810 sys32_setresgid(compat_gid_t rgid, compat_gid_t egid,
2811 compat_gid_t sgid)
2813 gid_t srgid, segid, ssgid;
2815 srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid);
2816 segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid);
2817 ssgid = (sgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)sgid);
2818 return sys_setresgid(srgid, segid, ssgid);
2820 #endif /* NOTYET */