Commit 7b362270 authored by Matthew Dempsky's avatar Matthew Dempsky Committed by Ian Lance Taylor

runtime: remove C-style strcmp and strncmp helpers

Change-Id: I4aa23e3a0e765651c91907507a0194fd528b6223
Reviewed-on: https://go-review.googlesource.com/4662Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent f10e0377
......@@ -10,11 +10,11 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
_g_ := getg()
var t sigTabT
var docrash bool
var length int
var sig int
var flags int
c := &sigctxt{_ureg}
notestr := gostringnocopy(note)
// The kernel will never pass us a nil note or ureg so we probably
// made a mistake somewhere in sigtramp.
......@@ -24,8 +24,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
}
// Check that the note is no more than ERRMAX bytes (including
// the trailing NUL). We should never receive a longer note.
length = findnull(note)
if length > _ERRMAX-1 {
if len(notestr) > _ERRMAX-1 {
print("sighandler: note is longer than ERRMAX\n")
goto Throw
}
......@@ -34,11 +33,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
// level by the program but will otherwise be ignored.
flags = _SigNotify
for sig, t = range sigtable {
n := len(t.name)
if length < n {
continue
}
if strncmp(note, &t.name[0], uintptr(n)) == 0 {
if hasprefix(notestr, t.name) {
flags = t.flags
break
}
......@@ -49,7 +44,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
if flags&_SigPanic != 0 {
// Copy the error string from sigtramp's stack into m->notesig so
// we can reliably access it from the panic routines.
memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(length+1))
memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1))
gp.sig = uint32(sig)
gp.sigpc = c.pc()
// Only push sigpanic if PC != 0.
......@@ -86,7 +81,7 @@ Throw:
_g_.m.throwing = 1
_g_.m.caughtsig = gp
startpanic()
print(gostringnocopy(note), "\n")
print(notestr, "\n")
print("PC=", hex(c.pc()), "\n")
print("\n")
if gotraceback(&docrash) > 0 {
......
......@@ -6,7 +6,7 @@ package runtime
type sigTabT struct {
flags int
name []byte
name string
}
// Incoming notes are compared against this table using strncmp, so the
......@@ -18,37 +18,37 @@ type sigTabT struct {
// and also update the constant values is os2_plan9.go.
var sigtable = [...]sigTabT{
// Traps that we cannot be recovered.
{_SigThrow, []byte("sys: trap: debug exception")},
{_SigThrow, []byte("sys: trap: invalid opcode")},
{_SigThrow, "sys: trap: debug exception"},
{_SigThrow, "sys: trap: invalid opcode"},
// We can recover from some memory errors in runtime·sigpanic.
{_SigPanic, []byte("sys: trap: fault read addr")}, // SIGRFAULT
{_SigPanic, []byte("sys: trap: fault write addr")}, // SIGWFAULT
{_SigPanic, "sys: trap: fault read addr"}, // SIGRFAULT
{_SigPanic, "sys: trap: fault write addr"}, // SIGWFAULT
// We can also recover from math errors.
{_SigPanic, []byte("sys: trap: divide error")}, // SIGINTDIV
{_SigPanic, []byte("sys: fp:")}, // SIGFLOAT
{_SigPanic, "sys: trap: divide error"}, // SIGINTDIV
{_SigPanic, "sys: fp:"}, // SIGFLOAT
// All other traps are normally handled as if they were marked SigThrow.
// We mark them SigPanic here so that debug.SetPanicOnFault will work.
{_SigPanic, []byte("sys: trap:")}, // SIGTRAP
{_SigPanic, "sys: trap:"}, // SIGTRAP
// Writes to a closed pipe can be handled if desired, otherwise they're ignored.
{_SigNotify, []byte("sys: write on closed pipe")},
{_SigNotify, "sys: write on closed pipe"},
// Other system notes are more serious and cannot be recovered.
{_SigThrow, []byte("sys:")},
{_SigThrow, "sys:"},
// Issued to all other procs when calling runtime·exit.
{_SigGoExit, []byte("go: exit ")},
{_SigGoExit, "go: exit "},
// Kill is sent by external programs to cause an exit.
{_SigKill, []byte("kill")},
{_SigKill, "kill"},
// Interrupts can be handled if desired, otherwise they cause an exit.
{_SigNotify + _SigKill, []byte("interrupt")},
{_SigNotify + _SigKill, []byte("hangup")},
{_SigNotify + _SigKill, "interrupt"},
{_SigNotify + _SigKill, "hangup"},
// Alarms can be handled if desired, otherwise they're ignored.
{_SigNotify, []byte("alarm")},
{_SigNotify, "alarm"},
}
......@@ -67,42 +67,3 @@ func gostringw(strw *uint16) string {
b[n2] = 0 // for luck
return s[:n2]
}
func strcmp(s1, s2 *byte) int32 {
p1 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s1))
p2 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s2))
for i := uintptr(0); ; i++ {
c1 := p1[i]
c2 := p2[i]
if c1 < c2 {
return -1
}
if c1 > c2 {
return +1
}
if c1 == 0 {
return 0
}
}
}
func strncmp(s1, s2 *byte, n uintptr) int32 {
p1 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s1))
p2 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s2))
for i := uintptr(0); i < n; i++ {
c1 := p1[i]
c2 := p2[i]
if c1 < c2 {
return -1
}
if c1 > c2 {
return +1
}
if c1 == 0 {
break
}
}
return 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment