RE: what is the best binding for stat() on Linux

  • From: William Adams <william_a_adams@xxxxxxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Sun, 11 Oct 2015 14:59:23 +0000



----------------------------------------

Date: Sat, 10 Oct 2015 22:38:44 -0700
Subject: Re: what is the best binding for stat() on Linux
From: chighland@xxxxxxxxx
To: luajit@xxxxxxxxxxxxx

On Sat, Oct 10, 2015 at 10:51 AM, William Adams
<william_a_adams@xxxxxxxxxxx> wrote:

It would be nice if there were a middle project, something like
ljplatform. This is where all the platform specific #defines, and
syscalls would go. Then projects such as ljsyscall, which intends to
avoid the use of libc could take that as a dependency. Similarly,
LJIT2libc, which intends to utilize the embedded libc, and avoid using
syscall, could also take a dependency, because they both end up
defining a ton of the same stuff.

It could also make sense to export this data from glibc. glibc
already generates regular system call wrappers from a table.


Not quite sure I understand this comment.

what is needed are the hundreds of declarations wrapped up in ffi.cdef
blocks.

Are you implying that you can get that automatically out of glibc?

For example, the definitions for the epoll structure, the NR_xxx constants,
the
inode_t and all the other special typedefs and defines. You need those to be
platform and OS specific, easily selectable from LJIT2libc or ljsyscall.

-- William


If nothing else, gcc -E will get you fully-preprocessed source for a
desired header file. From there you only need to recognize a few
important patterns (not full C-language parsing) to know what to pull
out and cdef.

You can do this in the build process; once you've digested the
headers, it should remain valid for that platform more or less
indefinitely.

/s/ Adam


Getting the definitions is not the hard part.  The challenge is organizing them
in
such a way that they are easy to consume by projects such as ljsyscall and
LJIT2libc.

ljsyscall already does this.  If you look at it, it nicely splits out
definitions according
to architecture and OS (bsd, netbsd, linux, osx...). 

I am just suggesting that this particular aspect of ljsyscall could be split
out into
its own project.  Because I'm pretty much doing the same thing for LJIT2libc,
for example.
Why don't I just depend on ljsyscall?  Because I don't want the rest of what it
brings.  I just
want those cdefs and constants which are related to the types.  In my
particular case,
I then throw in all the cdefs related to the function calls in libc.

Some other project might use them in some other way.


Other related posts: