forked from filecoin-project/filecoin-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle allocations for problematic structs to avoid sharing pointers-…
…to-pointers with C (from Go) (filecoin-project#82) * alternative verify post * manually allocate proxy object to prevent sharing Go heap with C * Revert "alternative verify post" This reverts commit 841ff78. * manually allocate proxy object to prevent sharing Go heap with C * pass flattened messages to fil_hash_verify to prevent pointer-to-pointer issues with CGO * rename symbols within custom allocate methods * run go test with cgocheck=2 * delete temporary branches from circleci config
- Loading branch information
Showing
5 changed files
with
106 additions
and
92 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,54 @@ | ||
package generated | ||
|
||
/* | ||
#cgo LDFLAGS: -L${SRCDIR}/.. -lfilcrypto | ||
#cgo pkg-config: ${SRCDIR}/../filcrypto.pc | ||
#include "../filcrypto.h" | ||
#include <stdlib.h> | ||
#include "cgo_helpers.h" | ||
*/ | ||
import "C" | ||
import ( | ||
"unsafe" | ||
) | ||
|
||
// AllocateProxy allocates a FilPrivateReplicaInfo proxy object in the C heap, | ||
// returning a function which, when called, frees the allocated memory. This | ||
// method exists because the default c-for-go allocation strategy allocates a | ||
// C struct with a field whose values is a pointer into the Go heap, which is | ||
// not permitted by the most strict CGO check (cgocheck=2). | ||
func (x *FilPrivateReplicaInfo) AllocateProxy() func() { | ||
mem := allocFilPrivateReplicaInfoMemory(1) | ||
proxy := (*C.fil_PrivateReplicaInfo)(mem) | ||
proxy.cache_dir_path = C.CString(x.CacheDirPath) | ||
proxy.comm_r = *(*[32]C.uint8_t)(unsafe.Pointer(&x.CommR)) | ||
proxy.registered_proof = (C.fil_RegisteredPoStProof)(x.RegisteredProof) | ||
proxy.replica_path = C.CString(x.ReplicaPath) | ||
proxy.sector_id = (C.uint64_t)(x.SectorId) | ||
|
||
x.ref81a31e9b = proxy | ||
|
||
return func() { | ||
C.free(unsafe.Pointer(proxy.cache_dir_path)) | ||
C.free(unsafe.Pointer(proxy.replica_path)) | ||
C.free(unsafe.Pointer(proxy)) | ||
} | ||
} | ||
|
||
// AllocateProxy allocates a FilPoStProof proxy object in the C heap, | ||
// returning a function which, when called, frees the allocated memory. | ||
func (x *FilPoStProof) AllocateProxy() func() { | ||
mem := allocFilPoStProofMemory(1) | ||
proxy := (*C.fil_PoStProof)(mem) | ||
|
||
proxy.registered_proof = (C.fil_RegisteredPoStProof)(x.RegisteredProof) | ||
proxy.proof_len = (C.size_t)(x.ProofLen) | ||
proxy.proof_ptr = (*C.uchar)(unsafe.Pointer(C.CString(x.ProofPtr))) | ||
|
||
x.ref3451bfa = proxy | ||
|
||
return func() { | ||
C.free(unsafe.Pointer(proxy.proof_ptr)) | ||
C.free(unsafe.Pointer(proxy)) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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