6c92f85d10
Bring the Nexus/Praxis/Hexis integration in line with MAVEN_ECOSYSTEM_ARCHITECTURE.md: - Praxis over HTTP: drop the in-process praxis.db open (praxisstore/ praxistools) and call praxisd's /api/v1/tools/* API via a new praxisClient. Honors the "no component reads another's DB" invariant (AC#12). PraxisConfig.DBPath -> URL. - Hexis confirmation gate: mutating capabilities (ReadOnly=false) now park a bound pendingHexis confirmation and require a spoken "да" before executing; read-only run immediately (AC#7, no auto attention->action). - Capability safety: >1 verb match is ambiguous -> ask instead of firing the first; ambiguous Nexus resolution asks for clarification (AC#2). - Correlation IDs on Hexis execute, recorded in the cross-service trace. - Bug: importance arrives as JSON float64 over HTTP, not int. - Tests: confirm-gate, decline, read-only, and ambiguity paths. Build: vendor/ bakes in the hexis client (replace-directed at a sibling repo outside the Docker context); Dockerfile builds from vendor and no longer `go mod download`s the unreachable replace paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
141 lines
3.6 KiB
Go
141 lines
3.6 KiB
Go
// Copyright 2021 The Libc 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 libc.membrk && !libc.memgrind && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
|
|
|
|
// This is a debug-only version of the memory handling functions. When a
|
|
// program is built with -tags=libc.membrk a simple but safe version of malloc
|
|
// and friends is used that works like sbrk(2). Additionally free becomes a
|
|
// nop.
|
|
|
|
package libc // import "modernc.org/libc"
|
|
|
|
import (
|
|
"math"
|
|
"math/bits"
|
|
"unsafe"
|
|
|
|
"modernc.org/libc/errno"
|
|
"modernc.org/libc/sys/types"
|
|
)
|
|
|
|
const (
|
|
heapAlign = 16
|
|
memgrind = false
|
|
)
|
|
|
|
var (
|
|
heap = make([]byte, heapSize)
|
|
heapP = uintptr(unsafe.Pointer(&heap[heapAlign]))
|
|
heapLast = uintptr(unsafe.Pointer(&heap[heapSize-1]))
|
|
)
|
|
|
|
// void *malloc(size_t size);
|
|
func Xmalloc(t *TLS, n types.Size_t) uintptr {
|
|
if __ccgo_strace {
|
|
trc("t=%v n=%v, (%v:)", t, n, origin(2))
|
|
}
|
|
if n == 0 {
|
|
// malloc(0) should return unique pointers
|
|
// (often expected and gnulib replaces malloc if malloc(0) returns 0)
|
|
n = 1
|
|
}
|
|
|
|
allocMu.Lock()
|
|
|
|
defer allocMu.Unlock()
|
|
|
|
n2 := uintptr(n) + uintptrSize // reserve space for recording block size
|
|
p := roundup(heapP, 16)
|
|
if p+uintptr(n2) >= heapLast {
|
|
t.setErrno(errno.ENOMEM)
|
|
return 0
|
|
}
|
|
|
|
heapP = p + uintptr(n2)
|
|
*(*uintptr)(unsafe.Pointer(p - uintptrSize)) = uintptr(n)
|
|
return p
|
|
}
|
|
|
|
// void *calloc(size_t nmemb, size_t size);
|
|
func Xcalloc(t *TLS, n, size types.Size_t) uintptr {
|
|
if __ccgo_strace {
|
|
trc("t=%v n=%v size=%v, (%v:)", t, n, size, origin(2))
|
|
}
|
|
hi, rq := bits.Mul(uint(n), uint(size))
|
|
if hi != 0 || rq > math.MaxInt {
|
|
t.setErrno(errno.ENOMEM)
|
|
return 0
|
|
}
|
|
return Xmalloc(t, types.Size_t(rq))
|
|
}
|
|
|
|
// void *realloc(void *ptr, size_t size);
|
|
func Xrealloc(t *TLS, ptr uintptr, size types.Size_t) uintptr {
|
|
if __ccgo_strace {
|
|
trc("t=%v ptr=%v size=%v, (%v:)", t, ptr, size, origin(2))
|
|
}
|
|
switch {
|
|
case ptr != 0 && size != 0:
|
|
p := Xmalloc(t, size)
|
|
sz0 := UsableSize(ptr)
|
|
if p != 0 {
|
|
copy((*RawMem)(unsafe.Pointer(p))[:size:size], (*RawMem)(unsafe.Pointer(ptr))[:sz0:sz0])
|
|
}
|
|
return p
|
|
case ptr == 0 && size != 0:
|
|
return Xmalloc(t, size)
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// void free(void *ptr);
|
|
|
|
func Xfree(t *TLS, p uintptr) {
|
|
if __ccgo_strace {
|
|
trc("t=%v p=%v, (%v:)", t, p, origin(2))
|
|
}
|
|
}
|
|
|
|
func UsableSize(p uintptr) types.Size_t {
|
|
if p == 0 {
|
|
return 0
|
|
}
|
|
return types.Size_t(*(*uintptr)(unsafe.Pointer(p - uintptrSize)))
|
|
}
|
|
|
|
type MemAllocatorStat struct {
|
|
Allocs int
|
|
Bytes int
|
|
Mmaps int
|
|
}
|
|
|
|
// MemStat no-op for this build tag
|
|
func MemStat() MemAllocatorStat {
|
|
return MemAllocatorStat{}
|
|
}
|
|
|
|
// MemAuditStart locks the memory allocator, initializes and enables memory
|
|
// auditing. Finaly it unlocks the memory allocator.
|
|
//
|
|
// Some memory handling errors, like double free or freeing of unallocated
|
|
// memory, will panic when memory auditing is enabled.
|
|
//
|
|
// This memory auditing functionality has to be enabled using the libc.memgrind
|
|
// build tag.
|
|
//
|
|
// It is intended only for debug/test builds. It slows down memory allocation
|
|
// routines and it has additional memory costs.
|
|
func MemAuditStart() {}
|
|
|
|
// MemAuditReport locks the memory allocator, reports memory leaks, if any.
|
|
// Finally it disables memory auditing and unlocks the memory allocator.
|
|
//
|
|
// This memory auditing functionality has to be enabled using the libc.memgrind
|
|
// build tag.
|
|
//
|
|
// It is intended only for debug/test builds. It slows down memory allocation
|
|
// routines and it has additional memory costs.
|
|
func MemAuditReport() error { return nil }
|