From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1202C43334 for ; Wed, 29 Jun 2022 02:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiF2CmR (ORCPT ); Tue, 28 Jun 2022 22:42:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbiF2CmQ (ORCPT ); Tue, 28 Jun 2022 22:42:16 -0400 Received: from mail.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B3C71FCD9; Tue, 28 Jun 2022 19:42:14 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 7E9661E80D11; Wed, 29 Jun 2022 10:41:05 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KkPVWUOZtBJR; Wed, 29 Jun 2022 10:41:02 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id A51DF1E80CDC; Wed, 29 Jun 2022 10:41:02 +0800 (CST) From: Li kunyu To: skhan@linuxfoundation.org Cc: kunyu@nfschina.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: Re: [PATCH] tools: Strong conversion of void type pointer could be removed Date: Wed, 29 Jun 2022 10:42:06 +0800 Message-Id: <20220629024207.6523-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <9b587975-db5b-c7bf-eb8f-bd6e5c3d9f54@linuxfoundation.org> References: <9b587975-db5b-c7bf-eb8f-bd6e5c3d9f54@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shuah, now I can't paste the test code, so I could write a demo and paste it: -------------source--------------- #include #include struct ucontext { struct ucontext *uc_link; unsigned long uc_flags; sigset_t uc_sigmask; struct ucontext *uc_mcontext; }; typedef struct ucontext ucontext_t; void sigsegv(void *ctx_void) { ucontext_t *ctx = (ucontext_t*)ctx_void; ucontext_t *ctx2 = (int *)ctx_void; ucontext_t *ctx3 = ctx_void; printf("ctx:%p, ctx2:%p, ctx3:%p.\n", ctx, ctx2, ctx3); } int main() { ucontext_t *test = malloc(sizeof(ucontext_t)); sigsegv(test); return 0; } -------------------------------------- The result is CTX: 0x563D96CE5010, CTX2:0x563D96CE5010, CTx3:0x563D96CE5010. Now force ucontext_t and int pointers are the same as the addresses obtained without forced conversion. Now I'll paste the assembly code for them: |0x700 push %rbp │ │0x701 mov %rsp,%rbp │ │0x704 sub $0x30,%rsp │ │0x708 mov %rdi,-0x28(%rbp) │ │0x70c mov -0x28(%rbp),%rax │ │0x710 mov %rax,-0x8(%rbp) │ │0x714 mov -0x28(%rbp),%rax │ │0x718 mov %rax,-0x10(%rbp) │ │0x71c mov -0x28(%rbp),%rax │ │0x720 mov %rax,-0x18(%rbp) │ │0x724 mov -0x18(%rbp),%rcx │ │0x728 mov -0x10(%rbp),%rdx │ │0x72c mov -0x8(%rbp),%rax │ │0x730 mov %rax,%rsi │ │0x733 lea 0xba(%rip),%rdi # 0x7f4 │ │0x73a mov $0x0,%eax │ │0x73f callq 0x5a0 │ │0x744 nop │ │0x745 leaveq │ │0x746 retq