Re: arch_prctl()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 22, 2024 at 5:21 AM Adhemerval Zanella Netto
<adhemerval.zanella@xxxxxxxxxx> wrote:
>
>
>
> On 21/08/24 16:41, Alejandro Colomar wrote:
> > Hi Adhemerval, Elliott,
> >
> > On Wed, Aug 21, 2024 at 03:19:02PM GMT, Adhemerval Zanella Netto wrote:
> >> I would use either the kernel interface:
> >>
> >> arch/x86/kernel/process_64.c
> >> 961 SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)
> >>
> >> Where is seems to what most caller do, or maybe something like:
> >>
> >> union __arch_prctl_arg
> >> {
> >>   unsigned long addr;
> >>   unsigned long *vaddr;
> >> };
> >>
> >> int arch_prctl (int option, union __arch_prctl_arg *arg);
> >
> > Or you could use a transparent union:
> >
> >       $ cat arch_prctl.c
> >       union __attribute__((__transparent_union__)) __arch_prctl_arg {
> >               unsigned long  set;
> >               unsigned long  *get;
> >       };
> >
> >       int my_arch_prctl(int op, union __arch_prctl_arg arg2);
> >
> >       int
> >       main(void)
> >       {
> >               unsigned long  u = 0;
> >
> >               my_arch_prctl(1, u);
> >               my_arch_prctl(1, &u);
> >       }
> >       $ gcc -Wall -Wextra -S arch_prctl.c
> >       $
>
> Although we do use __transparent_union__ we have to still handle very old
> compilers:

We can hide the prototype for the older compilers.  Softwares need to
deal with the missing prototype anyway.

> socket/sys/socket.h
>
>  51 /* This is the type we use for generic socket address arguments.
>  52
>  53    With GCC 2.7 and later, the funky union causes redeclarations or
>  54    uses with any of the listed types to be allowed without complaint.
>  55    G++ 2.7 does not support transparent unions so there we want the
>  56    old-style declaration, too.  */
>  57 #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
>
> I guess this is not really required anymore.
>
> >
> >> And for constants, it would require a x86_64 specific sys/prctl.h header
> >> with either the has_include tricks to include the kernel one or to just
> >> copy the kernel one (along with possible a test to check the sync with
> >> kernel definitions).
> >
> > I think including would be simpler, if it's possible.
> >
> > I've seen some problems arise from copying kernel stuff in glibc
> > headers, such as being unable to include both a some kernel and some
> > glibc headers in the same program due to redefinitions.
> >
> >
> > Have a lovely night!
> > Alex
> >
> >



-- 
H.J.





[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux