Re: Using sysarch specific syscalls in assembly?
On Fri Sep 2 05, John Baldwin wrote: On Friday 12 August 2005 07:22 pm, alexander wrote: On Thu Aug 11 05, alexander wrote: Hmm...very odd. Should I file a bug report about this problem? Alright. I submitted a PR and got a suggestion on how to solve the problem by Bruce Evans. Could somebody (apart from me) try out his workaround and see if it works? Thx a bunch. Could you please try the patch I posted to the PR? -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org /usr/src/sys/i386/i386/machdep.c:1276: warning: redundant redeclaration of \ 'private_tss' ./machine/pcb_ext.h:47: warning: previous declaration of 'private_tss' was here *** Error code 1 Stop in /usr/obj/usr/src/sys/ARUNDEL. *** Error code 1 Stop in /usr/src. *** Error code 1 Stop in /usr/src. machdep.c : \ $FreeBSD: src/sys/i386/i386/machdep.c,v 1.616.2.1 2005/07/28 03:30:53 jkoshy \ Exp $ pcb_ext.h : \ $FreeBSD: src/sys/i386/include/pcb_ext.h,v 1.9 2002/03/20 05:48:58 alfred Exp $ Cheers. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Friday 12 August 2005 07:22 pm, alexander wrote: On Thu Aug 11 05, alexander wrote: Hmm...very odd. Should I file a bug report about this problem? Alright. I submitted a PR and got a suggestion on how to solve the problem by Bruce Evans. Could somebody (apart from me) try out his workaround and see if it works? Thx a bunch. Could you please try the patch I posted to the PR? -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Thu Aug 11 05, alexander wrote: Hmm...very odd. Should I file a bug report about this problem? Alright. I submitted a PR and got a suggestion on how to solve the problem by Bruce Evans. Could somebody (apart from me) try out his workaround and see if it works? Thx a bunch. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Wed Aug 10 05, Daan Vreeken [PA4DAN] wrote: I can confirm that. I have tested the program on 5.4-RELEASE here. Testing your program (I called it p) 10 times gives the following output : [EMAIL PROTECTED] for a in 0 1 2 3 4 5 6 7 8 9;do echo starting p; ./p ;done starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p [EMAIL PROTECTED] However, opening /dev/io to gain IO privileges instead of using sysarch always works. I tested that with the following program : #include fcntl.h static inline void outb (unsigned short int port, unsigned char val) { __asm__ volatile (outb %0,%1\n::a (val), d (port) ); } int main (void) { if (open(/dev/io, O_RDONLY) == -1) { printf(EEK!\n); exit(1); } outb(0x378, 0xff); } --- EOF --- grtz, Daan Hmm...very odd. Should I file a bug report about this problem? ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
I tried to write a little C app that uses sysarch and i386_set_ioperm to gain access to certain ports and after a bit of testing I'm pretty sure that there is a bug or better a timing issue with the sysarch syscall or the i386_set_ioperm procedure. Please have a look at the following code: //CODE START #include machine/sysarch.h int main (void) { unsigned int port = 0x378; unsigned char val = 'A'; int number = 4; static inline void outb (unsigned short int port, unsigned char val) { __asm__ volatile (outb %0,%1\n::a (val), d (port) ); } struct i386_ioperm_args { unsigned int start; unsigned int length; int enable; }; struct i386_ioperm_args *args; struct i386_ioperm_args arg; args = arg; args-start = 0x378; args-length = 1; args-enable = 1; if(sysarch(number,args) == 0) { /* int i; for(i=0; i 100; i++) { printf(DELAY\n); } */ outb(0x378,0xF); exit(0); } else { printf(Error during syscall); exit(1); } } //eof //CODE END On my PC this code will cause a core dump (Bus error: 10). If I however add a delay (the code that's commented out) the app will end without any errors. It seems FBSD needs some time to set the I/O permissions for an app. Can somebody test this code on his computer? Maybe this is a bug in RELENG_6. I'm running: FreeBSD 6.0-BETA1 #0: Mon Jul 18 03:00:45 CEST 2005 Thx a bunch. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Wednesday 10 August 2005 15:09, alexander wrote: I tried to write a little C app that uses sysarch and i386_set_ioperm to gain access to certain ports and after a bit of testing I'm pretty sure that there is a bug or better a timing issue with the sysarch syscall or the i386_set_ioperm procedure. Please have a look at the following code: //CODE START #include machine/sysarch.h int main (void) { unsigned int port = 0x378; unsigned char val = 'A'; int number = 4; static inline void outb (unsigned short int port, unsigned char val) { __asm__ volatile (outb %0,%1\n::a (val), d (port) ); } struct i386_ioperm_args { unsigned int start; unsigned int length; int enable; }; struct i386_ioperm_args *args; struct i386_ioperm_args arg; args = arg; args-start = 0x378; args-length = 1; args-enable = 1; if(sysarch(number,args) == 0) { /* int i; for(i=0; i 100; i++) { printf(DELAY\n); } */ outb(0x378,0xF); exit(0); } else { printf(Error during syscall); exit(1); } } //eof //CODE END On my PC this code will cause a core dump (Bus error: 10). If I however add a delay (the code that's commented out) the app will end without any errors. It seems FBSD needs some time to set the I/O permissions for an app. Can somebody test this code on his computer? Maybe this is a bug in RELENG_6. I'm running: FreeBSD 6.0-BETA1 #0: Mon Jul 18 03:00:45 CEST 2005 I can confirm that. I have tested the program on 5.4-RELEASE here. Testing your program (I called it p) 10 times gives the following output : [EMAIL PROTECTED] for a in 0 1 2 3 4 5 6 7 8 9;do echo starting p; ./p ;done starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p starting p Bus error (core dumped) starting p Bus error (core dumped) starting p starting p [EMAIL PROTECTED] However, opening /dev/io to gain IO privileges instead of using sysarch always works. I tested that with the following program : #include fcntl.h static inline void outb (unsigned short int port, unsigned char val) { __asm__ volatile (outb %0,%1\n::a (val), d (port) ); } int main (void) { if (open(/dev/io, O_RDONLY) == -1) { printf(EEK!\n); exit(1); } outb(0x378, 0xff); } --- EOF --- grtz, Daan ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Mon, 8 Aug 2005, ari edelkind wrote: On 8/8/2005, alexander [EMAIL PROTECTED] wrote: [...] i386_set_ioperm(2) states that this procedure is a system call. So it should be easily accessable through assembly language and it's specific syscall id. Unfortunately I wasn't able to find the syscall id in any of the syscalls.master files that are part of the source tree. machine/sysarch.h states that this is a sysarch specific syscall for i386 (hence the i386_*). The following definitions are being made: #define I386_GET_IOPERM 3 #define I386_SET_IOPERM 4 These syscall numbers however are already taken by read(2) and write(2). So how can I make use of these i386 specific syscalls? Is it even possible? If you're unsure of how a function is called, you can always check the C library, under 'src/lib/libc/'. I won't repeat john baldwin's answer, but it's exactly what you'd find there. That said, C library calls are no more difficult to perform from assembly language than system calls, so long as you're willing to link in the standard C library. If you're trying to be more portable, then unless you have specific reasons for not doing so, perhaps it's something you'd like to consider. In general, it is much preferable that applications link against libc to get the system call stubs than that they directly invoke system calls. That way, if compatibility interfaces are introduced, etc, the application will continue to function. For example, there was at one point a migration away from explicit system calls to set certain kernel parameters, such as hostname and domainname, towards using sysctl, with the system calls being marked obsolete. The C library still provides a sethostname() interface, which is actually a wrapper in user space around sysctl(). So invoking the C function provided by libc for a system call will generally be preferred, even if the originating code is assembly. Robert N M Watson ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Tue Aug 9 05, Robert Watson wrote: In general, it is much preferable that applications link against libc to get the system call stubs than that they directly invoke system calls. That way, if compatibility interfaces are introduced, etc, the application will continue to function. For example, there was at one point a migration away from explicit system calls to set certain kernel parameters, such as hostname and domainname, towards using sysctl, with the system calls being marked obsolete. The C library still provides a sethostname() interface, which is actually a wrapper in user space around sysctl(). So invoking the C function provided by libc for a system call will generally be preferred, even if the originating code is assembly. Robert N M Watson Thx. I'll try that. Unfortunately I'm experiencing some problems right now. From time to time I'm getting a 'Bus error: 10 (core dumped)' This however appears randomly. One time I run the app everything works fine,the next time it core dumps. Are there any errors in my code? %define SYSARCH 165 ; syscall sysarch(2) %define I386_SET_IOPERM 4 ; i386_set_ioperm(2) number ioperm_args dd 378h dd 3 dd 1 OpenIO: push byte ioperm_args push dword I386_SET_IOPERM mov eax,SYSARCH Call _syscall lea esp,[esp+8] ret I'm really confused by the fact that it works sometimes and sometimes it doesn't. I loaded the app into ddd and found more oddities. When I set a breakpoint before the first in/out and then hit continue everything works allright. However when I set a breakpoint after the first in/out the app core dumps with a bus error. Any ideas? Maybe a timing issue? I added a i386_get_ioperm(2) call just to check if the permsissions are being handled correctly. i386_get_ioperm(2) tells me everything is allright. Port range and enable argument are set according to my specs in ioperm_args. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Tue Aug 9 05, alexander wrote: Any ideas? Maybe a timing issue? Ehmm...can anybody explain the following to me? out dx,al ; - bus error mov ecx,0FFh .wait: nop loop .wait,ecx out dx,al ; - no bus error I'm clueless. :( ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Tuesday 09 August 2005 09:31 am, alexander wrote: On Tue Aug 9 05, Robert Watson wrote: In general, it is much preferable that applications link against libc to get the system call stubs than that they directly invoke system calls. That way, if compatibility interfaces are introduced, etc, the application will continue to function. For example, there was at one point a migration away from explicit system calls to set certain kernel parameters, such as hostname and domainname, towards using sysctl, with the system calls being marked obsolete. The C library still provides a sethostname() interface, which is actually a wrapper in user space around sysctl(). So invoking the C function provided by libc for a system call will generally be preferred, even if the originating code is assembly. Robert N M Watson Thx. I'll try that. Unfortunately I'm experiencing some problems right now. From time to time I'm getting a 'Bus error: 10 (core dumped)' This however appears randomly. One time I run the app everything works fine,the next time it core dumps. Are there any errors in my code? %define SYSARCH 165 ; syscall sysarch(2) %define I386_SET_IOPERM 4 ; i386_set_ioperm(2) number ioperm_args dd 378h dd 3 dd 1 OpenIO: push byte ioperm_args push dword I386_SET_IOPERM mov eax,SYSARCH Call _syscall lea esp,[esp+8] ret Just change this to: push byte ioperm_args ; this might be wrong, you need ; to be pushing a 32-bit pointer ; to the ioperm_args structure, not ; a byte push dword I386_SET_IOPERM call sysarch addl $8,%esp ret To use the sysarch() function in libc. -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On 8/9/2005, alexander [EMAIL PROTECTED] wrote: [...] Unfortunately I'm experiencing some problems right now. From time to time I'm getting a 'Bus error: 10 (core dumped)' This however appears randomly. One time I run the app everything works fine,the next time it core dumps. Are there any errors in my code? %define SYSARCH165 ; syscall sysarch(2) %define I386_SET_IOPERM 4 ; i386_set_ioperm(2) number ioperm_argsdd 378h dd 3 dd 1 OpenIO: push byte ioperm_args push dword I386_SET_IOPERM mov eax,SYSARCH Call _syscall [...] You need to push a _pointer_ to a structure as your second argument to sysarch(2). This means something more along the lines of: ioperm_args dd 378h dd 3 dd 1 argp dd ioperm_args [...] push dword argp push dword I386_SET_IOPERM [...] Get this wrong, and you'll have unpredictable results. ari ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Tue Aug 9 05, ari edelkind wrote: You need to push a _pointer_ to a structure as your second argument to sysarch(2). This means something more along the lines of: ioperm_args dd 378h dd 3 dd 1 argp dd ioperm_args [...] push dword argp push dword I386_SET_IOPERM [...] Get this wrong, and you'll have unpredictable results. ari Nope. That doesn't work. The carry flag is being set and eax is 16h, which is: [EINVAL] An invalid range was specified by the start or length arguments. (quoted from i386_set_ioperm(2)). Here is some data that might be usefull (cp from ddd): %esp = 0xbfbfea58 mem(%esp) = 0x0004 0x0804a214 mem(0x0804a214) = 0x0804a1fc mem(0x0804a1fc) = 0x03780x0004 0x0003 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Using sysarch specific syscalls in assembly?
Hi there. I wrote a program that needs to access I/O ports with the in/out machinecodes. To gain priviliges to do so I have opened /dev/io. Now somebody told me that I'd rather use i386_set_ioperm which will be much saver, because of the port range limitation. Plus it will make the program more portable because Linux does not have a /dev/io device node. i386_set_ioperm(2) states that this procedure is a system call. So it should be easily accessable through assembly language and it's specific syscall id. Unfortunately I wasn't able to find the syscall id in any of the syscalls.master files that are part of the source tree. machine/sysarch.h states that this is a sysarch specific syscall for i386 (hence the i386_*). The following definitions are being made: #define I386_GET_IOPERM 3 #define I386_SET_IOPERM 4 These syscall numbers however are already taken by read(2) and write(2). So how can I make use of these i386 specific syscalls? Is it even possible? Thx in advance. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Monday 08 August 2005 03:19 pm, alexander wrote: Hi there. I wrote a program that needs to access I/O ports with the in/out machinecodes. To gain priviliges to do so I have opened /dev/io. Now somebody told me that I'd rather use i386_set_ioperm which will be much saver, because of the port range limitation. Plus it will make the program more portable because Linux does not have a /dev/io device node. i386_set_ioperm(2) states that this procedure is a system call. So it should be easily accessable through assembly language and it's specific syscall id. Unfortunately I wasn't able to find the syscall id in any of the syscalls.master files that are part of the source tree. machine/sysarch.h states that this is a sysarch specific syscall for i386 (hence the i386_*). The following definitions are being made: #define I386_GET_IOPERM 3 #define I386_SET_IOPERM 4 These syscall numbers however are already taken by read(2) and write(2). So how can I make use of these i386 specific syscalls? Is it even possible? Thx in advance. You have to call the sysarch() system call. The first argument to it would be the operation (I386_GET_IOPERM, etc.). -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On Mon Aug 8 05, John Baldwin wrote: On Monday 08 August 2005 03:19 pm, alexander wrote: Hi there. I wrote a program that needs to access I/O ports with the in/out machinecodes. To gain priviliges to do so I have opened /dev/io. Now somebody told me that I'd rather use i386_set_ioperm which will be much saver, because of the port range limitation. Plus it will make the program more portable because Linux does not have a /dev/io device node. i386_set_ioperm(2) states that this procedure is a system call. So it should be easily accessable through assembly language and it's specific syscall id. Unfortunately I wasn't able to find the syscall id in any of the syscalls.master files that are part of the source tree. machine/sysarch.h states that this is a sysarch specific syscall for i386 (hence the i386_*). The following definitions are being made: #define I386_GET_IOPERM 3 #define I386_SET_IOPERM 4 These syscall numbers however are already taken by read(2) and write(2). So how can I make use of these i386 specific syscalls? Is it even possible? Thx in advance. You have to call the sysarch() system call. The first argument to it would be the operation (I386_GET_IOPERM, etc.). -- John Baldwin [EMAIL PROTECTED]http://www.FreeBSD.org/~jhb/ Power Users Use the Power to Serve = http://www.FreeBSD.org Thx a lot. That worked. ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Using sysarch specific syscalls in assembly?
On 8/8/2005, alexander [EMAIL PROTECTED] wrote: [...] i386_set_ioperm(2) states that this procedure is a system call. So it should be easily accessable through assembly language and it's specific syscall id. Unfortunately I wasn't able to find the syscall id in any of the syscalls.master files that are part of the source tree. machine/sysarch.h states that this is a sysarch specific syscall for i386 (hence the i386_*). The following definitions are being made: #define I386_GET_IOPERM 3 #define I386_SET_IOPERM 4 These syscall numbers however are already taken by read(2) and write(2). So how can I make use of these i386 specific syscalls? Is it even possible? If you're unsure of how a function is called, you can always check the C library, under 'src/lib/libc/'. I won't repeat john baldwin's answer, but it's exactly what you'd find there. That said, C library calls are no more difficult to perform from assembly language than system calls, so long as you're willing to link in the standard C library. If you're trying to be more portable, then unless you have specific reasons for not doing so, perhaps it's something you'd like to consider. ari ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]