Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160512002230.GA23989@dora.lan>
Date: Wed, 11 May 2016 19:22:30 -0500
From: Bobby Bingham <koorogi@...rogi.info>
To: musl@...ts.openwall.com
Subject: Re: Deduplicating __NR_* and SYS_* syscall defines

On Wed, May 11, 2016 at 05:53:12PM -0400, Rich Felker wrote:
> On Mon, May 09, 2016 at 07:26:37PM -0500, Bobby Bingham wrote:
> > During the powerpc64 review, Rich mentioned wanting to replace the
> > arch/*/bits/syscall.h files with .in files that would be preprocessed with
> > something like:
> > 
> >     sed -e p -e s/__NR_/SYS_/ < $< > $@
> > 
> > This would eliminate a lot of intra-file duplication here.
> > 
> > I took a look, and this won't quite work as-is, because the following
> > lines in the arm version would end up outputting duplicate definitions:
> > 
> >     #define __ARM_NR_breakpoint	0x0f0001
> >     #define __ARM_NR_cacheflush	0x0f0002
> >     #define __ARM_NR_usr26		0x0f0003
> >     #define __ARM_NR_usr32		0x0f0004
> >     #define __ARM_NR_set_tls	0x0f0005
> 
> This is easily fixed by something like:
> 
> sed -e /__NR_/p -e s/__NR_/SYS_/ < $< > $@

Neat.  I didn't know about /p.

Any objection to using Alexander's approach to avoid interleaving the
__NR_* and SYS_* lines?

> 
> > Same thing for this line in x32:
> > 
> >     #define __X32_SYSCALL_BIT        0x40000000
> 
> In general we've tried to eliminate this sort of macro and direct-code
> the values. I would be in favor of doing the same for x32 I think. But
> with my fixed sed command (above) I think that change is unnecssary
> and orthogonal to the deduplication.

I'll submit a separate patch to clean this up.

> 
> > I'm thinking something like the following awk script would work:
> > 
> >     {
> >         print
> >     }
> > 
> >     $1 ~ /^#(define|undef)$/ && $2 ~ /^__NR_/ {
> >         sub(/__NR_/, "SYS_", $2)
> >         print
> >     }
> > 
> > The handling for #undef is for the x32 file.  It looks like only the
> > `#undef __NR_getdents' in that file is actually necessary, and even that
> > could be avoided by just omitting the earlier line:
> > 
> >     #define __NR_getdents (__X32_SYSCALL_BIT + 78)
> 
> I don't see why any #undef is needed here; this looks like leftover
> cruft that was not properly cleaned up. All the logic for replacing
> syscall numbers belongs in src/internal/syscall.h or
> arch/$ARCH/syscall_arch.h, I think.

Ok.

> 
> > So maybe we can get rid of the #undefs there, and simplify the awk script
> > accordingly.
> > 
> > Thoughts on this approach?  If this sounds ok, I'll submit a patch.
> 
> I'd rather use sed than awk if possible since it's more universally
> available and understood.

I must be the exception then :)

Bobby

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.