From unknown Sat Jun 21 12:24:17 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8298: 'volatile' needed for local variables around vfork Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Mar 2011 04:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8298 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 8298@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.13005959934897 (code B ref -1); Sun, 20 Mar 2011 04:40:02 +0000 Received: (at submit) by debbugs.gnu.org; 20 Mar 2011 04:39:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1AQi-0001Gw-Dg for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1AQf-0001Gj-Cj for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1AQZ-0002NC-Dp for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:44 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:33643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1AQZ-0002N8-BM for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:43 -0400 Received: from [140.186.70.92] (port=37092 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1AQY-0002l5-88 for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1AQW-0002Mq-Mt for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:42 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:33086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1AQW-0002LY-5s for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:40 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 3EB6839E8116 for ; Sat, 19 Mar 2011 21:39:32 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aphfXJVoT+jK for ; Sat, 19 Mar 2011 21:39:31 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 46FD439E80DB for ; Sat, 19 Mar 2011 21:39:31 -0700 (PDT) Message-ID: <4D858502.8050800@cs.ucla.edu> Date: Sat, 19 Mar 2011 21:39:30 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 199.232.76.165 X-Spam-Score: -4.6 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) In three places, GNU Emacs assumes that a local variable is preserved after a successful vfork, but on some architectures these variables may be clobbered. (I found this problem by compiling with gcc -Wclobbered.) I plan to address this problem with the following patch: 2011-03-19 Paul Eggert * callproc.c (Fcall_process): Use 'volatile' to avoid vfork clobbering. * process.c (create_process): Likewise. * sysdep.c (sys_subshell): Likewise. Previously, the sys_subshell 'volatile' was incorrectly IF_LINTted out. === modified file 'src/callproc.c' --- src/callproc.c 2011-03-18 04:45:18 +0000 +++ src/callproc.c 2011-03-18 05:56:46 +0000 @@ -180,7 +180,7 @@ (int nargs, register Lisp_Object *args) { Lisp_Object infile, buffer, current_dir, path; - int display_p; + volatile int display_p_volatile; int fd[2]; int filefd; register int pid; @@ -190,6 +190,7 @@ int bufsize = CALLPROC_BUFFER_SIZE_MIN; int count = SPECPDL_INDEX (); + const unsigned char **volatile new_argv_volatile; register const unsigned char **new_argv; /* File to use for stderr in the child. t means use same as standard output. */ @@ -343,7 +344,7 @@ UNGCPRO; } - display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); + display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]); filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); if (filefd < 0) @@ -371,7 +372,7 @@ && SREF (path, 1) == ':') path = Fsubstring (path, make_number (2), Qnil); - new_argv = (const unsigned char **) + new_argv_volatile = new_argv = (const unsigned char **) alloca (max (2, nargs - 2) * sizeof (char *)); if (nargs > 4) { @@ -542,6 +543,8 @@ pid = vfork (); + new_argv = new_argv_volatile; + if (pid == 0) { if (fd[0] >= 0) @@ -673,6 +676,7 @@ int first = 1; EMACS_INT total_read = 0; int carryover = 0; + int display_p = display_p_volatile; int display_on_the_fly = display_p; struct coding_system saved_coding; === modified file 'src/process.c' --- src/process.c 2011-03-20 02:48:50 +0000 +++ src/process.c 2011-03-20 03:07:54 +0000 @@ -1912,8 +1912,7 @@ /* child_setup must clobber environ on systems with true vfork. Protect it from permanent change. */ char **save_environ = environ; - - current_dir = ENCODE_FILE (current_dir); + volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir); #ifndef WINDOWSNT pid = vfork (); @@ -2054,13 +2053,13 @@ child_setup_tty (xforkout); #ifdef WINDOWSNT pid = child_setup (xforkin, xforkout, xforkout, - new_argv, 1, current_dir); + new_argv, 1, encoded_current_dir); #else /* not WINDOWSNT */ #ifdef FD_CLOEXEC emacs_close (wait_child_setup[0]); #endif child_setup (xforkin, xforkout, xforkout, - new_argv, 1, current_dir); + new_argv, 1, encoded_current_dir); #endif /* not WINDOWSNT */ } environ = save_environ; === modified file 'src/sysdep.c' --- src/sysdep.c 2011-03-14 23:31:21 +0000 +++ src/sysdep.c 2011-03-18 05:50:40 +0000 @@ -488,7 +488,8 @@ int pid; struct save_signal saved_handlers[5]; Lisp_Object dir; - unsigned char * IF_LINT (volatile) str = 0; + unsigned char *volatile str_volatile = 0; + unsigned char *str; int len; saved_handlers[0].code = SIGINT; @@ -512,7 +513,7 @@ goto xyzzy; dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil); - str = (unsigned char *) alloca (SCHARS (dir) + 2); + str_volatile = str = (unsigned char *) alloca (SCHARS (dir) + 2); len = SCHARS (dir); memcpy (str, SDATA (dir), len); if (str[len - 1] != '/') str[len++] = '/'; @@ -544,6 +545,7 @@ sh = "sh"; /* Use our buffer's default directory for the subshell. */ + str = str_volatile; if (str && chdir ((char *) str) != 0) { #ifndef DOS_NT From unknown Sat Jun 21 12:24:17 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Paul Eggert Subject: bug#8298: closed (fix merged to trunk) Message-ID: References: <4D8A6EF6.6010006@cs.ucla.edu> <4D858502.8050800@cs.ucla.edu> X-Gnu-PR-Message: they-closed 8298 X-Gnu-PR-Package: emacs Reply-To: 8298@debbugs.gnu.org Date: Wed, 23 Mar 2011 22:07:09 +0000 Content-Type: multipart/mixed; boundary="----------=_1300918029-30507-1" This is a multi-part message in MIME format... ------------=_1300918029-30507-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #8298: 'volatile' needed for local variables around vfork which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 8298@debbugs.gnu.org. --=20 8298: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D8298 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1300918029-30507-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 8298-done) by debbugs.gnu.org; 23 Mar 2011 22:07:03 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2WCi-0007uv-6M for submit@debbugs.gnu.org; Wed, 23 Mar 2011 18:07:00 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2WCb-0007uA-KO; Wed, 23 Mar 2011 18:06:54 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 7955339E80F5; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DCQ03AM5OnEs; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 2047839E80B1; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) Message-ID: <4D8A6EF6.6010006@cs.ucla.edu> Date: Wed, 23 Mar 2011 15:06:46 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Thunderbird/3.1.9 MIME-Version: 1.0 To: 8310-done@debbugs.gnu.org, 8318-done@debbugs.gnu.org, 8306-done@debbugs.gnu.org, 8303-done@debbugs.gnu.org, 8277-done@debbugs.gnu.org, 8298-done@debbugs.gnu.org, 8290-done@debbugs.gnu.org, 8278-done@debbugs.gnu.org Subject: fix merged to trunk Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.3 (---) X-Debbugs-Envelope-To: 8298-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.2 (---) I committed a fix to the trunk for this, as part of a recent merge (bzr 103721). ------------=_1300918029-30507-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 20 Mar 2011 04:39:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1AQi-0001Gw-Dg for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1AQf-0001Gj-Cj for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1AQZ-0002NC-Dp for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:44 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:33643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1AQZ-0002N8-BM for submit@debbugs.gnu.org; Sun, 20 Mar 2011 00:39:43 -0400 Received: from [140.186.70.92] (port=37092 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1AQY-0002l5-88 for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1AQW-0002Mq-Mt for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:42 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:33086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1AQW-0002LY-5s for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2011 00:39:40 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 3EB6839E8116 for ; Sat, 19 Mar 2011 21:39:32 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aphfXJVoT+jK for ; Sat, 19 Mar 2011 21:39:31 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 46FD439E80DB for ; Sat, 19 Mar 2011 21:39:31 -0700 (PDT) Message-ID: <4D858502.8050800@cs.ucla.edu> Date: Sat, 19 Mar 2011 21:39:30 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: bug-gnu-emacs@gnu.org Subject: 'volatile' needed for local variables around vfork Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 199.232.76.165 X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) In three places, GNU Emacs assumes that a local variable is preserved after a successful vfork, but on some architectures these variables may be clobbered. (I found this problem by compiling with gcc -Wclobbered.) I plan to address this problem with the following patch: 2011-03-19 Paul Eggert * callproc.c (Fcall_process): Use 'volatile' to avoid vfork clobbering. * process.c (create_process): Likewise. * sysdep.c (sys_subshell): Likewise. Previously, the sys_subshell 'volatile' was incorrectly IF_LINTted out. === modified file 'src/callproc.c' --- src/callproc.c 2011-03-18 04:45:18 +0000 +++ src/callproc.c 2011-03-18 05:56:46 +0000 @@ -180,7 +180,7 @@ (int nargs, register Lisp_Object *args) { Lisp_Object infile, buffer, current_dir, path; - int display_p; + volatile int display_p_volatile; int fd[2]; int filefd; register int pid; @@ -190,6 +190,7 @@ int bufsize = CALLPROC_BUFFER_SIZE_MIN; int count = SPECPDL_INDEX (); + const unsigned char **volatile new_argv_volatile; register const unsigned char **new_argv; /* File to use for stderr in the child. t means use same as standard output. */ @@ -343,7 +344,7 @@ UNGCPRO; } - display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); + display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]); filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); if (filefd < 0) @@ -371,7 +372,7 @@ && SREF (path, 1) == ':') path = Fsubstring (path, make_number (2), Qnil); - new_argv = (const unsigned char **) + new_argv_volatile = new_argv = (const unsigned char **) alloca (max (2, nargs - 2) * sizeof (char *)); if (nargs > 4) { @@ -542,6 +543,8 @@ pid = vfork (); + new_argv = new_argv_volatile; + if (pid == 0) { if (fd[0] >= 0) @@ -673,6 +676,7 @@ int first = 1; EMACS_INT total_read = 0; int carryover = 0; + int display_p = display_p_volatile; int display_on_the_fly = display_p; struct coding_system saved_coding; === modified file 'src/process.c' --- src/process.c 2011-03-20 02:48:50 +0000 +++ src/process.c 2011-03-20 03:07:54 +0000 @@ -1912,8 +1912,7 @@ /* child_setup must clobber environ on systems with true vfork. Protect it from permanent change. */ char **save_environ = environ; - - current_dir = ENCODE_FILE (current_dir); + volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir); #ifndef WINDOWSNT pid = vfork (); @@ -2054,13 +2053,13 @@ child_setup_tty (xforkout); #ifdef WINDOWSNT pid = child_setup (xforkin, xforkout, xforkout, - new_argv, 1, current_dir); + new_argv, 1, encoded_current_dir); #else /* not WINDOWSNT */ #ifdef FD_CLOEXEC emacs_close (wait_child_setup[0]); #endif child_setup (xforkin, xforkout, xforkout, - new_argv, 1, current_dir); + new_argv, 1, encoded_current_dir); #endif /* not WINDOWSNT */ } environ = save_environ; === modified file 'src/sysdep.c' --- src/sysdep.c 2011-03-14 23:31:21 +0000 +++ src/sysdep.c 2011-03-18 05:50:40 +0000 @@ -488,7 +488,8 @@ int pid; struct save_signal saved_handlers[5]; Lisp_Object dir; - unsigned char * IF_LINT (volatile) str = 0; + unsigned char *volatile str_volatile = 0; + unsigned char *str; int len; saved_handlers[0].code = SIGINT; @@ -512,7 +513,7 @@ goto xyzzy; dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil); - str = (unsigned char *) alloca (SCHARS (dir) + 2); + str_volatile = str = (unsigned char *) alloca (SCHARS (dir) + 2); len = SCHARS (dir); memcpy (str, SDATA (dir), len); if (str[len - 1] != '/') str[len++] = '/'; @@ -544,6 +545,7 @@ sh = "sh"; /* Use our buffer's default directory for the subshell. */ + str = str_volatile; if (str && chdir ((char *) str) != 0) { #ifndef DOS_NT ------------=_1300918029-30507-1--