From patchwork Thu Feb 11 17:37:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 42018 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 D55EE383F841; Thu, 11 Feb 2021 17:37:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D55EE383F841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1613065039; bh=EnxBm0s4f1xqn3PAdeP4WAiMC+Ol5zWSpKfgJZpbIsE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RfrI4KvqGsTCTdDKpWvEktBmfkbziq05ev/MhYsXdWmR/0DEarAMHA2+I+Sr/87GY k/YKZtTL4slBemwZcglP4d4WO/rMoAjfKmnzd0d+lt0vdjyN/WiXQw1fLRCP+J+9Cg FrBfqpIUDxXfLx2UKAQanyxiJ2noD3hoQBeJeC4s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 27EA53870868 for ; Thu, 11 Feb 2021 17:37:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 27EA53870868 Received: by mail-pl1-x62f.google.com with SMTP id x9so3689974plb.5 for ; Thu, 11 Feb 2021 09:37:16 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=EnxBm0s4f1xqn3PAdeP4WAiMC+Ol5zWSpKfgJZpbIsE=; b=bxxELLgb+iBmqSirpf+oxRUh0dlk8Zncn6XcMIFI1s+q+vvOi1VFzoH/YKDxyPPdFn BR7LoOJUz4FQcsjoAYLERXh84xSy1PEhXDdebq1YImMrBrWu95vNvuGVPGhu6dzfIdyb x8ctYrBNtYI5HWaespmNGExGIn3uHpLe36psfMC8eybO/1C+341UkfNCGa4m32u+CDbP sOvn1ROPYWWhOwZFGUopPsrqBcyw8bDasa7R9SxskVLPi9onqUThDxpC4C3H6UaBASnJ gjdQhqCgRN0ufKPu0rvugPGI5KKbGm2hDClKvfw8fHxa0cC+J3twwpjka9FO80NyvWTG +zjQ== X-Gm-Message-State: AOAM532Zqyk8MTi8Nc4nqmw9lCC0Pi1UUNtPivwO6Bd6qqhzzVVHx9fK 5OaBqboS+uFf3zvNbY2/TEbs5KxEs2Y= X-Google-Smtp-Source: ABdhPJwA+WSYX5zUVXy8r3VRqsn4nMHheinXOAWDBtYJGptJO/Hftp3QOaoQ3tXspch7K2t//IPT9A== X-Received: by 2002:a17:90b:4ad2:: with SMTP id mh18mr4838153pjb.137.1613065034707; Thu, 11 Feb 2021 09:37:14 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id c18sm6225276pfi.167.2021.02.11.09.37.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 09:37:14 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 05B821A0107 for ; Thu, 11 Feb 2021 09:37:13 -0800 (PST) To: libc-alpha@sourceware.org Subject: [RFC] : An API for tagged address Date: Thu, 11 Feb 2021 09:37:11 -0800 Message-Id: <20210211173711.71736-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" An API for tagged address: /* Get the current address bits used in address translation. */ extern unsigned int get_tagged_address_bits (void); /* Get the current mask for address bits used in address translation. */ extern uintptr_t get_tagged_address_mask (void); /* Set the mask for address bits used in address translation. Return 0 on success. Return -1 on error. */ extern int set_tagged_address_mask (uintptr_t __mask); /* Return the tagged address of __ADDR with the tag value __TAG. */ extern void *tag_address (void *__addr, unsigned int __tag); /* Return the untagged address of __ADDR. */ extern void *untag_address (void *__addr); /* TRUE if constant address BITS is a valid tagged address bits. */ #define TAGGED_ADDRESS_VALID_BITS(BITS) /* A mask for constant address BITS used in address translation. */ #define TAGGED_ADDRESS_MASK(BITS) --- bits/tagged-address.h | 25 +++++++++ include/sys/tagged-address.h | 9 +++ misc/Makefile | 3 +- misc/Versions | 7 +++ misc/set-tagged-address-mask.c | 28 ++++++++++ misc/sys/tagged-address.h | 56 +++++++++++++++++++ misc/tagged-address.c | 55 ++++++++++++++++++ sysdeps/generic/inline-tagged-address.h | 43 ++++++++++++++ sysdeps/unix/sysv/linux/i386/libc.abilist | 5 ++ .../unix/sysv/linux/x86_64/64/libc.abilist | 5 ++ .../unix/sysv/linux/x86_64/x32/libc.abilist | 5 ++ 11 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 bits/tagged-address.h create mode 100644 include/sys/tagged-address.h create mode 100644 misc/set-tagged-address-mask.c create mode 100644 misc/sys/tagged-address.h create mode 100644 misc/tagged-address.c create mode 100644 sysdeps/generic/inline-tagged-address.h diff --git a/bits/tagged-address.h b/bits/tagged-address.h new file mode 100644 index 0000000000..24f865b8af --- /dev/null +++ b/bits/tagged-address.h @@ -0,0 +1,25 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_TAGGED_ADDRESS_H +#define _BITS_TAGGED_ADDRESS_H 1 + +#ifndef _SYS_TAGGED_ADDRESS_H +# error "Never include this file directly. Use instead" +#endif + +#endif /* */ diff --git a/include/sys/tagged-address.h b/include/sys/tagged-address.h new file mode 100644 index 0000000000..2e902f72b2 --- /dev/null +++ b/include/sys/tagged-address.h @@ -0,0 +1,9 @@ +#include + +#ifndef _ISOMAC +# include +# define get_tagged_address_bits() __get_tagged_address_bits () +# define get_tagged_address_mask() __get_tagged_address_mask () +# define tag_address(addr, tag) __tag_address ((addr), (tag)) +# define untag_address(addr) __untag_address ((addr)) +#endif diff --git a/misc/Makefile b/misc/Makefile index b08d7c68ab..c5d8838486 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -73,7 +73,8 @@ routines := brk sbrk sstk ioctl \ fgetxattr flistxattr fremovexattr fsetxattr getxattr \ listxattr lgetxattr llistxattr lremovexattr lsetxattr \ removexattr setxattr getauxval ifunc-impl-list makedev \ - allocate_once fd_to_filename single_threaded + allocate_once fd_to_filename single_threaded \ + tagged-address set-tagged-address-mask generated += tst-error1.mtrace tst-error1-mem.out \ tst-allocate_once.mtrace tst-allocate_once-mem.out diff --git a/misc/Versions b/misc/Versions index 95666f6548..9e9ded4d5c 100644 --- a/misc/Versions +++ b/misc/Versions @@ -164,6 +164,13 @@ libc { GLIBC_2.32 { __libc_single_threaded; } + GLIBC_2.34 { + get_tagged_address_bits; + get_tagged_address_mask; + set_tagged_address_mask; + tag_address; + untag_address; + } GLIBC_PRIVATE { __madvise; __mktemp; diff --git a/misc/set-tagged-address-mask.c b/misc/set-tagged-address-mask.c new file mode 100644 index 0000000000..89902b47c2 --- /dev/null +++ b/misc/set-tagged-address-mask.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Set the mask for address bits used in address translation. Return 0 + on success. Return -1 on error. */ + +int +set_tagged_address_mask (uintptr_t mask) +{ + __set_errno (ENOSYS); + return -1; +} diff --git a/misc/sys/tagged-address.h b/misc/sys/tagged-address.h new file mode 100644 index 0000000000..540db14dd2 --- /dev/null +++ b/misc/sys/tagged-address.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_TAGGED_ADDRESS_H +#define _SYS_TAGGED_ADDRESS_H 1 + +#include +#include +#include + +#if defined TAGGED_ADDRESS_VALID_BITS && defined __GNUC__ +/* A mask for constant address BITS used in address translation. */ +# define TAGGED_ADDRESS_MASK(BITS) \ + (__extension__ \ + ({ \ + _Static_assert (TAGGED_ADDRESS_VALID_BITS (BITS), \ + "Tagged address bits must be valid"); \ + (((uintptr_t) 1) << (BITS)) - 1; \ + })) +#endif + +__BEGIN_DECLS + +/* Get the current address bits used in address translation. */ +extern unsigned int get_tagged_address_bits (void); + +/* Get the current mask for address bits used in address translation. */ +extern uintptr_t get_tagged_address_mask (void); + +/* Set the mask for address bits used in address translation. Return 0 + on success. Return -1 on error. */ +extern int set_tagged_address_mask (uintptr_t __mask); + +/* Return the tagged address of __ADDR with the tag value __TAG. */ +extern void *tag_address (void *__addr, unsigned int __tag); + +/* Return the untagged address of __ADDR. */ +extern void *untag_address (void *__addr); + +__END_DECLS + +#endif /* */ diff --git a/misc/tagged-address.c b/misc/tagged-address.c new file mode 100644 index 0000000000..df474f3d0b --- /dev/null +++ b/misc/tagged-address.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#undef get_tagged_address_bits +#undef get_tagged_address_mask +#undef tag_address +#undef untag_address + +/* Get the current address bits used in address translation. */ + +unsigned int +get_tagged_address_bits (void) +{ + return __get_tagged_address_bits (); +} + +/* Get the current mask for address bits used in address translation. */ + +uintptr_t +get_tagged_address_mask (void) +{ + return __get_tagged_address_mask (); +} + +/* Return the tagged address of ADDR with the tag value TAG. */ + +void * +tag_address (void *addr, unsigned int tag) +{ + return __tag_address (addr, tag); +} + +/* Return the untagged address of ADDR. */ + +void * +untag_address (void *addr) +{ + return __untag_address (addr); +} diff --git a/sysdeps/generic/inline-tagged-address.h b/sysdeps/generic/inline-tagged-address.h new file mode 100644 index 0000000000..a016b16f21 --- /dev/null +++ b/sysdeps/generic/inline-tagged-address.h @@ -0,0 +1,43 @@ +/* Inline tagged address functions. Generic version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +static inline unsigned int +__get_tagged_address_bits (void) +{ + return sizeof (uintptr_t) * 8; +} + +static inline uintptr_t +__get_tagged_address_mask (void) +{ + return (uintptr_t) -1; +} + +static inline void * +__tag_address (void *addr, unsigned int tag) +{ + return addr; +} + +static inline void * +__untag_address (void *addr) +{ + return addr; +} diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index ddc5837059..464c8af2ee 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -2241,6 +2241,11 @@ GLIBC_2.33 mknod F GLIBC_2.33 mknodat F GLIBC_2.33 stat F GLIBC_2.33 stat64 F +GLIBC_2.34 get_tagged_address_bits F +GLIBC_2.34 get_tagged_address_mask F +GLIBC_2.34 set_tagged_address_mask F +GLIBC_2.34 tag_address F +GLIBC_2.34 untag_address F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 2744bba4af..7486bf09bc 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2088,6 +2088,11 @@ GLIBC_2.33 mknod F GLIBC_2.33 mknodat F GLIBC_2.33 stat F GLIBC_2.33 stat64 F +GLIBC_2.34 get_tagged_address_bits F +GLIBC_2.34 get_tagged_address_mask F +GLIBC_2.34 set_tagged_address_mask F +GLIBC_2.34 tag_address F +GLIBC_2.34 untag_address F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index ce2f4fb72b..d88202196f 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2185,3 +2185,8 @@ GLIBC_2.33 mknod F GLIBC_2.33 mknodat F GLIBC_2.33 stat F GLIBC_2.33 stat64 F +GLIBC_2.34 get_tagged_address_bits F +GLIBC_2.34 get_tagged_address_mask F +GLIBC_2.34 set_tagged_address_mask F +GLIBC_2.34 tag_address F +GLIBC_2.34 untag_address F