Message ID | 20240226153754.24998-2-andrea.cervesato@suse.de |
---|---|
State | Superseded |
Headers | show |
Series | SysV IPC bug reproducer | expand |
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Hi Andrea, > Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com> > --- > include/tst_safe_macros.h | 5 +++++ > lib/safe_macros.c | 18 ++++++++++++++++++ > 2 files changed, 23 insertions(+) Although Cyril acked this I wonder why we are adding it into the old API. Shouldn't it be added only into tst_safe_macros.c? Kind regards, Petr
Hi! > > Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com> > > --- > > include/tst_safe_macros.h | 5 +++++ > > lib/safe_macros.c | 18 ++++++++++++++++++ > > 2 files changed, 23 insertions(+) > > Although Cyril acked this I wonder why we are adding it into the old API. > Shouldn't it be added only into tst_safe_macros.c? To be honest I do not care that much as long as we do not expose the functions into the headers for old API. We will have to convert the safe_macros.c with coccinelle once all tests are converted and one more function in there does not really matter that much.
> Hi! > > > Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com> > > > --- > > > include/tst_safe_macros.h | 5 +++++ > > > lib/safe_macros.c | 18 ++++++++++++++++++ > > > 2 files changed, 23 insertions(+) > > Although Cyril acked this I wonder why we are adding it into the old API. > > Shouldn't it be added only into tst_safe_macros.c? > To be honest I do not care that much as long as we do not expose the > functions into the headers for old API. We will have to convert the > safe_macros.c with coccinelle once all tests are converted and one more > function in there does not really matter that much. OTOH we have tst_* file, moving it there (+ remove 'm' from functions) would be trivial (and less confusing). Sure, finally coccinelle will be used. Kind regards, Petr
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index f2ce8919b..bd401f094 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -625,6 +625,11 @@ int safe_munlock(const char *file, const int lineno, const char *addr, size_t len); #define SAFE_MUNLOCK(addr, len) safe_munlock(__FILE__, __LINE__, (addr), (len)) +int safe_mprotect(const char *file, const int lineno, const char *addr, + size_t len, int prot); +#define SAFE_MPROTECT(addr, len, prot) \ + safe_mprotect(__FILE__, __LINE__, (addr), (len), (prot)) + int safe_mincore(const char *file, const int lineno, void *start, size_t length, unsigned char *vec); #define SAFE_MINCORE(start, length, vec) \ diff --git a/lib/safe_macros.c b/lib/safe_macros.c index 951e1b064..69ca3eabc 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -1317,6 +1317,24 @@ int safe_munlock(const char *file, const int lineno, const void *addr, return rval; } +int safe_mprotect(const char *file, const int lineno, const void *addr, + size_t len, int prot) +{ + int rval; + + rval = mprotect(addr, len, prot); + + if (rval == -1) { + tst_brkm_(file, lineno, TBROK | TERRNO, NULL, + "mprotect() failed"); + } else if (rval) { + tst_brkm_(file, lineno, TBROK | TERRNO, NULL, + "Invalid mprotect() return value %d", rval); + } + + return rval; +} + int safe_mincore(const char *file, const int lineno, void *start, size_t length, unsigned char *vec) {