| ... | @@ -111,7 +111,11 @@ functions: std.AutoArrayHashMapUnmanaged(struct { file: ?u16, index: u32 }, std. | ... | @@ -111,7 +111,11 @@ functions: std.AutoArrayHashMapUnmanaged(struct { file: ?u16, index: u32 }, std. |
| 111 | /// Output global section | 111 | /// Output global section |
| 112 | wasm_globals: std.ArrayListUnmanaged(std.wasm.Global) = .{}, | 112 | wasm_globals: std.ArrayListUnmanaged(std.wasm.Global) = .{}, |
| 113 | /// Memory section | 113 | /// Memory section |
| 114 | memories: std.wasm.Memory = .{ .limits = .{ .min = 0, .max = null } }, | 114 | memories: std.wasm.Memory = .{ .limits = .{ |
| | 115 | .min = 0, |
| | 116 | .max = undefined, |
| | 117 | .flags = 0, |
| | 118 | } }, |
| 115 | /// Output table section | 119 | /// Output table section |
| 116 | tables: std.ArrayListUnmanaged(std.wasm.Table) = .{}, | 120 | tables: std.ArrayListUnmanaged(std.wasm.Table) = .{}, |
| 117 | /// Output export section | 121 | /// Output export section |
| ... | @@ -396,7 +400,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -396,7 +400,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 396 | const loc = try wasm_bin.createSyntheticSymbol("__indirect_function_table", .table); | 400 | const loc = try wasm_bin.createSyntheticSymbol("__indirect_function_table", .table); |
| 397 | const symbol = loc.getSymbol(wasm_bin); | 401 | const symbol = loc.getSymbol(wasm_bin); |
| 398 | const table: std.wasm.Table = .{ | 402 | const table: std.wasm.Table = .{ |
| 399 | .limits = .{ .min = 0, .max = null }, // will be overwritten during `mapFunctionTable` | 403 | .limits = .{ .flags = 0, .min = 0, .max = undefined }, // will be overwritten during `mapFunctionTable` |
| 400 | .reftype = .funcref, | 404 | .reftype = .funcref, |
| 401 | }; | 405 | }; |
| 402 | if (options.output_mode == .Obj or options.import_table) { | 406 | if (options.output_mode == .Obj or options.import_table) { |
| ... | @@ -1524,7 +1528,7 @@ fn mapFunctionTable(wasm: *Wasm) void { | ... | @@ -1524,7 +1528,7 @@ fn mapFunctionTable(wasm: *Wasm) void { |
| 1524 | const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?; | 1528 | const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?; |
| 1525 | const symbol = sym_loc.getSymbol(wasm); | 1529 | const symbol = sym_loc.getSymbol(wasm); |
| 1526 | const table = &wasm.tables.items[symbol.index - wasm.imported_tables_count]; | 1530 | const table = &wasm.tables.items[symbol.index - wasm.imported_tables_count]; |
| 1527 | table.limits = .{ .min = index, .max = index }; | 1531 | table.limits = .{ .min = index, .max = index, .flags = 0x1 }; |
| 1528 | } | 1532 | } |
| 1529 | } | 1533 | } |
| 1530 | | 1534 | |
| ... | @@ -2236,8 +2240,9 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2236,8 +2240,9 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2236 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { | 2240 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { |
| 2237 | if (wasm.findGlobalSymbol("__tls_base")) |loc| { | 2241 | if (wasm.findGlobalSymbol("__tls_base")) |loc| { |
| 2238 | const sym = loc.getSymbol(wasm); | 2242 | const sym = loc.getSymbol(wasm); |
| 2239 | sym.index = try wasm.globals.append(wasm.base.allocator, wasm.imports.globalCount, .{ | 2243 | sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count; |
| 2240 | .global_type = .{ .valtype = .i32_const, .mutable = false }, | 2244 | try wasm.wasm_globals.append(wasm.base.allocator, .{ |
| | 2245 | .global_type = .{ .valtype = .i32, .mutable = false }, |
| 2241 | .init = .{ .i32_const = @intCast(i32, memory_ptr) }, | 2246 | .init = .{ .i32_const = @intCast(i32, memory_ptr) }, |
| 2242 | }); | 2247 | }); |
| 2243 | } | 2248 | } |
| ... | @@ -2305,6 +2310,10 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2305,6 +2310,10 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2305 | return error.MemoryTooBig; | 2310 | return error.MemoryTooBig; |
| 2306 | } | 2311 | } |
| 2307 | wasm.memories.limits.max = @intCast(u32, max_memory / page_size); | 2312 | wasm.memories.limits.max = @intCast(u32, max_memory / page_size); |
| | 2313 | wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_HAS_MAX); |
| | 2314 | if (wasm.base.options.shared_memory) { |
| | 2315 | wasm.memories.limits.setFlag(.WASM_LIMITS_FLAG_IS_SHARED); |
| | 2316 | } |
| 2308 | log.debug("Maximum memory pages: {?d}", .{wasm.memories.limits.max}); | 2317 | log.debug("Maximum memory pages: {?d}", .{wasm.memories.limits.max}); |
| 2309 | } | 2318 | } |
| 2310 | } | 2319 | } |
| ... | @@ -3517,10 +3526,10 @@ fn emitNameSubsection(wasm: *Wasm, section_id: std.wasm.NameSubsection, names: a | ... | @@ -3517,10 +3526,10 @@ fn emitNameSubsection(wasm: *Wasm, section_id: std.wasm.NameSubsection, names: a |
| 3517 | } | 3526 | } |
| 3518 | | 3527 | |
| 3519 | fn emitLimits(writer: anytype, limits: std.wasm.Limits) !void { | 3528 | fn emitLimits(writer: anytype, limits: std.wasm.Limits) !void { |
| 3520 | try leb.writeULEB128(writer, @boolToInt(limits.max != null)); | 3529 | try writer.writeByte(limits.flags); |
| 3521 | try leb.writeULEB128(writer, limits.min); | 3530 | try leb.writeULEB128(writer, limits.min); |
| 3522 | if (limits.max) |max| { | 3531 | if (limits.hasFlag(.WASM_LIMITS_FLAG_HAS_MAX)) { |
| 3523 | try leb.writeULEB128(writer, max); | 3532 | try leb.writeULEB128(writer, limits.max); |
| 3524 | } | 3533 | } |
| 3525 | } | 3534 | } |
| 3526 | | 3535 | |