@@ -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) \
@@ -1317,6 +1317,46 @@ int safe_munlock(const char *file, const int lineno, const void *addr,
return rval;
}
+int safe_mprotect(const char *file, const int lineno, void *addr,
+ size_t len, int prot)
+{
+ int rval;
+ char prot_buf[16];
+
+ switch (prot) {
+ case PROT_NONE:
+ snprintf(prot_buf, 16, "PROT_NONE");
+ break;
+ case PROT_WRITE:
+ snprintf(prot_buf, 16, "PROT_WRITE");
+ break;
+ case PROT_READ:
+ snprintf(prot_buf, 16, "PROT_READ");
+ break;
+ case PROT_EXEC:
+ snprintf(prot_buf, 16, "PROT_EXEC");
+ break;
+ default:
+ snprintf(prot_buf, 16, "UNKNOWN");
+ break;
+ }
+
+ tst_res_(file, lineno, TDEBUG,
+ "mprotect(%p, %d, %s)", addr, len, prot_buf);
+
+ 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)
{