From a78155400fb10b94dc7e804535044205c1fb6b5d Mon Sep 17 00:00:00 2001 From: leitner Date: Fri, 22 Nov 2024 19:22:42 +0000 Subject: [PATCH] update function attributes --- byte.h | 29 +++++++++-------------------- io.h | 25 +++++++++++++++---------- str.h | 14 +++++++------- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/byte.h b/byte.h index c1e84e5..013ea00 100644 --- a/byte.h +++ b/byte.h @@ -15,25 +15,22 @@ extern "C" { /* byte_chr returns the smallest integer i between 0 and len-1 * inclusive such that one[i] equals needle, or len if not found. */ -att_readn(1,2) +att_pure __bufin(1,2) size_t byte_chr(const void* haystack, size_t len, char needle) noexcept; /* byte_rchr returns the largest integer i between 0 and len-1 inclusive * such that one[i] equals needle, or len if not found. */ -att_pure -att_readn(1,2) +att_pure __bufin(1,2) size_t byte_rchr(const void* haystack,size_t len,char needle) noexcept; /* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1] * to out[len-1]. */ -att_writen(1,2) -att_readn(3,2) +__bufout(1,2) __bufin(3,2) void byte_copy(void* out, size_t len, const void* in) noexcept; /* byte_copyr copies in[len-1] to out[len-1], in[len-2] to out[len-2], * ... and in[0] to out[0] */ -att_writen(1,2) -att_readn(3,2) +__bufout(1,2) __bufin(3,2) void byte_copyr(void* out, size_t len, const void* in) noexcept; /* byte_diff returns negative, 0, or positive, depending on whether the @@ -41,28 +38,22 @@ void byte_copyr(void* out, size_t len, const void* in) noexcept; * than, equal to, or greater than the string b[0], b[1], ..., * b[len-1]. When the strings are different, byte_diff does not read * bytes past the first difference. */ -att_pure -att_readn(1,2) -att_readn(3,2) +att_pure __bufin(1,2) __bufin(3,2) int byte_diff(const void* a, size_t len, const void* b) noexcept; /* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */ -att_writen(1,2) +__bufout(1,2) void byte_zero(void* out, size_t len) noexcept; #define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) /* Return 1 iff (b,blen) is a prefix of (a,alen), 0 otherwise. * Will abort early on mismatch */ -att_pure -att_readn(1,2) -att_readn(3,4) +att_pure __bufin(1,2) __bufin(3,4) int byte_start(const void* a,size_t alen,const void* b,size_t blen) noexcept; /* equivalent to byte_start(a,alen,str,strlen(str)) */ -att_pure -att_readn(1,2) -att_read(3) +att_pure __bufin(1,2) __strin(3) int byte_starts(const void* a,size_t alen,const char* str) noexcept; #if defined(__GNUC__) && !defined(__LIBOWFAT_INTERNAL) @@ -70,9 +61,7 @@ int byte_starts(const void* a,size_t alen,const char* str) noexcept; #define byte_starts(a,alen,str) (__builtin_constant_p(str) ? byte_start(a,alen,str,strlen(str)) : byte_starts(a,alen,str)) #endif -att_pure -att_readn(1,2) -att_readn(3,2) +att_pure __bufin(1,2) __bufin(3,2) int byte_equal_notimingattack(const void* a, size_t len,const void* b) noexcept; #if defined(__i386__) || defined(__x86_64__) diff --git a/io.h b/io.h index 1f76724..9a1d94a 100644 --- a/io.h +++ b/io.h @@ -19,28 +19,28 @@ extern "C" { /* like open(s,O_RDONLY) */ /* return 1 if ok, 0 on error */ /* sandboxing: open(2) (glibc: openat(2)) */ -att_read(2) +__strin(2) att_write(1) int io_readfile(int64* d,const char* filename); /* like open(s,O_WRONLY|O_CREAT|O_TRUNC,0600) */ /* return 1 if ok, 0 on error */ /* sandboxing: open(2) (glibc: openat(2)) */ -att_read(2) +__strin(2) att_write(1) int io_createfile(int64* d,const char* filename); /* like open(s,O_RDWR) */ /* return 1 if ok, 0 on error */ /* sandboxing: open(2) (glibc: openat(2)) */ -att_read(2) +__strin(2) att_write(1) int io_readwritefile(int64* d,const char* filename); /* like open(s,O_WRONLY|O_APPEND|O_CREAT,0600) */ /* return 1 if ok, 0 on error */ /* sandboxing: open(2) (glibc: openat(2)) */ -att_read(2) +__strin(2) att_write(1) int io_appendfile(int64* d,const char* filename); @@ -58,22 +58,22 @@ int io_socketpair(int64* d); /* non-blocking read(), -1 for EAGAIN and -3+errno for other errors */ /* sandboxing: poll(2), setitimer(2), read(2) */ -att_writen(2, 3) +__bufout(2, 3) int64 io_tryread(int64 d,char* buf,int64 len); /* blocking read(), with -3 instead of -1 for errors */ /* sandboxing: poll(2), read(2) */ -att_writen(2, 3) +__bufout(2, 3) int64 io_waitread(int64 d,char* buf,int64 len); /* non-blocking write(), -1 for EAGAIN and -3+errno for other errors */ /* sandboxing: poll(2), setitimer(2), write(2) */ -att_readn(2, 3) +__bufin(2, 3) int64 io_trywrite(int64 d,const char* buf,int64 len); /* blocking write(), with -3 instead of -1 for errors */ /* sandboxing: poll(2), write(2) */ -att_readn(2, 3) +__bufin(2, 3) int64 io_waitwrite(int64 d,const char* buf,int64 len); /* modify timeout attribute of file descriptor */ @@ -83,13 +83,13 @@ void io_timeout(int64 d,tai6464 t); /* like io_tryread but will return -2,errno=ETIMEDOUT if d has a timeout * associated and it is passed without input being there */ /* sandboxing: poll(2), setitimer(2), gettimeofday(2), read(2) */ -att_writen(2, 3) +__bufout(2, 3) int64 io_tryreadtimeout(int64 d,char* buf,int64 len); /* like io_trywrite but will return -2,errno=ETIMEDOUT if d has a timeout * associated and it is passed without being able to write */ /* sandboxing: poll(2), setitimer(2), gettimeofday(2), write(2) */ -att_readn(2, 3) +__bufin(2, 3) int64 io_trywritetimeout(int64 d,const char* buf,int64 len); /* sandboxing: linux: epoll_ctl(2), bsd: kevent(2), solaris: write(2), oldlinux: poll(2) */ @@ -244,6 +244,7 @@ typedef struct iomux { /* Init master context */ +att_nonnull(1) att_write(1) int iom_init(iomux_t* c); /* Add socket to iomux */ @@ -254,19 +255,23 @@ enum { }; /* signal interest in events from a socket */ /* return -1 if error, events can be IOM_READ or IOM_WRITE */ +att_nonnull(1) att_mangle(1) int iom_add(iomux_t* c,int64 s,unsigned int events); /* signal interest in more events from a socket */ +att_nonnull(1) att_mangle(1) int iom_requeue(iomux_t* c,int64 s,unsigned int events); /* Blocking wait for single event, timeout in milliseconds */ /* return -1 if error, 0 if ok; s set to fd, revents set to known events on that fd */ /* when done with the fd, call iom_requeue on it to receive more events! */ /* This can be called by multiple threads in parallel */ +att_write(2) att_write(3) att_mangle(1) att_nonnull(1) att_nonnull(2) att_nonnull(3) int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout); /* Call this to terminate all threads waiting in iom_wait */ /* Returns 0 on success, -1 on failure */ +att_nonnull(1) int iom_abort(iomux_t* c); #ifdef __cplusplus diff --git a/str.h b/str.h index 71d728a..022caf9 100644 --- a/str.h +++ b/str.h @@ -12,7 +12,7 @@ extern "C" { /* str_copy copies leading bytes from in to out until \0. * return number of copied bytes. */ -att_write(1) att_read(2) +__strout(1) __strin(2) size_t str_copy(char *out,const char *in) noexcept; /* str_diff returns negative, 0, or positive, depending on whether the @@ -20,7 +20,7 @@ size_t str_copy(char *out,const char *in) noexcept; * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'. * If the strings are different, str_diff does not read bytes past the * first difference. */ -att_pure att_read(1) att_read(2) +att_pure __strin(1) __strin(2) int str_diff(const char *a,const char *b) noexcept; /* str_diffn returns negative, 0, or positive, depending on whether the @@ -29,7 +29,7 @@ int str_diff(const char *a,const char *b) noexcept; * If the strings are different, str_diffn does not read bytes past the * first difference. The strings will be considered equal if the first * limit characters match. */ -att_pure att_read(1) att_read(2) +att_pure __strnin(1,3) __strnin(2,3) int str_diffn(const char *a,const char *b,size_t limit) noexcept; #ifdef __dietlibc__ @@ -37,20 +37,20 @@ int str_diffn(const char *a,const char *b,size_t limit) noexcept; #define str_len(foo) strlen(foo) #else /* str_len returns the index of \0 in s */ -att_pure att_read(1) +att_pure __strin(1) size_t str_len(const char *s) noexcept; #endif /* str_chr returns the index of the first occurance of needle or \0 in haystack */ -att_pure att_read(1) +att_pure __strin(1) size_t str_chr(const char *haystack,char needle) noexcept; /* str_rchr returns the index of the last occurance of needle or \0 in haystack */ -att_pure att_read(1) +att_pure __strin(1) size_t str_rchr(const char *haystack,char needle) noexcept; /* str_start returns 1 if the b is a prefix of a, 0 otherwise */ -att_pure att_read(1) att_read(2) +att_pure __strin(1) __strin(2) int str_start(const char *a,const char *b) noexcept; /* convenience shortcut to test for string equality */