►
From YouTube: Unix systems programming in Rust — Kamal Marhubi
Description
Materials for this talk are available at http://www.rust-belt-rust.com/kamal-marhubi-system-programming-16x9.pdf
Systems programming often seems scary. To start with, you need to know C. Debugging obscure pointer issues is hard, and nobody will tell you if you're passing the wrong type of flag to a function. I've been doing a bunch of systems programming in Rust recently, and I've found it a lot easier, more accessible, and more fun.
http://www.rust-belt-rust.com/
A
A
My
analysis
shows
that
this
is
the
twice
as
rusty
as
any
other
rust
conference,
which
makes
it
the
rustiest
rust
conference
ever
so
we're
all
agreed
right.
Rust
is
awesome,
yeah
and
we
are
in
the
last
session-
and
you
know
I'm
gonna
direct
attention
away
from
me
to
the
organizers
for
five
seconds
and
just
say
thanks
so
much
for
organizing
this.
This
has
been
really
great.
Okay,
now
back
to
me,
so
the
rescue
truck
comes
from
ever
we
agreed
that
rust
is
awesome,
but
I
want
to
convince
you
that
systems,
programming
and
rust
is
awesome.
A
In
fact,
I
think
systems.
Programming
is
awesome
even
without
rust,
but
Rhett
just
makes
it
that
much
better,
but
to
get
started.
We
have
to
start
with.
You
know
what
do
I
mean
by
UNIX
systems.
Programming
and
I've
got
a
tongue-in-cheek
definition,
which
is
where
you
spend
more
time.
Looking
at
man
pages,
then
it's
Stack
Overflow.
A
This
is
like
extra
useful,
because
it
also
means
that
you
don't
need
an
internet
connection
to
kind
of
make
a
good
deal
of
progress,
but
like
more
seriously
systems
programming,
especially
UNIX
systems,
program,
I,
think,
is
a
lot
about
making
system
calls
and
dealing
with
the
interface
that
we
have
to
the
the
kernel
of
the
OS
that
we're
running
on.
So
what
our
system
calls
I
like
to
think
of
system
calls
as
writing
a
letter
to
the
kernel.
A
It's
like
dear
Colonel,
please
open
this
jiff
for
me
thanks
and
then
the
kernel
gets
back
to
us
with
this
jiff
saw
earlier
today,
I'm
not
going
to
leave
it
up
for
too
long
because
it's
dangerous,
but
the
the
the
key
thing
here
is
that
there
are
a
lot
of
operations
that
is
not
safe
or
secure
for
our
programs
to
do,
and
we
have
to
ask
the
kernel
to
do
them
for
us.
Opening
files
make
sure
that
we
have
the
right
permissions
and
so
on.
A
So
we
make
a
system
call
dear
colonel
and
then
it
does
all
the
checking
and
makes
it
that
we
have
that
file
open
there.
It
is
again
for
a
couple
seconds
so
here
are
a
couple
of
example:
system
calls
like
they're,
not
that
alien.
If
you
haven't
done
systems
programming,
they
should
still
be
familiar.
When
we're
doing
file
operations,
we
have
an
open
system
call
which
we
just
saw.
It
doesn't
actually
give
you
a
diff.
It
would
give
you
a
file.
A
Descriptor
and
you'd
have
to
go
and
do
a
bunch
of
other
stuff
to
get
the
jiff,
but
you
know
I
think
it
illustrates
well
enough,
but
open
readwrite.
These
are
you
know
all
things
we
expect
to
do
with
files
processes.
If
we
have
a
shell,
it's
gonna
fork.
It's
gonna
exec
the
new
process.
It's
going
to
you're,
probably
gonna,
have
to
kill
it
at
some
point
because
it's
broken
in
networking.
You
know
sockets
and
you
create
a
socket
with
socket.
You
connect,
you
listen,
you
accept
a
connection.
A
These
are
all
system
calls
that
should
sound
familiar
if
you've
done
programming
that
is
involving
networking
or
files,
but
they,
you
may
not
recognize
them
as
being
something
that
kernel
knows
especially
about,
but
they
are
so
to
give
a
few
examples
before
going
further
into.
Why
I
think
rust
is
great.
Here
are
a
couple
of
examples
of
things
I've
done
or
worked
on
in
rust
in,
like
the
UNIX
systems,
the
kind
of
world
I've
just
been
describing.
A
A
Target
containing
thing
this
is
running
so
the
route
FS
directory.
There
is
an
extracted,
Debian,
docker
image
and
I'm
now
route
inside
a
little
well,
if
I
can
type
I'm
now
route
inside
a
little
container,
but
I
didn't
need
route
to
get
into
the
container,
which
is
great,
I
have
like
ideas
for
where
I'm
going
to
use
this
to
allow
using
docker
and
Travis
CI
sometime
soon,
hopefully
without
it
being
slow.
A
But
this
is
a
cool
little
thing
like
you
end
up
learning
a
lot
when
you
do
something
like
this
about
how
all
of
these
weird
systems
are
put
together.
So
that's
my
little
project
containing
thing
which
I've
just
come
back
to
after
months
of
hiatus.
Ruby
stacked
rates
this.
If
anyone
was
at
the
rest
conf,
this
came
up
briefly
in
Julia.
Evans
is
closing
keynote
I
wasn't
able
to
be
there,
but
I
did
feature
in
one
slide.
A
So
this
is
like
the
best
I
can
do
it's
like
just
some
recursive
calls
and
they
sleep
and
stuff
and
what
the
Ruby
stacktrace
program
does
is.
It
goes
and
like
routes
around
inside
the
memory
of
the
Ruby
process
and
reads
out
the
Ruby
stack,
and
so
it's
able
to
like
see
where
time
is
being
spent
in
that
Ruby
process.
It
also
is
able
to
do
flame
graphs,
but
that's
a
bit
more
involved.
So
I'm
not
gonna
demo
here,
but
this
is
like
kind
of
sampling.
A
I,
don't
know
every
100
milliseconds
of
like
what
is
that
Ruby
process
doing
that
go
away,
okay,
so
silly
things
are
okay
too.
So
those
are
like
kind
of
serious
projects
right
that
could
be
useful
for
build
systems
or
in
production
or
something,
but
at
bang
bang
con,
which
is
this
really
awesome
conference
in
New
York,
which
is
like
lots
of
10-minute
talks
of
people
sharing
something
exciting
about
about
computers.
I
on
stage
broke
my
computer
with
pipes
with
a
rest
program
by
invoking
the
out
of
memory
killer
by
exhausting
the
amount
of
memory.
A
My
computer
had
I'm
not
going
to
demo
that
one,
because
that
actually
like
breaks
my
computer
I'm
using
it
I,
did
break
my
computer
onstage
because
it
was
the
end
of
the
talk
here
in
the
middle
of
the
talk
it's
dangerous,
but
silly
things
are
also
an
excellent
way
to
learn
a
lot
more
about
how
your
computers
work
and
the
reason
I
think
rust
is
really
great.
For
systems
programming
comes
down
to
a
few
things.
A
We're
like
familiar
with
these
slogans
a
little
bit
like
rust
lets.
You
be
fearless
and
a
good
analogy,
or
not
analogy
example.
I.
Think
of
this
is
when
you
know
we
were
working
on
the
Ruby
stacktrace
program
and
Julia
had
reached
this
point.
Where
she
was
getting
hard,
also
I
think
Russ
is
really
convenient.
A
We
we
can
kind
of
bypass
the
standard
library
so
to
go
into
a
few
examples
of
what
I
mean
by
rust,
letting
us
be
fearless,
so
systems
programming
is
traditionally
done
in
C.
You
know
there's
millions
and
millions
and
millions
of
lines
of
C
code,
and
there
are
a
bunch
of
things
that
are
really
scary
about
C.
If
you
don't
actually
know
C
like
me,
so
there
was
a
person
that,
on
the
first
day,
who
said
they
spent
20
years,
writing
Harry
C
programs.
A
That's
not
me
and
that's
not
lots
of
people
and
getting
like
simple
things
like
Eric.
Well,
simple,
but
error
checking
is
hard,
but
error.
Checking
is
much
easier
and
rust
because
of
the
result
type
then
in
C,
where
its
while
it
depends
on
the
library
and
the
program
that
you're
using
exactly
how
handle
there's
no
standard
memory
management.
This
is
kind
of
the
main
reason
we've
translated.
A
A
Do
you
want
some
functionality?
That's
not
in
the
standard
library,
there's,
probably
a
crate
that
will
handle
it
in
a
you
know,
best
practices,
kind
of
way,
there's
like
a
map,
crates
and
signal
handling,
crates
and
crates
for
all
kinds
of
things,
and
this
I
think
that
the
ability
to
use
somebody
else's
library
by
adding
one
line
to
a
config
file-
that's
also
really
really
convenient.
A
So,
moving
on
to
the
next
thing,
I
think
is
great,
which
is
that
rust
allows
transparent
access
to
the
underlying
OS
and
in
the
standard
library
we
do
have
STD
OS
UNIX.
This
is
a
kind
of
grab
bag
of
ways
to
add
UNIX
extensions
to
various
types
that
get
file
descriptors
from
files
and
sockets.
It
lets
us
do
some
extra
things
with
processes
to
like
set
up
the
environment
a
bit
more
specifically
before
we
run
a
command.
A
Oh
yeah,
strings
in
UNIX
are
byte
strings,
and
so
there's
like
interoperability,
interoperability
between
Oster
and
stir
that
isn't
available
or
or
between
OS
string
and
bytes.
That's
not
available
on
Windows
because
of
the
WTF
thing
that
I
still
don't
understand.
So
that's
great,
but
we
can
actually
go.
We
can
get
around
the
standard
library
and
get
even
you
know
closer
access
to
what's
going
on
below,
because
we
have
this
fantastic.
A
Compatibility
like
we
can
have
C
functions
that
are
called
transparently
from
our
stuff.
We
can
have
structs
that
mirror
the
C
struct
exactly
and
just
call
directly
into
Lipsy
or
into
whatever
other
c
libraries
that
are
helping
us
do
what
we
need
to
do
so.
This
lets
us
drop
down
below
the
lip
standard
and
I'd
be
completely
remiss
here.
If
I
didn't
bring
up.
A
Miss
ordering
my
slides
sorry
so
examples
of
where
the
dropping
down
below
Lib
standard
come
in
is
where
we
want
to
go
more
specific
than
just
UNIX
versus
not
UNIX,
but
into
specific
things
about
which
flavor
of
Unix.
So
the
examples
that
I
gave
with
containing
thing
is
using
these
kind
of
container
or
oriented
system
calls
like
unshare,
which
does
very
weird
things.
I
highly
recommend.
Reading
the
I
think
there's
a
series
on
the
Linux
weekly
news
about
what
all
this
namespace
stuff
is.
A
It's
kind
of
mind-blowing
there's
mount,
which
was
how
I
was
able
to
change
the
view
of
the
file
system
inside
the
container
in
the
Ruby
stack
trace.
We're
using
this
really
like
I,
don't
know
how
I
feel
about
this
system
call
it
lets.
You
just
read
another
processes:
memory.
It's
just
like
hey
I,
want
to
read
like
10
kilobytes
out
of
that
part
of
that
person's
memory,
and
then
you
can
just
read
it
and
then
you
can
do
whatever
you
want.
So
that's
what
that
stack
program
is
doing.
A
If
you've
written
C
systems,
programs
there's
like
some
slightly
annoying
parts
where
error
handling
is
not
as
nice
as
you
would
like,
especially
from
the
rough
side.
That's
a
question
for
the
room.
Actually,
what
is
the
right
word
for
this?
Turning
something
more
rusty
like
rusty,
5x,
it
dies
anyway,
like
making
lip
see
nicer
to
use
from
rust
right.
So
the
example
I
mentioned
there
result
instead
of
like
returning
minus
1
and
look
err.
A
No-
and
you
know-
maybe
you
forget,
do
that
and
things
go
wrong
in
some
sense,
like
we
kind
of
read
the
man
pages,
so
you
don't
have
to
because
there
are
some
cases
where,
like
the
exact
return
value
that
ignites
an
error
is
like
naught
minus
one-
maybe
maybe
it's
like
you
know,
plus
one
I
don't
know,
but
they
exist
and
it's
like
it's
Harry.
We
translate
it
to
a
result.
A
A
If
you
want
to
create
a
pipe
where
you
get
to
file
the
scripters
you've
liked,
you
know
pipe,
and
then
you
have
to
create
an
array
on
the
stack
and
then
check
that
it's
minus
one
and
check
check
if
it
failed
and
then
return
minus
one.
All
of
that
in
rust
is
just
like
try
pipe
or
in
rust
soon
try
it's
a
pipe
with
an
upwards.
A
C
A
Got
those
right
yeah
I
did,
but
you
know
the
referring
to
like
pipe
FD
0
and
pipe
FD,
1
kind
of
gets
old,
so
I
typically
end
up
renaming
them
as
read
and
write
anyway.
It's
great
to
do
that
in
one
line
instead
of
six.
This
is
one
of
my
favorites
is
using
slices
instead
of
void,
star
and
size
pairs.
So
this
is
like
in
system
calls
like
read
and
write
where
you're
passing
a
bunch
of
memory
over
and
something
supposed
to
happen
to
it
or
in
like
that
process.
A
Vm
read,
v1
I
gave
as
an
example
where
you're
saying
please
get
me
that
much
memory
from
that
other
process.
It's
all
like
void,
star
size,
pairs
and
actually
I'm.
Just
gonna
go
on
a
little
aside
here
because,
like
I
love
slices
like
I,
think
that
slices
are
one
of
the
best
things
in
rust,
they're
a
standard
way
to
pass
pieces
of
buffers
that
aren't
necessarily
yours
to
someone
else
and
everything
just
works
out
like
standard
means
it's
ecosystem
wide.
This
is
so
so
so
important
I've
like
done
some
C++
programming
and
there's
no
standard.
A
There
are
just
you
know
in
Google
code,
there's
string
piece
in
I,
don't
know.
What's
in
Mozilla
code
by
I
did
a
little
bit
of
captain
proto
code
and
there's
like
an
array
pointer,
they're,
all
Stan's
start
length
or
start
end
pairs,
but
they're,
not
standard
you're
gonna
have
to
write
all
these
inter
conversions.
If
you
ever
want
to
reach
across
into
a
different
part
of
the
ecosystem,
and
that's
just
really
annoying
C++
17
will
hopefully
have
a
string
view
which
will
be
kind
of
like
a
stare
slice.
A
That's
2017,
it
still
won't
protect
you
from
lifetime
mishaps
and
the
fact
that
is
2017
and
C++
is
gonna,
be
by
then
34
years
old
or
something
you
won't
actually
be
able
to
use
it
if
you're
interpreting
with
any
other
code
Russ
had
slices
from
the
beginning.
This
means
that
this
idea
of
slices
of
transparently
being
able
to
pass
memory
across
library
boundaries
across
into
you
know
some
crate.
You
just
got
out
of
crates,
IO
being
able
to
use
a
part
of
a
memory,
mapped
file
and
just
pass
it
to
some
crate.
A
That
knows
nothing
about
memory
map
files
that
just
works,
because
we
had
slices
from
the
very
start
and
I
this
like
a
bit
extreme
but
I
think
if
all
ownership
like
the
whole,
like
borrow
check
stuff
got
us,
was
a
safe
way
to
pass
bytes
to
other
functions
without
needing
to
allocate
and
copy,
and
without
needing
to
worry
that
we're
gonna
shoot
ourselves
in
the
foot
by
having
some
kind
of
dangling
pointer
thing,
I
think
it
would
have
been
worth
it
all
of
that
borrow
checking
pain.
Of
course
it
gets
us
so
much
more.
A
So
that's
like
pretty
great
end
of
a
side,
so
Nix
is
great
and
I
think
you
should
check
it
out.
It's
on
crates
and
now
that,
like
I've,
hopefully
convinced
you
a
little
bit
that
you
would
like
to
explore
this
systems
programming
world
I
want
to
give
you
a
couple
of
ideas
of
how
you
might
get
started.
So
this
is
not
a
rust
thing,
but
I
wrote
a
workshop
for
some
conference.
Strangely,
maybe
a
couple
of
years
ago.
A
Just
try
some
other
systems.
Programming
in
yeah
in
rust,
with
NYX
I,
think
Nick's
does
make
it
quite
a
bit
nicer.
So
that's
why
I'm
keep
kind
of
keep
pitching
it
and
you
can
learn
a
lot
by
being
silly.
The
pipes
thing
I
mentioned
where
I
broke
my
computer
on
stage
by
exhausting
the
memory
of
the
system
via
pipes
like
I,
learned
an
incredible
amount
of
weird
but
stuff.
A
That's
actually
coming
useful
about
process
memory
limits
and
how
memory
is
accounted
two
different
processes
and
how
you
can
ask
for
pipes
that
are
bigger
than
the
normal
pipe.
This
is
like
part
of
how
you
go.
You
can
go
in
this
direction
of
breaking
things.
You
can
say,
give
me
bigger
pipes,
please,
colonel
and
just
I
think
that
systems
programming
is
often
viewed
as
this.
Like
really
kind
of
serious.
A
You
know,
I
trimmed
my
beard
because
I
was
going
through
u.s.
customs
and
they
hate
me.
Sorry,
that's
remind
Middle.
Eastern
names
are
difficult.
So,
but
you
know
it's
it's
viewed
as
like.
You
know
serious,
like
neckbeard
kind
of
like
gray
beard
really
we're
gonna
do
some
like
hard
programming
here
you
can
just
be
silly.
You
can
do
all
this
really
really
silly
stuff
with
your
systems.
Programming
you'll
learn
a
lot.
A
It
doesn't
matter
if
you
make
something:
that's
gonna
be
like
super
useful
and
like
docker
or
it's
gonna,
be
you
know
if
you're
building
some
of
the
awesome
things
that
people
in
this
room
I'm
sure
have
built,
you
can
just
go
off
and
do
something
silly
and
you'll
still
learn
a
lot
and
how
you
can
help
with
this
kind
of
thing.
I'm,
just
gonna
kind
of
have
a
little
country,
tunics
wink,
but
more
importantly,
I
think
is
do
cool
things
and
tell
other
people
about
them.
So
this
could
be
writing
blog
posts.
A
A
D
A
I.
Consider
that
silly
because
it's
not
really
a
useful
attack.
Somebody
would
have
to
run
your
program
on
their
system
and
then
their
system
will
stop
working.
But
that's
like
not
super
useful,
non
pipe.
Silly
things
since
fork
bombing
yeah,
I,
guess
you
could
you
could
find
other
ways
to
exhaust
system
resources.