<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 15, 2021, at 6:03 PM, Michael Brown <<a href="mailto:mcb30@ipxe.org" class="">mcb30@ipxe.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 16/04/2021 01:59, Ethin Probst wrote:<br class=""><blockquote type="cite" class="">Also, I'm a bit confused. I've looked at several VirtIO devices now<br class="">and have seen things like this:<br class="">#define VIRTIO_PCI_DEVICE_SIGNATURE   SIGNATURE_32 ('V', 'P', 'C', 'I')<br class="">// ...<br class="">   UINT32                 Signature;<br class="">I'm quite confused because I can't seem to find this anywhere in the<br class="">VirtIO specification. The spec says nothing about signature values<br class="">anywhere, just the magic value of 0x74726976. So where does this come<br class="">from?<br class=""></blockquote><br class="">From a quick look at the code, it seems to be a private signature value applied to a software-only data structure used by the UEFI driver, and is used solely for sanity checking that a pointer is pointing to the right kind of object.<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>Ethin,</div><div><br class=""></div><div>This is a common edk2 code pattern. We have something called a Containment Record (CR) macro [1] and the DEBUG version of the CR macro [2] checks the signature. What happens is the public API is a Field in the private data structure, thus you can convert the This pointer to the private context of the driver for that protocol instances. The driver publishes the protocol from the Start() function so that is why the This pointer is always going to be a member of the larger private context structure. </div><div><br class=""></div><div>This pattern is also used for double linked lists as the data structure to represent the link list is generic and the data is attached to it via the Containment Record scheme by making that linked list data structure part of the larger data structure. </div><div><br class=""></div><div>[1] <span style="caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">#</span><span class="pl-k" style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre;">define</span><span style="caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="box-sizing: border-box; color: var(--color-prettylights-syntax-entity); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre;">BASE_CR</span><span style="caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">(</span><span class="pl-v" style="box-sizing: border-box; color: var(--color-prettylights-syntax-variable); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre;">Record, TYPE, Field</span><span style="caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">)  ((TYPE *) ((CHAR8 *) (Record) - OFFSET_OF (TYPE, Field)))</span></div><div><br class=""></div><div>[2] </div><table class="js-file-line-container highlight tab-size" data-tab-size="8" data-paste-markdown-skip="" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14px;"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""><td id="L594" class="blob-num js-line-number" data-line-number="594" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; line-height: 20px; color: var(--color-diff-blob-num-text); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none;"></td><td id="LC594" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; color: var(--color-text-primary); word-wrap: normal; white-space: pre;">  #<span class="pl-k" style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">define</span> <span class="pl-en" style="box-sizing: border-box; color: var(--color-prettylights-syntax-entity);">CR</span>(<span class="pl-v" style="box-sizing: border-box; color: var(--color-prettylights-syntax-variable);">Record, TYPE, Field, TestSignature</span>)                                              \</td></tr><tr style="box-sizing: border-box;" class=""><td id="L595" class="blob-num js-line-number" data-line-number="595" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; line-height: 20px; color: var(--color-diff-blob-num-text); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none;"></td><td id="LC595" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; color: var(--color-text-primary); word-wrap: normal; white-space: pre;">    (<span class="pl-c1" style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">DebugAssertEnabled</span> () && (<span class="pl-c1" style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">BASE_CR</span> (Record, TYPE, Field)-><span class="pl-smi" style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">Signature</span> != TestSignature)) ?  \</td></tr><tr style="box-sizing: border-box;" class=""><td id="L596" class="blob-num js-line-number" data-line-number="596" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; line-height: 20px; color: var(--color-diff-blob-num-text); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none;"></td><td id="LC596" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; color: var(--color-text-primary); word-wrap: normal; white-space: pre;">    (TYPE *) (<span class="pl-c1" style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">_ASSERT</span> (CR has Bad Signature), Record) :                                       \</td></tr><tr style="box-sizing: border-box;" class=""><td id="L597" class="blob-num js-line-number" data-line-number="597" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; line-height: 20px; color: var(--color-diff-blob-num-text); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none;"></td><td id="LC597" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; color: var(--color-text-primary); word-wrap: normal; white-space: pre;">    <span class="pl-c1" style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">BASE_CR</span> (Record, TYPE, Field)</td></tr><tr style="box-sizing: border-box;" class=""><td id="L598" class="blob-num js-line-number" data-line-number="598" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; line-height: 20px; color: var(--color-diff-blob-num-text); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none;"></td></tr></tbody></table><br class=""><div>Thanks,</div><div><br class=""></div><div>Andrew Fish</div></div><br class=""></body></html>

 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/74191">View/Reply Online (#74191)</a> |    |  <a target="_blank" href="https://groups.io/mt/81710286/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>