log_msg2.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2020 Nordic Semiconductor
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <zephyr.h>
  7. #include <syscall_handler.h>
  8. #include <logging/log_msg2.h>
  9. #include <logging/log_core.h>
  10. #include <logging/log_ctrl.h>
  11. void z_log_msg2_finalize(struct log_msg2 *msg, const void *source,
  12. const struct log_msg2_desc desc, const void *data)
  13. {
  14. if (!msg) {
  15. z_log_dropped();
  16. return;
  17. }
  18. if (data) {
  19. uint8_t *d = msg->data + desc.package_len;
  20. memcpy(d, data, desc.data_len);
  21. }
  22. msg->hdr.desc = desc;
  23. msg->hdr.source = source;
  24. z_log_msg2_commit(msg);
  25. }
  26. void z_impl_z_log_msg2_static_create(const void *source,
  27. const struct log_msg2_desc desc,
  28. uint8_t *package, const void *data)
  29. {
  30. uint32_t msg_wlen = log_msg2_get_total_wlen(desc);
  31. struct log_msg2 *msg = z_log_msg2_alloc(msg_wlen);
  32. if (msg) {
  33. memcpy(msg->data, package, desc.package_len);
  34. }
  35. z_log_msg2_finalize(msg, source, desc, data);
  36. }
  37. #ifdef CONFIG_USERSPACE
  38. static inline void z_vrfy_z_log_msg2_static_create(const void *source,
  39. const struct log_msg2_desc desc,
  40. uint8_t *package, const void *data)
  41. {
  42. return z_impl_z_log_msg2_static_create(source, desc, package, data);
  43. }
  44. #include <syscalls/z_log_msg2_static_create_mrsh.c>
  45. #endif
  46. void z_impl_z_log_msg2_runtime_vcreate(uint8_t domain_id, const void *source,
  47. uint8_t level, const void *data, size_t dlen,
  48. const char *fmt, va_list ap)
  49. {
  50. int plen;
  51. if (fmt) {
  52. va_list ap2;
  53. va_copy(ap2, ap);
  54. plen = cbvprintf_package(NULL, Z_LOG_MSG2_ALIGN_OFFSET, 0,
  55. fmt, ap2);
  56. __ASSERT_NO_MSG(plen >= 0);
  57. va_end(ap2);
  58. } else {
  59. plen = 0;
  60. }
  61. size_t msg_wlen = Z_LOG_MSG2_ALIGNED_WLEN(plen, dlen);
  62. struct log_msg2 *msg;
  63. struct log_msg2_desc desc =
  64. Z_LOG_MSG_DESC_INITIALIZER(domain_id, level, plen, dlen);
  65. if (IS_ENABLED(CONFIG_LOG2_MODE_IMMEDIATE)) {
  66. msg = alloca(msg_wlen * sizeof(int));
  67. } else {
  68. msg = z_log_msg2_alloc(msg_wlen);
  69. }
  70. if (msg && fmt) {
  71. plen = cbvprintf_package(msg->data, (size_t)plen, 0, fmt, ap);
  72. __ASSERT_NO_MSG(plen >= 0);
  73. }
  74. z_log_msg2_finalize(msg, source, desc, data);
  75. }
  76. #ifdef CONFIG_USERSPACE
  77. static inline void z_vrfy_z_log_msg2_runtime_vcreate(uint8_t domain_id,
  78. const void *source,
  79. uint8_t level, const void *data, size_t dlen,
  80. const char *fmt, va_list ap)
  81. {
  82. return z_impl_z_log_msg2_runtime_vcreate(domain_id, source, level, data,
  83. dlen, fmt, ap);
  84. }
  85. #include <syscalls/z_log_msg2_runtime_vcreate_mrsh.c>
  86. #endif