浏览代码

don't fail to map library/executable with zero-length segment maps

reportedly the GNU linker can emit such segments, causing spurious
failure to load due to mmap with a length of zero producing EINVAL.
no action is required for such a load map (it's effectively a nop in
the program headers table) so just treat it as always successful.
Rich Felker 4 年之前
父节点
当前提交
cfdfd5ea3c
共有 1 个文件被更改,包括 1 次插入0 次删除
  1. 1 0
      ldso/dynlink.c

+ 1 - 0
ldso/dynlink.c

@@ -579,6 +579,7 @@ static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t of
 {
 {
 	static int no_map_fixed;
 	static int no_map_fixed;
 	char *q;
 	char *q;
+	if (!n) return p;
 	if (!no_map_fixed) {
 	if (!no_map_fixed) {
 		q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
 		q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
 		if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)
 		if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)