// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT. //go:build (freebsd && amd64) || (freebsd && arm64) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64) package sqlite3 import ( "unsafe" "modernc.org/libc" ) type Tkey_t = int64 // C documentation // // /* // ** Initialize the operating system interface. // ** // ** This routine registers all VFS implementations for unix-like operating // ** systems. This routine, and the sqlite3_os_end() routine that follows, // ** should be the only routines in this file that are visible from other // ** files. // ** // ** This routine is called once during SQLite initialization and by a // ** single thread. The memory allocation and mutex subsystems have not // ** necessarily been initialized when this routine is called, and so they // ** should not be used. // */ func Xsqlite3_os_init(tls *libc.TLS) (r int32) { var i uint32 _ = i /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ /* Settle POSIX vs OFD locking before any file can be opened */ /* Register all VFSes defined in the aVfs[] array */ i = uint32(0) for { if !(uint64(i) < libc.Uint64FromInt64(672)/libc.Uint64FromInt64(168)) { break } Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&_aVfs))+uintptr(i)*168, libc.BoolInt32(i == uint32(0))) goto _1 _1: ; i = i + 1 } _unixBigLock = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)) /* Validate lock assumptions */ /* Number of available locks */ /* Start of locking area */ /* Locks: ** WRITE UNIX_SHM_BASE 120 ** CKPT UNIX_SHM_BASE+1 121 ** RECOVER UNIX_SHM_BASE+2 122 ** READ-0 UNIX_SHM_BASE+3 123 ** READ-1 UNIX_SHM_BASE+4 124 ** READ-2 UNIX_SHM_BASE+5 125 ** READ-3 UNIX_SHM_BASE+6 126 ** READ-4 UNIX_SHM_BASE+7 127 ** DMS UNIX_SHM_BASE+8 128 */ /* Byte offset of the deadman-switch */ /* Initialize temp file dir array. */ _unixTempFileInit(tls) return SQLITE_OK } /* ** The following macro defines an initializer for an sqlite3_vfs object. ** The name of the VFS is NAME. The pAppData is a pointer to a pointer ** to the "finder" function. (pAppData is a pointer to a pointer because ** silly C90 rules prohibit a void* from being cast to a function pointer ** and so we have to go through the intermediate pointer to avoid problems ** when compiling with -pedantic-errors on GCC.) ** ** The FINDER parameter to this macro is the name of the pointer to the ** finder-function. The finder-function returns a pointer to the ** sqlite_io_methods object that implements the desired locking ** behaviors. See the division above that contains the IOMETHODS ** macro for addition information on finder-functions. ** ** Most finders simply return a pointer to a fixed sqlite3_io_methods ** object. But the "autolockIoFinder" available on MacOSX does a little ** more than that; it looks at the filesystem type that hosts the ** database file and tries to choose an locking method appropriate for ** that filesystem time. */ // C documentation // // /* // ** Change the lock state for a shared-memory segment. // ** // ** Note that the relationship between SHARED and EXCLUSIVE locks is a little // ** different here than in posix. In xShmLock(), one can go from unlocked // ** to shared and back or from unlocked to exclusive and back. But one may // ** not go from shared to exclusive or from exclusive to shared. // */ func _unixShmLock(tls *libc.TLS, fd uintptr, ofst int32, n int32, flags int32) (r int32) { var aLock, p, pDbFd, pShmNode, v1 uintptr var bUnlock, ii, rc int32 var mask Tu16 _, _, _, _, _, _, _, _, _ = aLock, bUnlock, ii, mask, p, pDbFd, pShmNode, rc, v1 pDbFd = fd /* The underlying file iNode */ rc = SQLITE_OK /* Result code */ mask = libc.Uint16FromInt32(int32(1)<<(ofst+n) - int32(1)<=3 && ofst int32(1) { bUnlock = 0 **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) = **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) - 1 v1 = p + 18 *(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromUint16(mask)) } } if bUnlock != 0 { rc = _unixShmSystemLock(tls, pDbFd, int32(F_UNLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n) if rc == SQLITE_OK { libc.Xmemset(tls, aLock+uintptr(ofst)*4, 0, uint64(4)*libc.Uint64FromInt32(n)) v1 = p + 18 *(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromUint16(mask)) v1 = p + 20 *(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromUint16(mask)) } } } else { if flags&int32(SQLITE_SHM_SHARED) != 0 { /* Case (b) - a shared lock. */ if **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) < 0 { /* An exclusive lock is held by some other connection. BUSY. */ rc = int32(SQLITE_BUSY) } else { if **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) == 0 { rc = _unixShmSystemLock(tls, pDbFd, int32(F_RDLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n) } } /* Get the local shared locks */ if rc == SQLITE_OK { v1 = p + 18 *(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromUint16(mask)) **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) = **(**int32)(__ccgo_up(aLock + uintptr(ofst)*4)) + 1 } } else { /* Make sure no sibling connections hold locks that will block this ** lock. If any do, return SQLITE_BUSY right away. */ ii = ofst for { if !(ii < ofst+n) { break } if **(**int32)(__ccgo_up(aLock + uintptr(ii)*4)) != 0 { rc = int32(SQLITE_BUSY) break } goto _5 _5: ; ii = ii + 1 } /* Get the exclusive locks at the system level. Then if successful ** also update the in-memory values. */ if rc == SQLITE_OK { rc = _unixShmSystemLock(tls, pDbFd, int32(F_WRLCK), ofst+(libc.Int32FromInt32(22)+libc.Int32FromInt32(SQLITE_SHM_NLOCK))*libc.Int32FromInt32(4), n) if rc == SQLITE_OK { v1 = p + 20 *(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromUint16(mask)) ii = ofst for { if !(ii < ofst+n) { break } **(**int32)(__ccgo_up(aLock + uintptr(ii)*4)) = -int32(1) goto _7 _7: ; ii = ii + 1 } } } } } } /* Drop the mutexes acquired above. */ Xsqlite3_mutex_leave(tls, (*TunixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex) } return rc } func init() { p := unsafe.Pointer(&_aSyscall) *(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_posixOpen) *(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(libc.Xclose) *(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(libc.Xaccess) *(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(libc.Xgetcwd) *(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(libc.Xstat) *(*uintptr)(unsafe.Add(p, 128)) = __ccgo_fp(libc.Xfstat) *(*uintptr)(unsafe.Add(p, 152)) = __ccgo_fp(libc.Xftruncate) *(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(libc.Xfcntl) *(*uintptr)(unsafe.Add(p, 200)) = __ccgo_fp(libc.Xread) *(*uintptr)(unsafe.Add(p, 272)) = __ccgo_fp(libc.Xwrite) *(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(libc.Xfchmod) *(*uintptr)(unsafe.Add(p, 392)) = __ccgo_fp(libc.Xunlink) *(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_openDirectory) *(*uintptr)(unsafe.Add(p, 440)) = __ccgo_fp(libc.Xmkdir) *(*uintptr)(unsafe.Add(p, 464)) = __ccgo_fp(libc.Xrmdir) *(*uintptr)(unsafe.Add(p, 488)) = __ccgo_fp(libc.Xfchown) *(*uintptr)(unsafe.Add(p, 512)) = __ccgo_fp(libc.Xgeteuid) *(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(libc.Xmmap) *(*uintptr)(unsafe.Add(p, 560)) = __ccgo_fp(libc.Xmunmap) *(*uintptr)(unsafe.Add(p, 608)) = __ccgo_fp(_unixGetpagesize) *(*uintptr)(unsafe.Add(p, 632)) = __ccgo_fp(libc.Xreadlink) *(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(libc.Xlstat) } /* End of the overrideable system calls */ type t__intptr_t = int64 type t__register_t = int64 type t__uintptr_t = uint64