Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-03-05 Thread Jessica Clarke
On 5 Mar 2023, at 20:46, Sergey Bugaev wrote: > > Speaking of wrapping the syscall and INTR_MSG_TRAP, I might need a > little help — is there a proper way to tell GCC that my inline > assembly needs a specific register as input _and_ clobbers it? In > Rust, this would be, for instance, > > asm!(

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-03-05 Thread Sergey Bugaev
Speaking of wrapping the syscall and INTR_MSG_TRAP, I might need a little help — is there a proper way to tell GCC that my inline assembly needs a specific register as input _and_ clobbers it? In Rust, this would be, for instance, asm!("whatever", inout("rdi") msg => _) but GCC doesn't like asm

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-03-05 Thread Samuel Thibault
Hello, Sergey Bugaev, le dim. 05 mars 2023 23:12:42 +0300, a ecrit: > On Wed, Mar 1, 2023 at 9:44 AM Luca Dariz wrote: > > Il 28/02/23 15:14, Sergey Bugaev ha scritto: > > > - nothing else is clobbered, in particular not rflags (or is the > > > "reserved" half of rflags clobbered?) and not the re

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-03-05 Thread Sergey Bugaev
On Wed, Mar 1, 2023 at 9:44 AM Luca Dariz wrote: > Il 28/02/23 15:14, Sergey Bugaev ha scritto: > > - nothing else is clobbered, in particular not rflags (or is the > > "reserved" half of rflags clobbered?) and not the registers that > > contain args > > if we follow the usual calling conventions,

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Luca Dariz
Il 28/02/23 15:14, Sergey Bugaev ha scritto: On Tue, Feb 28, 2023 at 4:26 PM Luca Dariz wrote: +/* check if we need to place some arguments on the stack */ +_syscall64_args_stack: +mov EXT(mach_trap_table)(%rax),%r10 /* get number of arguments */ +subq$6,%r10

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Luca Dariz
Il 28/02/23 07:39, Sergey Bugaev ha scritto: On Mon, Feb 27, 2023 at 11:46 PM Luca Dariz wrote: +static inline void wrmsr(uint32_t regaddr, uint64_t value) +{ +uint32_t low=(uint32_t)value, high=((uint32_t)(value >> 32)); I think it'd be more idiomatic in both GNU and Mach styles to put m

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Sergey Bugaev
On Wed, Mar 1, 2023 at 12:04 AM Samuel Thibault wrote: > That looks like pure luck :) That looks like mach_msg was overdesigned, if you ask me :) But at least we don't have mach_msg_overwrite, which has... 9 args! Sergey

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Samuel Thibault
Sergey Bugaev, le mar. 28 févr. 2023 18:15:45 +0300, a ecrit: > On Tue, Feb 28, 2023 at 5:37 PM Samuel Thibault > wrote: > > > -- unlike on Linux? > > > > ? Linux does put only 6 args in registers, too. > > It does not look like Linux has any syscalls that take 7 args or more, Oh, indeed! That

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Sergey Bugaev
On Tue, Feb 28, 2023 at 5:37 PM Samuel Thibault wrote: > Now it also has another meaning: since it clobbers memory, gcc is > not allowed to keep values in registers, i.e. this is a memory > synchronization barrier concerning the compiler. If for instance we have > prepared some data in memory befo

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Samuel Thibault
Sergey Bugaev, le mar. 28 févr. 2023 17:14:05 +0300, a ecrit: > On Tue, Feb 28, 2023 at 4:26 PM Luca Dariz wrote: > > >> +/* check if we need to place some arguments on the stack */ > > >> +_syscall64_args_stack: > > >> +mov EXT(mach_trap_table)(%rax),%r10 /* get number of arguments >

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Samuel Thibault
Sergey Bugaev, le mar. 28 févr. 2023 10:45:47 +0300, a ecrit: > On Tue, Feb 28, 2023 at 10:18 AM Samuel Thibault > wrote: > > > > Sergey Bugaev, le mar. 28 févr. 2023 09:39:40 +0300, a ecrit: > > > > + : \ > > > > + : "c" (regadd

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Sergey Bugaev
On Tue, Feb 28, 2023 at 4:26 PM Luca Dariz wrote: > >> +/* check if we need to place some arguments on the stack */ > >> +_syscall64_args_stack: > >> +mov EXT(mach_trap_table)(%rax),%r10 /* get number of arguments */ > >> +subq$6,%r10 /* the first 6 args are alr

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Samuel Thibault
Luca Dariz, le mar. 28 févr. 2023 14:25:59 +0100, a ecrit: > Il 27/02/23 23:02, Samuel Thibault ha scritto: > > > +#if defined(__x86_64__) && ! defined(USER32) > > > +#define kernel_trap(trap_name,trap_number,number_args) \ > > > +ENTRY(trap_name) \ > > > + movq

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-28 Thread Luca Dariz
Il 27/02/23 23:02, Samuel Thibault ha scritto: Luca Dariz, le lun. 27 févr. 2023 21:45:01 +0100, a ecrit: diff --git a/i386/i386/ldt.h b/i386/i386/ldt.h index b15f11a5..4490f99f 100644 --- a/i386/i386/ldt.h +++ b/i386/i386/ldt.h @@ -45,9 +45,14 @@ #define USER_SCALL 0x07

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Sergey Bugaev
On Tue, Feb 28, 2023 at 10:18 AM Samuel Thibault wrote: > > Sergey Bugaev, le mar. 28 févr. 2023 09:39:40 +0300, a ecrit: > > > + : \ > > > + : "c" (regaddr), "a" (low), "d" (high) \ > > > + : "memory"

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Samuel Thibault
Sergey Bugaev, le mar. 28 févr. 2023 09:39:40 +0300, a ecrit: > > + : \ > > + : "c" (regaddr), "a" (low), "d" (high) \ > > + : "memory" \ > > +); > > +} > > Why "memory" here? C

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Sergey Bugaev
> But then glibc does not actually use mach/syscall_sw.h, it has its own > syscall impl Uh, actually looks like it does both. Fun! :) Sergey

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Sergey Bugaev
On Mon, Feb 27, 2023 at 11:46 PM Luca Dariz wrote: > > While theoretically we could still use the same call gate as for > 32-bit userspace, it doesn't seem very common, and gcc seems to not > encode properly the instruction. Instead we use syscall/sysret as > other kernels (e.g. XNU,Linux). This v

Re: [PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Samuel Thibault
Luca Dariz, le lun. 27 févr. 2023 21:45:01 +0100, a ecrit: > diff --git a/i386/i386/ldt.h b/i386/i386/ldt.h > index b15f11a5..4490f99f 100644 > --- a/i386/i386/ldt.h > +++ b/i386/i386/ldt.h > @@ -45,9 +45,14 @@ > #define USER_SCALL 0x07/* system call gate */ > #ifdef __x86_6

[PATCH 5/5] x86_64: add 64-bit syscall entry point

2023-02-27 Thread Luca Dariz
While theoretically we could still use the same call gate as for 32-bit userspace, it doesn't seem very common, and gcc seems to not encode properly the instruction. Instead we use syscall/sysret as other kernels (e.g. XNU,Linux). This version still has some limitations, but should be enough to sta