aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authormunjinoo <2jwdream7029@naver.com>2019-05-06 13:55:50 +0900
committerDmitry Vyukov <dvyukov@google.com>2019-05-07 08:48:35 +0200
commit001e36bc7862e1663aa5e6608882e78f08ebab41 (patch)
tree68f14264f40fe4a08b765ea4e3a225077307dec3 /pkg
parent04e9d8cedd9dc356d116c5387eac8c1ea9d547f7 (diff)
executor: change syscall argument type to intptr_t
The type size of long depends on compiler. Therefore, changing to intptr_t makes it depends on architecture.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/csource.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index d58c361ee..c5beb68c6 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -96,7 +96,7 @@ func (ctx *context) generateSyscalls(calls []string, hasVars bool) string {
buf := new(bytes.Buffer)
if !opts.Threaded && !opts.Collide {
if hasVars || opts.Trace {
- fmt.Fprintf(buf, "\tlong res = 0;\n")
+ fmt.Fprintf(buf, "\tintptr_t res = 0;\n")
}
if opts.Repro {
fmt.Fprintf(buf, "\tif (write(1, \"executing program\\n\", sizeof(\"executing program\\n\") - 1)) {}\n")
@@ -109,7 +109,7 @@ func (ctx *context) generateSyscalls(calls []string, hasVars bool) string {
}
} else {
if hasVars || opts.Trace {
- fmt.Fprintf(buf, "\tlong res;")
+ fmt.Fprintf(buf, "\tintptr_t res;")
}
fmt.Fprintf(buf, "\tswitch (call) {\n")
for i, c := range calls {
@@ -232,7 +232,7 @@ func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCo
if native && ctx.target.PtrSize == 4 {
// syscall accepts args as ellipsis, resources are uint64
// and take 2 slots without the cast, which would be wrong.
- val = "(long)" + val
+ val = "(intptr_t)" + val
}
fmt.Fprintf(w, "%v", val)
default:
@@ -249,9 +249,9 @@ func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCo
if trace {
cast := ""
if !native && !strings.HasPrefix(callName, "syz_") {
- // Potentially we casted a function returning int to a function returning long.
- // So instead of long -1 we can get 0x00000000ffffffff. Sign extend it to long.
- cast = "(long)(int)"
+ // Potentially we casted a function returning int to a function returning intptr_t.
+ // So instead of intptr_t -1 we can get 0x00000000ffffffff. Sign extend it to intptr_t.
+ cast = "(intptr_t)(int)"
}
fmt.Fprintf(w, "\tfprintf(stderr, \"### call=%v errno=%%u\\n\", %vres == -1 ? errno : 0);\n", ci, cast)
}
@@ -264,11 +264,11 @@ func (ctx *context) emitCallName(w *bytes.Buffer, call prog.ExecCall, native boo
} else if strings.HasPrefix(callName, "syz_") {
fmt.Fprintf(w, "%v(", callName)
} else {
- args := strings.Repeat(",long", len(call.Args))
+ args := strings.Repeat(",intptr_t", len(call.Args))
if args != "" {
args = args[1:]
}
- fmt.Fprintf(w, "((long(*)(%v))CAST(%v))(", args, callName)
+ fmt.Fprintf(w, "((intptr_t(*)(%v))CAST(%v))(", args, callName)
}
}
@@ -355,7 +355,7 @@ func (ctx *context) copyinVal(w *bytes.Buffer, addr, size uint64, val string, bf
func (ctx *context) copyout(w *bytes.Buffer, call prog.ExecCall, resCopyout bool) {
if ctx.sysTarget.OS == "fuchsia" {
// On fuchsia we have real system calls that return ZX_OK on success,
- // and libc calls that are casted to function returning long,
+ // and libc calls that are casted to function returning intptr_t,
// as the result int -1 is returned as 0x00000000ffffffff rather than full -1.
if strings.HasPrefix(call.Meta.CallName, "zx_") {
fmt.Fprintf(w, "\tif (res == ZX_OK)")