uintptrcheck

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package uintptrcheck implements the `glutter-gen uintptrcheck` subcommand, which reads the Windows code and reports a Go pointer that is turned into a uintptr anywhere but in the argument list of a call that keeps it alive (SPEC §25.2).

A uintptr does not keep an object alive, and does not follow it when the stack moves. The compiler makes an exception for the arguments of a call to a function marked //go:uintptrescapes and for syscall.SyscallN: the object stays alive, on the heap, for the call. A conversion written earlier (into a variable, a table, a struct, or in an if that picks between a pointer and 0) has no such protection, and is wrong whenever the call runs Go code before it returns (a COM method of an object made in Go, a window procedure, a callback).

The check reads the syntax only, so it matches a callee by its name: the functions marked in the checked packages and the Syscall functions of the standard library.

Flutter: no counterpart.

Index

Constants

View Source
const RulePtrEscape = "ptr-escape"

RulePtrEscape says that uintptr(unsafe.Pointer(p)) is written in the argument list of a call to a function marked //go:uintptrescapes, or of syscall.SyscallN, and nowhere else.

Variables

View Source
var DefaultDirs = []string{
	"internal/platform/windows", "internal/gpu/d3d12", "internal/gpu/gdiwindow",
	"internal/engine", "cmd/glutter-windows",
}

DefaultDirs are the directories that call Windows, below the root of the module.

Flutter: no counterpart.

Functions

func ReadAllow

func ReadAllow(path string) (map[string]bool, error)

ReadAllow reads an allow file: each line is "rule file:Func", optionally followed by "# why". Blank lines and lines that start with # are skipped.

Flutter: no counterpart.

func Run

func Run(args []string) error

Run is the subcommand: it checks DefaultDirs, drops what the allow file accepts, prints the rest and fails with UintptrCheckViolations when there are some or the allow file is stale.

Flutter: no counterpart.

Types

type Violation

type Violation struct {
	// Rule is RulePtrEscape.
	Rule string
	// File is the path of the file below the root, with slashes.
	File string
	// Func is the function that holds the code: "Name", "Type.Name", or "-" outside any.
	Func string
	// Line is where the conversion is.
	Line int
	// Message says what is wrong.
	Message string
}

Violation is one place where a pointer is converted outside such an argument list.

Flutter: no counterpart.

func Check

func Check(root string, dirs []string) ([]Violation, error)

Check reads every .go file below the directories (whatever its build tags) and returns the violations, sorted by file and line.

Flutter: no counterpart.

func (Violation) Key

func (v Violation) Key() string

Key is how an allow file names the violation: "rule file:Func".

Flutter: no counterpart.

func (Violation) String

func (v Violation) String() string

String is the line of the report.

Flutter: no counterpart.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL