tem_ruby 0.10.3 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.11. Procedure calls (fw 1.11) and improved TEM exception information dump.
2
+
1
3
  v0.10.3. Fixed benchmarking via the tem_bench binary.
2
4
 
3
5
  v0.10.2. More internal refactorings.
@@ -129,14 +129,20 @@ module Tem::Isa
129
129
  :reladdr => 2}
130
130
  isa.instruction 0x25, :jle, {:name => :to, :type => :tem_ushort,
131
131
  :reladdr => 2}
132
+
133
+ # 0 ST -> 1 ST; IP
134
+ isa.instruction 0x3E, :call, {:name => :proc, :type => :tem_ushort,
135
+ :reladdr => 2}
136
+ # 1 ST -> 0 ST; IP (without IM)
137
+ isa.instruction 0x3F, :ret
132
138
 
133
139
  # 1 IM_B -> 1 ST
134
140
  isa.instruction 0x30, :ldbc, {:name => :const, :type => :tem_byte}
135
141
  # 1 IM -> 1 ST
136
142
  isa.instruction 0x31, :ldwc, {:name => :const, :type => :tem_short}
137
- # 1 ST -> 1 ST
143
+ # 0 ST -> 1 ST
138
144
  isa.instruction 0x32, :ldb, {:name => :from, :type => :tem_ushort}
139
- # 1 ST -> 1 ST
145
+ # 0 ST -> 1 ST
140
146
  isa.instruction 0x33, :ldw, {:name => :from, :type => :tem_ushort}
141
147
  # 1 ST -> 1 ST
142
148
  isa.instruction 0x36, :ldbv
@@ -4,20 +4,43 @@ class Tem::SecExecError < StandardError
4
4
  attr_reader :buffer_state, :key_state
5
5
  attr_reader :trace
6
6
 
7
- def initialize(line_info, tem_trace, buffer_state, key_state)
7
+ def initialize(secpack, tem_trace, buffer_state, key_state)
8
8
  super 'SEC execution failed on the TEM'
9
- @line_info = line_info
10
- line_ip, atom, backtrace = *line_info
11
- @atom = atom
9
+
10
+ if tem_trace
11
+ if tem_trace[:ip]
12
+ @ip_line_info = secpack.line_info_for_addr tem_trace[:ip]
13
+ @ip_label_info = secpack.label_info_for_addr tem_trace[:ip]
14
+ end
15
+ if tem_trace[:sp]
16
+ @sp_line_info = secpack.line_info_for_addr tem_trace[:sp]
17
+ end
18
+ end
19
+ @ip_line_info ||= [0, :unknown, []]
20
+ @ip_label_info ||= [0, :unknown]
21
+ @sp_line_info ||= [0, :unknown, []]
22
+
23
+ line_ip, atom, backtrace = *@ip_line_info
24
+ set_backtrace backtrace
25
+ @ip_atom = atom
26
+ @ip_label = @ip_label_info[1]
12
27
  if tem_trace and tem_trace[:ip]
13
28
  @ip_delta = tem_trace[:ip] - line_ip
29
+ @ip_label_delta = tem_trace[:ip] - @ip_label_info[0]
14
30
  else
15
- @ip_delta = 0
31
+ @ip_delta = @ip_label_delta = 0
16
32
  end
33
+ line_sp, atom, backtrace = *@sp_line_info
34
+ @sp_atom = atom
35
+ if tem_trace and tem_trace[:sp]
36
+ @sp_delta = tem_trace[:sp] - line_sp
37
+ else
38
+ @sp_delta = 0
39
+ end
40
+
17
41
  @trace = tem_trace
18
42
  @buffer_state = buffer_state
19
43
  @key_state = key_state
20
- set_backtrace backtrace
21
44
  end
22
45
 
23
46
  def bstat_str
@@ -40,7 +63,10 @@ class Tem::SecExecError < StandardError
40
63
  if @trace.nil?
41
64
  "no trace available"
42
65
  else
43
- "ip=#{'%04x' % @trace[:ip]} sp=#{'%04x' % @trace[:sp]} out=#{'%04x' % @trace[:out]} pscell=#{'%04x' % @trace[:pscell]}"
66
+ "ip=#{'%04x' % @trace[:ip]} (#{@ip_atom}+0x#{'%x' % @ip_delta}) " +
67
+ "sp=#{'%04x' % @trace[:sp]} (#{@sp_atom}+0x#{'%x' % @sp_delta}) " +
68
+ "out=#{'%04x' % @trace[:out]} " +
69
+ "pscell=#{'%04x' % @trace[:pscell]}"
44
70
  end
45
71
  end
46
72
 
@@ -52,7 +78,7 @@ TEM Trace: #{trace_str}
52
78
  TEM Buffer Status:#{bstat_str}
53
79
  TEM Key Status:#{kstat_str}
54
80
 
55
- TEM execution error at #{@atom}+#{@ip_delta}
81
+ TEM execution error at #{@ip_label}+0x#{'%x' % @ip_label_delta}:
56
82
  ENDSTRING
57
83
  string.strip
58
84
  end
@@ -54,12 +54,7 @@ module Tem::SeClosures
54
54
  b_stat = stat_buffers() rescue nil
55
55
  k_stat = stat_keys() rescue nil
56
56
  trace = sec_trace()
