Exemplo
golang.org/x/sys v0.31.0: unix.EFD_NONBLOCK
Amostra verificada para golang golang.org/x/sys v0.31.0: unix.EFD_NONBLOCK. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.
sha256:f024369c2b5fc6fb4be6e19b4f1c586354ad03f128195c16531e001a43de8838
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-30 |
Caso
HOW- Objetivo
- verify golang.org/x/sys/unix.EFD_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0
- Pacotes
- Símbolos
-
- golang.org/x/sys/unix.EFD_NONBLOCK
- Criado
- 2026-08-30T16:25:09Z
Contrato
- Eventfd created with EFD_NONBLOCK returns EAGAIN on empty read instead of blocking
- Eventfd created with EFD_NONBLOCK successfully reads value after write
- Eventfd created with EFD_NONBLOCK returns EAGAIN on subsequent read after counter is consumed
- Eventfd created with EFD_NONBLOCK and initial counter > 0 allows immediate read without blocking
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify golang.org/x/sys/unix.EFD_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sys@v0.31.0
Demonstrate these symbols/APIs:
- golang.org/x/sys/unix.EFD_NONBLOCK
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:2071119373309075533dc6da14f77f747267f4987422346c2aa02ee0415bb5b4","contract":["Eventfd created with EFD_NONBLOCK returns EAGAIN on empty read instead of blocking","Eventfd created with EFD_NONBLOCK successfully reads value after write","Eventfd created with EFD_NONBLOCK returns EAGAIN on subsequent read after counter is consumed","Eventfd created with EFD_NONBLOCK and initial counter \u003e 0 allows immediate read without blocking"],"goal":"verify golang.org/x/sys/unix.EFD_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"symbols":["golang.org/x/sys/unix.EFD_NONBLOCK"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sys@v0.31.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.31.0","symbols":["golang.org/x/sys/unix.EFD_NONBLOCK"],"verifierAdapter":"golang@1"}
module sample
go 1.23.0
require golang.org/x/sys v0.31.0
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
package main
import (
"encoding/binary"
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
// NonBlockingEventFD wraps a Linux eventfd configured with non-blocking mode.
type NonBlockingEventFD struct {
fd int
}
// NewNonBlockingEventFD creates an eventfd descriptor with EFD_NONBLOCK flag.
func NewNonBlockingEventFD(initval uint) (*NonBlockingEventFD, error) {
fd, err := unix.Eventfd(initval, unix.EFD_NONBLOCK)
if err != nil {
return nil, fmt.Errorf("eventfd creation failed: %w", err)
}
return &NonBlockingEventFD{fd: fd}, nil
}
// Write adds a value to the counter.
func (e *NonBlockingEventFD) Write(val uint64) error {
var buf [8]byte
binary.NativeEndian.PutUint64(buf[:], val)
_, err := unix.Write(e.fd, buf[:])
return err
}
// Read attempts to read the current counter value without blocking.
// Returns unix.EAGAIN if no event has occurred (counter is 0).
func (e *NonBlockingEventFD) Read() (uint64, error) {
var buf [8]byte
n, err := unix.Read(e.fd, buf[:])
if err != nil {
return 0, err
}
if n != 8 {
return 0, fmt.Errorf("unexpected read size: %d", n)
}
return binary.NativeEndian.Uint64(buf[:]), nil
}
// Close closes the underlying file descriptor.
func (e *NonBlockingEventFD) Close() error {
return unix.Close(e.fd)
}
func main() {
efd, err := NewNonBlockingEventFD(0)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create non-blocking eventfd: %v\n", err)
os.Exit(1)
}
defer efd.Close()
// Initial non-blocking read on empty counter returns EAGAIN
_, err = efd.Read()
if !errors.Is(err, unix.EAGAIN) {
fmt.Fprintf(os.Stderr, "expected EAGAIN on empty eventfd, got: %v\n", err)
os.Exit(1)
}
// Write value to eventfd
if err := efd.Write(1); err != nil {
fmt.Fprintf(os.Stderr, "failed to write to eventfd: %v\n", err)
os.Exit(1)
}
// Read value back
val, err := efd.Read()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read from eventfd: %v\n", err)
os.Exit(1)
}
fmt.Printf("eventfd read value: %d\n", val)
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sys/unix.EFD_NONBLOCK in pkg:golang/golang.org/x/sys@v0.31.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sys@v0.31.0"
],
"symbols": [
"golang.org/x/sys/unix.EFD_NONBLOCK"
]
}
package main
import (
"encoding/binary"
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
func main() {
// 1. Eventfd created with EFD_NONBLOCK returns EAGAIN on empty read instead of blocking
{
fd, err := unix.Eventfd(0, unix.EFD_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create eventfd with EFD_NONBLOCK: %v\n", err)
os.Exit(1)
}
defer unix.Close(fd)
var buf [8]byte
_, err = unix.Read(fd, buf[:])
if !errors.Is(err, unix.EAGAIN) {
fmt.Fprintf(os.Stderr, "FAIL: expected EAGAIN on empty non-blocking eventfd read, got %v\n", err)
os.Exit(1)
}
}
// 2. Eventfd created with EFD_NONBLOCK successfully reads value after write
{
fd, err := unix.Eventfd(0, unix.EFD_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create eventfd with EFD_NONBLOCK: %v\n", err)
os.Exit(1)
}
defer unix.Close(fd)
var writeBuf [8]byte
expectedVal := uint64(42)
binary.NativeEndian.PutUint64(writeBuf[:], expectedVal)
n, err := unix.Write(fd, writeBuf[:])
if err != nil || n != 8 {
fmt.Fprintf(os.Stderr, "FAIL: expected write to succeed, got n=%d, err=%v\n", n, err)
os.Exit(1)
}
var readBuf [8]byte
n, err = unix.Read(fd, readBuf[:])
if err != nil || n != 8 {
fmt.Fprintf(os.Stderr, "FAIL: expected read to succeed, got n=%d, err=%v\n", n, err)
os.Exit(1)
}
gotVal := binary.NativeEndian.Uint64(readBuf[:])
if gotVal != expectedVal {
fmt.Fprintf(os.Stderr, "FAIL: expected value %d, got %d\n", expectedVal, gotVal)
os.Exit(1)
}
}
// 3. Eventfd created with EFD_NONBLOCK returns EAGAIN on subsequent read after counter is consumed
{
fd, err := unix.Eventfd(0, unix.EFD_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create eventfd with EFD_NONBLOCK: %v\n", err)
os.Exit(1)
}
defer unix.Close(fd)
var writeBuf [8]byte
binary.NativeEndian.PutUint64(writeBuf[:], 1)
if _, err := unix.Write(fd, writeBuf[:]); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: write failed: %v\n", err)
os.Exit(1)
}
var readBuf [8]byte
if _, err := unix.Read(fd, readBuf[:]); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: first read failed: %v\n", err)
os.Exit(1)
}
// Subsequent read should immediately fail with EAGAIN
_, err = unix.Read(fd, readBuf[:])
if !errors.Is(err, unix.EAGAIN) {
fmt.Fprintf(os.Stderr, "FAIL: expected EAGAIN on second read, got %v\n", err)
os.Exit(1)
}
}
// 4. Eventfd created with EFD_NONBLOCK and initial counter > 0 allows immediate read without blocking
{
initialVal := uint(10)
fd, err := unix.Eventfd(initialVal, unix.EFD_NONBLOCK)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: failed to create eventfd with initial value: %v\n", err)
os.Exit(1)
}
defer unix.Close(fd)
var readBuf [8]byte
n, err := unix.Read(fd, readBuf[:])
if err != nil || n != 8 {
fmt.Fprintf(os.Stderr, "FAIL: expected immediate read to succeed, got n=%d, err=%v\n", n, err)
os.Exit(1)
}
gotVal := binary.NativeEndian.Uint64(readBuf[:])
if gotVal != uint64(initialVal) {
fmt.Fprintf(os.Stderr, "FAIL: expected initial value %d, got %d\n", initialVal, gotVal)
os.Exit(1)
}
}
fmt.Println("PASS: all contract assertions passed")
}
Seeder de origem
anônimo