lkml.org 
[lkml]   [2024]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v12 11/20] KVM: xen: allow shared_info to be mapped by fixed HVA
From
Date
On Thu, 2024-02-08 at 16:51 +0000, Paul Durrant wrote:
> On 08/02/2024 16:48, Sean Christopherson wrote:
> > On Thu, Feb 08, 2024, Paul Durrant wrote:
> > > With the benefit of some sleep, I'm wondering why 0 is a 'ridiculous'
> > > invalid value for a *virtual* address? Surely it's essentially a numerical
> > > cast of the canonically invalid NULL pointer?
> >
> > It's legal to mmap() virtual address '0', albeit not by default:

Well yes, to make dosemu work. But if you attempt to actually *do* that
in C code, the compiler itself doesn't cope...

$ cat foo.c
int foo(int *bar)
{
if (bar)
return 0;
return *bar;
}
$ gcc -O2 -S -o- foo.c
..
foo:
LFB0:
.cfi_startproc
endbr64
testq %rdi, %rdi
je .L4
xorl %eax, %eax
ret
.p2align 4,,10
.p2align 3
L4:
movl 0, %eax
ud2
.cfi_endproc
LFE0:
.size foo, .-foo

Note the ud2 instead of actually trying to dereference it.

Using anything except NULL as the "no value" value doesn't make sense
to me. It violates the principle of least surprise and would be a
really bad API.
[unhandled content-type:application/pkcs7-signature]
\
 
 \ /
  Last update: 2024-05-27 14:55    [W:0.101 / U:0.408 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site