From owner-freebsd-hackers@freebsd.org Wed Apr 12 03:57:19 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 16F0DD37B11 for ; Wed, 12 Apr 2017 03:57:19 +0000 (UTC) (envelope-from crb@chrisbowman.com) Received: from mail-pg0-x231.google.com (mail-pg0-x231.google.com [IPv6:2607:f8b0:400e:c05::231]) (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 E20D9A3E for ; Wed, 12 Apr 2017 03:57:18 +0000 (UTC) (envelope-from crb@chrisbowman.com) Received: by mail-pg0-x231.google.com with SMTP id 81so8220328pgh.2 for ; Tue, 11 Apr 2017 20:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisbowman-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=qq6KklBUCgjaidDLjYU4IdnW+9X6goX8WPcZ5iJ03lg=; b=VEiOU9624Ii7TLINxtJ7dTrnY/ZX9IkM1EzTPbidmVRO0xv0yLmQbpjKWEhnAfqpW3 60dv1yAVnFHlueq+8PGhVPHCLxVBAeMW2IJOy5OUJpH37MHLuE7o6xyrb84msYQTkXCy aS0jPYVtZybGmDzi8tAe7Z8hroJtGF9CF+4JW8wIv9AES88x3Ge8Xu0UrYPbwBfsg47y q0+QVzeTX5pUAwmlGgLdrytSe2VpTsZG6gVRYMrmFLBvyoMHJN3jWr1vdSG45fXAPlRk hC09LK3KtZjpyV33jT/696PmR9se/2GqhpZWBVUFAJIdQuHTkxBCsgwTA06Dx6dJ3h/2 0+XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=qq6KklBUCgjaidDLjYU4IdnW+9X6goX8WPcZ5iJ03lg=; b=hdcG9FZ+kjXr7x6Ir6mzwBwh7xAn1GF4OPNqvtwxn774YzB+RBVkB4igGQjHVuUcp4 cZVY+JA+rv7iMp6lN1xx3FUliUnLbCQntMpLJLwdQY5/dM3fkid/a2FiugrlHK4nipL3 pPqbkz930YNariILzPAHcCYCMGMnYI+JO4QMb5elxodNYPJB8UfXTuLVT2P1/66O6Nba hbI7tpjxkpfn8m5zcQYZg9NjcyjqWz2r+vDyo6DavGIXN6LDYzqcrhYkAdpUpdcJmkvC byz10BPyfH5KUXnUBkC31iHFqskqh4ics882DeugDIsyRZZ0gYqdzRr10fnvpkykZZGK g9aw== X-Gm-Message-State: AFeK/H2dxjjkMDg7GSTNRty2SJ+G99irTbqrioaAiXu991JK70V/BFHLTI9R8NSy7c0+Zg== X-Received: by 10.99.97.12 with SMTP id v12mr65838575pgb.124.1491969438431; Tue, 11 Apr 2017 20:57:18 -0700 (PDT) Received: from ?IPv6:2601:647:4e00:bbb5:a1e9:e0d1:714c:d747? ([2601:647:4e00:bbb5:a1e9:e0d1:714c:d747]) by smtp.gmail.com with ESMTPSA id v86sm33094945pfa.86.2017.04.11.20.57.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 20:57:17 -0700 (PDT) From: "Christopher R. Bowman" X-Google-Original-From: "Christopher R. Bowman" Message-Id: <15DF9D2C-40A4-4341-AE7E-E8A776ED3F09@ChrisBowman.com> Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Dtrace oddity Date: Tue, 11 Apr 2017 20:57:16 -0700 In-Reply-To: <20170411151426.3b760182@fabiankeil.de> Cc: freebsd-hackers@freebsd.org To: Fabian Keil References: <20170411151426.3b760182@fabiankeil.de> X-Mailer: Apple Mail (2.3273) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Wed, 12 Apr 2017 03:57:19 -0000 Fabian, That was hugely helpful. I should have known about the extra = mmap sys calls, but sometimes your mind only sees what it expects to = see. Checking for negative values on open is also the right thing to do = (I had mis-read the man page to imply that zero indicated a failure to = open). But the real help was putting one of the flags for mmap. I = don=E2=80=99t think FreeBSD used to check for that as I have a vague = recollection that this code used to work on a pervious version. Thanks SO SO much for the help! Christopher -------- Christopher R. Bowman email: crb@ChrisBowman.com World Wide GSM cell: +1 (408) 476-2299 > On Apr 11, 2017, at 6:14 AM, Fabian Keil = wrote: >=20 > Christopher Bowman wrote: >=20 >> The man page lists a bunch of reasons for EINVAL so I want to >> investigate this and I don=E2=80=99t quite know good strategies to = debug the >> kernel (yet) so I thought I=E2=80=99d experiment with Dtrace a bit. = Here is the >> oddity: when I run Dtrace and then run my test program I get the >> following output from Dtrace: >>=20 >> crb@retread:60> dtrace -n 'syscall:freebsd:mmap:entry /execname =3D=3D = "test"/ {}' >> dtrace: description 'syscall:freebsd:mmap:entry ' matched 1 >> probe CPU ID FUNCTION:NAME >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >> 0 63401 mmap:entry=20 >>=20 >> I think Dtrace is indicating that the mmap syscall was called 12 = times >> by my test program yet I can see how the program below would have = done >> that. >=20 > A bunch of mmap syscalls occur before main is even entered. > Try running your program with truss to see what's going on. >=20 >> Here is my program: > [...] >> printf("opening device %s\n", argv[1]); >> int device =3D open (argv[1], O_RDWR); >> if (device =3D=3D 0) { >=20 > You should check for -1 here. >=20 >> void *pa =3D mmap (0, 4095, PROT_READ | PROT_WRITE, 0, device, = 0); >=20 > No flags? =46rom the mmap man page: >=20 > | [EINVAL] None of MAP_ANON, MAP_PRIVATE, MAP_SHARED, or > | MAP_STACK was specified. At least one of = these flags > | must be included. >=20 > Fabian