<feed xmlns='http://www.w3.org/2005/Atom'>
<title>unit-wasm.git/src/rust, branch v0.4.0</title>
<subtitle>Development libraries (C &amp; Rust) for writing WebAssembly modules for NGINX Unit</subtitle>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/'/>
<entry>
<title>unit-wasm 0.4.0</title>
<updated>2025-05-14T19:46:09+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2025-05-14T19:46:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=7ef2f181304f19aba59066a35c72e1a239a4218d'/>
<id>7ef2f181304f19aba59066a35c72e1a239a4218d</id>
<content type='text'>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: Fix building of unit-wasm and rust examples</title>
<updated>2025-05-14T17:09:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2025-05-14T16:00:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=12763f6351d0c25b6f90dd7adbe0da3896d8e9c9'/>
<id>12763f6351d0c25b6f90dd7adbe0da3896d8e9c9</id>
<content type='text'>
When building the rust stuff we were getting the following compiler
error

  error: failed to run `rustc` to learn about target-specific information

  ...

    --- stderr
    error: Error loading target specification: Could not find specification for target "wasm32-wasi". Run `rustc --print target-list` for a list of built-in targets

This is due to wasm32-wasi being renamed to wasm32-wasip1, with
wasm32-wasi being kept clear for an eventual WASI 1.0 release.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When building the rust stuff we were getting the following compiler
error

  error: failed to run `rustc` to learn about target-specific information

  ...

    --- stderr
    error: Error loading target specification: Could not find specification for target "wasm32-wasi". Run `rustc --print target-list` for a list of built-in targets

This is due to wasm32-wasi being renamed to wasm32-wasip1, with
wasm32-wasi being kept clear for an eventual WASI 1.0 release.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>unit-wasm 0.3.0</title>
<updated>2023-10-19T18:35:12+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-10-19T18:35:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=01c43784ec53aa1ff22aca7e7ae6f18b4591b514'/>
<id>01c43784ec53aa1ff22aca7e7ae6f18b4591b514</id>
<content type='text'>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust/rusty: Add wrappers for new functions</title>
<updated>2023-09-25T16:39:51+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-09-22T20:17:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=f8927bd16a5fa996d23eebfed8762c1b0dc0244c'/>
<id>f8927bd16a5fa996d23eebfed8762c1b0dc0244c</id>
<content type='text'>
libunit-wasm added two new functions, luw_req_buf_copy() &amp;
luw_mem_splice_file(). See the previous two commits...

This second function takes a file-descriptor as one of its arguments, in
rusty we make this a Rust File object, then pass the underlying fd into
libunit-wasm.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
libunit-wasm added two new functions, luw_req_buf_copy() &amp;
luw_mem_splice_file(). See the previous two commits...

This second function takes a file-descriptor as one of its arguments, in
rusty we make this a Rust File object, then pass the underlying fd into
libunit-wasm.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>libunit-wasm: Allow uploads larger than 4GiB</title>
<updated>2023-09-25T16:36:23+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-09-14T20:43:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=ee64ca584081b812d9254ec116e1a060483071ec'/>
<id>ee64ca584081b812d9254ec116e1a060483071ec</id>
<content type='text'>
Currently Wasm modules are limited to a 32bit address space (until at
least the memory64 work is completed). All the counters etc in the
request structure were u32's. Which matched with the 32bit memory
limitation.

However there is really no need to not allow &gt;4GiB uploads that can be
saved off to disk or some such.

To do this we need to increase the -&gt;content_len &amp; -&gt;total_content_sent
members to u64's and also adjust the return types of
(luw,uwr}_get_http_content_len() and
{luw,uwr}_get_http_total_content_sent() similarly.

However because we need the request structure to have the exact same
layout on 32bit (for Wasm modules) as it does on 64bit we need to re-jig
the order of some of these members and add a four-byte padding member.

Thus the request structure now looks like on 32bit (as shown by
pahole(1))

  struct luw_req {
          u32                        method_off;           /*     0     4 */
          u32                        method_len;           /*     4     4 */
          u32                        version_off;          /*     8     4 */
          u32                        version_len;          /*    12     4 */
          u32                        path_off;             /*    16     4 */
          u32                        path_len;             /*    20     4 */
          u32                        query_off;            /*    24     4 */
          u32                        query_len;            /*    28     4 */
          u32                        remote_off;           /*    32     4 */
          u32                        remote_len;           /*    36     4 */
          u32                        local_addr_off;       /*    40     4 */
          u32                        local_addr_len;       /*    44     4 */
          u32                        local_port_off;       /*    48     4 */
          u32                        local_port_len;       /*    52     4 */
          u32                        server_name_off;      /*    56     4 */
          u32                        server_name_len;      /*    60     4 */
          /* --- cacheline 1 boundary (64 bytes) --- */
          u64                        content_len;          /*    64     8 */
          u64                        total_content_sent;   /*    72     8 */
          u32                        content_sent;         /*    80     4 */
          u32                        content_off;          /*    84     4 */
          u32                        request_size;         /*    88     4 */
          u32                        nr_fields;            /*    92     4 */
          u32                        tls;                  /*    96     4 */
          char                       __pad[4];             /*   100     4 */
          struct luw_hdr_field       fields[];             /*   104     0 */

          /* size: 104, cachelines: 2, members: 25 */
          /* last cacheline: 40 bytes */
  };

and the same structure (taken from Unit) compiled as 64bit

  struct nxt_wasm_request_s {
          uint32_t                   method_off;           /*     0     4 */
          uint32_t                   method_len;           /*     4     4 */
          uint32_t                   version_off;          /*     8     4 */
          uint32_t                   version_len;          /*    12     4 */
          uint32_t                   path_off;             /*    16     4 */
          uint32_t                   path_len;             /*    20     4 */
          uint32_t                   query_off;            /*    24     4 */
          uint32_t                   query_len;            /*    28     4 */
          uint32_t                   remote_off;           /*    32     4 */
          uint32_t                   remote_len;           /*    36     4 */
          uint32_t                   local_addr_off;       /*    40     4 */
          uint32_t                   local_addr_len;       /*    44     4 */
          uint32_t                   local_port_off;       /*    48     4 */
          uint32_t                   local_port_len;       /*    52     4 */
          uint32_t                   server_name_off;      /*    56     4 */
          uint32_t                   server_name_len;      /*    60     4 */
          /* --- cacheline 1 boundary (64 bytes) --- */
          uint64_t                   content_len;          /*    64     8 */
          uint64_t                   total_content_sent;   /*    72     8 */
          uint32_t                   content_sent;         /*    80     4 */
          uint32_t                   content_off;          /*    84     4 */
          uint32_t                   request_size;         /*    88     4 */
          uint32_t                   nfields;              /*    92     4 */
          uint32_t                   tls;                  /*    96     4 */
          char                       __pad[4];             /*   100     4 */
          nxt_wasm_http_field_t      fields[];             /*   104     0 */

          /* size: 104, cachelines: 2, members: 25 */
          /* last cacheline: 40 bytes */
  };

We can see the structures have the same layout, same size and no
padding.

We need the __pad member as otherwise I saw gcc and clang on Alpine
Linux automatically add the 'packed' attribute to the structure which
made the two structures not match.

Link: &lt;https://github.com/WebAssembly/memory64&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently Wasm modules are limited to a 32bit address space (until at
least the memory64 work is completed). All the counters etc in the
request structure were u32's. Which matched with the 32bit memory
limitation.

However there is really no need to not allow &gt;4GiB uploads that can be
saved off to disk or some such.

To do this we need to increase the -&gt;content_len &amp; -&gt;total_content_sent
members to u64's and also adjust the return types of
(luw,uwr}_get_http_content_len() and
{luw,uwr}_get_http_total_content_sent() similarly.

However because we need the request structure to have the exact same
layout on 32bit (for Wasm modules) as it does on 64bit we need to re-jig
the order of some of these members and add a four-byte padding member.

Thus the request structure now looks like on 32bit (as shown by
pahole(1))

  struct luw_req {
          u32                        method_off;           /*     0     4 */
          u32                        method_len;           /*     4     4 */
          u32                        version_off;          /*     8     4 */
          u32                        version_len;          /*    12     4 */
          u32                        path_off;             /*    16     4 */
          u32                        path_len;             /*    20     4 */
          u32                        query_off;            /*    24     4 */
          u32                        query_len;            /*    28     4 */
          u32                        remote_off;           /*    32     4 */
          u32                        remote_len;           /*    36     4 */
          u32                        local_addr_off;       /*    40     4 */
          u32                        local_addr_len;       /*    44     4 */
          u32                        local_port_off;       /*    48     4 */
          u32                        local_port_len;       /*    52     4 */
          u32                        server_name_off;      /*    56     4 */
          u32                        server_name_len;      /*    60     4 */
          /* --- cacheline 1 boundary (64 bytes) --- */
          u64                        content_len;          /*    64     8 */
          u64                        total_content_sent;   /*    72     8 */
          u32                        content_sent;         /*    80     4 */
          u32                        content_off;          /*    84     4 */
          u32                        request_size;         /*    88     4 */
          u32                        nr_fields;            /*    92     4 */
          u32                        tls;                  /*    96     4 */
          char                       __pad[4];             /*   100     4 */
          struct luw_hdr_field       fields[];             /*   104     0 */

          /* size: 104, cachelines: 2, members: 25 */
          /* last cacheline: 40 bytes */
  };

and the same structure (taken from Unit) compiled as 64bit

  struct nxt_wasm_request_s {
          uint32_t                   method_off;           /*     0     4 */
          uint32_t                   method_len;           /*     4     4 */
          uint32_t                   version_off;          /*     8     4 */
          uint32_t                   version_len;          /*    12     4 */
          uint32_t                   path_off;             /*    16     4 */
          uint32_t                   path_len;             /*    20     4 */
          uint32_t                   query_off;            /*    24     4 */
          uint32_t                   query_len;            /*    28     4 */
          uint32_t                   remote_off;           /*    32     4 */
          uint32_t                   remote_len;           /*    36     4 */
          uint32_t                   local_addr_off;       /*    40     4 */
          uint32_t                   local_addr_len;       /*    44     4 */
          uint32_t                   local_port_off;       /*    48     4 */
          uint32_t                   local_port_len;       /*    52     4 */
          uint32_t                   server_name_off;      /*    56     4 */
          uint32_t                   server_name_len;      /*    60     4 */
          /* --- cacheline 1 boundary (64 bytes) --- */
          uint64_t                   content_len;          /*    64     8 */
          uint64_t                   total_content_sent;   /*    72     8 */
          uint32_t                   content_sent;         /*    80     4 */
          uint32_t                   content_off;          /*    84     4 */
          uint32_t                   request_size;         /*    88     4 */
          uint32_t                   nfields;              /*    92     4 */
          uint32_t                   tls;                  /*    96     4 */
          char                       __pad[4];             /*   100     4 */
          nxt_wasm_http_field_t      fields[];             /*   104     0 */

          /* size: 104, cachelines: 2, members: 25 */
          /* last cacheline: 40 bytes */
  };

We can see the structures have the same layout, same size and no
padding.

We need the __pad member as otherwise I saw gcc and clang on Alpine
Linux automatically add the 'packed' attribute to the structure which
made the two structures not match.

Link: &lt;https://github.com/WebAssembly/memory64&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust/rusty: Add a wrapper for the new luw_http_set_response_status()</title>
<updated>2023-09-12T16:21:11+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-09-09T01:04:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=43b84013e5383d0b2f915c6fbf8c71acc281c1ad'/>
<id>43b84013e5383d0b2f915c6fbf8c71acc281c1ad</id>
<content type='text'>
The new uwr_http_set_response_status() function allows to set the HTTP
response status in Rust WebAssembly modules. It takes one of the
luw_http_status_t response status values.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The new uwr_http_set_response_status() function allows to set the HTTP
response status in Rust WebAssembly modules. It takes one of the
luw_http_status_t response status values.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>rust: Change how bindgen creates enums</title>
<updated>2023-09-05T19:35:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-09-05T19:24:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=76f8f41487e361c00099a729dee2e293a4b713a5'/>
<id>76f8f41487e361c00099a729dee2e293a4b713a5</id>
<content type='text'>
Previously bindgen was picking the 'constified_enum'. E.g it would turn
the luw_srb_flags_t enum

  typedef enum {
          LUW_SRB_NONE = 0x00,
          LUW_SRB_APPEND = 0x01,
          LUW_SRB_ALLOC = 0x02,
          LUW_SRB_FULL_SIZE = 0x04,

          LUW_SRB_FLAGS_ALL = (LUW_SRB_NONE|LUW_SRB_APPEND|LUW_SRB_ALLOC|
                               LUW_SRB_FULL_SIZE)
  } luw_srb_flags_t;

into

  pub const luw_srb_flags_t_LUW_SRB_NONE: luw_srb_flags_t = 0;
  pub const luw_srb_flags_t_LUW_SRB_APPEND: luw_srb_flags_t = 1;
  pub const luw_srb_flags_t_LUW_SRB_ALLOC: luw_srb_flags_t = 2;
  pub const luw_srb_flags_t_LUW_SRB_FULL_SIZE: luw_srb_flags_t = 4;
  pub const luw_srb_flags_t_LUW_SRB_FLAGS_ALL: luw_srb_flags_t = 7;

But then this requires some further changes to make the names nicer
without the type prefixed.

This will only be exasperated when adding an enum containing the HTTP
status codes...

