From 4c84df8538e24e3c8df55e720307942236bff02d Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Wed, 3 May 2017 20:49:48 -0700 Subject: [PATCH] Basic XS start --- dist.ini | 16 +++++++++++++++- lib/Sys/Linux/Mount.pm | 6 ------ lib/Sys/Linux/Mount.xs | 23 +++++++++++++++++++++++ lib/Sys/Linux/Unshare.pm | 6 ------ unshare.xs => lib/Sys/Linux/Unshare.xs | 13 +++++++++---- 5 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 lib/Sys/Linux/Mount.xs rename unshare.xs => lib/Sys/Linux/Unshare.xs (82%) diff --git a/dist.ini b/dist.ini index 906514b..d5bdf30 100644 --- a/dist.ini +++ b/dist.ini @@ -6,8 +6,22 @@ copyright_year = 2017 [@Starter] revision = 2 -installer = ModuleBuildTiny +-remove = GatherDir +-remove = MakeMaker + +[Git::GatherDir] +[MakeMaker::Awesome] +; #WriteMakefile_arg = CCFLAGS => `pkg-config --cflags libpng` +header = die 'Unsupported OS' unless $^O eq 'linux'; +delimiter = | +WriteMakefile_arg = | XSMULTI => 1 +; #footer = |package MY; +; #footer = |sub postamble { +; #footer = | my $self = shift; +; #footer = | return $self->SUPER::postamble . "\n\nfoo: bar\n\t$(CP) bar foo\n"; +; #footer = |} [Git::NextVersion] [AutoPrereqs] [Prereqs] +ExtUtils::MakeMaker=7.12 diff --git a/lib/Sys/Linux/Mount.pm b/lib/Sys/Linux/Mount.pm index 6360302..3efbaf6 100644 --- a/lib/Sys/Linux/Mount.pm +++ b/lib/Sys/Linux/Mount.pm @@ -5,12 +5,6 @@ use warnings; require Exporter; our @ISA = qw/Exporter/; -BEGIN { - # Force reloading of all .ph files - delete $INC{$_} for (grep {/\.ph$/} keys %INC); - require 'syscall.ph'; -} - my @mount_consts = qw/MS_RDONLY MS_NOSUID MS_NODEV MS_NOEXEC MS_SYNCHRONOUS MS_REMOUNT MS_MANDLOCK MS_DIRSYNC MS_NOATIME MS_NODIRATIME MS_BIND MS_MOVE MS_REC MS_SILENT MS_POSIXACL MS_UNBINDABLE MS_PRIVATE MS_SLAVE MS_SHARED MS_RELATIME MS_KERNMOUNT MS_I_VERSION MS_STRICTATIME MS_LAZYTIME MS_ACTIVE MS_NOUSER/; our @EXPORT_OK = (@mount_consts, qw/mount/); diff --git a/lib/Sys/Linux/Mount.xs b/lib/Sys/Linux/Mount.xs new file mode 100644 index 0000000..5f72111 --- /dev/null +++ b/lib/Sys/Linux/Mount.xs @@ -0,0 +1,23 @@ +#define PERL_NO_GET_CONTEXT // we'll define thread context if necessary (faster) +#include "EXTERN.h" // globals/constant import locations +#include "perl.h" // Perl symbols, structures and constants definition +#include "XSUB.h" // xsubpp functions and macros +#include + +MODULE = Sys::Linux::Mount PACKAGE = Sys::Linux::Mount +PROTOTYPES: ENABLE + + # XS code goes here + + # XS comments begin with " #" to avoid them being interpreted as pre-processor + # directives + +int +_unshare_sys(source, target, filesystem, mount, data) +const char *source +const char *target +const char *filesystem +unsigned long mountflags +const char *data + CODE: + return mount(source, target, filesystem, mount, (const void *) data); diff --git a/lib/Sys/Linux/Unshare.pm b/lib/Sys/Linux/Unshare.pm index d33869b..983fb50 100644 --- a/lib/Sys/Linux/Unshare.pm +++ b/lib/Sys/Linux/Unshare.pm @@ -10,12 +10,6 @@ require XSLoader; XSLoader::load(); -BEGIN { - # Force reloading of all .ph files - delete $INC{$_} for (grep {/\.ph$/} keys %INC); - require 'syscall.ph'; -} - my @unshare_consts = qw/CSIGNAL CLONE_VM CLONE_FS CLONE_FILES CLONE_SIGHAND CLONE_PTRACE CLONE_VFORK CLONE_PARENT CLONE_THREAD CLONE_NEWNS CLONE_SYSVSEM CLONE_SETTLS CLONE_PARENT_SETTID CLONE_CHILD_CLEARTID CLONE_DETACHED CLONE_UNTRACED CLONE_CHILD_SETTID CLONE_NEWCGROUP CLONE_NEWUTS CLONE_NEWIPC CLONE_NEWUSER CLONE_NEWPID CLONE_NEWNET CLONE_IO/; our @EXPORT_OK = (@unshare_consts, qw/unshare/); diff --git a/unshare.xs b/lib/Sys/Linux/Unshare.xs similarity index 82% rename from unshare.xs rename to lib/Sys/Linux/Unshare.xs index 6f376fd..61cd269 100644 --- a/unshare.xs +++ b/lib/Sys/Linux/Unshare.xs @@ -1,9 +1,10 @@ #define PERL_NO_GET_CONTEXT // we'll define thread context if necessary (faster) +#define _GNU_SOURCE #include "EXTERN.h" // globals/constant import locations #include "perl.h" // Perl symbols, structures and constants definition #include "XSUB.h" // xsubpp functions and macros -#include // rand() - +#include + // additional c code goes here MODULE = Sys::Linux::Unshare PACKAGE = Sys::Linux::Unshare @@ -14,5 +15,9 @@ PROTOTYPES: ENABLE # XS comments begin with " #" to avoid them being interpreted as pre-processor # directives -unsigned int -rand() +int +_unshare_sys(flags) +int flags + CODE: + return unshare(flags); +