ReactOS  0.4.14-dev-606-g14ebc0b
sys_arch.c File Reference
#include "lwip/sys.h"
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "lwip/err.h"
#include "rosip.h"
#include <debug.h>
Include dependency graph for sys_arch.c:

Go to the source code of this file.

Classes

struct  _thread_t
 

Typedefs

typedef struct _thread_tthread_t
 

Functions

u32_t sys_now (void)
 
void sys_arch_protect (sys_prot_t *lev)
 
void sys_arch_unprotect (sys_prot_t lev)
 
err_t sys_sem_new (sys_sem_t *sem, u8_t count)
 
int sys_sem_valid (sys_sem_t *sem)
 
void sys_sem_set_invalid (sys_sem_t *sem)
 
void sys_sem_free (sys_sem_t *sem)
 
void sys_sem_signal (sys_sem_t *sem)
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 
err_t sys_mbox_new (sys_mbox_t *mbox, int size)
 
int sys_mbox_valid (sys_mbox_t *mbox)
 
void sys_mbox_set_invalid (sys_mbox_t *mbox)
 
void sys_mbox_free (sys_mbox_t *mbox)
 
void sys_mbox_post (sys_mbox_t *mbox, void *msg)
 
u32_t sys_arch_mbox_fetch (sys_mbox_t *mbox, void **msg, u32_t timeout)
 
u32_t sys_arch_mbox_tryfetch (sys_mbox_t *mbox, void **msg)
 
err_t sys_mbox_trypost (sys_mbox_t *mbox, void *msg)
 
VOID NTAPI LwipThreadMain (PVOID Context)
 
sys_thread_t sys_thread_new (const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
 
void sys_init (void)
 
void sys_shutdown (void)
 

Variables

static LIST_ENTRY ThreadListHead
 
static KSPIN_LOCK ThreadListLock
 
KEVENT TerminationEvent
 
NPAGED_LOOKASIDE_LIST MessageLookasideList
 
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
 
static LARGE_INTEGER StartTime
 

Typedef Documentation

◆ thread_t

Function Documentation

◆ LwipThreadMain()

VOID NTAPI LwipThreadMain ( PVOID  Context)

Definition at line 261 of file sys_arch.c.

262 {
263  thread_t Container = (thread_t)Context;
264  KIRQL OldIrql;
265 
267 
268  Container->ThreadFunction(Container->ThreadContext);
269 
271  RemoveEntryList(&Container->ListEntry);
273 
274  ExFreePool(Container);
275 
277 }
void * ThreadContext
Definition: sys_arch.c:24
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
LIST_ENTRY ListEntry
Definition: sys_arch.c:25
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
void(* ThreadFunction)(void *arg)
Definition: sys_arch.c:23
static KSPIN_LOCK ThreadListLock
Definition: sys_arch.c:12
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct _thread_t * thread_t
static LIST_ENTRY ThreadListHead
Definition: sys_arch.c:11
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by sys_thread_new().

◆ sys_arch_mbox_fetch()

u32_t sys_arch_mbox_fetch ( sys_mbox_t mbox,
void **  msg,
u32_t  timeout 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
time (in milliseconds) waited for a message, may be 0 if not waited or SYS_ARCH_TIMEOUT on timeout The returned time has to be accurate to prevent timer jitter!

Definition at line 182 of file sys_arch.c.

183 {
184  LARGE_INTEGER LargeTimeout, PreWaitTime, PostWaitTime;
185  UINT64 TimeDiff;
187  PVOID Message;
188  PLWIP_MESSAGE_CONTAINER Container;
190  KIRQL OldIrql;
191  PVOID WaitObjects[] = {&mbox->Event, &TerminationEvent};
192 
193  LargeTimeout.QuadPart = Int32x32To64(timeout, -10000);
194 
195  KeQuerySystemTime(&PreWaitTime);
196 
198  WaitObjects,
199  WaitAny,
200  Executive,
201  KernelMode,
202  FALSE,
203  timeout != 0 ? &LargeTimeout : NULL,
204  NULL);
205 
206  if (Status == STATUS_WAIT_0)
207  {
210  ASSERT(Entry);
211  if (IsListEmpty(&mbox->ListHead))
214 
215  Container = CONTAINING_RECORD(Entry, LWIP_MESSAGE_CONTAINER, ListEntry);
216  Message = Container->Message;
217  ExFreePool(Container);
218 
219  if (msg)
220  *msg = Message;
221 
222  KeQuerySystemTime(&PostWaitTime);
223  TimeDiff = PostWaitTime.QuadPart - PreWaitTime.QuadPart;
224  TimeDiff /= 10000;
225 
226  return TimeDiff;
227  }
228  else if (Status == STATUS_WAIT_1)
229  {
230  /* DON'T remove ourselves from the thread list! */
232 
233  /* We should never get here! */
234  ASSERT(FALSE);
235 
236  return 0;
237  }
238 
239  return SYS_ARCH_TIMEOUT;
240 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListHead
Definition: sys_arch.h:13
struct _Entry Entry
Definition: kefuncs.h:640
LONG NTSTATUS
Definition: precomp.h:26
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
Definition: dhcpd.h:245
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
KEVENT TerminationEvent
Definition: sys_arch.c:14
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CHAR Message[80]
Definition: alive.c:5
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define msg(x)
Definition: auth_time.c:54
unsigned long long UINT64
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
static sys_mbox_t mbox
Definition: tcpip.c:56
base of all file and directory entries
Definition: entries.h:82
#define Int32x32To64(a, b)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
KSPIN_LOCK Lock
Definition: sys_arch.h:12
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by sys_arch_mbox_tryfetch().

◆ sys_arch_mbox_tryfetch()

u32_t sys_arch_mbox_tryfetch ( sys_mbox_t mbox,
void **  msg 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
0 (milliseconds) if a message has been received or SYS_MBOX_EMPTY if the mailbox is empty

Definition at line 243 of file sys_arch.c.

244 {
246  return 0;
247  else
248  return SYS_MBOX_EMPTY;
249 }
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
Definition: sys_arch.c:182
#define SYS_MBOX_EMPTY
Definition: sys.h:83
#define msg(x)
Definition: auth_time.c:54
static sys_mbox_t mbox
Definition: tcpip.c:56

◆ sys_arch_protect()

void sys_arch_protect ( sys_prot_t lev)

Definition at line 38 of file sys_arch.c.

39 {
40  /* Preempt the dispatcher */
42 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

◆ sys_arch_sem_wait()

u32_t sys_arch_sem_wait ( sys_sem_t sem,
u32_t  timeout 
)

Wait for a semaphore for the specified timeout

Parameters
semthe semaphore to wait for
timeouttimeout in milliseconds to wait (0 = wait forever)
Returns
time (in milliseconds) waited for the semaphore or SYS_ARCH_TIMEOUT on timeout

Definition at line 91 of file sys_arch.c.

92 {
93  LARGE_INTEGER LargeTimeout, PreWaitTime, PostWaitTime;
94  UINT64 TimeDiff;
96  PVOID WaitObjects[] = {&sem->Event, &TerminationEvent};
97 
98  LargeTimeout.QuadPart = Int32x32To64(timeout, -10000);
99 
100  KeQuerySystemTime(&PreWaitTime);
101 
103  WaitObjects,
104  WaitAny,
105  Executive,
106  KernelMode,
107  FALSE,
108  timeout != 0 ? &LargeTimeout : NULL,
109  NULL);
110  if (Status == STATUS_WAIT_0)
111  {
112  KeQuerySystemTime(&PostWaitTime);
113  TimeDiff = PostWaitTime.QuadPart - PreWaitTime.QuadPart;
114  TimeDiff /= 10000;
115 
116  return TimeDiff;
117  }
118  else if (Status == STATUS_WAIT_1)
119  {
120  /* DON'T remove ourselves from the thread list! */
122 
123  /* We should never get here! */
124  ASSERT(FALSE);
125 
126  return 0;
127  }
128 
129  return SYS_ARCH_TIMEOUT;
130 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
LONG NTSTATUS
Definition: precomp.h:26
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
Definition: dhcpd.h:245
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:416
KEVENT TerminationEvent
Definition: sys_arch.c:14
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
static HANDLE sem
Definition: sync.c:677
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
unsigned long long UINT64
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define Int32x32To64(a, b)
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by sys_msleep().

◆ sys_arch_unprotect()

void sys_arch_unprotect ( sys_prot_t  lev)

Definition at line 45 of file sys_arch.c.

46 {
47  KeLowerIrql(lev);
48 }
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602

◆ sys_init()

void sys_init ( void  )

Definition at line 310 of file sys_arch.c.

311 {
314 
316 
318 
320  NULL,
321  NULL,
322  0,
323  sizeof(struct lwip_callback_msg),
325  0);
326 
328  NULL,
329  NULL,
330  0,
331  sizeof(QUEUE_ENTRY),
333  0);
334 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15
#define LWIP_QUEUE_TAG
Definition: rosip.h:12
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
Definition: rosip.h:17
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
KEVENT TerminationEvent
Definition: sys_arch.c:14
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:222
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define LWIP_MESSAGE_TAG
Definition: rosip.h:11
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static KSPIN_LOCK ThreadListLock
Definition: sys_arch.c:12
static LIST_ENTRY ThreadListHead
Definition: sys_arch.c:11

Referenced by lwip_init().

◆ sys_mbox_free()

void sys_mbox_free ( sys_mbox_t mbox)

Delete an mbox

Parameters
mboxmbox to delete

Definition at line 157 of file sys_arch.c.

158 {
160 
162 }
LIST_ENTRY ListHead
Definition: sys_arch.h:13
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
void sys_mbox_set_invalid(sys_mbox_t *mbox)
Definition: sys_arch.c:151
static sys_mbox_t mbox
Definition: tcpip.c:56

◆ sys_mbox_new()

err_t sys_mbox_new ( sys_mbox_t mbox,
int  size 
)

Create a new mbox of specified size

Parameters
mboxpointer to the mbox to create
size(miminum) number of messages in this mbox
Returns
ERR_OK if successful, another err_t otherwise

Definition at line 133 of file sys_arch.c.

134 {
136 
138 
140 
141  mbox->Valid = 1;
142 
143  return ERR_OK;
144 }
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListHead
Definition: sys_arch.h:13
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
#define ERR_OK
Definition: err.h:52
int Valid
Definition: sys_arch.h:15
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static sys_mbox_t mbox
Definition: tcpip.c:56
KSPIN_LOCK Lock
Definition: sys_arch.h:12

Referenced by tcpip_init().

◆ sys_mbox_post()

void sys_mbox_post ( sys_mbox_t mbox,
void msg 
)

Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Definition at line 165 of file sys_arch.c.

166 {
167  PLWIP_MESSAGE_CONTAINER Container;
168 
169  Container = ExAllocatePool(NonPagedPool, sizeof(*Container));
170  ASSERT(Container);
171 
172  Container->Message = msg;
173 
175  &Container->ListEntry,
176  &mbox->Lock);
177 
179 }
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListEntry
Definition: sys_arch.h:25
LIST_ENTRY ListHead
Definition: sys_arch.h:13
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static sys_mbox_t mbox
Definition: tcpip.c:56
KSPIN_LOCK Lock
Definition: sys_arch.h:12

Referenced by sys_mbox_trypost(), and tcpip_callback_with_block().

◆ sys_mbox_set_invalid()

void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid so that sys_mbox_valid returns 0

Definition at line 151 of file sys_arch.c.

152 {
153  mbox->Valid = 0;
154 }
int Valid
Definition: sys_arch.h:15
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by sys_mbox_free().

◆ sys_mbox_trypost()

err_t sys_mbox_trypost ( sys_mbox_t mbox,
void msg 
)

Try to post a message to an mbox - may fail if full or ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Definition at line 252 of file sys_arch.c.

253 {
255 
256  return ERR_OK;
257 }
#define ERR_OK
Definition: err.h:52
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:165
#define msg(x)
Definition: auth_time.c:54
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

◆ sys_mbox_valid()

int sys_mbox_valid ( sys_mbox_t mbox)

Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid

Definition at line 146 of file sys_arch.c.

147 {
148  return mbox->Valid;
149 }
int Valid
Definition: sys_arch.h:15
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

◆ sys_now()

u32_t sys_now ( void  )

Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.

Definition at line 28 of file sys_arch.c.

29 {
30  LARGE_INTEGER CurrentTime;
31 
32  KeQuerySystemTime(&CurrentTime);
33 
34  return (CurrentTime.QuadPart - StartTime.QuadPart) / 10000;
35 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
LONGLONG QuadPart
Definition: typedefs.h:112

◆ sys_sem_free()

void sys_sem_free ( sys_sem_t sem)

Delete a semaphore

Parameters
semsemaphore to delete

Definition at line 77 of file sys_arch.c.

78 {
79  /* No op (allocated in stack) */
80 
82 }
void sys_sem_set_invalid(sys_sem_t *sem)
Definition: sys_arch.c:71
static HANDLE sem
Definition: sync.c:677

Referenced by sys_msleep().

◆ sys_sem_new()

err_t sys_sem_new ( sys_sem_t sem,
u8_t  count 
)

Create a new semaphore

Parameters
sempointer to the semaphore to create
countinitial count of the semaphore
Returns
ERR_OK if successful, another err_t otherwise

Definition at line 51 of file sys_arch.c.

52 {
53  ASSERT(count == 0 || count == 1);
54 
55  /* It seems lwIP uses the semaphore implementation as either a completion event or a lock
56  * so I optimize for this case by using a synchronization event and setting its initial state
57  * to signalled for a lock and non-signalled for a completion event */
58 
60 
61  sem->Valid = 1;
62 
63  return ERR_OK;
64 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define ERR_OK
Definition: err.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static HANDLE sem
Definition: sync.c:677

Referenced by sys_msleep().

◆ sys_sem_set_invalid()

void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid so that sys_sem_valid returns 0

Definition at line 71 of file sys_arch.c.

72 {
73  sem->Valid = 0;
74 }
static HANDLE sem
Definition: sync.c:677

Referenced by sys_sem_free().

◆ sys_sem_signal()

void sys_sem_signal ( sys_sem_t sem)

Signals a semaphore

Parameters
semthe semaphore to signal

Definition at line 85 of file sys_arch.c.

86 {
88 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
static HANDLE sem
Definition: sync.c:677
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ sys_sem_valid()

int sys_sem_valid ( sys_sem_t sem)

Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid

Definition at line 66 of file sys_arch.c.

67 {
68  return sem->Valid;
69 }
static HANDLE sem
Definition: sync.c:677

◆ sys_shutdown()

void sys_shutdown ( void  )

Definition at line 337 of file sys_arch.c.

338 {
339  PLIST_ENTRY CurrentEntry;
340  thread_t Container;
341 
342  /* Set the termination event */
344 
345  /* Loop through the thread list and wait for each to die */
346  while ((CurrentEntry = ExInterlockedRemoveHeadList(&ThreadListHead, &ThreadListLock)))
347  {
348  Container = CONTAINING_RECORD(CurrentEntry, struct _thread_t, ListEntry);
349 
350  if (Container->ThreadFunction)
351  {
352  KeWaitForSingleObject(Container->Handle,
353  Executive,
354  KernelMode,
355  FALSE,
356  NULL);
357 
358  ZwClose(Container->Handle);
359  }
360  }
361 
364 }
HANDLE Handle
Definition: sys_arch.c:22
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
smooth NULL
Definition: ftsmooth.c:416
KEVENT TerminationEvent
Definition: sys_arch.c:14
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:117
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
void(* ThreadFunction)(void *arg)
Definition: sys_arch.c:23
static KSPIN_LOCK ThreadListLock
Definition: sys_arch.c:12
static LIST_ENTRY ThreadListHead
Definition: sys_arch.c:11
#define IO_NO_INCREMENT
Definition: iotypes.h:566
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:174

Referenced by LibIPShutdown().

◆ sys_thread_new()

sys_thread_t sys_thread_new ( const char name,
lwip_thread_fn  thread,
void arg,
int  stacksize,
int  prio 
)

The only thread function: Creates a new thread

Parameters
namehuman-readable name for the thread (used for debugging purposes)
threadthread-function
argparameter passed to 'thread'
stacksizestack size in bytes for the new thread (may be ignored by ports)
priopriority of the new thread (may be ignored by ports)

Definition at line 280 of file sys_arch.c.

281 {
282  thread_t Container;
284 
285  Container = ExAllocatePool(NonPagedPool, sizeof(*Container));
286  if (!Container)
287  return 0;
288 
289  Container->ThreadFunction = thread;
290  Container->ThreadContext = arg;
291 
292  Status = PsCreateSystemThread(&Container->Handle,
294  NULL,
295  NULL,
296  NULL,
298  Container);
299 
300  if (!NT_SUCCESS(Status))
301  {
302  ExFreePool(Container);
303  return 0;
304  }
305 
306  return 0;
307 }
HANDLE Handle
Definition: sys_arch.c:22
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
void * ThreadContext
Definition: sys_arch.c:24
LONG NTSTATUS
Definition: precomp.h:26
void * arg
Definition: msvc.h:10
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static HANDLE thread
Definition: service.c:33
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
void(* ThreadFunction)(void *arg)
Definition: sys_arch.c:23
VOID NTAPI LwipThreadMain(PVOID Context)
Definition: sys_arch.c:261
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by tcpip_init().

Variable Documentation

◆ MessageLookasideList

◆ QueueEntryLookasideList

◆ StartTime

◆ TerminationEvent

KEVENT TerminationEvent

◆ ThreadListHead

LIST_ENTRY ThreadListHead
static

Definition at line 11 of file sys_arch.c.

Referenced by LwipThreadMain(), NtQueryInformationThread(), sys_init(), and sys_shutdown().

◆ ThreadListLock

KSPIN_LOCK ThreadListLock
static

Definition at line 12 of file sys_arch.c.

Referenced by LwipThreadMain(), sys_init(), and sys_shutdown().