330 #ifdef TEST_SIZE
331 if (test_size(hi) == 0)
332 return (0);
333 #endif
334
335 return ((size_t)hi);
336 }
337
338
339
340 static size_t
341 _elf_upd_usr(Elf * elf)
342 {
343 NOTE(ASSUMING_PROTECTED(*elf))
344 Lword hi;
345 Elf_Scn * s;
346 register Lword sz;
347 Ehdr * eh = elf->ed_ehdr;
348 unsigned ver = eh->e_version;
349 register char *p = (char *)eh->e_ident;
350
351
352 /*
353 * Ehdr and Phdr table go first
354 */
355 p[EI_MAG0] = ELFMAG0;
356 p[EI_MAG1] = ELFMAG1;
357 p[EI_MAG2] = ELFMAG2;
358 p[EI_MAG3] = ELFMAG3;
359 p[EI_CLASS] = ELFCLASS;
360 /* LINTED */
361 p[EI_VERSION] = (Byte)ver;
362 hi = elf_fsize(ELF_T_EHDR, 1, ver);
363 /* LINTED */
364 eh->e_ehsize = (Half)hi;
365
366 /*
367 * If phnum is zero, phoff "should" be zero too,
368 * but the application is responsible for it.
369 * Allow a non-zero value here and update the
370 * hi water mark accordingly.
371 */
372
373 if (eh->e_phnum != 0)
374 /* LINTED */
375 eh->e_phentsize = (Half)elf_fsize(ELF_T_PHDR, 1, ver);
376 else
377 eh->e_phentsize = 0;
378 if ((sz = eh->e_phoff + eh->e_phentsize * eh->e_phnum) > hi)
379 hi = sz;
380
381 /*
382 * Loop through sections, skipping index zero.
383 * Compute section size before changing hi.
384 * Allow null buffers for NOBITS.
385 */
386
387 if ((s = elf->ed_hdscn) == 0)
388 eh->e_shnum = 0;
389 else {
390 eh->e_shnum = 1;
391 *(Shdr*)s->s_shdr = _elf_snode_init.sb_shdr;
392 s = s->s_next;
393 }
394 for (; s != 0; s = s->s_next) {
395 register Dnode *d;
396 register Lword fsz, j;
397 Shdr *sh = s->s_shdr;
398
399 if ((s->s_myflags & SF_READY) == 0)
400 (void) _elfxx_cookscn(s);
401
402 ++eh->e_shnum;
403 sz = 0;
404 for (d = s->s_hdnode; d != 0; d = d->db_next) {
405 if ((fsz = elf_fsize(d->db_data.d_type, 1,
406 ver)) == 0)
407 return (0);
408 j = _elf_msize(d->db_data.d_type, ver);
409 fsz *= (d->db_data.d_size / j);
410 d->db_osz = (size_t)fsz;
411
412 if ((sh->sh_type != SHT_NOBITS) &&
413 ((j = (d->db_data.d_off + d->db_osz)) > sz))
414 sz = j;
415 }
416 if (sh->sh_size < sz) {
417 _elf_seterr(EFMT_SCNSZ, 0);
418 return (0);
419 }
420 if ((sh->sh_type != SHT_NOBITS) &&
421 (hi < sh->sh_offset + sh->sh_size))
422 hi = sh->sh_offset + sh->sh_size;
423 }
424
425 /*
426 * Shdr table last. Comment above for phnum/phoff applies here.
427 */
428 if (eh->e_shnum != 0)
429 /* LINTED */
430 eh->e_shentsize = (Half)elf_fsize(ELF_T_SHDR, 1, ver);
431 else
432 eh->e_shentsize = 0;
433
434 if ((sz = eh->e_shoff + eh->e_shentsize * eh->e_shnum) > hi)
435 hi = sz;
436
437 #ifdef TEST_SIZE
438 if (test_size(hi) == 0)
439 return (0);
440 #endif
441
442 return ((size_t)hi);
443 }
444
445
446 static size_t
447 wrt(Elf * elf, Xword outsz, unsigned fill, int update_cmd)
448 {
449 NOTE(ASSUMING_PROTECTED(*elf))
450 Elf_Data dst, src;
451 unsigned flag;
452 Xword hi, sz;
453 char *image;
454 Elf_Scn *s;
|
330 #ifdef TEST_SIZE
331 if (test_size(hi) == 0)
332 return (0);
333 #endif
334
335 return ((size_t)hi);
336 }
337
338
339
340 static size_t
341 _elf_upd_usr(Elf * elf)
342 {
343 NOTE(ASSUMING_PROTECTED(*elf))
344 Lword hi;
345 Elf_Scn * s;
346 register Lword sz;
347 Ehdr * eh = elf->ed_ehdr;
348 unsigned ver = eh->e_version;
349 register char *p = (char *)eh->e_ident;
350 size_t scncnt;
351
352 /*
353 * Ehdr and Phdr table go first
354 */
355 p[EI_MAG0] = ELFMAG0;
356 p[EI_MAG1] = ELFMAG1;
357 p[EI_MAG2] = ELFMAG2;
358 p[EI_MAG3] = ELFMAG3;
359 p[EI_CLASS] = ELFCLASS;
360 /* LINTED */
361 p[EI_VERSION] = (Byte)ver;
362 hi = elf_fsize(ELF_T_EHDR, 1, ver);
363 /* LINTED */
364 eh->e_ehsize = (Half)hi;
365
366 /*
367 * If phnum is zero, phoff "should" be zero too,
368 * but the application is responsible for it.
369 * Allow a non-zero value here and update the
370 * hi water mark accordingly.
371 */
372
373 if (eh->e_phnum != 0)
374 /* LINTED */
375 eh->e_phentsize = (Half)elf_fsize(ELF_T_PHDR, 1, ver);
376 else
377 eh->e_phentsize = 0;
378 if ((sz = eh->e_phoff + eh->e_phentsize * eh->e_phnum) > hi)
379 hi = sz;
380
381 /*
382 * Loop through sections, skipping index zero.
383 * Compute section size before changing hi.
384 * Allow null buffers for NOBITS.
385 */
386
387 if ((s = elf->ed_hdscn) == 0) {
388 eh->e_shnum = 0;
389 scncnt = 0;
390 } else {
391 scncnt = 1;
392 s = s->s_next;
393 }
394 for (; s != 0; s = s->s_next) {
395 register Dnode *d;
396 register Lword fsz, j;
397 Shdr *sh = s->s_shdr;
398
399 if ((s->s_myflags & SF_READY) == 0)
400 (void) _elfxx_cookscn(s);
401
402 ++scncnt;
403 sz = 0;
404 for (d = s->s_hdnode; d != 0; d = d->db_next) {
405 if ((fsz = elf_fsize(d->db_data.d_type, 1,
406 ver)) == 0)
407 return (0);
408 j = _elf_msize(d->db_data.d_type, ver);
409 fsz *= (d->db_data.d_size / j);
410 d->db_osz = (size_t)fsz;
411
412 if ((sh->sh_type != SHT_NOBITS) &&
413 ((j = (d->db_data.d_off + d->db_osz)) > sz))
414 sz = j;
415 }
416 if (sh->sh_size < sz) {
417 _elf_seterr(EFMT_SCNSZ, 0);
418 return (0);
419 }
420 if ((sh->sh_type != SHT_NOBITS) &&
421 (hi < sh->sh_offset + sh->sh_size))
422 hi = sh->sh_offset + sh->sh_size;
423 }
424
425 /*
426 * Shdr table last. Comment above for phnum/phoff applies here.
427 */
428 if (scncnt != 0) {
429 /* LINTED */
430 eh->e_shentsize = (Half)elf_fsize(ELF_T_SHDR, 1, ver);
431 if (scncnt < SHN_LORESERVE) {
432 eh->e_shnum = scncnt;
433 } else {
434 Shdr *sh;
435 sh = (Shdr *)elf->ed_hdscn->s_shdr;
436 sh->sh_size = scncnt;
437 eh->e_shnum = 0;
438 }
439 } else {
440 eh->e_shentsize = 0;
441 }
442
443 if ((sz = eh->e_shoff + eh->e_shentsize * scncnt) > hi)
444 hi = sz;
445
446 #ifdef TEST_SIZE
447 if (test_size(hi) == 0)
448 return (0);
449 #endif
450
451 return ((size_t)hi);
452 }
453
454
455 static size_t
456 wrt(Elf * elf, Xword outsz, unsigned fill, int update_cmd)
457 {
458 NOTE(ASSUMING_PROTECTED(*elf))
459 Elf_Data dst, src;
460 unsigned flag;
461 Xword hi, sz;
462 char *image;
463 Elf_Scn *s;
|