So instead, tell bindgen to use the 'rustified_enum' method which
produces this

  pub enum luw_srb_flags_t {
      LUW_SRB_NONE = 0,
      LUW_SRB_APPEND = 1,
      LUW_SRB_ALLOC = 2,
      LUW_SRB_FULL_SIZE = 4,
      LUW_SRB_FLAGS_ALL = 7,
  }

which in theory requires no extra changes (it doesn't with the http
status codes enum), however in this specific case, because these are
actually bitflags we still need to cast them to u32 so they can be OR'd.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously bindgen was picking the 'constified_enum'. E.g it would turn
the luw_srb_flags_t enum

  typedef enum {
          LUW_SRB_NONE = 0x00,
          LUW_SRB_APPEND = 0x01,
          LUW_SRB_ALLOC = 0x02,
          LUW_SRB_FULL_SIZE = 0x04,

          LUW_SRB_FLAGS_ALL = (LUW_SRB_NONE|LUW_SRB_APPEND|LUW_SRB_ALLOC|
                               LUW_SRB_FULL_SIZE)
  } luw_srb_flags_t;

into

  pub const luw_srb_flags_t_LUW_SRB_NONE: luw_srb_flags_t = 0;
  pub const luw_srb_flags_t_LUW_SRB_APPEND: luw_srb_flags_t = 1;
  pub const luw_srb_flags_t_LUW_SRB_ALLOC: luw_srb_flags_t = 2;
  pub const luw_srb_flags_t_LUW_SRB_FULL_SIZE: luw_srb_flags_t = 4;
  pub const luw_srb_flags_t_LUW_SRB_FLAGS_ALL: luw_srb_flags_t = 7;

But then this requires some further changes to make the names nicer
without the type prefixed.

This will only be exasperated when adding an enum containing the HTTP
status codes...

So instead, tell bindgen to use the 'rustified_enum' method which
produces this

  pub enum luw_srb_flags_t {
      LUW_SRB_NONE = 0,
      LUW_SRB_APPEND = 1,
      LUW_SRB_ALLOC = 2,
      LUW_SRB_FULL_SIZE = 4,
      LUW_SRB_FLAGS_ALL = 7,
  }

which in theory requires no extra changes (it doesn't with the http
status codes enum), however in this specific case, because these are
actually bitflags we still need to cast them to u32 so they can be OR'd.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>unit-wasm 0.2.0</title>
<updated>2023-08-30T13:56:03+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-08-30T13:56:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=d81bc9290edc8d1eb59ced024499359ccd4da77a'/>
<id>d81bc9290edc8d1eb59ced024499359ccd4da77a</id>
<content type='text'>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Rust/rusty: Make use of uwr_get_http_total_content_sent()</title>
<updated>2023-08-29T22:41:11+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-08-29T22:31:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=04197e036a01d3826e0529f1396924a868bb4dd2'/>
<id>04197e036a01d3826e0529f1396924a868bb4dd2</id>
<content type='text'>
When the uwr_get_http_content_str() function, which returns the request
body content as a string, was added it used uwr_get_http_content_len()
to determine the length of the returned string (the request body content
is not null-terminated).

This could potentially in some circumstances return too much data if the
request was split over multiple calls into the Wasm module and
uwr_get_http_content_str() was called before all the data had actually
been received.

Instead use the newly introduced uwr_get_http_total_content_sent()
function to determine the amount of data to return in the string as it
currently stands.

Fixes: bf968c9 ("Rust/rusty: Add uwr_get_http_content_str()")
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When the uwr_get_http_content_str() function, which returns the request
body content as a string, was added it used uwr_get_http_content_len()
to determine the length of the returned string (the request body content
is not null-terminated).

This could potentially in some circumstances return too much data if the
request was split over multiple calls into the Wasm module and
uwr_get_http_content_str() was called before all the data had actually
been received.

Instead use the newly introduced uwr_get_http_total_content_sent()
function to determine the amount of data to return in the string as it
currently stands.

Fixes: bf968c9 ("Rust/rusty: Add uwr_get_http_content_str()")
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Rust/rusty: Add a wrapper for luw_get_http_total_content_sent()</title>
<updated>2023-08-29T22:30:21+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-08-29T22:30:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit-wasm.git/commit/?id=5dc0cf051059ac83899b55f4a55df363faea4419'/>
<id>5dc0cf051059ac83899b55f4a55df363faea4419</id>
<content type='text'>
This returns the total amount of content that the Wasm module has
received so far.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This returns the total amount of content that the Wasm module has
received so far.

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
