[Mono.Profiler.Log] Check MLPD version when reading header
[mono.git] / mcs / class / Mono.Profiler.Log / Mono.Profiler.Log / LogStreamHeader.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System;
6
7 namespace Mono.Profiler.Log {
8
9         public sealed class LogStreamHeader {
10                 const int MinimumMLPDSupportedVersion = 13;
11                 const int MaximumMLPDSupportedVersion = 14;
12
13                 const int Id = 0x4d505a01;
14
15                 public Version Version { get; }
16
17                 public int FormatVersion { get; }
18
19                 public byte PointerSize { get; }
20
21                 public ulong StartupTime { get; }
22
23                 public int TimerOverhead { get; }
24
25                 public int Flags { get; }
26
27                 public int ProcessId { get; }
28
29                 public int Port { get; }
30
31                 public string Arguments { get; }
32
33                 public string Architecture { get; }
34
35                 public string OperatingSystem { get; }
36
37                 internal LogStreamHeader (LogReader reader)
38                 {
39                         var id = reader.ReadInt32 ();
40
41                         if (id != Id)
42                                 throw new LogException ($"Invalid stream header ID (0x{id:X}).");
43
44                         Version = new Version (reader.ReadByte (), reader.ReadByte ());
45                         FormatVersion = reader.ReadByte ();
46
47                         if (FormatVersion < MinimumMLPDSupportedVersion || FormatVersion > MaximumMLPDSupportedVersion)
48                                 throw new LogException ($"Unsupported MLPD version {FormatVersion}. Should be >= {MinimumMLPDSupportedVersion} and <= {MaximumMLPDSupportedVersion}");
49                         
50                         PointerSize = reader.ReadByte ();
51                         StartupTime = reader.ReadUInt64 ();
52                         TimerOverhead = reader.ReadInt32 ();
53                         Flags = reader.ReadInt32 ();
54                         ProcessId = reader.ReadInt32 ();
55                         Port = reader.ReadUInt16 ();
56                         Arguments = reader.ReadHeaderString ();
57                         Architecture = reader.ReadHeaderString ();
58                         OperatingSystem = reader.ReadHeaderString ();
59                 }
60         }
61 }