-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] Setting up PerlIO callbacks when embedding a Perl interpreter using C (before any *.pm
modules were ever loaded or any Perl code executed)
#22571
Comments
*.pm
modules were ever loaded or any Perl code executed)*.pm
modules were ever loaded or any Perl code executed)
There is PERL_IMPLICIT_SYS, but that replaces all I/O (not just module loading) and only has a host implementation on Windows. If you just want modules to be loaded from memory you can add a hook to |
I'll check out
Actually, interested both for modules and for regular, basic file reads. For modules, can such INC-hook be added via C perlembed interface (without executing Perl code)?
And regarding PerlIO infra, is it relevant for my usecase (module / Thank you! |
It's only ever been done before for Windows but there's no reason it would be impossible on Linux. See |
Thanks for the pointers! I'll look into what entails using And maybe the last question, if you would know if PerlIO can also be used for this I/O override goal? And if so, can it be configured via a C API before any Perl code gets executed? |
After perl_construct() something like:
You could also define the hook sub in perl with eval_pv()/eval_sv().
You might be able to do it by modifying It also won't allow you to hook operations like stat() and fcntl(). |
Hi!
I managed to do a fully hermetic single-file static build of perl via building all modules statically (followed https://perldoc.perl.org/perlembed) and providing my own implementations of open/fopen/read/seek to serve
*.pm
system files from memory.Is there a way to hook up to the Perl's own PerlIO layers system to make sure that Perl only calls these functions (including for module/
*.pm
discovery and loading) and never goes to libc's IO functions or does libc IO function calls / IO syscalls? This would be much cleaner and a more robust solution.It would be nice if setting up PerlIO in perlembed scenario was covered in docs.
I also wonder how diamond operator is implemented in the code and which functions from https://github.com/Perl/perl5/blob/blead/perlio.c it calls and in what sequence (e.g. for
perl -e 'open(f,"<","my.txt");print(<f>);'
and forperl -e 'open(f,"<","my.txt");$line=<f>;print($line);'
)Thanks!
If anyone's curious to see what my hack looks like - https://github.com/vadimkantorov/perlpack, but it's very much a WIP
My current problem is that overriding
open
/close
/read
/stat
/lseek
/access
/fopen
/fileno
was sufficient forperl -e 'use Cwd;print(Cwd::cwd(),"\n");'
, so it can successfully discover and load theCwd.pm
file from my virtual read-only FS, but doingperl -e 'open(F,"<","/mnt/perlpack/.../Cwd.pm");print(<F>);'
does not work - probably because Perl is trying to do fcntl/ioctl/some other version of stat call and I am not implementing these. In any case, it is currently not invoking theread
function for some reason when I'm using the diamond operator because of some failures on the way. Which IO/stdio calls are used by Perl in a typical opening/reading a file?strace
showsopen
->fcntl
->ioctl
->lseek
->fstat
->mmap
->read
, but these are raw syscalls, so I'm wondering what are the concrete libc/stdio IO functions (I imagine this is somewhere inperlio.c
ordo_io.c
but there are quite a few of indirection layers - so hard to parse through by a novice in the perl's codebase) are used by Perl in a typical opening/reading a file (e.g. stat has many variants) - so that I can override them.The text was updated successfully, but these errors were encountered: