Skip to content

Commit 10a3cd2

Browse files
committed
A much simpler implementation of linux's copy_from/to_user.
Windows allows page fault in kernel space and the device control runs in user context. So let the OS handle the copy for us.
1 parent d6e7913 commit 10a3cd2

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

ntkrutils.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,8 @@ static __inline size_t copy_from_user(void *dst, const void *src, size_t size)
965965
static __inline size_t __copy_user(void *dst, const void *src, size_t size,
966966
int from)
967967
{
968-
PMDL lock_mdl;
969968
int clac = 0;
970969

971-
lock_mdl = IoAllocateMdl(from? src : dst, size, FALSE, FALSE, NULL);
972-
if (!lock_mdl)
973-
return size;
974-
975-
if (!__MmProbeAndLockPages(lock_mdl, UserMode, IoWriteAccess)) {
976-
IoFreeMdl(lock_mdl);
977-
return size;
978-
}
979-
980970
/*
981971
* If Windows turns on SMAP, we need set AC flag before accessing
982972
* user addr. However, since we do not know Windows's logic for AC
@@ -993,14 +983,18 @@ static __inline size_t __copy_user(void *dst, const void *src, size_t size,
993983
} else
994984
local_irq_enable();
995985
}
996-
memcpy(dst, src, size);
986+
987+
__try {
988+
memcpy(dst, src, size);
989+
} __except (EXCEPTION_EXECUTE_HANDLER) {
990+
return size;
991+
}
992+
997993
if (clac) {
998994
_clac();
999995
local_irq_enable();
1000996
}
1001997

1002-
MmUnlockPages(lock_mdl);
1003-
IoFreeMdl(lock_mdl);
1004998
return 0;
1005999
}
10061000

0 commit comments

Comments
 (0)