implement generic I/O async request object to replace file-specific async requests, refactor lwIP network stack to dispatch requests through IRPs with cancellation support, add cancellation polling to lwIP accept and receive operations using LwipSocketWaitRecvNetbuf and LwipSocketWaitAccept, introduce NetSubmitSocketIrp for routing socket operations via device IRPs, track network IRP statistics with SYS_NET_IRP_STATS, add process module lock spinlock and reference counting for process modules, implement dynamic module loading and unloading via user module handles, add POSIX dynamic loader APIs including dlopen, dlsym, dlerror, and dlclose, introduce PosixStart entry point for posix applications, add new native smoke tests for net IRPs.
This commit is contained in:
1 parent
ed3d065abd
commit
1f5477cf66
32 files changed
+3713
-551
No files matched your search
@@ -4,7 +4,8 @@
|
||||
// net_stack.h - provider interface between kernel socket facade and network stack drivers.
|
||||
|
||||
// The kernel owns process handles, user-memory copying, NET_DEVICE registration,
|
||||
// and SOCKET_OBJECT lifetime. A stack driver owns protocol implementation.
|
||||
// and SOCKET_OBJECT lifetime. A stack driver owns protocol implementation behind
|
||||
// a DEVICE_OBJECT so socket operations enter the same IRP pipe as other I/O.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -12,39 +13,165 @@
|
||||
#include <ntlite/ddi/net_device.h>
|
||||
#include <ntlite/ddi/net_abi.h>
|
||||
|
||||
#define NET_STACK_PROVIDER_VERSION 1u
|
||||
struct DEVICE_OBJECT;
|
||||
|
||||
#define NET_STACK_PROVIDER_VERSION 2u
|
||||
#define NET_IOCTL_SOCKET 0x4E455401u
|
||||
|
||||
typedef enum NET_SOCKET_IRP_OPERATION {
|
||||
NetSocketIrpInvalid = 0,
|
||||
NetSocketIrpCreate = 1,
|
||||
NetSocketIrpClose = 2,
|
||||
NetSocketIrpBind = 3,
|
||||
NetSocketIrpListen = 4,
|
||||
NetSocketIrpAccept = 5,
|
||||
NetSocketIrpConnect = 6,
|
||||
NetSocketIrpSend = 7,
|
||||
NetSocketIrpReceive = 8,
|
||||
NetSocketIrpSendTo = 9,
|
||||
NetSocketIrpReceiveFrom = 10,
|
||||
NetSocketIrpShutdown = 11,
|
||||
NetSocketIrpSetOption = 12,
|
||||
NetSocketIrpGetOption = 13,
|
||||
NetSocketIrpPoll = 14,
|
||||
NetSocketIrpResolveHost = 15,
|
||||
NetSocketIrpOperationCount,
|
||||
} NET_SOCKET_IRP_OPERATION;
|
||||
|
||||
typedef struct NET_SOCKET_IRP_REQUEST {
|
||||
uint32_t Size;
|
||||
uint32_t Operation;
|
||||
volatile uint8_t* CancelRequested;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t Domain;
|
||||
uint32_t Type;
|
||||
uint32_t Protocol;
|
||||
void** ProviderSocketOut;
|
||||
} Create;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
} Close;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
const SYS_SOCKET_ADDRESS_K* Address;
|
||||
size_t AddressSize;
|
||||
} Bind;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
uint32_t Backlog;
|
||||
} Listen;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
void** AcceptedOut;
|
||||
SYS_SOCKET_ADDRESS_K* RemoteOut;
|
||||
} Accept;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
const SYS_SOCKET_ADDRESS_K* Address;
|
||||
size_t AddressSize;
|
||||
} Connect;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
const void* Buffer;
|
||||
size_t Length;
|
||||
uint32_t Flags;
|
||||
size_t* SentOut;
|
||||
} Send;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
void* Buffer;
|
||||
size_t Length;
|
||||
uint32_t Flags;
|
||||
size_t* ReceivedOut;
|
||||
} Receive;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
const void* Buffer;
|
||||
size_t Length;
|
||||
uint32_t Flags;
|
||||
const SYS_SOCKET_ADDRESS_K* Remote;
|
||||
size_t RemoteSize;
|
||||
size_t* SentOut;
|
||||
} SendTo;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
void* Buffer;
|
||||
size_t Length;
|
||||
uint32_t Flags;
|
||||
SYS_SOCKET_ADDRESS_K* RemoteOut;
|
||||
size_t* ReceivedOut;
|
||||
} ReceiveFrom;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
uint32_t How;
|
||||
} Shutdown;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
uint32_t Option;
|
||||
const void* Value;
|
||||
size_t ValueSize;
|
||||
} SetOption;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
uint32_t Option;
|
||||
void* Value;
|
||||
size_t ValueSize;
|
||||
size_t* ActualSizeOut;
|
||||
} GetOption;
|
||||
|
||||
struct {
|
||||
void* Socket;
|
||||
uint32_t Events;
|
||||
uint32_t* ReturnedEventsOut;
|
||||
} Poll;
|
||||
|
||||
struct {
|
||||
const char* Name;
|
||||
uint32_t Family;
|
||||
SYS_SOCKET_ADDRESS_K* AddressOut;
|
||||
} ResolveHost;
|
||||
} u;
|
||||
} NET_SOCKET_IRP_REQUEST;
|
||||
|
||||
typedef struct NET_IRP_STATS {
|
||||
uint64_t Submitted;
|
||||
uint64_t Completed;
|
||||
uint64_t CompletedSynchronously;
|
||||
uint64_t CompletedAsynchronously;
|
||||
uint64_t Pending;
|
||||
uint64_t CancelRequested;
|
||||
uint64_t Cancelled;
|
||||
uint64_t WouldBlock;
|
||||
uint64_t Timeout;
|
||||
uint64_t Failed;
|
||||
uint64_t ByOperation[NetSocketIrpOperationCount];
|
||||
} NET_IRP_STATS;
|
||||
|
||||
typedef struct NET_STACK_PROVIDER NET_STACK_PROVIDER;
|
||||
|
||||
struct NET_STACK_PROVIDER {
|
||||
uint32_t Version;
|
||||
const char* Name;
|
||||
struct DEVICE_OBJECT* StackDevice;
|
||||
|
||||
KSTATUS (*AttachDevice)(NET_DEVICE* device);
|
||||
KSTATUS (*ReceiveFrame)(NET_DEVICE* device, const void* frame, size_t length);
|
||||
|
||||
KSTATUS (*SocketCreate)(uint32_t domain, uint32_t type, uint32_t protocol, void** outSocket);
|
||||
void (*SocketClose)(void* socket);
|
||||
|
||||
KSTATUS (*Bind)(void* socket, const SYS_SOCKET_ADDRESS_K* address, size_t addressSize);
|
||||
KSTATUS (*Listen)(void* socket, uint32_t backlog);
|
||||
KSTATUS (*Accept)(void* socket, void** acceptedOut, SYS_SOCKET_ADDRESS_K* remoteOut);
|
||||
KSTATUS (*Connect)(void* socket, const SYS_SOCKET_ADDRESS_K* address, size_t addressSize);
|
||||
|
||||
KSTATUS (*Send)(void* socket, const void* buffer, size_t length, uint32_t flags, size_t* sentOut);
|
||||
KSTATUS (*Receive)(void* socket, void* buffer, size_t length, uint32_t flags, size_t* receivedOut);
|
||||
KSTATUS (*SendTo)(void* socket, const void* buffer, size_t length, uint32_t flags,
|
||||
const SYS_SOCKET_ADDRESS_K* remote, size_t remoteSize, size_t* sentOut);
|
||||
KSTATUS (*ReceiveFrom)(void* socket, void* buffer, size_t length, uint32_t flags,
|
||||
SYS_SOCKET_ADDRESS_K* remoteOut, size_t* receivedOut);
|
||||
|
||||
KSTATUS (*Shutdown)(void* socket, uint32_t how);
|
||||
KSTATUS (*SetOption)(void* socket, uint32_t option, const void* value, size_t valueSize);
|
||||
KSTATUS (*GetOption)(void* socket, uint32_t option, void* value, size_t valueSize, size_t* actualSizeOut);
|
||||
KSTATUS (*Poll)(void* socket, uint32_t events, uint32_t* returnedEventsOut);
|
||||
|
||||
KSTATUS (*ResolveHost)(const char* name, uint32_t family, SYS_SOCKET_ADDRESS_K* addressOut);
|
||||
};
|
||||
|
||||
__declspec(dllexport) KSTATUS NetRegisterStackProvider(const NET_STACK_PROVIDER* provider);
|
||||
__declspec(dllexport) const NET_STACK_PROVIDER* NetGetStackProvider(void);
|
||||
__declspec(dllexport) void NetQueryIrpStats(NET_IRP_STATS* out);
|
||||
Reference in new issue
Block a user