File: ShmInterface.cpp

package info (click to toggle)
pd-vstplugin 0.6.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,008 kB
  • sloc: cpp: 22,783; lisp: 2,860; makefile: 37; sh: 26
file content (704 lines) | stat: -rw-r--r-- 20,830 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#include "ShmInterface.h"

#include "Log.h"
#include "MiscUtils.h"

#include <cstring>

#if VST_HOST_SYSTEM == VST_WINDOWS
# ifndef NOMINMAX
#  define NOMINMAX
# endif
# include <windows.h>
#else
# include <unistd.h>
# include <sys/types.h>
# include <fcntl.h>
# include <sys/shm.h>
# include <sys/mman.h>
# if SHM_FUTEX
#  include <sys/syscall.h>
#  include <linux/futex.h>
# else // semaphore
#  include <semaphore.h>
#  if VST_HOST_SYSTEM == VST_MACOS
#   include <sys/stat.h>
#  endif
# endif
#endif

#ifndef DEBUG_SHM
#define DEBUG_SHM 0
#endif

#if DEBUG_SHM
#define LOG_SHM(x) LOG_DEBUG(x)
#else
#define LOG_SHM(x)
#endif

namespace vst {

#if SHM_FUTEX
int futex(std::atomic<uint32_t>* uaddr, int futex_op, uint32_t val,
          const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
{
    return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
}

void futex_wait(std::atomic<uint32_t>* futexp)
{
    for (;;) {
        // is futex available?
        uint32_t expected = 1;
        if (futexp->compare_exchange_strong(expected, 0)){
            // success
            break;
        }
        // not available - wait
        auto ret = futex(futexp, FUTEX_WAIT, 0, nullptr, nullptr, 0);
        if (ret < 0 && errno != EAGAIN){
            throw Error(Error::SystemError,
                        "futex_wait() failed: " + errorMessage(errno));
        }
    }
}

void futex_post(std::atomic<uint32_t>* futexp)
{
    uint32_t expected = 0;
    if (futexp->compare_exchange_strong(expected, 1)) {
       // wake one waiter
       if (futex(futexp, FUTEX_WAKE, 1, nullptr, nullptr, 0) < 0) {
           throw Error(Error::SystemError,
                       "futex_post() failed: " + errorMessage(errno));
       }
    }
}
#endif

constexpr size_t align_to(size_t s, size_t alignment){
    auto mask = alignment - 1;
    return (s + mask) & ~mask;
}

/*/////////////// ShmChannel ////////////*/


ShmChannel::ShmChannel(Type type, int32_t size, std::string_view name)
    : owner_(true), type_(type), bufferSize_(size), name_(name)
{
#if SHM_FUTEX || SHM_EVENT
    static_assert(sizeof(Header) == 64, "bad size for Header");
#else
    static_assert(sizeof(Header) == 128, "bad size for Header");
#endif
    auto total = sizeof(Header) + sizeof(Data) + size;
    totalSize_ = align_to(total, alignment);
}

void ShmChannel::HandleDeleter::operator ()(void *handle){
    // only invoked if handle is not NULL
#if SHM_EVENT
    // LOG_SHM("close event " << handle);
    CloseHandle((HANDLE)handle);
#elif SHM_SEMAPHORE
    if (sem_close((sem_t *)handle) != 0) {
        LOG_ERROR("sem_close() failed: " << errorMessage(errno));
    }
#endif
    // nothing to do for SHM_FUTEX
}

ShmChannel::~ShmChannel(){
    // LOG_SHM("~ShmChannel");
#if SHM_SEMAPHORE
    // unlink semaphores in the owner, so that they are removed
    // from the system once both ends have closed their handles
    // (happens automatically if the subprocess crashes).
    if (owner_) {
        if (eventA_ && sem_unlink((const char *)header_->data1) != 0) {
            LOG_ERROR("sem_unlink() failed: " << errorMessage(errno));
        }
        if (eventB_ && sem_unlink((const char *)header_->data2) != 0) {
            LOG_ERROR("sem_unlink() failed: " << errorMessage(errno));
        }
    }
#endif
}

size_t ShmChannel::peekMessage() const {
    if (data_->size.load(std::memory_order_relaxed) > 0){
        auto msg = (Message *)&data_->data[rdhead_];
        return msg->size;
    } else {
        return 0;
    }
}

bool ShmChannel::readMessage(void * buffer, size_t& size) {
    if (data_->size.load(std::memory_order_relaxed) > 0){
        auto msg = (Message *)&data_->data[rdhead_];
        if (msg->size > size){
            size = msg->size; // return required minimum size
            return false;
        }

        auto begin = msg->data;
        auto end = begin + msg->size;
        auto limit = data_->data + data_->capacity;
        auto msgsize = msg->size + sizeof(msg->size);

        // >= ensures rdhead wrap around!
        if (end >= limit){
            auto n1 = limit - begin;
            auto n2 = end - limit;
            memcpy(buffer, begin, n1);
            memcpy((char *)buffer + n1, data_->data, n2);
            rdhead_ = n2;
        } else {
            memcpy(buffer, begin, msg->size);
            rdhead_ += msgsize;
        }

        data_->size -= msgsize; // atomic decrement!

        size = msg->size; // return actual size
        return true;
    } else {
        size = 0;
        return false;
    }
}

bool ShmChannel::writeMessage(const void *data, size_t size) {
    auto capacity = data_->capacity;
    // get actual message size (+ size field + alignment)
    auto msgsize = align_to(size + sizeof(Message::size), Message::alignment);
    if ((capacity - data_->size.load(std::memory_order_relaxed)) >= msgsize){
        auto msg = (Message *)&data_->data[wrhead_];

        msg->size = msgsize - sizeof(msg->size); // minus size field!

        auto begin = msg->data;
        auto end = begin + size; // use original size!
        auto limit = data_->data + capacity;

        if (end > limit){
            auto n1 = limit - begin;
            auto n2 = end - limit;
            memcpy(begin, data, n1);
            memcpy(data_->data, (const char *)data + n1, n2);
        } else {
            memcpy(begin, data, size); // use original size!
        }

        // we have to handle wrhead seperately because msg->size != size
        wrhead_ += msgsize;
        if (wrhead_ >= capacity){
            wrhead_ -= capacity;
        }

        data_->size.fetch_add(msgsize, std::memory_order_release);

        return true;
    } else {
        return false;
    }
}

bool ShmChannel::addMessage(const void * data, size_t size) {
    auto capacity = data_->capacity;
    // get actual message size (+ size field + alignment)
    auto msgsize = align_to(size + sizeof(Message::size), Message::alignment);
    if ((capacity - data_->size.load(std::memory_order_relaxed)) >= msgsize){
        auto msg = (Message *)&data_->data[wrhead_];

        msg->size = msgsize - sizeof(msg->size); // minus size field!
        memcpy(msg->data, data, size); // use original size!

        wrhead_ += msgsize;
        data_->size.fetch_add(msgsize, std::memory_order_release);

        return true;
    } else {
        return false;
    }
}

bool ShmChannel::getMessage(const void *& buf, size_t& size) {
    if (data_->size.load(std::memory_order_relaxed) > 0){
        auto msg = (Message *)&data_->data[rdhead_];

        buf = msg->data;
        size = msg->size;

        auto msgsize = msg->size + sizeof(msg->size);
        rdhead_ += msgsize;
        data_->size -= msgsize; // atomic decrement!

        return true;
    } else {
        return false;
    }
}

void ShmChannel::clear(){
    data_->size = 0;
    reset();
}

void ShmChannel::reset(){
    rdhead_ = 0;
    wrhead_ = 0;
}

void ShmChannel::post(){
    postEvent(eventA_.get());
}

void ShmChannel::wait(){
    waitEvent(eventA_.get());
}

void ShmChannel::postReply(){
    postEvent(eventB_.get());
}

void ShmChannel::waitReply(){
    waitEvent(eventB_.get());
}

void ShmChannel::init(ShmInterface& shm, char *data, int num){
    LOG_SHM("init channel " << num);
    header_ = reinterpret_cast<Header *>(data);
    if (owner_){
        // placement new
        new (header_) Header(type_, name_.c_str(), totalSize_);
    #if SHM_SEMAPHORE
        // POSIX expects leading slash
        snprintf(header_->data1, sizeof(header_->data1),
                 "/vst_shm_%p_%da", &shm, num);
        if (type_ == Request){
            snprintf(header_->data2, sizeof(header_->data2),
                     "/vst_shm_%p_%db", &shm, num);
        } else {
            header_->data2[0] = '\0';
        }
    #endif
    } else {
        if (header_->offset != sizeof(Header)){
            throw Error(Error::SystemError, "shared memory interface not compatible (wrong header size)!");
        }
        totalSize_ = header_->size;
        type_ = (Type)header_->type;
        name_ = header_->name;
    }

    initEvent(shm, eventA_, &header_->data1);
    if (type_ == Request){
        initEvent(shm, eventB_, &header_->data2);
    }

    if (owner_){
        // placement new
        data_ = new (data + header_->offset) Data();
        data_->capacity = bufferSize_;
    } else {
        data_ = reinterpret_cast<Data *>(data + header_->offset);
    }

    LOG_SHM("init ShmChannel " << num << " (" << name_
              << "): buffer size = " << data_->capacity
              << ", total size = " << totalSize_
              << ", start address = " << (void *)data);
}

void ShmChannel::initEvent(ShmInterface& shm, Handle& event, void *data){
    // LOG_SHM("ShmChannel: init event " << which);
#if SHM_EVENT
    if (owner_){
        // create new Event
        event.reset(CreateEventA(0, 0, 0, 0));
        if (!event){
            throw Error(Error::SystemError, "CreateEvent() failed: "
                        + errorMessage(GetLastError()));
        }
        // HANDLE can be safely truncated to 32-bit integer
        uint32_t handle = (uint32_t)reinterpret_cast<uintptr_t>(event.get());
        memcpy(data, &handle, sizeof(handle));
    } else {
        // get Event handle from shared memory segment and duplicate it
        // to get a handle that is valid in this process.
        uint32_t intHandle;
        memcpy(&intHandle, data, sizeof(uint32_t));
        auto sourceHandle = reinterpret_cast<HANDLE>(intHandle);
        auto sourceProcess = (HANDLE)shm.getParentProcessHandle();
        auto targetProcess = GetCurrentProcess();
        HANDLE targetHandle;
        auto result = DuplicateHandle(sourceProcess, sourceHandle,
                                      targetProcess, &targetHandle,
                                      0, FALSE, DUPLICATE_SAME_ACCESS);
        if (!result){
            throw Error(Error::SystemError, "DuplicateHandle() failed: "
                        + errorMessage(GetLastError()));
        }
        event.reset(targetHandle);
    }
    LOG_SHM("create event " << event.get());
#elif SHM_SEMAPHORE
    if (owner_){
        // create semaphore and return an error if it already exists
        event.reset(sem_open((const char *)data, O_CREAT | O_EXCL, 0755, 0));
        LOG_SHM("ShmChannel: created semaphore " << (const char *)data);
    } else {
        // open an existing semaphore
        event.reset(sem_open((const char *)data, 0, 0, 0, 0));
        LOG_SHM("ShmChannel: created semaphore " << (const char *)data);
    }
    if (event.get() == SEM_FAILED){
        throw Error(Error::SystemError, "sem_open() failed: "
                    + errorMessage(errno));
    }
#elif SHM_FUTEX
    event.reset(data);
#endif
}

void ShmChannel::postEvent(void *event){
#if SHM_EVENT
    if (!SetEvent((HANDLE)event)){
        throw Error(Error::SystemError, "SetEvent() failed: "
                    + errorMessage(GetLastError()));
    }
#elif SHM_SEMAPHORE
    if (sem_post((sem_t *)event) != 0){
        throw Error(Error::SystemError, "sem_post() failed: "
                    + errorMessage(errno));
    }
#elif SHM_FUTEX
    futex_post(static_cast<std::atomic<uint32_t>*>(event));
#endif
}

void ShmChannel::waitEvent(void *event){
#if SHM_EVENT
    auto result = WaitForSingleObject(event, INFINITE);
    if (result != WAIT_OBJECT_0){
        if (result == WAIT_ABANDONED){
            LOG_ERROR("WaitForSingleObject() failed! Event abandoned");
        } else {
            throw Error(Error::SystemError, "WaitForSingleObject() failed: "
                        + errorMessage(GetLastError()));
        }
    }
#elif SHM_SEMAPHORE
    if (sem_wait((sem_t *)event) != 0){
        throw Error(Error::SystemError, "sem_wait() failed: "
                    + errorMessage(errno));
    }
#elif SHM_FUTEX
    futex_wait(static_cast<std::atomic<uint32_t>*>(event));
#endif
}

/*//////////////// ShmInterface //////////////////*/

ShmInterface::Header::Header(uint32_t _size, uint32_t _numChannels) {
    size = _size;
    versionMajor = VERSION_MAJOR;
    versionMinor = VERSION_MINOR;
    versionPatch = VERSION_PATCH;
#if SHM_EVENT
    processID = GetCurrentProcessId();
#endif
    numChannels = _numChannels;
    memset(channelOffset, 0, sizeof(channelOffset));
}

ShmInterface::ShmInterface(){}

ShmInterface::~ShmInterface(){
    // *first* clear channels because the channel destructor might want to
    // access the shared memory region, e.g. to unlink semaphores.
    channels_.clear();
    closeShm();
    LOG_SHM("closed ShmInterface");

#if SHM_EVENT
    CloseHandle(hParentProcess_);
#endif
}

void ShmInterface::connect(const std::string &path){
    if (data_){
        throw Error(Error::SystemError, "ShmInterface: already connected()!");
    }

    openShm(path, false);
    LOG_SHM("ShmInterface: connected to " << path);
    auto header = reinterpret_cast<Header *>(data_);
    LOG_SHM("total size: " << header->size);

#if SHM_EVENT
    // needed for channel events
    hParentProcess_ = OpenProcess(PROCESS_DUP_HANDLE, FALSE, header->processID);
    if (!hParentProcess_){
        throw Error(Error::SystemError, "OpenProcess() failed: "
                    + errorMessage(GetLastError()));
    }
#endif

    // channels_.reserve(header->numChannels);
    for (size_t i = 0; i < header->numChannels; ++i){
        channels_.emplace_back();
        channels_[i].init(*this, data_ + header->channelOffset[i], i);
    }
}

void ShmInterface::disconnect(){
    if (data_){
        if (!owner_){
            closeShm();
        } else {
            LOG_ERROR("ShmInterface: owner must not call disconnect()!");
        }
    } else {
        LOG_WARNING("ShmInterface::disconnect: not connected");
    }
}

void ShmInterface::addChannel(ShmChannel::Type type,
                              size_t size, std::string_view name)
{
    if (data_){
        throw Error(Error::SystemError,
                    "ShmInterface: must not call addChannel() after create()!");
    }

    if (channels_.size() == maxNumChannels){
        throw Error(Error::SystemError,
                    "ShmInterface: max. number of channels reached!");
    }
    channels_.emplace_back(type, size, name);
}

void ShmInterface::create(){
    if (data_){
        throw Error(Error::SystemError, "ShmInterface: already created()!");
    }

    char path[64];
    // POSIX expects leading slash
    snprintf(path, sizeof(path), "/vst_shm_%p", this);

    openShm(path, true);
    LOG_SHM("ShmInterface: created " << path);
    LOG_SHM("total size: " << size_);

    // placement new
    auto header = new (data_) Header(size_, channels_.size());
    char *ptr = data_ + sizeof(Header);

    for (size_t i = 0; i < channels_.size(); ++i){
        channels_[i].init(*this, ptr, i);
        header->channelOffset[i] = ptr - data_;
        ptr += channels_[i].size();
    }
}

void ShmInterface::close(){
    if (data_){
        if (owner_){
            closeShm();
        } else {
            LOG_ERROR("ShmInterface: only owner may call close()!");
        }
    }
}

void ShmInterface::openShm(const std::string &path, bool create){
    size_t totalSize = sizeof(Header);

    if (create) {
        for (auto& chn : channels_) {
            totalSize += chn.size();
        }
    }

    orphaned_.store(false);

#if VST_HOST_SYSTEM == VST_WINDOWS
    HANDLE hMapFile;
    if (create){
        hMapFile = CreateFileMappingA(
            INVALID_HANDLE_VALUE,    // use paging file
            NULL,                    // default security
            PAGE_READWRITE,          // read/write access
            0,                       // maximum object size (high-order DWORD)
            totalSize,               // maximum object size (low-order DWORD)
            path.c_str());           // name of mapping object

        if (!hMapFile)
        {
            throw Error(Error::SystemError, "CreateFileMapping() failed: "
                        + errorMessage(GetLastError()));
        }
    } else {
        hMapFile = OpenFileMappingA(
            FILE_MAP_ALL_ACCESS,   // read/write access
            FALSE,                 // do not inherit the name
            path.c_str());         // name of mapping object

        if (!hMapFile){
            throw Error(Error::SystemError, "OpenFileMapping() failed: "
                        + errorMessage(GetLastError()));
        }
    }
    void *data = MapViewOfFile(hMapFile, // handle to map object
                               FILE_MAP_ALL_ACCESS, // read/write permission
                               0, 0, totalSize);    // size
    if (data && !create){
        // get actual total size
        totalSize = static_cast<Header *>(data)->size;
        UnmapViewOfFile(data);
        // map again with correct size
        data = MapViewOfFile(hMapFile,
                             FILE_MAP_ALL_ACCESS,
                             0, 0, totalSize);
    }

    if (!data){
        CloseHandle(hMapFile);
        throw Error(Error::SystemError, "MapViewOfFile() failed: "
                    + errorMessage(GetLastError()));
    }

    // try to lock the file to physical memory
    // first we have to increase the minimum working set size
    SIZE_T minSize, maxSize;
    if (GetProcessWorkingSetSize(GetCurrentProcess(), &minSize, &maxSize)){
        LOG_SHM("working set size: min = " << minSize << ", max = " << maxSize);
        LOG_SHM("request size: " << totalSize);
        if (totalSize > minSize){
            minSize += totalSize;
        }
        if (totalSize > maxSize){
            maxSize += totalSize;
        }
       if (!SetProcessWorkingSetSize(GetCurrentProcess(), minSize, maxSize)){
            LOG_WARNING("ShmInterface: SetProcessWorkingSetSize() failed: "
                        << GetLastError());
        }
    } else {
        LOG_WARNING("ShmInterface: GetProcessWorkingSetSize() failed: "
                    << GetLastError());
    }
    // now we can attempt to lock the memory
    if (!VirtualLock(data, totalSize)){
        LOG_WARNING("ShmInterface: VirtualLock() failed: "
                    << GetLastError());
    }
#else
    int fd;
    if (create){
        fd = shm_open(path.c_str(), O_CREAT | O_RDWR | O_EXCL, 0666);
    } else {
        fd = shm_open(path.c_str(), O_RDWR, 0666);
    }
    if (fd < 0){
        throw Error(Error::SystemError, "shm_open() failed: "
                    + errorMessage(errno));
    }
    if (create){
        // configure size of shared memory object
        if (ftruncate(fd, totalSize) != 0){
            ::close(fd);
            shm_unlink(path.c_str());
            throw Error(Error::SystemError, "ftruncate() failed: "
                        + errorMessage(errno));
        }
    }
    // memory map the shared memory object
    int err = 0;
    void *data = mmap(0, totalSize, PROT_WRITE, MAP_SHARED, fd, 0);
    if (!data) {
        err = errno; // cache errno
    } else if (!create) {
        // get actual total size
        auto oldSize = totalSize;
        totalSize = static_cast<Header *>(data)->size;
        munmap(data, oldSize);
        // map again with correct size
        data = mmap(0, totalSize, PROT_WRITE, MAP_SHARED, fd, 0);
        if (!data) {
            err = errno; // cache errno
        }
    }
    // we can close the fd after calling mmap()!
    ::close(fd);

    if (!data){
        if (create){
            shm_unlink(path.c_str());
        }
        throw Error(Error::SystemError, "mmap() failed: "
                    + errorMessage(err));
    }
#if 1
    // try to lock the file to physical memory
    if (mlock(data, totalSize) != 0){
        LOG_WARNING("ShmInterface: mlock() failed: "
                    << strerror(errno));
    }
#endif

#endif // Unix

    // success!
    path_ = path;
    owner_ = create;
#if VST_HOST_SYSTEM == VST_WINDOWS
    hMapFile_ = hMapFile;
#endif
    data_ = (char *)data;
    size_ = totalSize;

    if (create){
        // zero the memory region. this also ensures
        // that everything will be paged in.
        memset(data, 0, totalSize);
    }
}

void ShmInterface::closeShm(){
#if VST_HOST_SYSTEM == VST_WINDOWS
    if (data_){
        UnmapViewOfFile(data_);
    }
    if (hMapFile_){
        CloseHandle(hMapFile_);
        hMapFile_ = nullptr;
    }
#else
    if (data_){
        munmap(data_, size_);
        if (owner_ || orphaned_.load()){
            shm_unlink(path_.c_str());
        }
    }
#endif
    path_.clear();
    data_ = nullptr;
    size_ = 0;
    channels_.clear();
}

void ShmInterface::getVersion(int& major, int& minor, int& patch) const {
    auto header = reinterpret_cast<const Header *>(data_);
    major = header->versionMajor;
    minor = header->versionMinor;
    patch = header->versionPatch;
}

} // vst