Complex Lab – Operating Systems - Sessions and Dynamic Memory

Similar documents
Complex Lab – Operating Systems - Graphical Console

はじめに

open / window / I / shall / the? something / want / drink / I / to the way / you / tell / the library / would / to / me

What s your name? Help me carry the baggage, please. politeness What s your name? Help me carry the baggage, please. iii



C. S2 X D. E.. (1) X S1 10 S2 X+S1 3 X+S S1S2 X+S1+S2 X S1 X+S S X+S2 X A. S1 2 a. b. c. d. e. 2

Microsoft Word - Win-Outlook.docx

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

平成29年度英語力調査結果(中学3年生)の概要

目次 1. レッスンで使える表現 レッスンでお困りの際に使えるフレーズからレッスンの中でよく使われるフレーズまで 便利な表現をご紹介させていただきます ご活用方法として 講師に伝えたいことが伝わらない場合に下記の通りご利用ください 1 該当の表現を直接講師に伝える 2 該当の英語表現を Skype

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

\615L\625\761\621\745\615\750\617\743\623\6075\614\616\615\606.PS

Introduction Purpose This training course describes the configuration and session features of the High-performance Embedded Workshop (HEW), a key tool

きずなプロジェクト-表紙.indd


Microsoft Word - j201drills27.doc

L1 What Can You Blood Type Tell Us? Part 1 Can you guess/ my blood type? Well,/ you re very serious person/ so/ I think/ your blood type is A. Wow!/ G

生研ニュースNo.132

西川町広報誌NETWORKにしかわ2011年1月号

国際恋愛で避けるべき7つの失敗と解決策

AERA_English_CP_Sample_org.pdf

VE-GP32DL_DW_ZA

2

fx-9860G Manager PLUS_J


Microsoft Word - j201drills27.doc

<4D F736F F F696E74202D CEA8D758DC E396BC8E8C F92758E8C81458C E8C81458F9593AE8E8C>

S1Šû‘KŒâ‚è

GP05取説.indb

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM

Read the following text messages. Study the names carefully. 次のメッセージを読みましょう 名前をしっかり覚えましょう Dear Jenny, Iʼm Kim Garcia. Iʼm your new classmate. These ar

-2-

<4D F736F F D208BB38DDE5F F4390B394C52E646F6378>




Z7000操作編_本文.indb

untitled

Contents Logging in 3-14 Downloading files from e-ijlp 15 Submitting files on e-ijlp Sending messages to instructors Setting up automatic

<95DB8C9288E397C389C88A E696E6462>

キャリアワークショップ教師用

第16回ニュージェネレーション_cs4.indd

VE-GD21DL_DW_ZB

取説_KX-PW38CL_PW48CL

Hospitality-mae.indd

自分の天職をつかめ

紀要1444_大扉&目次_初.indd

25 II :30 16:00 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 3.. Answer the following 3 proble

取説_KX-PW101CL_PW102CW


高2SL高1HL 文法後期後半_テキスト-0108.indd

L3 Japanese (90570) 2008

PFQX2227_ZA


2

2


...

CONTENTS Public relations brochure of Higashikawa November No.745 Higashikawa 215 November 2

LC304_manual.ai

第17回勉強会「英語の教え方教室」報告

2

Warm Up Topic Question Who was the last person you gave a gift to? 一番最近誰にプレゼントをあげましたか? Special Topics2

MEET 270

富士フイルムニュース vol.63

elemmay09.pub

千葉県における温泉地の地域的展開

アンケート2

Webサービス本格活用のための設計ポイント

-2-


オブジェクト脳のつくり方

BS・110度CSデジタルハイビジョンチューナー P-TU1000JS取扱説明書


untitled

2

取扱説明書_KX-PW100CL


1 ( 8:12) Eccles. 1:8 2 2

sein_sandwich2_FM_bounus_NYUKO.indd

19_22_26R9000操作編ブック.indb

Microsoft Word - PCM TL-Ed.4.4(特定電気用品適合性検査申込のご案内)




鹿大広報149号

ユーザーズマニュアル

Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involv

Ver.1 1/17/2003 2

日本語教育紀要 7/pdf用 表紙

David A Thayne Presents. Bonus Edition OK! tossa_h_ol.indd 1 12/12/07 21:09

i5 Catalyst Case Instructions JP

2009 No


駒田朋子.indd

H8000操作編

untitled

soturon.dvi

