Deleted Added
full compact
link_elf.c (109605) link_elf.c (109623)
1/*-
2 * Copyright (c) 1998-2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998-2000 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/kern/link_elf.c 109605 2003-01-21 02:42:44Z jake $
26 * $FreeBSD: head/sys/kern/link_elf.c 109623 2003-01-21 08:56:16Z alfred $
27 */
28
29#include "opt_ddb.h"
30#include "opt_mac.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>

--- 195 unchanged lines hidden (view full) ---

230 /* Notify MD code that a module is being loaded. */
231 error = elf_cpu_load_file(lf);
232 if (error)
233 return (error);
234
235#ifdef DDB
236 GDB_STATE(RT_ADD);
237 ef->gdb.l_addr = lf->address;
27 */
28
29#include "opt_ddb.h"
30#include "opt_mac.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>

--- 195 unchanged lines hidden (view full) ---

230 /* Notify MD code that a module is being loaded. */
231 error = elf_cpu_load_file(lf);
232 if (error)
233 return (error);
234
235#ifdef DDB
236 GDB_STATE(RT_ADD);
237 ef->gdb.l_addr = lf->address;
238 newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, M_WAITOK);
238 newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, 0);
239 strcpy(newfilename, lf->filename);
240 ef->gdb.l_name = newfilename;
241 ef->gdb.l_ld = ef->dynamic;
242 link_elf_add_gdb(&ef->gdb);
243 GDB_STATE(RT_CONSISTENT);
244#endif
245
246 return (0);

--- 319 unchanged lines hidden (view full) ---

566 firstpage = NULL;
567 goto out;
568 }
569#endif
570
571 /*
572 * Read the elf header from the file.
573 */
239 strcpy(newfilename, lf->filename);
240 ef->gdb.l_name = newfilename;
241 ef->gdb.l_ld = ef->dynamic;
242 link_elf_add_gdb(&ef->gdb);
243 GDB_STATE(RT_CONSISTENT);
244#endif
245
246 return (0);

--- 319 unchanged lines hidden (view full) ---

566 firstpage = NULL;
567 goto out;
568 }
569#endif
570
571 /*
572 * Read the elf header from the file.
573 */
574 firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
574 firstpage = malloc(PAGE_SIZE, M_LINKER, 0);
575 if (firstpage == NULL) {
576 error = ENOMEM;
577 goto out;
578 }
579 hdr = (Elf_Ehdr *)firstpage;
580 error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
581 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
582 &resid, td);

--- 114 unchanged lines hidden (view full) ---

697 mapsize, 1,
698 VM_PROT_ALL, VM_PROT_ALL, 0);
699 if (error) {
700 vm_object_deallocate(ef->object);
701 ef->object = 0;
702 goto out;
703 }
704#else
575 if (firstpage == NULL) {
576 error = ENOMEM;
577 goto out;
578 }
579 hdr = (Elf_Ehdr *)firstpage;
580 error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
581 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
582 &resid, td);

--- 114 unchanged lines hidden (view full) ---

697 mapsize, 1,
698 VM_PROT_ALL, VM_PROT_ALL, 0);
699 if (error) {
700 vm_object_deallocate(ef->object);
701 ef->object = 0;
702 goto out;
703 }
704#else
705 ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
705 ef->address = malloc(mapsize, M_LINKER, 0);
706 if (!ef->address) {
707 error = ENOMEM;
708 goto out;
709 }
710#endif
711 mapbase = ef->address;
712
713 /*

--- 54 unchanged lines hidden (view full) ---

768 error = relocate_file(ef);
769 if (error)
770 goto out;
771
772 /* Try and load the symbol table if it's present. (you can strip it!) */
773 nbytes = hdr->e_shnum * hdr->e_shentsize;
774 if (nbytes == 0 || hdr->e_shoff == 0)
775 goto nosyms;
706 if (!ef->address) {
707 error = ENOMEM;
708 goto out;
709 }
710#endif
711 mapbase = ef->address;
712
713 /*

--- 54 unchanged lines hidden (view full) ---

768 error = relocate_file(ef);
769 if (error)
770 goto out;
771
772 /* Try and load the symbol table if it's present. (you can strip it!) */
773 nbytes = hdr->e_shnum * hdr->e_shentsize;
774 if (nbytes == 0 || hdr->e_shoff == 0)
775 goto nosyms;
776 shdr = malloc(nbytes, M_LINKER, M_WAITOK | M_ZERO);
776 shdr = malloc(nbytes, M_LINKER, M_ZERO);
777 if (shdr == NULL) {
778 error = ENOMEM;
779 goto out;
780 }
781 error = vn_rdwr(UIO_READ, nd.ni_vp,
782 (caddr_t)shdr, nbytes, hdr->e_shoff,
783 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
784 &resid, td);

