-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28d6a8e
commit ffdcfe4
Showing
73 changed files
with
3,725 additions
and
0 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
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 @@ | ||
/build |
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,25 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
id("ru.pixnews.sqlite.open.helper.gradle.multiplatform.kotlin") | ||
} | ||
|
||
group = "ru.pixnews.sqlite.open.helper.host" | ||
|
||
kotlin { | ||
jvm() | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
api(projects.commonApi) | ||
} | ||
commonTest.dependencies { | ||
implementation(kotlin("test")) | ||
implementation(libs.assertk) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...emscripten-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/WasmValueType.kt
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,26 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host | ||
|
||
// https://webassembly.github.io/spec/core/appendix/index-types.html | ||
@JvmInline | ||
public value class WasmValueType( | ||
public val opcode: Byte?, | ||
) { | ||
@Suppress("VARIABLE_NAME_INCORRECT") | ||
public companion object WebAssemblyTypes { | ||
public val I32: WasmValueType = WasmValueType(0x7f) | ||
public val I64: WasmValueType = WasmValueType(0x7e) | ||
public val F32: WasmValueType = WasmValueType(0x7d) | ||
public val F64: WasmValueType = WasmValueType(0x7c) | ||
public val V128: WasmValueType = WasmValueType(0x7b) | ||
public val FuncRef: WasmValueType = WasmValueType(0x70) | ||
public val ExternRef: WasmValueType = WasmValueType(0x6f) | ||
public val FunctionType: WasmValueType = WasmValueType(0x60) | ||
public val ResultType: WasmValueType = WasmValueType(0x40) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...cripten-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/WasmValueTypeExt.kt
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,14 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host | ||
|
||
import ru.pixnews.sqlite.open.helper.host.WasmValueType.WebAssemblyTypes.I32 | ||
|
||
public val POINTER: WasmValueType get() = I32 | ||
|
||
public val WasmValueType.pointer: WasmValueType | ||
get() = POINTER |
39 changes: 39 additions & 0 deletions
39
...mmonMain/kotlin/ru/pixnews/sqlite/open/helper/host/emscripten/AssertionFailedException.kt
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,39 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.emscripten | ||
|
||
public class AssertionFailedException( | ||
condition: String?, | ||
filename: String?, | ||
line: Int, | ||
func: String?, | ||
) : RuntimeException( | ||
formatErrMsg( | ||
condition, | ||
filename, | ||
line, | ||
func, | ||
), | ||
) { | ||
private companion object { | ||
fun formatErrMsg( | ||
condition: String?, | ||
filename: String?, | ||
line: Int, | ||
func: String?, | ||
): String = buildString { | ||
append("Assertion failed: ") | ||
append(condition ?: "``") | ||
append(", at ") | ||
listOf( | ||
filename ?: "unknown filename", | ||
line.toString(), | ||
func ?: "unknown function", | ||
).joinTo(this, ", ", prefix = "[", postfix = "]") | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/filesystem/ReadWriteStrategy.kt
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,12 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.filesystem | ||
|
||
public enum class ReadWriteStrategy { | ||
DO_NOT_CHANGE_POSITION, | ||
CHANGE_POSITION, | ||
} |
15 changes: 15 additions & 0 deletions
15
...-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/filesystem/SysException.kt
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,15 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.filesystem | ||
|
||
import ru.pixnews.sqlite.open.helper.host.wasi.preview1.type.Errno | ||
|
||
public class SysException( | ||
public val errNo: Errno, | ||
msg: String? = null, | ||
cause: Throwable? = null, | ||
) : RuntimeException(msg, cause) |
21 changes: 21 additions & 0 deletions
21
...commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/functiontable/IndirectFunctionRef.kt
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,21 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.functiontable | ||
|
||
public sealed interface IndirectFunctionRef { | ||
public val ref: Int | ||
|
||
@JvmInline | ||
public value class FuncRef( | ||
override val ref: Int, | ||
) : IndirectFunctionRef | ||
|
||
@JvmInline | ||
public value class ExternalRef( | ||
override val ref: Int, | ||
) : IndirectFunctionRef | ||
} |
12 changes: 12 additions & 0 deletions
12
...ain/kotlin/ru/pixnews/sqlite/open/helper/host/functiontable/IndirectFunctionTableIndex.kt
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,12 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.functiontable | ||
|
||
@JvmInline | ||
public value class IndirectFunctionTableIndex( | ||
public val funcId: Int, | ||
) |
58 changes: 58 additions & 0 deletions
58
...emscripten-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/include/Fcntl.kt
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,58 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
@file:Suppress("VARIABLE_HAS_PREFIX", "BLANK_LINE_BETWEEN_PROPERTIES") | ||
|
||
package ru.pixnews.sqlite.open.helper.host.include | ||
|
||
public object Fcntl { | ||
public const val O_RDONLY: UInt = 0x0U | ||
public const val O_WRONLY: UInt = 0x1U | ||
public const val O_RDWR: UInt = 0x2U | ||
public const val O_ACCMODE: UInt = 0x3U | ||
|
||
public const val O_CREAT: UInt = 0x40U | ||
public const val O_EXCL: UInt = 0x80U | ||
public const val O_NOCTTY: UInt = 0x100U | ||
public const val O_TRUNC: UInt = 0x200U | ||
public const val O_APPEND: UInt = 0x400U | ||
public const val O_NONBLOCK: UInt = 0x800U | ||
public const val O_NDELAY: UInt = O_NONBLOCK | ||
public const val O_DSYNC: UInt = 0x1000U | ||
public const val O_ASYNC: UInt = 0x2000U | ||
public const val O_DIRECT: UInt = 0x4000U | ||
public const val O_LARGEFILE: UInt = 0x8000U | ||
public const val O_DIRECTORY: UInt = 0x10000U | ||
public const val O_NOFOLLOW: UInt = 0x20000U | ||
public const val O_NOATIME: UInt = 0x40000U | ||
public const val O_CLOEXEC: UInt = 0x80000U | ||
public const val O_SYNC: UInt = 0x101000U | ||
public const val O_PATH: UInt = 0x200000U | ||
public const val O_TMPFILE: UInt = 0x410000U | ||
public const val O_SEARCH: UInt = O_PATH | ||
|
||
public const val S_ISUID: UInt = 0x800U | ||
public const val S_ISGID: UInt = 0x400U | ||
public const val S_ISVTX: UInt = 0x200U | ||
public const val S_IRUSR: UInt = 0x100U | ||
public const val S_IWUSR: UInt = 0x80U | ||
public const val S_IXUSR: UInt = 0x40U | ||
public const val S_IRWXU: UInt = 0x1c0U | ||
public const val S_IRGRP: UInt = 0x20U | ||
public const val S_IWGRP: UInt = 0x10U | ||
public const val S_IXGRP: UInt = 0x08U | ||
public const val S_IRWXG: UInt = 0x38U | ||
public const val S_IROTH: UInt = 0x04U | ||
public const val S_IWOTH: UInt = 0x02U | ||
public const val S_IXOTH: UInt = 0x01U | ||
public const val S_IRWXO: UInt = 0x07U | ||
|
||
public const val AT_FDCWD: Int = -100 | ||
public const val AT_SYMLINK_NOFOLLOW: UInt = 0x100U | ||
public const val AT_REMOVEDIR: UInt = 0x200U | ||
public const val AT_SYMLINK_FOLLOW: UInt = 0x400U | ||
public const val AT_EACCESS: UInt = 0x200U | ||
} |
91 changes: 91 additions & 0 deletions
91
...cripten-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/include/FcntlExt.kt
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,91 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
@file:Suppress("MagicNumber") | ||
|
||
package ru.pixnews.sqlite.open.helper.host.include | ||
|
||
import kotlin.reflect.KProperty0 | ||
|
||
public fun Fcntl.oMaskToString(mask: UInt): String { | ||
val startNames = if (mask.and(O_ACCMODE) == 0U) { | ||
listOf(Fcntl::O_RDONLY.name) | ||
} else { | ||
emptyList() | ||
} | ||
|
||
return maskToString( | ||
mask, | ||
listOf( | ||
Fcntl::O_WRONLY, | ||
Fcntl::O_RDWR, | ||
Fcntl::O_CREAT, | ||
Fcntl::O_EXCL, | ||
Fcntl::O_NOCTTY, | ||
Fcntl::O_TRUNC, | ||
Fcntl::O_APPEND, | ||
Fcntl::O_NONBLOCK, | ||
Fcntl::O_SYNC, | ||
Fcntl::O_TMPFILE, | ||
Fcntl::O_DSYNC, | ||
Fcntl::O_ASYNC, | ||
Fcntl::O_DIRECT, | ||
Fcntl::O_LARGEFILE, | ||
Fcntl::O_DIRECTORY, | ||
Fcntl::O_NOFOLLOW, | ||
Fcntl::O_NOATIME, | ||
Fcntl::O_CLOEXEC, | ||
Fcntl::O_PATH, | ||
), | ||
startNames, | ||
) | ||
} | ||
|
||
public fun Fcntl.sMaskToString(mask: UInt): String = "0${mask.toString(8)}" | ||
|
||
public fun Fcntl.sMaskToStringLong(mask: UInt): String = maskToString( | ||
mask, | ||
listOf( | ||
Fcntl::S_ISUID, | ||
Fcntl::S_ISGID, | ||
Fcntl::S_ISVTX, | ||
Fcntl::S_IRUSR, | ||
Fcntl::S_IWUSR, | ||
Fcntl::S_IXUSR, | ||
Fcntl::S_IRWXU, | ||
Fcntl::S_IRGRP, | ||
Fcntl::S_IWGRP, | ||
Fcntl::S_IXGRP, | ||
Fcntl::S_IRWXG, | ||
Fcntl::S_IROTH, | ||
Fcntl::S_IWOTH, | ||
Fcntl::S_IXOTH, | ||
Fcntl::S_IRWXO, | ||
), | ||
) | ||
|
||
private fun maskToString( | ||
mask: UInt, | ||
maskProps: List<KProperty0<UInt>>, | ||
startNames: List<String> = emptyList(), | ||
): String { | ||
var left = mask | ||
val names = startNames.toMutableList() | ||
maskProps.forEach { prop: KProperty0<UInt> -> | ||
val propMask: UInt = prop.get() | ||
if (left.and(propMask) != 0U) { | ||
names.add(prop.name) | ||
left = left.and(propMask.inv()) | ||
} | ||
} | ||
return buildString { | ||
names.joinTo(this, ",") | ||
if (left != 0U) { | ||
append("0") | ||
append(left.toString(8)) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n-host/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/include/StructTimespec.kt
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,19 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.include | ||
|
||
@Suppress("PropertyName", "ConstructorParameterNaming") | ||
public data class StructTimespec( | ||
val tv_sec: time_t, | ||
val tv_nsec: ULong, | ||
) | ||
|
||
@Suppress("TYPEALIAS_NAME_INCORRECT_CASE") | ||
public typealias time_t = ULong | ||
|
||
public val StructTimespec.timeMillis: ULong | ||
get(): ULong = tv_sec * 1000U + tv_nsec / 1_000_000U |
34 changes: 34 additions & 0 deletions
34
...t/src/commonMain/kotlin/ru/pixnews/sqlite/open/helper/host/wasi/preview1/ext/FdReadExt.kt
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,34 @@ | ||
/* | ||
* Copyright 2024, the wasm-sqlite-open-helper project authors and contributors. Please see the AUTHORS file | ||
* for details. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ru.pixnews.sqlite.open.helper.host.wasi.preview1.ext | ||
|
||
import ru.pixnews.sqlite.open.helper.common.api.WasmPtr | ||
import ru.pixnews.sqlite.open.helper.common.api.plus | ||
import ru.pixnews.sqlite.open.helper.host.memory.Memory | ||
import ru.pixnews.sqlite.open.helper.host.memory.readPtr | ||
import ru.pixnews.sqlite.open.helper.host.wasi.preview1.type.Iovec | ||
import ru.pixnews.sqlite.open.helper.host.wasi.preview1.type.IovecArray | ||
import ru.pixnews.sqlite.open.helper.host.wasi.preview1.type.Size | ||
|
||
@Suppress("VARIABLE_HAS_PREFIX") | ||
public object FdReadExt { | ||
public fun readIovecs( | ||
memory: Memory, | ||
pIov: WasmPtr<Iovec>, | ||
iovCnt: Int, | ||
): IovecArray { | ||
@Suppress("UNCHECKED_CAST", "MagicNumber") | ||
val iovecs = MutableList(iovCnt) { idx -> | ||
val pIovec: WasmPtr<*> = pIov + 8 * idx | ||
Iovec( | ||
buf = memory.readPtr(pIovec as WasmPtr<WasmPtr<Byte>>), | ||
bufLen = Size(memory.readI32(pIovec + 4).toUInt()), | ||
) | ||
} | ||
return IovecArray(iovecs) | ||
} | ||
} |
Oops, something went wrong.