fs9p.cc (11793:ef606668d247) fs9p.cc (12076:d6fa15da87cd)
1/*
1/*
2 * Copyright (c) 2014-2015 ARM Limited
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>
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>
47#include <unistd.h>
48
48#include <unistd.h>
49
50#include <fstream>
51
52#include "base/output.hh"
49#include "debug/VIO9P.hh"
50#include "debug/VIO9PData.hh"
51#include "params/VirtIO9PBase.hh"
52#include "params/VirtIO9PDiod.hh"
53#include "params/VirtIO9PProxy.hh"
54#include "params/VirtIO9PSocket.hh"
55#include "sim/system.hh"
56

--- 272 unchanged lines hidden (view full) ---

329 const Params *p(dynamic_cast<const Params *>(params()));
330 int pipe_rfd[2];
331 int pipe_wfd[2];
332 const int DIOD_RFD = 3;
333 const int DIOD_WFD = 4;
334
335 const char *diod(p->diod.c_str());
336
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
337 if (pipe(pipe_rfd) == -1 || pipe(pipe_wfd) == -1)
338 panic("Failed to create DIOD pipes: %i\n", errno);
339
340 fd_to_diod = pipe_rfd[1];
341 fd_from_diod = pipe_wfd[0];
342
343 diod_pid = fork();
344 if (diod_pid == -1) {
345 panic("Fork failed: %i\n", errno);
346 } else if (diod_pid == 0) {
347 close(STDIN_FILENO);
348
349 if (dup2(pipe_rfd[0], DIOD_RFD) == -1 ||
350 dup2(pipe_wfd[1], DIOD_WFD) == -1) {
351
352 panic("Failed to setup read/write pipes: %i\n",
353 errno);
354 }
355
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
356 execlp(diod, diod,
357 "-f", // start in foreground
358 "-r", "3", // setup read FD
359 "-w", "4", // setup write FD
360 "-e", p->root.c_str(), // path to export
361 "-n", // disable security
362 "-S", // squash all users
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
363 (char *)NULL);
397 (char *)NULL);
364 panic("Failed to execute diod: %i\n", errno);
398 perror("Starting DIOD");
399 panic("Failed to execute diod to %s: %i\n",socket_path, errno);
365 } else {
366 close(pipe_rfd[0]);
367 close(pipe_wfd[1]);
368 }
369
370#undef DIOD_RFD
371#undef DIOD_WFD
372}

--- 125 unchanged lines hidden ---
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 ---