|
1 | 1 | use std::collections::HashMap;
|
2 | 2 | use std::convert::{TryFrom, TryInto};
|
3 | 3 | use std::fs::{remove_file, File, OpenOptions};
|
4 |
| -use std::io::{Read, Write}; |
| 4 | +use std::io::{Read, Seek, SeekFrom, Write}; |
5 | 5 | use std::path::PathBuf;
|
6 | 6 | use std::time::SystemTime;
|
7 | 7 |
|
@@ -264,6 +264,40 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
264 | 264 | }
|
265 | 265 | }
|
266 | 266 |
|
| 267 | + fn lseek64( |
| 268 | + &mut self, |
| 269 | + fd_op: OpTy<'tcx, Tag>, |
| 270 | + offset_op: OpTy<'tcx, Tag>, |
| 271 | + whence_op: OpTy<'tcx, Tag>, |
| 272 | + ) -> InterpResult<'tcx, i64> { |
| 273 | + let this = self.eval_context_mut(); |
| 274 | + |
| 275 | + this.check_no_isolation("lseek64")?; |
| 276 | + |
| 277 | + let fd = this.read_scalar(fd_op)?.to_i32()?; |
| 278 | + let offset = this.read_scalar(offset_op)?.to_i64()?; |
| 279 | + let whence = this.read_scalar(whence_op)?.to_i32()?; |
| 280 | + |
| 281 | + let seek_from = if whence == this.eval_libc_i32("SEEK_SET")? { |
| 282 | + SeekFrom::Start(offset as u64) |
| 283 | + } else if whence == this.eval_libc_i32("SEEK_CUR")? { |
| 284 | + SeekFrom::Current(offset) |
| 285 | + } else if whence == this.eval_libc_i32("SEEK_END")? { |
| 286 | + SeekFrom::End(offset) |
| 287 | + } else { |
| 288 | + let einval = this.eval_libc("EINVAL")?; |
| 289 | + this.set_last_error(einval)?; |
| 290 | + return Ok(-1); |
| 291 | + }; |
| 292 | + |
| 293 | + if let Some(handle) = this.machine.file_handler.handles.get_mut(&fd) { |
| 294 | + let result = handle.file.seek(seek_from).map(|offset| offset as i64); |
| 295 | + this.try_unwrap_io_result(result) |
| 296 | + } else { |
| 297 | + this.handle_not_found() |
| 298 | + } |
| 299 | + } |
| 300 | + |
267 | 301 | fn unlink(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
268 | 302 | let this = self.eval_context_mut();
|
269 | 303 |
|
|
0 commit comments