From owner-svn-src-all@freebsd.org Mon Jun 4 16:28:07 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A628FF3898; Mon, 4 Jun 2018 16:28:07 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1C55171620; Mon, 4 Jun 2018 16:28:07 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F1A1F7DC2; Mon, 4 Jun 2018 16:28:06 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w54GS6f8009366; Mon, 4 Jun 2018 16:28:06 GMT (envelope-from alc@FreeBSD.org) Received: (from alc@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w54GS6Nq009364; Mon, 4 Jun 2018 16:28:06 GMT (envelope-from alc@FreeBSD.org) Message-Id: <201806041628.w54GS6Nq009364@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alc set sender to alc@FreeBSD.org using -f From: Alan Cox Date: Mon, 4 Jun 2018 16:28:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334621 - in head/sys: kern vm X-SVN-Group: head X-SVN-Commit-Author: alc X-SVN-Commit-Paths: in head/sys: kern vm X-SVN-Commit-Revision: 334621 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2018 16:28:07 -0000 Author: alc Date: Mon Jun 4 16:28:06 2018 New Revision: 334621 URL: https://svnweb.freebsd.org/changeset/base/334621 Log: Use a single, consistent approach to returning success versus failure in vm_map_madvise(). Previously, vm_map_madvise() used a traditional Unix- style "return (0);" to indicate success in the common case, but Mach- style return values in the edge cases. Since KERN_SUCCESS equals zero, the only problem with this inconsistency was stylistic. vm_map_madvise() has exactly two callers in the entire source tree, and only one of them cares about the return value. That caller, kern_madvise(), can be simplified if vm_map_madvise() consistently uses Unix-style return values. Since vm_map_madvise() uses the variable modify_map as a Boolean, make it one. Eliminate a redundant error check from kern_madvise(). Add a comment explaining where the check is performed. Explicitly note that exec_release_args_kva() doesn't care about vm_map_madvise()'s return value. Since MADV_FREE is passed as the behavior, the return value will always be zero. Reviewed by: kib, markj MFC after: 7 days Modified: head/sys/kern/kern_exec.c head/sys/vm/vm_map.c head/sys/vm/vm_mmap.c Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Mon Jun 4 16:21:18 2018 (r334620) +++ head/sys/kern/kern_exec.c Mon Jun 4 16:28:06 2018 (r334621) @@ -1380,7 +1380,7 @@ exec_release_args_kva(struct exec_args_kva *argkva, u_ base = argkva->addr; if (argkva->gen != gen) { - vm_map_madvise(exec_map, base, base + exec_map_entry_size, + (void)vm_map_madvise(exec_map, base, base + exec_map_entry_size, MADV_FREE); argkva->gen = gen; } Modified: head/sys/vm/vm_map.c ============================================================================== --- head/sys/vm/vm_map.c Mon Jun 4 16:21:18 2018 (r334620) +++ head/sys/vm/vm_map.c Mon Jun 4 16:28:06 2018 (r334621) @@ -2215,7 +2215,7 @@ vm_map_madvise( int behav) { vm_map_entry_t current, entry; - int modify_map = 0; + bool modify_map; /* * Some madvise calls directly modify the vm_map_entry, in which case @@ -2232,19 +2232,20 @@ vm_map_madvise( case MADV_NOCORE: case MADV_CORE: if (start == end) - return (KERN_SUCCESS); - modify_map = 1; + return (0); + modify_map = true; vm_map_lock(map); break; case MADV_WILLNEED: case MADV_DONTNEED: case MADV_FREE: if (start == end) - return (KERN_SUCCESS); + return (0); + modify_map = false; vm_map_lock_read(map); break; default: - return (KERN_INVALID_ARGUMENT); + return (EINVAL); } /* Modified: head/sys/vm/vm_mmap.c ============================================================================== --- head/sys/vm/vm_mmap.c Mon Jun 4 16:21:18 2018 (r334620) +++ head/sys/vm/vm_mmap.c Mon Jun 4 16:28:06 2018 (r334621) @@ -683,11 +683,6 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_ } /* - * Check for illegal behavior - */ - if (behav < 0 || behav > MADV_CORE) - return (EINVAL); - /* * Check for illegal addresses. Watch out for address wrap... Note * that VM_*_ADDRESS are not constants due to casts (argh). */ @@ -705,9 +700,10 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_ start = trunc_page(addr); end = round_page(addr + len); - if (vm_map_madvise(map, start, end, behav)) - return (EINVAL); - return (0); + /* + * vm_map_madvise() checks for illegal values of behav. + */ + return (vm_map_madvise(map, start, end, behav)); } #ifndef _SYS_SYSPROTO_H_