--- 6 unchanged lines hidden (view full) ---

791 symtabindex = i;
792 symstrindex = shdr[i].sh_link;
793 }
794 }
795 if (symtabindex < 0 || symstrindex < 0)
796 goto nosyms;
797
798 symcnt = shdr[symtabindex].sh_size;
777 if (shdr == NULL) {
778 error = ENOMEM;
779 goto out;
780 }
781 error = vn_rdwr(UIO_READ, nd.ni_vp,
782 (caddr_t)shdr, nbytes, hdr->e_shoff,
783 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
784 &resid, td);

--- 6 unchanged lines hidden (view full) ---

791 symtabindex = i;
792 symstrindex = shdr[i].sh_link;
793 }
794 }
795 if (symtabindex < 0 || symstrindex < 0)
796 goto nosyms;
797
798 symcnt = shdr[symtabindex].sh_size;
799 ef->symbase = malloc(symcnt, M_LINKER, M_WAITOK);
799 ef->symbase = malloc(symcnt, M_LINKER, 0);
800 strcnt = shdr[symstrindex].sh_size;
800 strcnt = shdr[symstrindex].sh_size;
801 ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
801 ef->strbase = malloc(strcnt, M_LINKER, 0);
802
803 if (ef->symbase == NULL || ef->strbase == NULL) {
804 error = ENOMEM;
805 goto out;
806 }
807 error = vn_rdwr(UIO_READ, nd.ni_vp,
808 ef->symbase, symcnt, shdr[symtabindex].sh_offset,
809 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,

--- 309 unchanged lines hidden (view full) ---

1119{
1120 c_linker_sym_t sym;
1121 linker_symval_t symval;
1122 char *setsym;
1123 void **start, **stop;
1124 int len, error = 0, count;
1125
1126 len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
802
803 if (ef->symbase == NULL || ef->strbase == NULL) {
804 error = ENOMEM;
805 goto out;
806 }
807 error = vn_rdwr(UIO_READ, nd.ni_vp,
808 ef->symbase, symcnt, shdr[symtabindex].sh_offset,
809 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,

--- 309 unchanged lines hidden (view full) ---

1119{
1120 c_linker_sym_t sym;
1121 linker_symval_t symval;
1122 char *setsym;
1123 void **start, **stop;
1124 int len, error = 0, count;
1125
1126 len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
1127 setsym = malloc(len, M_LINKER, M_WAITOK);
1127 setsym = malloc(len, M_LINKER, 0);
1128 if (setsym == NULL)
1129 return ENOMEM;
1130
1131 /* get address of first entry */
1132 snprintf(setsym, len, "%s%s", "__start_set_", name);
1133 error = link_elf_lookup_symbol(lf, setsym, &sym);
1134 if (error)
1135 goto out;

--- 165 unchanged lines hidden ---
1128 if (setsym == NULL)
1129 return ENOMEM;
1130
1131 /* get address of first entry */
1132 snprintf(setsym, len, "%s%s", "__start_set_", name);
1133 error = link_elf_lookup_symbol(lf, setsym, &sym);
1134 if (error)
1135 goto out;

--- 165 unchanged lines hidden ---