/ [Save & Submit Code]ボタン が 下 部 やや 左 に ありますが このボタンを 押 すと 右 上 の 小 さいウィンドウ(the results tab) が 本 物 のブラウザのようにアク ションします (ブラウザの 例 : Chrome(グーグルクロム) Firefox(

Transcription:

Complex Lab Operating Systems Sessions and Dynamic Memory Martin Küttler

Last assignment Sending multiple messages for large texts is ok. 1 / 19

Last assignment Sending multiple messages for large texts is ok. If you allocate memory, remember to deallocate the memory and capabilities. 1 / 19

Last assignment Sending multiple messages for large texts is ok. If you allocate memory, remember to deallocate the memory and capabilities. You should update your Control le (libc_be_mem, stdlib,...) 1 / 19

Last assignment Sending multiple messages for large texts is ok. If you allocate memory, remember to deallocate the memory and capabilities. You should update your Control le (libc_be_mem, stdlib,...) Please report problems (errors/missing informations in slides, missing/bad documentation) to me. 1 / 19

Last assignment Sending multiple messages for large texts is ok. If you allocate memory, remember to deallocate the memory and capabilities. You should update your Control le (libc_be_mem, stdlib,...) Please report problems (errors/missing informations in slides, missing/bad documentation) to me. Any questions? 1 / 19

We are here Pong Server Paddle Client 1 Paddle Client 2 Moe Sigma0 Fiasco Kernel 2 / 19

Today's goal Pong Server Paddle Client 1 Paddle Client 2 Keyboard Driver Console Memory Management Moe Sigma0 Fiasco Kernel 3 / 19

Sessions Scenario: Multiple clients per server Server stores per-client data, needs to distinguish between clients 4 / 19

Sessions Scenario: Multiple clients per server Server stores per-client data, needs to distinguish between clients Poor man's solution: Assign dynamic ID, which clients sends with each call Problem: IDs can be faked 4 / 19

Sessions Scenario: Multiple clients per server Server stores per-client data, needs to distinguish between clients Poor man's solution: Assign dynamic ID, which clients sends with each call Problem: IDs can be faked Better (actual) solution: Sessions One IPC gate per client Clients can be distinguished by the gate label Preferably clients should not even know about sessions 4 / 19

Sessions in L4Re Ned create gate 5 / 19

Sessions in L4Re start server Ned Server 5 / 19

Sessions in L4Re Ned call Factory::create() Server 5 / 19

Sessions in L4Re Ned Server create 5 / 19

Sessions in L4Re Ned start client Server Client 5 / 19

Sessions in L4Re Ned Server invoke Client 5 / 19

Lua Example: Simple local L4 = require (" L4 " ); local ld = L4.default_loader ; local log = ld : new_channel (); ld : start ({ caps = { log_server = log : svr () }, log = { " server ", " blue " } }, " rom / logging " ); ld : start ({ caps = { log_server = log }, log = { " client ", " green " } }, " rom / logging_client " ); 6 / 19

Lua Example: Sessions local L4 = require (" L4 " ); local ld = L4.default_loader ; local log = ld : new_channel (); ld : start ({ caps = { log_server = log : svr () }, log = { " server ", " blue " } }, " rom / logging " ); ld : start ({ caps = { log_server = log : create (0, " args ") }, log = { " client ", " green " } }, " rom / logging_client " ); 7 / 19

Sessions Implementation Clients don't change at all (that's what we wanted, remember?) Servers need to handle the create call. 8 / 19

Sessions Implementation Clients don't change at all (that's what we wanted, remember?) Servers need to handle the create call. Before we look at that,... 8 / 19

Sessions Implementation Clients don't change at all (that's what we wanted, remember?) Servers need to handle the create call. Before we look at that,... A short tour of the L4Re IPC server framework 8 / 19

A short tour of the L4Re IPC server framework L4 : : Server implements the basic server loop: void loop () { while (1) { m = recv_message (); ret = dispatch (m, utcb ); reply (m, ret ); } } 9 / 19

A short tour of the L4Re IPC server framework L4 : : Server implements the basic server loop: void loop () { while (1) { m = recv_message (); ret = dispatch (m, utcb ); reply (m, ret ); } } For each IPC gate there is a L4 : : Epiface, which keeps the capability to the IPC gate, handles messages from this gate (implements d i s p a t c h ( ) ) 9 / 19

A short tour of the L4Re IPC server framework L4 : : Server implements the basic server loop: void loop () { while (1) { m = recv_message (); ret = dispatch (m, utcb ); reply (m, ret ); } } For each IPC gate there is a L4 : : Epiface, which keeps the capability to the IPC gate, handles messages from this gate (implements d i s p a t c h ( ) ) How does the server know which Epiface it should call? 9 / 19

IPC tour: Epiface registry L4 : : Epifaces are stored in a per-server registry. The registry can nd Epifaces by an ID (label of IPC gate) L4 : : B a s i c _ r e g i s t r y : ID is pointer to object L4Re : : U t i l : : Object_registry provides a convenient interface: L4 :: Cap < void > register_obj ( L4 :: Epiface *o, char const * service ); L4 :: Cap < void > register_obj ( L4 :: Epiface *o ); bool unregister_obj ( L4 :: Epiface *o ); 10 / 19

IPC tour: Registry server L4Re : : U t i l : : Registry_server is a L4 : : Server that maintaines a L4Re : : U t i l : : Object_registry static L4Re :: Util :: Registry_server <> server ; class MyServer : public L4 :: Epiface_t < MyServer, MyInterface > {... }; // When you need a new session object server. registry () - > register_obj ( new MyServer ()); 11 / 19

Session Implementation Factory Server class SessionServer : L4 :: Epiface_t < SessionServer, L4 :: Factory > { public : int op_create ( L4 :: Factory :: Rights, L4 :: Ipc :: Cap < void >& res, l4_mword_t type, L4 :: Ipc :: Varg_list <> args ) { if ( type!= 0) return - L4_ENODEV ; L4 :: Ipc :: Varg tag = args. next (); if (! tag. is_of < char const * >()) return - L4_EINVAL ; }; } auto helloserver = new HelloServer ( tag. value < char const * >()); server. registry () - > register_obj ( helloserver ); res = L4 :: Ipc :: make_cap_rw ( helloserver -> obj_cap ()); return L4_ EOK ; 12 / 19

Sessions With that you can add support for multiple clients in the hello server. 13 / 19

Sessions With that you can add support for multiple clients in the hello server. Assignment 1.5: Make your hello server a logging server that supports multiple clients Client messages should be prexed with an id string, that is passed to the server in the create call. 13 / 19

Sessions With that you can add support for multiple clients in the hello server. Assignment 1.5: Make your hello server a logging server that supports multiple clients Client messages should be prexed with an id string, that is passed to the server in the create call. Problem: Now you need dynamic memory, but malloc and f r e e are missing. 13 / 19

Memory Allocation Memory allocation is (currently not) implemented in a backend of L4Re's C library (in src/l4/pkg/l4re-core/libc_backends/) You can get new pages from Moe: Allocate a dataspace capability Get a dataspace from Moe: L4Re : : Env : : env() >mem_alloc() > a l l o c ( s i z e, ds ) ; Attach dataspace to local address space: L4Re : : Env : : env() >rm() > a t t a c h (&addr, s i z e, f l a g s, ds ) ; To free unused pages: L4Re : : Env : : env() >rm() >detach ( addr, n u l l p t r ) ; L4Re : : Env : : env() >mem_alloc() > f r e e ( ds ) ; 14 / 19

Incorrect malloc() void * malloc ( unsigned size ) { L4 :: Cap < L4Re :: Dataspace > ds = L4Re :: Util :: cap_alloc. alloc < L4Re :: Dataspace >(); if (! ds. is_valid ()) return 0; long err = L4Re :: Env :: env () - > mem_alloc () - > alloc ( size, ds ); if ( err ) return 0; void * addr = 0; err = L4Re :: Env :: env () - > rm () - > attach (& addr, size, L4Re :: Rm :: Search_addr, ds ); if ( err ) return 0; } return addr ; 15 / 19

Memory Management Lists Idea: Keep list of (address, size) pairs In malloc, search for an appropreate entry Problem: You'd need dynamic memory for that list. Typical Solution: Inlining Put size and next-pointer directly into your memory Do not hand out the memory where size is stored it's needed for free. That's what most libc-implementations do. 16 / 19

Memory Management bitmaps Manage memory as pool of xed-sized chunks. Use bitmap to store available chunks. 17 / 19

Memory Management problems You will need some initial memory. You can use L4Re's memory allocator for that. As soon as you have multiple threads (you will), you need proper locking. There are more options for the implementation. Come up with something yourself, or have a look in some book / the internet. 18 / 19

Assignment 2 Implement a session-capable hello server (that's going to be our logging server) For that you'll need to implement malloc, f r e e and r e a l l o c. From there on, you should be able to use C++'s STL. 19 / 19