| 646 | |
| 647 | #define LS_PADDING 0x90909090 |
| 648 | static int |
| 649 | parse_dpcpu(elf_file_t ef) |
| 650 | { |
| 651 | int error, size; |
| 652 | #if defined(__i386__) |
| 653 | uint32_t pad; |
| 654 | #endif |
| 655 | |
| 656 | ef->pcpu_start = 0; |
| 657 | ef->pcpu_stop = 0; |
| 658 | error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start, |
| 659 | (void ***)&ef->pcpu_stop, NULL); |
| 660 | /* Error just means there is no pcpu set to relocate. */ |
| 661 | if (error != 0) |
| 662 | return (0); |
| 663 | size = (uintptr_t)ef->pcpu_stop - (uintptr_t)ef->pcpu_start; |
| 664 | /* Empty set? */ |
| 665 | if (size < 1) |
| 666 | return (0); |
| 667 | #if defined(__i386__) |
| 668 | /* In case we do find __start/stop_set_ symbols double-check. */ |
| 669 | if (size < 4) { |
| 670 | uprintf("Kernel module '%s' must be recompiled with " |
| 671 | "linker script\n", ef->lf.pathname); |
| 672 | return (ENOEXEC); |
| 673 | } |
| 674 | |
| 675 | /* Padding from linker-script correct? */ |
| 676 | pad = *(uint32_t *)((uintptr_t)ef->pcpu_stop - sizeof(pad)); |
| 677 | if (pad != LS_PADDING) { |
| 678 | uprintf("Kernel module '%s' must be recompiled with " |
| 679 | "linker script, invalid padding %#04x (%#04x)\n", |
| 680 | ef->lf.pathname, pad, LS_PADDING); |
| 681 | return (ENOEXEC); |
| 682 | } |
| 683 | /* If we only have valid padding, nothing to do. */ |
| 684 | if (size == 4) |
| 685 | return (0); |
| 686 | #endif |
| 687 | /* |
| 688 | * Allocate space in the primary pcpu area. Copy in our |
| 689 | * initialization from the data section and then initialize |
| 690 | * all per-cpu storage from that. |
| 691 | */ |
| 692 | ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(size); |
| 693 | if (ef->pcpu_base == 0) { |
| 694 | printf("%s: pcpu module space is out of space; " |
| 695 | "cannot allocate %d for %s\n", |
| 696 | __func__, size, ef->lf.pathname); |
| 697 | return (ENOSPC); |
| 698 | } |
| 699 | memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, size); |
| 700 | dpcpu_copy((void *)ef->pcpu_base, size); |
| 701 | elf_set_add(&set_pcpu_list, ef->pcpu_start, ef->pcpu_stop, |
| 702 | ef->pcpu_base); |
| 703 | |
| 704 | return (0); |
| 705 | } |
no test coverage detected