57
- if trace and trace[:ip]
58
- line_info = secpack.line_info_for_ip(trace[:ip])
59
- else
60
- line_info = [0, :unknown, Kernel.caller]
61
- end
62
- sec_exception = Tem::SecExecError.new line_info, trace, b_stat, k_stat
57
+ sec_exception = Tem::SecExecError.new secpack, trace, b_stat, k_stat
63
58
  break
64
59
  when 4 # persistent store fault
65
60
  solve_psfault
data/lib/tem/secpack.rb CHANGED
@@ -94,14 +94,38 @@ class Tem::SecPack
94
94
  [tem_header, @body, [0] * @extra_bytes].flatten
95
95
  end
96
96
 
97
- def line_info_for_ip(ip)
97
+ def line_info_for_addr(addr)
98
98
  return nil unless @lines
99
99
 
100
100
  @lines.reverse_each do |info|
101
101
  # If something breaks, it's likely to happen after the opcode of the
102
102
  # offending instruction has been read, so assume offending_ip < ip.
103
- return info if ip >= info[0]
103
+ return info if addr >= info[0]
104
104
  end
105
105
  return info.first
106
106
  end
107
+
108
+ def label_info_for_addr(addr)
109
+ @labels.to_a.reverse_each do |info|
110
+ return info.reverse if addr >= info[1]
111
+ end
112
+ end
113
+
114
+ # Methods for interacting with the plaintext content of a SECpack.
115
+
116
+ def set_value(label, abi_type, value)
117
+ expand_extra_bytes
118
+ raise "Unknown label #{label}" unless addr = @labels[label]
119
+ bytes = Tem::Abi.send :"to_#{abi_type}", value
120
+ @body[addr, bytes.length] = bytes
121
+ #trim_extra_bytes
122
+ end
123
+
124
+ def get_value(label, abi_type)
125
+ expand_extra_bytes
126
+ raise "Unknown label #{label}" unless addr = @labels[label]
127
+ value = Tem::Abi.send :"read_#{abi_type}", @body, addr
128
+ #trim_extra_bytes
129
+ value
130
+ end
107
131
  end
data/tem_ruby.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tem_ruby}
5
- s.version = "0.10.3"
5
+ s.version = "0.11"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
@@ -18,13 +18,13 @@ module TemBoundSecpackTestCase
18
18
  # Make sure the zero_bytes optimization doesn't screw things up.
19
19
  s.zeros :tem_ubyte, 60
20
20
  s.label :plain
21
+ s.zeros :tem_ubyte, 20
21
22
  s.stack 4
22
23
  }
23
24
 
24
25
  sb = bound_sec.body
25
- secret_found = false
26
- 0.upto(sb.length - 1) { |i| if secret == sb[i, secret.length] then secret_found = true; break; end }
27
- assert secret_found, 'test_bound_secpack needs rethinking: the unbound secpack does not contain the secret'
26
+ secret_offset = (0...sb.length).find { |i| secret == sb[i, secret.length] }
27
+ assert secret_offset, 'The unbound secpack does not contain the secret.'
28
28
 
29
29
  bound_sec.bind pubk, :secret, :plain
30
30
  if yaml_roundtrip
@@ -36,11 +36,18 @@ module TemBoundSecpackTestCase
36
36
  assert_equal secret, result, 'TEM failed to decrypt secpack'
37
37
 
38
38
  sb = bound_sec.body
39
- 0.upto(sb.length - 1) { |i| assert_not_equal secret, sb[i, secret.length], 'secret found unencrypted in bound secpack' }
39
+ assert !(0...sb.length).find { |i| secret == sb[i, secret.length] },
40
+ 'Secret found unencrypted in bound secpack'
40
41
 
41
- bound_sec.body[bound_sec.label_address(:mess_place)] += 1
42
- assert_raise(RuntimeError, 'secpack validation isn\'t working') { @tem.execute bound_sec }
43
- end
42
+ assert_equal 0, bound_sec.get_value(:plain, :tem_ushort),
43
+ 'SecPack plaintext corrupted during binding'
44
+
45
+ bound_sec.set_value :mess_place, :tem_ubyte,
46
+ bound_sec.get_value(:mess_place, :tem_ubyte) + 1
47
+ assert_raise(RuntimeError, "secpack validation isn't working") do
48
+ @tem.execute bound_sec
49
+ end
50
+ end
44
51
  end
45
52
 
46
53
  class TemBoundSecpackTest < TemTestCase
@@ -53,4 +53,30 @@ class TemBranchingTest < TemTestCase
53
53
  0x10, 0x11, 0x12],
54
54
  result, 'the branching unit isn\'t working well'
55
55
  end
56
+
57
+ def test_calls
58
+ secpack = @tem.assemble { |s|
59
+ s.ldbc 4
60
+ s.outnew
61
+ s.call :proc1
62
+ s.call :proc1
63
+ s.call :proc1
64
+ s.call :proc1
65
+ s.halt
66
+
67
+ s.label :proc1
68
+ s.ldw :proc1var
69
+ s.dupn :n => 1
70
+ s.outb
71
+ s.ldbc 1
72
+ s.add
73
+ s.stw :proc1var
74
+ s.ret
75
+ s.label :proc1var
76
+ s.data :tem_short, 5
77
+ s.stack 3
78
+ }
79
+ result = @tem.execute secpack
80
+ assert_equal [5, 6, 7, 8], result, 'the branching unit isn\'t working well'
81
+ end
56
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tem_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: "0.11"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan