Skip to content

spec: write rules for safe use of unsafe.Pointer and uintptr #7192

Closed
@ianlancetaylor

Description

@ianlancetaylor
People are confused about when it is safe to convert an unsafe.Pointer to a uintptr.  If
the unsafe.Pointer is the only pointer to the object, when is the GC permitted to
collect it?  We need to write down some rules for constructs that are always safe.

It seems to me that we must permit
    unsafe.Pointer(uintptr(p) + offset)

It also seems to me that we must permit passing unsafe.Pointer values converted to
uintptr to syscall.Syscall.
    syscall.Syscall(SYS_OPEN, uintptr(unsafe.Pointer(StringBytePtr(n))))

If these sorts of constructs will not work safely, then we should consider disallowing
them.

And in general we must write down what is permitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions