61bc3326e287be6545ec682537df8cd6e3c4d98b
[linux-flexiantxendom0-3.2.10.git] / arch / i386 / kernel / process.c
1 /*
2  *  linux/arch/i386/kernel/process.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *
6  *  Pentium III FXSR, SSE support
7  *      Gareth Hughes <gareth@valinux.com>, May 2000
8  */
9
10 /*
11  * This file handles the architecture-dependent parts of process handling..
12  */
13
14 #define __KERNEL_SYSCALLS__
15 #include <stdarg.h>
16
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/fs.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/elfcore.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/stddef.h>
26 #include <linux/unistd.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/user.h>
30 #include <linux/a.out.h>
31 #include <linux/interrupt.h>
32 #include <linux/config.h>
33 #include <linux/delay.h>
34 #include <linux/reboot.h>
35 #include <linux/init.h>
36 #include <linux/mc146818rtc.h>
37 #include <linux/module.h>
38 #include <linux/kallsyms.h>
39 #include <linux/ptrace.h>
40
41 #include <asm/uaccess.h>
42 #include <asm/pgtable.h>
43 #include <asm/system.h>
44 #include <asm/io.h>
45 #include <asm/ldt.h>
46 #include <asm/processor.h>
47 #include <asm/i387.h>
48 #include <asm/irq.h>
49 #include <asm/desc.h>
50 #ifdef CONFIG_MATH_EMULATION
51 #include <asm/math_emu.h>
52 #endif
53
54 #include <linux/irq.h>
55 #include <linux/err.h>
56
57 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
58
59 int hlt_counter;
60
61 /*
62  * Return saved PC of a blocked thread.
63  */
64 unsigned long thread_saved_pc(struct task_struct *tsk)
65 {
66         return ((unsigned long *)tsk->thread.esp)[3];
67 }
68
69 /*
70  * Powermanagement idle function, if any..
71  */
72 void (*pm_idle)(void);
73
74 void disable_hlt(void)
75 {
76         hlt_counter++;
77 }
78
79 void enable_hlt(void)
80 {
81         hlt_counter--;
82 }
83
84 /*
85  * We use this if we don't have any better
86  * idle routine..
87  */
88 void default_idle(void)
89 {
90         if (!hlt_counter && current_cpu_data.hlt_works_ok) {
91                 local_irq_disable();
92                 if (!need_resched())
93                         safe_halt();
94                 else
95                         local_irq_enable();
96         }
97 }
98
99 /*
100  * On SMP it's slightly faster (but much more power-consuming!)
101  * to poll the ->work.need_resched flag instead of waiting for the
102  * cross-CPU IPI to arrive. Use this option with caution.
103  */
104 static void poll_idle (void)
105 {
106         int oldval;
107
108         local_irq_enable();
109
110         /*
111          * Deal with another CPU just having chosen a thread to
112          * run here:
113          */
114         oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
115
116         if (!oldval) {
117                 set_thread_flag(TIF_POLLING_NRFLAG);
118                 asm volatile(
119                         "2:"
120                         "testl %0, %1;"
121                         "rep; nop;"
122                         "je 2b;"
123                         : : "i"(_TIF_NEED_RESCHED), "m" (current_thread_info()->flags));
124
125                 clear_thread_flag(TIF_POLLING_NRFLAG);
126         } else {
127                 set_need_resched();
128         }
129 }
130
131 /*
132  * The idle thread. There's no useful work to be
133  * done, so just try to conserve power and have a
134  * low exit latency (ie sit in a loop waiting for
135  * somebody to say that they'd like to reschedule)
136  */
137 void cpu_idle (void)
138 {
139         /* endless idle loop with no priority at all */
140         while (1) {
141                 void (*idle)(void) = pm_idle;
142                 if (!idle)
143                         idle = default_idle;
144                 irq_stat[smp_processor_id()].idle_timestamp = jiffies;
145                 while (!need_resched())
146                         idle();
147                 schedule();
148         }
149 }
150
151 static int __init idle_setup (char *str)
152 {
153         if (!strncmp(str, "poll", 4)) {
154                 printk("using polling idle threads.\n");
155                 pm_idle = poll_idle;
156         }
157
158         return 1;
159 }
160
161 __setup("idle=", idle_setup);
162
163 void show_regs(struct pt_regs * regs)
164 {
165         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
166
167         printk("\n");
168         printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
169         printk("EIP: %04x:[<%08lx>] CPU: %d\n",0xffff & regs->xcs,regs->eip, smp_processor_id());
170         print_symbol("EIP is at %s\n", regs->eip);
171
172         if (regs->xcs & 3)
173                 printk(" ESP: %04x:%08lx",0xffff & regs->xss,regs->esp);
174         printk(" EFLAGS: %08lx    %s\n",regs->eflags, print_tainted());
175         printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
176                 regs->eax,regs->ebx,regs->ecx,regs->edx);
177         printk("ESI: %08lx EDI: %08lx EBP: %08lx",
178                 regs->esi, regs->edi, regs->ebp);
179         printk(" DS: %04x ES: %04x\n",
180                 0xffff & regs->xds,0xffff & regs->xes);
181
182         __asm__("movl %%cr0, %0": "=r" (cr0));
183         __asm__("movl %%cr2, %0": "=r" (cr2));
184         __asm__("movl %%cr3, %0": "=r" (cr3));
185         /* This could fault if %cr4 does not exist */
186         __asm__("1: movl %%cr4, %0              \n"
187                 "2:                             \n"
188                 ".section __ex_table,\"a\"      \n"
189                 ".long 1b,2b                    \n"
190                 ".previous                      \n"
191                 : "=r" (cr4): "0" (0));
192         printk("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n", cr0, cr2, cr3, cr4);
193         show_trace(NULL, &regs->esp);
194 }
195
196 /*
197  * This gets run with %ebx containing the
198  * function to call, and %edx containing
199  * the "args".
200  */
201 extern void kernel_thread_helper(void);
202 __asm__(".align 4\n"
203         "kernel_thread_helper:\n\t"
204         "movl %edx,%eax\n\t"
205         "pushl %edx\n\t"
206         "call *%ebx\n\t"
207         "pushl %eax\n\t"
208         "call do_exit");
209
210 /*
211  * Create a kernel thread
212  */
213 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
214 {
215         struct pt_regs regs;
216
217         memset(&regs, 0, sizeof(regs));
218
219         regs.ebx = (unsigned long) fn;
220         regs.edx = (unsigned long) arg;
221
222         regs.xds = __USER_DS;
223         regs.xes = __USER_DS;
224         regs.orig_eax = -1;
225         regs.eip = (unsigned long) kernel_thread_helper;
226         regs.xcs = __KERNEL_CS;
227         regs.eflags = 0x286;
228
229         /* Ok, create the new process.. */
230         return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
231 }
232
233 /*
234  * Free current thread data structures etc..
235  */
236 void exit_thread(void)
237 {
238         struct task_struct *tsk = current;
239
240         /* The process may have allocated an io port bitmap... nuke it. */
241         if (unlikely(NULL != tsk->thread.ts_io_bitmap)) {
242                 kfree(tsk->thread.ts_io_bitmap);
243                 tsk->thread.ts_io_bitmap = NULL;
244         }
245 }
246
247 void flush_thread(void)
248 {
249         struct task_struct *tsk = current;
250
251         memset(tsk->thread.debugreg, 0, sizeof(unsigned long)*8);
252         memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));        
253         /*
254          * Forget coprocessor state..
255          */
256         clear_fpu(tsk);
257         tsk->used_math = 0;
258 }
259
260 void release_thread(struct task_struct *dead_task)
261 {
262         if (dead_task->mm) {
263                 // temporary debugging check
264                 if (dead_task->mm->context.size) {
265                         printk("WARNING: dead process %8s still has LDT? <%p/%d>\n",
266                                         dead_task->comm,
267                                         dead_task->mm->context.ldt,
268                                         dead_task->mm->context.size);
269                         BUG();
270                 }
271         }
272
273         release_x86_irqs(dead_task);
274 }
275
276 /*
277  * This gets called before we allocate a new thread and copy
278  * the current task into it.
279  */
280 void prepare_to_copy(struct task_struct *tsk)
281 {
282         unlazy_fpu(tsk);
283 }
284
285 int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
286         unsigned long unused,
287         struct task_struct * p, struct pt_regs * regs)
288 {
289         struct pt_regs * childregs;
290         struct task_struct *tsk;
291         int err;
292
293         childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
294         struct_cpy(childregs, regs);
295         childregs->eax = 0;
296         childregs->esp = esp;
297         p->set_child_tid = p->clear_child_tid = NULL;
298
299         p->thread.esp = (unsigned long) childregs;
300         p->thread.esp0 = (unsigned long) (childregs+1);
301
302         p->thread.eip = (unsigned long) ret_from_fork;
303
304         savesegment(fs,p->thread.fs);
305         savesegment(gs,p->thread.gs);
306
307         tsk = current;
308         if (unlikely(NULL != tsk->thread.ts_io_bitmap)) {
309                 p->thread.ts_io_bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
310                 if (!p->thread.ts_io_bitmap)
311                         return -ENOMEM;
312                 memcpy(p->thread.ts_io_bitmap, tsk->thread.ts_io_bitmap,
313                         IO_BITMAP_BYTES);
314         }
315
316         /*
317          * Set a new TLS for the child thread?
318          */
319         if (clone_flags & CLONE_SETTLS) {
320                 struct desc_struct *desc;
321                 struct user_desc info;
322                 int idx;
323
324                 err = -EFAULT;
325                 if (copy_from_user(&info, (void __user *)childregs->esi, sizeof(info)))
326                         goto out;
327                 err = -EINVAL;
328                 if (LDT_empty(&info))
329                         goto out;
330
331                 idx = info.entry_number;
332                 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
333                         goto out;
334
335                 desc = p->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
336                 desc->a = LDT_entry_a(&info);
337                 desc->b = LDT_entry_b(&info);
338         }
339
340         err = 0;
341  out:
342         if (err && p->thread.ts_io_bitmap)
343                 kfree(p->thread.ts_io_bitmap);
344         return err;
345 }
346
347 /*
348  * fill in the user structure for a core dump..
349  */
350 void dump_thread(struct pt_regs * regs, struct user * dump)
351 {
352         int i;
353
354 /* changed the size calculations - should hopefully work better. lbt */
355         dump->magic = CMAGIC;
356         dump->start_code = 0;
357         dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
358         dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
359         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
360         dump->u_dsize -= dump->u_tsize;
361         dump->u_ssize = 0;
362         for (i = 0; i < 8; i++)
363                 dump->u_debugreg[i] = current->thread.debugreg[i];  
364
365         if (dump->start_stack < TASK_SIZE)
366                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
367
368         dump->regs.ebx = regs->ebx;
369         dump->regs.ecx = regs->ecx;
370         dump->regs.edx = regs->edx;
371         dump->regs.esi = regs->esi;
372         dump->regs.edi = regs->edi;
373         dump->regs.ebp = regs->ebp;
374         dump->regs.eax = regs->eax;
375         dump->regs.ds = regs->xds;
376         dump->regs.es = regs->xes;
377         savesegment(fs,dump->regs.fs);
378         savesegment(gs,dump->regs.gs);
379         dump->regs.orig_eax = regs->orig_eax;
380         dump->regs.eip = regs->eip;
381         dump->regs.cs = regs->xcs;
382         dump->regs.eflags = regs->eflags;
383         dump->regs.esp = regs->esp;
384         dump->regs.ss = regs->xss;
385
386         dump->u_fpvalid = dump_fpu (regs, &dump->i387);
387 }
388
389 /* 
390  * Capture the user space registers if the task is not running (in user space)
391  */
392 int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
393 {
394         struct pt_regs ptregs;
395         
396         ptregs = *(struct pt_regs *)
397                 ((unsigned long)tsk->thread_info+THREAD_SIZE - sizeof(ptregs));
398         ptregs.xcs &= 0xffff;
399         ptregs.xds &= 0xffff;
400         ptregs.xes &= 0xffff;
401         ptregs.xss &= 0xffff;
402
403         elf_core_copy_regs(regs, &ptregs);
404
405         return 1;
406 }
407
408 /*
409  * This special macro can be used to load a debugging register
410  */
411 #define loaddebug(thread,register) \
412                 __asm__("movl %0,%%db" #register  \
413                         : /* no output */ \
414                         :"r" (thread->debugreg[register]))
415
416 /*
417  *      switch_to(x,yn) should switch tasks from x to y.
418  *
419  * We fsave/fwait so that an exception goes off at the right time
420  * (as a call from the fsave or fwait in effect) rather than to
421  * the wrong process. Lazy FP saving no longer makes any sense
422  * with modern CPU's, and this simplifies a lot of things (SMP
423  * and UP become the same).
424  *
425  * NOTE! We used to use the x86 hardware context switching. The
426  * reason for not using it any more becomes apparent when you
427  * try to recover gracefully from saved state that is no longer
428  * valid (stale segment register values in particular). With the
429  * hardware task-switch, there is no way to fix up bad state in
430  * a reasonable manner.
431  *
432  * The fact that Intel documents the hardware task-switching to
433  * be slow is a fairly red herring - this code is not noticeably
434  * faster. However, there _is_ some room for improvement here,
435  * so the performance issues may eventually be a valid point.
436  * More important, however, is the fact that this allows us much
437  * more flexibility.
438  *
439  * The return value (in %eax) will be the "prev" task after
440  * the task-switch, and shows up in ret_from_fork in entry.S,
441  * for example.
442  */
443 struct task_struct * __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
444 {
445         struct thread_struct *prev = &prev_p->thread,
446                                  *next = &next_p->thread;
447         int cpu = smp_processor_id();
448         struct tss_struct *tss = init_tss + cpu;
449
450         /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
451
452         unlazy_fpu(prev_p);
453
454         /*
455          * Reload esp0, LDT and the page table pointer:
456          */
457         load_esp0(tss, next->esp0);
458
459         /*
460          * Load the per-thread Thread-Local Storage descriptor.
461          */
462         load_TLS(next, cpu);
463
464         /*
465          * Save away %fs and %gs. No need to save %es and %ds, as
466          * those are always kernel segments while inside the kernel.
467          */
468         asm volatile("movl %%fs,%0":"=m" (*(int *)&prev->fs));
469         asm volatile("movl %%gs,%0":"=m" (*(int *)&prev->gs));
470
471         /*
472          * Restore %fs and %gs if needed.
473          */
474         if (unlikely(prev->fs | prev->gs | next->fs | next->gs)) {
475                 loadsegment(fs, next->fs);
476                 loadsegment(gs, next->gs);
477         }
478
479         /*
480          * Now maybe reload the debug registers
481          */
482         if (unlikely(next->debugreg[7])) {
483                 loaddebug(next, 0);
484                 loaddebug(next, 1);
485                 loaddebug(next, 2);
486                 loaddebug(next, 3);
487                 /* no 4 and 5 */
488                 loaddebug(next, 6);
489                 loaddebug(next, 7);
490         }
491
492         if (unlikely(prev->ts_io_bitmap || next->ts_io_bitmap)) {
493                 if (next->ts_io_bitmap) {
494                         /*
495                          * 4 cachelines copy ... not good, but not that
496                          * bad either. Anyone got something better?
497                          * This only affects processes which use ioperm().
498                          * [Putting the TSSs into 4k-tlb mapped regions
499                          * and playing VM tricks to switch the IO bitmap
500                          * is not really acceptable.]
501                          */
502                         memcpy(tss->io_bitmap, next->ts_io_bitmap,
503                                 IO_BITMAP_BYTES);
504                         tss->bitmap = IO_BITMAP_OFFSET;
505                 } else
506                         /*
507                          * a bitmap offset pointing outside of the TSS limit
508                          * causes a nicely controllable SIGSEGV if a process
509                          * tries to use a port IO instruction. The first
510                          * sys_ioperm() call sets up the bitmap properly.
511                          */
512                         tss->bitmap = INVALID_IO_BITMAP_OFFSET;
513         }
514         return prev_p;
515 }
516
517 asmlinkage int sys_fork(struct pt_regs regs)
518 {
519         return do_fork(SIGCHLD, regs.esp, &regs, 0, NULL, NULL);
520 }
521
522 asmlinkage int sys_clone(struct pt_regs regs)
523 {
524         unsigned long clone_flags;
525         unsigned long newsp;
526         int __user *parent_tidptr, *child_tidptr;
527
528         clone_flags = regs.ebx;
529         newsp = regs.ecx;
530         parent_tidptr = (int __user *)regs.edx;
531         child_tidptr = (int __user *)regs.edi;
532         if (!newsp)
533                 newsp = regs.esp;
534         return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, parent_tidptr, child_tidptr);
535 }
536
537 /*
538  * This is trivial, and on the face of it looks like it
539  * could equally well be done in user mode.
540  *
541  * Not so, for quite unobvious reasons - register pressure.
542  * In user mode vfork() cannot have a stack frame, and if
543  * done by calling the "clone()" system call directly, you
544  * do not have enough call-clobbered registers to hold all
545  * the information you need.
546  */
547 asmlinkage int sys_vfork(struct pt_regs regs)
548 {
549         return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0, NULL, NULL);
550 }
551
552 /*
553  * sys_execve() executes a new program.
554  */
555 asmlinkage int sys_execve(struct pt_regs regs)
556 {
557         int error;
558         char * filename;
559
560         filename = getname((char __user *) regs.ebx);
561         error = PTR_ERR(filename);
562         if (IS_ERR(filename))
563                 goto out;
564         error = do_execve(filename,
565                         (char __user * __user *) regs.ecx,
566                         (char __user * __user *) regs.edx,
567                         &regs);
568         if (error == 0) {
569                 current->ptrace &= ~PT_DTRACE;
570                 /* Make sure we don't return using sysenter.. */
571                 set_thread_flag(TIF_IRET);
572         }
573         putname(filename);
574 out:
575         return error;
576 }
577
578 /*
579  * These bracket the sleeping functions..
580  */
581 extern void scheduling_functions_start_here(void);
582 extern void scheduling_functions_end_here(void);
583 #define first_sched     ((unsigned long) scheduling_functions_start_here)
584 #define last_sched      ((unsigned long) scheduling_functions_end_here)
585
586 unsigned long get_wchan(struct task_struct *p)
587 {
588         unsigned long ebp, esp, eip;
589         unsigned long stack_page;
590         int count = 0;
591         if (!p || p == current || p->state == TASK_RUNNING)
592                 return 0;
593         stack_page = (unsigned long)p->thread_info;
594         esp = p->thread.esp;
595         if (!stack_page || esp < stack_page || esp > 8188+stack_page)
596                 return 0;
597         /* include/asm-i386/system.h:switch_to() pushes ebp last. */
598         ebp = *(unsigned long *) esp;
599         do {
600                 if (ebp < stack_page || ebp > 8184+stack_page)
601                         return 0;
602                 eip = *(unsigned long *) (ebp+4);
603                 if (eip < first_sched || eip >= last_sched)
604                         return eip;
605                 ebp = *(unsigned long *) ebp;
606         } while (count++ < 16);
607         return 0;
608 }
609 #undef last_sched
610 #undef first_sched
611
612 /*
613  * sys_alloc_thread_area: get a yet unused TLS descriptor index.
614  */
615 static int get_free_idx(void)
616 {
617         struct thread_struct *t = &current->thread;
618         int idx;
619
620         for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++)
621                 if (desc_empty(t->tls_array + idx))
622                         return idx + GDT_ENTRY_TLS_MIN;
623         return -ESRCH;
624 }
625
626 /*
627  * Set a given TLS descriptor:
628  */
629 asmlinkage int sys_set_thread_area(struct user_desc __user *u_info)
630 {
631         struct thread_struct *t = &current->thread;
632         struct user_desc info;
633         struct desc_struct *desc;
634         int cpu, idx;
635
636         if (copy_from_user(&info, u_info, sizeof(info)))
637                 return -EFAULT;
638         idx = info.entry_number;
639
640         /*
641          * index -1 means the kernel should try to find and
642          * allocate an empty descriptor:
643          */
644         if (idx == -1) {
645                 idx = get_free_idx();
646                 if (idx < 0)
647                         return idx;
648                 if (put_user(idx, &u_info->entry_number))
649                         return -EFAULT;
650         }
651
652         if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
653                 return -EINVAL;
654
655         desc = t->tls_array + idx - GDT_ENTRY_TLS_MIN;
656
657         /*
658          * We must not get preempted while modifying the TLS.
659          */
660         cpu = get_cpu();
661
662         if (LDT_empty(&info)) {
663                 desc->a = 0;
664                 desc->b = 0;
665         } else {
666                 desc->a = LDT_entry_a(&info);
667                 desc->b = LDT_entry_b(&info);
668         }
669         load_TLS(t, cpu);
670
671         put_cpu();
672
673         return 0;
674 }
675
676 /*
677  * Get the current Thread-Local Storage area:
678  */
679
680 #define GET_BASE(desc) ( \
681         (((desc)->a >> 16) & 0x0000ffff) | \
682         (((desc)->b << 16) & 0x00ff0000) | \
683         ( (desc)->b        & 0xff000000)   )
684
685 #define GET_LIMIT(desc) ( \
686         ((desc)->a & 0x0ffff) | \
687          ((desc)->b & 0xf0000) )
688         
689 #define GET_32BIT(desc)         (((desc)->b >> 23) & 1)
690 #define GET_CONTENTS(desc)      (((desc)->b >> 10) & 3)
691 #define GET_WRITABLE(desc)      (((desc)->b >>  9) & 1)
692 #define GET_LIMIT_PAGES(desc)   (((desc)->b >> 23) & 1)
693 #define GET_PRESENT(desc)       (((desc)->b >> 15) & 1)
694 #define GET_USEABLE(desc)       (((desc)->b >> 20) & 1)
695
696 asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
697 {
698         struct user_desc info;
699         struct desc_struct *desc;
700         int idx;
701
702         if (get_user(idx, &u_info->entry_number))
703                 return -EFAULT;
704         if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
705                 return -EINVAL;
706
707         desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
708
709         info.entry_number = idx;
710         info.base_addr = GET_BASE(desc);
711         info.limit = GET_LIMIT(desc);
712         info.seg_32bit = GET_32BIT(desc);
713         info.contents = GET_CONTENTS(desc);
714         info.read_exec_only = !GET_WRITABLE(desc);
715         info.limit_in_pages = GET_LIMIT_PAGES(desc);
716         info.seg_not_present = !GET_PRESENT(desc);
717         info.useable = GET_USEABLE(desc);
718
719         if (copy_to_user(u_info, &info, sizeof(info)))
720                 return -EFAULT;
721         return 0;
722 }
723