Cygwin: move get_obj_handle_count() to miscfuncs.cc

get_obj_handle_count() is used in flock only so far, but pipe
handling might have a usage, too, soon.  Given that this function
might be generally useful and isn't restricted to flock usage,
move it to miscfuncs.cc and make it non-static.  Add a prototype
in miscfuncs.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2021-09-03 10:15:57 +02:00
parent 9cfbb5aa82
commit e9d4cb765f
3 changed files with 19 additions and 16 deletions

View File

@ -216,22 +216,6 @@ allow_others_to_sync ()
done = true;
}
/* Get the handle count of an object. */
static ULONG
get_obj_handle_count (HANDLE h)
{
OBJECT_BASIC_INFORMATION obi;
NTSTATUS status;
ULONG hdl_cnt = 0;
status = NtQueryObject (h, ObjectBasicInformation, &obi, sizeof obi, NULL);
if (!NT_SUCCESS (status))
debug_printf ("NtQueryObject: %y", status);
else
hdl_cnt = obi.HandleCount;
return hdl_cnt;
}
/* Helper struct to construct a local OBJECT_ATTRIBUTES on the stack. */
struct lockfattr_t
{

View File

@ -18,6 +18,22 @@ details. */
#include "tls_pbuf.h"
#include "mmap_alloc.h"
/* Get handle count of an object. */
ULONG
get_obj_handle_count (HANDLE h)
{
OBJECT_BASIC_INFORMATION obi;
NTSTATUS status;
ULONG hdl_cnt = 0;
status = NtQueryObject (h, ObjectBasicInformation, &obi, sizeof obi, NULL);
if (!NT_SUCCESS (status))
debug_printf ("NtQueryObject: %y", status);
else
hdl_cnt = obi.HandleCount;
return hdl_cnt;
}
int __reg2
check_invalid_virtual_addr (const void *s, unsigned sz)
{

View File

@ -98,6 +98,9 @@ transform_chars (PUNICODE_STRING upath, USHORT start_idx)
PWCHAR transform_chars_af_unix (PWCHAR, const char *, __socklen_t);
/* Get handle count of an object. */
ULONG get_obj_handle_count (HANDLE h);
/* Memory checking */
int __reg2 check_invalid_virtual_addr (const void *s, unsigned sz);