xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/ext/Opcode/Opcode.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage Opcode;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse 5.006_001;
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateuse strict;
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gateour($VERSION, $XS_VERSION, @ISA, @EXPORT_OK);
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate$VERSION = "1.05";
10*0Sstevel@tonic-gate$XS_VERSION = "1.03";
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gateuse Carp;
13*0Sstevel@tonic-gateuse Exporter ();
14*0Sstevel@tonic-gateuse XSLoader ();
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gateBEGIN {
17*0Sstevel@tonic-gate    @ISA = qw(Exporter);
18*0Sstevel@tonic-gate    @EXPORT_OK = qw(
19*0Sstevel@tonic-gate	opset ops_to_opset
20*0Sstevel@tonic-gate	opset_to_ops opset_to_hex invert_opset
21*0Sstevel@tonic-gate	empty_opset full_opset
22*0Sstevel@tonic-gate	opdesc opcodes opmask define_optag
23*0Sstevel@tonic-gate	opmask_add verify_opset opdump
24*0Sstevel@tonic-gate    );
25*0Sstevel@tonic-gate}
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gatesub opset (;@);
28*0Sstevel@tonic-gatesub opset_to_hex ($);
29*0Sstevel@tonic-gatesub opdump (;$);
30*0Sstevel@tonic-gateuse subs @EXPORT_OK;
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateXSLoader::load 'Opcode', $XS_VERSION;
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate_init_optags();
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gatesub ops_to_opset { opset @_ }	# alias for old name
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gatesub opset_to_hex ($) {
39*0Sstevel@tonic-gate    return "(invalid opset)" unless verify_opset($_[0]);
40*0Sstevel@tonic-gate    unpack("h*",$_[0]);
41*0Sstevel@tonic-gate}
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gatesub opdump (;$) {
44*0Sstevel@tonic-gate	my $pat = shift;
45*0Sstevel@tonic-gate    # handy utility: perl -MOpcode=opdump -e 'opdump File'
46*0Sstevel@tonic-gate    foreach(opset_to_ops(full_opset)) {
47*0Sstevel@tonic-gate        my $op = sprintf "  %12s  %s\n", $_, opdesc($_);
48*0Sstevel@tonic-gate		next if defined $pat and $op !~ m/$pat/i;
49*0Sstevel@tonic-gate		print $op;
50*0Sstevel@tonic-gate    }
51*0Sstevel@tonic-gate}
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gatesub _init_optags {
56*0Sstevel@tonic-gate    my(%all, %seen);
57*0Sstevel@tonic-gate    @all{opset_to_ops(full_opset)} = (); # keys only
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate    local($_);
60*0Sstevel@tonic-gate    local($/) = "\n=cut"; # skip to optags definition section
61*0Sstevel@tonic-gate    <DATA>;
62*0Sstevel@tonic-gate    $/ = "\n=";		# now read in 'pod section' chunks
63*0Sstevel@tonic-gate    while(<DATA>) {
64*0Sstevel@tonic-gate	next unless m/^item\s+(:\w+)/;
65*0Sstevel@tonic-gate	my $tag = $1;
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate	# Split into lines, keep only indented lines
68*0Sstevel@tonic-gate	my @lines = grep { m/^\s/    } split(/\n/);
69*0Sstevel@tonic-gate	foreach (@lines) { s/--.*//  } # delete comments
70*0Sstevel@tonic-gate	my @ops   = map  { split ' ' } @lines; # get op words
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate	foreach(@ops) {
73*0Sstevel@tonic-gate	    warn "$tag - $_ already tagged in $seen{$_}\n" if $seen{$_};
74*0Sstevel@tonic-gate	    $seen{$_} = $tag;
75*0Sstevel@tonic-gate	    delete $all{$_};
76*0Sstevel@tonic-gate	}
77*0Sstevel@tonic-gate	# opset will croak on invalid names
78*0Sstevel@tonic-gate	define_optag($tag, opset(@ops));
79*0Sstevel@tonic-gate    }
80*0Sstevel@tonic-gate    close(DATA);
81*0Sstevel@tonic-gate    warn "Untagged opnames: ".join(' ',keys %all)."\n" if %all;
82*0Sstevel@tonic-gate}
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate1;
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate__DATA__
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate=head1 NAME
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gateOpcode - Disable named opcodes when compiling perl code
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate=head1 SYNOPSIS
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate  use Opcode;
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate=head1 DESCRIPTION
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gatePerl code is always compiled into an internal format before execution.
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gateEvaluating perl code (e.g. via "eval" or "do 'file'") causes
103*0Sstevel@tonic-gatethe code to be compiled into an internal format and then,
104*0Sstevel@tonic-gateprovided there was no error in the compilation, executed.
105*0Sstevel@tonic-gateThe internal format is based on many distinct I<opcodes>.
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gateBy default no opmask is in effect and any code can be compiled.
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gateThe Opcode module allow you to define an I<operator mask> to be in
110*0Sstevel@tonic-gateeffect when perl I<next> compiles any code.  Attempting to compile code
111*0Sstevel@tonic-gatewhich contains a masked opcode will cause the compilation to fail
112*0Sstevel@tonic-gatewith an error. The code will not be executed.
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate=head1 NOTE
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gateThe Opcode module is not usually used directly. See the ops pragma and
117*0Sstevel@tonic-gateSafe modules for more typical uses.
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate=head1 WARNING
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gateThe authors make B<no warranty>, implied or otherwise, about the
122*0Sstevel@tonic-gatesuitability of this software for safety or security purposes.
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gateThe authors shall not in any case be liable for special, incidental,
125*0Sstevel@tonic-gateconsequential, indirect or other similar damages arising from the use
126*0Sstevel@tonic-gateof this software.
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gateYour mileage will vary. If in any doubt B<do not use it>.
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate=head1 Operator Names and Operator Lists
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gateThe canonical list of operator names is the contents of the array
134*0Sstevel@tonic-gatePL_op_name defined and initialised in file F<opcode.h> of the Perl
135*0Sstevel@tonic-gatesource distribution (and installed into the perl library).
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gateEach operator has both a terse name (its opname) and a more verbose or
138*0Sstevel@tonic-gaterecognisable descriptive name. The opdesc function can be used to
139*0Sstevel@tonic-gatereturn a list of descriptions for a list of operators.
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gateMany of the functions and methods listed below take a list of
142*0Sstevel@tonic-gateoperators as parameters. Most operator lists can be made up of several
143*0Sstevel@tonic-gatetypes of element. Each element can be one of
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate=over 8
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate=item an operator name (opname)
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gateOperator names are typically small lowercase words like enterloop,
150*0Sstevel@tonic-gateleaveloop, last, next, redo etc. Sometimes they are rather cryptic
151*0Sstevel@tonic-gatelike gv2cv, i_ncmp and ftsvtx.
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate=item an operator tag name (optag)
154*0Sstevel@tonic-gate
155*0Sstevel@tonic-gateOperator tags can be used to refer to groups (or sets) of operators.
156*0Sstevel@tonic-gateTag names always begin with a colon. The Opcode module defines several
157*0Sstevel@tonic-gateoptags and the user can define others using the define_optag function.
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate=item a negated opname or optag
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gateAn opname or optag can be prefixed with an exclamation mark, e.g., !mkdir.
162*0Sstevel@tonic-gateNegating an opname or optag means remove the corresponding ops from the
163*0Sstevel@tonic-gateaccumulated set of ops at that point.
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate=item an operator set (opset)
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gateAn I<opset> as a binary string of approximately 44 bytes which holds a
168*0Sstevel@tonic-gateset or zero or more operators.
169*0Sstevel@tonic-gate
170*0Sstevel@tonic-gateThe opset and opset_to_ops functions can be used to convert from
171*0Sstevel@tonic-gatea list of operators to an opset and I<vice versa>.
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gateWherever a list of operators can be given you can use one or more opsets.
174*0Sstevel@tonic-gateSee also Manipulating Opsets below.
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate=back
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate=head1 Opcode Functions
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gateThe Opcode package contains functions for manipulating operator names
182*0Sstevel@tonic-gatetags and sets. All are available for export by the package.
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate=over 8
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate=item opcodes
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gateIn a scalar context opcodes returns the number of opcodes in this
189*0Sstevel@tonic-gateversion of perl (around 350 for perl-5.7.0).
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gateIn a list context it returns a list of all the operator names.
192*0Sstevel@tonic-gate(Not yet implemented, use @names = opset_to_ops(full_opset).)
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate=item opset (OP, ...)
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gateReturns an opset containing the listed operators.
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate=item opset_to_ops (OPSET)
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gateReturns a list of operator names corresponding to those operators in
201*0Sstevel@tonic-gatethe set.
202*0Sstevel@tonic-gate
203*0Sstevel@tonic-gate=item opset_to_hex (OPSET)
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gateReturns a string representation of an opset. Can be handy for debugging.
206*0Sstevel@tonic-gate
207*0Sstevel@tonic-gate=item full_opset
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gateReturns an opset which includes all operators.
210*0Sstevel@tonic-gate
211*0Sstevel@tonic-gate=item empty_opset
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gateReturns an opset which contains no operators.
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate=item invert_opset (OPSET)
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gateReturns an opset which is the inverse set of the one supplied.
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate=item verify_opset (OPSET, ...)
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gateReturns true if the supplied opset looks like a valid opset (is the
222*0Sstevel@tonic-gateright length etc) otherwise it returns false. If an optional second
223*0Sstevel@tonic-gateparameter is true then verify_opset will croak on an invalid opset
224*0Sstevel@tonic-gateinstead of returning false.
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gateMost of the other Opcode functions call verify_opset automatically
227*0Sstevel@tonic-gateand will croak if given an invalid opset.
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate=item define_optag (OPTAG, OPSET)
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gateDefine OPTAG as a symbolic name for OPSET. Optag names always start
232*0Sstevel@tonic-gatewith a colon C<:>.
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gateThe optag name used must not be defined already (define_optag will
235*0Sstevel@tonic-gatecroak if it is already defined). Optag names are global to the perl
236*0Sstevel@tonic-gateprocess and optag definitions cannot be altered or deleted once
237*0Sstevel@tonic-gatedefined.
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gateIt is strongly recommended that applications using Opcode should use a
240*0Sstevel@tonic-gateleading capital letter on their tag names since lowercase names are
241*0Sstevel@tonic-gatereserved for use by the Opcode module. If using Opcode within a module
242*0Sstevel@tonic-gateyou should prefix your tags names with the name of your module to
243*0Sstevel@tonic-gateensure uniqueness and thus avoid clashes with other modules.
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate=item opmask_add (OPSET)
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gateAdds the supplied opset to the current opmask. Note that there is
248*0Sstevel@tonic-gatecurrently I<no> mechanism for unmasking ops once they have been masked.
249*0Sstevel@tonic-gateThis is intentional.
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate=item opmask
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gateReturns an opset corresponding to the current opmask.
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate=item opdesc (OP, ...)
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gateThis takes a list of operator names and returns the corresponding list
258*0Sstevel@tonic-gateof operator descriptions.
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate=item opdump (PAT)
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gateDumps to STDOUT a two column list of op names and op descriptions.
263*0Sstevel@tonic-gateIf an optional pattern is given then only lines which match the
264*0Sstevel@tonic-gate(case insensitive) pattern will be output.
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gateIt's designed to be used as a handy command line utility:
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gate	perl -MOpcode=opdump -e opdump
269*0Sstevel@tonic-gate	perl -MOpcode=opdump -e 'opdump Eval'
270*0Sstevel@tonic-gate
271*0Sstevel@tonic-gate=back
272*0Sstevel@tonic-gate
273*0Sstevel@tonic-gate=head1 Manipulating Opsets
274*0Sstevel@tonic-gate
275*0Sstevel@tonic-gateOpsets may be manipulated using the perl bit vector operators & (and), | (or),
276*0Sstevel@tonic-gate^ (xor) and ~ (negate/invert).
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gateHowever you should never rely on the numerical position of any opcode
279*0Sstevel@tonic-gatewithin the opset. In other words both sides of a bit vector operator
280*0Sstevel@tonic-gateshould be opsets returned from Opcode functions.
281*0Sstevel@tonic-gate
282*0Sstevel@tonic-gateAlso, since the number of opcodes in your current version of perl might
283*0Sstevel@tonic-gatenot be an exact multiple of eight, there may be unused bits in the last
284*0Sstevel@tonic-gatebyte of an upset. This should not cause any problems (Opcode functions
285*0Sstevel@tonic-gateignore those extra bits) but it does mean that using the ~ operator
286*0Sstevel@tonic-gatewill typically not produce the same 'physical' opset 'string' as the
287*0Sstevel@tonic-gateinvert_opset function.
288*0Sstevel@tonic-gate
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate=head1 TO DO (maybe)
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate    $bool = opset_eq($opset1, $opset2)	true if opsets are logically eqiv
293*0Sstevel@tonic-gate
294*0Sstevel@tonic-gate    $yes = opset_can($opset, @ops)	true if $opset has all @ops set
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate    @diff = opset_diff($opset1, $opset2) => ('foo', '!bar', ...)
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate=cut
299*0Sstevel@tonic-gate
300*0Sstevel@tonic-gate# the =cut above is used by _init_optags() to get here quickly
301*0Sstevel@tonic-gate
302*0Sstevel@tonic-gate=head1 Predefined Opcode Tags
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gate=over 5
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate=item :base_core
307*0Sstevel@tonic-gate
308*0Sstevel@tonic-gate    null stub scalar pushmark wantarray const defined undef
309*0Sstevel@tonic-gate
310*0Sstevel@tonic-gate    rv2sv sassign
311*0Sstevel@tonic-gate
312*0Sstevel@tonic-gate    rv2av aassign aelem aelemfast aslice av2arylen
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate    rv2hv helem hslice each values keys exists delete
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gate    preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec
317*0Sstevel@tonic-gate    int hex oct abs pow multiply i_multiply divide i_divide
318*0Sstevel@tonic-gate    modulo i_modulo add i_add subtract i_subtract
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate    left_shift right_shift bit_and bit_xor bit_or negate i_negate
321*0Sstevel@tonic-gate    not complement
322*0Sstevel@tonic-gate
323*0Sstevel@tonic-gate    lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp
324*0Sstevel@tonic-gate    slt sgt sle sge seq sne scmp
325*0Sstevel@tonic-gate
326*0Sstevel@tonic-gate    substr vec stringify study pos length index rindex ord chr
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate    ucfirst lcfirst uc lc quotemeta trans chop schop chomp schomp
329*0Sstevel@tonic-gate
330*0Sstevel@tonic-gate    match split qr
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate    list lslice splice push pop shift unshift reverse
333*0Sstevel@tonic-gate
334*0Sstevel@tonic-gate    cond_expr flip flop andassign orassign and or xor
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate    warn die lineseq nextstate scope enter leave setstate
337*0Sstevel@tonic-gate
338*0Sstevel@tonic-gate    rv2cv anoncode prototype
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate    entersub leavesub leavesublv return method method_named -- XXX loops via recursion?
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate    leaveeval -- needed for Safe to operate, is safe without entereval
343*0Sstevel@tonic-gate
344*0Sstevel@tonic-gate=item :base_mem
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gateThese memory related ops are not included in :base_core because they
347*0Sstevel@tonic-gatecan easily be used to implement a resource attack (e.g., consume all
348*0Sstevel@tonic-gateavailable memory).
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate    concat repeat join range
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gate    anonlist anonhash
353*0Sstevel@tonic-gate
354*0Sstevel@tonic-gateNote that despite the existance of this optag a memory resource attack
355*0Sstevel@tonic-gatemay still be possible using only :base_core ops.
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gateDisabling these ops is a I<very> heavy handed way to attempt to prevent
358*0Sstevel@tonic-gatea memory resource attack. It's probable that a specific memory limit
359*0Sstevel@tonic-gatemechanism will be added to perl in the near future.
360*0Sstevel@tonic-gate
361*0Sstevel@tonic-gate=item :base_loop
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gateThese loop ops are not included in :base_core because they can easily be
364*0Sstevel@tonic-gateused to implement a resource attack (e.g., consume all available CPU time).
365*0Sstevel@tonic-gate
366*0Sstevel@tonic-gate    grepstart grepwhile
367*0Sstevel@tonic-gate    mapstart mapwhile
368*0Sstevel@tonic-gate    enteriter iter
369*0Sstevel@tonic-gate    enterloop leaveloop unstack
370*0Sstevel@tonic-gate    last next redo
371*0Sstevel@tonic-gate    goto
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate=item :base_io
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gateThese ops enable I<filehandle> (rather than filename) based input and
376*0Sstevel@tonic-gateoutput. These are safe on the assumption that only pre-existing
377*0Sstevel@tonic-gatefilehandles are available for use.  To create new filehandles other ops
378*0Sstevel@tonic-gatesuch as open would need to be enabled.
379*0Sstevel@tonic-gate
380*0Sstevel@tonic-gate    readline rcatline getc read
381*0Sstevel@tonic-gate
382*0Sstevel@tonic-gate    formline enterwrite leavewrite
383*0Sstevel@tonic-gate
384*0Sstevel@tonic-gate    print sysread syswrite send recv
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gate    eof tell seek sysseek
387*0Sstevel@tonic-gate
388*0Sstevel@tonic-gate    readdir telldir seekdir rewinddir
389*0Sstevel@tonic-gate
390*0Sstevel@tonic-gate=item :base_orig
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gateThese are a hotchpotch of opcodes still waiting to be considered
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate    gvsv gv gelem
395*0Sstevel@tonic-gate
396*0Sstevel@tonic-gate    padsv padav padhv padany
397*0Sstevel@tonic-gate
398*0Sstevel@tonic-gate    rv2gv refgen srefgen ref
399*0Sstevel@tonic-gate
400*0Sstevel@tonic-gate    bless -- could be used to change ownership of objects (reblessing)
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate    pushre regcmaybe regcreset regcomp subst substcont
403*0Sstevel@tonic-gate
404*0Sstevel@tonic-gate    sprintf prtf -- can core dump
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate    crypt
407*0Sstevel@tonic-gate
408*0Sstevel@tonic-gate    tie untie
409*0Sstevel@tonic-gate
410*0Sstevel@tonic-gate    dbmopen dbmclose
411*0Sstevel@tonic-gate    sselect select
412*0Sstevel@tonic-gate    pipe_op sockpair
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate    getppid getpgrp setpgrp getpriority setpriority localtime gmtime
415*0Sstevel@tonic-gate
416*0Sstevel@tonic-gate    entertry leavetry -- can be used to 'hide' fatal errors
417*0Sstevel@tonic-gate
418*0Sstevel@tonic-gate    custom -- where should this go
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gate=item :base_math
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gateThese ops are not included in :base_core because of the risk of them being
423*0Sstevel@tonic-gateused to generate floating point exceptions (which would have to be caught
424*0Sstevel@tonic-gateusing a $SIG{FPE} handler).
425*0Sstevel@tonic-gate
426*0Sstevel@tonic-gate    atan2 sin cos exp log sqrt
427*0Sstevel@tonic-gate
428*0Sstevel@tonic-gateThese ops are not included in :base_core because they have an effect
429*0Sstevel@tonic-gatebeyond the scope of the compartment.
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gate    rand srand
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gate=item :base_thread
434*0Sstevel@tonic-gate
435*0Sstevel@tonic-gateThese ops are related to multi-threading.
436*0Sstevel@tonic-gate
437*0Sstevel@tonic-gate    lock threadsv
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gate=item :default
440*0Sstevel@tonic-gate
441*0Sstevel@tonic-gateA handy tag name for a I<reasonable> default set of ops.  (The current ops
442*0Sstevel@tonic-gateallowed are unstable while development continues. It will change.)
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate    :base_core :base_mem :base_loop :base_io :base_orig :base_thread
445*0Sstevel@tonic-gate
446*0Sstevel@tonic-gateIf safety matters to you (and why else would you be using the Opcode module?)
447*0Sstevel@tonic-gatethen you should not rely on the definition of this, or indeed any other, optag!
448*0Sstevel@tonic-gate
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gate=item :filesys_read
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate    stat lstat readlink
453*0Sstevel@tonic-gate
454*0Sstevel@tonic-gate    ftatime ftblk ftchr ftctime ftdir fteexec fteowned fteread
455*0Sstevel@tonic-gate    ftewrite ftfile ftis ftlink ftmtime ftpipe ftrexec ftrowned
456*0Sstevel@tonic-gate    ftrread ftsgid ftsize ftsock ftsuid fttty ftzero ftrwrite ftsvtx
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gate    fttext ftbinary
459*0Sstevel@tonic-gate
460*0Sstevel@tonic-gate    fileno
461*0Sstevel@tonic-gate
462*0Sstevel@tonic-gate=item :sys_db
463*0Sstevel@tonic-gate
464*0Sstevel@tonic-gate    ghbyname ghbyaddr ghostent shostent ehostent      -- hosts
465*0Sstevel@tonic-gate    gnbyname gnbyaddr gnetent snetent enetent         -- networks
466*0Sstevel@tonic-gate    gpbyname gpbynumber gprotoent sprotoent eprotoent -- protocols
467*0Sstevel@tonic-gate    gsbyname gsbyport gservent sservent eservent      -- services
468*0Sstevel@tonic-gate
469*0Sstevel@tonic-gate    gpwnam gpwuid gpwent spwent epwent getlogin       -- users
470*0Sstevel@tonic-gate    ggrnam ggrgid ggrent sgrent egrent                -- groups
471*0Sstevel@tonic-gate
472*0Sstevel@tonic-gate=item :browse
473*0Sstevel@tonic-gate
474*0Sstevel@tonic-gateA handy tag name for a I<reasonable> default set of ops beyond the
475*0Sstevel@tonic-gate:default optag.  Like :default (and indeed all the other optags) its
476*0Sstevel@tonic-gatecurrent definition is unstable while development continues. It will change.
477*0Sstevel@tonic-gate
478*0Sstevel@tonic-gateThe :browse tag represents the next step beyond :default. It it a
479*0Sstevel@tonic-gatesuperset of the :default ops and adds :filesys_read the :sys_db.
480*0Sstevel@tonic-gateThe intent being that scripts can access more (possibly sensitive)
481*0Sstevel@tonic-gateinformation about your system but not be able to change it.
482*0Sstevel@tonic-gate
483*0Sstevel@tonic-gate    :default :filesys_read :sys_db
484*0Sstevel@tonic-gate
485*0Sstevel@tonic-gate=item :filesys_open
486*0Sstevel@tonic-gate
487*0Sstevel@tonic-gate    sysopen open close
488*0Sstevel@tonic-gate    umask binmode
489*0Sstevel@tonic-gate
490*0Sstevel@tonic-gate    open_dir closedir -- other dir ops are in :base_io
491*0Sstevel@tonic-gate
492*0Sstevel@tonic-gate=item :filesys_write
493*0Sstevel@tonic-gate
494*0Sstevel@tonic-gate    link unlink rename symlink truncate
495*0Sstevel@tonic-gate
496*0Sstevel@tonic-gate    mkdir rmdir
497*0Sstevel@tonic-gate
498*0Sstevel@tonic-gate    utime chmod chown
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gate    fcntl -- not strictly filesys related, but possibly as dangerous?
501*0Sstevel@tonic-gate
502*0Sstevel@tonic-gate=item :subprocess
503*0Sstevel@tonic-gate
504*0Sstevel@tonic-gate    backtick system
505*0Sstevel@tonic-gate
506*0Sstevel@tonic-gate    fork
507*0Sstevel@tonic-gate
508*0Sstevel@tonic-gate    wait waitpid
509*0Sstevel@tonic-gate
510*0Sstevel@tonic-gate    glob -- access to Cshell via <`rm *`>
511*0Sstevel@tonic-gate
512*0Sstevel@tonic-gate=item :ownprocess
513*0Sstevel@tonic-gate
514*0Sstevel@tonic-gate    exec exit kill
515*0Sstevel@tonic-gate
516*0Sstevel@tonic-gate    time tms -- could be used for timing attacks (paranoid?)
517*0Sstevel@tonic-gate
518*0Sstevel@tonic-gate=item :others
519*0Sstevel@tonic-gate
520*0Sstevel@tonic-gateThis tag holds groups of assorted specialist opcodes that don't warrant
521*0Sstevel@tonic-gatehaving optags defined for them.
522*0Sstevel@tonic-gate
523*0Sstevel@tonic-gateSystemV Interprocess Communications:
524*0Sstevel@tonic-gate
525*0Sstevel@tonic-gate    msgctl msgget msgrcv msgsnd
526*0Sstevel@tonic-gate
527*0Sstevel@tonic-gate    semctl semget semop
528*0Sstevel@tonic-gate
529*0Sstevel@tonic-gate    shmctl shmget shmread shmwrite
530*0Sstevel@tonic-gate
531*0Sstevel@tonic-gate=item :still_to_be_decided
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gate    chdir
534*0Sstevel@tonic-gate    flock ioctl
535*0Sstevel@tonic-gate
536*0Sstevel@tonic-gate    socket getpeername ssockopt
537*0Sstevel@tonic-gate    bind connect listen accept shutdown gsockopt getsockname
538*0Sstevel@tonic-gate
539*0Sstevel@tonic-gate    sleep alarm -- changes global timer state and signal handling
540*0Sstevel@tonic-gate    sort -- assorted problems including core dumps
541*0Sstevel@tonic-gate    tied -- can be used to access object implementing a tie
542*0Sstevel@tonic-gate    pack unpack -- can be used to create/use memory pointers
543*0Sstevel@tonic-gate
544*0Sstevel@tonic-gate    entereval -- can be used to hide code from initial compile
545*0Sstevel@tonic-gate    require dofile
546*0Sstevel@tonic-gate
547*0Sstevel@tonic-gate    caller -- get info about calling environment and args
548*0Sstevel@tonic-gate
549*0Sstevel@tonic-gate    reset
550*0Sstevel@tonic-gate
551*0Sstevel@tonic-gate    dbstate -- perl -d version of nextstate(ment) opcode
552*0Sstevel@tonic-gate
553*0Sstevel@tonic-gate=item :dangerous
554*0Sstevel@tonic-gate
555*0Sstevel@tonic-gateThis tag is simply a bucket for opcodes that are unlikely to be used via
556*0Sstevel@tonic-gatea tag name but need to be tagged for completness and documentation.
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gate    syscall dump chroot
559*0Sstevel@tonic-gate
560*0Sstevel@tonic-gate
561*0Sstevel@tonic-gate=back
562*0Sstevel@tonic-gate
563*0Sstevel@tonic-gate=head1 SEE ALSO
564*0Sstevel@tonic-gate
565*0Sstevel@tonic-gateops(3) -- perl pragma interface to Opcode module.
566*0Sstevel@tonic-gate
567*0Sstevel@tonic-gateSafe(3) -- Opcode and namespace limited execution compartments
568*0Sstevel@tonic-gate
569*0Sstevel@tonic-gate=head1 AUTHORS
570*0Sstevel@tonic-gate
571*0Sstevel@tonic-gateOriginally designed and implemented by Malcolm Beattie,
572*0Sstevel@tonic-gatembeattie@sable.ox.ac.uk as part of Safe version 1.
573*0Sstevel@tonic-gate
574*0Sstevel@tonic-gateSplit out from Safe module version 1, named opcode tags and other
575*0Sstevel@tonic-gatechanges added by Tim Bunce.
576*0Sstevel@tonic-gate
577*0Sstevel@tonic-gate=cut
578*0Sstevel@tonic-gate
579