Skip to content

Commit ccd7e84

Browse files
authored
WASM ABI: Strip leading underscore from syscall names (#1705)
1 parent a9cead8 commit ccd7e84

File tree

13 files changed

+107
-110
lines changed

13 files changed

+107
-110
lines changed

crates/bindings-csharp/Runtime/Internal/FFI.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,23 @@ public readonly record struct RowIter(uint Handle)
115115
}
116116

117117
[LibraryImport(StdbNamespace)]
118-
public static partial CheckedStatus _table_id_from_name(
118+
public static partial CheckedStatus table_id_from_name(
119119
[In] byte[] name,
120120
uint name_len,
121121
out TableId out_
122122
);
123123

124124
[LibraryImport(StdbNamespace)]
125-
public static partial CheckedStatus _datastore_table_row_count(
126-
TableId table_id,
127-
out ulong out_
128-
);
125+
public static partial CheckedStatus datastore_table_row_count(TableId table_id, out ulong out_);
129126

130127
[LibraryImport(StdbNamespace)]
131-
public static partial CheckedStatus _datastore_table_scan_bsatn(
128+
public static partial CheckedStatus datastore_table_scan_bsatn(
132129
TableId table_id,
133130
out RowIter out_
134131
);
135132

136133
[LibraryImport(StdbNamespace)]
137-
public static partial CheckedStatus _iter_by_col_eq(
134+
public static partial CheckedStatus iter_by_col_eq(
138135
TableId table_id,
139136
ColId col_id,
140137
[In] byte[] value,
@@ -143,14 +140,14 @@ out RowIter out_
143140
);
144141

145142
[LibraryImport(StdbNamespace)]
146-
public static partial CheckedStatus _datastore_insert_bsatn(
143+
public static partial CheckedStatus datastore_insert_bsatn(
147144
TableId table_id,
148145
Span<byte> row,
149146
ref uint row_len
150147
);
151148

152149
[LibraryImport(StdbNamespace)]
153-
public static partial CheckedStatus _delete_by_col_eq(
150+
public static partial CheckedStatus delete_by_col_eq(
154151
TableId table_id,
155152
ColId col_id,
156153
[In] byte[] value,
@@ -159,33 +156,33 @@ out uint out_
159156
);
160157

161158
[LibraryImport(StdbNamespace)]
162-
public static partial CheckedStatus _iter_start_filtered(
159+
public static partial CheckedStatus iter_start_filtered(
163160
TableId table_id,
164161
[In] byte[] filter,
165162
uint filter_len,
166163
out RowIter out_
167164
);
168165

169166
[LibraryImport(StdbNamespace)]
170-
public static partial Errno _row_iter_bsatn_advance(
167+
public static partial Errno row_iter_bsatn_advance(
171168
RowIter iter_handle,
172169
[MarshalUsing(CountElementName = nameof(buffer_len))] [Out] byte[] buffer,
173170
ref uint buffer_len
174171
);
175172

176173
[LibraryImport(StdbNamespace)]
177-
public static partial CheckedStatus _row_iter_bsatn_close(RowIter iter_handle);
174+
public static partial CheckedStatus row_iter_bsatn_close(RowIter iter_handle);
178175

179176
[LibraryImport(StdbNamespace)]
180-
public static partial CheckedStatus _datastore_delete_all_by_eq_bsatn(
177+
public static partial CheckedStatus datastore_delete_all_by_eq_bsatn(
181178
TableId table_id,
182179
[In] byte[] relation,
183180
uint relation_len,
184181
out uint out_
185182
);
186183

187184
[LibraryImport(StdbNamespace)]
188-
public static partial void _volatile_nonatomic_schedule_immediate(
185+
public static partial void volatile_nonatomic_schedule_immediate(
189186
[In] byte[] name,
190187
uint name_len,
191188
[In] byte[] args,
@@ -203,7 +200,7 @@ public enum LogLevel : byte
203200
}
204201

205202
[LibraryImport(StdbNamespace)]
206-
public static partial void _console_log(
203+
public static partial void console_log(
207204
LogLevel level,
208205
[In] byte[] target,
209206
uint target_len,
@@ -215,14 +212,14 @@ uint message_len
215212
);
216213

217214
[LibraryImport(StdbNamespace)]
218-
public static partial Errno _bytes_source_read(
215+
public static partial Errno bytes_source_read(
219216
BytesSource source,
220217
Span<byte> buffer,
221218
ref uint buffer_len
222219
);
223220

224221
[LibraryImport(StdbNamespace)]
225-
public static partial CheckedStatus _bytes_sink_write(
222+
public static partial CheckedStatus bytes_sink_write(
226223
BytesSink sink,
227224
ReadOnlySpan<byte> buffer,
228225
ref uint buffer_len
@@ -254,8 +251,8 @@ internal static class ConsoleTimerIdMarshaller
254251
}
255252

256253
[LibraryImport(StdbNamespace)]
257-
public static partial ConsoleTimerId _console_timer_start([In] byte[] name, uint name_len);
254+
public static partial ConsoleTimerId console_timer_start([In] byte[] name, uint name_len);
258255

259256
[LibraryImport(StdbNamespace)]
260-
public static partial CheckedStatus _console_timer_end(ConsoleTimerId stopwatch_id);
257+
public static partial CheckedStatus console_timer_end(ConsoleTimerId stopwatch_id);
261258
}

crates/bindings-csharp/Runtime/Internal/IReducer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void VolatileNonatomicScheduleImmediate(string name, MemoryStream
1717
var name_bytes = Encoding.UTF8.GetBytes(name);
1818
var args_bytes = args.ToArray();
1919

20-
FFI._volatile_nonatomic_schedule_immediate(
20+
FFI.volatile_nonatomic_schedule_immediate(
2121
name_bytes,
2222
(uint)name_bytes.Length,
2323
args_bytes,

crates/bindings-csharp/Runtime/Internal/ITable.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public bool MoveNext()
3737
while (true)
3838
{
3939
buffer_len = (uint)buffer.Length;
40-
var ret = FFI._row_iter_bsatn_advance(handle, buffer, ref buffer_len);
40+
var ret = FFI.row_iter_bsatn_advance(handle, buffer, ref buffer_len);
4141
if (ret == Errno.EXHAUSTED)
4242
{
4343
handle = FFI.RowIter.INVALID;
@@ -74,7 +74,7 @@ public void Dispose()
7474
{
7575
if (handle != FFI.RowIter.INVALID)
7676
{
77-
FFI._row_iter_bsatn_close(handle);
77+
FFI.row_iter_bsatn_close(handle);
7878
handle = FFI.RowIter.INVALID;
7979
// Avoid running ~RowIter if Dispose was executed successfully.
8080
GC.SuppressFinalize(this);
@@ -120,28 +120,28 @@ public IEnumerable<T> Parse()
120120
private class RawTableIter(FFI.TableId tableId) : RawTableIterBase
121121
{
122122
protected override void IterStart(out FFI.RowIter handle) =>
123-
FFI._datastore_table_scan_bsatn(tableId, out handle);
123+
FFI.datastore_table_scan_bsatn(tableId, out handle);
124124
}
125125

126126
private class RawTableIterFiltered(FFI.TableId tableId, byte[] filterBytes) : RawTableIterBase
127127
{
128128
protected override void IterStart(out FFI.RowIter handle) =>
129-
FFI._iter_start_filtered(tableId, filterBytes, (uint)filterBytes.Length, out handle);
129+
FFI.iter_start_filtered(tableId, filterBytes, (uint)filterBytes.Length, out handle);
130130
}
131131

132132
private class RawTableIterByColEq(FFI.TableId tableId, FFI.ColId colId, byte[] value)
133133
: RawTableIterBase
134134
{
135135
protected override void IterStart(out FFI.RowIter handle) =>
136-
FFI._iter_by_col_eq(tableId, colId, value, (uint)value.Length, out handle);
136+
FFI.iter_by_col_eq(tableId, colId, value, (uint)value.Length, out handle);
137137
}
138138

139139
// Note: this must be Lazy to ensure that we don't try to get the tableId during startup, before the module is initialized.
140140
private static readonly Lazy<FFI.TableId> tableId_ =
141141
new(() =>
142142
{
143143
var name_bytes = System.Text.Encoding.UTF8.GetBytes(typeof(View).Name);
144-
FFI._table_id_from_name(name_bytes, (uint)name_bytes.Length, out var out_);
144+
FFI.table_id_from_name(name_bytes, (uint)name_bytes.Length, out var out_);
145145
return out_;
146146
});
147147

@@ -159,7 +159,7 @@ protected static T Insert(T row)
159159
// Insert the row.
160160
var bytes = IStructuralReadWrite.ToBytes(row);
161161
var bytes_len = (uint)bytes.Length;
162-
FFI._datastore_insert_bsatn(tableId, bytes, ref bytes_len);
162+
FFI.datastore_insert_bsatn(tableId, bytes, ref bytes_len);
163163

164164
// Write back any generated column values.
165165
using var stream = new MemoryStream(bytes, 0, (int)bytes_len);
@@ -190,7 +190,7 @@ public static ColEq Where<TCol, TColRW>(ushort colId, TCol colValue, TColRW rw)
190190

191191
public bool Delete()
192192
{
193-
FFI._delete_by_col_eq(tableId, colId, value, (uint)value.Length, out var out_);
193+
FFI.delete_by_col_eq(tableId, colId, value, (uint)value.Length, out var out_);
194194
return out_ > 0;
195195
}
196196

crates/bindings-csharp/Runtime/Internal/Module.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private static byte[] Consume(this BytesSource source)
121121
// Write into the spare capacity of the buffer.
122122
var spare = buffer.AsSpan((int)written);
123123
var buf_len = (uint)spare.Length;
124-
var ret = FFI._bytes_source_read(source, spare, ref buf_len);
124+
var ret = FFI.bytes_source_read(source, spare, ref buf_len);
125125
written += buf_len;
126126
switch (ret)
127127
{
@@ -155,7 +155,7 @@ private static void Write(this BytesSink sink, byte[] bytes)
155155
{
156156
var written = (uint)bytes.Length;
157157
var buffer = bytes.AsSpan((int)start);
158-
FFI._bytes_sink_write(sink, buffer, ref written);
158+
FFI.bytes_sink_write(sink, buffer, ref written);
159159
start += written;
160160
}
161161
}

crates/bindings-csharp/Runtime/Log.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ uint lineNumber
165165
var filename_bytes = Encoding.UTF8.GetBytes(filename);
166166
var text_bytes = Encoding.UTF8.GetBytes(text);
167167

168-
FFI._console_log(
168+
FFI.console_log(
169169
level,
170170
target_bytes,
171171
(uint)target_bytes.Length,

crates/bindings-csharp/Runtime/LogStopwatch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class LogStopwatch : IDisposable
1111
public LogStopwatch(string name)
1212
{
1313
var name_bytes = Encoding.UTF8.GetBytes(name);
14-
StopwatchId = FFI._console_timer_start(name_bytes, (uint)name_bytes.Length);
14+
StopwatchId = FFI.console_timer_start(name_bytes, (uint)name_bytes.Length);
1515
}
1616

1717
void IDisposable.Dispose()
@@ -24,7 +24,7 @@ void IDisposable.Dispose()
2424

2525
public void End()
2626
{
27-
FFI._console_timer_end(StopwatchId);
27+
FFI.console_timer_end(StopwatchId);
2828
WasStopped = true;
2929
}
3030
}

crates/bindings-csharp/Runtime/bindings.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,54 @@ OPAQUE_TYPEDEF(ConsoleTimerId, uint32_t);
3636
#define IMPORT(ret, name, params, args) STDB_EXTERN(name) ret name params;
3737
#endif
3838

39-
IMPORT(void, _console_log,
39+
IMPORT(void, console_log,
4040
(LogLevel level, const uint8_t* target_ptr, uint32_t target_len,
4141
const uint8_t* filename_ptr, uint32_t filename_len, uint32_t line_number,
4242
const uint8_t* message_ptr, uint32_t message_len),
4343
(level, target_ptr, target_len, filename_ptr, filename_len, line_number,
4444
message_ptr, message_len));
4545

46-
IMPORT(Status, _table_id_from_name,
46+
IMPORT(Status, table_id_from_name,
4747
(const uint8_t* name, uint32_t name_len, TableId* id),
4848
(name, name_len, id));
49-
IMPORT(Status, _datastore_table_row_count,
49+
IMPORT(Status, datastore_table_row_count,
5050
(TableId table_id, uint64_t* count),
5151
(table_id, count));
52-
IMPORT(Status, _datastore_table_scan_bsatn, (TableId table_id, RowIter* iter),
52+
IMPORT(Status, datastore_table_scan_bsatn, (TableId table_id, RowIter* iter),
5353
(table_id, iter));
54-
IMPORT(Status, _iter_by_col_eq,
54+
IMPORT(Status, iter_by_col_eq,
5555
(TableId table_id, ColId col_id, const uint8_t* value,
5656
uint32_t value_len, RowIter* iter),
5757
(table_id, col_id, value, value_len, iter));
58-
IMPORT(Status, _datastore_insert_bsatn, (TableId table_id, const uint8_t* row_ptr, size_t* row_len_ptr),
58+
IMPORT(Status, datastore_insert_bsatn, (TableId table_id, const uint8_t* row_ptr, size_t* row_len_ptr),
5959
(table_id, row_ptr, row_len_ptr));
60-
IMPORT(Status, _delete_by_col_eq,
60+
IMPORT(Status, delete_by_col_eq,
6161
(TableId table_id, ColId col_id, const uint8_t* value,
6262
uint32_t value_len, uint32_t* num_deleted),
6363
(table_id, col_id, value, value_len, num_deleted));
64-
IMPORT(Status, _iter_start_filtered,
64+
IMPORT(Status, iter_start_filtered,
6565
(TableId table_id, const uint8_t* filter, uint32_t filter_len,
6666
RowIter* iter),
6767
(table_id, filter, filter_len, iter));
68-
IMPORT(int16_t, _row_iter_bsatn_advance,
68+
IMPORT(int16_t, row_iter_bsatn_advance,
6969
(RowIter iter, uint8_t* buffer_ptr, size_t* buffer_len_ptr),
7070
(iter, buffer_ptr, buffer_len_ptr));
71-
IMPORT(uint16_t, _row_iter_bsatn_close, (RowIter iter), (iter));
72-
IMPORT(Status, _datastore_delete_all_by_eq_bsatn,
71+
IMPORT(uint16_t, row_iter_bsatn_close, (RowIter iter), (iter));
72+
IMPORT(Status, datastore_delete_all_by_eq_bsatn,
7373
(TableId table_id, const uint8_t* rel_ptr, uint32_t rel_len,
7474
uint32_t* num_deleted),
7575
(table_id, rel_ptr, rel_len, num_deleted));
76-
IMPORT(void, _volatile_nonatomic_schedule_immediate,
76+
IMPORT(void, volatile_nonatomic_schedule_immediate,
7777
(const uint8_t* name, size_t name_len, const uint8_t* args, size_t args_len),
7878
(name, name_len, args, args_len));
79-
IMPORT(int16_t, _bytes_source_read, (BytesSource source, uint8_t* buffer_ptr, size_t* buffer_len_ptr),
79+
IMPORT(int16_t, bytes_source_read, (BytesSource source, uint8_t* buffer_ptr, size_t* buffer_len_ptr),
8080
(source, buffer_ptr, buffer_len_ptr));
81-
IMPORT(uint16_t, _bytes_sink_write, (BytesSink sink, const uint8_t* buffer_ptr, size_t* buffer_len_ptr),
81+
IMPORT(uint16_t, bytes_sink_write, (BytesSink sink, const uint8_t* buffer_ptr, size_t* buffer_len_ptr),
8282
(sink, buffer_ptr, buffer_len_ptr));
83-
IMPORT(ConsoleTimerId, _console_timer_start,
83+
IMPORT(ConsoleTimerId, console_timer_start,
8484
(const uint8_t* name, size_t name_len),
8585
(name, name_len));
86-
IMPORT(Status, _console_timer_end,
86+
IMPORT(Status, console_timer_end,
8787
(ConsoleTimerId stopwatch_id),
8888
(stopwatch_id));
8989

@@ -236,7 +236,7 @@ int32_t WASI_NAME(fd_write)(__wasi_fd_t fd, const __wasi_ciovec_t* iovs,
236236
// Note: this will produce ugly broken output, but there's not much we can
237237
// do about it until we have proper line-buffered WASI writer in the core.
238238
// It's better than nothing though.
239-
_console_log((LogLevel){fd == STDERR_FILENO ? /*WARN*/ 1 : /*INFO*/
239+
console_log((LogLevel){fd == STDERR_FILENO ? /*WARN*/ 1 : /*INFO*/
240240
2},
241241
CSTR("wasi"), CSTR(__FILE__), __LINE__, iovs[i].buf,
242242
iovs[i].buf_len);

crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.targets

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<ItemGroup Condition="'$(EXPERIMENTAL_WASM_AOT)' == '1'">
44
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\bindings.c" />
55
<UnmanagedEntryPointsAssembly Include="SpacetimeDB.Runtime" />
6-
<WasmImport Include="$(SpacetimeNamespace)!_iter_by_col_eq" />
7-
<WasmImport Include="$(SpacetimeNamespace)!_delete_by_col_eq" />
8-
<WasmImport Include="$(SpacetimeNamespace)!_iter_start_filtered" />
9-
<WasmImport Include="$(SpacetimeNamespace)!_table_id_from_name" />
10-
<WasmImport Include="$(SpacetimeNamespace)!_datastore_table_row_count" />
11-
<WasmImport Include="$(SpacetimeNamespace)!_datastore_table_scan_bsatn" />
12-
<WasmImport Include="$(SpacetimeNamespace)!_row_iter_bsatn_advance" />
13-
<WasmImport Include="$(SpacetimeNamespace)!_row_iter_bsatn_close" />
14-
<WasmImport Include="$(SpacetimeNamespace)!_datastore_insert_bsatn" />
15-
<WasmImport Include="$(SpacetimeNamespace)!_datastore_delete_all_by_eq_bsatn" />
16-
<WasmImport Include="$(SpacetimeNamespace)!_bytes_source_read" />
17-
<WasmImport Include="$(SpacetimeNamespace)!_bytes_sink_write" />
18-
<WasmImport Include="$(SpacetimeNamespace)!_console_log" />
6+
<WasmImport Include="$(SpacetimeNamespace)!iter_by_col_eq" />
7+
<WasmImport Include="$(SpacetimeNamespace)!delete_by_col_eq" />
8+
<WasmImport Include="$(SpacetimeNamespace)!iter_start_filtered" />
9+
<WasmImport Include="$(SpacetimeNamespace)!table_id_from_name" />
10+
<WasmImport Include="$(SpacetimeNamespace)!datastore_table_row_count" />
11+
<WasmImport Include="$(SpacetimeNamespace)!datastore_table_scan_bsatn" />
12+
<WasmImport Include="$(SpacetimeNamespace)!row_iter_bsatn_advance" />
13+
<WasmImport Include="$(SpacetimeNamespace)!row_iter_bsatn_close" />
14+
<WasmImport Include="$(SpacetimeNamespace)!datastore_insert_bsatn" />
15+
<WasmImport Include="$(SpacetimeNamespace)!datastore_delete_all_by_eq_bsatn" />
16+
<WasmImport Include="$(SpacetimeNamespace)!bytes_source_read" />
17+
<WasmImport Include="$(SpacetimeNamespace)!bytes_sink_write" />
18+
<WasmImport Include="$(SpacetimeNamespace)!console_log" />
1919

2020
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="8.0.0-*" />
2121
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="8.0.0-*" />

0 commit comments

Comments
 (0)