Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
d16685bd
Unverified
Commit
d16685bd
authored
May 04, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd: improve exit handling
parent
d2241c6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
run.go
cmd/run.go
+11
-1
main.go
main.go
+24
-3
mips.go
mipsevm/mips.go
+6
-6
No files found.
cmd/run.go
View file @
d16685bd
...
@@ -162,7 +162,13 @@ func (p *ProcessPreimageOracle) Close() error {
...
@@ -162,7 +162,13 @@ func (p *ProcessPreimageOracle) Close() error {
}
}
_
=
p
.
cmd
.
Process
.
Signal
(
os
.
Interrupt
)
_
=
p
.
cmd
.
Process
.
Signal
(
os
.
Interrupt
)
p
.
cmd
.
WaitDelay
=
time
.
Second
*
10
p
.
cmd
.
WaitDelay
=
time
.
Second
*
10
return
p
.
cmd
.
Wait
()
err
:=
p
.
cmd
.
Wait
()
if
err
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
if
err
.
Success
()
{
return
nil
}
}
return
err
}
}
type
StepFn
func
(
proof
bool
)
(
*
mipsevm
.
StepWitness
,
error
)
type
StepFn
func
(
proof
bool
)
(
*
mipsevm
.
StepWitness
,
error
)
...
@@ -248,6 +254,10 @@ func Run(ctx *cli.Context) error {
...
@@ -248,6 +254,10 @@ func Run(ctx *cli.Context) error {
startStep
:=
state
.
Step
startStep
:=
state
.
Step
for
!
state
.
Exited
{
for
!
state
.
Exited
{
if
err
:=
ctx
.
Context
.
Err
();
err
!=
nil
{
return
err
}
step
:=
state
.
Step
step
:=
state
.
Step
name
:=
meta
.
LookupSymbol
(
state
.
PC
)
name
:=
meta
.
LookupSymbol
(
state
.
PC
)
...
...
main.go
View file @
d16685bd
package
main
package
main
import
(
import
(
"context"
"errors"
"fmt"
"fmt"
"os"
"os"
"os/signal"
"syscall"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
...
@@ -18,9 +22,26 @@ func main() {
...
@@ -18,9 +22,26 @@ func main() {
cmd
.
LoadELFCommand
,
cmd
.
LoadELFCommand
,
cmd
.
RunCommand
,
cmd
.
RunCommand
,
}
}
err
:=
app
.
Run
(
os
.
Args
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
go
func
()
{
for
{
<-
c
cancel
()
fmt
.
Println
(
"
\r\n
Exiting..."
)
}
}()
err
:=
app
.
RunContext
(
ctx
,
os
.
Args
)
if
err
!=
nil
{
if
err
!=
nil
{
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
"error: %v"
,
err
)
if
errors
.
Is
(
err
,
ctx
.
Err
())
{
os
.
Exit
(
1
)
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
"command interrupted"
)
os
.
Exit
(
130
)
}
else
{
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
"error: %v"
,
err
)
os
.
Exit
(
1
)
}
}
}
}
}
mipsevm/mips.go
View file @
d16685bd
...
@@ -41,7 +41,7 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -41,7 +41,7 @@ func (m *InstrumentedState) handleSyscall() error {
a1
:=
m
.
state
.
Registers
[
5
]
a1
:=
m
.
state
.
Registers
[
5
]
a2
:=
m
.
state
.
Registers
[
6
]
a2
:=
m
.
state
.
Registers
[
6
]
fmt
.
Printf
(
"syscall: %d
\n
"
,
syscallNum
)
//
fmt.Printf("syscall: %d\n", syscallNum)
switch
syscallNum
{
switch
syscallNum
{
case
4090
:
// mmap
case
4090
:
// mmap
sz
:=
a1
sz
:=
a1
...
@@ -50,11 +50,11 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -50,11 +50,11 @@ func (m *InstrumentedState) handleSyscall() error {
}
}
if
a0
==
0
{
if
a0
==
0
{
v0
=
m
.
state
.
Heap
v0
=
m
.
state
.
Heap
fmt
.
Printf
(
"mmap heap 0x%x size 0x%x
\n
"
,
v0
,
sz
)
//
fmt.Printf("mmap heap 0x%x size 0x%x\n", v0, sz)
m
.
state
.
Heap
+=
sz
m
.
state
.
Heap
+=
sz
}
else
{
}
else
{
v0
=
a0
v0
=
a0
fmt
.
Printf
(
"mmap hint 0x%x size 0x%x
\n
"
,
v0
,
sz
)
//
fmt.Printf("mmap hint 0x%x size 0x%x\n", v0, sz)
}
}
// Go does this thing where it first gets memory with PROT_NONE,
// Go does this thing where it first gets memory with PROT_NONE,
// and then mmaps with a hint with prot=3 (PROT_READ|WRITE).
// and then mmaps with a hint with prot=3 (PROT_READ|WRITE).
...
@@ -84,7 +84,7 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -84,7 +84,7 @@ func (m *InstrumentedState) handleSyscall() error {
m
.
trackMemAccess
(
effAddr
)
m
.
trackMemAccess
(
effAddr
)
mem
:=
m
.
state
.
Memory
.
GetMemory
(
effAddr
)
mem
:=
m
.
state
.
Memory
.
GetMemory
(
effAddr
)
dat
,
datLen
:=
m
.
readPreimage
(
m
.
state
.
PreimageKey
,
m
.
state
.
PreimageOffset
)
dat
,
datLen
:=
m
.
readPreimage
(
m
.
state
.
PreimageKey
,
m
.
state
.
PreimageOffset
)
fmt
.
Printf
(
"reading pre-image data: addr: %08x, offset: %d, datLen: %d, data: %x, key: %s count: %d
\n
"
,
a1
,
m
.
state
.
PreimageOffset
,
datLen
,
dat
[
:
datLen
],
m
.
state
.
PreimageKey
,
a2
)
//
fmt.Printf("reading pre-image data: addr: %08x, offset: %d, datLen: %d, data: %x, key: %s count: %d\n", a1, m.state.PreimageOffset, datLen, dat[:datLen], m.state.PreimageKey, a2)
alignment
:=
a1
&
3
alignment
:=
a1
&
3
space
:=
4
-
alignment
space
:=
4
-
alignment
if
space
<
datLen
{
if
space
<
datLen
{
...
@@ -99,7 +99,7 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -99,7 +99,7 @@ func (m *InstrumentedState) handleSyscall() error {
m
.
state
.
Memory
.
SetMemory
(
effAddr
,
binary
.
BigEndian
.
Uint32
(
outMem
[
:
]))
m
.
state
.
Memory
.
SetMemory
(
effAddr
,
binary
.
BigEndian
.
Uint32
(
outMem
[
:
]))
m
.
state
.
PreimageOffset
+=
datLen
m
.
state
.
PreimageOffset
+=
datLen
v0
=
datLen
v0
=
datLen
fmt
.
Printf
(
"read %d pre-image bytes, new offset: %d, eff addr: %08x mem: %08x
\n
"
,
datLen
,
m
.
state
.
PreimageOffset
,
effAddr
,
outMem
)
//
fmt.Printf("read %d pre-image bytes, new offset: %d, eff addr: %08x mem: %08x\n", datLen, m.state.PreimageOffset, effAddr, outMem)
case
fdHintRead
:
// hint response
case
fdHintRead
:
// hint response
// don't actually read into memory, just say we read it all, we ignore the result anyway
// don't actually read into memory, just say we read it all, we ignore the result anyway
v0
=
a2
v0
=
a2
...
@@ -147,7 +147,7 @@ func (m *InstrumentedState) handleSyscall() error {
...
@@ -147,7 +147,7 @@ func (m *InstrumentedState) handleSyscall() error {
copy
(
key
[
32
-
a2
:
],
tmp
[
:
])
copy
(
key
[
32
-
a2
:
],
tmp
[
:
])
m
.
state
.
PreimageKey
=
key
m
.
state
.
PreimageKey
=
key
m
.
state
.
PreimageOffset
=
0
m
.
state
.
PreimageOffset
=
0
fmt
.
Printf
(
"updating pre-image key: %s
\n
"
,
m
.
state
.
PreimageKey
)
//
fmt.Printf("updating pre-image key: %s\n", m.state.PreimageKey)
v0
=
a2
v0
=
a2
default
:
default
:
v0
=
0xFFffFFff
v0
=
0xFFffFFff
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment