kibi-swipl-linux-x64-gnu 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/bin/swipl +0 -0
- package/bin/swipl-win +0 -0
- package/build-manifest.json +70 -0
- package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
- package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
- package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
- package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
- package/lib/swipl/ABI +1 -0
- package/lib/swipl/LICENSE +41 -0
- package/lib/swipl/README.md +116 -0
- package/lib/swipl/app/README.md +25 -0
- package/lib/swipl/app/app.pl +87 -0
- package/lib/swipl/app/pack.pl +350 -0
- package/lib/swipl/app/qlf.pl +521 -0
- package/lib/swipl/app/splfr.pl +177 -0
- package/lib/swipl/app/sys.pl +310 -0
- package/lib/swipl/bin/swipl.home +1 -0
- package/lib/swipl/boot/apply.pl +73 -0
- package/lib/swipl/boot/attvar.pl +344 -0
- package/lib/swipl/boot/autoload.pl +1226 -0
- package/lib/swipl/boot/bags.pl +283 -0
- package/lib/swipl/boot/dcg.pl +388 -0
- package/lib/swipl/boot/dicts.pl +193 -0
- package/lib/swipl/boot/dwim.pl +485 -0
- package/lib/swipl/boot/engines.pl +152 -0
- package/lib/swipl/boot/expand.pl +1628 -0
- package/lib/swipl/boot/gc.pl +65 -0
- package/lib/swipl/boot/history.pl +304 -0
- package/lib/swipl/boot/init.pl +4682 -0
- package/lib/swipl/boot/iri.pl +64 -0
- package/lib/swipl/boot/license.pl +390 -0
- package/lib/swipl/boot/load.pl +81 -0
- package/lib/swipl/boot/messages.pl +2521 -0
- package/lib/swipl/boot/packs.pl +306 -0
- package/lib/swipl/boot/predopts.pl +154 -0
- package/lib/swipl/boot/qlf.pl +141 -0
- package/lib/swipl/boot/rc.pl +263 -0
- package/lib/swipl/boot/syspred.pl +1634 -0
- package/lib/swipl/boot/tabling.pl +2321 -0
- package/lib/swipl/boot/threads.pl +42 -0
- package/lib/swipl/boot/toplevel.pl +2248 -0
- package/lib/swipl/boot/topvars.pl +261 -0
- package/lib/swipl/boot.prc +0 -0
- package/lib/swipl/cmake/swipl.cmake +131 -0
- package/lib/swipl/customize/README.md +23 -0
- package/lib/swipl/customize/edit +101 -0
- package/lib/swipl/customize/init.pl +164 -0
- package/lib/swipl/demo/README.md +33 -0
- package/lib/swipl/demo/likes.pl +44 -0
- package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
- package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
- package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
- package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
- package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
- package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
- package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
- package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
- package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
- package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
- package/lib/swipl/doc/packages/examples/http/README.md +98 -0
- package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
- package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
- package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
- package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
- package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
- package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
- package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
- package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
- package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
- package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
- package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
- package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
- package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
- package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
- package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
- package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
- package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
- package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
- package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
- package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
- package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
- package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
- package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
- package/lib/swipl/include/SWI-Prolog.h +1544 -0
- package/lib/swipl/include/SWI-Stream.h +537 -0
- package/lib/swipl/include/Yap/YapInterface.h +283 -0
- package/lib/swipl/include/sicstus/sicstus.h +452 -0
- package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
- package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
- package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
- package/lib/swipl/lib/x86_64-linux/files.so +0 -0
- package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
- package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
- package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
- package/lib/swipl/lib/x86_64-linux/json.so +0 -0
- package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
- package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
- package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
- package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
- package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
- package/lib/swipl/lib/x86_64-linux/process.so +0 -0
- package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
- package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
- package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
- package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
- package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
- package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
- package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
- package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
- package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
- package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
- package/lib/swipl/lib/x86_64-linux/time.so +0 -0
- package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
- package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
- package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
- package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
- package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
- package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
- package/lib/swipl/library/INDEX.pl +1020 -0
- package/lib/swipl/library/aggregate.pl +755 -0
- package/lib/swipl/library/ansi_term.pl +653 -0
- package/lib/swipl/library/apply.pl +426 -0
- package/lib/swipl/library/apply_macros.pl +497 -0
- package/lib/swipl/library/arithmetic.pl +320 -0
- package/lib/swipl/library/assoc.pl +522 -0
- package/lib/swipl/library/atom.pl +169 -0
- package/lib/swipl/library/backcomp.pl +688 -0
- package/lib/swipl/library/base32.pl +291 -0
- package/lib/swipl/library/base64.pl +441 -0
- package/lib/swipl/library/broadcast.pl +161 -0
- package/lib/swipl/library/build/cmake.pl +137 -0
- package/lib/swipl/library/build/conan.pl +232 -0
- package/lib/swipl/library/build/make.pl +168 -0
- package/lib/swipl/library/build/tools.pl +825 -0
- package/lib/swipl/library/charsio.pl +195 -0
- package/lib/swipl/library/check.pl +1097 -0
- package/lib/swipl/library/check_installation.pl +912 -0
- package/lib/swipl/library/clp/INDEX.pl +157 -0
- package/lib/swipl/library/clp/bounds.pl +2036 -0
- package/lib/swipl/library/clp/clp_distinct.pl +263 -0
- package/lib/swipl/library/clp/clp_events.pl +92 -0
- package/lib/swipl/library/clp/clpb.pl +1896 -0
- package/lib/swipl/library/clp/clpfd.pl +7906 -0
- package/lib/swipl/library/clp/simplex.pl +1580 -0
- package/lib/swipl/library/codesio.pl +182 -0
- package/lib/swipl/library/coinduction.pl +183 -0
- package/lib/swipl/library/console_input.pl +289 -0
- package/lib/swipl/library/csv.pl +611 -0
- package/lib/swipl/library/ctypes.pl +161 -0
- package/lib/swipl/library/date.pl +370 -0
- package/lib/swipl/library/dcg/INDEX.pl +35 -0
- package/lib/swipl/library/dcg/basics.pl +514 -0
- package/lib/swipl/library/dcg/high_order.pl +227 -0
- package/lib/swipl/library/debug.pl +499 -0
- package/lib/swipl/library/dialect/bim.pl +186 -0
- package/lib/swipl/library/dialect/commons.pl +77 -0
- package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
- package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
- package/lib/swipl/library/dialect/hprolog.pl +314 -0
- package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
- package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
- package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
- package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
- package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
- package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
- package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
- package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
- package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
- package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
- package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
- package/lib/swipl/library/dialect/sicstus.pl +582 -0
- package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
- package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
- package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
- package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
- package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
- package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
- package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
- package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
- package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
- package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
- package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
- package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
- package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
- package/lib/swipl/library/dialect/sicstus4.pl +200 -0
- package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
- package/lib/swipl/library/dialect/xsb/README.md +20 -0
- package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
- package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
- package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
- package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
- package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
- package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
- package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
- package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
- package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
- package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
- package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
- package/lib/swipl/library/dialect/xsb/source.pl +308 -0
- package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
- package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
- package/lib/swipl/library/dialect/xsb/string.pl +76 -0
- package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
- package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
- package/lib/swipl/library/dialect/xsb.pl +688 -0
- package/lib/swipl/library/dialect/yap/README.TXT +8 -0
- package/lib/swipl/library/dialect/yap.pl +283 -0
- package/lib/swipl/library/dialect.pl +123 -0
- package/lib/swipl/library/dicts.pl +399 -0
- package/lib/swipl/library/dif.pl +426 -0
- package/lib/swipl/library/edinburgh.pl +138 -0
- package/lib/swipl/library/edit.pl +783 -0
- package/lib/swipl/library/error.pl +495 -0
- package/lib/swipl/library/exceptions.pl +231 -0
- package/lib/swipl/library/explain.pl +543 -0
- package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
- package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
- package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
- package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
- package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
- package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
- package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
- package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
- package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
- package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
- package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
- package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
- package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
- package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
- package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
- package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
- package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
- package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
- package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
- package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
- package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
- package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
- package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
- package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
- package/lib/swipl/library/ext/chr/chr.pl +686 -0
- package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
- package/lib/swipl/library/ext/clib/cgi.pl +86 -0
- package/lib/swipl/library/ext/clib/crypt.pl +44 -0
- package/lib/swipl/library/ext/clib/filesex.pl +644 -0
- package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
- package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
- package/lib/swipl/library/ext/clib/md5.pl +68 -0
- package/lib/swipl/library/ext/clib/memfile.pl +61 -0
- package/lib/swipl/library/ext/clib/process.pl +573 -0
- package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
- package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
- package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
- package/lib/swipl/library/ext/clib/sched.pl +85 -0
- package/lib/swipl/library/ext/clib/sha.pl +162 -0
- package/lib/swipl/library/ext/clib/socket.pl +1102 -0
- package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
- package/lib/swipl/library/ext/clib/streampool.pl +136 -0
- package/lib/swipl/library/ext/clib/syslog.pl +180 -0
- package/lib/swipl/library/ext/clib/time.pl +194 -0
- package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
- package/lib/swipl/library/ext/clib/uid.pl +220 -0
- package/lib/swipl/library/ext/clib/unix.pl +317 -0
- package/lib/swipl/library/ext/clib/uri.pl +530 -0
- package/lib/swipl/library/ext/clib/uuid.pl +207 -0
- package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
- package/lib/swipl/library/ext/http/http/README.md +34 -0
- package/lib/swipl/library/ext/http/http/ax.pl +189 -0
- package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
- package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
- package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
- package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
- package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
- package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
- package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
- package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
- package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
- package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
- package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
- package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
- package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
- package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
- package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
- package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
- package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
- package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
- package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
- package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
- package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
- package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
- package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
- package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
- package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
- package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
- package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
- package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
- package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
- package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
- package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
- package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
- package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
- package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
- package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
- package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
- package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
- package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
- package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
- package/lib/swipl/library/ext/http/http/hub.pl +600 -0
- package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
- package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
- package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
- package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
- package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
- package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
- package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
- package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
- package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
- package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
- package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
- package/lib/swipl/library/ext/json/INDEX.pl +36 -0
- package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
- package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
- package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
- package/lib/swipl/library/ext/json/http/json.pl +48 -0
- package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
- package/lib/swipl/library/ext/json/json.pl +1215 -0
- package/lib/swipl/library/ext/json/json_convert.pl +681 -0
- package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
- package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
- package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
- package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
- package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
- package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
- package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
- package/lib/swipl/library/ext/nlp/isub.pl +162 -0
- package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
- package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
- package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
- package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
- package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
- package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
- package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
- package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
- package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
- package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
- package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
- package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
- package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
- package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
- package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
- package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
- package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
- package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
- package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
- package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
- package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
- package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
- package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
- package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
- package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
- package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
- package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
- package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
- package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
- package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
- package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
- package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
- package/lib/swipl/library/ext/ssl/saml.pl +609 -0
- package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
- package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
- package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
- package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
- package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
- package/lib/swipl/library/fastrw.pl +105 -0
- package/lib/swipl/library/files.pl +80 -0
- package/lib/swipl/library/gensym.pl +111 -0
- package/lib/swipl/library/git.pl +1027 -0
- package/lib/swipl/library/hashtable.pl +365 -0
- package/lib/swipl/library/heaps.pl +252 -0
- package/lib/swipl/library/hotfix.pl +239 -0
- package/lib/swipl/library/http/jquery.pl +103 -0
- package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
- package/lib/swipl/library/increval.pl +217 -0
- package/lib/swipl/library/intercept.pl +263 -0
- package/lib/swipl/library/iostream.pl +237 -0
- package/lib/swipl/library/iri_scheme/file.pl +70 -0
- package/lib/swipl/library/lazy_lists.pl +481 -0
- package/lib/swipl/library/listing.pl +1362 -0
- package/lib/swipl/library/lists.pl +860 -0
- package/lib/swipl/library/lynx/INDEX.pl +14 -0
- package/lib/swipl/library/lynx/format.pl +380 -0
- package/lib/swipl/library/lynx/html_style.pl +129 -0
- package/lib/swipl/library/lynx/html_text.pl +865 -0
- package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
- package/lib/swipl/library/macros.pl +451 -0
- package/lib/swipl/library/main.pl +1200 -0
- package/lib/swipl/library/make.pl +197 -0
- package/lib/swipl/library/modules.pl +129 -0
- package/lib/swipl/library/nb_rbtrees.pl +267 -0
- package/lib/swipl/library/nb_set.pl +203 -0
- package/lib/swipl/library/obfuscate.pl +115 -0
- package/lib/swipl/library/occurs.pl +241 -0
- package/lib/swipl/library/operators.pl +182 -0
- package/lib/swipl/library/option.pl +388 -0
- package/lib/swipl/library/optparse.pl +966 -0
- package/lib/swipl/library/ordsets.pl +518 -0
- package/lib/swipl/library/oset.pl +160 -0
- package/lib/swipl/library/pairs.pl +187 -0
- package/lib/swipl/library/persistency.pl +713 -0
- package/lib/swipl/library/pio.pl +47 -0
- package/lib/swipl/library/portray_text.pl +277 -0
- package/lib/swipl/library/pprint.pl +940 -0
- package/lib/swipl/library/predicate_options.pl +975 -0
- package/lib/swipl/library/prolog_autoload.pl +233 -0
- package/lib/swipl/library/prolog_breakpoints.pl +396 -0
- package/lib/swipl/library/prolog_clause.pl +1104 -0
- package/lib/swipl/library/prolog_code.pl +416 -0
- package/lib/swipl/library/prolog_codewalk.pl +1248 -0
- package/lib/swipl/library/prolog_colour.pl +3301 -0
- package/lib/swipl/library/prolog_colour.qlf +0 -0
- package/lib/swipl/library/prolog_config.pl +154 -0
- package/lib/swipl/library/prolog_coverage.pl +1333 -0
- package/lib/swipl/library/prolog_debug.pl +404 -0
- package/lib/swipl/library/prolog_deps.pl +675 -0
- package/lib/swipl/library/prolog_evaluable.pl +234 -0
- package/lib/swipl/library/prolog_format.pl +219 -0
- package/lib/swipl/library/prolog_history.pl +161 -0
- package/lib/swipl/library/prolog_jiti.pl +333 -0
- package/lib/swipl/library/prolog_locale.pl +61 -0
- package/lib/swipl/library/prolog_metainference.pl +307 -0
- package/lib/swipl/library/prolog_pack.pl +3906 -0
- package/lib/swipl/library/prolog_profile.pl +346 -0
- package/lib/swipl/library/prolog_qlfmake.pl +533 -0
- package/lib/swipl/library/prolog_source.pl +1188 -0
- package/lib/swipl/library/prolog_stack.pl +794 -0
- package/lib/swipl/library/prolog_trace.pl +365 -0
- package/lib/swipl/library/prolog_versions.pl +347 -0
- package/lib/swipl/library/prolog_wrap.pl +164 -0
- package/lib/swipl/library/prolog_xref.pl +3090 -0
- package/lib/swipl/library/prolog_xref.qlf +0 -0
- package/lib/swipl/library/pure_input.pl +266 -0
- package/lib/swipl/library/qpforeign.pl +695 -0
- package/lib/swipl/library/qsave.pl +1516 -0
- package/lib/swipl/library/quasi_quotations.pl +300 -0
- package/lib/swipl/library/quintus.pl +437 -0
- package/lib/swipl/library/random.pl +459 -0
- package/lib/swipl/library/rbtrees.pl +1153 -0
- package/lib/swipl/library/readln.pl +256 -0
- package/lib/swipl/library/readutil.pl +304 -0
- package/lib/swipl/library/record.pl +544 -0
- package/lib/swipl/library/rwlocks.pl +172 -0
- package/lib/swipl/library/sandbox.pl +1384 -0
- package/lib/swipl/library/semweb/dc.rdfs +198 -0
- package/lib/swipl/library/semweb/eor.rdfs +95 -0
- package/lib/swipl/library/semweb/owl.owl +287 -0
- package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
- package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
- package/lib/swipl/library/settings.pl +755 -0
- package/lib/swipl/library/shell.pl +462 -0
- package/lib/swipl/library/shlib.pl +670 -0
- package/lib/swipl/library/solution_sequences.pl +439 -0
- package/lib/swipl/library/sort.pl +119 -0
- package/lib/swipl/library/statistics.pl +541 -0
- package/lib/swipl/library/streams.pl +118 -0
- package/lib/swipl/library/strings.pl +469 -0
- package/lib/swipl/library/system.pl +95 -0
- package/lib/swipl/library/tables.pl +381 -0
- package/lib/swipl/library/tableutil.pl +771 -0
- package/lib/swipl/library/tabling.pl +42 -0
- package/lib/swipl/library/terms.pl +457 -0
- package/lib/swipl/library/theme/auto.pl +61 -0
- package/lib/swipl/library/theme/dark.pl +455 -0
- package/lib/swipl/library/theme/light.pl +45 -0
- package/lib/swipl/library/thread.pl +810 -0
- package/lib/swipl/library/thread_pool.pl +508 -0
- package/lib/swipl/library/threadutil.pl +574 -0
- package/lib/swipl/library/tty.pl +316 -0
- package/lib/swipl/library/ugraphs.pl +644 -0
- package/lib/swipl/library/unicode/INDEX.pl +6 -0
- package/lib/swipl/library/unicode/blocks.pl +414 -0
- package/lib/swipl/library/url.pl +1129 -0
- package/lib/swipl/library/utf8.pl +145 -0
- package/lib/swipl/library/varnumbers.pl +221 -0
- package/lib/swipl/library/vm.pl +251 -0
- package/lib/swipl/library/wfs.pl +205 -0
- package/lib/swipl/library/when.pl +263 -0
- package/lib/swipl/library/writef.pl +278 -0
- package/lib/swipl/library/www_browser.pl +251 -0
- package/lib/swipl/library/yall.pl +574 -0
- package/lib/swipl/library/zip.pl +211 -0
- package/lib/swipl/swipl.home +1 -0
- package/lib/vendor/libcrypto.so.3 +0 -0
- package/lib/vendor/libpcre2-8.so.0 +0 -0
- package/lib/vendor/libssl.so.3 +0 -0
- package/lib/vendor/libz.so.1 +0 -0
- package/licenses/OpenSSL-LICENSE.txt +177 -0
- package/licenses/PCRE2-COPYING +5 -0
- package/licenses/README.md +12 -0
- package/licenses/SWI-Prolog-LICENSE +41 -0
- package/licenses/zlib-LICENSE +22 -0
- package/package.json +27 -0
|
@@ -0,0 +1,1384 @@
|
|
|
1
|
+
/* Part of SWI-Prolog
|
|
2
|
+
|
|
3
|
+
Author: Jan Wielemaker
|
|
4
|
+
E-mail: J.Wielemaker@vu.nl
|
|
5
|
+
WWW: http://www.swi-prolog.org
|
|
6
|
+
Copyright (c) 2013-2024, VU University Amsterdam
|
|
7
|
+
CWI, Amsterdam
|
|
8
|
+
SWI-Prolog Solutions b.v
|
|
9
|
+
All rights reserved.
|
|
10
|
+
|
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
|
12
|
+
modification, are permitted provided that the following conditions
|
|
13
|
+
are met:
|
|
14
|
+
|
|
15
|
+
1. Redistributions of source code must retain the above copyright
|
|
16
|
+
notice, this list of conditions and the following disclaimer.
|
|
17
|
+
|
|
18
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
19
|
+
notice, this list of conditions and the following disclaimer in
|
|
20
|
+
the documentation and/or other materials provided with the
|
|
21
|
+
distribution.
|
|
22
|
+
|
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
24
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
25
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
26
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
27
|
+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
28
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
29
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
30
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
32
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
33
|
+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
34
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
:- module(sandbox,
|
|
38
|
+
[ safe_goal/1, % :Goal
|
|
39
|
+
safe_call/1 % :Goal
|
|
40
|
+
]).
|
|
41
|
+
:- use_module(library(apply_macros),[expand_phrase/2]).
|
|
42
|
+
:- use_module(library(apply),[maplist/2]).
|
|
43
|
+
:- use_module(library(assoc),[empty_assoc/1,get_assoc/3,put_assoc/4]).
|
|
44
|
+
:- use_module(library(debug),[debug/3,debugging/1]).
|
|
45
|
+
:- use_module(library(error),
|
|
46
|
+
[ must_be/2,
|
|
47
|
+
instantiation_error/1,
|
|
48
|
+
type_error/2,
|
|
49
|
+
permission_error/3
|
|
50
|
+
]).
|
|
51
|
+
:- use_module(library(lists),[append/3]).
|
|
52
|
+
:- use_module(library(prolog_format),[format_types/2]).
|
|
53
|
+
|
|
54
|
+
:- multifile
|
|
55
|
+
safe_primitive/1, % Goal
|
|
56
|
+
safe_meta_predicate/1, % Name/Arity
|
|
57
|
+
safe_meta/2, % Goal, Calls
|
|
58
|
+
safe_meta/3, % Goal, Context, Calls
|
|
59
|
+
safe_global_variable/1, % Name
|
|
60
|
+
safe_directive/1, % Module:Goal
|
|
61
|
+
safe_prolog_flag/2. % +Name, +Value
|
|
62
|
+
|
|
63
|
+
% :- debug(sandbox).
|
|
64
|
+
|
|
65
|
+
/** <module> Sandboxed Prolog code
|
|
66
|
+
|
|
67
|
+
Prolog is a full-featured Turing complete programming language in which
|
|
68
|
+
it is easy to write programs that can harm your computer. On the other
|
|
69
|
+
hand, Prolog is a logic based _query language_ which can be exploited to
|
|
70
|
+
query data interactively from, e.g., the web. This library provides
|
|
71
|
+
safe_goal/1, which determines whether it is safe to call its argument.
|
|
72
|
+
|
|
73
|
+
@tbd Handling of ^ and // meta predicates
|
|
74
|
+
@tbd Complete set of whitelisted predicates
|
|
75
|
+
@see http://www.swi-prolog.org/pldoc/package/pengines.html
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
:- meta_predicate
|
|
80
|
+
safe_goal(:),
|
|
81
|
+
safe_call(0).
|
|
82
|
+
|
|
83
|
+
%! safe_call(:Goal)
|
|
84
|
+
%
|
|
85
|
+
% Call Goal if it complies with the sandboxing rules. Before
|
|
86
|
+
% calling Goal, it performs expand_goal/2, followed by
|
|
87
|
+
% safe_goal/1. Expanding is done explicitly because situations in
|
|
88
|
+
% which safe_call/1 typically concern goals that are not known at
|
|
89
|
+
% compile time.
|
|
90
|
+
%
|
|
91
|
+
% @see safe_goal/1.
|
|
92
|
+
|
|
93
|
+
safe_call(Goal0) :-
|
|
94
|
+
expand_goal(Goal0, Goal),
|
|
95
|
+
safe_goal(Goal),
|
|
96
|
+
call(Goal).
|
|
97
|
+
|
|
98
|
+
%! safe_goal(:Goal) is det.
|
|
99
|
+
%
|
|
100
|
+
% True if calling Goal provides no security risc. This implies
|
|
101
|
+
% that:
|
|
102
|
+
%
|
|
103
|
+
% - The call-graph can be fully expanded. Full expansion *stops*
|
|
104
|
+
% if a meta-goal is found for which we cannot determine enough
|
|
105
|
+
% details to know which predicate will be called.
|
|
106
|
+
%
|
|
107
|
+
% - All predicates referenced from the fully expanded are
|
|
108
|
+
% whitelisted by the predicate safe_primitive/1 and safe_meta/2.
|
|
109
|
+
%
|
|
110
|
+
% - It is not allowed to make explicitly qualified calls into
|
|
111
|
+
% modules to predicates that are not exported or declared
|
|
112
|
+
% public.
|
|
113
|
+
%
|
|
114
|
+
% @error instantiation_error if the analysis encounters a term in
|
|
115
|
+
% a callable position that is insufficiently instantiated
|
|
116
|
+
% to determine the predicate called.
|
|
117
|
+
% @error permission_error(call, sandboxed, Goal) if Goal is in
|
|
118
|
+
% the call-tree and not white-listed.
|
|
119
|
+
|
|
120
|
+
safe_goal(M:Goal) :-
|
|
121
|
+
empty_assoc(Safe0),
|
|
122
|
+
catch(safe(Goal, M, [], Safe0, _), E, true),
|
|
123
|
+
!,
|
|
124
|
+
nb_delete(sandbox_last_error),
|
|
125
|
+
( var(E)
|
|
126
|
+
-> true
|
|
127
|
+
; throw(E)
|
|
128
|
+
).
|
|
129
|
+
safe_goal(_) :-
|
|
130
|
+
nb_current(sandbox_last_error, E),
|
|
131
|
+
!,
|
|
132
|
+
nb_delete(sandbox_last_error),
|
|
133
|
+
throw(E).
|
|
134
|
+
safe_goal(G) :-
|
|
135
|
+
debug(sandbox(fail), 'safe_goal/1 failed for ~p', [G]),
|
|
136
|
+
throw(error(instantiation_error, sandbox(G, []))).
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
%! safe(+Goal, +Module, +Parents, +Safe0, -Safe) is semidet.
|
|
140
|
+
%
|
|
141
|
+
% Is true if Goal can only call safe code.
|
|
142
|
+
|
|
143
|
+
safe(V, _, Parents, _, _) :-
|
|
144
|
+
var(V),
|
|
145
|
+
!,
|
|
146
|
+
Error = error(instantiation_error, sandbox(V, Parents)),
|
|
147
|
+
nb_setval(sandbox_last_error, Error),
|
|
148
|
+
throw(Error).
|
|
149
|
+
safe(M:G, _, Parents, Safe0, Safe) :-
|
|
150
|
+
!,
|
|
151
|
+
must_be(atom, M),
|
|
152
|
+
must_be(callable, G),
|
|
153
|
+
known_module(M:G, Parents),
|
|
154
|
+
( predicate_property(M:G, imported_from(M2))
|
|
155
|
+
-> true
|
|
156
|
+
; M2 = M
|
|
157
|
+
),
|
|
158
|
+
( ( safe_primitive(M2:G)
|
|
159
|
+
; safe_primitive(G),
|
|
160
|
+
predicate_property(G, iso)
|
|
161
|
+
)
|
|
162
|
+
-> Safe = Safe0
|
|
163
|
+
; ( predicate_property(M:G, exported)
|
|
164
|
+
; predicate_property(M:G, public)
|
|
165
|
+
; predicate_property(M:G, multifile)
|
|
166
|
+
; predicate_property(M:G, iso)
|
|
167
|
+
; memberchk(M:_, Parents)
|
|
168
|
+
)
|
|
169
|
+
-> safe(G, M, Parents, Safe0, Safe)
|
|
170
|
+
; throw(error(permission_error(call, sandboxed, M:G),
|
|
171
|
+
sandbox(M:G, Parents)))
|
|
172
|
+
).
|
|
173
|
+
safe(G, _, Parents, _, _) :-
|
|
174
|
+
debugging(sandbox(show)),
|
|
175
|
+
length(Parents, Level),
|
|
176
|
+
debug(sandbox(show), '[~D] SAFE ~q?', [Level, G]),
|
|
177
|
+
fail.
|
|
178
|
+
safe(G, _, Parents, Safe, Safe) :-
|
|
179
|
+
catch(safe_primitive(G),
|
|
180
|
+
error(instantiation_error, _),
|
|
181
|
+
rethrow_instantition_error([G|Parents])),
|
|
182
|
+
predicate_property(G, iso),
|
|
183
|
+
!.
|
|
184
|
+
safe(G, M, Parents, Safe, Safe) :-
|
|
185
|
+
known_module(M:G, Parents),
|
|
186
|
+
( predicate_property(M:G, imported_from(M2))
|
|
187
|
+
-> true
|
|
188
|
+
; M2 = M
|
|
189
|
+
),
|
|
190
|
+
( catch(safe_primitive(M2:G),
|
|
191
|
+
error(instantiation_error, _),
|
|
192
|
+
rethrow_instantition_error([M2:G|Parents]))
|
|
193
|
+
; predicate_property(M2:G, number_of_rules(0))
|
|
194
|
+
),
|
|
195
|
+
!.
|
|
196
|
+
safe(G, M, Parents, Safe0, Safe) :-
|
|
197
|
+
predicate_property(G, iso),
|
|
198
|
+
safe_meta_call(G, M, Called),
|
|
199
|
+
!,
|
|
200
|
+
add_iso_parent(G, Parents, Parents1),
|
|
201
|
+
safe_list(Called, M, Parents1, Safe0, Safe).
|
|
202
|
+
safe(G, M, Parents, Safe0, Safe) :-
|
|
203
|
+
( predicate_property(M:G, imported_from(M2))
|
|
204
|
+
-> true
|
|
205
|
+
; M2 = M
|
|
206
|
+
),
|
|
207
|
+
safe_meta_call(M2:G, M, Called),
|
|
208
|
+
!,
|
|
209
|
+
safe_list(Called, M, Parents, Safe0, Safe).
|
|
210
|
+
safe(G, M, Parents, Safe0, Safe) :-
|
|
211
|
+
goal_id(M:G, Id, Gen),
|
|
212
|
+
( get_assoc(Id, Safe0, _)
|
|
213
|
+
-> Safe = Safe0
|
|
214
|
+
; put_assoc(Id, Safe0, true, Safe1),
|
|
215
|
+
( Gen == M:G
|
|
216
|
+
-> safe_clauses(Gen, M, [Id|Parents], Safe1, Safe)
|
|
217
|
+
; catch(safe_clauses(Gen, M, [Id|Parents], Safe1, Safe),
|
|
218
|
+
error(instantiation_error, Ctx),
|
|
219
|
+
unsafe(Parents, Ctx))
|
|
220
|
+
)
|
|
221
|
+
),
|
|
222
|
+
!.
|
|
223
|
+
safe(G, M, Parents, _, _) :-
|
|
224
|
+
debug(sandbox(fail),
|
|
225
|
+
'safe/1 failed for ~p (parents:~p)', [M:G, Parents]),
|
|
226
|
+
fail.
|
|
227
|
+
|
|
228
|
+
unsafe(Parents, Var) :-
|
|
229
|
+
var(Var),
|
|
230
|
+
!,
|
|
231
|
+
nb_setval(sandbox_last_error,
|
|
232
|
+
error(instantiation_error, sandbox(_, Parents))),
|
|
233
|
+
fail.
|
|
234
|
+
unsafe(_Parents, Ctx) :-
|
|
235
|
+
Ctx = sandbox(_,_),
|
|
236
|
+
nb_setval(sandbox_last_error,
|
|
237
|
+
error(instantiation_error, Ctx)),
|
|
238
|
+
fail.
|
|
239
|
+
|
|
240
|
+
rethrow_instantition_error(Parents) :-
|
|
241
|
+
throw(error(instantiation_error, sandbox(_, Parents))).
|
|
242
|
+
|
|
243
|
+
safe_clauses(G, M, Parents, Safe0, Safe) :-
|
|
244
|
+
predicate_property(M:G, interpreted),
|
|
245
|
+
def_module(M:G, MD:QG),
|
|
246
|
+
\+ compiled(MD:QG),
|
|
247
|
+
!,
|
|
248
|
+
findall(Ref-Body, clause(MD:QG, Body, Ref), Bodies),
|
|
249
|
+
safe_bodies(Bodies, MD, Parents, Safe0, Safe).
|
|
250
|
+
safe_clauses(G, M, [_|Parents], _, _) :-
|
|
251
|
+
predicate_property(M:G, visible),
|
|
252
|
+
!,
|
|
253
|
+
throw(error(permission_error(call, sandboxed, G),
|
|
254
|
+
sandbox(M:G, Parents))).
|
|
255
|
+
safe_clauses(_, _, [G|Parents], _, _) :-
|
|
256
|
+
throw(error(existence_error(procedure, G),
|
|
257
|
+
sandbox(G, Parents))).
|
|
258
|
+
|
|
259
|
+
compiled(system:(@(_,_))).
|
|
260
|
+
|
|
261
|
+
known_module(M:_, _) :-
|
|
262
|
+
current_module(M),
|
|
263
|
+
!.
|
|
264
|
+
known_module(M:G, Parents) :-
|
|
265
|
+
throw(error(permission_error(call, sandboxed, M:G),
|
|
266
|
+
sandbox(M:G, Parents))).
|
|
267
|
+
|
|
268
|
+
add_iso_parent(G, Parents, Parents) :-
|
|
269
|
+
is_control(G),
|
|
270
|
+
!.
|
|
271
|
+
add_iso_parent(G, Parents, [G|Parents]).
|
|
272
|
+
|
|
273
|
+
is_control((_,_)).
|
|
274
|
+
is_control((_;_)).
|
|
275
|
+
is_control((_->_)).
|
|
276
|
+
is_control((_*->_)).
|
|
277
|
+
is_control(\+(_)).
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
%! safe_bodies(+Bodies, +Module, +Parents, +Safe0, -Safe)
|
|
281
|
+
%
|
|
282
|
+
% Verify the safety of bodies. If a clause was compiled with a
|
|
283
|
+
% qualified module, we consider execution of the body in a
|
|
284
|
+
% different module _not_ a cross-module call.
|
|
285
|
+
|
|
286
|
+
safe_bodies([], _, _, Safe, Safe).
|
|
287
|
+
safe_bodies([Ref-H|T], M, Parents, Safe0, Safe) :-
|
|
288
|
+
( H = M2:H2, nonvar(M2),
|
|
289
|
+
clause_property(Ref, module(M2))
|
|
290
|
+
-> copy_term(H2, H3),
|
|
291
|
+
CM = M2
|
|
292
|
+
; copy_term(H, H3),
|
|
293
|
+
CM = M
|
|
294
|
+
),
|
|
295
|
+
safe(H3, CM, Parents, Safe0, Safe1),
|
|
296
|
+
safe_bodies(T, M, Parents, Safe1, Safe).
|
|
297
|
+
|
|
298
|
+
def_module(M:G, MD:QG) :-
|
|
299
|
+
predicate_property(M:G, imported_from(MD)),
|
|
300
|
+
!,
|
|
301
|
+
meta_qualify(MD:G, M, QG).
|
|
302
|
+
def_module(M:G, M:QG) :-
|
|
303
|
+
meta_qualify(M:G, M, QG).
|
|
304
|
+
|
|
305
|
+
%! safe_list(+Called, +Module, +Parents, +Safe0, -Safe)
|
|
306
|
+
%
|
|
307
|
+
% Processed objects called through meta predicates. If the called
|
|
308
|
+
% object is in our current context we remove the module
|
|
309
|
+
% qualification to avoid the cross-module check.
|
|
310
|
+
|
|
311
|
+
safe_list([], _, _, Safe, Safe).
|
|
312
|
+
safe_list([H|T], M, Parents, Safe0, Safe) :-
|
|
313
|
+
( H = M2:H2,
|
|
314
|
+
M == M2 % in our context
|
|
315
|
+
-> copy_term(H2, H3)
|
|
316
|
+
; copy_term(H, H3) % cross-module call
|
|
317
|
+
),
|
|
318
|
+
safe(H3, M, Parents, Safe0, Safe1),
|
|
319
|
+
safe_list(T, M, Parents, Safe1, Safe).
|
|
320
|
+
|
|
321
|
+
%! meta_qualify(:G, +M, -QG) is det.
|
|
322
|
+
%
|
|
323
|
+
% Perform meta-qualification of the goal-argument
|
|
324
|
+
|
|
325
|
+
meta_qualify(MD:G, M, QG) :-
|
|
326
|
+
predicate_property(MD:G, meta_predicate(Head)),
|
|
327
|
+
!,
|
|
328
|
+
G =.. [Name|Args],
|
|
329
|
+
Head =.. [_|Q],
|
|
330
|
+
qualify_args(Q, M, Args, QArgs),
|
|
331
|
+
QG =.. [Name|QArgs].
|
|
332
|
+
meta_qualify(_:G, _, G).
|
|
333
|
+
|
|
334
|
+
qualify_args([], _, [], []).
|
|
335
|
+
qualify_args([H|T], M, [A|AT], [Q|QT]) :-
|
|
336
|
+
qualify_arg(H, M, A, Q),
|
|
337
|
+
qualify_args(T, M, AT, QT).
|
|
338
|
+
|
|
339
|
+
qualify_arg(S, M, A, Q) :-
|
|
340
|
+
q_arg(S),
|
|
341
|
+
!,
|
|
342
|
+
qualify(A, M, Q).
|
|
343
|
+
qualify_arg(_, _, A, A).
|
|
344
|
+
|
|
345
|
+
q_arg(I) :- integer(I), !.
|
|
346
|
+
q_arg(:).
|
|
347
|
+
q_arg(^).
|
|
348
|
+
q_arg(//).
|
|
349
|
+
|
|
350
|
+
qualify(A, M, MZ:Q) :-
|
|
351
|
+
strip_module(M:A, MZ, Q).
|
|
352
|
+
|
|
353
|
+
%! goal_id(:Goal, -Id, -Gen) is nondet.
|
|
354
|
+
%
|
|
355
|
+
% Generate an identifier for the goal proven to be safe. We
|
|
356
|
+
% first try to prove the most general form of the goal. If
|
|
357
|
+
% this fails, we try to prove more specific versions.
|
|
358
|
+
%
|
|
359
|
+
% @tbd Do step-by-step generalisation instead of the current
|
|
360
|
+
% two levels (most general and most specific).
|
|
361
|
+
% @tbd We could also use variant_sha1 for the goal ids.
|
|
362
|
+
|
|
363
|
+
goal_id(M:Goal, M:Id, Gen) :-
|
|
364
|
+
!,
|
|
365
|
+
goal_id(Goal, Id, Gen).
|
|
366
|
+
goal_id(Var, _, _) :-
|
|
367
|
+
var(Var),
|
|
368
|
+
!,
|
|
369
|
+
instantiation_error(Var).
|
|
370
|
+
goal_id(Atom, Atom, Atom) :-
|
|
371
|
+
atom(Atom),
|
|
372
|
+
!.
|
|
373
|
+
goal_id(Term, _, _) :-
|
|
374
|
+
\+ compound(Term),
|
|
375
|
+
!,
|
|
376
|
+
type_error(callable, Term).
|
|
377
|
+
goal_id(Term, Skolem, Gen) :- % most general form
|
|
378
|
+
compound_name_arity(Term, Name, Arity),
|
|
379
|
+
compound_name_arity(Skolem, Name, Arity),
|
|
380
|
+
compound_name_arity(Gen, Name, Arity),
|
|
381
|
+
copy_goal_args(1, Term, Skolem, Gen),
|
|
382
|
+
( Gen =@= Term
|
|
383
|
+
-> ! % No more specific one; we can commit
|
|
384
|
+
; true
|
|
385
|
+
),
|
|
386
|
+
numbervars(Skolem, 0, _).
|
|
387
|
+
goal_id(Term, Skolem, Term) :- % most specific form
|
|
388
|
+
debug(sandbox(specify), 'Retrying with ~p', [Term]),
|
|
389
|
+
copy_term(Term, Skolem),
|
|
390
|
+
numbervars(Skolem, 0, _).
|
|
391
|
+
|
|
392
|
+
%! copy_goal_args(+I, +Term, +Skolem, +Gen) is det.
|
|
393
|
+
%
|
|
394
|
+
% Create the most general form, but keep module qualified
|
|
395
|
+
% arguments because they will likely be called anyway.
|
|
396
|
+
|
|
397
|
+
copy_goal_args(I, Term, Skolem, Gen) :-
|
|
398
|
+
arg(I, Term, TA),
|
|
399
|
+
!,
|
|
400
|
+
arg(I, Skolem, SA),
|
|
401
|
+
arg(I, Gen, GA),
|
|
402
|
+
copy_goal_arg(TA, SA, GA),
|
|
403
|
+
I2 is I + 1,
|
|
404
|
+
copy_goal_args(I2, Term, Skolem, Gen).
|
|
405
|
+
copy_goal_args(_, _, _, _).
|
|
406
|
+
|
|
407
|
+
copy_goal_arg(Arg, SArg, Arg) :-
|
|
408
|
+
copy_goal_arg(Arg),
|
|
409
|
+
!,
|
|
410
|
+
copy_term(Arg, SArg).
|
|
411
|
+
copy_goal_arg(_, _, _).
|
|
412
|
+
|
|
413
|
+
copy_goal_arg(Var) :- var(Var), !, fail.
|
|
414
|
+
copy_goal_arg(_:_).
|
|
415
|
+
|
|
416
|
+
%! verify_safe_declaration(+Decl)
|
|
417
|
+
%
|
|
418
|
+
% See whether a safe declaration makes sense. That is, the
|
|
419
|
+
% predicate must be defined (such that the attacker cannot define
|
|
420
|
+
% the predicate), must be sufficiently instantiated and only ISO
|
|
421
|
+
% declared predicates may omit a module qualification.
|
|
422
|
+
%
|
|
423
|
+
% @tbd Verify safe_meta/2 declarations. It is a bit less clear
|
|
424
|
+
% what the rules are.
|
|
425
|
+
|
|
426
|
+
term_expansion(safe_primitive(Goal), Term) :-
|
|
427
|
+
( verify_safe_declaration(Goal)
|
|
428
|
+
-> Term = safe_primitive(Goal)
|
|
429
|
+
; Term = []
|
|
430
|
+
).
|
|
431
|
+
term_expansion((safe_primitive(Goal) :- Body), Term) :-
|
|
432
|
+
( verify_safe_declaration(Goal)
|
|
433
|
+
-> Term = (safe_primitive(Goal) :- Body)
|
|
434
|
+
; Term = []
|
|
435
|
+
).
|
|
436
|
+
|
|
437
|
+
system:term_expansion(sandbox:safe_primitive(Goal), Term) :-
|
|
438
|
+
\+ current_prolog_flag(xref, true),
|
|
439
|
+
( verify_safe_declaration(Goal)
|
|
440
|
+
-> Term = sandbox:safe_primitive(Goal)
|
|
441
|
+
; Term = []
|
|
442
|
+
).
|
|
443
|
+
system:term_expansion((sandbox:safe_primitive(Goal) :- Body), Term) :-
|
|
444
|
+
\+ current_prolog_flag(xref, true),
|
|
445
|
+
( verify_safe_declaration(Goal)
|
|
446
|
+
-> Term = (sandbox:safe_primitive(Goal) :- Body)
|
|
447
|
+
; Term = []
|
|
448
|
+
).
|
|
449
|
+
|
|
450
|
+
verify_safe_declaration(Var) :-
|
|
451
|
+
var(Var),
|
|
452
|
+
!,
|
|
453
|
+
instantiation_error(Var).
|
|
454
|
+
verify_safe_declaration(Module:Goal) :-
|
|
455
|
+
!,
|
|
456
|
+
must_be(atom, Module),
|
|
457
|
+
must_be(callable, Goal),
|
|
458
|
+
( ok_meta(Module:Goal)
|
|
459
|
+
-> true
|
|
460
|
+
; ( predicate_property(Module:Goal, visible)
|
|
461
|
+
-> true
|
|
462
|
+
; predicate_property(Module:Goal, foreign)
|
|
463
|
+
),
|
|
464
|
+
\+ predicate_property(Module:Goal, imported_from(_)),
|
|
465
|
+
\+ predicate_property(Module:Goal, meta_predicate(_))
|
|
466
|
+
-> true
|
|
467
|
+
; permission_error(declare, safe_goal, Module:Goal)
|
|
468
|
+
).
|
|
469
|
+
verify_safe_declaration(Goal) :-
|
|
470
|
+
must_be(callable, Goal),
|
|
471
|
+
( predicate_property(system:Goal, iso),
|
|
472
|
+
\+ predicate_property(system:Goal, meta_predicate())
|
|
473
|
+
-> true
|
|
474
|
+
; permission_error(declare, safe_goal, Goal)
|
|
475
|
+
).
|
|
476
|
+
|
|
477
|
+
ok_meta(system:assert(_)).
|
|
478
|
+
ok_meta(system:load_files(_,_)).
|
|
479
|
+
ok_meta(system:use_module(_,_)).
|
|
480
|
+
ok_meta(system:use_module(_)).
|
|
481
|
+
ok_meta('$syspreds':predicate_property(_,_)).
|
|
482
|
+
|
|
483
|
+
verify_predefined_safe_declarations :-
|
|
484
|
+
forall(clause(safe_primitive(Goal), _Body, Ref),
|
|
485
|
+
( E = error(F,_),
|
|
486
|
+
catch(verify_safe_declaration(Goal), E, true),
|
|
487
|
+
( nonvar(F)
|
|
488
|
+
-> clause_property(Ref, file(File)),
|
|
489
|
+
clause_property(Ref, line_count(Line)),
|
|
490
|
+
print_message(error, bad_safe_declaration(Goal, File, Line))
|
|
491
|
+
; true
|
|
492
|
+
)
|
|
493
|
+
)).
|
|
494
|
+
|
|
495
|
+
:- initialization(verify_predefined_safe_declarations, now).
|
|
496
|
+
|
|
497
|
+
%! safe_primitive(?Goal) is nondet.
|
|
498
|
+
%
|
|
499
|
+
% True if Goal is safe to call (i.e., cannot access dangerous
|
|
500
|
+
% system-resources and cannot upset other parts of the Prolog
|
|
501
|
+
% process). There are two types of facts. ISO built-ins are
|
|
502
|
+
% declared without a module prefix. This is safe because it is not
|
|
503
|
+
% allowed to (re-)define these primitives (i.e., give them an
|
|
504
|
+
% unsafe implementation) and the way around
|
|
505
|
+
% (redefine_system_predicate/1) is unsafe. The other group are
|
|
506
|
+
% module-qualified and only match if the system infers that the
|
|
507
|
+
% predicate is imported from the given module.
|
|
508
|
+
|
|
509
|
+
% First, all ISO system predicates that are considered safe
|
|
510
|
+
|
|
511
|
+
safe_primitive(true).
|
|
512
|
+
safe_primitive(fail).
|
|
513
|
+
safe_primitive(system:false).
|
|
514
|
+
safe_primitive(repeat).
|
|
515
|
+
safe_primitive(!).
|
|
516
|
+
% types
|
|
517
|
+
safe_primitive(var(_)).
|
|
518
|
+
safe_primitive(nonvar(_)).
|
|
519
|
+
safe_primitive(system:attvar(_)).
|
|
520
|
+
safe_primitive(integer(_)).
|
|
521
|
+
safe_primitive(float(_)).
|
|
522
|
+
:- if(current_predicate(rational/1)).
|
|
523
|
+
safe_primitive(system:rational(_)).
|
|
524
|
+
safe_primitive(system:rational(_,_,_)).
|
|
525
|
+
:- endif.
|
|
526
|
+
safe_primitive(number(_)).
|
|
527
|
+
safe_primitive(atom(_)).
|
|
528
|
+
safe_primitive(system:blob(_,_)).
|
|
529
|
+
safe_primitive(system:string(_)).
|
|
530
|
+
safe_primitive(atomic(_)).
|
|
531
|
+
safe_primitive(compound(_)).
|
|
532
|
+
safe_primitive(callable(_)).
|
|
533
|
+
safe_primitive(ground(_)).
|
|
534
|
+
safe_primitive(system:nonground(_,_)).
|
|
535
|
+
safe_primitive(system:cyclic_term(_)).
|
|
536
|
+
safe_primitive(acyclic_term(_)).
|
|
537
|
+
safe_primitive(system:is_stream(_)).
|
|
538
|
+
safe_primitive(system:'$is_char'(_)).
|
|
539
|
+
safe_primitive(system:'$is_char_code'(_)).
|
|
540
|
+
safe_primitive(system:'$is_char_list'(_,_)).
|
|
541
|
+
safe_primitive(system:'$is_code_list'(_,_)).
|
|
542
|
+
% ordering
|
|
543
|
+
safe_primitive(@>(_,_)).
|
|
544
|
+
safe_primitive(@>=(_,_)).
|
|
545
|
+
safe_primitive(==(_,_)).
|
|
546
|
+
safe_primitive(@<(_,_)).
|
|
547
|
+
safe_primitive(@=<(_,_)).
|
|
548
|
+
safe_primitive(compare(_,_,_)).
|
|
549
|
+
safe_primitive(sort(_,_)).
|
|
550
|
+
safe_primitive(keysort(_,_)).
|
|
551
|
+
safe_primitive(system: =@=(_,_)).
|
|
552
|
+
safe_primitive(system:'$btree_find_node'(_,_,_,_,_)).
|
|
553
|
+
|
|
554
|
+
% unification and equivalence
|
|
555
|
+
safe_primitive(=(_,_)).
|
|
556
|
+
safe_primitive(\=(_,_)).
|
|
557
|
+
safe_primitive(system:'?='(_,_)).
|
|
558
|
+
safe_primitive(system:unifiable(_,_,_)).
|
|
559
|
+
safe_primitive(unify_with_occurs_check(_,_)).
|
|
560
|
+
safe_primitive(\==(_,_)).
|
|
561
|
+
% arithmetic
|
|
562
|
+
safe_primitive(is(_,_)).
|
|
563
|
+
safe_primitive(>(_,_)).
|
|
564
|
+
safe_primitive(>=(_,_)).
|
|
565
|
+
safe_primitive(=:=(_,_)).
|
|
566
|
+
safe_primitive(=\=(_,_)).
|
|
567
|
+
safe_primitive(=<(_,_)).
|
|
568
|
+
safe_primitive(<(_,_)).
|
|
569
|
+
:- if(current_prolog_flag(bounded, false)).
|
|
570
|
+
safe_primitive(system:nth_integer_root_and_remainder(_,_,_,_)).
|
|
571
|
+
:- endif.
|
|
572
|
+
safe_primitive(system:current_arithmetic_function(_)).
|
|
573
|
+
safe_primitive(system:bounded_number(_,_,_)).
|
|
574
|
+
safe_primitive(system:float_class(_,_)).
|
|
575
|
+
safe_primitive(system:float_parts(_,_,_,_)).
|
|
576
|
+
|
|
577
|
+
% term-handling
|
|
578
|
+
safe_primitive(arg(_,_,_)).
|
|
579
|
+
safe_primitive(system:setarg(_,_,_)).
|
|
580
|
+
safe_primitive(system:nb_setarg(_,_,_)).
|
|
581
|
+
safe_primitive(system:nb_linkarg(_,_,_)).
|
|
582
|
+
safe_primitive(functor(_,_,_)).
|
|
583
|
+
safe_primitive(system:functor(_,_,_,_)).
|
|
584
|
+
safe_primitive(_ =.. _).
|
|
585
|
+
safe_primitive(system:compound_name_arity(_,_,_)).
|
|
586
|
+
safe_primitive(system:compound_name_arguments(_,_,_)).
|
|
587
|
+
safe_primitive(system:'$filled_array'(_,_,_,_)).
|
|
588
|
+
safe_primitive(copy_term(_,_)).
|
|
589
|
+
safe_primitive(system:copy_term(_,_,_,_)).
|
|
590
|
+
safe_primitive(system:duplicate_term(_,_)).
|
|
591
|
+
safe_primitive(system:copy_term_nat(_,_)).
|
|
592
|
+
safe_primitive(system:size_abstract_term(_,_,_)).
|
|
593
|
+
safe_primitive(numbervars(_,_,_)).
|
|
594
|
+
safe_primitive(system:numbervars(_,_,_,_)).
|
|
595
|
+
safe_primitive(subsumes_term(_,_)).
|
|
596
|
+
safe_primitive(system:term_hash(_,_)).
|
|
597
|
+
safe_primitive(system:term_hash(_,_,_,_)).
|
|
598
|
+
safe_primitive(system:variant_sha1(_,_)).
|
|
599
|
+
safe_primitive(system:variant_hash(_,_)).
|
|
600
|
+
safe_primitive(system:'$term_size'(_,_,_)).
|
|
601
|
+
|
|
602
|
+
% dicts
|
|
603
|
+
safe_primitive(system:is_dict(_)).
|
|
604
|
+
safe_primitive(system:is_dict(_,_)).
|
|
605
|
+
safe_primitive(system:get_dict(_,_,_)).
|
|
606
|
+
safe_primitive(system:get_dict(_,_,_,_,_)).
|
|
607
|
+
safe_primitive(system:'$get_dict_ex'(_,_,_)).
|
|
608
|
+
safe_primitive(system:dict_create(_,_,_)).
|
|
609
|
+
safe_primitive(system:dict_pairs(_,_,_)).
|
|
610
|
+
safe_primitive(system:put_dict(_,_,_)).
|
|
611
|
+
safe_primitive(system:put_dict(_,_,_,_)).
|
|
612
|
+
safe_primitive(system:del_dict(_,_,_,_)).
|
|
613
|
+
safe_primitive(system:select_dict(_,_,_)).
|
|
614
|
+
safe_primitive(system:b_set_dict(_,_,_)).
|
|
615
|
+
safe_primitive(system:nb_set_dict(_,_,_)).
|
|
616
|
+
safe_primitive(system:nb_link_dict(_,_,_)).
|
|
617
|
+
safe_primitive(system:(:<(_,_))).
|
|
618
|
+
safe_primitive(system:(>:<(_,_))).
|
|
619
|
+
% atoms
|
|
620
|
+
safe_primitive(atom_chars(_, _)).
|
|
621
|
+
safe_primitive(atom_codes(_, _)).
|
|
622
|
+
safe_primitive(sub_atom(_,_,_,_,_)).
|
|
623
|
+
safe_primitive(atom_concat(_,_,_)).
|
|
624
|
+
safe_primitive(atom_length(_,_)).
|
|
625
|
+
safe_primitive(char_code(_,_)).
|
|
626
|
+
safe_primitive(system:name(_,_)).
|
|
627
|
+
safe_primitive(system:atomic_concat(_,_,_)).
|
|
628
|
+
safe_primitive(system:atomic_list_concat(_,_)).
|
|
629
|
+
safe_primitive(system:atomic_list_concat(_,_,_)).
|
|
630
|
+
safe_primitive(system:downcase_atom(_,_)).
|
|
631
|
+
safe_primitive(system:upcase_atom(_,_)).
|
|
632
|
+
safe_primitive(system:char_type(_,_)).
|
|
633
|
+
safe_primitive(system:normalize_space(_,_)).
|
|
634
|
+
safe_primitive(system:sub_atom_icasechk(_,_,_)).
|
|
635
|
+
% numbers
|
|
636
|
+
safe_primitive(number_codes(_,_)).
|
|
637
|
+
safe_primitive(number_chars(_,_)).
|
|
638
|
+
safe_primitive(system:atom_number(_,_)).
|
|
639
|
+
safe_primitive(system:code_type(_,_)).
|
|
640
|
+
% strings
|
|
641
|
+
safe_primitive(system:atom_string(_,_)).
|
|
642
|
+
safe_primitive(system:number_string(_,_)).
|
|
643
|
+
safe_primitive(system:string_chars(_, _)).
|
|
644
|
+
safe_primitive(system:string_codes(_, _)).
|
|
645
|
+
safe_primitive(system:string_code(_,_,_)).
|
|
646
|
+
safe_primitive(system:sub_string(_,_,_,_,_)).
|
|
647
|
+
safe_primitive(system:split_string(_,_,_,_)).
|
|
648
|
+
safe_primitive(system:atomics_to_string(_,_,_)).
|
|
649
|
+
safe_primitive(system:atomics_to_string(_,_)).
|
|
650
|
+
safe_primitive(system:string_concat(_,_,_)).
|
|
651
|
+
safe_primitive(system:string_length(_,_)).
|
|
652
|
+
safe_primitive(system:string_lower(_,_)).
|
|
653
|
+
safe_primitive(system:string_upper(_,_)).
|
|
654
|
+
safe_primitive(system:term_string(_,_)).
|
|
655
|
+
safe_primitive('$syspreds':term_string(_,_,_)).
|
|
656
|
+
% Lists
|
|
657
|
+
safe_primitive(length(_,_)).
|
|
658
|
+
% exceptions
|
|
659
|
+
safe_primitive(throw(_)).
|
|
660
|
+
safe_primitive(system:abort).
|
|
661
|
+
% misc
|
|
662
|
+
safe_primitive(current_prolog_flag(_,_)).
|
|
663
|
+
safe_primitive(current_op(_,_,_)).
|
|
664
|
+
safe_primitive(system:sleep(_)).
|
|
665
|
+
safe_primitive(system:thread_self(_)).
|
|
666
|
+
safe_primitive(system:get_time(_)).
|
|
667
|
+
safe_primitive(system:statistics(_,_)).
|
|
668
|
+
:- if(current_prolog_flag(threads,true)).
|
|
669
|
+
safe_primitive(system:thread_statistics(Id,_,_)) :-
|
|
670
|
+
( var(Id)
|
|
671
|
+
-> instantiation_error(Id)
|
|
672
|
+
; thread_self(Id)
|
|
673
|
+
).
|
|
674
|
+
safe_primitive(system:thread_property(Id,_)) :-
|
|
675
|
+
( var(Id)
|
|
676
|
+
-> instantiation_error(Id)
|
|
677
|
+
; thread_self(Id)
|
|
678
|
+
).
|
|
679
|
+
:- endif.
|
|
680
|
+
safe_primitive(system:format_time(_,_,_)).
|
|
681
|
+
safe_primitive(system:format_time(_,_,_,_)).
|
|
682
|
+
safe_primitive(system:date_time_stamp(_,_)).
|
|
683
|
+
safe_primitive(system:stamp_date_time(_,_,_)).
|
|
684
|
+
safe_primitive(system:strip_module(_,_,_)).
|
|
685
|
+
safe_primitive('$messages':message_to_string(_,_)).
|
|
686
|
+
safe_primitive(system:import_module(_,_)).
|
|
687
|
+
safe_primitive(system:file_base_name(_,_)).
|
|
688
|
+
safe_primitive(system:file_directory_name(_,_)).
|
|
689
|
+
safe_primitive(system:file_name_extension(_,_,_)).
|
|
690
|
+
|
|
691
|
+
safe_primitive(clause(H,_)) :- safe_clause(H).
|
|
692
|
+
safe_primitive(asserta(X)) :- safe_assert(X).
|
|
693
|
+
safe_primitive(assertz(X)) :- safe_assert(X).
|
|
694
|
+
safe_primitive(retract(X)) :- safe_assert(X).
|
|
695
|
+
safe_primitive(retractall(X)) :- safe_assert(X).
|
|
696
|
+
safe_primitive(current_predicate(X)) :- safe_current_predicate(X).
|
|
697
|
+
safe_primitive('$dcg':dcg_translate_rule(_,_)).
|
|
698
|
+
safe_primitive('$syspreds':predicate_property(Pred, _)) :-
|
|
699
|
+
nonvar(Pred),
|
|
700
|
+
Pred \= (_:_).
|
|
701
|
+
|
|
702
|
+
% We need to do data flow analysis to find the tag of the
|
|
703
|
+
% target key before we can conclude that functions on dicts
|
|
704
|
+
% are safe.
|
|
705
|
+
safe_primitive('$dicts':'.'(_,K,_)) :- atom(K).
|
|
706
|
+
safe_primitive('$dicts':'.'(_,K,_)) :-
|
|
707
|
+
( nonvar(K)
|
|
708
|
+
-> dict_built_in(K)
|
|
709
|
+
; instantiation_error(K)
|
|
710
|
+
).
|
|
711
|
+
|
|
712
|
+
dict_built_in(get(_)).
|
|
713
|
+
dict_built_in(get(_,_)).
|
|
714
|
+
dict_built_in(put(_)).
|
|
715
|
+
dict_built_in(put(_,_)).
|
|
716
|
+
|
|
717
|
+
% The non-ISO system predicates. These can be redefined, so we must
|
|
718
|
+
% be careful to ensure the system ones are used.
|
|
719
|
+
|
|
720
|
+
safe_primitive(system:false).
|
|
721
|
+
safe_primitive(system:cyclic_term(_)).
|
|
722
|
+
safe_primitive(system:msort(_,_)).
|
|
723
|
+
safe_primitive(system:sort(_,_,_,_)).
|
|
724
|
+
safe_primitive(system:between(_,_,_)).
|
|
725
|
+
safe_primitive(system:succ(_,_)).
|
|
726
|
+
safe_primitive(system:plus(_,_,_)).
|
|
727
|
+
safe_primitive(system:float_class(_,_)).
|
|
728
|
+
safe_primitive(system:term_singletons(_,_)).
|
|
729
|
+
safe_primitive(system:term_variables(_,_)).
|
|
730
|
+
safe_primitive(system:term_variables(_,_,_)).
|
|
731
|
+
safe_primitive(system:'$term_size'(_,_,_)).
|
|
732
|
+
safe_primitive(system:atom_to_term(_,_,_)).
|
|
733
|
+
safe_primitive(system:term_to_atom(_,_)).
|
|
734
|
+
safe_primitive(system:atomic_list_concat(_,_,_)).
|
|
735
|
+
safe_primitive(system:atomic_list_concat(_,_)).
|
|
736
|
+
safe_primitive(system:downcase_atom(_,_)).
|
|
737
|
+
safe_primitive(system:upcase_atom(_,_)).
|
|
738
|
+
safe_primitive(system:is_list(_)).
|
|
739
|
+
safe_primitive(system:memberchk(_,_)).
|
|
740
|
+
safe_primitive(system:'$skip_list'(_,_,_)).
|
|
741
|
+
safe_primitive(system:'$seek_list'(_, _, _, _)).
|
|
742
|
+
% attributes
|
|
743
|
+
safe_primitive(system:get_attr(_,_,_)).
|
|
744
|
+
safe_primitive(system:get_attrs(_,_)).
|
|
745
|
+
safe_primitive(system:term_attvars(_,_)).
|
|
746
|
+
safe_primitive(system:del_attr(_,_)).
|
|
747
|
+
safe_primitive(system:del_attrs(_)).
|
|
748
|
+
safe_primitive('$attvar':copy_term(_,_,_)).
|
|
749
|
+
% globals
|
|
750
|
+
safe_primitive(system:b_getval(_,_)).
|
|
751
|
+
safe_primitive(system:b_setval(Var,_)) :-
|
|
752
|
+
safe_global_var(Var).
|
|
753
|
+
safe_primitive(system:nb_getval(_,_)).
|
|
754
|
+
safe_primitive(system:nb_setval(Var,_)) :-
|
|
755
|
+
safe_global_var(Var).
|
|
756
|
+
safe_primitive(system:nb_linkval(Var,_)) :-
|
|
757
|
+
safe_global_var(Var).
|
|
758
|
+
safe_primitive(system:nb_current(_,_)).
|
|
759
|
+
% database
|
|
760
|
+
safe_primitive(system:assert(X)) :-
|
|
761
|
+
safe_assert(X).
|
|
762
|
+
% Output
|
|
763
|
+
safe_primitive(system:writeln(_)).
|
|
764
|
+
safe_primitive('$messages':print_message(_,_)).
|
|
765
|
+
|
|
766
|
+
% Stack limits (down)
|
|
767
|
+
safe_primitive('$syspreds':set_prolog_stack(Stack, limit(ByteExpr))) :-
|
|
768
|
+
nonvar(Stack),
|
|
769
|
+
stack_name(Stack),
|
|
770
|
+
catch(Bytes is ByteExpr, _, fail),
|
|
771
|
+
prolog_stack_property(Stack, limit(Current)),
|
|
772
|
+
Bytes =< Current.
|
|
773
|
+
|
|
774
|
+
stack_name(global).
|
|
775
|
+
stack_name(local).
|
|
776
|
+
stack_name(trail).
|
|
777
|
+
|
|
778
|
+
safe_primitive('$tabling':abolish_all_tables).
|
|
779
|
+
safe_primitive('$tabling':'$wrap_tabled'(Module:_Head, _Mode)) :-
|
|
780
|
+
prolog_load_context(module, Module),
|
|
781
|
+
!.
|
|
782
|
+
safe_primitive('$tabling':'$moded_wrap_tabled'(Module:_Head,_,_,_,_)) :-
|
|
783
|
+
prolog_load_context(module, Module),
|
|
784
|
+
!.
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
% use_module/1. We only allow for .pl files that are loaded from
|
|
788
|
+
% relative paths that do not contain /../
|
|
789
|
+
|
|
790
|
+
safe_primitive(system:use_module(Spec, _Import)) :-
|
|
791
|
+
safe_primitive(system:use_module(Spec)).
|
|
792
|
+
safe_primitive(system:load_files(Spec, Options)) :-
|
|
793
|
+
safe_primitive(system:use_module(Spec)),
|
|
794
|
+
maplist(safe_load_file_option, Options).
|
|
795
|
+
safe_primitive(system:use_module(Spec)) :-
|
|
796
|
+
ground(Spec),
|
|
797
|
+
( atom(Spec)
|
|
798
|
+
-> Path = Spec
|
|
799
|
+
; Spec =.. [_Alias, Segments],
|
|
800
|
+
phrase(segments_to_path(Segments), List),
|
|
801
|
+
atomic_list_concat(List, Path)
|
|
802
|
+
),
|
|
803
|
+
\+ is_absolute_file_name(Path),
|
|
804
|
+
\+ sub_atom(Path, _, _, _, '/../'),
|
|
805
|
+
absolute_file_name(Spec, AbsFile,
|
|
806
|
+
[ access(read),
|
|
807
|
+
file_type(prolog),
|
|
808
|
+
file_errors(fail)
|
|
809
|
+
]),
|
|
810
|
+
file_name_extension(_, Ext, AbsFile),
|
|
811
|
+
save_extension(Ext).
|
|
812
|
+
|
|
813
|
+
% support predicates for safe_primitive, validating the safety of
|
|
814
|
+
% arguments to certain goals.
|
|
815
|
+
|
|
816
|
+
segments_to_path(A/B) -->
|
|
817
|
+
!,
|
|
818
|
+
segments_to_path(A),
|
|
819
|
+
[/],
|
|
820
|
+
segments_to_path(B).
|
|
821
|
+
segments_to_path(X) -->
|
|
822
|
+
[X].
|
|
823
|
+
|
|
824
|
+
save_extension(pl).
|
|
825
|
+
|
|
826
|
+
safe_load_file_option(if(changed)).
|
|
827
|
+
safe_load_file_option(if(not_loaded)).
|
|
828
|
+
safe_load_file_option(must_be_module(_)).
|
|
829
|
+
safe_load_file_option(optimise(_)).
|
|
830
|
+
safe_load_file_option(silent(_)).
|
|
831
|
+
|
|
832
|
+
%! safe_assert(+Term) is semidet.
|
|
833
|
+
%
|
|
834
|
+
% True if assert(Term) is safe, which means it asserts in the
|
|
835
|
+
% current module. Cross-module asserts are considered unsafe. We
|
|
836
|
+
% only allow for adding facts. In theory, we could also allow for
|
|
837
|
+
% rules if we prove the safety of the body.
|
|
838
|
+
|
|
839
|
+
safe_assert(C) :- cyclic_term(C), !, fail.
|
|
840
|
+
safe_assert(X) :- var(X), !, fail.
|
|
841
|
+
safe_assert(_Head:-_Body) :- !, fail.
|
|
842
|
+
safe_assert(_:_) :- !, fail.
|
|
843
|
+
safe_assert(_).
|
|
844
|
+
|
|
845
|
+
%! safe_clause(+Head) is semidet.
|
|
846
|
+
%
|
|
847
|
+
% Consider a call to clause safe if it does not try to cross a
|
|
848
|
+
% module boundary. Cross-module usage of clause/2 can extract
|
|
849
|
+
% private information from other modules.
|
|
850
|
+
|
|
851
|
+
safe_clause(H) :- var(H), !.
|
|
852
|
+
safe_clause(_:_) :- !, fail.
|
|
853
|
+
safe_clause(_).
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
%! safe_global_var(+Name) is semidet.
|
|
857
|
+
%
|
|
858
|
+
% True if Name is a global variable to which assertion is
|
|
859
|
+
% considered safe.
|
|
860
|
+
|
|
861
|
+
safe_global_var(Name) :-
|
|
862
|
+
var(Name),
|
|
863
|
+
!,
|
|
864
|
+
instantiation_error(Name).
|
|
865
|
+
safe_global_var(Name) :-
|
|
866
|
+
safe_global_variable(Name).
|
|
867
|
+
|
|
868
|
+
%! safe_global_variable(Name) is semidet.
|
|
869
|
+
%
|
|
870
|
+
% Declare the given global variable safe to write to.
|
|
871
|
+
|
|
872
|
+
%! safe_current_predicate(+X)
|
|
873
|
+
%
|
|
874
|
+
% current_predicate/1 is safe when not used with qualification.
|
|
875
|
+
|
|
876
|
+
safe_current_predicate(X) :-
|
|
877
|
+
nonvar(X),
|
|
878
|
+
X = _:_, !,
|
|
879
|
+
fail.
|
|
880
|
+
safe_current_predicate(_).
|
|
881
|
+
|
|
882
|
+
%! safe_meta(+Goal, -Called:list(callable)) is semidet.
|
|
883
|
+
%
|
|
884
|
+
% Hook. True if Goal is a meta-predicate that is considered safe
|
|
885
|
+
% iff all elements in Called are safe.
|
|
886
|
+
|
|
887
|
+
safe_meta(system:put_attr(V,M,A), Called) :-
|
|
888
|
+
!,
|
|
889
|
+
( atom(M)
|
|
890
|
+
-> attr_hook_predicates([ attr_unify_hook(A, _),
|
|
891
|
+
attribute_goals(V,_,_),
|
|
892
|
+
project_attributes(_,_)
|
|
893
|
+
], M, Called)
|
|
894
|
+
; instantiation_error(M)
|
|
895
|
+
).
|
|
896
|
+
safe_meta(system:with_output_to(Output, G), [G]) :-
|
|
897
|
+
safe_output(Output),
|
|
898
|
+
!.
|
|
899
|
+
safe_meta(system:format(Format, Args), Calls) :-
|
|
900
|
+
format_calls(Format, Args, Calls).
|
|
901
|
+
safe_meta(system:format(Output, Format, Args), Calls) :-
|
|
902
|
+
safe_output(Output),
|
|
903
|
+
format_calls(Format, Args, Calls).
|
|
904
|
+
safe_meta(prolog_debug:debug(_Term, Format, Args), Calls) :-
|
|
905
|
+
format_calls(Format, Args, Calls).
|
|
906
|
+
safe_meta(system:set_prolog_flag(Flag, Value), []) :-
|
|
907
|
+
atom(Flag),
|
|
908
|
+
safe_prolog_flag(Flag, Value).
|
|
909
|
+
safe_meta('$attvar':freeze(_Var,Goal), [Goal]).
|
|
910
|
+
safe_meta(phrase(NT,Xs0,Xs), [Goal]) :- % phrase/2,3 and call_dcg/2,3
|
|
911
|
+
expand_nt(NT,Xs0,Xs,Goal).
|
|
912
|
+
safe_meta(phrase(NT,Xs0), [Goal]) :-
|
|
913
|
+
expand_nt(NT,Xs0,[],Goal).
|
|
914
|
+
safe_meta('$dcg':call_dcg(NT,Xs0,Xs), [Goal]) :-
|
|
915
|
+
expand_nt(NT,Xs0,Xs,Goal).
|
|
916
|
+
safe_meta('$dcg':call_dcg(NT,Xs0), [Goal]) :-
|
|
917
|
+
expand_nt(NT,Xs0,[],Goal).
|
|
918
|
+
safe_meta('$tabling':abolish_table_subgoals(V), []) :-
|
|
919
|
+
\+ qualified(V).
|
|
920
|
+
safe_meta('$tabling':current_table(V, _), []) :-
|
|
921
|
+
\+ qualified(V).
|
|
922
|
+
safe_meta('$tabling':tnot(G), [G]).
|
|
923
|
+
safe_meta('$tabling':not_exists(G), [G]).
|
|
924
|
+
|
|
925
|
+
qualified(V) :-
|
|
926
|
+
nonvar(V),
|
|
927
|
+
V = _:_.
|
|
928
|
+
|
|
929
|
+
%! attr_hook_predicates(+Hooks0, +Module, -Hooks) is det.
|
|
930
|
+
%
|
|
931
|
+
% Filter the defined hook implementations. This is safe because
|
|
932
|
+
% (1) calling an undefined predicate is not a safety issue, (2)
|
|
933
|
+
% the user an only assert in the current module and only
|
|
934
|
+
% predicates that have a safe body. This avoids the need to define
|
|
935
|
+
% attribute hooks solely for the purpose of making them safe.
|
|
936
|
+
|
|
937
|
+
attr_hook_predicates([], _, []).
|
|
938
|
+
attr_hook_predicates([H|T], M, Called) :-
|
|
939
|
+
( predicate_property(M:H, defined)
|
|
940
|
+
-> Called = [M:H|Rest]
|
|
941
|
+
; Called = Rest
|
|
942
|
+
),
|
|
943
|
+
attr_hook_predicates(T, M, Rest).
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
%! expand_nt(+NT, ?Xs0, ?Xs, -NewGoal)
|
|
947
|
+
%
|
|
948
|
+
% Similar to expand_phrase/2, but we do throw errors instead of
|
|
949
|
+
% failing if NT is not sufficiently instantiated.
|
|
950
|
+
|
|
951
|
+
expand_nt(NT, _Xs0, _Xs, _NewGoal) :-
|
|
952
|
+
strip_module(NT, _, Plain),
|
|
953
|
+
var(Plain),
|
|
954
|
+
!,
|
|
955
|
+
instantiation_error(Plain).
|
|
956
|
+
expand_nt(NT, Xs0, Xs, NewGoal) :-
|
|
957
|
+
dcg_translate_rule((pseudo_nt --> NT),
|
|
958
|
+
(pseudo_nt(Xs0c,Xsc) :- NewGoal0)),
|
|
959
|
+
( var(Xsc), Xsc \== Xs0c
|
|
960
|
+
-> Xs = Xsc, NewGoal1 = NewGoal0
|
|
961
|
+
; NewGoal1 = (NewGoal0, Xsc = Xs)
|
|
962
|
+
),
|
|
963
|
+
( var(Xs0c)
|
|
964
|
+
-> Xs0 = Xs0c,
|
|
965
|
+
NewGoal = NewGoal1
|
|
966
|
+
; NewGoal = ( Xs0 = Xs0c, NewGoal1 )
|
|
967
|
+
).
|
|
968
|
+
|
|
969
|
+
%! safe_meta_call(+Goal, +Context, -Called:list(callable)) is semidet.
|
|
970
|
+
%
|
|
971
|
+
% True if Goal is a meta-predicate that is considered safe
|
|
972
|
+
% iff all elements in Called are safe.
|
|
973
|
+
|
|
974
|
+
safe_meta_call(Goal, _, _Called) :-
|
|
975
|
+
debug(sandbox(meta), 'Safe meta ~p?', [Goal]),
|
|
976
|
+
fail.
|
|
977
|
+
safe_meta_call(Goal, Context, Called) :-
|
|
978
|
+
( safe_meta(Goal, Called)
|
|
979
|
+
-> true
|
|
980
|
+
; safe_meta(Goal, Context, Called)
|
|
981
|
+
),
|
|
982
|
+
!. % call hook
|
|
983
|
+
safe_meta_call(Goal, _, Called) :-
|
|
984
|
+
Goal = M:Plain,
|
|
985
|
+
compound(Plain),
|
|
986
|
+
compound_name_arity(Plain, Name, Arity),
|
|
987
|
+
safe_meta_predicate(M:Name/Arity),
|
|
988
|
+
predicate_property(Goal, meta_predicate(Spec)),
|
|
989
|
+
!,
|
|
990
|
+
called(Spec, Plain, Called).
|
|
991
|
+
safe_meta_call(M:Goal, _, Called) :-
|
|
992
|
+
!,
|
|
993
|
+
generic_goal(Goal, Gen),
|
|
994
|
+
safe_meta(M:Gen),
|
|
995
|
+
called(Gen, Goal, Called).
|
|
996
|
+
safe_meta_call(Goal, _, Called) :-
|
|
997
|
+
generic_goal(Goal, Gen),
|
|
998
|
+
safe_meta(Gen),
|
|
999
|
+
called(Gen, Goal, Called).
|
|
1000
|
+
|
|
1001
|
+
called(Gen, Goal, Called) :-
|
|
1002
|
+
compound_name_arity(Goal, _, Arity),
|
|
1003
|
+
called(1, Arity, Gen, Goal, Called).
|
|
1004
|
+
|
|
1005
|
+
called(I, Arity, Gen, Goal, Called) :-
|
|
1006
|
+
I =< Arity,
|
|
1007
|
+
!,
|
|
1008
|
+
arg(I, Gen, Spec),
|
|
1009
|
+
( calling_meta_spec(Spec)
|
|
1010
|
+
-> arg(I, Goal, Called0),
|
|
1011
|
+
extend(Spec, Called0, G),
|
|
1012
|
+
Called = [G|Rest]
|
|
1013
|
+
; Called = Rest
|
|
1014
|
+
),
|
|
1015
|
+
I2 is I+1,
|
|
1016
|
+
called(I2, Arity, Gen, Goal, Rest).
|
|
1017
|
+
called(_, _, _, _, []).
|
|
1018
|
+
|
|
1019
|
+
generic_goal(G, Gen) :-
|
|
1020
|
+
functor(G, Name, Arity),
|
|
1021
|
+
functor(Gen, Name, Arity).
|
|
1022
|
+
|
|
1023
|
+
calling_meta_spec(V) :- var(V), !, fail.
|
|
1024
|
+
calling_meta_spec(I) :- integer(I), !.
|
|
1025
|
+
calling_meta_spec(^).
|
|
1026
|
+
calling_meta_spec(//).
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
extend(^, G, Plain) :-
|
|
1030
|
+
!,
|
|
1031
|
+
strip_existential(G, Plain).
|
|
1032
|
+
extend(//, DCG, Goal) :-
|
|
1033
|
+
!,
|
|
1034
|
+
( expand_phrase(call_dcg(DCG,_,_), Goal)
|
|
1035
|
+
-> true
|
|
1036
|
+
; instantiation_error(DCG) % Ask more instantiation.
|
|
1037
|
+
). % might not help, but does not harm.
|
|
1038
|
+
extend(0, G, G) :- !.
|
|
1039
|
+
extend(I, M:G0, M:G) :-
|
|
1040
|
+
!,
|
|
1041
|
+
G0 =.. List,
|
|
1042
|
+
length(Extra, I),
|
|
1043
|
+
append(List, Extra, All),
|
|
1044
|
+
G =.. All.
|
|
1045
|
+
extend(I, G0, G) :-
|
|
1046
|
+
G0 =.. List,
|
|
1047
|
+
length(Extra, I),
|
|
1048
|
+
append(List, Extra, All),
|
|
1049
|
+
G =.. All.
|
|
1050
|
+
|
|
1051
|
+
strip_existential(Var, Var) :-
|
|
1052
|
+
var(Var),
|
|
1053
|
+
!.
|
|
1054
|
+
strip_existential(M:G0, M:G) :-
|
|
1055
|
+
!,
|
|
1056
|
+
strip_existential(G0, G).
|
|
1057
|
+
strip_existential(_^G0, G) :-
|
|
1058
|
+
!,
|
|
1059
|
+
strip_existential(G0, G).
|
|
1060
|
+
strip_existential(G, G).
|
|
1061
|
+
|
|
1062
|
+
%! safe_meta(?Template).
|
|
1063
|
+
|
|
1064
|
+
safe_meta((0,0)).
|
|
1065
|
+
safe_meta((0;0)).
|
|
1066
|
+
safe_meta((0->0)).
|
|
1067
|
+
safe_meta(system:(0*->0)).
|
|
1068
|
+
safe_meta(catch(0,*,0)).
|
|
1069
|
+
safe_meta(findall(*,0,*)).
|
|
1070
|
+
safe_meta('$bags':findall(*,0,*,*)).
|
|
1071
|
+
safe_meta(setof(*,^,*)).
|
|
1072
|
+
safe_meta(bagof(*,^,*)).
|
|
1073
|
+
safe_meta('$bags':findnsols(*,*,0,*)).
|
|
1074
|
+
safe_meta('$bags':findnsols(*,*,0,*,*)).
|
|
1075
|
+
safe_meta(system:call_cleanup(0,0)).
|
|
1076
|
+
safe_meta(system:setup_call_cleanup(0,0,0)).
|
|
1077
|
+
safe_meta(system:setup_call_catcher_cleanup(0,0,*,0)).
|
|
1078
|
+
safe_meta('$attvar':call_residue_vars(0,*)).
|
|
1079
|
+
safe_meta('$syspreds':call_with_inference_limit(0,*,*)).
|
|
1080
|
+
safe_meta('$syspreds':call_with_depth_limit(0,*,*)).
|
|
1081
|
+
safe_meta('$syspreds':undo(0)).
|
|
1082
|
+
safe_meta(^(*,0)).
|
|
1083
|
+
safe_meta(\+(0)).
|
|
1084
|
+
safe_meta(call(0)).
|
|
1085
|
+
safe_meta(call(1,*)).
|
|
1086
|
+
safe_meta(call(2,*,*)).
|
|
1087
|
+
safe_meta(call(3,*,*,*)).
|
|
1088
|
+
safe_meta(call(4,*,*,*,*)).
|
|
1089
|
+
safe_meta(call(5,*,*,*,*,*)).
|
|
1090
|
+
safe_meta(call(6,*,*,*,*,*,*)).
|
|
1091
|
+
safe_meta('$tabling':start_tabling(*,0)).
|
|
1092
|
+
safe_meta('$tabling':start_tabling(*,0,*,*)).
|
|
1093
|
+
safe_meta(wfs:call_delays(0,*)).
|
|
1094
|
+
|
|
1095
|
+
%! safe_output(+Output)
|
|
1096
|
+
%
|
|
1097
|
+
% True if something is a safe output argument for with_output_to/2
|
|
1098
|
+
% and friends. We do not want writing to streams.
|
|
1099
|
+
|
|
1100
|
+
safe_output(Output) :-
|
|
1101
|
+
var(Output),
|
|
1102
|
+
!,
|
|
1103
|
+
instantiation_error(Output).
|
|
1104
|
+
safe_output(atom(_)).
|
|
1105
|
+
safe_output(string(_)).
|
|
1106
|
+
safe_output(codes(_)).
|
|
1107
|
+
safe_output(codes(_,_)).
|
|
1108
|
+
safe_output(chars(_)).
|
|
1109
|
+
safe_output(chars(_,_)).
|
|
1110
|
+
safe_output(current_output).
|
|
1111
|
+
safe_output(current_error).
|
|
1112
|
+
|
|
1113
|
+
%! format_calls(+Format, +FormatArgs, -Calls)
|
|
1114
|
+
%
|
|
1115
|
+
% Find ~@ calls from Format and Args.
|
|
1116
|
+
|
|
1117
|
+
:- public format_calls/3. % used in pengines_io
|
|
1118
|
+
|
|
1119
|
+
format_calls(Format, Args, Calls) :-
|
|
1120
|
+
is_list(Args),
|
|
1121
|
+
!,
|
|
1122
|
+
format_types(Format, Types),
|
|
1123
|
+
( format_callables(Types, Args, Calls)
|
|
1124
|
+
-> true
|
|
1125
|
+
; throw(error(format_error(Format, Types, Args), _))
|
|
1126
|
+
).
|
|
1127
|
+
format_calls(Format, Arg, Calls) :-
|
|
1128
|
+
format_calls(Format, [Arg], Calls).
|
|
1129
|
+
|
|
1130
|
+
format_callables([], [], []).
|
|
1131
|
+
format_callables([callable|TT], [G|TA], [G|TG]) :-
|
|
1132
|
+
!,
|
|
1133
|
+
format_callables(TT, TA, TG).
|
|
1134
|
+
format_callables([_|TT], [_|TA], TG) :-
|
|
1135
|
+
!,
|
|
1136
|
+
format_callables(TT, TA, TG).
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
/*******************************
|
|
1140
|
+
* SAFE COMPILATION HOOKS *
|
|
1141
|
+
*******************************/
|
|
1142
|
+
|
|
1143
|
+
:- multifile
|
|
1144
|
+
prolog:sandbox_allowed_directive/1,
|
|
1145
|
+
prolog:sandbox_allowed_goal/1,
|
|
1146
|
+
prolog:sandbox_allowed_expansion/1.
|
|
1147
|
+
|
|
1148
|
+
%! prolog:sandbox_allowed_directive(:G) is det.
|
|
1149
|
+
%
|
|
1150
|
+
% Throws an exception if G is not considered a safe directive.
|
|
1151
|
+
|
|
1152
|
+
prolog:sandbox_allowed_directive(Directive) :-
|
|
1153
|
+
debug(sandbox(directive), 'Directive: ~p', [Directive]),
|
|
1154
|
+
fail.
|
|
1155
|
+
prolog:sandbox_allowed_directive(Directive) :-
|
|
1156
|
+
safe_directive(Directive),
|
|
1157
|
+
!.
|
|
1158
|
+
prolog:sandbox_allowed_directive(M:PredAttr) :-
|
|
1159
|
+
\+ prolog_load_context(module, M),
|
|
1160
|
+
!,
|
|
1161
|
+
debug(sandbox(directive), 'Cross-module directive', []),
|
|
1162
|
+
permission_error(execute, sandboxed_directive, (:- M:PredAttr)).
|
|
1163
|
+
prolog:sandbox_allowed_directive(M:PredAttr) :-
|
|
1164
|
+
safe_pattr(PredAttr),
|
|
1165
|
+
!,
|
|
1166
|
+
PredAttr =.. [Attr, Preds],
|
|
1167
|
+
( safe_pattr(Preds, Attr)
|
|
1168
|
+
-> true
|
|
1169
|
+
; permission_error(execute, sandboxed_directive, (:- M:PredAttr))
|
|
1170
|
+
).
|
|
1171
|
+
prolog:sandbox_allowed_directive(_:Directive) :-
|
|
1172
|
+
safe_source_directive(Directive),
|
|
1173
|
+
!.
|
|
1174
|
+
prolog:sandbox_allowed_directive(_:Directive) :-
|
|
1175
|
+
directive_loads_file(Directive, File),
|
|
1176
|
+
!,
|
|
1177
|
+
safe_path(File).
|
|
1178
|
+
prolog:sandbox_allowed_directive(G) :-
|
|
1179
|
+
safe_goal(G).
|
|
1180
|
+
|
|
1181
|
+
%! safe_directive(:Directive) is semidet.
|
|
1182
|
+
%
|
|
1183
|
+
% Hook to declare additional directives as safe. The argument is a
|
|
1184
|
+
% term `Module:Directive` (without =|:-|= wrapper). In almost all
|
|
1185
|
+
% cases, the implementation must verify that the `Module` is the
|
|
1186
|
+
% current load context as illustrated below. This check is not
|
|
1187
|
+
% performed by the system to allow for cases where particular
|
|
1188
|
+
% cross-module directives are allowed.
|
|
1189
|
+
%
|
|
1190
|
+
% ==
|
|
1191
|
+
% sandbox:safe_directive(M:Directive) :-
|
|
1192
|
+
% prolog_load_context(module, M),
|
|
1193
|
+
% ...
|
|
1194
|
+
% ==
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
safe_pattr(dynamic(_)).
|
|
1198
|
+
safe_pattr(thread_local(_)).
|
|
1199
|
+
safe_pattr(volatile(_)).
|
|
1200
|
+
safe_pattr(discontiguous(_)).
|
|
1201
|
+
safe_pattr(multifile(_)).
|
|
1202
|
+
safe_pattr(public(_)).
|
|
1203
|
+
safe_pattr(meta_predicate(_)).
|
|
1204
|
+
safe_pattr(table(_)).
|
|
1205
|
+
safe_pattr(non_terminal(_)).
|
|
1206
|
+
|
|
1207
|
+
safe_pattr(Var, _) :-
|
|
1208
|
+
var(Var),
|
|
1209
|
+
!,
|
|
1210
|
+
instantiation_error(Var).
|
|
1211
|
+
safe_pattr((A,B), Attr) :-
|
|
1212
|
+
!,
|
|
1213
|
+
safe_pattr(A, Attr),
|
|
1214
|
+
safe_pattr(B, Attr).
|
|
1215
|
+
safe_pattr(M:G, Attr) :-
|
|
1216
|
+
!,
|
|
1217
|
+
( atom(M),
|
|
1218
|
+
prolog_load_context(module, M)
|
|
1219
|
+
-> true
|
|
1220
|
+
; Goal =.. [Attr,M:G],
|
|
1221
|
+
permission_error(directive, sandboxed, (:- Goal))
|
|
1222
|
+
).
|
|
1223
|
+
safe_pattr(_, _).
|
|
1224
|
+
|
|
1225
|
+
safe_source_directive(op(_,_,Name)) :-
|
|
1226
|
+
!,
|
|
1227
|
+
( atom(Name)
|
|
1228
|
+
-> true
|
|
1229
|
+
; is_list(Name),
|
|
1230
|
+
maplist(atom, Name)
|
|
1231
|
+
).
|
|
1232
|
+
safe_source_directive(set_prolog_flag(Flag, Value)) :-
|
|
1233
|
+
!,
|
|
1234
|
+
atom(Flag), ground(Value),
|
|
1235
|
+
safe_prolog_flag(Flag, Value).
|
|
1236
|
+
safe_source_directive(style_check(_)).
|
|
1237
|
+
safe_source_directive(initialization(_)). % Checked at runtime
|
|
1238
|
+
safe_source_directive(initialization(_,_)). % Checked at runtime
|
|
1239
|
+
|
|
1240
|
+
directive_loads_file(use_module(library(X)), X).
|
|
1241
|
+
directive_loads_file(use_module(library(X), _Imports), X).
|
|
1242
|
+
directive_loads_file(load_files(library(X), _Options), X).
|
|
1243
|
+
directive_loads_file(ensure_loaded(library(X)), X).
|
|
1244
|
+
directive_loads_file(include(X), X).
|
|
1245
|
+
|
|
1246
|
+
safe_path(X) :-
|
|
1247
|
+
var(X),
|
|
1248
|
+
!,
|
|
1249
|
+
instantiation_error(X).
|
|
1250
|
+
safe_path(X) :-
|
|
1251
|
+
( atom(X)
|
|
1252
|
+
; string(X)
|
|
1253
|
+
),
|
|
1254
|
+
!,
|
|
1255
|
+
\+ sub_atom(X, 0, _, 0, '..'),
|
|
1256
|
+
\+ sub_atom(X, 0, _, _, '/'),
|
|
1257
|
+
\+ sub_atom(X, 0, _, _, '../'),
|
|
1258
|
+
\+ sub_atom(X, _, _, 0, '/..'),
|
|
1259
|
+
\+ sub_atom(X, _, _, _, '/../').
|
|
1260
|
+
safe_path(A/B) :-
|
|
1261
|
+
!,
|
|
1262
|
+
safe_path(A),
|
|
1263
|
+
safe_path(B).
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
%! safe_prolog_flag(+Flag, +Value) is det.
|
|
1267
|
+
%
|
|
1268
|
+
% True if it is safe to set the flag Flag to Value.
|
|
1269
|
+
%
|
|
1270
|
+
% @tbd If we can avoid that files are loaded after changing
|
|
1271
|
+
% this flag, we can allow for more flags. The syntax
|
|
1272
|
+
% flags are safe because they are registered with the
|
|
1273
|
+
% module.
|
|
1274
|
+
|
|
1275
|
+
% misc
|
|
1276
|
+
safe_prolog_flag(generate_debug_info, _).
|
|
1277
|
+
safe_prolog_flag(optimise, _).
|
|
1278
|
+
safe_prolog_flag(occurs_check, _).
|
|
1279
|
+
safe_prolog_flag(write_attributes, _).
|
|
1280
|
+
% syntax
|
|
1281
|
+
safe_prolog_flag(var_prefix, _).
|
|
1282
|
+
safe_prolog_flag(double_quotes, _).
|
|
1283
|
+
safe_prolog_flag(back_quotes, _).
|
|
1284
|
+
safe_prolog_flag(rational_syntax, _).
|
|
1285
|
+
% arithmetic
|
|
1286
|
+
safe_prolog_flag(prefer_rationals, _).
|
|
1287
|
+
safe_prolog_flag(float_overflow, _).
|
|
1288
|
+
safe_prolog_flag(float_zero_div, _).
|
|
1289
|
+
safe_prolog_flag(float_undefined, _).
|
|
1290
|
+
safe_prolog_flag(float_underflow, _).
|
|
1291
|
+
safe_prolog_flag(float_rounding, _).
|
|
1292
|
+
safe_prolog_flag(float_rounding, _).
|
|
1293
|
+
safe_prolog_flag(max_rational_size, _).
|
|
1294
|
+
safe_prolog_flag(max_rational_size_action, _).
|
|
1295
|
+
% tabling
|
|
1296
|
+
safe_prolog_flag(max_answers_for_subgoal,_).
|
|
1297
|
+
safe_prolog_flag(max_answers_for_subgoal_action,_).
|
|
1298
|
+
safe_prolog_flag(max_table_answer_size,_).
|
|
1299
|
+
safe_prolog_flag(max_table_answer_size_action,_).
|
|
1300
|
+
safe_prolog_flag(max_table_subgoal_size,_).
|
|
1301
|
+
safe_prolog_flag(max_table_subgoal_size_action,_).
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
%! prolog:sandbox_allowed_expansion(:G) is det.
|
|
1305
|
+
%
|
|
1306
|
+
% Throws an exception if G is not considered a safe expansion
|
|
1307
|
+
% goal. This deals with call-backs from the compiler for
|
|
1308
|
+
%
|
|
1309
|
+
% - goal_expansion/2
|
|
1310
|
+
% - term_expansion/2
|
|
1311
|
+
% - Quasi quotations.
|
|
1312
|
+
%
|
|
1313
|
+
% Our assumption is that external expansion rules are coded safely
|
|
1314
|
+
% and we only need to be careful if the sandboxed code defines
|
|
1315
|
+
% expansion rules.
|
|
1316
|
+
|
|
1317
|
+
prolog:sandbox_allowed_expansion(M:G) :-
|
|
1318
|
+
prolog_load_context(module, M),
|
|
1319
|
+
!,
|
|
1320
|
+
debug(sandbox(expansion), 'Expand in ~p: ~p', [M, G]),
|
|
1321
|
+
safe_goal(M:G).
|
|
1322
|
+
prolog:sandbox_allowed_expansion(_,_).
|
|
1323
|
+
|
|
1324
|
+
%! prolog:sandbox_allowed_goal(:G) is det.
|
|
1325
|
+
%
|
|
1326
|
+
% Throw an exception if it is not safe to call G
|
|
1327
|
+
|
|
1328
|
+
prolog:sandbox_allowed_goal(G) :-
|
|
1329
|
+
safe_goal(G).
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
/*******************************
|
|
1333
|
+
* MESSAGES *
|
|
1334
|
+
*******************************/
|
|
1335
|
+
|
|
1336
|
+
:- multifile
|
|
1337
|
+
prolog:message//1,
|
|
1338
|
+
prolog:message_context//1,
|
|
1339
|
+
prolog:error_message//1.
|
|
1340
|
+
|
|
1341
|
+
prolog:message(error(instantiation_error, Context)) -->
|
|
1342
|
+
{ nonvar(Context),
|
|
1343
|
+
Context = sandbox(_Goal,Parents),
|
|
1344
|
+
numbervars(Context, 1, _)
|
|
1345
|
+
},
|
|
1346
|
+
[ 'Sandbox restriction!'-[], nl,
|
|
1347
|
+
'Could not derive which predicate may be called from'-[]
|
|
1348
|
+
],
|
|
1349
|
+
( { Parents == [] }
|
|
1350
|
+
-> [ 'Search space too large'-[] ]
|
|
1351
|
+
; callers(Parents, 10)
|
|
1352
|
+
).
|
|
1353
|
+
|
|
1354
|
+
prolog:message_context(sandbox(_G, [])) --> !.
|
|
1355
|
+
prolog:message_context(sandbox(_G, Parents)) -->
|
|
1356
|
+
[ nl, 'Reachable from:'-[] ],
|
|
1357
|
+
callers(Parents, 10).
|
|
1358
|
+
|
|
1359
|
+
callers([], _) --> !.
|
|
1360
|
+
callers(_, 0) --> !.
|
|
1361
|
+
callers([G|Parents], Level) -->
|
|
1362
|
+
{ NextLevel is Level-1
|
|
1363
|
+
},
|
|
1364
|
+
[ nl, '\t ~p'-[G] ],
|
|
1365
|
+
callers(Parents, NextLevel).
|
|
1366
|
+
|
|
1367
|
+
prolog:message(bad_safe_declaration(Goal, File, Line)) -->
|
|
1368
|
+
[ '~w:~d: Invalid safe_primitive/1 declaration: ~p'-
|
|
1369
|
+
[File, Line, Goal] ].
|
|
1370
|
+
|
|
1371
|
+
prolog:error_message(format_error(Format, Types, Args)) -->
|
|
1372
|
+
format_error(Format, Types, Args).
|
|
1373
|
+
|
|
1374
|
+
format_error(Format, Types, Args) -->
|
|
1375
|
+
{ length(Types, TypeLen),
|
|
1376
|
+
length(Args, ArgsLen),
|
|
1377
|
+
( TypeLen > ArgsLen
|
|
1378
|
+
-> Problem = 'not enough'
|
|
1379
|
+
; Problem = 'too many'
|
|
1380
|
+
)
|
|
1381
|
+
},
|
|
1382
|
+
[ 'format(~q): ~w arguments (found ~w, need ~w)'-
|
|
1383
|
+
[Format, Problem, ArgsLen, TypeLen]
|
|
1384
|
+
].
|