我想使用copystr()将字符串复制到本地缓冲区,但一直遇到问题。我要复制的字符串是来自/usr/src/sys/kern/vfs_syscalls.c中VFS函数sys_chdir的uap->路径。这是我尝试过的一件事:
#define USR_MAX_LEN 22
char mypath[USR_MAX_LEN + 1];
size_t len = USR_MAX_LEN;
size_t done;
copystr(uap->path, mypath, len, &done);
不幸的是,当我这样做时,我最终得到内核恐慌和随后的崩溃。它总是在copystr()崩溃:
(kgdb) list *0xffffffff80c8c860
0xffffffff80c8c860 is at /usr/src/sys/amd64/amd64/support.S:606.
601 cld
602 1:
603 decq %rdx
604 jz 4f
605 lodsb
606 stosb
607 orb %al,%al
608 jnz 1b
609
610 /* Success -- 0 byte reached */
Current language: auto; currently minimal
(kgdb) bt
#0 doadump (textdump=<value optimized out>) at pcpu.h:219
#1 0xffffffff808af530 in kern_reboot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:447
#2 0xffffffff808af8f4 in panic (fmt=<value optimized out>) at /usr/src/sys/kern/kern_shutdown.c:754
#3 0xffffffff80c8e6d2 in trap_fatal (frame=<value optimized out>, eva=<value optimized out>)
at /usr/src/sys/amd64/amd64/trap.c:882
#4 0xffffffff80c8e9a9 in trap_pfault (frame=0xfffffe004e8ed9f0, usermode=0) at /usr/src/sys/amd64/amd64/trap.c:699
#5 0xffffffff80c8e136 in trap (frame=0xfffffe004e8ed9f0) at /usr/src/sys/amd64/amd64/trap.c:463
#6 0xffffffff80c753d2 in calltrap () at /usr/src/sys/amd64/amd64/exception.S:232
#7 0xffffffff80c8c860 in copystr () at /usr/src/sys/amd64/amd64/support.S:605
#8 0xffffffff80950e64 in sys_chdir (td=0xfffff80002782000, uap=0xfffffe004e8edb80) at /usr/src/sys/kern/vfs_syscalls.c:838
#9 0xffffffff80c8efc7 in amd64_syscall (td=0xfffff80002782000, traced=0) at subr_syscall.c:134
#10 0xffffffff80c756bb in Xfast_syscall () at /usr/src/sys/amd64/amd64/exception.S:391
#11 0x0000000800d1fc0a in ?? ()
Previous frame inner to this frame (corrupt stack?)
(kgdb)
我在这里做错了什么?据我所知,我的数据类型满足copystr手册页中的数据类型所以我不认为它是那样的。任何帮助表示赞赏。感谢。
答案 0 :(得分:0)
copystr()函数复制一个以NUL结尾的字符串,最多为len 从内核空间地址kfaddr到内核空间地址的字节长, kdaddr 强>
但看起来您正在尝试从用户空间复制。在这种情况下,我认为您正在寻找copyin
或copyinstr
。