public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nolibc: optimise _start() on x86_64
Date: Sat, 2 Dec 2023 14:23:59 +0100	[thread overview]
Message-ID: <20231202132359.GA15040@1wt.eu> (raw)
In-Reply-To: <38183c29-9b7f-4960-8702-d71ce816cf80@p183>

Hi Alexey,

On Sat, Dec 02, 2023 at 03:45:13PM +0300, Alexey Dobriyan wrote:
> Just jump into _start_c, it is not going to return anyway.

Thanks, but what's upper in the stack there ? I'm trying to make sure
that if _start_c returns we don't get a random behavior. If we get a
systematic crash (e.g. 0 always there) that's fine, what would be
annoying would be random infinite loops etc. In the psABI description
(table 3.9) I'm seeing "undefined" before argc, which I don't find
much appealing.

> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> 
> 	Also, kernel clears all registers before starting process,
> 	I'm not sure why
> 
> 		xor ebp, ebp
> 
> 	was added.

Hmmm psABI says:

  Only the registers listed below have specied values at process entry:

  %rbp The content of this register is unspecied at process initialization
       time, but the user code should mark the deepest stack frame by setting
       the frame pointer to zero.

  %rsp The stack pointer holds the address of the byte with lowest address
	which is part of the stack. It is guaranteed to be 16-byte aligned at
        process entry.

  %rdx a function pointer that the application should register with atexit (BA_OS).

Thus apparently it's documented as being our job to clear it :-/

Willy

  reply	other threads:[~2023-12-02 13:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-02 12:45 [PATCH] nolibc: optimise _start() on x86_64 Alexey Dobriyan
2023-12-02 13:23 ` Willy Tarreau [this message]
2023-12-03 12:00   ` Alexey Dobriyan
2023-12-03 21:37     ` Willy Tarreau

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=20231202132359.GA15040@1wt.eu \
    --to=w@1wt.eu \
    --cc=adobriyan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    /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