From patchwork Fri May 2 19:15:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 29581 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5545F203F3 for ; Fri, 2 May 2014 19:21:27 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf23764890pab.11 for ; Fri, 02 May 2014 12:21:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ZIF3yfWnbLhufsXeu7kIl0vPwdYFSTI7xTQZoUAsKpk=; b=Ju1mhjULV+WeAlWX9ef/xLaJWzhOUwGTF/ApUkx73YnwqM0nvmVE+VMIF4ddzBAOqa r+MBgEXrYnbbpbd/DD7v98G+ZUfb1BSwM5dPdUV2uWVUIMAjDWOP5kvsdDFbrhZqbDp3 OUs30eFXK1zfgQE3v1gcxpQOMxX/ER/g6165pgMJgAfXe2rBxA/0mgBKOYyrj2kWcT9x fefftHxUO0m1+zyqEHSQT2zPCHOC/JUqDhuALaclDrt6M3ygNgKUwbOXFSwQyXXR/CpB i0klWSGQ9nth2tmP8AGTkmJNEKZ+rPFodAAlVRAlNzy8t7xiWVmaBmuiZu4LdUSmCTXo xZZg== X-Gm-Message-State: ALoCoQmUSGqHGitHvhT97Gry+v3ZPqR38dH3RQsNIZ6RacwMGZ+gHcI6sCSSDrmSjIsapIgqYonY X-Received: by 10.66.122.70 with SMTP id lq6mr5359567pab.47.1399058486401; Fri, 02 May 2014 12:21:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.99 with SMTP id y90ls106034qgd.82.gmail; Fri, 02 May 2014 12:21:26 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr14544475veb.21.1399058486192; Fri, 02 May 2014 12:21:26 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id u5si6903053vdo.166.2014.05.02.12.21.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 12:21:26 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id db12so2425701veb.11 for ; Fri, 02 May 2014 12:21:26 -0700 (PDT) X-Received: by 10.58.38.40 with SMTP id d8mr1007344vek.61.1399058486127; Fri, 02 May 2014 12:21:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp126037vcb; Fri, 2 May 2014 12:21:25 -0700 (PDT) X-Received: by 10.140.26.243 with SMTP id 106mr23079334qgv.91.1399058485729; Fri, 02 May 2014 12:21:25 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t1si3728890qap.92.2014.05.02.12.21.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 12:21:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:45990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgJ1R-0007XL-5y for patch@linaro.org; Fri, 02 May 2014 15:21:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIwF-00083b-B7 for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgIw5-0000C2-GH for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:03 -0400 Received: from afflict.kos.to ([92.243.29.197]:48078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIw5-00009k-4a for qemu-devel@nongnu.org; Fri, 02 May 2014 15:15:53 -0400 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 02C7A264D1; Fri, 2 May 2014 21:15:51 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 2 May 2014 22:15:44 +0300 Message-Id: <6d30db19caab3cc71a9353cab772b258f0545503.1399057853.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: peter.maydell@linaro.org, Riku Voipio Subject: [Qemu-devel] [PULL 09/14] linux-user: move uname functions to uname.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Riku Voipio Make syscall.c slightly smaller by moving uname-related functions to uname.c. Signed-off-by: Riku Voipio --- linux-user/syscall.c | 102 --------------------------------------------------- linux-user/uname.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ linux-user/uname.h | 9 +++++ 3 files changed, 110 insertions(+), 102 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0f4a092..9fc28bd 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -60,7 +60,6 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #include #include #include -#include //#include #include #include @@ -92,7 +91,6 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #include #include -#include #include #include #include @@ -287,40 +285,6 @@ static bitmask_transtbl fcntl_flags_tbl[] = { { 0, 0, 0, 0 } }; -#define COPY_UTSNAME_FIELD(dest, src) \ - do { \ - /* __NEW_UTS_LEN doesn't include terminating null */ \ - (void) strncpy((dest), (src), __NEW_UTS_LEN); \ - (dest)[__NEW_UTS_LEN] = '\0'; \ - } while (0) - -static int sys_uname(struct new_utsname *buf) -{ - struct utsname uts_buf; - - if (uname(&uts_buf) < 0) - return (-1); - - /* - * Just in case these have some differences, we - * translate utsname to new_utsname (which is the - * struct linux kernel uses). - */ - - memset(buf, 0, sizeof(*buf)); - COPY_UTSNAME_FIELD(buf->sysname, uts_buf.sysname); - COPY_UTSNAME_FIELD(buf->nodename, uts_buf.nodename); - COPY_UTSNAME_FIELD(buf->release, uts_buf.release); - COPY_UTSNAME_FIELD(buf->version, uts_buf.version); - COPY_UTSNAME_FIELD(buf->machine, uts_buf.machine); -#ifdef _GNU_SOURCE - COPY_UTSNAME_FIELD(buf->domainname, uts_buf.domainname); -#endif - return (0); - -#undef COPY_UTSNAME_FIELD -} - static int sys_getcwd1(char *buf, size_t size) { if (getcwd(buf, size) == NULL) { @@ -4983,72 +4947,6 @@ int host_to_target_waitstatus(int status) return status; } -static int relstr_to_int(const char *s) -{ - /* Convert a uname release string like "2.6.18" to an integer - * of the form 0x020612. (Beware that 0x020612 is *not* 2.6.12.) - */ - int i, n, tmp; - - tmp = 0; - for (i = 0; i < 3; i++) { - n = 0; - while (*s >= '0' && *s <= '9') { - n *= 10; - n += *s - '0'; - s++; - } - tmp = (tmp << 8) + n; - if (*s == '.') { - s++; - } - } - return tmp; -} - -int get_osversion(void) -{ - static int osversion; - struct new_utsname buf; - const char *s; - - if (osversion) - return osversion; - if (qemu_uname_release && *qemu_uname_release) { - s = qemu_uname_release; - } else { - if (sys_uname(&buf)) - return 0; - s = buf.release; - } - osversion = relstr_to_int(s); - return osversion; -} - -void init_qemu_uname_release(void) -{ - /* Initialize qemu_uname_release for later use. - * If the host kernel is too old and the user hasn't asked for - * a specific fake version number, we might want to fake a minimum - * target kernel version. - */ -#ifdef UNAME_MINIMUM_RELEASE - struct new_utsname buf; - - if (qemu_uname_release && *qemu_uname_release) { - return; - } - - if (sys_uname(&buf)) { - return; - } - - if (relstr_to_int(buf.release) < relstr_to_int(UNAME_MINIMUM_RELEASE)) { - qemu_uname_release = UNAME_MINIMUM_RELEASE; - } -#endif -} - static int open_self_maps(void *cpu_env, int fd) { #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) diff --git a/linux-user/uname.c b/linux-user/uname.c index 26e90e5..fa5013e 100644 --- a/linux-user/uname.c +++ b/linux-user/uname.c @@ -70,3 +70,104 @@ const char *cpu_to_uname_machine(void *cpu_env) return UNAME_MACHINE; #endif } + + +#define COPY_UTSNAME_FIELD(dest, src) \ + do { \ + /* __NEW_UTS_LEN doesn't include terminating null */ \ + (void) strncpy((dest), (src), __NEW_UTS_LEN); \ + (dest)[__NEW_UTS_LEN] = '\0'; \ + } while (0) + +int sys_uname(struct new_utsname *buf) +{ + struct utsname uts_buf; + + if (uname(&uts_buf) < 0) + return (-1); + + /* + * Just in case these have some differences, we + * translate utsname to new_utsname (which is the + * struct linux kernel uses). + */ + + memset(buf, 0, sizeof(*buf)); + COPY_UTSNAME_FIELD(buf->sysname, uts_buf.sysname); + COPY_UTSNAME_FIELD(buf->nodename, uts_buf.nodename); + COPY_UTSNAME_FIELD(buf->release, uts_buf.release); + COPY_UTSNAME_FIELD(buf->version, uts_buf.version); + COPY_UTSNAME_FIELD(buf->machine, uts_buf.machine); +#ifdef _GNU_SOURCE + COPY_UTSNAME_FIELD(buf->domainname, uts_buf.domainname); +#endif + return (0); + +#undef COPY_UTSNAME_FIELD +} + +static int relstr_to_int(const char *s) +{ + /* Convert a uname release string like "2.6.18" to an integer + * of the form 0x020612. (Beware that 0x020612 is *not* 2.6.12.) + */ + int i, n, tmp; + + tmp = 0; + for (i = 0; i < 3; i++) { + n = 0; + while (*s >= '0' && *s <= '9') { + n *= 10; + n += *s - '0'; + s++; + } + tmp = (tmp << 8) + n; + if (*s == '.') { + s++; + } + } + return tmp; +} + +int get_osversion(void) +{ + static int osversion; + struct new_utsname buf; + const char *s; + + if (osversion) + return osversion; + if (qemu_uname_release && *qemu_uname_release) { + s = qemu_uname_release; + } else { + if (sys_uname(&buf)) + return 0; + s = buf.release; + } + osversion = relstr_to_int(s); + return osversion; +} + +void init_qemu_uname_release(void) +{ + /* Initialize qemu_uname_release for later use. + * If the host kernel is too old and the user hasn't asked for + * a specific fake version number, we might want to fake a minimum + * target kernel version. + */ +#ifdef UNAME_MINIMUM_RELEASE + struct new_utsname buf; + + if (qemu_uname_release && *qemu_uname_release) { + return; + } + + if (sys_uname(&buf)) { + return; + } + + if (relstr_to_int(buf.release) < relstr_to_int(UNAME_MINIMUM_RELEASE)) { + qemu_uname_release = UNAME_MINIMUM_RELEASE; + } +#endif +} diff --git a/linux-user/uname.h b/linux-user/uname.h index 32492de..cc62e76 100644 --- a/linux-user/uname.h +++ b/linux-user/uname.h @@ -1 +1,10 @@ +#ifndef UNAME_H +#define UNAME_H 1 + +#include +#include + const char *cpu_to_uname_machine(void *cpu_env); +int sys_uname(struct new_utsname *buf); + +#endif /* UNAME _H */