@@ -10,6 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | use crate::macho::constants::*; |
| 12 | 12 | use crate::macho::reader::{name16_str, ReadError, Section64Header}; |
| 13 | +use crate::resolve::AtomId; |
| 13 | 14 | |
| 14 | 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 15 | 16 | pub enum SectionKind { |
@@ -213,6 +214,72 @@ impl InputSection { |
| 213 | 214 | } |
| 214 | 215 | } |
| 215 | 216 | |
| 217 | +// --------------------------------------------------------------------------- |
| 218 | +// Output layout model — populated by Sprint 10's layout pass. |
| 219 | +// --------------------------------------------------------------------------- |
| 220 | + |
| 221 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] |
| 222 | +pub struct OutputSectionId(pub u32); |
| 223 | + |
| 224 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 225 | +pub struct Prot(u32); |
| 226 | + |
| 227 | +impl Prot { |
| 228 | + pub const NONE: Prot = Prot(0); |
| 229 | + pub const READ: Prot = Prot(1); |
| 230 | + pub const WRITE: Prot = Prot(2); |
| 231 | + pub const EXECUTE: Prot = Prot(4); |
| 232 | + pub const READ_ONLY: Prot = Prot(Self::READ.0); |
| 233 | + pub const READ_WRITE: Prot = Prot(Self::READ.0 | Self::WRITE.0); |
| 234 | + pub const READ_EXECUTE: Prot = Prot(Self::READ.0 | Self::EXECUTE.0); |
| 235 | + |
| 236 | + pub fn bits(self) -> u32 { |
| 237 | + self.0 |
| 238 | + } |
| 239 | +} |
| 240 | + |
| 241 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 242 | +pub struct OutputAtom { |
| 243 | + pub atom: AtomId, |
| 244 | + pub offset: u64, |
| 245 | + pub size: u64, |
| 246 | + pub data: Vec<u8>, |
| 247 | +} |
| 248 | + |
| 249 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 250 | +pub struct OutputSection { |
| 251 | + pub segment: String, |
| 252 | + pub name: String, |
| 253 | + pub kind: SectionKind, |
| 254 | + pub align_pow2: u8, |
| 255 | + pub flags: u32, |
| 256 | + pub reserved1: u32, |
| 257 | + pub reserved2: u32, |
| 258 | + pub reserved3: u32, |
| 259 | + pub atoms: Vec<OutputAtom>, |
| 260 | + pub addr: u64, |
| 261 | + pub size: u64, |
| 262 | + pub file_off: u64, |
| 263 | +} |
| 264 | + |
| 265 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 266 | +pub struct OutputSegment { |
| 267 | + pub name: String, |
| 268 | + pub sections: Vec<OutputSectionId>, |
| 269 | + pub vm_addr: u64, |
| 270 | + pub vm_size: u64, |
| 271 | + pub file_off: u64, |
| 272 | + pub file_size: u64, |
| 273 | + pub init_prot: Prot, |
| 274 | + pub max_prot: Prot, |
| 275 | +} |
| 276 | + |
| 277 | +impl OutputSection { |
| 278 | + pub fn is_zerofill(&self) -> bool { |
| 279 | + is_zerofill(self.kind) |
| 280 | + } |
| 281 | +} |
| 282 | + |
| 216 | 283 | #[cfg(test)] |
| 217 | 284 | mod tests { |
| 218 | 285 | use super::*; |