From sacadmin Fri Aug 25 13:36:50 2006
Received: from triplex.East.Sun.COM (triplex.East.Sun.COM [129.148.174.104])
	by sac.sfbay.sun.com (8.13.6+Sun/8.13.6) with ESMTP id k7PKaoYf001881
	for <psarc@sac.sfbay.sun.com>; Fri, 25 Aug 2006 13:36:50 -0700 (PDT)
Received: from triplex.East.Sun.COM (localhost [127.0.0.1])
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8) with ESMTP id k7PKan4E013617;
	Fri, 25 Aug 2006 16:36:49 -0400 (EDT)
Received: (from meem@localhost)
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8/Submit) id k7PKannX013614;
	Fri, 25 Aug 2006 16:36:49 -0400 (EDT)
From: Peter Memishian <peter.memishian@sun.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <17647.24417.780670.4938@triplex.East.Sun.COM>
Date: Fri, 25 Aug 2006 16:36:49 -0400
To: psarc@sac.sfbay.sun.com
Cc: garrett@damore.org, garrett_damore@tadpole.com, Eric.Lowe@sun.com
Subject: PSARC/2006/510 Kstat Constification
X-Mailer: VM 7.17 under 21.4 (patch 18) "Social Property" XEmacs Lucid
Status: RO
Content-Length: 4057


I am sponsoring this case on behalf of Garrett D'Amore, from the
OpenSolaris community (contributor agreement number #OS0034).

Patch binding is requested.  All interfaces remain at their existing
stability levels.  Since this case is quite straightforward, the timer
is set for Wednesday, August 30th.

*** NOTE: This case has "open" exposure, and will be visible to the    ***
***       OpenSolaris community.  No confidential information, please! ***

Problem
-------

  Currently, the interface used for device drivers wishing to export
  kernel statistics (kstats) uses a kernel API where a number of otherwise
  immutable strings are listed in the signature of routines as char *
  rather than const char *.  Here are the relevant prototypes from
  <sys/kstat.h>:

    extern kstat_t *kstat_create(char *, int, char *, char *, uchar_t,
        uint_t, uchar_t);
    extern kstat_t *kstat_create_zone(char *, int, char *, char *, uchar_t,
        uint_t, uchar_t, zoneid_t);
    extern void kstat_set_string(char *, char *);
    extern void kstat_delete_byname(char *, int, char *);
    extern void kstat_delete_byname_zone(char *, int, char *, zoneid_t);
    extern void kstat_named_init(kstat_named_t *, char *, uchar_t);
    extern void kstat_timer_init(kstat_timer_t *, char *);

  Of these, only kstat_create() and kstat_named_init() are part of the
  Solaris DDI.  In the future, other members of this list might be
  promoted to the Solaris DDI, but that is beyond the scope of this
  proposal.

  This leads to a few issues:

  1. Developers may believe that the kstat framework may modify the
     strings.  To work around that, developers may use inefficient
     solutions, like storing strings into temporary buffers before passing
     them to kstat.

  2. Many developers use casting to work around this.  For example, the
     return from ddi_driver_name() is often used as the first argument to
     kstat_create().  This is actually safe, because the kstat framework
     doesn't modify the string.  But it is potentially unsafe because it
     assumes a promise that the kstat framework doesn't make.  If it did
     modify the string, that would be very bad, because ddi_driver_name()
     returns a pointer to a string that is stored in other internal kernel
     structures.  In general, casting to workaround problems like this
     indicates an API problem.

  3. The use of non-constant strings may prevent the compiler from
     performing optimizations that it might otherwise be able to do,
     knowing that the data pointed to will not be modified.

Proposed Solution
-----------------

  We propose to simply change the kernel API of the kstat framework so
  that immutable strings have a const attribute in the function signature.
  The resulting API thus becomes:

    extern kstat_t *kstat_create(const char *, int, const char *, const char *,
        uchar_t, uint_t, uchar_t);
    extern kstat_t *kstat_create_zone(const char *, int, const char *,
        const char *, uchar_t, uint_t, uchar_t, zoneid_t);
    extern void kstat_set_string(char *, const char *);
    extern void kstat_delete_byname(const char *, int, const char *);
    extern void kstat_delete_byname_zone(const char *, int, const char *,
        zoneid_t);
    extern void kstat_named_init(kstat_named_t *, const char *, uchar_t);
    extern void kstat_timer_init(kstat_timer_t *, const char *);

  This creates a 100% backwards compatible solution (both source and
  binary), as the compiler will happily promote non-const char * strings
  to const *, making it safe to pass either type of string.  New code that
  takes advantage of this can dispense with an intermediate cast, and can
  directly use const char * values.  (Code written thusly might not be
  portable to earlier versions of SunOS, but such a reverse backwards
  compatibility has never been guaranteed.)

  The online manual pages for kstat_create(9F) and kstat_named_init(9F)
  will be updated to reflect the change of these data types from char * to
  const char *.

-- 
meem

From sacadmin Wed Aug 30 17:20:22 2006
Received: from triplex.East.Sun.COM (triplex.East.Sun.COM [129.148.174.104])
	by sac.sfbay.sun.com (8.13.6+Sun/8.13.6) with ESMTP id k7V0KLRx009904
	for <psarc@sac.sfbay.sun.com>; Wed, 30 Aug 2006 17:20:22 -0700 (PDT)
Received: from triplex.East.Sun.COM (localhost [127.0.0.1])
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8) with ESMTP id k7V0KKle009291;
	Wed, 30 Aug 2006 20:20:20 -0400 (EDT)
Received: (from meem@localhost)
	by triplex.East.Sun.COM (8.13.8+Sun/8.13.8/Submit) id k7V0KKqD009288;
	Wed, 30 Aug 2006 20:20:20 -0400 (EDT)
From: Peter Memishian <peter.memishian@sun.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <17654.11076.117573.540534@triplex.East.Sun.COM>
Date: Wed, 30 Aug 2006 20:20:20 -0400
To: psarc@sac.sfbay.sun.com
Cc: garrett@damore.org, garrett_damore@tadpole.com, Eric.Lowe@sun.com,
        meem@eng.Sun.COM
Subject: Re: PSARC/2006/510 Kstat Constification
X-Mailer: VM 7.17 under 21.4 (patch 18) "Social Property" XEmacs Lucid
Status: RO
Content-Length: 129


This case was approved at today's PSARC meeting.

Garrett, Eric: will contact you separately regarding how to proceed.

--
meem

