linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Linux doesn't follow x86/x86-64 ABI wrt direction flag
@ 2008-03-05 15:30 Aurelien Jarno
  2008-03-05 16:00 ` H. Peter Anvin
                   ` (2 more replies)
  0 siblings, 3 replies; 98+ messages in thread
From: Aurelien Jarno @ 2008-03-05 15:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: gcc

Hi all,

Since version 4.3, gcc changed its behaviour concerning the x86/x86-64 
ABI and the direction flag, that is it now assumes that the direction 
flag is cleared at the entry of a function and it doesn't clear once 
more if needed.

This causes some problems with the Linux kernel which does not clear
the direction flag when entering a signal handler. The small code below
(for x86-64) demonstrates that. 

If the signal handler is using code that need the direction flag cleared
(for example bzero() or memset()), the code is incorrectly executed.

I guess this has to be fixed on the kernel side, but also gcc-4.3 could
revert back to the old behaviour, that is clearing the direction flag
when entering a routine that touches it until most people are running a
fixed kernel.

Kind regards,
Aurelien

[1] http://gcc.gnu.org/gcc-4.3/changes.html


#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>

void handler(int signal) {
	uint64_t rflags;
	
	asm volatile("pushfq ; popq %0" : "=g" (rflags));

	if (rflags & (1 << 10))
		printf("DF = 1\n");
	else
		printf("DF = 0\n");
}

int main() {
	signal(SIGUSR1, handler);

	while(1)
	{
		asm volatile("std\r\n");
	}

	return 0;
}

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net

^ permalink raw reply	[flat|nested] 98+ messages in thread

end of thread, other threads:[~2008-03-08 19:12 UTC | newest]

Thread overview: 98+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-05 15:30 Linux doesn't follow x86/x86-64 ABI wrt direction flag Aurelien Jarno
2008-03-05 16:00 ` H. Peter Anvin
2008-03-05 19:58   ` Joe Buck
2008-03-05 20:23     ` Aurelien Jarno
2008-03-05 20:38       ` Michael Matz
2008-03-05 20:42         ` Joe Buck
2008-03-05 20:49           ` Jan Hubicka
2008-03-05 21:02             ` Michael Matz
2008-03-05 21:20               ` RELEASE BLOCKER: " Joe Buck
2008-03-05 21:32                 ` Richard Guenther
2008-03-05 21:34                   ` H. Peter Anvin
2008-03-05 21:40                     ` Richard Guenther
2008-03-05 22:16                       ` David Miller
2008-03-05 22:37                         ` Joe Buck
2008-03-05 22:51                         ` Michael Matz
2008-03-05 22:58                           ` H. Peter Anvin
2008-03-05 23:07                             ` Michael Matz
2008-03-05 23:10                               ` David Miller
2008-03-05 23:16                                 ` Joe Buck
2008-03-05 23:12                               ` Olivier Galibert
2008-03-05 21:43                     ` Joe Buck
2008-03-05 21:44                       ` Richard Guenther
     [not found]                     ` <738B72DB-A1D6-43F8-813A-E49688D05771@apple.com>
2008-03-05 21:59                       ` Michael Matz
2008-03-05 22:13                         ` Adrian Bunk
2008-03-05 22:21                           ` David Miller
2008-03-05 23:13                           ` Olivier Galibert
2008-03-06  0:36                         ` Chris Lattner
2008-03-06  0:47                           ` H. Peter Anvin
     [not found]                             ` <578FCA7D-D7A6-44F6-9310-4A97C13CDCBE@apple.com>
2008-03-06  1:12                               ` H. Peter Anvin
2008-03-06  9:17                                 ` Jakub Jelinek
2008-03-06 13:51                                 ` Olivier Galibert
2008-03-06 14:03                                   ` Paolo Bonzini
2008-03-06 14:12                                     ` Olivier Galibert
2008-03-06 14:15                                       ` Andrew Haley
2008-03-06 17:58                                       ` Joe Buck
2008-03-06 18:10                                         ` Olivier Galibert
2008-03-06 18:13                                           ` Paolo Bonzini
2008-03-06 18:31                                             ` Jack Lloyd
2008-03-06 18:35                                               ` Andrew Pinski
2008-03-06 19:44                                                 ` Paolo Bonzini
2008-03-06 19:43                                               ` Paolo Bonzini
2008-03-06 20:16                                                 ` Jack Lloyd
2008-03-06 21:37                                                   ` Artur Skawina
2008-03-06 15:09                                   ` Robert Dewar
2008-03-06 15:37                                   ` NightStrike
2008-03-06 15:43                                     ` H.J. Lu
2008-03-06 15:50                                       ` H. Peter Anvin
2008-03-06 16:23                                         ` Jakub Jelinek
2008-03-06 16:27                                           ` İsmail Dönmez
2008-03-06 16:58                                           ` H.J. Lu
2008-03-06 17:06                                             ` H. Peter Anvin
2008-03-06 17:14                                               ` H.J. Lu
2008-03-06 17:17                                                 ` H. Peter Anvin
2008-03-06 17:34                                                   ` H.J. Lu
2008-03-06 19:35                                                     ` Robert Dewar
2008-03-06 17:18                                                 ` Robert Dewar
2008-03-06 17:19                                                   ` H. Peter Anvin
2008-03-06 19:25                                                     ` Robert Dewar
2008-03-06 20:37                                                       ` H. Peter Anvin
2008-03-07  8:28                                                       ` Florian Weimer
2008-03-07  8:00                                                     ` Andreas Jaeger
2008-03-06 15:57                                     ` Robert Dewar
2008-03-06 16:29                                       ` Paolo Bonzini
2008-03-06 17:18                                       ` H. Peter Anvin
2008-03-06 16:14                                   ` Artur Skawina
2008-03-06  0:49                           ` Aurelien Jarno
2008-03-05 22:05                       ` H. Peter Anvin
2008-03-06  2:11                         ` Krzysztof Halasa
2008-03-06  8:44                     ` Andi Kleen
2008-03-06  9:01                       ` Jakub Jelinek
2008-03-06 15:20                         ` H. Peter Anvin
2008-03-05 21:45                   ` Aurelien Jarno
2008-03-05 21:43                 ` Andrew Pinski
2008-03-05 21:43                 ` Michael Matz
2008-03-05 22:12                   ` Joe Buck
2008-03-05 22:17                   ` David Miller
2008-03-05 23:17                   ` Olivier Galibert
2008-03-05 23:21                     ` David Daney
2008-03-06 14:06                       ` Olivier Galibert
2008-03-08 19:10                         ` Alexandre Oliva
2008-03-05 21:07             ` H. Peter Anvin
2008-03-05 20:44         ` H. Peter Anvin
2008-03-05 20:52           ` Aurelien Jarno
2008-03-05 21:23             ` David Miller
2008-03-06  9:53             ` Andrew Haley
2008-03-06 11:45               ` Andi Kleen
2008-03-06 12:06                 ` Richard Guenther
2008-03-06 17:34                   ` Joe Buck
2008-03-06 20:54                     ` Richard Guenther
2008-03-06 20:56                       ` H. Peter Anvin
2008-03-06 22:06                         ` Andi Kleen
2008-03-07  4:56                           ` Chris Lattner
2008-03-07 14:09                           ` Michael Matz
2008-03-06  9:45       ` Mikael Pettersson
2008-03-05 16:56 ` H.J. Lu
2008-03-05 18:14 ` [PATCH] x86: Clear DF before calling signal handler Aurelien Jarno
2008-03-05 18:17   ` H. Peter Anvin
2008-03-06  9:21   ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).