From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id BD67F46970E for ; Fri, 10 Jan 2020 17:27:52 +0300 (MSK) Received: by mail-lj1-f194.google.com with SMTP id a13so2315870ljm.10 for ; Fri, 10 Jan 2020 06:27:52 -0800 (PST) From: Cyrill Gorcunov Date: Fri, 10 Jan 2020 17:27:49 +0300 Message-Id: <20200110142749.11577-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] fiber: set diag error on madvise, mprotect fails List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Currently we use say_x to log if error happened. Strictly speaking when madvise is used to relax pressue on mm subsystem since we started to use bigger stacks (due to libreadline increased memory usage). Same time mprotect usage is more sensitive -- we setup guard pages with its help and when failing it is definitely an error which we should not only mention in logger but provide a caller diag error. Here is an example from memcached | expire_fiber = fiber_new(name, memcached_expire_loop); | const box_error_t *err = box_error_last(); | if (err) { | say_error("Can't start the expire fiber"); | say_error("%s", box_error_message(err)); | return -1; | } Thus make fiber_madivse and fiber_mprotect being inline functions instead of macros and setup diag error accordingly. Fixes #4722 Reported-by: Alexander Turenko Signed-off-by: Cyrill Gorcunov --- issue https://github.com/tarantool/tarantool/issues/4722 branch gorcunov/gh-4722-mprotect-diag-error src/lib/core/fiber.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index 00ae8cded..724260bad 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -173,21 +173,27 @@ static int (*fiber_invoke)(fiber_func f, va_list ap); #define ASAN_FINISH_SWITCH_FIBER(var_name) #endif -#define fiber_madvise(addr, len, advice) \ -({ \ - int err = madvise((addr), (len), (advice)); \ - if (err) \ - say_syserror("madvise"); \ - err; \ -}) - -#define fiber_mprotect(addr, len, prot) \ -({ \ - int err = mprotect((addr), (len), (prot)); \ - if (err) \ - say_syserror("mprotect"); \ - err; \ -}) +static inline int +fiber_madvise(void *addr, size_t len, int advice) +{ + if (madvise(addr, len, advice)) { + diag_set(SystemError, "fiber madvise %p:%zu:%d failed", + addr, len, advice); + return -1; + } + return 0; +} + +static inline int +fiber_mprotect(void *addr, size_t len, int prot) +{ + if (mprotect(addr, len, prot)) { + diag_set(SystemError, "fiber mprotect %p:%zu:%d failed", + addr, len, prot); + return -1; + } + return 0; +} #if ENABLE_FIBER_TOP static __thread bool fiber_top_enabled = false; -- 2.20.1