Skip to content

Commit 19a41f6

Browse files
authored
Merge branch 'main' into clippy
2 parents a7e4933 + 2a6b99c commit 19a41f6

17 files changed

Lines changed: 609 additions & 283 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ jobs:
7676
uses: actions/cache@v3
7777
with:
7878
path: |
79-
~/.cargo/registry/index/
80-
~/.cargo/registry/cache/
81-
~/.cargo/git/db/
82-
# invalidate the cache once per month
83-
key: cargo-registry-${{ steps.get-month.outputs.month }}
79+
~/.cargo/registry
80+
~/.cargo/git
81+
# key *and* restore-keys include the month to force a monthly reset instead
82+
# of unbounded growth.
83+
key: cargo-registry-${{ steps.get-month.outputs.month }}-${{ hashFiles('src/Cargo.lock') }}
8484
restore-keys: |
85-
cargo-registry-
85+
cargo-registry-${{ steps.get-month.outputs.month }}
8686
8787
- name: Build
8888
run: . ci/container_scripts/build_and_install.sh

.github/workflows/extra_tests.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ env:
3333

3434
jobs:
3535
build_shadow:
36+
env:
37+
# used by cargo
38+
RUSTC_WRAPPER: sccache
39+
SCCACHE_CACHE_SIZE: 2G
40+
SCCACHE_DIR: /home/runner/.cache/sccache
41+
# SCCACHE_RECACHE: 1 # Uncomment this to clear cache, then comment it back out
3642
runs-on: ubuntu-20.04
3743
container:
3844
# Should match env.CONTAINER.
3945
image: ubuntu:22.04
4046
steps:
47+
- run: apt-get update
4148
- name: Checkout shadow
4249
uses: actions/checkout@v3
4350
with:
@@ -48,31 +55,59 @@ jobs:
4855
# See https://github.com/shadow/shadow/issues/2166
4956
ref: ${{ github.event.pull_request.head.sha }}
5057
persist-credentials: false
51-
- name: Get month
52-
id: get-month
53-
run: |
54-
echo "month=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
5558
- name: Install dependencies
5659
run: |
5760
cd shadow
5861
. ci/container_scripts/install_deps.sh
5962
. ci/container_scripts/install_extra_deps.sh
6063
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
64+
- name: Get month
65+
id: get-month
66+
run: |
67+
echo "month=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
6168
- name: Restore cargo registry cache
6269
uses: actions/cache@v3
6370
with:
6471
path: |
65-
~/.cargo/registry/index/
66-
~/.cargo/registry/cache/
67-
~/.cargo/git/db/
68-
# invalidate the cache once per month
69-
key: cargo-registry-${{ steps.get-month.outputs.month }}
72+
~/.cargo/registry
73+
~/.cargo/git
74+
key: cargo-registry-${{ steps.get-month.outputs.month }}-${{ hashFiles('shadow/src/Cargo.lock') }}
7075
restore-keys: |
71-
cargo-registry-
76+
cargo-registry-${{ steps.get-month.outputs.month }}
77+
- name: Get rust version
78+
id: get-rustv
79+
run: |
80+
echo rustv=\"$(rustc --version)\" >> $GITHUB_OUTPUT
81+
- name: Restore sccache cache
82+
uses: actions/cache@v3
83+
continue-on-error: false
84+
with:
85+
path: ${{ env.SCCACHE_DIR }}
86+
key: sccache-${{ steps.get-month.outputs.month }}-${{ steps.get-rustv.outputs.rustv }}-${{ env.CONTAINER }}-${{ env.CC }}-${{ env.BUILDTYPE }}-${{ hashFiles('shadow/src/Cargo.lock') }}
87+
restore-keys: |
88+
sccache-${{ steps.get-month.outputs.month }}-${{ steps.get-rustv.outputs.rustv }}-${{ env.CONTAINER }}-${{ env.CC }}-${{ env.BUILDTYPE }}-
89+
- name: Install sccache
90+
env:
91+
LINK: https://github.com/mozilla/sccache/releases/download
92+
SCCACHE_VERSION: v0.3.1
93+
run: |
94+
apt-get install -y curl
95+
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
96+
mkdir -p $HOME/.local/bin
97+
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
98+
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
99+
chmod +x $HOME/.local/bin/sccache
100+
echo "$HOME/.local/bin" >> $GITHUB_PATH
101+
- name: Start sccache server
102+
run: sccache --start-server
72103
- name: Build shadow
73104
run: |
74105
cd shadow
75106
. ci/container_scripts/build_and_install.sh
107+
- name: Print sccache stats
108+
run: sccache --show-stats
109+
- name: Stop sccache server
110+
run: sccache --stop-server || true
76111
# We need to wrap in a tarball to preserve permissions.
77112
# We're grabbing the source directory and a lot of the build
78113
# directory here, since there are scripts and generated

.github/workflows/run_tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ jobs:
109109
uses: actions/cache@v3
110110
with:
111111
path: |
112-
~/.cargo/registry/index/
113-
~/.cargo/registry/cache/
114-
~/.cargo/git/db/
115-
# invalidate the cache once per month
116-
key: cargo-registry-${{ steps.get-month.outputs.month }}
112+
~/.cargo/registry
113+
~/.cargo/git
114+
# key *and* restore-keys include the month to force a monthly reset instead
115+
# of unbounded growth.
116+
key: cargo-registry-${{ steps.get-month.outputs.month }}-${{ hashFiles('src/Cargo.lock') }}
117117
restore-keys: |
118-
cargo-registry-
118+
cargo-registry-${{ steps.get-month.outputs.month }}
119119
120120
- name: Build
121121
run: . ci/container_scripts/build_and_install.sh

CHANGELOG.md

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,10 @@
11
A list of user-facing changes since the latest Shadow release.
22

3-
* If running Shadow in Docker, you should use `--tmpfs
4-
/dev/shm:rw,nosuid,nodev,exec,size=1024g` rather than `--shm-size=1024g` to
5-
mount `/dev/shm` as executable. This fixes errors when the managed process
6-
maps executable pages. https://github.com/shadow/shadow/issues/2400
7-
* Added latency modeling and potential thread-yield to rdtsc emulation,
8-
allowing managed code to avoid deadlock in busy-loops that use only the rdtsc
9-
instruction and no syscalls. https://github.com/shadow/shadow/pull/2314
10-
* The build now internally uses `pkg-config` to locate glib, instead of a custom cmake module.
11-
This is the [recommended](https://docs.gtk.org/glib/compiling.html) way of
12-
getting the appropriate glib compile flags, and works better in non-standard layouts such
13-
as in a [guix](https://guix.gnu.org/) environment.
14-
* The `setup` script now has a `--search` option, which can be used to add additional directories
15-
to search for pkg-config files, C headers, and libraries. It obsoletes the options `--library` and `--include`.
16-
* Fixed a bug causing `mmap` to fail when called on a file descriptor that was
17-
opened with `O_NOFOLLOW`. https://github.com/shadow/shadow/pull/2353
18-
* Bare executable names are now resolved by searching shadow's `PATH`. Previously these were
19-
interpreted as relative to the current directory. For backwards compatibility, Shadow will currently
20-
prefer a binary in that location if one is found but log a warning. Such cases should be disambiguated
21-
by using an absolute path or prefixing with `./`.
22-
* Fixed order-of-operations bug in CoDel control law that could lead to an
23-
unexpected packet drop schedule. We think the bug could have caused Shadow to
24-
slightly more aggressively drop packets that have already been sitting in the
25-
CoDel queue for longer than 110 milliseconds. Based on the results of some Tor
26-
network simulations, the bug didn't appear to affect Tor network performance
27-
enough to lead us to believe that previous Tor simulations are invalid.
28-
https://github.com/shadow/shadow/pull/2479
29-
* Changed the default scheduler from `thread-per-host` to `thread-per-core`, which has better
30-
performance on most machines.
31-
* Experimental host heartbeat log messages are enabled by default
32-
(`experimental.host_heartbeat_interval` defaults to `"1 sec"`), but the
33-
format of these messages is not stable.
34-
* Some of Shadow's emulated syscalls and object allocations are counted and
35-
written to a `shadow.data/sim-stats.json` file.
36-
* Improved experimental strace logging for `brk`, `mmap`, `munmap`, `mremap`,
37-
`mprotect`, `open`, and `openat` syscalls.
38-
* Several small simulation examples were added to an `examples/` directory.
39-
* Fixed the file access mode for stdin in the managed process (changed from
40-
`O_WRONLY` to `O_RDONLY`).
41-
* Fixed support for `readv` and `writev` syscalls, and added support for
42-
`preadv` and `pwritev`.
43-
* Fixed a rare crash in Shadow's shim while logging.
44-
https://github.com/shadow/shadow/pull/2459
45-
* Set the `ifa_netmask` field in `getifaddrs()` to improve compatibility with
46-
Node.js applications. https://github.com/shadow/shadow/pull/2456
47-
* Shadow no longer depends on its absolute installed location, allowing the
48-
installation directory to be safely moved. https://github.com/shadow/shadow/pull/2391
49-
* Shadow now emulated `PR_SET_DUMPABLE`, allowing it to work for programs that try to
50-
disable memory inspection. https://github.com/shadow/shadow/pull/2370
51-
* Added new test cases to check Shadow's simulated network performance. These
52-
new tests help us verify that Shadow's network stack is capable of
53-
facilitating high-bandwidth transfers when using a single TCP stream or when
54-
using many streams in parallel, and across networks with various latency and
55-
bandwidth characteristics. Since we run the tests as part of our CI, it is now
56-
much more likely that we will notice when we make changes that significantly
57-
reduces Shadow's simulated network performance. We plan to expand the cases
58-
that we test in future releases. https://github.com/shadow/shadow/pull/2549
3+
* Fixed an uncommon memory leak in `epoll_ctl`.
4+
https://github.com/shadow/shadow/pull/2586
595
* (add entry here)
606

61-
Raw changes since v2.2.0:
7+
Raw changes since v2.3.0:
628

63-
* [Merged PRs](https://github.com/shadow/shadow/pulls?q=is%3Apr+merged%3A%3E2022-07-19T16%3A42-0400)
64-
* [Closed issues](https://github.com/shadow/shadow/issues?q=is%3Aissue+closed%3A%3E2022-07-19T16%3A42-0400)
9+
* [Merged PRs](https://github.com/shadow/shadow/pulls?q=is%3Apr+merged%3A%3E2022-11-29T13%3A02-0500)
10+
* [Closed issues](https://github.com/shadow/shadow/issues?q=is%3Aissue+closed%3A%3E2022-11-29T13%3A02-0500)

docs/maintainer_playbook.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ Now if everything looks good, push to GitHub:
6969
git push origin "v$VERSION"
7070

7171
Our releases will then be tagged off of the main branch.
72+
73+
You probably want to also reset the `CHANGELOG.md` file in a new commit after
74+
tagging/pushing the release.

src/main/host/descriptor/epoll.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static gint _epollwatch_compare(gconstpointer ptr_1, gconstpointer ptr_2) {
171171
/* forward declaration */
172172
static void _epoll_fileStatusChanged(Epoll* epoll, const EpollKey* key);
173173

174+
// Will take its own reference to the file object.
174175
static EpollWatch* _epollwatch_new(Epoll* epoll, int fd, EpollWatchTypes type,
175176
EpollWatchObject object, const struct epoll_event* event,
176177
const Host* host) {
@@ -183,6 +184,8 @@ static EpollWatch* _epollwatch_new(Epoll* epoll, int fd, EpollWatchTypes type,
183184
* (which is freed below in _epollwatch_free) */
184185
if (type == EWT_LEGACY_FILE) {
185186
legacyfile_ref(object.as_legacy_file);
187+
} else if (type == EWT_GENERIC_FILE) {
188+
object.as_file = file_cloneRef(object.as_file);
186189
}
187190

188191
watch->id = ++epoll->watch_id_counter;
@@ -432,13 +435,15 @@ static const gchar* _epoll_operationToStr(gint op) {
432435
}
433436
}
434437

438+
// Increases the reference count of the inner file.
435439
static void _getWatchObject(const Descriptor* descriptor, EpollWatchTypes* watchType,
436440
EpollWatchObject* watchObject) {
437441
LegacyFile* legacyDescriptor = descriptor_asLegacyFile(descriptor);
438442

439443
/* if the descriptor is for a legacy file */
440444
if (legacyDescriptor != NULL) {
441445
*watchType = EWT_LEGACY_FILE;
446+
legacyfile_ref(legacyDescriptor);
442447
watchObject->as_legacy_file = legacyDescriptor;
443448
} else {
444449
const File* file = descriptor_newRefFile(descriptor);
@@ -475,17 +480,20 @@ gint epoll_control(Epoll* epoll, gint operation, int fd, const Descriptor* descr
475480
case EWT_GENERIC_FILE:
476481
key.objectPtr = file_getCanonicalHandle(watchObject.as_file);
477482
break;
478-
default: utility_panic("unrecognized watch type"); return -ENOENT;
483+
default: utility_panic("unrecognized watch type");
479484
}
480485

481486
EpollWatch* watch = g_hash_table_lookup(epoll->watching, &key);
482487

488+
int rv = 0;
489+
483490
switch (operation) {
484491
case EPOLL_CTL_ADD: {
485492
/* EEXIST op was EPOLL_CTL_ADD, and the supplied file descriptor
486493
* fd is already registered with this epoll instance. */
487494
if(watch) {
488-
return -EEXIST;
495+
rv = -EEXIST;
496+
break;
489497
}
490498

491499
/* start watching for status changes */
@@ -517,7 +525,8 @@ gint epoll_control(Epoll* epoll, gint operation, int fd, const Descriptor* descr
517525
case EPOLL_CTL_MOD: {
518526
/* ENOENT op was EPOLL_CTL_MOD, and fd is not registered with this epoll instance */
519527
if(!watch) {
520-
return -ENOENT;
528+
rv = -ENOENT;
529+
break;
521530
}
522531

523532
MAGIC_ASSERT(watch);
@@ -538,7 +547,8 @@ gint epoll_control(Epoll* epoll, gint operation, int fd, const Descriptor* descr
538547
case EPOLL_CTL_DEL: {
539548
/* ENOENT op was EPOLL_CTL_DEL, and fd is not registered with this epoll instance */
540549
if(!watch) {
541-
return -ENOENT;
550+
rv = -ENOENT;
551+
break;
542552
}
543553

544554
MAGIC_ASSERT(watch);
@@ -567,7 +577,17 @@ gint epoll_control(Epoll* epoll, gint operation, int fd, const Descriptor* descr
567577
}
568578
}
569579

570-
return 0;
580+
switch (watchType) {
581+
case EWT_LEGACY_FILE:
582+
legacyfile_unref(watchObject.as_legacy_file);
583+
break;
584+
case EWT_GENERIC_FILE:
585+
file_drop(watchObject.as_file);
586+
break;
587+
default: utility_panic("unrecognized watch type");
588+
}
589+
590+
return rv;
571591
}
572592

573593
guint epoll_getNumReadyEvents(Epoll* epoll) {

src/main/host/descriptor/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,15 @@ mod export {
950950
unsafe { Box::from_raw(file as *mut File) };
951951
}
952952

953+
/// Increment the ref count of the `File` object. The returned pointer will not be the same as
954+
/// the given pointer (they are distinct references), and they both must be dropped with
955+
/// `file_drop` separately later.
956+
#[no_mangle]
957+
pub extern "C" fn file_cloneRef(file: *const File) -> *const File {
958+
let file = unsafe { file.as_ref() }.unwrap();
959+
Box::into_raw(Box::new(file.clone()))
960+
}
961+
953962
/// Get the state of the `File` object.
954963
#[no_mangle]
955964
pub extern "C" fn file_getStatus(file: *const File) -> c::Status {

0 commit comments

Comments
 (0)