Takagi Lab ServerSide
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `Goならわかるシステムプログラミング` # 第5回 Goから見たシステムコール https://ascii.jp/elem/000/001/267/1267477/ ## 1. システムコールとは システムコールとは「特権モードでOSの機能を呼ぶ」こと. ### そもそもOSとはなんだったか ・ プロセス間の通信 ・ メモリや時間などの資源の管理 ・ 外部入出力機能 を提供するソフトウェアの一種. ### 特権モードとは CPUの動作モードには, ・ 特権モード ・ ユーザーモード の2種類があり,実行するソフトウェアの種類によってアクセス可能なハードウェアの機能に制限を設けている. (例えば,変なプロセスがおイタしないように自分以外へのメモリアクセスを制限したりする.) **通常のアプリケーションはユーザモードで実行されるが,メモリ割り当て,外部入出力,通信などの権限を持たない.** ### システムコール 特権モードでのみ許されている機能をユーザモードのアプリケーションから利用できるようにする機能. SYSCALL命令などで呼び出されたプロセスは特権モードで動作する. ## 2. Go言語における各OSのシステムコールの実装 前回までに扱ったioパッケージのインターフェースは最終的にシステムコールを呼んでいる.各OSにおけるsyscall.Open()関数の実装をのぞいてみよう. ### macOSの場合(恐らくUnix全般) * zsyscall_darwin_amd64.goのOpen()関数を呼ぶ. * Syscall()関数を呼ぶ. ここで,pathは先頭要素へのポインタに変換される.また,ヘッダファイルから自動生成されるSYS_OPENの**番号**でOSの処理を指定している. * asm_darwin_amd64.sのSYSCALL以下で以下をを呼ぶ. entersyscall()関数: 実行中のOSスレッドがブロックされているフラグを立てる existsyscall() 関数: フラグを外す →スレッド立てるという重い処理を最小限に抑えることができる ### Linuxの場合 macOSとほぼ同じ * syscall_linux.goのOpen()関数でopenat()関数を呼ぶ. * 渡せるパラメータが多いSyscall6()関数を呼ぶ.違いは不明. 以下は同じ. ### Windowsの場合 システムコールを直接は呼び出せない.DLLと共にWin32 APIなどを使って呼ぶ. - [ ] DLL(Dynamic Link Library): 部品化されたプログラムで .exeファイルなどど一緒にメモリに展開される. http://e-words.jp/w/DLL.html ## 3. POSIX.1 システムコールを呼び出すためのOS間で共通のインタフェースを定めた規格. **C言語で**open(),read(),write(),close(),lseek()の5つの関数名と引数,返り値が定義されている. ## 4. システムコールより内側の世界 カーネル側のコードを見てみよう. ユーザモードのアプリケーションと特権モードのカーネル間で呼び出されるSYSCALL命令では,引数などの情報はすべてCPUのレジスタ経由で渡される. - [ ] レジスタ: CPUの計算記憶領域.https://ponsuke-tarou.hatenablog.com/entry/2017/10/03/235932 ## 5. Go言語のシステムコールとPOSIX GoはPOSIXのコンセプトを利用しておらず,自前で番号指定してシステムコールを呼び出している. →プラットフォームに依らない開発が容易. - [ ] クロスコンパイル: コンパイラが動作している以外のプラットフォーム向けに実行ファイルを生成すること.Macで開発していてもLinux,Windows用のバイナリが作れる. ## 6. システムコールのモニタリング アプリケーションの動作の監視にはシステムコールのログを見るという手もある. # 第6回 GoでたたくTCPソケット(前編) https://ascii.jp/elem/000/001/276/1276572/ ## 1. プロトコルとレイヤー インターネット通信ではTCP/IP参照モデルで機能をレイヤーに分割し,各々のプロトコルを規定している. レイヤー分割のおかげで,開発ではトランスポート層以上のレイヤーのみ考えれば良い. ## 2. HTTPとその上のプロトコルたち ### HTTPの基本 HTTP/1.0では以下のようなリクエスト/レスポンスで通信を行う. HTTPリクエスト(改行区切りテキスト): ・メソッド(POST,GET)+パス+HTTPバージョン ・ヘッダー ・ボディ HTTPレスポンス: ・HTTPバージョン+200+OK ・ヘッダー ・ボディ - [ ] SSL(Secure Sockets Layer)/TLS(Transport Layer Security): インターネット上でデータを暗号化して送受信するプロトコル. ### RPC(Remote Procedure Calling) サーバが用意している機能を関数のように呼び出すためのHTTP上のプロトコルのこと. Go言語ではJSON-RPCが標準ライブラリとして提供されている. ### REST(Representational State Transfer) ウェブサービスのような分散型システムの通信において,以下の4つの原則を適用したリソース指向アーキテクチャスタイルのこと. * アドレス可能性(Addressability) * リソースがURLを通して表現できること.リソースとURLは一対一に対応している. * ステートレス性(Stateless) * 全てのHTTPリクエストが完全に分離している性質のこと.セッション等の状態管理はせず,やり取りされる情報はそれ自体で完結させる. * 接続性(Connectability) * リソースの内部に別のリソースやリンクを含めることができること.リソースに含まれるリンクをもとに別のリソースに接続可能となる. * 統一インターフェース(Uniform Interface) * 情報の操作は全てHTTPメソッド(GET,POST,PUT,DELETE)を利用すること. RESTの思想にしたがうシステムのことを「RESTful」という.https://qiita.com/NagaokaKenichi/items/0647c30ef596cedf4bf2 - [ ] リソース: Web上に存在する情報.ウェブサイトを構成するもの一般(文書・画像・その他諸々のデータファイルなど) - [ ] HATEOAS: よくわからない. http://uehaj.hatenablog.com/entry/hateoas ### GraphQL 複数の属性から構成されている要素をピンポイントで取得するためのクエリ言語. リソース表現が複数考えられる場合でも統一的に記述できる. ## 3. ソケットとは アプリケーション層からトランスポート層のプロトコルを利用するときのAPIのこと. アドレスとポート番号が分かればローカルだけではなく外部のコンピュータとも通信が行える. ## 4. ソケット通信の基本構造 サーバ:ソケットを開いて待ち受ける.Listen() クライアント:開いているソケットに接続し,通信を行う.Dial() GoにおけるTCPソケットを使った通信はnet.Connインタフェースを満たすオブジェクトを介して行われる. ## 5. Go言語でHTTPサーバを実装する TCPソケットを使ったHTTPサーバ TCPソケットを使ったHTTPクライアント ## 6. HTTP/1.1のKeep-Aliveに対応させる Keep-Aliveでしばらくの間はTCP接続のセッションを維持して使いまわせる.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully