Skip to content

Instantly share code, notes, and snippets.

@orumin
Created February 26, 2020 07:02
Show Gist options
  • Save orumin/8c001967bcf5ccca16af958196608574 to your computer and use it in GitHub Desktop.
Save orumin/8c001967bcf5ccca16af958196608574 to your computer and use it in GitHub Desktop.
Proposal for Google Summer of Code 2014

General Information

Name: Minoru KANATSU

Email: [email protected]

IM/IRC: Skype:kotatsu_mikan

Languages (spoken and written): Japanese, English

Availabillity:
I can spend 20 hours per week.

Bio:
5th grade student in Matsue College of Technology(- March 31st, 2014)
3rd grade student in Osaka University(April 1st, 2014 - )
Hacking system call of Linux kernel and developing UEFI apps for a hobby.
An attendee of "Security Programming Camp 2012", the summer camp for special skilled students held by Ministry of Economy, Trade and Industry

Possible Mentor: Takuya ASADA

Project Information

Project Title:

Porting CRuby to OSv

Project Description:

Right now OSv has two Ruby implementation, mruby and JRuby.

mruby is lightweight implementation of Ruby, but it doesn't have API compatibility with existing Ruby application, such as Ruby on Rails.
JRuby provides standard Ruby API, but many Ruby applications use a gem with C extension, which won't work on JRuby.
Therefore JRuby has compatibility issue too.
So most of Ruby users using CRuby, if it can work on OSv, we can get lot of benefit from that.

Porting CRuby is brought us powerful and usability,
but OSv libc doesn't have enough functions to port it.

The project goal is to port CRuby to OSv, and support Ruby applications on top of it.
Additionally, I want to provide these things:

  • Ruby application target on OSv module infrastructure, which provides a way to use gems in OSv
  • A Ruby application sample witch using the target (Right now I'm considering to port CLI based Twitter client called "earthquake.gem")

\

The project steps are:

Find missing functions on OSv libc (Already done)

Find missing functions on OSv libc, using check-libcfunc-avail.sh (https://groups.google.com/d/msg/osv-dev/nJcqMVtAUWg/rKAp6DUSuBcJ).\ Below is a list of missing functions:

  • Missing function for ruby
pthread_attr_getguardsize
raise
utimensat
_exit
chroot
pthread_attr_setinheritsched
backtrace_symbols
eaccess
__isinf
swapcontext
getsid
rewinddir
setgroups
crypt
setsid
malloc_usable_size
execve
ppoll
__memmove_chk
makecontext
prctl
getgroups
killpg
endpwent
seekdir
lchown
telldir
__strncpy_chk
setreuid
sendfile
chown
setregid
getpwnam_r
__longjmp_chk
waitpid
getpgrp
flock
getpgid
getgrnam_r
setpgid
pipe2
getppid
execle
execl
getcontext
initgroups
execv
setegid
seteuid
  • Missing function for libgmp
raise
_obstack_newchunk
__memset_chk
obstack_vprintf
  • Missing function for libcrypt
__open
__read
__libc_alloca_cutoff
encrypt
encrypt_r
setkey
crypt
crypt_r
fcrypt
setkey_r

Implement / port missing libc functions

  • Implement as stub function

These functions are OK to implement as stub.

initgroups
getgroups
setgroups
getpgid
setpgid
getpgrp
getppid
getsid
setsid
waitpid
getgrnam_r
getpwnam_r
setegid
setregid   
setreuid
seteuid

OSv does not have multiuser feature, so these UID/GID stuff can go as stub.

__longjmp_chk
__memmove_chk
__memset_chk
__strncpy_chk

These glibc internal function can go as stub.

execl
execle
execv
execve

We won't support exec from Ruby, so these functions just need to return -1.

  • Porting from musl-libc

These functions are able to port from musl-libc.

crypt
crypt_r
encrypt
encrypt_r
fcrypt
setkey
setkey_r

crypt,crypt_r and encrypt are in musl-libc.
encrypt_r,fcrypt,setkey and setkey_r are not available in musl-libc but they can be diverted from musl/src/crypt/*.

endpwent
eaccess

musl has musl/src/passwd/getpwent.c:setpwent and musl/src/legacy/euideaccess.c:euideaccess
setpwent is weak alias of endpwent, and euideacess is weak alias of eaccess.

__open
__read

__open is alias of open, __read is alias of read.

  • Implement from scratch

These functions are not avilable on musl-libc, so I need to implement from scrach.

rewinddir
seekdir
telldir

These function are available on osv/fs/vfs/main.cc as sys_*.

pthread_attr_getguardsize
pthread_attr_setinheritsched

Implement in osv/libc/pthread.cc.
It will only few change.

__isinf

Check gave value is inf or not on fpu.
Written in assembly.

backtrace_symbols

I can refer print_backtrace() on runtime.cc.

malloc_usable_size

Checking left size of malloc manage memory area and return it.

__libc_alloca_cutoff

main thread stack size compare with const number.
Modifications on CRuby

  • getcontext on CRuby cont.c in CRuby depends on getcontext/makecontext/swapcontext, these calls are not available on OSv.
    But it seems to prevent calling it by changing ifdef flags(FIBER_USE_NATIVE=0).
    To to so, I'll add some modification on Makefile.

It whould be nice to send a patch to CRuby upstream as well.

  • Patching libgmp

  • Add CRuby on apps/ruby

Ruby application target on OSv module infrastructure
Current OSv implementation includes Java application support on module infrastructure.
For example, on apps/cassandra/module.py we have:

api.run_java(jvm_args=[], classpath=[], args=[])

We want

api.run_ruby()

for Ruby application.
A Ruby application sample witch using the target

Port CLI based Twitter client called "earthquake.gem".
The application depends openssl and readline gems.
To build gems and copy gems on OSv filesystem, I will use builder on building stage.

Add earthquake.gem on apps/earthquake, using Ruby application target.

Note: I need to implement another libc functions to port openssl and readline gems.
I will work on it week 10 - week 12, too.

Test Plan: Implement unit test on tests/ for each libc functions.
For testing CRuby, I will use test code on CRuby distribution.

Project Schedule:
week 1:
Implement stub functions, implement tests/ for it, and test it

week 2 - week 4 :
Porting function from musl-libc, implement tests/ for it, and test it

week 5 - week 6 (mid-term):
Implement functions from scratch, implement tests/ for it, and test it On mid-term, we will see all tests for new functions work without problem.

week 7 - week 9:
Implement modifications on CRuby, test it using test code on CRuby distribution

week 10 - week12 (penscil down):
Implement Ruby application target on OSv module, port Ruby application sample on it, test it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment