github.com/golang/gofrontend@v0.0.0-20240429183944-60f985a78526/libgo/misc/cgo/test/issue4029.c (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !windows,!static
     6  // +build !darwin !internal_pie,!arm64
     7  
     8  #include <stdint.h>
     9  #include <dlfcn.h>
    10  
    11  // Write our own versions of dlopen/dlsym/dlclose so that we represent
    12  // the opaque handle as a Go uintptr rather than a Go pointer to avoid
    13  // garbage collector confusion.  See issue 23663.
    14  
    15  uintptr_t dlopen4029(char* name, int flags) {
    16  	return (uintptr_t)(dlopen(name, flags));
    17  }
    18  
    19  uintptr_t dlsym4029(uintptr_t handle, char* name) {
    20  	return (uintptr_t)(dlsym((void*)(handle), name));
    21  }
    22  
    23  int dlclose4029(uintptr_t handle) {
    24  	return dlclose((void*)(handle));
    25  }
    26  
    27  void call4029(void *arg) {
    28  	void (*fn)(void) = arg;
    29  	fn();
    30  }