Skip to content

Commit

Permalink
payload: Ensure dup3() is declared on Linux
Browse files Browse the repository at this point in the history
Older libc versions don't have it.

Co-authored-by: Håvard Sørbø <[email protected]>
  • Loading branch information
oleavr and hsorbo committed Apr 29, 2024
1 parent 16d14e1 commit 4fcfcb3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/payload/fdt-padder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace Frida {
int result = -1;
#if LINUX
do {
result = Linux.dup3 (fd, pair[0], Posix.FD_CLOEXEC);
result = LibcShim.dup3 (fd, pair[0], Posix.FD_CLOEXEC);
} while (result == -1 && Posix.errno == Posix.EINTR);
#else
do {
Expand Down
8 changes: 8 additions & 0 deletions lib/payload/libc-shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __FRIDA_LIBC_SHIM_H__
#define __FRIDA_LIBC_SHIM_H__

#ifdef HAVE_LINUX
int dup3 (int oldfd, int newfd, int flags);
#endif

#endif
6 changes: 6 additions & 0 deletions lib/payload/libc-shim.vapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[CCode (cheader_filename = "libc-shim.h", lower_case_cprefix = "", gir_namespace = "FridaLibcShim", gir_version = "1.0")]
namespace Frida.LibcShim {
#if LINUX
public int dup3 (int oldfd, int newfd, int flags);
#endif
}
8 changes: 7 additions & 1 deletion lib/payload/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ payload_vala_args = gum_vala_args + gumjs_vala_args

payload = static_library('frida-payload-' + api_version, payload_sources,
c_args: frida_component_cflags,
vala_args: [payload_vala_args, base_vala_args, extra_vala_args],
vala_args: [
'--vapidir=' + meson.current_source_dir(),
'--pkg=libc-shim',
payload_vala_args,
base_vala_args,
extra_vala_args,
],
vala_header: 'frida-payload.h',
vala_vapi: f'frida-payload-@[email protected]',
dependencies: [gio_dep, gee_dep, json_glib_dep, gum_dep, gumjs_dep, base_dep],
Expand Down

0 comments on commit 4fcfcb3

Please sign in to comment.