mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	libbpf: Call memfd_create() syscall directly
Some versions of Android do not implement memfd_create() wrapper in their libc implementation, leading to build failures ([0]). On the other hand, memfd_create() is available as a syscall on quite old kernels (3.17+, while bpf() syscall itself is available since 3.18+), so it is ok to assume that syscall availability and call into it with syscall() helper to avoid Android-specific workarounds. Validated in libbpf-bootstrap's CI ([1]). [0] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7701003207/job/20986080319#step:5:83 [1] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7715988887/job/21031767212?pr=253 Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20240201172027.604869-2-andrii@kernel.org
This commit is contained in:
		
							parent
							
								
									1581e5118e
								
							
						
					
					
						commit
						9fa5e1a180
					
				
					 1 changed files with 10 additions and 1 deletions
				
			
		| 
						 | 
					@ -1525,11 +1525,20 @@ static Elf64_Sym *find_elf_var_sym(const struct bpf_object *obj, const char *nam
 | 
				
			||||||
	return ERR_PTR(-ENOENT);
 | 
						return ERR_PTR(-ENOENT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Some versions of Android don't provide memfd_create() in their libc
 | 
				
			||||||
 | 
					 * implementation, so avoid complications and just go straight to Linux
 | 
				
			||||||
 | 
					 * syscall.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int sys_memfd_create(const char *name, unsigned flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return syscall(__NR_memfd_create, name, flags);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int create_placeholder_fd(void)
 | 
					static int create_placeholder_fd(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int fd;
 | 
						int fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fd = ensure_good_fd(memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC));
 | 
						fd = ensure_good_fd(sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC));
 | 
				
			||||||
	if (fd < 0)
 | 
						if (fd < 0)
 | 
				
			||||||
		return -errno;
 | 
							return -errno;
 | 
				
			||||||
	return fd;
 | 
						return fd;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue