From owner-freebsd-hackers@freebsd.org Fri Jun 16 09:49:37 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69771BFC34B for ; Fri, 16 Jun 2017 09:49:37 +0000 (UTC) (envelope-from karnajitw@gmail.com) Received: from mail-it0-x229.google.com (mail-it0-x229.google.com [IPv6:2607:f8b0:4001:c0b::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2925878AA2 for ; Fri, 16 Jun 2017 09:49:37 +0000 (UTC) (envelope-from karnajitw@gmail.com) Received: by mail-it0-x229.google.com with SMTP id m62so32337596itc.0 for ; Fri, 16 Jun 2017 02:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=9HCn1ZXu1bXGetV/0N1PQcliPF0xAtoLzjmtAIMqPUM=; b=Cxksj95teiWwlXgIFDdmt6o4yLGR4+vosqjhcgzxQi4nRMoCPi7x4pDsu9B9QQl84Y nkiz+7WUsDjv2JftYxepdcskiSK7+UDI8gEIivQHO+2D1EXdDxmdxtX1rX+v69KPHXKM S/WuDukxvNAOcWhHj41pN4N0+3zmUEVLJGQnlj4kmi5fD18LXclq9kNf066q2RfR9Klk xIiqmrKLz+kLrv5gBR/aR5729INHCwYQEN22UB6Sf1DGPimjRM9DT9rWJtesNzwy2rsd hXz9q4WE/UhXLQPAftVS0duzfFeLZb1Mafs469eFodY+mmtSV05Xqki/0yCNO1KZx56N nomg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=9HCn1ZXu1bXGetV/0N1PQcliPF0xAtoLzjmtAIMqPUM=; b=LJ4D1gBX+7SgP9WloVZtR1CBF0SW9YsyxPmQ0rgE8zw2HsrIuQGpz1m9EKANr/OV7m 5q4UxaTnjBGXwJjrhC0vB6gwFAScQ3CrUjetr246HGOn9fK359IfvOckNKzOzak8hW/K gqwilhsT+p7nQ5zUCkTg5Unv1I9g4Xi7Zuhg67wNzIoDjMLj0I+aDGjaZhX6DfYjKA9r IzqmLuKb+H4U42//9LxgFDGV2jG8A2PsGRNE1N9kq50BHsBPbqY1ZRNY76GbrqJ/1XXA PplvUQGvljXTl/MmDQJ1zmuWQ7PDym9vg/qxfKwO0WyGjjl6KOh8KuhP4n1Iph7jj4yY GeaA== X-Gm-Message-State: AKS2vOzjHS2fgThEjlCMnA6KS/nrXWfaNLQsyPpjXykj96+QAnaRClsI r4nRuMXqH0lMvK64Zau1Gv9i8i9hKi1L X-Received: by 10.36.125.208 with SMTP id b199mr9488537itc.87.1497606576272; Fri, 16 Jun 2017 02:49:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.136.131 with HTTP; Fri, 16 Jun 2017 02:49:35 -0700 (PDT) From: karnajit wangkhem Date: Fri, 16 Jun 2017 15:19:35 +0530 Message-ID: Subject: Undesirable FPU tag word value after PT_SETFPREGS on i386 To: freebsd-hackers@freebsd.org X-Mailman-Approved-At: Fri, 16 Jun 2017 11:13:06 +0000 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jun 2017 09:49:37 -0000 Hi All, Please help me understand why NaN is reported after PT_SETFPREGS. As a result of this, if the inferior process contains an float operations, they result in NaN. This behavior is not seen in case of 32/64 bit binary on amd64. My env kern.ostype: FreeBSD kern.osrelease: 11.0-RELEASE-p1 kern.version: FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 03:40:55 UTC 2016 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC hw.machine_arch: i386 Result of the below program on an i386 box FPU TAG = ffff FPU TAG = fe00 -> 11 11 11 10 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- #include #include #include #include #include #include #include int main() { pid_t child_pid = fork(); if (child_pid == 0) { ptrace(PT_TRACE_ME, 0, NULL, 0); execl("/bin/ls", "ls", NULL); perror("Exec failed\n"); exit(1); } int status; int options = 0; if (waitpid(child_pid, &status, options) < 0) { perror("Failed to wait for child process!\n"); exit(1); } if (WIFSTOPPED(status)) { printf("Child has stopped...\n"); } else { perror("Child suppose to stop\n"); exit(1); } //****************************************************// struct fpreg fpregs; ptrace(PT_GETFPREGS, child_pid, (caddr_t)&fpregs, 0); printf("FPU TAG = %04x\n", fpregs.fpr_env[2]); ptrace(PT_SETFPREGS, child_pid, (caddr_t)&fpregs, 0); // <------ ptrace(PT_GETFPREGS, child_pid, (caddr_t)&fpregs, 0); printf("FPU TAG = %04x\n", fpregs.fpr_env[2]); //****************************************************// printf("Send continue to child process\n"); ptrace(PT_CONTINUE, child_pid, (caddr_t)1, 0); if (waitpid(child_pid, &status, options) < 0) { perror("Failed to wait for child process!\n"); exit(1); } if (WIFEXITED(status)) { printf("Child exited\n"); } else { perror("Child suppose to exit\n"); exit(1); } return 0; } Regards, Karan