-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: leongross <[email protected]>
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2012 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !plan9 && !windows && !js && !wasm && !wasip1 && !wasip2 | ||
// +build !plan9,!windows,!js,!wasm,!wasip1,!wasip2 | ||
|
||
package signal | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
numSig = 65 // max across all systems | ||
) | ||
|
||
type Signal interface { | ||
String() string | ||
Signal() // to distinguish from other Stringers | ||
} | ||
|
||
// Defined by the runtime package and used by syscall/sigqueue.go. | ||
func signal_disable(uint32) | ||
func signal_enable(uint32) | ||
func signal_ignore(uint32) | ||
func signal_ignored(uint32) bool | ||
func signal_recv() uint32 | ||
|
||
func signum(sig os.Signal) int { | ||
switch sig := sig.(type) { | ||
case syscall.Signal: | ||
i := int(sig) | ||
if i < 0 || i >= numSig { | ||
return -1 | ||
} | ||
return i | ||
default: | ||
return -1 | ||
} | ||
} | ||
|
||
func enableSignal(sig int) { | ||
signal_enable(uint32(sig)) | ||
} | ||
|
||
func disableSignal(sig int) { | ||
signal_disable(uint32(sig)) | ||
} | ||
|
||
func ignoreSignal(sig int) { | ||
signal_ignore(uint32(sig)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//go:build !plan9 && !windows && !js && !wasm && !wasip1 && !wasip2 | ||
// +build !plan9,!windows,!js,!wasm,!wasip1,!wasip2 | ||
|
||
package signal | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
// The file sigqueue.go contains preliminary stubs for signal handling. | ||
// Since tinygo ultimately lacks support for signals, these stubs are | ||
// placeholders for future work. | ||
// There might be userland applications that rely on these functions | ||
// from the upstream go package os/signal that we want to enable | ||
// building and linking. | ||
|
||
func TestSignalHandling(t *testing.T) { | ||
if runtime.GOOS == "wasip1" || runtime.GOOS == "wasip2" { | ||
t.Skip() | ||
} | ||
|
||
// This test is a placeholder for future work. | ||
// It is here to ensure that the stubs in sigqueue.go | ||
// are correctly linked and can be called from userland | ||
// applications. | ||
enableSignal(0) | ||
disableSignal(0) | ||
ignoreSignal(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !plan9 | ||
// +build !plan9 | ||
|
||
package runtime | ||
|
||
// Stub definitions copied from upstream golang | ||
// TODO: implement a minimal functional version of these functions | ||
|
||
// go: linkname os/signal.signal_disable signal_disable | ||
func signal_disable(_ uint32) {} | ||
|
||
// go: linkname os/signal.signal_enable signal_enable | ||
func signal_enable(_ uint32) {} | ||
|
||
// go: linkname os/signal.signal_ignore signal_ignore | ||
func signal_ignore(_ uint32) {} | ||
|
||
// go: linkname os/signal.signal_ignored signal_ignored | ||
func signal_ignored(_ uint32) bool { return true } | ||
|
||
// go: linkname os/signal.signal_recv signal_recv | ||
func signal_recv() uint32 { return 0 } |