user.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  4. */
  5. #ifndef __USER_H__
  6. #define __USER_H__
  7. #include <generated/asm-offsets.h>
  8. /*
  9. * The usual definition - copied here because the kernel provides its own,
  10. * fancier, type-safe, definition. Using that one would require
  11. * copying too much infrastructure for my taste, so userspace files
  12. * get less checking than kernel files.
  13. */
  14. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  15. /* This is to get size_t and NULL */
  16. #ifndef __UM_HOST__
  17. #include <linux/types.h>
  18. #else
  19. #include <stddef.h>
  20. #include <sys/types.h>
  21. #endif
  22. extern void panic(const char *fmt, ...)
  23. __attribute__ ((format (printf, 1, 2)));
  24. /* Requires preincluding include/linux/kern_levels.h */
  25. #define UM_KERN_EMERG KERN_EMERG
  26. #define UM_KERN_ALERT KERN_ALERT
  27. #define UM_KERN_CRIT KERN_CRIT
  28. #define UM_KERN_ERR KERN_ERR
  29. #define UM_KERN_WARNING KERN_WARNING
  30. #define UM_KERN_NOTICE KERN_NOTICE
  31. #define UM_KERN_INFO KERN_INFO
  32. #define UM_KERN_DEBUG KERN_DEBUG
  33. #define UM_KERN_CONT KERN_CONT
  34. #if IS_ENABLED(CONFIG_PRINTK)
  35. #define printk(...) _printk(__VA_ARGS__)
  36. extern int _printk(const char *fmt, ...)
  37. __attribute__ ((format (printf, 1, 2)));
  38. extern void print_hex_dump(const char *level, const char *prefix_str,
  39. int prefix_type, int rowsize, int groupsize,
  40. const void *buf, size_t len, _Bool ascii);
  41. #else
  42. static inline int printk(const char *fmt, ...)
  43. {
  44. return 0;
  45. }
  46. static inline void print_hex_dump(const char *level, const char *prefix_str,
  47. int prefix_type, int rowsize, int groupsize,
  48. const void *buf, size_t len, _Bool ascii)
  49. {
  50. }
  51. #endif
  52. extern int in_aton(char *str);
  53. extern size_t strlcat(char *, const char *, size_t);
  54. extern size_t sized_strscpy(char *, const char *, size_t);
  55. #define strscpy(dst, src) sized_strscpy(dst, src, sizeof(dst))
  56. /* Copied from linux/compiler-gcc.h since we can't include it directly */
  57. #define barrier() __asm__ __volatile__("": : :"memory")
  58. #endif