From cd5d5c3277aa300cac91d09ba02212c06e6b1218 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 12 Dec 2016 00:04:51 -0500 Subject: vmount module: removed current impl. of the virtual mount system client. the current design of the virtual mount system turned out to be less than ideal in terms of both simplicity and robustness. since its importance seems to be rather marginal at the moment, it is better to first remove it in its entirety, and then, given sufficient interest, re-implement and integrate it into the system. --- src/internal/ntapi.c | 14 -- src/internal/ntapi_fnapi.h | 13 -- src/vmount/ntapi_vms_cache.c | 216 ------------------------------- src/vmount/ntapi_vms_client_connect.c | 86 ------------ src/vmount/ntapi_vms_client_disconnect.c | 37 ------ src/vmount/ntapi_vms_helper.c | 118 ----------------- src/vmount/ntapi_vms_point_attach.c | 52 -------- src/vmount/ntapi_vms_ref_count.c | 96 -------------- src/vmount/ntapi_vms_table_query.c | 45 ------- 9 files changed, 677 deletions(-) delete mode 100644 src/vmount/ntapi_vms_cache.c delete mode 100644 src/vmount/ntapi_vms_client_connect.c delete mode 100644 src/vmount/ntapi_vms_client_disconnect.c delete mode 100644 src/vmount/ntapi_vms_helper.c delete mode 100644 src/vmount/ntapi_vms_point_attach.c delete mode 100644 src/vmount/ntapi_vms_ref_count.c delete mode 100644 src/vmount/ntapi_vms_table_query.c (limited to 'src') diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index fe928ac..e491bff 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -339,19 +338,6 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) /* nt_statfs.h */ __ntapi->tt_statfs = __ntapi_tt_statfs; - /* nt_vmount.h */ - __ntapi->vms_get_node_by_dev_name = __ntapi_vms_get_node_by_dev_name; - __ntapi->vms_get_node_by_end_component = __ntapi_vms_get_node_by_end_component; - __ntapi->vms_cache_alloc = __ntapi_vms_cache_alloc; - __ntapi->vms_cache_free = __ntapi_vms_cache_free; - __ntapi->vms_client_connect = __ntapi_vms_client_connect; - __ntapi->vms_client_disconnect = __ntapi_vms_client_disconnect; - __ntapi->vms_point_attach = __ntapi_vms_point_attach; - __ntapi->vms_point_get_handles = __ntapi_vms_point_get_handles; - __ntapi->vms_ref_count_inc = __ntapi_vms_ref_count_inc; - __ntapi->vms_ref_count_dec = __ntapi_vms_ref_count_dec; - __ntapi->vms_table_query = __ntapi_vms_table_query; - /* nt_debug.h */ #ifdef __DEBUG __ntapi->dbg_write = __dbg_write; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 650839e..8715b7a 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -239,19 +239,6 @@ ntapi_tt_stat __ntapi_tt_stat; /* nt_statfs.h */ ntapi_tt_statfs __ntapi_tt_statfs; -/* nt_vmount.h */ -ntapi_vms_get_node_by_dev_name __ntapi_vms_get_node_by_dev_name; -ntapi_vms_get_node_by_end_component __ntapi_vms_get_node_by_end_component; -ntapi_vms_cache_alloc __ntapi_vms_cache_alloc; -ntapi_vms_cache_free __ntapi_vms_cache_free; -ntapi_vms_client_connect __ntapi_vms_client_connect; -ntapi_vms_client_disconnect __ntapi_vms_client_disconnect; -ntapi_vms_point_attach __ntapi_vms_point_attach; -ntapi_vms_point_get_handles __ntapi_vms_point_get_handles; -ntapi_vms_ref_count_inc __ntapi_vms_ref_count_inc; -ntapi_vms_ref_count_dec __ntapi_vms_ref_count_dec; -ntapi_vms_table_query __ntapi_vms_table_query; - /* nt_hashes.h */ ntapi_tt_populate_hashed_import_table __ntapi_tt_populate_hashed_import_table; diff --git a/src/vmount/ntapi_vms_cache.c b/src/vmount/ntapi_vms_cache.c deleted file mode 100644 index c97ff04..0000000 --- a/src/vmount/ntapi_vms_cache.c +++ /dev/null @@ -1,216 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -typedef struct nt_vms_cache_interface { - nt_vms_system * vms_sys; - struct dalist_ex cache; - size_t alloc_size; - uintptr_t buffer[1]; -} nt_vms_cache_context; - - -typedef struct _nt_vms_cache_record { - void * hfile; - uint32_t dev_name_hash; - nt_large_integer index_number; - intptr_t client_key; - intptr_t server_key; -} nt_vms_cache_record; - - -int32_t __stdcall __ntapi_vms_cache_free( - __in nt_vms_cache vms_cache) -{ - int32_t status; - void * region_addr; - size_t region_size; - - /* validation */ - if (!vms_cache) - return NT_STATUS_INVALID_PARAMETER; - - /* free memory */ - region_addr = vms_cache; - region_size = vms_cache->alloc_size; - - status = __ntapi->zw_free_virtual_memory( - NT_CURRENT_PROCESS_HANDLE, - ®ion_addr, - ®ion_size, - NT_MEM_RELEASE); - - return status; -} - -/* vms optional cache functions */ -nt_vms_cache __stdcall __ntapi_vms_cache_alloc( - __in nt_vms_system * vms_sys, - __in uint32_t flags __reserved, - __in void * options __reserved, - __out int32_t * status __optional) -{ - int32_t _status; - void * buffer; - size_t buffer_size; - nt_vms_cache_context * vms_cache; - - /* unused params */ - (void)flags; - (void)options; - - /* status */ - if (!status) status = &_status; - - /* validation */ - if (!vms_sys) { - *status = NT_STATUS_INVALID_PARAMETER; - return (nt_vms_cache)0; - } - - /* calculate size */ - buffer_size = sizeof(nt_vms_cache_context); - buffer_size += vms_sys->vms_points_cap * (sizeof(nt_vms_cache_record) - sizeof(uintptr_t)); - - /* allocate buffer */ - *status = __ntapi->zw_allocate_virtual_memory( - NT_CURRENT_PROCESS_HANDLE, - &buffer, - 0, - &buffer_size, - NT_MEM_COMMIT, - NT_PAGE_READWRITE); - - if (*status) return (nt_vms_cache)0; - - /* init vms cache */ - vms_cache = (nt_vms_cache_context *)buffer; - vms_cache->vms_sys = vms_sys; - vms_cache->alloc_size = buffer_size; - - /* init list */ - *status = dalist_init_ex( - &vms_cache->cache, - sizeof(nt_vms_cache_record), - 0x1000, - __ntapi->zw_allocate_virtual_memory, - DALIST_MEMFN_NT_ALLOCATE_VIRTUAL_MEMORY); - - if (*status != DALIST_OK) { - *status = NT_STATUS_UNSUCCESSFUL; - __ntapi_vms_cache_free(vms_cache); - return (nt_vms_cache)0; - } - - /* set list buffer */ - buffer_size -= (size_t)&(((nt_vms_cache_context *)0)->buffer); - - *status = dalist_deposit_memory_block( - &vms_cache->cache, - &vms_cache->buffer, - buffer_size); - - return vms_cache; -} - - -int32_t __stdcall __ntapi_vms_cache_record_append( - __in nt_vms_cache cache, - __in void * hfile, - __in uint32_t dev_name_hash, - __in nt_large_integer index_number, - __in intptr_t client_key, - __in intptr_t server_key) -{ - int32_t status; - struct dalist_node_ex * node; - nt_vms_cache_record * cache_record; - - status = dalist_get_node_by_key( - &cache->cache, - &node, - (uintptr_t)hfile, - DALIST_NODE_TYPE_EXISTING, - (uintptr_t *)0); - - if (status != DALIST_OK) - status = NT_STATUS_INTERNAL_ERROR; - else if (node) - status = NT_STATUS_OBJECTID_EXISTS; - else { - status = dalist_get_free_node(&cache->cache,(void **)&node); - - if (status == DALIST_OK) { - cache_record = (nt_vms_cache_record *)&node->dblock; - - __ntapi->tt_aligned_block_memset( - node, - 0, - (uintptr_t)&((struct dalist_node_ex *)0)->dblock + sizeof(*cache_record)); - - node->key = (uintptr_t)hfile; - - cache_record->hfile = hfile; - cache_record->dev_name_hash = dev_name_hash; - cache_record->index_number.quad = index_number.quad; - cache_record->client_key = client_key; - cache_record->server_key = server_key; - - status = dalist_insert_node_by_key( - &cache->cache, - node); - - if (status != DALIST_OK) - dalist_deposit_free_node( - &cache->cache, - node); - } - } - - return status; -} - - -int32_t __stdcall __ntapi_vms_cache_record_remove( - __in nt_vms_cache cache, - __in void * hfile, - __in uint32_t dev_name_hash, - __in nt_large_integer index_number) -{ - int32_t status; - struct dalist_node_ex * node; - - (void)dev_name_hash; - (void)index_number; - - status = dalist_get_node_by_key( - &cache->cache, - &node, - (uintptr_t)hfile, - DALIST_NODE_TYPE_EXISTING, - (uintptr_t *)0); - - if (status != DALIST_OK) - status = NT_STATUS_INTERNAL_ERROR; - else if (node) - status = NT_STATUS_INVALID_PARAMETER; - else { - status = dalist_discard_node( - &cache->cache, - node); - - if (status != DALIST_OK) - status = NT_STATUS_INTERNAL_ERROR; - } - - return status; -} diff --git a/src/vmount/ntapi_vms_client_connect.c b/src/vmount/ntapi_vms_client_connect.c deleted file mode 100644 index 6477a1b..0000000 --- a/src/vmount/ntapi_vms_client_connect.c +++ /dev/null @@ -1,86 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include -#include "ntapi_impl.h" - - -static void __vms_port_name_from_server_info( - __out nt_port_name * vms_port_name, - __in nt_tty_vms_info * vmsinfo) -{ - nt_port_attr port_attr; - - port_attr.type = NT_PORT_TYPE_VMOUNT; - port_attr.subtype = NT_PORT_SUBTYPE_DEFAULT; - - __ntapi->tt_aligned_block_memcpy( - (uintptr_t *)&port_attr.keys, - (uintptr_t *)&vmsinfo->vms_keys, - sizeof(nt_port_keys)); - - __ntapi->tt_port_guid_from_type( - &port_attr.guid, - port_attr.type, - port_attr.subtype); - - __ntapi->tt_port_name_from_attributes( - vms_port_name, - &port_attr); -} - - -int32_t __stdcall __ntapi_vms_client_connect( - __out void ** hvms, - __in nt_tty_vms_info * vmsinfo) -{ - int32_t status; - nt_port_name vms_port_name; - - nt_unicode_string name; - nt_sqos sqos; - nt_oa oa; - - /* vmount daemon port name */ - __vms_port_name_from_server_info( - &vms_port_name, - vmsinfo); - - /* port name init */ - name.buffer = (wchar16_t *)&vms_port_name; - name.maxlen = 0; - name.strlen = (uint16_t)(size_t)(&((nt_port_name *)0)->null_termination); - - /* init security structure */ - sqos.length = sizeof(sqos); - sqos.impersonation_level = NT_SECURITY_IMPERSONATION; - sqos.context_tracking_mode = NT_SECURITY_TRACKING_DYNAMIC; - sqos.effective_only = 1; - - /* init the port's object attributes */ - oa.len = sizeof(oa); - oa.root_dir = (void *)0; - oa.obj_name = &name; - oa.obj_attr = 0; - oa.sec_desc = (nt_security_descriptor *)0; - oa.sec_qos = &sqos; - - status = __ntapi->zw_connect_port( - hvms, - &name, - &sqos, - (nt_port_section_write *)0, - (nt_port_section_read *)0, - (uint32_t *)0, - (void *)0, - (uint32_t *)0); - - return status; -} diff --git a/src/vmount/ntapi_vms_client_disconnect.c b/src/vmount/ntapi_vms_client_disconnect.c deleted file mode 100644 index c16ea6d..0000000 --- a/src/vmount/ntapi_vms_client_disconnect.c +++ /dev/null @@ -1,37 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -int32_t __stdcall __ntapi_vms_client_disconnect( - __in void * hvms) -{ - nt_vms_daemon_msg msg; - - if (!hvms) return NT_STATUS_INVALID_HANDLE; - - /* msg */ - __ntapi->tt_aligned_block_memset(&msg,0,sizeof(msg)); - - msg.header.msg_type = NT_LPC_NEW_MESSAGE; - msg.header.data_size = sizeof(msg.data); - msg.header.msg_size = sizeof(msg); - msg.data.msginfo.opcode = NT_VMS_CLIENT_DISCONNECT; - - /* zw_request_wait_reply_port */ - __ntapi->zw_request_wait_reply_port( - hvms, - &msg, - &msg); - - /* close client handle */ - return __ntapi->zw_close(hvms); -} diff --git a/src/vmount/ntapi_vms_helper.c b/src/vmount/ntapi_vms_helper.c deleted file mode 100644 index 4d07bf0..0000000 --- a/src/vmount/ntapi_vms_helper.c +++ /dev/null @@ -1,118 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -nt_vms_node * __stdcall __ntapi_vms_get_end_component_first_node( - __in nt_vms_system * pvms_sys, - __in uint32_t end_component_hash) -{ - nt_vms_node * node; - - /* verify non-empty list and valid input */ - if (!pvms_sys->dev_name_head_node || !end_component_hash) - return (nt_vms_node *)0; - - /* find first node by end component hash */ - node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node); - - while (node->next && (node->end_component_hash < end_component_hash)) - node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next); - - if (node->end_component_hash == end_component_hash) - return node; - else - return (nt_vms_node *)0; -} - - -static nt_vms_node * __stdcall __ntapi_vms_get_node( - __in nt_vms_system * pvms_sys, - __in uint32_t end_component_hash, - __in uint32_t dev_name_hash, - __in nt_large_integer index_number) -{ - nt_vms_node * node; - - /* verify non-empty list */ - if (!pvms_sys->dev_name_head_node) - return (nt_vms_node *)0; - - /* end_component_hash */ - if (end_component_hash) { - node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node); - - while (node->next && (node->end_component_hash < end_component_hash)) - node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next); - - if (node->end_component_hash != end_component_hash) - return (nt_vms_node *)0; - } else - node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->dev_name_head_node); - - /* find device nodes */ - while (node->next && (node->dev_name_hash < dev_name_hash)) - node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next); - - if (node->dev_name_hash != dev_name_hash) - return (nt_vms_node *)0; - - /* find mount-point nodes */ - while (node->next && (node->index_number.quad < index_number.quad)) - node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next); - - if (node->index_number.quad != index_number.quad) - return (nt_vms_node *)0; - - return node; -} - - -nt_vms_node * __stdcall __ntapi_vms_get_node_by_dev_name( - __in nt_vms_system * pvms_sys, - __in uint32_t dev_name_hash, - __in nt_large_integer index_number) -{ - return __ntapi_vms_get_node( - pvms_sys, - 0, - dev_name_hash, - index_number); -} - - -nt_vms_node * __stdcall __ntapi_vms_get_node_by_end_component( - __in nt_vms_system * pvms_sys, - __in uint32_t end_component_hash, - __in uint32_t dev_name_hash, - __in nt_large_integer index_number) -{ - return __ntapi_vms_get_node( - pvms_sys, - end_component_hash, - dev_name_hash, - index_number); -} - - -nt_vms_point * __stdcall __ntapi_vms_get_top_of_stack_mount_point( - __in nt_vms_system * pvms_sys, - __in nt_vms_node * node) -{ - nt_vms_point * point; - - point = (nt_vms_point *)((uintptr_t)pvms_sys + node->stack); - - while (point->next) - point = (nt_vms_point *)((uintptr_t)pvms_sys + point->next); - - return point; -} diff --git a/src/vmount/ntapi_vms_point_attach.c b/src/vmount/ntapi_vms_point_attach.c deleted file mode 100644 index 21ee0ce..0000000 --- a/src/vmount/ntapi_vms_point_attach.c +++ /dev/null @@ -1,52 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -static int32_t __stdcall __ntapi_vms_point_attach_detach( - __in void * hvms, - __in nt_vms_point_info * point_info, - __in int32_t vms_opcode) -{ - int32_t status; - nt_vms_daemon_msg msg; - - /* msg */ - __ntapi->tt_aligned_block_memset(&msg,0,sizeof(msg)); - - msg.header.msg_type = NT_LPC_NEW_MESSAGE; - msg.header.data_size = sizeof(msg.data); - msg.header.msg_size = sizeof(msg); - msg.data.msginfo.opcode = vms_opcode; - - /* copy point to msg */ - __ntapi->tt_aligned_block_memcpy( - (uintptr_t *)&(msg.data.pointinfo), - (uintptr_t *)point_info, - sizeof(*point_info)); - - /* zw_request_wait_reply_port */ - status = __ntapi->zw_request_wait_reply_port(hvms,&msg,&msg); - - /* return vms status */ - return status ? status : msg.data.msginfo.status; -} - - -int32_t __stdcall __ntapi_vms_point_attach( - __in void * hvms, - __in nt_vms_point_info * point_info) -{ - return __ntapi_vms_point_attach_detach( - hvms, - point_info, - NT_VMS_POINT_ATTACH); -} diff --git a/src/vmount/ntapi_vms_ref_count.c b/src/vmount/ntapi_vms_ref_count.c deleted file mode 100644 index c61b2ea..0000000 --- a/src/vmount/ntapi_vms_ref_count.c +++ /dev/null @@ -1,96 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -static int32_t __stdcall __ntapi_vms_ref_count_inc_dec( - __in void * hvms, - __in nt_vms_ref_count_info * ref_cnt_info, - __in int32_t vms_opcode) -{ - int32_t status; - nt_vms_daemon_msg msg; - - /* msg */ - __ntapi->tt_aligned_block_memset(&msg,0,sizeof(msg)); - - msg.header.msg_type = NT_LPC_NEW_MESSAGE; - msg.header.data_size = sizeof(msg.data); - msg.header.msg_size = sizeof(msg); - msg.data.msginfo.opcode = vms_opcode; - - /* copy ref count info to msg */ - __ntapi->tt_aligned_block_memcpy( - (uintptr_t *)&(msg.data.refcntinfo), - (uintptr_t *)ref_cnt_info, - sizeof(*ref_cnt_info)); - - /* zw_request_wait_reply_port */ - status = __ntapi->zw_request_wait_reply_port( - hvms, - &msg, - &msg); - - if (status) return status; - - /* return info */ - __ntapi->tt_aligned_block_memcpy( - (uintptr_t *)ref_cnt_info, - (uintptr_t *)&(msg.data.refcntinfo), - sizeof(*ref_cnt_info)); - - /* return vms status */ - return status ? status : msg.data.msginfo.status; -} - - -int32_t __stdcall __ntapi_vms_ref_count_inc( - __in void * hvms, - __in nt_vms_ref_count_info * ref_cnt_info) -{ - return __ntapi_vms_ref_count_inc_dec( - hvms, - ref_cnt_info, - NT_VMS_REF_COUNT_INC); -} - - -int32_t __stdcall __ntapi_vms_ref_count_dec( - __in void * hvms, - __in nt_vms_ref_count_info * ref_cnt_info) -{ - return __ntapi_vms_ref_count_inc_dec( - hvms, - ref_cnt_info, - NT_VMS_REF_COUNT_DEC); -} - - -int32_t __stdcall __ntapi_vms_point_detach( - __in void * hvms, - __in nt_vms_ref_count_info * ref_cnt_info) -{ - return __ntapi_vms_ref_count_inc_dec( - hvms, - ref_cnt_info, - NT_VMS_POINT_DETACH); -} - - -int32_t __stdcall __ntapi_vms_point_get_handles( - __in void * hvms, - __in nt_vms_ref_count_info * ref_cnt_info) -{ - return __ntapi_vms_ref_count_inc_dec( - hvms, - ref_cnt_info, - NT_VMS_POINT_GET_HANDLES); -} diff --git a/src/vmount/ntapi_vms_table_query.c b/src/vmount/ntapi_vms_table_query.c deleted file mode 100644 index eb9358a..0000000 --- a/src/vmount/ntapi_vms_table_query.c +++ /dev/null @@ -1,45 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -#include -#include -#include -#include -#include "ntapi_impl.h" - - -int32_t __stdcall __ntapi_vms_table_query( - __in void * hvms, - __in nt_vms_daemon_info * vms_info) -{ - int32_t status; - nt_vms_daemon_msg msg; - - /* msg */ - __ntapi->tt_aligned_block_memset(&msg,0,sizeof(msg)); - - msg.header.msg_type = NT_LPC_NEW_MESSAGE; - msg.header.data_size = sizeof(msg.data); - msg.header.msg_size = sizeof(msg); - msg.data.msginfo.opcode = NT_VMS_TABLE_QUERY; - - /* zw_request_wait_reply_port */ - status = __ntapi->zw_request_wait_reply_port( - hvms, - &msg, - &msg); - - if (status) return status; - - /* return info */ - __ntapi->tt_aligned_block_memcpy( - (uintptr_t *)vms_info, - (uintptr_t *)&(msg.data.vmsinfo), - sizeof(*vms_info)); - - /* return vms status */ - return status ? status : msg.data.msginfo.status; -} -- cgit v1.2.3