summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-05-10 01:16:26 -0400
committermidipix <writeonce@midipix.org>2016-05-14 07:18:24 -0400
commit25347d2a2820f20f30c8556baef36fe6e7067a79 (patch)
tree18a04c2166b2a72ea7bccce82994ab7b50628806
parent71dc38b91f0468c8f520e91ff005330352c01d25 (diff)
downloadntapi-25347d2a2820f20f30c8556baef36fe6e7067a79.tar.bz2
ntapi-25347d2a2820f20f30c8556baef36fe6e7067a79.tar.xz
internals: __ntapi_log_write(): initial implementation.
-rw-r--r--project/headers.mk1
-rw-r--r--src/internal/ntapi_log.h66
2 files changed, 67 insertions, 0 deletions
diff --git a/project/headers.mk b/project/headers.mk
index 09b3e7c..84db879 100644
--- a/project/headers.mk
+++ b/project/headers.mk
@@ -69,6 +69,7 @@ INTERNAL_HEADERS = \
$(PROJECT_DIR)/src/internal/./ntapi_fnapi.h \
$(PROJECT_DIR)/src/internal/./ntapi_hash_table.h \
$(PROJECT_DIR)/src/internal/./ntapi_impl.h \
+ $(PROJECT_DIR)/src/internal/./ntapi_log.h \
$(PROJECT_DIR)/src/internal/./ntapi_pty.h \
ALL_HEADERS = $(API_HEADERS) $(INTERNAL_HEADERS) \
diff --git a/src/internal/ntapi_log.h b/src/internal/ntapi_log.h
new file mode 100644
index 0000000..108bc18
--- /dev/null
+++ b/src/internal/ntapi_log.h
@@ -0,0 +1,66 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013--2016 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <psxtypes/psxtypes.h>
+#include <ntapi/nt_file.h>
+#include <ntapi/ntapi.h>
+#include "ntapi_impl.h"
+
+static inline int __ntapi_uintptr_to_utf8(uintptr_t value,unsigned char * buf)
+{
+ int i,len;
+ uintptr_t val;
+
+ if (!value) {
+ *buf = '0';
+ len = 1;
+ } else {
+ for (len=0,val=value; val; val=val/10,len++);
+ for (i=len,buf+=len-1; i; i--,buf--,value=value/10)
+ *buf = '0' + (value % 10);
+ }
+
+ return len;
+}
+
+static inline ssize_t __ntapi_log_write(void * msg,uint32_t size)
+{
+ int32_t status;
+ void * hlog;
+ nt_iosb iosb;
+ uintptr_t buffer[8] = {0};
+ char * ch = (char *)buffer;
+
+ if (!(hlog = __ntapi_internals()->rtdata->hlog))
+ return NT_STATUS_INVALID_HANDLE;
+
+ *ch++ = '@';
+ ch += __ntapi_uintptr_to_utf8(
+ pe_get_current_process_id(),
+ ch);
+ *ch++ = ':';
+ ch += __ntapi_uintptr_to_utf8(
+ pe_get_current_thread_id(),
+ ch);
+ *ch++ = '@';
+ *ch++ = ' ';
+
+ __ntapi->zw_write_file(
+ hlog,
+ 0,0,0,&iosb,
+ buffer,
+ (uint32_t)(ch-(char *)buffer),
+ 0,0);
+
+ status = __ntapi->zw_write_file(
+ hlog,
+ 0,0,0,&iosb,
+ msg,
+ (uint32_t)size,
+ 0,0);
+
+ return status ? -1 : iosb.info;
+}