-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for darwin/arm64 (#7)
This diff ensures we hardcode the capabilities of darwin/arm64. While there, strive to make the packages naming slightly less confusing. Reference issue: ooni/probe#2122. Surpersedes (and draws from) #5. Co-authored-by: ain ghazal ainghazal42@gmail.com Co-authored-by: ain ghazal <ainghazal42@gmail.com>
- Loading branch information
1 parent
72b2086
commit d01c7ff
Showing
8 changed files
with
107 additions
and
48 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
//go:build !arm64 || (!darwin && !android) | ||
|
||
package cpuoverlay | ||
|
||
import "golang.org/x/sys/cpu" | ||
|
||
// | ||
// This file is built when we're not on arm64 or we're on windows/arm64. In the | ||
// former case, just returning false would do. In the latter case, the right thing | ||
// to do is to return cpu.ARM64.HasXXX. Because cpu.ARM64.HasXXX are always false | ||
// when not on arm64, we conflate these two cases in a single file. | ||
// | ||
|
||
// arm64HasAES returns whether the CPU supports AES. | ||
func arm64HasAES() bool { | ||
return cpu.ARM64.HasAES | ||
} | ||
|
||
// arm64HasPMULL returns whether the CPU supports PMULL. | ||
func arm64HasPMULL() bool { | ||
return cpu.ARM64.HasPMULL | ||
} |
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,44 @@ | ||
// Package cpuoverlay is a logic overlay on top of x/sys/cpu that | ||
// attempts to avoid cases in which x/sys/cpu is wrong. | ||
// | ||
// android/arm64 | ||
// | ||
// The main problem that we want to solve is that on Android there are | ||
// cases where reading /proc/self/auxv is not possible. | ||
// | ||
// This causes crypto/tls to not choose AES where it would otherwise | ||
// be possible, in turn causing censorship. See also the | ||
// https://github.com/ooni/probe/issues/1444 issue for more details. | ||
// | ||
// Ideally we would like to call getauxval(3) when initializing | ||
// the runtime package. However, runtime cannot use CGO. Doing that | ||
// leads to an import loop, so we cannot build. | ||
// | ||
// Until this is fixed in src/runtime, we call getauxval(3) here. | ||
// | ||
// darwin/arm64 | ||
// | ||
// Additionally, we may use this package to solve other CPU issues. For | ||
// example, x/sys/cpu does not currently know about darwin/arm64 features. | ||
// | ||
// Design | ||
// | ||
// This package contains GOOS/GOARCH-specific files with predicate | ||
// functions returning the correct value in cases in which x/sys/cpu | ||
// is wrong. You are expected to replace the code that normally | ||
// lives inside src/crypto/tls and src/cryto/aes and that we have | ||
// forked in this repository such that you call the predicates | ||
// of this package as opposed to using directly x/sys/cpu values. | ||
package cpuoverlay | ||
|
||
// We dispatch to GOOS/GOARCH specific implementations | ||
|
||
// Arm64HasAES returns whether the CPU supports AES. | ||
func Arm64HasAES() bool { | ||
return arm64HasAES() | ||
} | ||
|
||
// Arm64HasPMULL returns whether the CPU supports PMULL. | ||
func Arm64HasPMULL() bool { | ||
return arm64HasPMULL() | ||
} |
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,24 @@ | ||
//go:build arm64 && darwin | ||
|
||
package cpuoverlay | ||
|
||
// | ||
// As documented below, there's no support for detecting the | ||
// capabilities of darwin/arm64 in x/sys/cpu so we're going to | ||
// do what internal/cpu currently is doing, i.e., hardcoding | ||
// true because we know M1 supports these HW capabilities. | ||
// | ||
// See https://github.com/ooni/probe/issues/2122 | ||
// | ||
// See https://github.com/golang/go/issues/43046 | ||
// | ||
|
||
// arm64HasAES returns whether the CPU supports AES. | ||
func arm64HasAES() bool { | ||
return true | ||
} | ||
|
||
// arm64HasPMULL returns whether the CPU supports PMULL. | ||
func arm64HasPMULL() bool { | ||
return true | ||
} |
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