Project

General

Profile

Feature #9851

add sys/containerof.h and implement __containerof

Added by Toomas Soome 12 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
kernel
Start date:
2018-09-19
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:

Description

The sys/queue.h did use container_of() which was bad idea because of container_of is hidden from userland and therefore we block use cases in a way (even as user can define its own container_of. As an secondary reason, there is at least DRM driver boldly creating its own container_of without any checks if it is already defined or not. To reduce the issues and still provide useful macro, lets rename container_of to __containerof and move it to its own private header.

As a followup, we can fix the use cases for container_of and finally remove it from sys/stddef.h.


Related issues

Related to illumos gate - Bug #9731: uts: update sys/queue.hClosed2018-08-13

Actions

History

#1

Updated by Joshua M. Clulow 12 months ago

  • Related to Bug #9731: uts: update sys/queue.h added
#2

Updated by Joshua M. Clulow 12 months ago

As part of testing this change, I think we'll want to make sure we can build the DRM gate: https://github.com/illumos/gfx-drm

#3

Updated by Gordon Ross 12 months ago

What problem is solved by having illumos headers provide (any sort of) container_of() macro?
Seems like it might be going to a lot of trouble for something not standard and not all that widely used.

#4

Updated by Joshua M. Clulow 12 months ago

A survey has demonstrated that it's used in a handful of places in the gate already. The construct is sufficiently nuanced that it makes sense to have just one copy of it (as we wish to do with, say, offsetof()). By centralising on one implementation it's easier to add compile time type safety features (as this new header already seeks to do).

#5

Updated by Toomas Soome 12 months ago

Gordon Ross wrote:

What problem is solved by having illumos headers provide (any sort of) container_of() macro?
Seems like it might be going to a lot of trouble for something not standard and not all that widely used.

I do suggest to use src.illumos.org. It is rather useful tool to find answers to such questions.

#6

Updated by Joshua M. Clulow 10 months ago

Note that while integrating this I built it and inspected the wsdiff output. The noisiest changes were in the t4nex driver, but by far and away most of the changes were just related to line numbers in calls to assfail().

#7

Updated by Electric Monk 10 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

git commit 94c3dad2979525d0a82595f3d8350a6116aba8ed

commit  94c3dad2979525d0a82595f3d8350a6116aba8ed
Author: Toomas Soome <tsoome@me.com>
Date:   2018-11-12T04:37:51.000Z

    9851 add sys/containerof.h and implement __containerof
    Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
    Reviewed by: Andy Fiddaman <omnios@citrus-it.net>
    Approved by: Joshua M. Clulow <josh@sysmgr.org>

Also available in: Atom PDF