github.com/ebitengine/purego@v0.8.0-alpha.2.0.20240512170805-6cd12240d332/internal/cgo/syscall_cgo_unix.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
     3  
     4  //go:build freebsd || (linux && !(arm64 || amd64))
     5  
     6  package cgo
     7  
     8  // this file is placed inside internal/cgo and not package purego
     9  // because Cgo and assembly files can't be in the same package.
    10  
    11  /*
    12   #cgo LDFLAGS: -ldl
    13  
    14  #include <stdint.h>
    15  #include <dlfcn.h>
    16  #include <errno.h>
    17  #include <assert.h>
    18  
    19  typedef struct syscall15Args {
    20  	uintptr_t fn;
    21  	uintptr_t a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15;
    22  	uintptr_t f1, f2, f3, f4, f5, f6, f7, f8;
    23  	uintptr_t err;
    24  } syscall15Args;
    25  
    26  void syscall15(struct syscall15Args *args) {
    27  	assert((args->f1|args->f2|args->f3|args->f4|args->f5|args->f6|args->f7|args->f8) == 0);
    28  	uintptr_t (*func_name)(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6,
    29  		uintptr_t a7, uintptr_t a8, uintptr_t a9, uintptr_t a10, uintptr_t a11, uintptr_t a12,
    30  		uintptr_t a13, uintptr_t a14, uintptr_t a15);
    31  	*(void**)(&func_name) = (void*)(args->fn);
    32  	uintptr_t r1 =  func_name(args->a1,args->a2,args->a3,args->a4,args->a5,args->a6,args->a7,args->a8,args->a9,
    33  		args->a10,args->a11,args->a12,args->a13,args->a14,args->a15);
    34  	args->a1 = r1;
    35  	args->err = errno;
    36  }
    37  
    38  */
    39  import "C"
    40  import "unsafe"
    41  
    42  // assign purego.syscall15XABI0 to the C version of this function.
    43  var Syscall15XABI0 = unsafe.Pointer(C.syscall15)
    44  
    45  //go:nosplit
    46  func Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
    47  	args := C.syscall15Args{
    48  		C.uintptr_t(fn), C.uintptr_t(a1), C.uintptr_t(a2), C.uintptr_t(a3),
    49  		C.uintptr_t(a4), C.uintptr_t(a5), C.uintptr_t(a6),
    50  		C.uintptr_t(a7), C.uintptr_t(a8), C.uintptr_t(a9), C.uintptr_t(a10), C.uintptr_t(a11), C.uintptr_t(a12),
    51  		C.uintptr_t(a13), C.uintptr_t(a14), C.uintptr_t(a15), 0, 0, 0, 0, 0, 0, 0, 0, 0,
    52  	}
    53  	C.syscall15(&args)
    54  	return uintptr(args.a1), 0, uintptr(args.err)
    55  }