From patchwork Tue Aug 21 09:38:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 960173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vlxt34cmz9s5c for ; Tue, 21 Aug 2018 19:39:30 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 429673E63D8 for ; Tue, 21 Aug 2018 11:39:27 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id B9F243E63E1 for ; Tue, 21 Aug 2018 11:39:19 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 31EC11000C19 for ; Tue, 21 Aug 2018 11:39:16 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43735940" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2018 17:39:07 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id AE57B4B6AE0B for ; Tue, 21 Aug 2018 17:39:06 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 21 Aug 2018 17:39:08 +0800 From: Xiao Yang To: Date: Tue, 21 Aug 2018 17:38:57 +0800 Message-ID: <1534844339-8655-2-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <1534844339-8655-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: AE57B4B6AE0B.AB8B0 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 2/4] safe_macros: Add SAFE_MLOCK() and SAFE_MUNLOCK() macros X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Xiao Yang --- include/tst_safe_macros.h | 8 ++++++++ lib/safe_macros.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index a754399..dc6c1f7 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -482,6 +482,14 @@ int safe_mknod(const char *file, const int lineno, const char *pathname, #define SAFE_MKNOD(pathname, mode, dev) \ safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev)) +int safe_mlock(const char *file, const int lineno, const char *addr, + size_t len); +#define SAFE_MLOCK(addr, len) safe_mlock(__FILE__, __LINE__, (addr), (len)) + +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_fanotify_init(const char *file, const int lineno, unsigned int flags, unsigned int event_f_flags); #define SAFE_FANOTIFY_INIT(fan, mode) \ diff --git a/lib/safe_macros.c b/lib/safe_macros.c index 03bd7aa..fa92a6f 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -1006,3 +1006,31 @@ int safe_mknod(const char *file, const int lineno, const char *pathname, return rval; } + +int safe_mlock(const char *file, const int lineno, const void *addr, + size_t len) +{ + int rval; + + rval = mlock(addr, len); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, NULL, + "%s:%d: mlock() failed", file, lineno); + } + + return rval; +} + +int safe_munlock(const char *file, const int lineno, const void *addr, + size_t len) +{ + int rval; + + rval = munlock(addr, len); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, NULL, + "%s:%d: munlock() failed", file, lineno); + } + + return rval; +}