mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Clean up more code
- Found some bugs in LLVM compiler-rt library - The useless LIBC_STUBS package is now deleted - Improve the overflow checking story even further - Get chibicc tests working in MODE=dbg mode again - The libc/isystem/ headers now have correctly named guards
This commit is contained in:
parent
afc58a8b41
commit
d7c79f43ef
294 changed files with 912 additions and 1208 deletions
|
@ -19,14 +19,23 @@
|
|||
#include "libc/elf/elf.h"
|
||||
#include "libc/stdckdint.h"
|
||||
|
||||
// note: should not be used on bss section
|
||||
/**
|
||||
* Returns pointer to elf section file content.
|
||||
*
|
||||
* This function shouldn't be used on the bss section.
|
||||
*
|
||||
* @param elf points to the start of the executable image
|
||||
* @param mapsize is the number of bytes past `elf` we can access
|
||||
* @param shdr is from GetElfSectionHeaderAddress() and null-propagating
|
||||
* @return pointer to content bytes, or null on error
|
||||
*/
|
||||
void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
|
||||
size_t mapsize, // validated
|
||||
const Elf64_Shdr *shdr) { // foreign
|
||||
uint64_t addr, last;
|
||||
uint64_t last;
|
||||
if (!shdr) return 0;
|
||||
if (ckd_add(&addr, (uintptr_t)elf, shdr->sh_offset)) return 0;
|
||||
if (ckd_add(&last, addr, shdr->sh_size)) return 0;
|
||||
if (last > (uintptr_t)elf + mapsize) return 0;
|
||||
return (void *)addr;
|
||||
if (shdr->sh_size <= 0) return 0;
|
||||
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
|
||||
if (last > mapsize) return 0;
|
||||
return (char *)elf + shdr->sh_offset;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue