From owner-svn-src-stable-10@freebsd.org Sat Dec 19 02:35:33 2015 Return-Path: Delivered-To: svn-src-stable-10@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 8A47AA4C7B8; Sat, 19 Dec 2015 02:35:33 +0000 (UTC) (envelope-from vangyzen@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 mx1.freebsd.org (Postfix) with ESMTPS id 4B1DE11BC; Sat, 19 Dec 2015 02:35:33 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBJ2ZW6G022985; Sat, 19 Dec 2015 02:35:32 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBJ2ZWmC022984; Sat, 19 Dec 2015 02:35:32 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201512190235.tBJ2ZWmC022984@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Sat, 19 Dec 2015 02:35:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r292461 - stable/10/lib/libc/resolv X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Dec 2015 02:35:33 -0000 Author: vangyzen Date: Sat Dec 19 02:35:32 2015 New Revision: 292461 URL: https://svnweb.freebsd.org/changeset/base/292461 Log: MFC r289837 resolver: abuse _res a little less In the past, _res was a global variable. Now, it's multiple function calls. Several functions in the resolver use _res multiple times and therefore call the function(s) far more than necessary. Fix those callers to store the result of _res in a local variable. Add __noinline to the definition of res_init() to avoid the code bloat that these changes would have otherwise incurred. Thanks to jilles for noticing this. Sponsored by: Dell Inc. Modified: stable/10/lib/libc/resolv/res_data.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/resolv/res_data.c ============================================================================== --- stable/10/lib/libc/resolv/res_data.c Sat Dec 19 02:16:38 2015 (r292460) +++ stable/10/lib/libc/resolv/res_data.c Sat Dec 19 02:35:32 2015 (r292461) @@ -77,9 +77,10 @@ const char *_res_sectioncodes[] = { int res_ourserver_p(const res_state, const struct sockaddr_in *); -int +__noinline int res_init(void) { extern int __res_vinit(res_state, int); + res_state statp = &_res; /* * These three fields used to be statically initialized. This made @@ -100,14 +101,14 @@ res_init(void) { * set in RES_DEFAULT). Our solution is to declare such applications * "broken". They could fool us by setting RES_INIT but none do (yet). */ - if (!_res.retrans) - _res.retrans = RES_TIMEOUT; - if (!_res.retry) - _res.retry = RES_DFLRETRY; - if (!(_res.options & RES_INIT)) - _res.options = RES_DEFAULT; + if (!statp->retrans) + statp->retrans = RES_TIMEOUT; + if (!statp->retry) + statp->retry = RES_DFLRETRY; + if (!(statp->options & RES_INIT)) + statp->options = RES_DEFAULT; - return (__res_vinit(&_res, 1)); + return (__res_vinit(statp, 1)); } void @@ -122,10 +123,11 @@ fp_query(const u_char *msg, FILE *file) void fp_nquery(const u_char *msg, int len, FILE *file) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) return; - res_pquery(&_res, msg, len, file); + res_pquery(statp, msg, len, file); } int @@ -138,23 +140,25 @@ res_mkquery(int op, /*!< opcode of que u_char *buf, /*!< buffer to put query */ int buflen) /*!< size of buffer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nmkquery(&_res, op, dname, class, type, + return (res_nmkquery(statp, op, dname, class, type, data, datalen, newrr_in, buf, buflen)); } int res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nmkupdate(&_res, rrecp_in, buf, buflen)); + return (res_nmkupdate(statp, rrecp_in, buf, buflen)); } int @@ -163,11 +167,12 @@ res_query(const char *name, /*!< domain u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer buffer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nquery(&_res, name, class, type, answer, anslen)); + return (res_nquery(statp, name, class, type, answer, anslen)); } #ifndef _LIBC @@ -189,12 +194,13 @@ res_isourserver(const struct sockaddr_in int res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } - return (res_nsend(&_res, buf, buflen, ans, anssiz)); + return (res_nsend(statp, buf, buflen, ans, anssiz)); } #ifndef _LIBC @@ -202,12 +208,13 @@ int res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } - return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz)); + return (res_nsendsigned(statp, buf, buflen, key, ans, anssiz)); } #endif @@ -218,12 +225,13 @@ res_close(void) { int res_update(ns_updrec *rrecp_in) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nupdate(&_res, rrecp_in, NULL)); + return (res_nupdate(statp, rrecp_in, NULL)); } int @@ -232,12 +240,13 @@ res_search(const char *name, /*!< domain u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nsearch(&_res, name, class, type, answer, anslen)); + return (res_nsearch(statp, name, class, type, answer, anslen)); } int @@ -247,24 +256,26 @@ res_querydomain(const char *name, u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nquerydomain(&_res, name, domain, + return (res_nquerydomain(statp, name, domain, class, type, answer, anslen)); } u_int res_randomid(void) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nrandomid(&_res)); + return (res_nrandomid(statp)); } int @@ -284,13 +295,15 @@ hostalias(const char *name) { int local_hostname_length(const char *hostname) { int len_host, len_domain; + res_state statp; - if (!*_res.defdname) + statp = &_res; + if (!*statp->defdname) res_init(); len_host = strlen(hostname); - len_domain = strlen(_res.defdname); + len_domain = strlen(statp->defdname); if (len_host > len_domain && - !strcasecmp(hostname + len_host - len_domain, _res.defdname) && + !strcasecmp(hostname + len_host - len_domain, statp->defdname) && hostname[len_host - len_domain - 1] == '.') return (len_host - len_domain - 1); return (0);