coredump: remove VM_ALWAYSDUMP flag
[pandora-kernel.git] / arch / powerpc / kernel / vdso.c
1
2 /*
3  *    Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
4  *                       <benh@kernel.crashing.org>
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version
9  *  2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/smp.h>
17 #include <linux/stddef.h>
18 #include <linux/unistd.h>
19 #include <linux/slab.h>
20 #include <linux/user.h>
21 #include <linux/elf.h>
22 #include <linux/security.h>
23 #include <linux/bootmem.h>
24 #include <linux/memblock.h>
25
26 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/processor.h>
29 #include <asm/mmu.h>
30 #include <asm/mmu_context.h>
31 #include <asm/prom.h>
32 #include <asm/machdep.h>
33 #include <asm/cputable.h>
34 #include <asm/sections.h>
35 #include <asm/firmware.h>
36 #include <asm/vdso.h>
37 #include <asm/vdso_datapage.h>
38
39 #include "setup.h"
40
41 #undef DEBUG
42
43 #ifdef DEBUG
44 #define DBG(fmt...) printk(fmt)
45 #else
46 #define DBG(fmt...)
47 #endif
48
49 /* Max supported size for symbol names */
50 #define MAX_SYMNAME     64
51
52 /* The alignment of the vDSO */
53 #define VDSO_ALIGNMENT  (1 << 16)
54
55 extern char vdso32_start, vdso32_end;
56 static void *vdso32_kbase = &vdso32_start;
57 static unsigned int vdso32_pages;
58 static struct page **vdso32_pagelist;
59 unsigned long vdso32_sigtramp;
60 unsigned long vdso32_rt_sigtramp;
61
62 #ifdef CONFIG_PPC64
63 extern char vdso64_start, vdso64_end;
64 static void *vdso64_kbase = &vdso64_start;
65 static unsigned int vdso64_pages;
66 static struct page **vdso64_pagelist;
67 unsigned long vdso64_rt_sigtramp;
68 #endif /* CONFIG_PPC64 */
69
70 static int vdso_ready;
71
72 /*
73  * The vdso data page (aka. systemcfg for old ppc64 fans) is here.
74  * Once the early boot kernel code no longer needs to muck around
75  * with it, it will become dynamically allocated
76  */
77 static union {
78         struct vdso_data        data;
79         u8                      page[PAGE_SIZE];
80 } vdso_data_store __page_aligned_data;
81 struct vdso_data *vdso_data = &vdso_data_store.data;
82
83 /* Format of the patch table */
84 struct vdso_patch_def
85 {
86         unsigned long   ftr_mask, ftr_value;
87         const char      *gen_name;
88         const char      *fix_name;
89 };
90
91 /* Table of functions to patch based on the CPU type/revision
92  *
93  * Currently, we only change sync_dicache to do nothing on processors
94  * with a coherent icache
95  */
96 static struct vdso_patch_def vdso_patches[] = {
97         {
98                 CPU_FTR_COHERENT_ICACHE, CPU_FTR_COHERENT_ICACHE,
99                 "__kernel_sync_dicache", "__kernel_sync_dicache_p5"
100         },
101         {
102                 CPU_FTR_USE_TB, 0,
103                 "__kernel_gettimeofday", NULL
104         },
105         {
106                 CPU_FTR_USE_TB, 0,
107                 "__kernel_clock_gettime", NULL
108         },
109         {
110                 CPU_FTR_USE_TB, 0,
111                 "__kernel_clock_getres", NULL
112         },
113         {
114                 CPU_FTR_USE_TB, 0,
115                 "__kernel_get_tbfreq", NULL
116         },
117 };
118
119 /*
120  * Some infos carried around for each of them during parsing at
121  * boot time.
122  */
123 struct lib32_elfinfo
124 {
125         Elf32_Ehdr      *hdr;           /* ptr to ELF */
126         Elf32_Sym       *dynsym;        /* ptr to .dynsym section */
127         unsigned long   dynsymsize;     /* size of .dynsym section */
128         char            *dynstr;        /* ptr to .dynstr section */
129         unsigned long   text;           /* offset of .text section in .so */
130 };
131
132 struct lib64_elfinfo
133 {
134         Elf64_Ehdr      *hdr;
135         Elf64_Sym       *dynsym;
136         unsigned long   dynsymsize;
137         char            *dynstr;
138         unsigned long   text;
139 };
140
141
142 #ifdef __DEBUG
143 static void dump_one_vdso_page(struct page *pg, struct page *upg)
144 {
145         printk("kpg: %p (c:%d,f:%08lx)", __va(page_to_pfn(pg) << PAGE_SHIFT),
146                page_count(pg),
147                pg->flags);
148         if (upg && !IS_ERR(upg) /* && pg != upg*/) {
149                 printk(" upg: %p (c:%d,f:%08lx)", __va(page_to_pfn(upg)
150                                                        << PAGE_SHIFT),
151                        page_count(upg),
152                        upg->flags);
153         }
154         printk("\n");
155 }
156
157 static void dump_vdso_pages(struct vm_area_struct * vma)
158 {
159         int i;
160
161         if (!vma || is_32bit_task()) {
162                 printk("vDSO32 @ %016lx:\n", (unsigned long)vdso32_kbase);
163                 for (i=0; i<vdso32_pages; i++) {
164                         struct page *pg = virt_to_page(vdso32_kbase +
165                                                        i*PAGE_SIZE);
166                         struct page *upg = (vma && vma->vm_mm) ?
167                                 follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
168                                 : NULL;
169                         dump_one_vdso_page(pg, upg);
170                 }
171         }
172         if (!vma || !is_32bit_task()) {
173                 printk("vDSO64 @ %016lx:\n", (unsigned long)vdso64_kbase);
174                 for (i=0; i<vdso64_pages; i++) {
175                         struct page *pg = virt_to_page(vdso64_kbase +
176                                                        i*PAGE_SIZE);
177                         struct page *upg = (vma && vma->vm_mm) ?
178                                 follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
179                                 : NULL;
180                         dump_one_vdso_page(pg, upg);
181                 }
182         }
183 }
184 #endif /* DEBUG */
185
186 /*
187  * This is called from binfmt_elf, we create the special vma for the
188  * vDSO and insert it into the mm struct tree
189  */
190 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
191 {
192         struct mm_struct *mm = current->mm;
193         struct page **vdso_pagelist;
194         unsigned long vdso_pages;
195         unsigned long vdso_base;
196         int rc;
197
198         if (!vdso_ready)
199                 return 0;
200
201 #ifdef CONFIG_PPC64
202         if (is_32bit_task()) {
203                 vdso_pagelist = vdso32_pagelist;
204                 vdso_pages = vdso32_pages;
205                 vdso_base = VDSO32_MBASE;
206         } else {
207                 vdso_pagelist = vdso64_pagelist;
208                 vdso_pages = vdso64_pages;
209                 /*
210                  * On 64bit we don't have a preferred map address. This
211                  * allows get_unmapped_area to find an area near other mmaps
212                  * and most likely share a SLB entry.
213                  */
214                 vdso_base = 0;
215         }
216 #else
217         vdso_pagelist = vdso32_pagelist;
218         vdso_pages = vdso32_pages;
219         vdso_base = VDSO32_MBASE;
220 #endif
221
222         current->mm->context.vdso_base = 0;
223
224         /* vDSO has a problem and was disabled, just don't "enable" it for the
225          * process
226          */
227         if (vdso_pages == 0)
228                 return 0;
229         /* Add a page to the vdso size for the data page */
230         vdso_pages ++;
231
232         /*
233          * pick a base address for the vDSO in process space. We try to put it
234          * at vdso_base which is the "natural" base for it, but we might fail
235          * and end up putting it elsewhere.
236          * Add enough to the size so that the result can be aligned.
237          */
238         down_write(&mm->mmap_sem);
239         vdso_base = get_unmapped_area(NULL, vdso_base,
240                                       (vdso_pages << PAGE_SHIFT) +
241                                       ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
242                                       0, 0);
243         if (IS_ERR_VALUE(vdso_base)) {
244                 rc = vdso_base;
245                 goto fail_mmapsem;
246         }
247
248         /* Add required alignment. */
249         vdso_base = ALIGN(vdso_base, VDSO_ALIGNMENT);
250
251         /*
252          * Put vDSO base into mm struct. We need to do this before calling
253          * install_special_mapping or the perf counter mmap tracking code
254          * will fail to recognise it as a vDSO (since arch_vma_name fails).
255          */
256         current->mm->context.vdso_base = vdso_base;
257
258         /*
259          * our vma flags don't have VM_WRITE so by default, the process isn't
260          * allowed to write those pages.
261          * gdb can break that with ptrace interface, and thus trigger COW on
262          * those pages but it's then your responsibility to never do that on
263          * the "data" page of the vDSO or you'll stop getting kernel updates
264          * and your nice userland gettimeofday will be totally dead.
265          * It's fine to use that for setting breakpoints in the vDSO code
266          * pages though.
267          */
268         rc = install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
269                                      VM_READ|VM_EXEC|
270                                      VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
271                                      vdso_pagelist);
272         if (rc) {
273                 current->mm->context.vdso_base = 0;
274                 goto fail_mmapsem;
275         }
276
277         up_write(&mm->mmap_sem);
278         return 0;
279
280  fail_mmapsem:
281         up_write(&mm->mmap_sem);
282         return rc;
283 }
284
285 const char *arch_vma_name(struct vm_area_struct *vma)
286 {
287         if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso_base)
288                 return "[vdso]";
289         return NULL;
290 }
291
292
293
294 static void * __init find_section32(Elf32_Ehdr *ehdr, const char *secname,
295                                   unsigned long *size)
296 {
297         Elf32_Shdr *sechdrs;
298         unsigned int i;
299         char *secnames;
300
301         /* Grab section headers and strings so we can tell who is who */
302         sechdrs = (void *)ehdr + ehdr->e_shoff;
303         secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
304
305         /* Find the section they want */
306         for (i = 1; i < ehdr->e_shnum; i++) {
307                 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
308                         if (size)
309                                 *size = sechdrs[i].sh_size;
310                         return (void *)ehdr + sechdrs[i].sh_offset;
311                 }
312         }
313         *size = 0;
314         return NULL;
315 }
316
317 static Elf32_Sym * __init find_symbol32(struct lib32_elfinfo *lib,
318                                         const char *symname)
319 {
320         unsigned int i;
321         char name[MAX_SYMNAME], *c;
322
323         for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
324                 if (lib->dynsym[i].st_name == 0)
325                         continue;
326                 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
327                         MAX_SYMNAME);
328                 c = strchr(name, '@');
329                 if (c)
330                         *c = 0;
331                 if (strcmp(symname, name) == 0)
332                         return &lib->dynsym[i];
333         }
334         return NULL;
335 }
336
337 /* Note that we assume the section is .text and the symbol is relative to
338  * the library base
339  */
340 static unsigned long __init find_function32(struct lib32_elfinfo *lib,
341                                             const char *symname)
342 {
343         Elf32_Sym *sym = find_symbol32(lib, symname);
344
345         if (sym == NULL) {
346                 printk(KERN_WARNING "vDSO32: function %s not found !\n",
347                        symname);
348                 return 0;
349         }
350         return sym->st_value - VDSO32_LBASE;
351 }
352
353 static int __init vdso_do_func_patch32(struct lib32_elfinfo *v32,
354                                        struct lib64_elfinfo *v64,
355                                        const char *orig, const char *fix)
356 {
357         Elf32_Sym *sym32_gen, *sym32_fix;
358
359         sym32_gen = find_symbol32(v32, orig);
360         if (sym32_gen == NULL) {
361                 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", orig);
362                 return -1;
363         }
364         if (fix == NULL) {
365                 sym32_gen->st_name = 0;
366                 return 0;
367         }
368         sym32_fix = find_symbol32(v32, fix);
369         if (sym32_fix == NULL) {
370                 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", fix);
371                 return -1;
372         }
373         sym32_gen->st_value = sym32_fix->st_value;
374         sym32_gen->st_size = sym32_fix->st_size;
375         sym32_gen->st_info = sym32_fix->st_info;
376         sym32_gen->st_other = sym32_fix->st_other;
377         sym32_gen->st_shndx = sym32_fix->st_shndx;
378
379         return 0;
380 }
381
382
383 #ifdef CONFIG_PPC64
384
385 static void * __init find_section64(Elf64_Ehdr *ehdr, const char *secname,
386                                   unsigned long *size)
387 {
388         Elf64_Shdr *sechdrs;
389         unsigned int i;
390         char *secnames;
391
392         /* Grab section headers and strings so we can tell who is who */
393         sechdrs = (void *)ehdr + ehdr->e_shoff;
394         secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
395
396         /* Find the section they want */
397         for (i = 1; i < ehdr->e_shnum; i++) {
398                 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
399                         if (size)
400                                 *size = sechdrs[i].sh_size;
401                         return (void *)ehdr + sechdrs[i].sh_offset;
402                 }
403         }
404         if (size)
405                 *size = 0;
406         return NULL;
407 }
408
409 static Elf64_Sym * __init find_symbol64(struct lib64_elfinfo *lib,
410                                         const char *symname)
411 {
412         unsigned int i;
413         char name[MAX_SYMNAME], *c;
414
415         for (i = 0; i < (lib->dynsymsize / sizeof(Elf64_Sym)); i++) {
416                 if (lib->dynsym[i].st_name == 0)
417                         continue;
418                 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
419                         MAX_SYMNAME);
420                 c = strchr(name, '@');
421                 if (c)
422                         *c = 0;
423                 if (strcmp(symname, name) == 0)
424                         return &lib->dynsym[i];
425         }
426         return NULL;
427 }
428
429 /* Note that we assume the section is .text and the symbol is relative to
430  * the library base
431  */
432 static unsigned long __init find_function64(struct lib64_elfinfo *lib,
433                                             const char *symname)
434 {
435         Elf64_Sym *sym = find_symbol64(lib, symname);
436
437         if (sym == NULL) {
438                 printk(KERN_WARNING "vDSO64: function %s not found !\n",
439                        symname);
440                 return 0;
441         }
442 #ifdef VDS64_HAS_DESCRIPTORS
443         return *((u64 *)(vdso64_kbase + sym->st_value - VDSO64_LBASE)) -
444                 VDSO64_LBASE;
445 #else
446         return sym->st_value - VDSO64_LBASE;
447 #endif
448 }
449
450 static int __init vdso_do_func_patch64(struct lib32_elfinfo *v32,
451                                        struct lib64_elfinfo *v64,
452                                        const char *orig, const char *fix)
453 {
454         Elf64_Sym *sym64_gen, *sym64_fix;
455
456         sym64_gen = find_symbol64(v64, orig);
457         if (sym64_gen == NULL) {
458                 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", orig);
459                 return -1;
460         }
461         if (fix == NULL) {
462                 sym64_gen->st_name = 0;
463                 return 0;
464         }
465         sym64_fix = find_symbol64(v64, fix);
466         if (sym64_fix == NULL) {
467                 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", fix);
468                 return -1;
469         }
470         sym64_gen->st_value = sym64_fix->st_value;
471         sym64_gen->st_size = sym64_fix->st_size;
472         sym64_gen->st_info = sym64_fix->st_info;
473         sym64_gen->st_other = sym64_fix->st_other;
474         sym64_gen->st_shndx = sym64_fix->st_shndx;
475
476         return 0;
477 }
478
479 #endif /* CONFIG_PPC64 */
480
481
482 static __init int vdso_do_find_sections(struct lib32_elfinfo *v32,
483                                         struct lib64_elfinfo *v64)
484 {
485         void *sect;
486
487         /*
488          * Locate symbol tables & text section
489          */
490
491         v32->dynsym = find_section32(v32->hdr, ".dynsym", &v32->dynsymsize);
492         v32->dynstr = find_section32(v32->hdr, ".dynstr", NULL);
493         if (v32->dynsym == NULL || v32->dynstr == NULL) {
494                 printk(KERN_ERR "vDSO32: required symbol section not found\n");
495                 return -1;
496         }
497         sect = find_section32(v32->hdr, ".text", NULL);
498         if (sect == NULL) {
499                 printk(KERN_ERR "vDSO32: the .text section was not found\n");
500                 return -1;
501         }
502         v32->text = sect - vdso32_kbase;
503
504 #ifdef CONFIG_PPC64
505         v64->dynsym = find_section64(v64->hdr, ".dynsym", &v64->dynsymsize);
506         v64->dynstr = find_section64(v64->hdr, ".dynstr", NULL);
507         if (v64->dynsym == NULL || v64->dynstr == NULL) {
508                 printk(KERN_ERR "vDSO64: required symbol section not found\n");
509                 return -1;
510         }
511         sect = find_section64(v64->hdr, ".text", NULL);
512         if (sect == NULL) {
513                 printk(KERN_ERR "vDSO64: the .text section was not found\n");
514                 return -1;
515         }
516         v64->text = sect - vdso64_kbase;
517 #endif /* CONFIG_PPC64 */
518
519         return 0;
520 }
521
522 static __init void vdso_setup_trampolines(struct lib32_elfinfo *v32,
523                                           struct lib64_elfinfo *v64)
524 {
525         /*
526          * Find signal trampolines
527          */
528
529 #ifdef CONFIG_PPC64
530         vdso64_rt_sigtramp = find_function64(v64, "__kernel_sigtramp_rt64");
531 #endif
532         vdso32_sigtramp    = find_function32(v32, "__kernel_sigtramp32");
533         vdso32_rt_sigtramp = find_function32(v32, "__kernel_sigtramp_rt32");
534 }
535
536 static __init int vdso_fixup_datapage(struct lib32_elfinfo *v32,
537                                        struct lib64_elfinfo *v64)
538 {
539         Elf32_Sym *sym32;
540 #ifdef CONFIG_PPC64
541         Elf64_Sym *sym64;
542
543         sym64 = find_symbol64(v64, "__kernel_datapage_offset");
544         if (sym64 == NULL) {
545                 printk(KERN_ERR "vDSO64: Can't find symbol "
546                        "__kernel_datapage_offset !\n");
547                 return -1;
548         }
549         *((int *)(vdso64_kbase + sym64->st_value - VDSO64_LBASE)) =
550                 (vdso64_pages << PAGE_SHIFT) -
551                 (sym64->st_value - VDSO64_LBASE);
552 #endif /* CONFIG_PPC64 */
553
554         sym32 = find_symbol32(v32, "__kernel_datapage_offset");
555         if (sym32 == NULL) {
556                 printk(KERN_ERR "vDSO32: Can't find symbol "
557                        "__kernel_datapage_offset !\n");
558                 return -1;
559         }
560         *((int *)(vdso32_kbase + (sym32->st_value - VDSO32_LBASE))) =
561                 (vdso32_pages << PAGE_SHIFT) -
562                 (sym32->st_value - VDSO32_LBASE);
563
564         return 0;
565 }
566
567
568 static __init int vdso_fixup_features(struct lib32_elfinfo *v32,
569                                       struct lib64_elfinfo *v64)
570 {
571         void *start32;
572         unsigned long size32;
573
574 #ifdef CONFIG_PPC64
575         void *start64;
576         unsigned long size64;
577
578         start64 = find_section64(v64->hdr, "__ftr_fixup", &size64);
579         if (start64)
580                 do_feature_fixups(cur_cpu_spec->cpu_features,
581                                   start64, start64 + size64);
582
583         start64 = find_section64(v64->hdr, "__mmu_ftr_fixup", &size64);
584         if (start64)
585                 do_feature_fixups(cur_cpu_spec->mmu_features,
586                                   start64, start64 + size64);
587
588         start64 = find_section64(v64->hdr, "__fw_ftr_fixup", &size64);
589         if (start64)
590                 do_feature_fixups(powerpc_firmware_features,
591                                   start64, start64 + size64);
592
593         start64 = find_section64(v64->hdr, "__lwsync_fixup", &size64);
594         if (start64)
595                 do_lwsync_fixups(cur_cpu_spec->cpu_features,
596                                  start64, start64 + size64);
597 #endif /* CONFIG_PPC64 */
598
599         start32 = find_section32(v32->hdr, "__ftr_fixup", &size32);
600         if (start32)
601                 do_feature_fixups(cur_cpu_spec->cpu_features,
602                                   start32, start32 + size32);
603
604         start32 = find_section32(v32->hdr, "__mmu_ftr_fixup", &size32);
605         if (start32)
606                 do_feature_fixups(cur_cpu_spec->mmu_features,
607                                   start32, start32 + size32);
608
609 #ifdef CONFIG_PPC64
610         start32 = find_section32(v32->hdr, "__fw_ftr_fixup", &size32);
611         if (start32)
612                 do_feature_fixups(powerpc_firmware_features,
613                                   start32, start32 + size32);
614 #endif /* CONFIG_PPC64 */
615
616         start32 = find_section32(v32->hdr, "__lwsync_fixup", &size32);
617         if (start32)
618                 do_lwsync_fixups(cur_cpu_spec->cpu_features,
619                                  start32, start32 + size32);
620
621         return 0;
622 }
623
624 static __init int vdso_fixup_alt_funcs(struct lib32_elfinfo *v32,
625                                        struct lib64_elfinfo *v64)
626 {
627         int i;
628
629         for (i = 0; i < ARRAY_SIZE(vdso_patches); i++) {
630                 struct vdso_patch_def *patch = &vdso_patches[i];
631                 int match = (cur_cpu_spec->cpu_features & patch->ftr_mask)
632                         == patch->ftr_value;
633                 if (!match)
634                         continue;
635
636                 DBG("replacing %s with %s...\n", patch->gen_name,
637                     patch->fix_name ? "NONE" : patch->fix_name);
638
639                 /*
640                  * Patch the 32 bits and 64 bits symbols. Note that we do not
641                  * patch the "." symbol on 64 bits.
642                  * It would be easy to do, but doesn't seem to be necessary,
643                  * patching the OPD symbol is enough.
644                  */
645                 vdso_do_func_patch32(v32, v64, patch->gen_name,
646                                      patch->fix_name);
647 #ifdef CONFIG_PPC64
648                 vdso_do_func_patch64(v32, v64, patch->gen_name,
649                                      patch->fix_name);
650 #endif /* CONFIG_PPC64 */
651         }
652
653         return 0;
654 }
655
656
657 static __init int vdso_setup(void)
658 {
659         struct lib32_elfinfo    v32;
660         struct lib64_elfinfo    v64;
661
662         v32.hdr = vdso32_kbase;
663 #ifdef CONFIG_PPC64
664         v64.hdr = vdso64_kbase;
665 #endif
666         if (vdso_do_find_sections(&v32, &v64))
667                 return -1;
668
669         if (vdso_fixup_datapage(&v32, &v64))
670                 return -1;
671
672         if (vdso_fixup_features(&v32, &v64))
673                 return -1;
674
675         if (vdso_fixup_alt_funcs(&v32, &v64))
676                 return -1;
677
678         vdso_setup_trampolines(&v32, &v64);
679
680         return 0;
681 }
682
683 /*
684  * Called from setup_arch to initialize the bitmap of available
685  * syscalls in the systemcfg page
686  */
687 static void __init vdso_setup_syscall_map(void)
688 {
689         unsigned int i;
690         extern unsigned long *sys_call_table;
691         extern unsigned long sys_ni_syscall;
692
693
694         for (i = 0; i < __NR_syscalls; i++) {
695 #ifdef CONFIG_PPC64
696                 if (sys_call_table[i*2] != sys_ni_syscall)
697                         vdso_data->syscall_map_64[i >> 5] |=
698                                 0x80000000UL >> (i & 0x1f);
699                 if (sys_call_table[i*2+1] != sys_ni_syscall)
700                         vdso_data->syscall_map_32[i >> 5] |=
701                                 0x80000000UL >> (i & 0x1f);
702 #else /* CONFIG_PPC64 */
703                 if (sys_call_table[i] != sys_ni_syscall)
704                         vdso_data->syscall_map_32[i >> 5] |=
705                                 0x80000000UL >> (i & 0x1f);
706 #endif /* CONFIG_PPC64 */
707         }
708 }
709
710
711 static int __init vdso_init(void)
712 {
713         int i;
714
715 #ifdef CONFIG_PPC64
716         /*
717          * Fill up the "systemcfg" stuff for backward compatibility
718          */
719         strcpy((char *)vdso_data->eye_catcher, "SYSTEMCFG:PPC64");
720         vdso_data->version.major = SYSTEMCFG_MAJOR;
721         vdso_data->version.minor = SYSTEMCFG_MINOR;
722         vdso_data->processor = mfspr(SPRN_PVR);
723         /*
724          * Fake the old platform number for pSeries and iSeries and add
725          * in LPAR bit if necessary
726          */
727         vdso_data->platform = machine_is(iseries) ? 0x200 : 0x100;
728         if (firmware_has_feature(FW_FEATURE_LPAR))
729                 vdso_data->platform |= 1;
730         vdso_data->physicalMemorySize = memblock_phys_mem_size();
731         vdso_data->dcache_size = ppc64_caches.dsize;
732         vdso_data->dcache_line_size = ppc64_caches.dline_size;
733         vdso_data->icache_size = ppc64_caches.isize;
734         vdso_data->icache_line_size = ppc64_caches.iline_size;
735
736         /* XXXOJN: Blocks should be added to ppc64_caches and used instead */
737         vdso_data->dcache_block_size = ppc64_caches.dline_size;
738         vdso_data->icache_block_size = ppc64_caches.iline_size;
739         vdso_data->dcache_log_block_size = ppc64_caches.log_dline_size;
740         vdso_data->icache_log_block_size = ppc64_caches.log_iline_size;
741
742         /*
743          * Calculate the size of the 64 bits vDSO
744          */
745         vdso64_pages = (&vdso64_end - &vdso64_start) >> PAGE_SHIFT;
746         DBG("vdso64_kbase: %p, 0x%x pages\n", vdso64_kbase, vdso64_pages);
747 #else
748         vdso_data->dcache_block_size = L1_CACHE_BYTES;
749         vdso_data->dcache_log_block_size = L1_CACHE_SHIFT;
750         vdso_data->icache_block_size = L1_CACHE_BYTES;
751         vdso_data->icache_log_block_size = L1_CACHE_SHIFT;
752 #endif /* CONFIG_PPC64 */
753
754
755         /*
756          * Calculate the size of the 32 bits vDSO
757          */
758         vdso32_pages = (&vdso32_end - &vdso32_start) >> PAGE_SHIFT;
759         DBG("vdso32_kbase: %p, 0x%x pages\n", vdso32_kbase, vdso32_pages);
760
761
762         /*
763          * Setup the syscall map in the vDOS
764          */
765         vdso_setup_syscall_map();
766
767         /*
768          * Initialize the vDSO images in memory, that is do necessary
769          * fixups of vDSO symbols, locate trampolines, etc...
770          */
771         if (vdso_setup()) {
772                 printk(KERN_ERR "vDSO setup failure, not enabled !\n");
773                 vdso32_pages = 0;
774 #ifdef CONFIG_PPC64
775                 vdso64_pages = 0;
776 #endif
777                 return 0;
778         }
779
780         /* Make sure pages are in the correct state */
781         vdso32_pagelist = kzalloc(sizeof(struct page *) * (vdso32_pages + 2),
782                                   GFP_KERNEL);
783         BUG_ON(vdso32_pagelist == NULL);
784         for (i = 0; i < vdso32_pages; i++) {
785                 struct page *pg = virt_to_page(vdso32_kbase + i*PAGE_SIZE);
786                 ClearPageReserved(pg);
787                 get_page(pg);
788                 vdso32_pagelist[i] = pg;
789         }
790         vdso32_pagelist[i++] = virt_to_page(vdso_data);
791         vdso32_pagelist[i] = NULL;
792
793 #ifdef CONFIG_PPC64
794         vdso64_pagelist = kzalloc(sizeof(struct page *) * (vdso64_pages + 2),
795                                   GFP_KERNEL);
796         BUG_ON(vdso64_pagelist == NULL);
797         for (i = 0; i < vdso64_pages; i++) {
798                 struct page *pg = virt_to_page(vdso64_kbase + i*PAGE_SIZE);
799                 ClearPageReserved(pg);
800                 get_page(pg);
801                 vdso64_pagelist[i] = pg;
802         }
803         vdso64_pagelist[i++] = virt_to_page(vdso_data);
804         vdso64_pagelist[i] = NULL;
805 #endif /* CONFIG_PPC64 */
806
807         get_page(virt_to_page(vdso_data));
808
809         smp_wmb();
810         vdso_ready = 1;
811
812         return 0;
813 }
814 arch_initcall(vdso_init);
815
816 int in_gate_area_no_mm(unsigned long addr)
817 {
818         return 0;
819 }
820
821 int in_gate_area(struct mm_struct *mm, unsigned long addr)
822 {
823         return 0;
824 }
825
826 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
827 {
828         return NULL;
829 }
830