Skip to content

Commit c834e3b

Browse files
committed
Add function attributes to memcpy, malloc, and friends.
1 parent ca4986a commit c834e3b

13 files changed

Lines changed: 122 additions & 65 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef __wasm___functions_malloc_h
2+
#define __wasm___functions_malloc_h
3+
4+
#define __need_size_t
5+
#define __need_wchar_t
6+
#define __need_NULL
7+
#include <stddef.h>
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
void *malloc(size_t size) __attribute__((__malloc__, __warn_unused_result__));
14+
void free(void *ptr);
15+
void *calloc(size_t nmemb, size_t size) __attribute__((__malloc__, __warn_unused_result__));
16+
void *realloc(void *ptr, size_t size) __attribute__((__warn_unused_result__));
17+
18+
#ifdef __cplusplus
19+
}
20+
#endif
21+
22+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef __wasm___functions_memcpy_h
2+
#define __wasm___functions_memcpy_h
3+
4+
#define __need_size_t
5+
#define __need_NULL
6+
#include <stddef.h>
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
void *memcpy(void *__restrict__ dst, const void *__restrict__ src, size_t n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2)));
13+
void *memmove(void *dst, const void *src, size_t n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2)));
14+
void *memset(void *dst, int c, size_t n) __attribute__((__nothrow__, __leaf__, __nonnull__(1)));
15+
16+
#ifdef __cplusplus
17+
}
18+
#endif
19+
20+
#endif

basics/include/stdlib.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
#ifndef __wasm_basics_stdlib_h
2-
#define __wasm_basics_stdlib_h
3-
4-
#define __need_size_t
5-
#define __need_wchar_t
6-
#define __need_NULL
7-
#include <stddef.h>
8-
9-
#ifdef __cplusplus
10-
extern "C" {
11-
#endif
12-
13-
void *malloc(size_t size);
14-
void free(void *ptr);
15-
void *calloc(size_t nmemb, size_t size);
16-
void *realloc(void *ptr, size_t size);
17-
18-
#ifdef __cplusplus
19-
}
20-
#endif
1+
#ifndef __wasm_stdlib_h
2+
#define __wasm_stdlib_h
3+
4+
/*
5+
* Include the real implementation, which is factored into a separate file so
6+
* that it can be reused by other libc stdlib implementations.
7+
*/
8+
#include <__functions_malloc.h>
219

2210
#endif

basics/include/string.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
#ifndef __wasm_basics_string_h
2-
#define __wasm_basics_string_h
3-
4-
#define __need_size_t
5-
#define __need_NULL
6-
#include <stddef.h>
7-
8-
#ifdef __cplusplus
9-
extern "C" {
10-
#endif
11-
12-
void *memcpy(void *dst, const void *src, size_t n);
13-
void *memmove(void *dst, const void *src, size_t n);
14-
void *memset(void *dst, int c, size_t n);
15-
16-
#ifdef __cplusplus
17-
}
18-
#endif
1+
#ifndef __wasm_string_h
2+
#define __wasm_string_h
3+
4+
/*
5+
* Include the real implementation, which is factored into a separate file so
6+
* that it can be reused by other libc string implementations.
7+
*/
8+
#include <__functions_memcpy.h>
199

2010
#endif

dlmalloc/include/unistd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#define _SC_PAGESIZE
88

99
/* Declare sbrk. */
10-
void *sbrk(intptr_t increment);
10+
void *sbrk(intptr_t increment) __attribute__((__warn_unused_result__));

expected/wasm32-wasi/include-all.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
#include <__errno_values.h>
33
#include <__fd_set.h>
44
#include <__function___isatty.h>
5+
#include <__functions_malloc.h>
6+
#include <__functions_memcpy.h>
57
#include <__header_bits_signal.h>
68
#include <__header_dirent.h>
79
#include <__header_fcntl.h>
810
#include <__header_netinet_in.h>
911
#include <__header_poll.h>
12+
#include <__header_stdlib.h>
13+
#include <__header_string.h>
1014
#include <__header_sys_ioctl.h>
1115
#include <__header_sys_resource.h>
1216
#include <__header_sys_socket.h>

expected/wasm32-wasi/predefined-macros.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,6 +3639,8 @@
36393639
#define __wasilibc___header_sys_stat_h
36403640
#define __wasilibc___header_time_h
36413641
#define __wasilibc___header_unistd_h
3642+
#define __wasilibc___headers_stdlib_h
3643+
#define __wasilibc___headers_string_h
36423644
#define __wasilibc___macro_FD_SETSIZE_h
36433645
#define __wasilibc___struct_dirent_h
36443646
#define __wasilibc___struct_in6_addr_h
@@ -3669,6 +3671,8 @@
36693671
#define __wasm32 1
36703672
#define __wasm32__ 1
36713673
#define __wasm__ 1
3674+
#define __wasm___functions_malloc_h
3675+
#define __wasm___functions_memcpy_h
36723676
#define __wasm_basics___errno_h
36733677
#define __wasm_basics___macro_PAGESIZE_h
36743678
#define __wasm_basics___struct_stat_h
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef __wasilibc___headers_stdlib_h
2+
#define __wasilibc___headers_stdlib_h
3+
4+
#define __need_size_t
5+
#include <stddef.h>
6+
7+
#include <__functions_malloc.h>
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
void abort(void) __attribute__((__noreturn__));
14+
void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
15+
16+
#ifdef __cplusplus
17+
}
18+
#endif
19+
20+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef __wasilibc___headers_string_h
2+
#define __wasilibc___headers_string_h
3+
4+
#define __need_size_t
5+
#define __need_NULL
6+
#include <stddef.h>
7+
8+
#include <__functions_memcpy.h>
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1)));
15+
char *strdup(const char *) __attribute__((__nothrow__, __nonnull__(1)));
16+
int strcmp(const char *, const char *) __attribute__((__nothrow__, __pure__, __nonnull__(1, 2)));
17+
void *memchr(const void *, int, size_t) __attribute__((__nothrow__, __pure__, __nonnull__(1)));
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif
22+
23+
#endif
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#ifndef __wasilibc_stdlib_h
22
#define __wasilibc_stdlib_h
33

4-
#define __need_size_t
5-
#include <stddef.h>
6-
7-
void abort(void) __attribute__ ((__noreturn__));
8-
void qsort(void *, size_t, size_t,
9-
int (*)(const void *, const void *));
4+
/*
5+
* Include the real implementation, which is factored into a separate file so
6+
* that it can be reused by other libc stdlib implementations.
7+
*/
8+
#include <__headers_stdlib.h>
109

1110
#endif

0 commit comments

Comments
 (0)