summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/compiler.h25
-rw-r--r--src/include/curses.h66
-rw-r--r--src/include/gpxe/dhcp.h2
-rw-r--r--src/include/gpxe/editbox.h6
-rw-r--r--src/include/gpxe/editstring.h2
-rw-r--r--src/include/gpxe/iobuf.h2
-rw-r--r--src/include/gpxe/malloc.h4
-rw-r--r--src/include/gpxe/settings_ui.h2
-rw-r--r--src/include/readline/readline.h2
-rw-r--r--src/include/stdlib.h6
-rw-r--r--src/include/string.h54
11 files changed, 101 insertions, 70 deletions
diff --git a/src/include/compiler.h b/src/include/compiler.h
index 2151fc6ac..a195e5368 100644
--- a/src/include/compiler.h
+++ b/src/include/compiler.h
@@ -280,6 +280,31 @@ extern void dbg_hex_dump_da ( unsigned long dispaddr,
#define __cdecl __attribute__ (( cdecl , regparm(0) ))
/**
+ * Declare a function as pure - i.e. without side effects
+ */
+#define __pure __attribute__ (( pure ))
+
+/**
+ * Declare a function as const - i.e. it does not access global memory
+ * (including dereferencing pointers passed to it) at all.
+ * Must also not call any non-const functions.
+ */
+#define __const __attribute__ (( const ))
+
+/**
+ * Declare a function's pointer parameters as non-null - i.e. force
+ * compiler to check pointers at compile time and enable possible
+ * optimizations based on that fact
+ */
+#define __nonnull __attribute__ (( nonnull ))
+
+/**
+ * Declare a pointer returned by a function as a unique memory address
+ * as returned by malloc-type functions.
+ */
+#define __malloc __attribute__ (( malloc ))
+
+/**
* Declare a function as used.
*
* Necessary only if the function is called only from assembler code.
diff --git a/src/include/curses.h b/src/include/curses.h
index 762a63b5a..6b1c42d87 100644
--- a/src/include/curses.h
+++ b/src/include/curses.h
@@ -213,13 +213,13 @@ extern int beep ( void );
//extern void bkgdset ( chtype );
/*extern int border ( chtype, chtype, chtype, chtype, chtype, chtype, chtype,
chtype );*/
-extern int box ( WINDOW *, chtype, chtype );
+extern int box ( WINDOW *, chtype, chtype ) __nonnull;
//extern bool can_change_colour ( void );
#define can_change_color() can_change_colour()
extern int cbreak ( void );
//extern int clrtobot ( void );
//extern int clrtoeol ( void );
-extern int colour_content ( short, short *, short *, short * );
+extern int colour_content ( short, short *, short *, short * ) __nonnull;
#define color_content( c, r, g, b ) colour_content( (c), (r), (g), (b) )
//extern int colour_set ( short, void * );
#define color_set( cpno, opts ) colour_set( (cpno), (opts) )
@@ -232,10 +232,10 @@ extern int delay_output ( int );
//extern int delch ( void );
//extern int deleteln ( void );
extern void delscreen ( SCREEN * );
-extern int delwin ( WINDOW * );
-extern WINDOW *derwin ( WINDOW *, int, int, int, int );
+extern int delwin ( WINDOW * ) __nonnull;
+extern WINDOW *derwin ( WINDOW *, int, int, int, int ) __nonnull;
//extern int doupdate ( void );
-extern WINDOW *dupwin ( WINDOW * );
+extern WINDOW *dupwin ( WINDOW * ) __nonnull;
extern int echo ( void );
extern int echochar ( const chtype );
extern int endwin ( void );
@@ -244,7 +244,7 @@ extern char erasechar ( void );
extern void filter ( void );
extern int flash ( void );
extern int flushinp ( void );
-extern chtype getbkgd ( WINDOW * );
+extern __pure chtype getbkgd ( WINDOW * ) __nonnull;
//extern int getch ( void );
//extern int getnstr ( char *, int );
//extern int getstr ( char * );
@@ -312,7 +312,7 @@ extern int mvderwin ( WINDOW *, int, int );
//extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
//extern int mvwgetstr ( WINDOW *, int, int, char * );
//extern int mvwhline ( WINDOW *, int, int, chtype, int );
-extern int mvwin ( WINDOW *, int, int );
+extern int mvwin ( WINDOW *, int, int ) __nonnull;
//extern chtype mvwinch ( WINDOW *, int, int );
//extern int mvwinchnstr ( WINDOW *, int, int, chtype *, int );
//extern int mvwinchstr ( WINDOW *, int, int, chtype * );
@@ -337,7 +337,7 @@ extern int noraw ( void );
extern int notimeout ( WINDOW *, bool );
extern int overlay ( const WINDOW *, WINDOW * );
extern int overwrite ( const WINDOW *, WINDOW * );
-extern int pair_content ( short, short *, short * );
+extern int pair_content ( short, short *, short * ) __nonnull;
//extern int pechochar ( WINDOW *, chtype );
//extern int pnoutrefresh ( WINDOW *, int, int, int, int, int, int );
//extern int prefresh ( WINDOW *, int, int, int, int, int, int );
@@ -373,14 +373,14 @@ extern char *slk_label ( int );
extern int slk_noutrefresh ( void );
//extern int slk_refresh ( void );
extern int slk_restore ( void );
-extern int slk_set ( int, const char *, int );
+extern int slk_set ( int, const char *, int ) __nonnull;
extern int slk_touch ( void );
extern int standend ( void );
extern int standout ( void );
//extern int start_colour ( void );
#define start_color() start_colour()
//extern WINDOW *subpad ( WINDOW *, int, int, int, int );
-extern WINDOW *subwin ( WINDOW *, int, int, int, int );
+extern WINDOW *subwin ( WINDOW *, int, int, int, int ) __nonnull;
extern int syncok ( WINDOW *, bool );
extern chtype termattrs ( void );
extern attr_t term_attrs ( void );
@@ -403,37 +403,41 @@ extern int vid_puts ( attr_t, short, void *, int ( *) ( int) );
extern int vidputs ( chtype, int ( *) ( int) );
//extern int vline ( chtype, int );
//extern int vwprintw ( WINDOW *, const char *, va_list );
-extern int vw_printw ( WINDOW *, const char *, va_list );
+extern int vw_printw ( WINDOW *, const char *, va_list ) __nonnull;
//extern int vwscanw ( WINDOW *, char *, va_list );
//extern int vw_scanw ( WINDOW *, char *, va_list );
-extern int waddch ( WINDOW *, const chtype );
-extern int waddchnstr ( WINDOW *, const chtype *, int );
+extern int waddch ( WINDOW *, const chtype ) __nonnull;
+extern int waddchnstr ( WINDOW *, const chtype *, int ) __nonnull;
//extern int waddchstr ( WINDOW *, const chtype * );
-extern int waddnstr ( WINDOW *, const char *, int );
+extern int waddnstr ( WINDOW *, const char *, int ) __nonnull;
//extern int waddstr ( WINDOW *, const char * );
-extern int wattroff ( WINDOW *, int );
-extern int wattron ( WINDOW *, int );
-extern int wattrset ( WINDOW *, int );
-extern int wattr_get ( WINDOW *, attr_t *, short *, void * );
-extern int wattr_off ( WINDOW *, attr_t, void * );
-extern int wattr_on ( WINDOW *, attr_t, void * );
-extern int wattr_set ( WINDOW *, attr_t, short, void * );
+extern int wattroff ( WINDOW *, int ) __nonnull;
+extern int wattron ( WINDOW *, int ) __nonnull;
+extern int wattrset ( WINDOW *, int ) __nonnull;
+extern int wattr_get ( WINDOW *, attr_t *, short *, void * )
+ __attribute__ (( nonnull (1, 2, 3)));
+extern int wattr_off ( WINDOW *, attr_t, void * )
+ __attribute__ (( nonnull (1)));
+extern int wattr_on ( WINDOW *, attr_t, void * )
+ __attribute__ (( nonnull (1)));
+extern int wattr_set ( WINDOW *, attr_t, short, void * )
+ __attribute__ (( nonnull (1)));
//extern void wbkgdset ( WINDOW *, chtype );
extern int wborder ( WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
- chtype, chtype );
-extern int wclrtobot ( WINDOW * );
-extern int wclrtoeol ( WINDOW * );
+ chtype, chtype ) __nonnull;
+extern int wclrtobot ( WINDOW * ) __nonnull;
+extern int wclrtoeol ( WINDOW * ) __nonnull;
extern void wcursyncup ( WINDOW * );
-extern int wcolour_set ( WINDOW *, short, void * );
+extern int wcolour_set ( WINDOW *, short, void * ) __nonnull;
#define wcolor_set(w,s,v) wcolour_set((w),(s),(v))
-extern int wdelch ( WINDOW * );
-extern int wdeleteln ( WINDOW * );
+extern int wdelch ( WINDOW * ) __nonnull;
+extern int wdeleteln ( WINDOW * ) __nonnull;
extern int wechochar ( WINDOW *, const chtype );
-extern int werase ( WINDOW * );
+extern int werase ( WINDOW * ) __nonnull;
extern int wgetch ( WINDOW * );
extern int wgetnstr ( WINDOW *, char *, int );
//extern int wgetstr ( WINDOW *, char * );
-extern int whline ( WINDOW *, chtype, int );
+extern int whline ( WINDOW *, chtype, int ) __nonnull;
//extern chtype winch ( WINDOW * );
//extern int winchnstr ( WINDOW *, chtype *, int );
//extern int winchstr ( WINDOW *, chtype * );
@@ -444,7 +448,7 @@ extern int whline ( WINDOW *, chtype, int );
//extern int winstr ( WINDOW *, char * );
extern int wmove ( WINDOW *, int, int );
//extern int wnoutrefresh ( WINDOW * );
-extern int wprintw ( WINDOW *, const char *, ... );
+extern int wprintw ( WINDOW *, const char *, ... ) __nonnull;
//extern int wredrawln ( WINDOW *, int, int );
//extern int wrefresh ( WINDOW * );
//extern int wscanw ( WINDOW *, char *, ... );
@@ -456,7 +460,7 @@ extern void wsyncup ( WINDOW * );
extern void wsyncdown ( WINDOW * );
extern void wtimeout ( WINDOW *, int );
//extern int wtouchln ( WINDOW *, int, int, int );
-extern int wvline ( WINDOW *, chtype, int );
+extern int wvline ( WINDOW *, chtype, int ) __nonnull;
/*
* There is frankly a ridiculous amount of redundancy within the
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h
index bbd345c8b..43bccf185 100644
--- a/src/include/gpxe/dhcp.h
+++ b/src/include/gpxe/dhcp.h
@@ -507,7 +507,7 @@ extern void register_dhcp_options ( struct dhcp_option_block *options );
extern void unregister_dhcp_options ( struct dhcp_option_block *options );
extern void init_dhcp_options ( struct dhcp_option_block *options,
void *data, size_t max_len );
-extern struct dhcp_option_block * alloc_dhcp_options ( size_t max_len );
+extern struct dhcp_option_block * __malloc alloc_dhcp_options ( size_t max_len );
extern struct dhcp_option *
set_dhcp_option ( struct dhcp_option_block *options, unsigned int tag,
const void *data, size_t len );
diff --git a/src/include/gpxe/editbox.h b/src/include/gpxe/editbox.h
index 8f2bd2c46..47b07c25d 100644
--- a/src/include/gpxe/editbox.h
+++ b/src/include/gpxe/editbox.h
@@ -28,8 +28,10 @@ struct edit_box {
extern void init_editbox ( struct edit_box *box, char *buf, size_t len,
WINDOW *win, unsigned int row, unsigned int col,
- unsigned int width );
-extern void draw_editbox ( struct edit_box *box );
+ unsigned int width )
+ __attribute__ (( nonnull (1, 2) ));
+extern void draw_editbox ( struct edit_box *box ) __nonnull;
+static inline int __pure edit_editbox ( struct edit_box *box, int key ) __nonnull;
/**
* Edit text box widget
diff --git a/src/include/gpxe/editstring.h b/src/include/gpxe/editstring.h
index 7f3c5dcb1..fad8bd5a7 100644
--- a/src/include/gpxe/editstring.h
+++ b/src/include/gpxe/editstring.h
@@ -26,6 +26,6 @@ struct edit_string {
unsigned int mod_end;
};
-extern int edit_string ( struct edit_string *string, int key );
+extern int edit_string ( struct edit_string *string, int key ) __nonnull;
#endif /* _GPXE_EDITSTRING_H */
diff --git a/src/include/gpxe/iobuf.h b/src/include/gpxe/iobuf.h
index c0dfd434d..e3db01ac2 100644
--- a/src/include/gpxe/iobuf.h
+++ b/src/include/gpxe/iobuf.h
@@ -161,7 +161,7 @@ static inline size_t iob_tailroom ( struct io_buffer *iobuf ) {
return ( iobuf->end - iobuf->tail );
}
-extern struct io_buffer * alloc_iob ( size_t len );
+extern struct io_buffer * __malloc alloc_iob ( size_t len );
extern void free_iob ( struct io_buffer *iobuf );
extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
extern int iob_ensure_headroom ( struct io_buffer *iobuf, size_t len );
diff --git a/src/include/gpxe/malloc.h b/src/include/gpxe/malloc.h
index 0e18f6a35..cce5d1d34 100644
--- a/src/include/gpxe/malloc.h
+++ b/src/include/gpxe/malloc.h
@@ -19,7 +19,7 @@
extern size_t freemem;
-extern void * alloc_memblock ( size_t size, size_t align );
+extern void * __malloc alloc_memblock ( size_t size, size_t align );
extern void free_memblock ( void *ptr, size_t size );
extern void mpopulate ( void *start, size_t len );
extern void mdumpfree ( void );
@@ -35,7 +35,7 @@ extern void mdumpfree ( void );
*
* @c align must be a power of two. @c size may not be zero.
*/
-static inline void * malloc_dma ( size_t size, size_t phys_align ) {
+static inline void * __malloc malloc_dma ( size_t size, size_t phys_align ) {
return alloc_memblock ( size, phys_align );
}
diff --git a/src/include/gpxe/settings_ui.h b/src/include/gpxe/settings_ui.h
index 01b8f1728..70ee8cb3b 100644
--- a/src/include/gpxe/settings_ui.h
+++ b/src/include/gpxe/settings_ui.h
@@ -9,6 +9,6 @@
struct config_context;
-extern int settings_ui ( struct config_context *context );
+extern int settings_ui ( struct config_context *context ) __nonnull;
#endif /* _GPXE_SETTINGS_UI_H */
diff --git a/src/include/readline/readline.h b/src/include/readline/readline.h
index 4214a44ff..1a03b4836 100644
--- a/src/include/readline/readline.h
+++ b/src/include/readline/readline.h
@@ -7,6 +7,6 @@
*
*/
-extern char * readline ( const char *prompt );
+extern char * __malloc readline ( const char *prompt );
#endif /* _READLINE_H */
diff --git a/src/include/stdlib.h b/src/include/stdlib.h
index 5c8fc3df4..ae9969622 100644
--- a/src/include/stdlib.h
+++ b/src/include/stdlib.h
@@ -20,10 +20,10 @@ extern unsigned long strtoul ( const char *p, char **endp, int base );
****************************************************************************
*/
-extern void * malloc ( size_t size );
+extern void * __malloc malloc ( size_t size );
extern void * realloc ( void *old_ptr, size_t new_size );
extern void free ( void *ptr );
-extern void * zalloc ( size_t len );
+extern void * __malloc zalloc ( size_t len );
/**
* Allocate cleared memory
@@ -38,7 +38,7 @@ extern void * zalloc ( size_t len );
* function in zalloc(), since in most cases @c nmemb will be 1 and
* doing the multiply is just wasteful.
*/
-static inline void * calloc ( size_t nmemb, size_t size ) {
+static inline void * __malloc calloc ( size_t nmemb, size_t size ) {
return zalloc ( nmemb * size );
}
diff --git a/src/include/string.h b/src/include/string.h
index 1d104c524..a2894a3a3 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -17,33 +17,33 @@
#include <stddef.h>
#include <bits/string.h>
-int strnicmp(const char *s1, const char *s2, size_t len);
-char * strcpy(char * dest,const char *src);
-char * strncpy(char * dest,const char *src,size_t count);
-char * strcat(char * dest, const char * src);
-char * strncat(char *dest, const char *src, size_t count);
-int __attribute__ (( pure )) strcmp(const char * cs,const char * ct);
-int __attribute__ (( pure )) strncmp(const char * cs,const char * ct,
- size_t count);
-char * strchr(const char * s, int c);
-char * strrchr(const char * s, int c);
-size_t strlen(const char * s);
-size_t strnlen(const char * s, size_t count);
-size_t strspn(const char *s, const char *accept);
-size_t strcspn(const char *s, const char *reject);
-char * strpbrk(const char * cs,const char * ct);
-char * strtok(char * s,const char * ct);
-char * strsep(char **s, const char *ct);
-void * memset(void * s,int c,size_t count);
-void * memmove(void * dest,const void *src,size_t count);
-int __attribute__ (( pure )) memcmp(const void * cs,const void * ct,
- size_t count);
-void * memscan(void * addr, int c, size_t size);
-char * strstr(const char * s1,const char * s2);
-void * memchr(const void *s, int c, size_t n);
-char * strdup(const char *s);
-char * strndup(const char *s, size_t n);
+int __pure strnicmp(const char *s1, const char *s2, size_t len) __nonnull;
+char * strcpy(char * dest,const char *src) __nonnull;
+char * strncpy(char * dest,const char *src,size_t count) __nonnull;
+char * strcat(char * dest, const char * src) __nonnull;
+char * strncat(char *dest, const char *src, size_t count) __nonnull;
+int __pure strcmp(const char * cs,const char * ct) __nonnull;
+int __pure strncmp(const char * cs,const char * ct,
+ size_t count) __nonnull;
+char * __pure strchr(const char * s, int c) __nonnull;
+char * __pure strrchr(const char * s, int c) __nonnull;
+size_t __pure strlen(const char * s) __nonnull;
+size_t __pure strnlen(const char * s, size_t count) __nonnull;
+size_t __pure strspn(const char *s, const char *accept) __nonnull;
+size_t __pure strcspn(const char *s, const char *reject) __nonnull;
+char * __pure strpbrk(const char * cs,const char * ct) __nonnull;
+char * strtok(char * s,const char * ct) __nonnull;
+char * strsep(char **s, const char *ct) __nonnull;
+void * memset(void * s,int c,size_t count) __nonnull;
+void * memmove(void * dest,const void *src,size_t count) __nonnull;
+int __pure memcmp(const void * cs,const void * ct,
+ size_t count) __nonnull;
+void * __pure memscan(const void * addr, int c, size_t size) __nonnull;
+char * __pure strstr(const char * s1,const char * s2) __nonnull;
+void * __pure memchr(const void *s, int c, size_t n) __nonnull;
+char * __malloc strdup(const char *s) __nonnull;
+char * __malloc strndup(const char *s, size_t n) __nonnull;
-extern const char * strerror ( int errno );
+extern const char * __pure strerror ( int errno );
#endif /* ETHERBOOT_STRING */