From: Li kunyu <kunyu@nfschina.com>
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 [thread overview]
Message-ID: <20220629024207.6523-1-kunyu@nfschina.com> (raw)
In-Reply-To: <9b587975-db5b-c7bf-eb8f-bd6e5c3d9f54@linuxfoundation.org>
Hi Shuah, now I can't paste the test code, so I could write a demo and paste it:
-------------source---------------
#include <stdio.h>
#include <stdlib.h>
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 <sigsegv> push %rbp │
│0x701 <sigsegv+1> mov %rsp,%rbp │
│0x704 <sigsegv+4> sub $0x30,%rsp │
│0x708 <sigsegv+8> mov %rdi,-0x28(%rbp) │
│0x70c <sigsegv+12> mov -0x28(%rbp),%rax │
│0x710 <sigsegv+16> mov %rax,-0x8(%rbp) │
│0x714 <sigsegv+20> mov -0x28(%rbp),%rax │
│0x718 <sigsegv+24> mov %rax,-0x10(%rbp) │
│0x71c <sigsegv+28> mov -0x28(%rbp),%rax │
│0x720 <sigsegv+32> mov %rax,-0x18(%rbp) │
│0x724 <sigsegv+36> mov -0x18(%rbp),%rcx │
│0x728 <sigsegv+40> mov -0x10(%rbp),%rdx │
│0x72c <sigsegv+44> mov -0x8(%rbp),%rax │
│0x730 <sigsegv+48> mov %rax,%rsi │
│0x733 <sigsegv+51> lea 0xba(%rip),%rdi # 0x7f4 │
│0x73a <sigsegv+58> mov $0x0,%eax │
│0x73f <sigsegv+63> callq 0x5a0 <printf@plt> │
│0x744 <sigsegv+68> nop │
│0x745 <sigsegv+69> leaveq │
│0x746 <sigsegv+70> retq
next prev parent reply other threads:[~2022-06-29 2:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 8:56 Li kunyu
2022-06-27 19:57 ` Shuah Khan
2022-06-29 2:42 ` Li kunyu [this message]
2022-06-29 23:09 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220629024207.6523-1-kunyu@nfschina.com \
--to=kunyu@nfschina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®