From patchwork Sun Jan 28 16:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Askar Safin X-Patchwork-Id: 84848 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BD723858431 for ; Sun, 28 Jan 2024 16:40:36 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) by sourceware.org (Postfix) with ESMTPS id 01F243858D32 for ; Sun, 28 Jan 2024 16:40:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01F243858D32 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zohomail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 01F243858D32 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706460011; cv=pass; b=WdMt2OuBXhJaD/ooY052uf1wGuDqp8GOsKtSr6QyVQNutpwJ6SZNVXdx8T5cQI6IUS8eyRpkiEkH2w5DliQiYPPMbYbi7yJF872PrzWBY4p6m3zgWVU0d0ncLgDFlQYav2axmxL4VASsNL6JKjHvQVCCVJX7DoLO3vEQLTLerTY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706460011; c=relaxed/simple; bh=xe8krN6zRWDYr158ofCckl1aJM/3TjfubbfEQ0zFjdI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EBac87dg6sGC7Ae0Q1am4ElMHfpStn/cpzMGJ1yF2T6oUO3HpEFDYDfZIWrq4XVzb6+HPddZFbqIl2hWGDuvNgTSYDSB7rRGZzQ13pd7QiQ9vMnv8D2p6UPHgeCatUsB6k0YHXoRuiN/Rqf1JA0INkfeu/va2rnh121EaGxek8k= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1706460006; cv=none; d=zohomail.com; s=zohoarc; b=W/ja7+1ggb1f0BVFWozZhP0uBpUy952UjEUvPMv6Y9ZpAqhLQyJNM6K6nEESbBifdBM4IjkbRPfVlK3+DaTu740Z3do57PRXm7r5e7PiI+EnoF80V3rDRYntuL/iAygrxqWL/xVftaY2ZmjfDYDP+4lJwUH3LmoEJ917J7Jkxhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706460006; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=7kcFeyS0wvSOAmPcuYaHCjpw6GC7B1CcDP8pOgRpS14=; b=nr4LhL81bszCejUrz0O0AtKW9nRYb51MXFeAzm5N+SpfM1TJgx83EFv0WZpJ1NQmB8mNNDjQve4Oq798cFCmSqh1/OsiNo00I2vqqnqgqT3ZGOq6bKUfg0/Qn2abCwh+aWxFsjXvajMeS7bNou0YPaHEHmbtRFGRAoXa411oROk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=safinaskar@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706460006; s=zm2022; d=zohomail.com; i=safinaskar@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Message-Id:Reply-To; bh=7kcFeyS0wvSOAmPcuYaHCjpw6GC7B1CcDP8pOgRpS14=; b=DzAtmWxgLWHYL+bL1bRAWAJplOLLEjJgYEbcIObeJMTet4K6XEKIbTdHZ2EjoUGM 35IDSIktjAkSAykmQywYQlvJQn/h0sWKSOSStFf3R+eIy+P87HPXapUEjei9hgfd7KW KgbdkSrkRiKqFB76AmvxaxH3DdS5HkRHlNSDO9kY= Received: from localhost.localdomain (212.73.77.98 [212.73.77.98]) by mx.zohomail.com with SMTPS id 1706460003877306.1917394571458; Sun, 28 Jan 2024 08:40:03 -0800 (PST) From: Askar Safin To: libc-alpha@sourceware.org Cc: carlos@redhat.com Subject: [PATCH, RFC] Add public function syscall_no_errno Date: Sun, 28 Jan 2024 19:39:58 +0300 Message-ID: <20240128163958.17421-1-safinaskar@zohomail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Feedback-ID: rr0801122742182d36316ff77952df2e7d000006408b98952096817cf0b395d608633152e0062c324f9c729a:zu08011227e80ece76accc5b0220bf8b140000dd50022e267eee23d77e079b44209e96a0259c72b85090ec84:rf0801122cfcad0a00d38012da30cad1eb00003b737a48d93dde75b62b617f1a4446550d48c012ba30a0f5337bf8d05002:ZohoMail X-ZohoMailClient: External X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Hi! I want glibc to have function "syscall_no_errno" on Linux. It should do the same "syscall" does, but it should not interpret return value and set errno. This is useful for calling syscalls such as getuid. I. e. now the user can call directly all syscalls including getuid and similar. I add example patch. It is quick-and-dirty. I was unable to figure out how to add function to headers. So, please, don't apply it as-is. I just want to know do you agree with my proposal. If yes, I will try to write better patch. I will repeat: currently glibc is simply incomplete, because it does not provide a way to call directly syscalls, such as getuid. So the user have to craft assembly, which is very difficult. The patch is against current master, i. e. ae49a7b29acc184b03c2a6bd6ac01b5e08efd54f diff --git a/misc/Versions b/misc/Versions index d5b348e8..ad37a4c2 100644 --- a/misc/Versions +++ b/misc/Versions @@ -71,7 +71,7 @@ libc { # s* sbrk; select; setdomainname; setfsent; sethostent; sethostid; sethostname; setlogmask; setmntent; setregid; setreuid; setttyent; setusershell; sstk; - stty; sync; syscall; syslog; + stty; sync; syscall; syslog; syscall_no_errno; # t* tdelete; tfind; truncate; tsearch; ttyslot; twalk; diff --git a/posix/unistd.h b/posix/unistd.h index 54d7d752..2f0f6e79 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -1089,6 +1089,7 @@ extern void *sbrk (intptr_t __delta) __THROW; In Mach, all system calls take normal arguments and always return an error code (zero for success). */ extern long int syscall (long int __sysno, ...) __THROW; +extern long int syscall_no_errno (long int __sysno, ...) __THROW; #endif /* Use misc. */ diff --git a/sysdeps/unix/sysv/linux/syscall-names.list b/sysdeps/unix/sysv/linux/syscall-names.list index aac065e7..dac4d78e 100644 --- a/sysdeps/unix/sysv/linux/syscall-names.list +++ b/sysdeps/unix/sysv/linux/syscall-names.list @@ -612,6 +612,7 @@ sys_epoll_create sys_epoll_ctl sys_epoll_wait syscall +syscall_no_errno sysfs sysinfo syslog diff --git a/sysdeps/unix/sysv/linux/syscall.c b/sysdeps/unix/sysv/linux/syscall.c index 3cff1d97..481b18a4 100644 --- a/sysdeps/unix/sysv/linux/syscall.c +++ b/sysdeps/unix/sysv/linux/syscall.c @@ -41,3 +41,20 @@ syscall (long int number, ...) } return r; } +long int +syscall_no_errno (long int number, ...) +{ + va_list args; + + va_start (args, number); + long int a0 = va_arg (args, long int); + long int a1 = va_arg (args, long int); + long int a2 = va_arg (args, long int); + long int a3 = va_arg (args, long int); + long int a4 = va_arg (args, long int); + long int a5 = va_arg (args, long int); + va_end (args); + + long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5); + return r; +} diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index aea7848e..55d9dadd 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -1761,6 +1761,7 @@ GLIBC_2.2.5 sys_nerr D 0x4 GLIBC_2.2.5 sys_sigabbrev D 0x200 GLIBC_2.2.5 sys_siglist D 0x200 GLIBC_2.2.5 syscall F +GLIBC_2.2.5 syscall_no_errno F GLIBC_2.2.5 sysconf F GLIBC_2.2.5 sysctl F GLIBC_2.2.5 sysinfo F diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S index 43af8087..04483251 100644 --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S @@ -26,6 +26,18 @@ .text +ENTRY (syscall_no_errno) + movq %rdi, %rax /* Syscall number -> rax. */ + movq %rsi, %rdi /* shift arg1 - arg5. */ + movq %rdx, %rsi + movq %rcx, %rdx + movq %r8, %r10 + movq %r9, %r8 + movq 8(%rsp),%r9 /* arg6 is on the stack. */ + syscall /* Do the system call. */ + ret /* Return to caller. */ + +PSEUDO_END_NOERRNO (syscall_no_errno) ENTRY (syscall) movq %rdi, %rax /* Syscall number -> rax. */ movq %rsi, %rdi /* shift arg1 - arg5. */