Page Aligned allocation

[email protected] (Eyal BenDavid) Thu, 18 Oct 2018 18:39:26 +0300
Newsgroups perl.xs
Message-ID <CAPrnrPBA9=ykGzion6LVG5bN3hjvT_z-XWck=dd1S6vXoPkR6w@mail.gmail.com>
Hi all,

A driver exposes its API by ioctl interface.

The argument for the ioctl call is a memory buffer that its address
must aligned to OS page size.

For example the allocation in C would call valloc (or posix_memalign)

Simple Perl allocation of the buffer like this:

     $buffer = "\0" x  BUFFER_SIZE ;

is not enough since most probably the starting address of the scalar
wont be aligned to OS page size.

Is there a simple way to achieve this?

Note: I convert the buffer to the C address like this:

     my $c_address = unpack('Q', pack('P', $buffer));

Thanks!
Eyal