Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/glibc/lind_syscall/lind_syscall_num.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#define GETEUID_SYSCALL 107
#define GETEGID_SYSCALL 108
#define GETPPID_SYSCALL 110
#define GETPGID_SYSCALL 121
#define MKNOD_SYSCALL 133
#define STATFS_SYSCALL 137
#define FSTATFS_SYSCALL 138
Expand Down
11 changes: 8 additions & 3 deletions src/glibc/sysdeps/unix/sysv/linux/i386/i686/getpgid.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include <unistd.h>
#include <sysdep-cancel.h>
#include <syscall-template.h>
#include <lind_syscall_num.h>
#include <addr_translation.h>

pid_t
__getpgid (pid_t pid)
{
return pid;
return MAKE_LEGACY_SYSCALL (GETPGID_SYSCALL, "syscall|getpgid",
(uint64_t) pid, NOTUSED, NOTUSED,
NOTUSED, NOTUSED, NOTUSED, TRANSLATE_ERRNO_ON);
}


weak_alias (__getpgid, getpgid)
44 changes: 44 additions & 0 deletions src/rawposix/src/sys_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,50 @@ pub extern "C" fn getpid_syscall(
return cage.cageid as i32;
}

/// Reference to Linux: https://man7.org/linux/man-pages/man2/getpgid.2.html
///
/// Returns the process group ID of the process specified by pid.
/// If pid is 0, returns the process group ID of the calling process.
///
/// Lind does not implement process groups. This always returns the cage's
/// own cageid, which is platform-specific behavior that cannot be changed
/// with a grate since getpgid is handled directly by RawPOSIX.
///
/// ## Returns
/// - The cageid (as process group ID) on success.
pub extern "C" fn getpgid_syscall(
cageid: u64,
pid_arg: u64,
pid_cageid: u64,
arg2: u64,
arg2_cageid: u64,
arg3: u64,
arg3_cageid: u64,
arg4: u64,
arg4_cageid: u64,
arg5: u64,
arg5_cageid: u64,
arg6: u64,
arg6_cageid: u64,
) -> i32 {
if !(sc_unusedarg(arg2, arg2_cageid)
&& sc_unusedarg(arg3, arg3_cageid)
&& sc_unusedarg(arg4, arg4_cageid)
&& sc_unusedarg(arg5, arg5_cageid)
&& sc_unusedarg(arg6, arg6_cageid))
{
panic!(
"{}: unused arguments contain unexpected values -- security violation",
"getpgid_syscall"
);
}

// Lind doesn't implement process groups. Return own cageid regardless
// of the pid argument (matching the behavior of getpid).
let cage = get_cage(cageid).unwrap();
cage.cageid as i32
}

/// Reference to Linux: https://man7.org/linux/man-pages/man3/getppid.3p.html
///
/// See comments of `getpid_syscall` for more details
Expand Down
3 changes: 2 additions & 1 deletion src/rawposix/src/syscall_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::net_calls::{
};
use super::sys_calls::{
exec_syscall, exit_group_syscall, exit_syscall, fork_syscall, getegid_syscall, geteuid_syscall,
getgid_syscall, getpid_syscall, getppid_syscall, getuid_syscall, kill_syscall,
getgid_syscall, getpgid_syscall, getpid_syscall, getppid_syscall, getuid_syscall, kill_syscall,
prlimit64_syscall, sched_yield_syscall, setitimer_syscall, sigaction_syscall,
sigprocmask_syscall, waitpid_syscall,
};
Expand Down Expand Up @@ -123,6 +123,7 @@ pub const SYSCALL_TABLE: &[(u64, RawCallFunc)] = &[
(syscall_const::GETEUID_SYSCALL as u64, geteuid_syscall),
(syscall_const::GETEGID_SYSCALL as u64, getegid_syscall),
(syscall_const::GETPPID_SYSCALL as u64, getppid_syscall),
(syscall_const::GETPGID_SYSCALL as u64, getpgid_syscall),
(syscall_const::MKNOD_SYSCALL as u64, mknod_syscall),
(syscall_const::STATFS_SYSCALL as u64, statfs_syscall),
(syscall_const::FSTATFS_SYSCALL as u64, fstatfs_syscall),
Expand Down
1 change: 1 addition & 0 deletions src/sysdefs/src/constants/syscall_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub const GETGID_SYSCALL: i32 = 104;
pub const GETEUID_SYSCALL: i32 = 107;
pub const GETEGID_SYSCALL: i32 = 108;
pub const GETPPID_SYSCALL: i32 = 110;
pub const GETPGID_SYSCALL: i32 = 121;
pub const MKNOD_SYSCALL: i32 = 133;
pub const STATFS_SYSCALL: i32 = 137;
pub const FSTATFS_SYSCALL: i32 = 138;
Expand Down
11 changes: 11 additions & 0 deletions tests/unit-tests/file_tests/deterministic/getpgid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <unistd.h>
#include <assert.h>

int main(void) {
pid_t pgid = getpgid(0);
assert(pgid > 0);

printf("getpgid: all tests passed\n");
return 0;
}
Loading