From patchwork Fri Nov 23 00:19:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Boyko X-Patchwork-Id: 1002077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m8TtUDLs"; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 431H5D18DBz9s1x for ; Fri, 23 Nov 2018 11:20:12 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id D11C6100BF; Fri, 23 Nov 2018 01:20:04 +0100 (CET) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by helium.openadk.org (Postfix) with ESMTPS id 0F6B3100BF for ; Fri, 23 Nov 2018 01:20:02 +0100 (CET) Received: by mail-lf1-f66.google.com with SMTP id v5so7543358lfe.7 for ; Thu, 22 Nov 2018 16:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=3AJaWsuLoHg4kRF0ruN8EMeSdFALR87cPdp3oVuWACI=; b=m8TtUDLsKYZ8tUdRTp19civ9yPfdlUoiCLSlhbru39baBJ1u/NrscGpe/LrABv36+A d5G3gkzBlmaa7e6wDZ1XarYa6Rx4f4NBfl5NJ1ls1SrfrhZN0/iEPmlDTwDUeM9ZADiF wXmhcsE1vgt0pjnk6H7DZUFBKvweNriD2X8oPzqBUPeNWrn/xYlHdVW9Nf5HJmhWyhPU 1y0KIcmwQwVZ/F1tzybNYhFFfkvOuDuBDat2lxWQkMZZYw3QR1xGWukzBYDO2Repw2LE /I7IOVP6PyPcl0nDBGB/p7Yp8v+Oi0y9OBCfuJo/N8P5HmiXscFsaDHpxeeXOlOz8eud tNOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=3AJaWsuLoHg4kRF0ruN8EMeSdFALR87cPdp3oVuWACI=; b=kt+EqD/UyVF5JyrhcD4dnNY7Bm7dOxWwGmQ+56bLt62YErJA3uV6cnoPvrggoewkmS h4as53Sznn7UJM7YtXKm8GEhM5CPmy9PLSJ9S8J+L4Wbhi5buVNLVUhTJyz2bnMErZ4j /NrmVvux8gTbd5KmE4xv/WoxOpzlj0EIxahSVUT5bzRcUmyCAIs1UaUsxx1Y4iYeX9zL pppr2TgdaICvtckdl8X28GTmXXcV8blPwbRMFZ6/Hsi0cgje5024U0j1gqplso/UUye0 V8cNMtskSkPVNxlgh+gWjAAWqo2Hjb8Q+9HIv9gaSOn5kphPbpxX+6SC6LiO37k5MbSm nzWQ== X-Gm-Message-State: AGRZ1gLOC7BZKV9oLEffymKiq0qDhtCyrgKRm7o8DRI7FwaZFAD0RRf/ kvC5PfzXLR0RB9CW+rfQGEvMOf+v X-Google-Smtp-Source: AJdET5eqSto6XnWaqVJiyCFwRJhfZzu1/tRQ6DXncFWQB7L0JBWtpj5vt1kzdiP6cIFj3Pl9XSz0cQ== X-Received: by 2002:a19:9653:: with SMTP id y80mr7759199lfd.66.1542932401337; Thu, 22 Nov 2018 16:20:01 -0800 (PST) Received: from asus-nduk.lan ([193.93.219.3]) by smtp.gmail.com with ESMTPSA id s8-v6sm6646099ljh.14.2018.11.22.16.20.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 16:20:00 -0800 (PST) From: Volodymyr Boyko To: devel@uclibc-ng.org Date: Fri, 23 Nov 2018 02:19:55 +0200 Message-Id: <20181123001955.4846-1-boyko.cxx@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [uclibc-ng-devel] [PATCH] Defined INLINE_SYSCALL_NOERR_NCS in mips/bits/syscalls.h X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" On Linux/MIPS (O32 ABI) for system call we have two result registers - v0 and a3. v0 contains actual syscall result on success or error number on fail, a3 set to 0/1 for indicating syscall success/fail. (if a3 == 1, v0 contains errno). Now as we can see from definition of handle_sys (arch/mips/kernel/scall32-o32.S), handler treats returned by syscall function (let's call "original") values in range [-EMAXERRNO; 0[ as -errno, a3 is set to 1 and final returned (to userspace) value is (-original). INLINE_SYSCALL_NOERR_NCS defined in mips/bits/syscalls.h will handle this behaviour. Signed-off-by: Volodymyr Boyko --- libc/sysdeps/linux/mips/bits/syscalls.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libc/sysdeps/linux/mips/bits/syscalls.h b/libc/sysdeps/linux/mips/bits/syscalls.h index 787bb7d..b8f8059 100644 --- a/libc/sysdeps/linux/mips/bits/syscalls.h +++ b/libc/sysdeps/linux/mips/bits/syscalls.h @@ -29,6 +29,16 @@ } \ result_var; }) +#define INLINE_SYSCALL_NOERR_NCS(name, nr, args...) \ +({ \ + INTERNAL_SYSCALL_DECL(err); \ + long res = INTERNAL_SYSCALL_NCS(name, err, nr, args); \ + if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, err))) { \ + res = -res; \ + } \ + res; \ +}) + #define INTERNAL_SYSCALL_DECL(err) long err attribute_unused #define INTERNAL_SYSCALL_ERROR_P(val, err) ((long) (err))