ndis: fix ugly code

Paul B Mahol onemda at gmail.com
Wed Oct 6 00:27:51 UTC 2010


On 10/5/10, Julian Elischer <julian at freebsd.org> wrote:
>   On 10/5/10 1:19 PM, Paul B Mahol wrote:
>> Hi,
>>
>> If clang did not complain, I would probbaly never spot it.
>>
>> Patch attached.
>
> personally I think you could use kproc_kthread_add so that a single
> NDIS process had three threads.

Patch attached. Now we have single "ndis" kernel process with own threads.
-------------- next part --------------
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 714fcd8..eafbb7c 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -254,6 +254,7 @@ static int32_t KeDelayExecutionThread(uint8_t, uint8_t, int64_t *);
 static int32_t KeSetPriorityThread(struct thread *, int32_t);
 static void dummy(void);
 
+static struct proc *ndisproc;
 static struct mtx ntoskrnl_dispatchlock;
 static struct mtx ntoskrnl_interlock;
 static kspin_lock ntoskrnl_cancellock;
@@ -270,7 +271,7 @@ ntoskrnl_libinit()
 {
 	image_patch_table	*patch;
 	int			error;
-	struct proc		*p;
+	struct thread		*t;
 	kdpc_queue		*kq;
 	callout_entry		*e;
 	int			i;
@@ -320,8 +321,9 @@ ntoskrnl_libinit()
 #endif
 		kq = kq_queues + i;
 		kq->kq_cpu = i;
-		error = kproc_create(ntoskrnl_dpc_thread, kq, &p,
-		    RFHIGHPID, NDIS_KSTACK_PAGES, "Windows DPC %d", i);
+		error = kproc_kthread_add(ntoskrnl_dpc_thread, kq,
+		    &ndisproc, &t, RFHIGHPID, NDIS_KSTACK_PAGES, "ndis",
+		    "Windows DPC %d", i);
 		if (error)
 			panic("failed to launch DPC thread");
 	}
@@ -332,8 +334,9 @@ ntoskrnl_libinit()
 
 	for (i = 0; i < WORKITEM_THREADS; i++) {
 		kq = wq_queues + i;
-		error = kproc_create(ntoskrnl_workitem_thread, kq, &p,
-		    RFHIGHPID, NDIS_KSTACK_PAGES, "Windows Workitem %d", i);
+		error = kproc_kthread_add(ntoskrnl_workitem_thread, kq,
+		    &ndisproc, &t, RFHIGHPID, NDIS_KSTACK_PAGES, "ndis",
+		    "Windows Workitem %d", i);
 		if (error)
 			panic("failed to launch workitem thread");
 	}
@@ -2701,7 +2704,7 @@ ntoskrnl_workitem_thread(arg)
 #if __FreeBSD_version < 502113
 	mtx_lock(&Giant);
 #endif
-	kproc_exit(0);
+	kthread_exit();
 	return; /* notreached */
 }
 
@@ -3380,7 +3383,7 @@ PsCreateSystemThread(handle, reqaccess, objattrs, phandle,
 {
 	int			error;
 	thread_context		*tc;
-	struct proc		*p;
+	struct thread		*t;
 
 	tc = malloc(sizeof(thread_context), M_TEMP, M_NOWAIT);
 	if (tc == NULL)
@@ -3389,15 +3392,16 @@ PsCreateSystemThread(handle, reqaccess, objattrs, phandle,
 	tc->tc_thrctx = thrctx;
 	tc->tc_thrfunc = thrfunc;
 
-	error = kproc_create(ntoskrnl_thrfunc, tc, &p,
-	    RFHIGHPID, NDIS_KSTACK_PAGES, "Windows Kthread %d", ntoskrnl_kth);
+	error = kproc_kthread_add(ntoskrnl_thrfunc, tc, &ndisproc, &t,
+	    RFHIGHPID, NDIS_KSTACK_PAGES, "ndis",
+	    "Windows Kthread %d", ntoskrnl_kth);
 
 	if (error) {
 		free(tc, M_TEMP);
 		return (STATUS_INSUFFICIENT_RESOURCES);
 	}
 
-	*handle = p;
+	*handle = t;
 	ntoskrnl_kth++;
 
 	return (STATUS_SUCCESS);
@@ -3432,7 +3436,7 @@ PsTerminateSystemThread(status)
 #if __FreeBSD_version < 502113
 	mtx_lock(&Giant);
 #endif
-	kproc_exit(0);
+	kthread_exit();
 	return (0);	/* notreached */
 }
 
@@ -3740,7 +3744,7 @@ ntoskrnl_dpc_thread(arg)
 #if __FreeBSD_version < 502113
 	mtx_lock(&Giant);
 #endif
-	kproc_exit(0);
+	kthread_exit();
 	return; /* notreached */
 }
 


More information about the freebsd-net mailing list