Skip to content

Commit

Permalink
Add SAFE_PRCTL macro
Browse files Browse the repository at this point in the history
Link: https://lore.kernel.org/ltp/20240711-landlock-v3-4-c7b0e9edf9b0@suse.com/
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
  • Loading branch information
acerv authored and pevik committed Jul 11, 2024
1 parent e441050 commit 362731e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/tst_safe_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,10 @@ int safe_sscanf(const char *file, const int lineno, const char *restrict buffer,
#define SAFE_SSCANF(buffer, format, ...) \
safe_sscanf(__FILE__, __LINE__, (buffer), (format), ##__VA_ARGS__)

int safe_prctl(const char *file, const int lineno,
int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
#define SAFE_PRCTL(option, arg2, arg3, arg4, arg5) \
safe_prctl(__FILE__, __LINE__, (option), (arg2), (arg3), (arg4), (arg5))

#endif /* TST_SAFE_MACROS_H__ */
17 changes: 17 additions & 0 deletions lib/tst_safe_macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <errno.h>
#include <sched.h>
#include <sys/ptrace.h>
#include <sys/prctl.h>
#include "config.h"
#ifdef HAVE_SYS_FANOTIFY_H
# include <sys/fanotify.h>
Expand Down Expand Up @@ -710,3 +711,19 @@ int safe_mprotect(const char *file, const int lineno,

return rval;
}

int safe_prctl(const char *file, const int lineno,
int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
int rval;

rval = prctl(option, arg2, arg3, arg4, arg5);
if (rval == -1) {
tst_brk_(file, lineno, TBROK | TERRNO,
"prctl(%d, %lu, %lu, %lu, %lu)",
option, arg2, arg3, arg4, arg5);
}

return rval;
}

0 comments on commit 362731e

Please sign in to comment.