288 static caddr_t _edata;
289 #else
290 extern caddr_t _edata;
291 #endif
292
293 Addr dynseg = 0; /* load address of "dynamic" segment */
294 size_t dynsize; /* "dynamic" segment size */
295
296
297 int standalone = 1; /* an unwholey kernel? */
298 int use_iflush; /* iflush after relocations */
299
300 /*
301 * _kobj_printf() and _vkobj_printf()
302 *
303 * Common printf function pointer. Can handle only one conversion
304 * specification in the format string. Some of the functions invoked
305 * through this function pointer cannot handle more that one conversion
306 * specification in the format string.
307 */
308 void (*_kobj_printf)(void *, const char *, ...); /* printf routine */
309 void (*_vkobj_printf)(void *, const char *, va_list); /* vprintf routine */
310
311 /*
312 * Standalone function pointers for use within krtld.
313 * Many platforms implement optimized platmod versions of
314 * utilities such as bcopy and any such are not yet available
315 * until the kernel is more completely stitched together.
316 * See kobj_impl.h
317 */
318 void (*kobj_bcopy)(const void *, void *, size_t);
319 void (*kobj_bzero)(void *, size_t);
320 size_t (*kobj_strlcat)(char *, const char *, size_t);
321
322 static kobj_stat_t kobj_stat;
323
324 #define MINALIGN 8 /* at least a double-word */
325
326 int
327 get_weakish_int(int *ip)
328 {
329 if (standalone)
494 kobj_kdi_init();
495
496 if (boothowto & RB_KMDB) {
497 if (load_kmdb(bootaux) < 0)
498 goto fail;
499 }
500
501 /*
502 * Post setup.
503 */
504 s_text = _text;
505 e_text = _etext;
506 s_data = _data;
507 e_data = _edata;
508
509 kobj_sync_instruction_memory(s_text, e_text - s_text);
510
511 #ifdef KOBJ_DEBUG
512 if (kobj_debug & D_DEBUG)
513 _kobj_printf(ops,
514 "krtld: transferring control to: 0x%p\n", entry);
515 #endif
516
517 /*
518 * Make sure the mod system knows about the modules already loaded.
519 */
520 last_module_id = kobj_last_module_id;
521 bcopy(kobj_modules, &modules, sizeof (modules));
522 modp = &modules;
523 do {
524 if (modp->mod_next == kobj_modules)
525 modp->mod_next = &modules;
526 if (modp->mod_prev == kobj_modules)
527 modp->mod_prev = &modules;
528 } while ((modp = modp->mod_next) != &modules);
529
530 standalone = 0;
531
532 #ifdef KOBJ_DEBUG
533 if (kobj_debug & D_DEBUG)
534 _kobj_printf(ops,
535 "krtld: really transferring control to: 0x%p\n", entry);
536 #endif
537
538 /* restore printf/bcopy/bzero vectors before returning */
539 kobj_restore_vectors();
540
541 #if defined(_DBOOT)
542 /*
543 * krtld was called from a dboot ELF section, the embedded
544 * dboot code contains the real entry via bootaux
545 */
546 exitto((caddr_t)entry);
547 #else
548 /*
549 * krtld was directly called from startup
550 */
551 return;
552 #endif
553
554 fail:
555
840 KOBJ_MARK("chains");
841 mp->chains = kobj_zalloc(mp->nsyms * sizeof (symid_t), KM_WAIT);
842 KOBJ_MARK("buckets");
843 mp->buckets = kobj_zalloc(mp->hashsize * sizeof (symid_t), KM_WAIT);
844
845 mp->text = _text;
846 mp->data = _data;
847
848 mp->text_size = _etext - _text;
849 mp->data_size = _edata - _data;
850
851 cp->mod_text = mp->text;
852 cp->mod_text_size = mp->text_size;
853
854 mp->filename = cp->mod_filename;
855
856 #ifdef KOBJ_DEBUG
857 if (kobj_debug & D_LOADING) {
858 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
859 _kobj_printf(ops, "\ttext: 0x%p", mp->text);
860 _kobj_printf(ops, " size: 0x%x\n", mp->text_size);
861 _kobj_printf(ops, "\tdata: 0x%p", mp->data);
862 _kobj_printf(ops, " dsize: 0x%x\n", mp->data_size);
863 }
864 #endif /* KOBJ_DEBUG */
865
866 /*
867 * Insert symbols into the hash table.
868 */
869 for (i = 0; i < mp->nsyms; i++) {
870 sp = (Sym *)(mp->symtbl + i * mp->symhdr->sh_entsize);
871
872 if (sp->st_name == 0 || sp->st_shndx == SHN_UNDEF)
873 continue;
874 #if defined(__sparc)
875 /*
876 * Register symbols are ignored in the kernel
877 */
878 if (ELF_ST_TYPE(sp->st_info) == STT_SPARC_REGISTER)
879 continue;
880 #endif /* __sparc */
881
882 sym_insert(mp, mp->strings + sp->st_name, i);
951 mp->bss_align = 0; /* pre-aligned during allocation */
952 mp->bss_size = (uintptr_t)_edata - mp->bss;
953 mp->text_size = _etext - mp->text;
954 mp->data_size = _edata - mp->data;
955 mp->filename = cp->mod_filename;
956 cp->mod_text = mp->text;
957 cp->mod_text_size = mp->text_size;
958
959 /*
960 * Now that we've figured out where the linker is,
961 * set the limits for the booted object.
962 */
963 kmp->text_size = (size_t)(mp->text - kmp->text);
964 kmp->data_size = (size_t)(mp->data - kmp->data);
965 kobj_modules->mod_text_size = kmp->text_size;
966
967 #ifdef KOBJ_DEBUG
968 if (kobj_debug & D_LOADING) {
969 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
970 _kobj_printf(ops, "\ttext:0x%p", mp->text);
971 _kobj_printf(ops, " size: 0x%x\n", mp->text_size);
972 _kobj_printf(ops, "\tdata:0x%p", mp->data);
973 _kobj_printf(ops, " dsize: 0x%x\n", mp->data_size);
974 }
975 #endif /* KOBJ_DEBUG */
976
977 /*
978 * Insert the symbols into the hash table.
979 */
980 for (i = 0; i < mp->nsyms; i++) {
981 sp = (Sym *)(mp->symtbl + i * mp->symhdr->sh_entsize);
982
983 if (sp->st_name == 0 || sp->st_shndx == SHN_UNDEF)
984 continue;
985 if (ELF_ST_BIND(sp->st_info) == STB_GLOBAL) {
986 if (sp->st_shndx == SHN_COMMON)
987 sp->st_shndx = SHN_ABS;
988 }
989 sym_insert(mp, mp->strings + sp->st_name, i);
990 }
991
992 }
993
1993 /*
1994 * If we didn't dependency information from the dynamic section, look
1995 * for it the old-fashioned way.
1996 */
1997 if (mp->depends_on == NULL)
1998 mp->depends_on = depends_on(mp);
1999
2000 if (get_ctf(mp, file) < 0) {
2001 _kobj_printf(ops, "%s debug information will not "
2002 "be available\n", modname);
2003 }
2004
2005 /* primary kernel modules do not have a signature section */
2006 if (!(mp->flags & KOBJ_PRIM))
2007 get_signature(mp, file);
2008
2009 #ifdef KOBJ_DEBUG
2010 if (kobj_debug & D_LOADING) {
2011 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
2012 _kobj_printf(ops, "\ttext:0x%p", mp->text);
2013 _kobj_printf(ops, " size: 0x%x\n", mp->text_size);
2014 _kobj_printf(ops, "\tdata:0x%p", mp->data);
2015 _kobj_printf(ops, " dsize: 0x%x\n", mp->data_size);
2016 }
2017 #endif /* KOBJ_DEBUG */
2018
2019 /*
2020 * For primary kernel modules, we defer
2021 * symbol resolution and relocation until
2022 * all primary objects have been loaded.
2023 */
2024 if (!standalone) {
2025 int ddrval, dcrval;
2026 char *dependent_modname;
2027 /* load all dependents */
2028 dependent_modname = kobj_zalloc(MODMAXNAMELEN, KM_WAIT);
2029 ddrval = do_dependents(modp, dependent_modname, MODMAXNAMELEN);
2030
2031 /*
2032 * resolve undefined and common symbols,
2033 * also allocates common space
2034 */
2035 if ((dcrval = do_common(mp)) < 0) {
2697 SHA1_CTX ctx;
2698
2699 SHA1Init(&ctx);
2700
2701 for (shn = 1; shn < mp->hdr.e_shnum; shn++) {
2702 shp = (Shdr *)(mp->shdrs + shn * mp->hdr.e_shentsize);
2703 if (!(shp->sh_flags & SHF_ALLOC) || shp->sh_size == 0)
2704 continue;
2705
2706 /*
2707 * The check should ideally be shp->sh_type == SHT_NOBITS.
2708 * However, we can't do that check here as get_progbits()
2709 * resets the type.
2710 */
2711 if (strcmp(shstrtab + shp->sh_name, ".bss") == 0)
2712 continue;
2713 #ifdef KOBJ_DEBUG
2714 if (kobj_debug & D_DEBUG)
2715 _kobj_printf(ops,
2716 "krtld: crypto_es_hash: updating hash with"
2717 " %s data size=%d\n", shstrtab + shp->sh_name,
2718 shp->sh_size);
2719 #endif
2720 ASSERT(shp->sh_addr != 0);
2721 SHA1Update(&ctx, (const uint8_t *)shp->sh_addr, shp->sh_size);
2722 }
2723
2724 SHA1Final((uchar_t *)hash, &ctx);
2725 }
2726
2727 /*
2728 * Get the .SUNW_signature section for the module, it it exists.
2729 *
2730 * This section exists only for crypto modules. None of the
2731 * primary modules have this section currently.
2732 */
2733 static void
2734 get_signature(struct module *mp, struct _buf *file)
2735 {
2736 char *shstrtab, *sigdata = NULL;
2737 size_t shstrlen;
2738 Shdr *shp;
2851 c = 0;
2852 while (*p && *p != ' ' && *p != '\t') {
2853 if (c < modnamelen - 1) {
2854 *q++ = *p;
2855 c++;
2856 }
2857 p++;
2858 }
2859
2860 if (q == modname)
2861 break;
2862
2863 if (c == modnamelen - 1) {
2864 char *dep = kobj_alloc(p - d + 1, KM_WAIT|KM_TMP);
2865
2866 (void) strncpy(dep, d, p - d + 1);
2867 dep[p - d] = '\0';
2868
2869 _kobj_printf(ops, "%s: dependency ", modp->mod_modname);
2870 _kobj_printf(ops, "'%s' too long ", dep);
2871 _kobj_printf(ops, "(max %d chars)\n", modnamelen);
2872
2873 kobj_free(dep, p - d + 1);
2874
2875 return (-1);
2876 }
2877
2878 *q = '\0';
2879 if ((req = mod_load_requisite(modp, modname)) == NULL) {
2880 #ifndef KOBJ_DEBUG
2881 if (_moddebug & MODDEBUG_LOADMSG) {
2882 #endif /* KOBJ_DEBUG */
2883 _kobj_printf(ops,
2884 "%s: unable to resolve dependency, ",
2885 modp->mod_modname);
2886 _kobj_printf(ops, "cannot load module '%s'\n",
2887 modname);
2888 #ifndef KOBJ_DEBUG
2889 }
2890 #endif /* KOBJ_DEBUG */
2891 if (err_modname == NULL) {
3803 kobj_close(file->_fd);
3804 if (file->_base != NULL)
3805 kobj_free(file->_base, file->_bsize);
3806 if (file->_dbuf != NULL)
3807 kobj_free(file->_dbuf, file->_dsize);
3808 kobj_free(file->_name, strlen(file->_name)+1);
3809 kobj_free(file, sizeof (struct _buf));
3810 }
3811
3812 int
3813 kobj_read_file(struct _buf *file, char *buf, uint_t size, uint_t off)
3814 {
3815 int b_size, c_size;
3816 int b_off; /* Offset into buffer for start of bcopy */
3817 int count = 0;
3818 int page_addr;
3819
3820 if (_moddebug & MODDEBUG_ERRMSG) {
3821 _kobj_printf(ops, "kobj_read_file: size=%x,", size);
3822 _kobj_printf(ops, " offset=%x at", off);
3823 _kobj_printf(ops, " buf=%x\n", buf);
3824 }
3825
3826 /*
3827 * Handle compressed (gzip for now) file here. First get the
3828 * compressed size, then read the image into memory and finally
3829 * call zlib to decompress the image at the supplied memory buffer.
3830 */
3831 if (file->_iscmp == CH_MAGIC_GZIP) {
3832 ulong_t dlen;
3833 vattr_t vattr;
3834 struct vnode *vp = (struct vnode *)file->_fd;
3835 ssize_t resid;
3836 int err = 0;
3837
3838 if (VOP_GETATTR(vp, &vattr, 0, kcred, NULL) != 0)
3839 return (-1);
3840
3841 file->_dbuf = kobj_alloc(vattr.va_size, KM_WAIT|KM_TMP);
3842 file->_dsize = vattr.va_size;
3843
3846 (offset_t)(0), UIO_SYSSPACE, 0, (rlim64_t)0, CRED(),
3847 &resid)) != 0) {
3848
3849 _kobj_printf(ops, "kobj_read_file :vn_rdwr() failed, "
3850 "error code 0x%x\n", err);
3851 return (-1);
3852 }
3853
3854 dlen = size;
3855
3856 /* Decompress the image at the supplied memory buffer */
3857 if ((err = z_uncompress(buf, &dlen, file->_dbuf,
3858 vattr.va_size)) != Z_OK) {
3859 _kobj_printf(ops, "kobj_read_file: z_uncompress "
3860 "failed, error code : 0x%x\n", err);
3861 return (-1);
3862 }
3863
3864 if (dlen != size) {
3865 _kobj_printf(ops, "kobj_read_file: z_uncompress "
3866 "failed to uncompress (size returned 0x%x , "
3867 "expected size: 0x%x)\n", dlen, size);
3868 return (-1);
3869 }
3870
3871 return (0);
3872 }
3873
3874 while (size) {
3875 page_addr = F_PAGE(file, off);
3876 b_size = file->_size;
3877 /*
3878 * If we have the filesystem page the caller's referring to
3879 * and we have something in the buffer,
3880 * satisfy as much of the request from the buffer as we can.
3881 */
3882 if (page_addr == file->_off && b_size > 0) {
3883 b_off = B_OFFSET(file, off);
3884 c_size = b_size - b_off;
3885 /*
3886 * If there's nothing to copy, we're at EOF.
|
288 static caddr_t _edata;
289 #else
290 extern caddr_t _edata;
291 #endif
292
293 Addr dynseg = 0; /* load address of "dynamic" segment */
294 size_t dynsize; /* "dynamic" segment size */
295
296
297 int standalone = 1; /* an unwholey kernel? */
298 int use_iflush; /* iflush after relocations */
299
300 /*
301 * _kobj_printf() and _vkobj_printf()
302 *
303 * Common printf function pointer. Can handle only one conversion
304 * specification in the format string. Some of the functions invoked
305 * through this function pointer cannot handle more that one conversion
306 * specification in the format string.
307 */
308 void (*_kobj_printf)(void *, const char *, ...) __KPRINTFLIKE(2);
309 void (*_vkobj_printf)(void *, const char *, va_list) __KVPRINTFLIKE(2);
310
311 /*
312 * Standalone function pointers for use within krtld.
313 * Many platforms implement optimized platmod versions of
314 * utilities such as bcopy and any such are not yet available
315 * until the kernel is more completely stitched together.
316 * See kobj_impl.h
317 */
318 void (*kobj_bcopy)(const void *, void *, size_t);
319 void (*kobj_bzero)(void *, size_t);
320 size_t (*kobj_strlcat)(char *, const char *, size_t);
321
322 static kobj_stat_t kobj_stat;
323
324 #define MINALIGN 8 /* at least a double-word */
325
326 int
327 get_weakish_int(int *ip)
328 {
329 if (standalone)
494 kobj_kdi_init();
495
496 if (boothowto & RB_KMDB) {
497 if (load_kmdb(bootaux) < 0)
498 goto fail;
499 }
500
501 /*
502 * Post setup.
503 */
504 s_text = _text;
505 e_text = _etext;
506 s_data = _data;
507 e_data = _edata;
508
509 kobj_sync_instruction_memory(s_text, e_text - s_text);
510
511 #ifdef KOBJ_DEBUG
512 if (kobj_debug & D_DEBUG)
513 _kobj_printf(ops,
514 "krtld: transferring control to: 0x%lx\n", entry);
515 #endif
516
517 /*
518 * Make sure the mod system knows about the modules already loaded.
519 */
520 last_module_id = kobj_last_module_id;
521 bcopy(kobj_modules, &modules, sizeof (modules));
522 modp = &modules;
523 do {
524 if (modp->mod_next == kobj_modules)
525 modp->mod_next = &modules;
526 if (modp->mod_prev == kobj_modules)
527 modp->mod_prev = &modules;
528 } while ((modp = modp->mod_next) != &modules);
529
530 standalone = 0;
531
532 #ifdef KOBJ_DEBUG
533 if (kobj_debug & D_DEBUG)
534 _kobj_printf(ops,
535 "krtld: really transferring control to: 0x%lx\n", entry);
536 #endif
537
538 /* restore printf/bcopy/bzero vectors before returning */
539 kobj_restore_vectors();
540
541 #if defined(_DBOOT)
542 /*
543 * krtld was called from a dboot ELF section, the embedded
544 * dboot code contains the real entry via bootaux
545 */
546 exitto((caddr_t)entry);
547 #else
548 /*
549 * krtld was directly called from startup
550 */
551 return;
552 #endif
553
554 fail:
555
840 KOBJ_MARK("chains");
841 mp->chains = kobj_zalloc(mp->nsyms * sizeof (symid_t), KM_WAIT);
842 KOBJ_MARK("buckets");
843 mp->buckets = kobj_zalloc(mp->hashsize * sizeof (symid_t), KM_WAIT);
844
845 mp->text = _text;
846 mp->data = _data;
847
848 mp->text_size = _etext - _text;
849 mp->data_size = _edata - _data;
850
851 cp->mod_text = mp->text;
852 cp->mod_text_size = mp->text_size;
853
854 mp->filename = cp->mod_filename;
855
856 #ifdef KOBJ_DEBUG
857 if (kobj_debug & D_LOADING) {
858 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
859 _kobj_printf(ops, "\ttext: 0x%p", mp->text);
860 _kobj_printf(ops, " size: 0x%lx\n", mp->text_size);
861 _kobj_printf(ops, "\tdata: 0x%p", mp->data);
862 _kobj_printf(ops, " dsize: 0x%lx\n", mp->data_size);
863 }
864 #endif /* KOBJ_DEBUG */
865
866 /*
867 * Insert symbols into the hash table.
868 */
869 for (i = 0; i < mp->nsyms; i++) {
870 sp = (Sym *)(mp->symtbl + i * mp->symhdr->sh_entsize);
871
872 if (sp->st_name == 0 || sp->st_shndx == SHN_UNDEF)
873 continue;
874 #if defined(__sparc)
875 /*
876 * Register symbols are ignored in the kernel
877 */
878 if (ELF_ST_TYPE(sp->st_info) == STT_SPARC_REGISTER)
879 continue;
880 #endif /* __sparc */
881
882 sym_insert(mp, mp->strings + sp->st_name, i);
951 mp->bss_align = 0; /* pre-aligned during allocation */
952 mp->bss_size = (uintptr_t)_edata - mp->bss;
953 mp->text_size = _etext - mp->text;
954 mp->data_size = _edata - mp->data;
955 mp->filename = cp->mod_filename;
956 cp->mod_text = mp->text;
957 cp->mod_text_size = mp->text_size;
958
959 /*
960 * Now that we've figured out where the linker is,
961 * set the limits for the booted object.
962 */
963 kmp->text_size = (size_t)(mp->text - kmp->text);
964 kmp->data_size = (size_t)(mp->data - kmp->data);
965 kobj_modules->mod_text_size = kmp->text_size;
966
967 #ifdef KOBJ_DEBUG
968 if (kobj_debug & D_LOADING) {
969 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
970 _kobj_printf(ops, "\ttext:0x%p", mp->text);
971 _kobj_printf(ops, " size: 0x%lx\n", mp->text_size);
972 _kobj_printf(ops, "\tdata:0x%p", mp->data);
973 _kobj_printf(ops, " dsize: 0x%lx\n", mp->data_size);
974 }
975 #endif /* KOBJ_DEBUG */
976
977 /*
978 * Insert the symbols into the hash table.
979 */
980 for (i = 0; i < mp->nsyms; i++) {
981 sp = (Sym *)(mp->symtbl + i * mp->symhdr->sh_entsize);
982
983 if (sp->st_name == 0 || sp->st_shndx == SHN_UNDEF)
984 continue;
985 if (ELF_ST_BIND(sp->st_info) == STB_GLOBAL) {
986 if (sp->st_shndx == SHN_COMMON)
987 sp->st_shndx = SHN_ABS;
988 }
989 sym_insert(mp, mp->strings + sp->st_name, i);
990 }
991
992 }
993
1993 /*
1994 * If we didn't dependency information from the dynamic section, look
1995 * for it the old-fashioned way.
1996 */
1997 if (mp->depends_on == NULL)
1998 mp->depends_on = depends_on(mp);
1999
2000 if (get_ctf(mp, file) < 0) {
2001 _kobj_printf(ops, "%s debug information will not "
2002 "be available\n", modname);
2003 }
2004
2005 /* primary kernel modules do not have a signature section */
2006 if (!(mp->flags & KOBJ_PRIM))
2007 get_signature(mp, file);
2008
2009 #ifdef KOBJ_DEBUG
2010 if (kobj_debug & D_LOADING) {
2011 _kobj_printf(ops, "krtld: file=%s\n", mp->filename);
2012 _kobj_printf(ops, "\ttext:0x%p", mp->text);
2013 _kobj_printf(ops, " size: 0x%lx\n", mp->text_size);
2014 _kobj_printf(ops, "\tdata:0x%p", mp->data);
2015 _kobj_printf(ops, " dsize: 0x%lx\n", mp->data_size);
2016 }
2017 #endif /* KOBJ_DEBUG */
2018
2019 /*
2020 * For primary kernel modules, we defer
2021 * symbol resolution and relocation until
2022 * all primary objects have been loaded.
2023 */
2024 if (!standalone) {
2025 int ddrval, dcrval;
2026 char *dependent_modname;
2027 /* load all dependents */
2028 dependent_modname = kobj_zalloc(MODMAXNAMELEN, KM_WAIT);
2029 ddrval = do_dependents(modp, dependent_modname, MODMAXNAMELEN);
2030
2031 /*
2032 * resolve undefined and common symbols,
2033 * also allocates common space
2034 */
2035 if ((dcrval = do_common(mp)) < 0) {
2697 SHA1_CTX ctx;
2698
2699 SHA1Init(&ctx);
2700
2701 for (shn = 1; shn < mp->hdr.e_shnum; shn++) {
2702 shp = (Shdr *)(mp->shdrs + shn * mp->hdr.e_shentsize);
2703 if (!(shp->sh_flags & SHF_ALLOC) || shp->sh_size == 0)
2704 continue;
2705
2706 /*
2707 * The check should ideally be shp->sh_type == SHT_NOBITS.
2708 * However, we can't do that check here as get_progbits()
2709 * resets the type.
2710 */
2711 if (strcmp(shstrtab + shp->sh_name, ".bss") == 0)
2712 continue;
2713 #ifdef KOBJ_DEBUG
2714 if (kobj_debug & D_DEBUG)
2715 _kobj_printf(ops,
2716 "krtld: crypto_es_hash: updating hash with"
2717 " %s data size=%lx\n", shstrtab + shp->sh_name,
2718 (size_t)shp->sh_size);
2719 #endif
2720 ASSERT(shp->sh_addr != 0);
2721 SHA1Update(&ctx, (const uint8_t *)shp->sh_addr, shp->sh_size);
2722 }
2723
2724 SHA1Final((uchar_t *)hash, &ctx);
2725 }
2726
2727 /*
2728 * Get the .SUNW_signature section for the module, it it exists.
2729 *
2730 * This section exists only for crypto modules. None of the
2731 * primary modules have this section currently.
2732 */
2733 static void
2734 get_signature(struct module *mp, struct _buf *file)
2735 {
2736 char *shstrtab, *sigdata = NULL;
2737 size_t shstrlen;
2738 Shdr *shp;
2851 c = 0;
2852 while (*p && *p != ' ' && *p != '\t') {
2853 if (c < modnamelen - 1) {
2854 *q++ = *p;
2855 c++;
2856 }
2857 p++;
2858 }
2859
2860 if (q == modname)
2861 break;
2862
2863 if (c == modnamelen - 1) {
2864 char *dep = kobj_alloc(p - d + 1, KM_WAIT|KM_TMP);
2865
2866 (void) strncpy(dep, d, p - d + 1);
2867 dep[p - d] = '\0';
2868
2869 _kobj_printf(ops, "%s: dependency ", modp->mod_modname);
2870 _kobj_printf(ops, "'%s' too long ", dep);
2871 _kobj_printf(ops, "(max %d chars)\n", (int)modnamelen);
2872
2873 kobj_free(dep, p - d + 1);
2874
2875 return (-1);
2876 }
2877
2878 *q = '\0';
2879 if ((req = mod_load_requisite(modp, modname)) == NULL) {
2880 #ifndef KOBJ_DEBUG
2881 if (_moddebug & MODDEBUG_LOADMSG) {
2882 #endif /* KOBJ_DEBUG */
2883 _kobj_printf(ops,
2884 "%s: unable to resolve dependency, ",
2885 modp->mod_modname);
2886 _kobj_printf(ops, "cannot load module '%s'\n",
2887 modname);
2888 #ifndef KOBJ_DEBUG
2889 }
2890 #endif /* KOBJ_DEBUG */
2891 if (err_modname == NULL) {
3803 kobj_close(file->_fd);
3804 if (file->_base != NULL)
3805 kobj_free(file->_base, file->_bsize);
3806 if (file->_dbuf != NULL)
3807 kobj_free(file->_dbuf, file->_dsize);
3808 kobj_free(file->_name, strlen(file->_name)+1);
3809 kobj_free(file, sizeof (struct _buf));
3810 }
3811
3812 int
3813 kobj_read_file(struct _buf *file, char *buf, uint_t size, uint_t off)
3814 {
3815 int b_size, c_size;
3816 int b_off; /* Offset into buffer for start of bcopy */
3817 int count = 0;
3818 int page_addr;
3819
3820 if (_moddebug & MODDEBUG_ERRMSG) {
3821 _kobj_printf(ops, "kobj_read_file: size=%x,", size);
3822 _kobj_printf(ops, " offset=%x at", off);
3823 _kobj_printf(ops, " buf=%lx\n", (uintptr_t)buf);
3824 }
3825
3826 /*
3827 * Handle compressed (gzip for now) file here. First get the
3828 * compressed size, then read the image into memory and finally
3829 * call zlib to decompress the image at the supplied memory buffer.
3830 */
3831 if (file->_iscmp == CH_MAGIC_GZIP) {
3832 ulong_t dlen;
3833 vattr_t vattr;
3834 struct vnode *vp = (struct vnode *)file->_fd;
3835 ssize_t resid;
3836 int err = 0;
3837
3838 if (VOP_GETATTR(vp, &vattr, 0, kcred, NULL) != 0)
3839 return (-1);
3840
3841 file->_dbuf = kobj_alloc(vattr.va_size, KM_WAIT|KM_TMP);
3842 file->_dsize = vattr.va_size;
3843
3846 (offset_t)(0), UIO_SYSSPACE, 0, (rlim64_t)0, CRED(),
3847 &resid)) != 0) {
3848
3849 _kobj_printf(ops, "kobj_read_file :vn_rdwr() failed, "
3850 "error code 0x%x\n", err);
3851 return (-1);
3852 }
3853
3854 dlen = size;
3855
3856 /* Decompress the image at the supplied memory buffer */
3857 if ((err = z_uncompress(buf, &dlen, file->_dbuf,
3858 vattr.va_size)) != Z_OK) {
3859 _kobj_printf(ops, "kobj_read_file: z_uncompress "
3860 "failed, error code : 0x%x\n", err);
3861 return (-1);
3862 }
3863
3864 if (dlen != size) {
3865 _kobj_printf(ops, "kobj_read_file: z_uncompress "
3866 "failed to uncompress (size returned 0x%lx , "
3867 "expected size: 0x%x)\n", dlen, size);
3868 return (-1);
3869 }
3870
3871 return (0);
3872 }
3873
3874 while (size) {
3875 page_addr = F_PAGE(file, off);
3876 b_size = file->_size;
3877 /*
3878 * If we have the filesystem page the caller's referring to
3879 * and we have something in the buffer,
3880 * satisfy as much of the request from the buffer as we can.
3881 */
3882 if (page_addr == file->_off && b_size > 0) {
3883 b_off = B_OFFSET(file, off);
3884 c_size = b_size - b_off;
3885 /*
3886 * If there's nothing to copy, we're at EOF.
|