1/* |
2 * Copyright (c) 2014-2017 ARM Limited |
3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated --- 28 unchanged lines hidden (view full) --- 39 40#include "dev/virtio/fs9p.hh" 41 42#include <fcntl.h> 43#include <netdb.h> 44#include <netinet/in.h> 45#include <sys/socket.h> 46#include <sys/types.h> |
47#include <sys/un.h> |
48#include <unistd.h> 49 |
50#include <fstream> 51 52#include "base/output.hh" |
53#include "debug/VIO9P.hh" 54#include "debug/VIO9PData.hh" 55#include "params/VirtIO9PBase.hh" 56#include "params/VirtIO9PDiod.hh" 57#include "params/VirtIO9PProxy.hh" 58#include "params/VirtIO9PSocket.hh" 59#include "sim/system.hh" 60 --- 272 unchanged lines hidden (view full) --- 333 const Params *p(dynamic_cast<const Params *>(params())); 334 int pipe_rfd[2]; 335 int pipe_wfd[2]; 336 const int DIOD_RFD = 3; 337 const int DIOD_WFD = 4; 338 339 const char *diod(p->diod.c_str()); 340 |
341 DPRINTF(VIO9P, "Using diod at %s \n", p->diod.c_str()); 342 |
343 if (pipe(pipe_rfd) == -1 || pipe(pipe_wfd) == -1) 344 panic("Failed to create DIOD pipes: %i\n", errno); 345 346 fd_to_diod = pipe_rfd[1]; 347 fd_from_diod = pipe_wfd[0]; 348 349 diod_pid = fork(); 350 if (diod_pid == -1) { 351 panic("Fork failed: %i\n", errno); 352 } else if (diod_pid == 0) { 353 close(STDIN_FILENO); 354 355 if (dup2(pipe_rfd[0], DIOD_RFD) == -1 || 356 dup2(pipe_wfd[1], DIOD_WFD) == -1) { 357 358 panic("Failed to setup read/write pipes: %i\n", 359 errno); 360 } 361 |
362 // Create Unix domain socket 363 int socket_id = socket(AF_UNIX, SOCK_STREAM, 0); 364 if (socket_id == -1) { 365 panic("Socket creation failed %i \n", errno); 366 } 367 // Bind the socket to a path which will not be read 368 struct sockaddr_un socket_address; 369 memset(&socket_address, 0, sizeof(struct sockaddr_un)); 370 socket_address.sun_family = AF_UNIX; 371 372 const std::string socket_path = simout.resolve(p->socketPath); 373 fatal_if(!OutputDirectory::isAbsolute(socket_path), "Please make the" \ 374 " output directory an absolute path, else diod will fail!\n"); 375 376 // Prevent overflow in strcpy 377 fatal_if(sizeof(socket_address.sun_path) <= socket_path.length(), 378 "Incorrect length of socket path"); 379 strncpy(socket_address.sun_path, socket_path.c_str(), 380 sizeof(socket_address.sun_path)); 381 382 if (bind(socket_id, (struct sockaddr*) &socket_address, 383 sizeof(struct sockaddr_un)) == -1){ 384 perror("Socket binding"); 385 panic("Socket binding to %i failed - most likely the output dir" \ 386 " and hence unused socket already exists \n", socket_id); 387 } 388 |
389 execlp(diod, diod, 390 "-f", // start in foreground 391 "-r", "3", // setup read FD 392 "-w", "4", // setup write FD 393 "-e", p->root.c_str(), // path to export 394 "-n", // disable security 395 "-S", // squash all users |
396 "-l", socket_path.c_str(), // pass the socket |
397 (char *)NULL); |
398 perror("Starting DIOD"); 399 panic("Failed to execute diod to %s: %i\n",socket_path, errno); |
400 } else { 401 close(pipe_rfd[0]); 402 close(pipe_wfd[1]); 403 } 404 405#undef DIOD_RFD 406#undef DIOD_WFD 407} --- 125 unchanged lines hidden --- |